Demo: 2D physics using sensor module
Hi there,
I've made a small application that'll make use of the accelerometer in a mobile with PyS60 installed. You'll need the Python shell installed to be able to run it (I have not made it into a .sis file.)
Here it is: [url]http://projects.mezane.org/verlet.py[/url]
What you should see is a box that'll move in whatever direction that the phone is tilted. So if you tilt it right, it'll slide to the right of the screen, and the velocity will vary depending on the amount of tilt. In addition to this, it also applies forces from the acceleration of your phone. So if you hold your phone upright so that the box falls to the bottom of the screen, then move your phone quickly upwards and stop abruptly, the box will fly upwards as you'd expect.
This has only been tested on an N95 8GB and since this is the first Python script I've attempted I'd appreciate input on my code.
I'm positively surprised at the simplicity of developing applications using Python and also at the responsiveness of the accelerometer!
Regards,
Andreas
Re: Demo: 2D physics using sensor module
[QUOTE=Andreas Blixt;366255]This has only been tested on an N95 8GB and since this is the first Python script I've attempted I'd appreciate input on my code.
I'm positively surprised at the simplicity of developing applications using Python and also at the responsiveness of the accelerometer!
[/QUOTE]
Nice, it seems that the N95 8GB supports the "AccSensor" out-of-the-box - so the standard "sensor" extension can be used with the device to get acceleration data (I don't have a N95 8GB device to test it).
(ps. the "e32.ao_sleep()" can be somewhat dangerous to use - the application will panic should the user exit during the sleep call, please see the API document for more information)
Re: Demo: 2D physics using sensor module
[QUOTE=otsov;366359]Nice, it seems that the N95 8GB supports the "AccSensor" out-of-the-box - so the standard "sensor" extension can be used with the device to get acceleration data (I don't have a N95 8GB device to test it).
(ps. the "e32.ao_sleep()" can be somewhat dangerous to use - the application will panic should the user exit during the sleep call, please see the API document for more information)[/QUOTE]
Hi otsov,
Thanks for your input! Doesn't the PyS60 v1.4.1 sensor module enable accelerator access equally on all mobiles with an accelerator? Is there any way for me to make my script compatible with more mobiles?
I've changed my code to use e32.Ao_timer() and to call cancel() on the timer when the application is exiting. I hope this solves the "panic" problem?
I also added friction when an atom touches the edge of the screen.
Re: Demo: 2D physics using sensor module
[QUOTE=otsov;366359]Nice, it seems that the N95 8GB supports the "AccSensor" out-of-the-box - so the standard "sensor" extension can be used with the device to get acceleration data (I don't have a N95 8GB device to test it).
[/QUOTE]
Hello otsov ,
Yes N95 8GB support AccSensor and RotSensor from "sensor" extension without problem :D :) I have tested this on on a N95 8GB V10.0.021 29-09-07 :)
N95 with the new firmware released 20.0.015 has been reported working also ! :)
BR
Cyke64
Re: Demo: 2D physics using sensor module
[QUOTE=Andreas Blixt;366372]Hi otsov,
Thanks for your input! Doesn't the PyS60 v1.4.1 sensor module enable accelerator access equally on all mobiles with an accelerator? Is there any way for me to make my script compatible with more mobiles?
I've changed my code to use e32.Ao_timer() and to call cancel() on the timer when the application is exiting. I hope this solves the "panic" problem?
I also added friction when an atom touches the edge of the screen.[/QUOTE]
@andreas :
Congratulation for your cool example :)
"sensor" module don't work with all mobile containing an accelerator :eek:
Reported mobile 3rd edition containing an accelerator are N93i,N95,N95 8GB,N82 and 5500. If they support "sensor" (implementing sensor API from 5500) depend on firmware.
You could refer to [URL="http://wiki.forum.nokia.com/index.php/S60_Sensor_API"]this panel in the wiki[/URL] (sensor = "sensor" module support)
But you could also for N95 < 20.0.015 use module "aXYZ" and NRC plugin (search "aXYZ" for more info)
BR
Cyke64
Re: Demo: 2D physics using sensor module
@ andreas:
verlet.py is a [URL="http://projects.mezane.org/physics-enabled-html/"]short porting of verlet made in JavaScript[/URL].
Cool engine !
Cyke64
Re: Demo: 2D physics using sensor module
[QUOTE=cyke64;366479]verlet.py is a short porting of verlet made in JavaScript.[/QUOTE]
Yep, I've always liked coding Verlet particle physics and mass-spring physics because they're easy to implement and fun to play with.
Here are a few other tests I made with my JavaScript Verlet engine (they were mainly made for Mozilla Firefox, I'm afraid):
[url]http://projects.mezane.org/physics-enabled-html/test.html[/url]
[url]http://projects.mezane.org/physics-enabled-html/funnay.html[/url] (Use arrow keys)
I was thinking about how to turn Verlet physics + accelerometer into a game. One could make an obstacle course where the player has to rotate their phone to get through it.
Re: Demo: 2D physics using sensor module
[QUOTE=Andreas Blixt;366487]Yep, I've always liked coding Verlet particle physics and mass-spring physics because they're easy to implement and fun to play with.
Here are a few other tests I made with my JavaScript Verlet engine (they were mainly made for Mozilla Firefox, I'm afraid):
[url]http://projects.mezane.org/physics-enabled-html/test.html[/url]
[url]http://projects.mezane.org/physics-enabled-html/funnay.html[/url] (Use arrow keys)
I was thinking about how to turn Verlet physics + accelerometer into a game. One could make an obstacle course where the player has to rotate their phone to get through it.[/QUOTE]
Very funny :D
Yes it's a great idea !
[URL="http://discussion.forum.nokia.com/forum/showpost.php?p=366497&postcount=31"]I made a porting of your verlet.py for aXZY module[/URL] for other N95 with previous firmware.
I noted that X and Y data are inverted and sign inversion is not needed in aXYZ !
Cyke64
Re: Demo: 2D physics using sensor module
I got my new N82 today...
[QUOTE=Andreas Blixt;366255]I've made a small application that'll make use of the accelerometer in a mobile with PyS60 installed. [url]http://projects.mezane.org/verlet.py[/url]
What you should see is a box that'll move in whatever direction that the phone is tilted.[/QUOTE]
Works perfectly. Very cool. Very, very cool.
Re: Demo: 2D physics using sensor module
Unfortunately not for me due to the problem described here:
[url]http://discussion.forum.nokia.com/forum/showthread.php?t=118545[/url]
Regards
Re: Demo: 2D physics using sensor module
[QUOTE=neil.young;371300]Unfortunately not for me due to the problem described here:
[url]http://discussion.forum.nokia.com/forum/showthread.php?t=118545[/url]
Regards[/QUOTE]
Hmmm... I think I had that problem too, but I downloaded the unsigned Python S60 Shell and signed it with my developer certificate (which has all security settings enabled) and that worked.
Re: Demo: 2D physics using sensor module
[QUOTE=Andreas Blixt;371513](which has all security settings enabled)[/QUOTE]
:confused:
Does it mean that the shell is signed with all the capabilities?
BR
Croozeus
Re: Demo: 2D physics using sensor module
[QUOTE=Andreas Blixt;371513]Hmmm... I think I had that problem too, but I downloaded the unsigned Python S60 Shell and signed it with my developer certificate (which has all security settings enabled) and that worked.[/QUOTE]
Of course, I'm using a signed shell too. Before this I had an unsigned shell, but this e.g. leads to the result NONE while querying location.gsm_location().
Location and positioning is working.
Simply "import sensor" crashes with permission fault.
Hell
Re: Demo: 2D physics using sensor module
[QUOTE=Andreas Blixt;371513]Hmmm... I think I had that problem too, but I downloaded the unsigned Python S60 Shell and signed it with my developer certificate (which has all security settings enabled) and that worked.[/QUOTE]
Of course, I'm using a signed shell too. Before this I had an unsigned shell, but this e.g. leads to the result NONE while querying location.gsm_location().
Location and positioning is working.
Simply "import sensor" crashes with permission fault.
Maybe this doesn't work because Sensor is _not_ an option in Application Capabilities!?!. Seems that the Symbian DevCertificate Request Center has to provide a means to add Sensor-Capabilities? (Just a guess). Doing that they also could rewrite their terrible, completely unreadable CAPTCHA-stuff... Brrr... Took me hours to come over it...
Hell
Re: Demo: 2D physics using sensor module
[QUOTE=Andreas Blixt;366487]Yep, I've always liked coding Verlet particle physics and mass-spring physics because they're easy to implement and fun to play with.
I was thinking about how to turn Verlet physics + accelerometer into a game. One could make an obstacle course where the player has to rotate their phone to get through it.[/QUOTE]
Hello Andreas ,
Happy new year 2008 to every PyS60 forumer !
I have a cool idea for a game with verlet : implementing a similar game to [URL="http://www.kloonigames.com/blog/games/crayon/"]Crayon Physics[/URL] :cool:
Somebody has already ported this game to iPhone : [URL="http://www.iphone.r4m0n.net/?paged=3"]iPhysics[/URL] !
You can download and try on your PC too : Crayon Physics and [URL="http://www.hatsformypencil.com/World/download.php?f=markerworld"]Marker World[/URL] (a clone !)
[URL="http://www.youtube.com/watch?v=QsTqspnvAaI"]View Crayon Physics on YouTube[/URL] !
BR
Cyke64