Sensor library for Android

Use of external libraries (DLLs) from ZGE.

Moderator: Moderators

User avatar
Rado1
Posts: 672
Joined: Wed May 05, 2010 12:16 pm

Sensor library for Android

Postby Rado1 » Sun Mar 03, 2013 5:36 pm

I'm pleased to announce the ZGESensor shared library used to handle sensors for Android applications. For details, downloads, demo and code see http://code.google.com/p/zgesensor/.

I tested the library on Nexus 7, ZTE Blade II and HTC One V; everything works fine.

Ville, if you think it is useful, you can include the ZGESensor library definition file and menu item to standard ZGE distribution. Its definition is in the demo project.

User avatar
VilleK
Site Admin
Posts: 1706
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Postby VilleK » Mon Mar 04, 2013 8:41 am

This is great work Rado1! I haven't tested it yet but it looks clean and easy to use from the sources. Of course we should add this definition file to the general distribution.

User avatar
Rado1
Posts: 672
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Mon Mar 04, 2013 12:00 pm

FYI a small howto description is available here.

Any comments to implementation, usage, documentation, demo(s), etc. are welcome. I would appreciate if you can test ZGESensor library also on other devices to be sure it works properly.

I plan to implement more demos and games soon.

User avatar
jph_wacheski
Posts: 1004
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Postby jph_wacheski » Tue Mar 05, 2013 8:17 pm

Wow, this is excellent!

I will see what type of game I can knock out quickly,. I find I spent too much time on some things never getting them 'done',. perhaps a self imposed crunch-time will work.

Nice work Rado, seems to work very well here indeed. I did not even know these devices had all this sci-fi gear in-built! I will report any thing interesting that I happen to find while working with it.
iterationGAMES.com

User avatar
Rado1
Posts: 672
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Sun Mar 10, 2013 1:51 pm

I just committed v1.1 of ZGESensor library. Download it from here. The latest changes include:
- Function sensorGetData was divided to sensorGetData1, sensorGetData3 and sensorGetData4 with different numbers of parameters for different sensor types.
- Added demo project #2 for rotation vector sensor. This is a variant of the RotationVectorDemo from Android SDK samples implemented in ZGE.
- Updated ZExternalLibrary and ZGE demo projects accordingly.

Vile, please include the latest version of ZExternalLibrary for ZGESensor to ZGE. Thanks.

User avatar
Rado1
Posts: 672
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Sun Mar 24, 2013 12:12 pm

After painful learning and experiments with JNI, version 1.2 of the ZGESensor library was produced; it is available here. It includes:

- Added function getDisplayRotation; this is necessary for creating device-independent, sensor-aware applications
- Added JNI_OnLoad function to obtain display rotation from SDK
- Removed sensorUpdateData function; sensor data is updated automatically in a callback
- Added optional logging to logcat (switched off by default)
- Updated demo projects to handle device's display rotation

To be able to access Android SDK functions by JNI, I had to update the ZGEActivity.java; see the attachment. Without this change, accessing of non-static methods and fields of objects from running ZGE instance is impossible. This change is inevitable for any library which uses JNI, not just ZGESensor.

Ville, could you please add the updated version of ZGEActivity.java and ZGESensor ZExternalLibrary to official distribution? Thanks.
Attachments
ZgeActivity.zip
Updated ZgeActivity.java
(1.24 KiB) Downloaded 159 times
Last edited by Rado1 on Sun Mar 24, 2013 2:40 pm, edited 1 time in total.

User avatar
VilleK
Site Admin
Posts: 1706
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Postby VilleK » Sun Mar 24, 2013 2:39 pm

Good job Rado1, I know JNI coding can be very frustrating :-)
I've added the source file and also the latest library definitions to my local files and will commit to Google code.

This is the first time I try the demo projects. Sensor demo 2 works here, but demo 1 crashes and gives the following log:
E/ZgeAndroid(20238): glEnableVertexAttribArray
E/ZgeAndroid(20238): glVertexAttribPointer
E/ZgeAndroid(20238): sensorUpdateData
E/ZgeAndroid(20238): sensorUpdateData
E/ZgeAndroid(20238): sensorUpdateData
V/Sensors ( 482): int poll__setDelay(sensors_poll_device_t*, int, int64_t)
V/Sensors ( 482): int sensors_poll_context_t::setDelay(int, int64_t)
V/Sensors ( 482): setDelay - sensor Accelerometer (handle 4), rate 200 ms (5.00 Hz)
W/InputDispatcher( 482): channel '41fdfca0 com.rado1.SensorDemo1/org.zgameeditor.ZgeActivity (server)' ~ Consumer closed input channel or an error occurred.
vents=0x8
E/InputDispatcher( 482): channel '41fdfca0 com.rado1.SensorDemo1/org.zgameeditor.ZgeActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
I/ActivityManager( 482): Process com.rado1.SensorDemo1 (pid 20238) has died.
W/ActivityManager( 482): Force removing ActivityRecord{41456b88 com.rado1.SensorDemo1/org.zgameeditor.ZgeActivity}: app died, no saved state
V/Sensors ( 482): int poll__activate(sensors_poll_device_t*, int, int)
V/Sensors ( 482): int sensors_poll_context_t::activate(int, int)
E/Sensors ( 482): switch lsensor off OK!
V/Sensors ( 482): int poll__setDelay(sensors_poll_device_t*, int, int64_t)
V/Sensors ( 482): int sensors_poll_context_t::setDelay(int, int64_t)
W/InputDispatcher( 482): Attempted to unregister already unregistered input channel '41fdfca0 com.rado1.SensorDemo1/org.zgameeditor.ZgeActivity (server)'
I/WindowManager( 482): WIN DEATH: Window{42172e18 SurfaceView paused=false}
I/WindowManager( 482): WIN DEATH: Window{41fdfca0 com.rado1.SensorDemo1/org.zgameeditor.ZgeActivity paused=false}
D/memalloc( 231): ion: Freeing buffer base:0x43a40000 size:1011712 fd:68
D/memalloc( 231): ion: Unmapping buffer base:0x43a40000 size:1011712
I/Adreno200-EGLSUB( 872): <ConfigWindowMatch:2212>: Format RGBA_8888.
I/WindowManager( 482): WINDOW DIED Window{41fdfca0 com.rado1.SensorDemo1/org.zgameeditor.ZgeActivity paused=false}

User avatar
Rado1
Posts: 672
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Sun Mar 24, 2013 2:52 pm

VilleK wrote:This is the first time I try the demo projects. Sensor demo 2 works here, but demo 1 crashes

Hi Ville, are you sure you used the latest version of the Demo 1 project and ZGESensor library? The function sensorUpdateData was removed and is not called from the projects. However, I forget to remove it also from ZExternalLibrary (I'm going to do it now). Can it be the problem?
Last edited by Rado1 on Sun Mar 24, 2013 2:59 pm, edited 1 time in total.

User avatar
VilleK
Site Admin
Posts: 1706
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Postby VilleK » Sun Mar 24, 2013 2:53 pm

Thanks, you are right, I mistakenly used an old version of the zgeproj file. Works now!

User avatar
Rado1
Posts: 672
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Sun Mar 24, 2013 8:00 pm

New sensor demo #3 shows usage of rotation vector sensor to move a player in a 3D space.

Rotate the screen to rotate the camera view, touch right side of the screen with a single finger to move forward, left side of the screen to move backward, and touch the screen with three fingers to regenerate the scene and reset player's position.

And now imagine 3D maze, physics, things to collect, enemies to avoid and destruct, ... wouldn't it be nice? I'm going to create a game like this.

The demo was tested on Nexus 7 and ZTE Blade II, but does not work on devices without rotation vector sensor, e.g., HTC One V or ARCHOS 80 G9 I tried.

Could you please try it also on your devices? Any comments are welcome. Have a fun!
Attachments
screenshot.jpg
screenshot
screenshot.jpg (132.28 KiB) Viewed 3234 times

User avatar
VilleK
Site Admin
Posts: 1706
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Postby VilleK » Mon Mar 25, 2013 12:59 pm

It is very cool but I find it highly difficult (and dizzying) to navigate :)
Also frame update interval is slightly sluggish. Even though Fps is around 60. Is this because of the sensors not updating more often on my device?

User avatar
Rado1
Posts: 672
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Mon Mar 25, 2013 1:54 pm

VilleK wrote:Also frame update interval is slightly sluggish. Even though Fps is around 60. Is this because of the sensors not updating more often on my device?

Probably this is not matter of frame update, but precision of sensors on your device. The used rotation vector sensor is a virtual (software) sensor which takes information from accelerometer, geomagnetic field, and gyroscope sensors. If any of them is missing or imprecise, rotation vector can have problems. The demo works smoothly on newer devices, such as Nexus 7 or ASUS Transformer Pad TF300.

User avatar
jph_wacheski
Posts: 1004
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Postby jph_wacheski » Sun May 05, 2013 1:54 pm

Here is a little demo using the original version of the this,. I have to update my ZGE and this library to the latest,. as currently this is dependent on the screen orientation when you start,. that is if the controls are inverted (strange) just exit the app, flip your device and start it again.

I am hoping with this update I can implement it so gravity will be relative to the position of yourdevice when you start the game,. as currently down is towards the center of the earth, meaning you must be sitting upright to play,. fine for playing while taking a dump, but no good when lying down,. .

again, I get too involved in rendering/sound design to bother finishing the gameplay, so this is very simple so far. (although I think i can make it more interesting)
Attachments
SwampGas-debug.zip
.apk file in a zip folder,. .
(818.92 KiB) Downloaded 144 times
iterationGAMES.com

User avatar
Rado1
Posts: 672
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Sun Mar 15, 2015 8:45 am

Source code repository for ZgeSensor has been moved to GitHub.


Return to “Extensions”

Who is online

Users browsing this forum: No registered users and 0 guests