ZGameEditor forum Forum Index ZGameEditor forum
The rapid development solution with a tiny footprint. ZGE Wiki homepage.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sensor library for Android

 
Post new topic   Reply to topic    ZGameEditor forum Forum Index -> Extensions
View previous topic :: View next topic  
Author Message
Rado1



Joined: 05 May 2010
Posts: 520

PostPosted: Sun Mar 03, 2013 5:36 pm    Post subject: Sensor library for Android Reply with quote

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.
Back to top
View user's profile Send private message
VilleK
Site Admin


Joined: 15 Jan 2007
Posts: 1554
Location: Stockholm, Sweden

PostPosted: Mon Mar 04, 2013 8:41 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Rado1



Joined: 05 May 2010
Posts: 520

PostPosted: Mon Mar 04, 2013 12:00 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
jph_wacheski



Joined: 16 Feb 2008
Posts: 983
Location: Canada

PostPosted: Tue Mar 05, 2013 8:17 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Rado1



Joined: 05 May 2010
Posts: 520

PostPosted: Sun Mar 10, 2013 1:51 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Rado1



Joined: 05 May 2010
Posts: 520

PostPosted: Sun Mar 24, 2013 12:12 pm    Post subject: Reply with quote

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.



ZgeActivity.zip
 Description:
Updated ZgeActivity.java

Download
 Filename:  ZgeActivity.zip
 Filesize:  1.24 KB
 Downloaded:  115 Time(s)



Last edited by Rado1 on Sun Mar 24, 2013 2:40 pm; edited 1 time in total
Back to top
View user's profile Send private message
VilleK
Site Admin


Joined: 15 Jan 2007
Posts: 1554
Location: Stockholm, Sweden

PostPosted: Sun Mar 24, 2013 2:39 pm    Post subject: Reply with quote

Good job Rado1, I know JNI coding can be very frustrating Smile
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:
Quote:
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}
Back to top
View user's profile Send private message Visit poster's website
Rado1



Joined: 05 May 2010
Posts: 520

PostPosted: Sun Mar 24, 2013 2:52 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
VilleK
Site Admin


Joined: 15 Jan 2007
Posts: 1554
Location: Stockholm, Sweden

PostPosted: Sun Mar 24, 2013 2:53 pm    Post subject: Reply with quote

Thanks, you are right, I mistakenly used an old version of the zgeproj file. Works now!
Back to top
View user's profile Send private message Visit poster's website
Rado1



Joined: 05 May 2010
Posts: 520

PostPosted: Sun Mar 24, 2013 8:00 pm    Post subject: Reply with quote

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!



screenshot.jpg
 Description:
screenshot
 Filesize:  132.28 KB
 Viewed:  2124 Time(s)

screenshot.jpg


Back to top
View user's profile Send private message
VilleK
Site Admin


Joined: 15 Jan 2007
Posts: 1554
Location: Stockholm, Sweden

PostPosted: Mon Mar 25, 2013 12:59 pm    Post subject: Reply with quote

It is very cool but I find it highly difficult (and dizzying) to navigate Smile
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?
Back to top
View user's profile Send private message Visit poster's website
Rado1



Joined: 05 May 2010
Posts: 520

PostPosted: Mon Mar 25, 2013 1:54 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
jph_wacheski



Joined: 16 Feb 2008
Posts: 983
Location: Canada

PostPosted: Sun May 05, 2013 1:54 pm    Post subject: Reply with quote

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)



SwampGas-debug.zip
 Description:
.apk file in a zip folder,. .

Download
 Filename:  SwampGas-debug.zip
 Filesize:  818.92 KB
 Downloaded:  97 Time(s)


_________________
iterationGAMES.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    ZGameEditor forum Forum Index -> Extensions All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group