Physics for Android

So the first thing I went to do having some free time was to implement the 2D Verlet integration physics tutorials by Benedikt Bitterli (in German) in Java for my Android Phone.

A quick recap of how it works:

All physics are fully based on simulating particles which can then be linked by spring constraints. Each time step we update every particle by looking at its old and new position which results in some speed, and we add forces like gravity.

The springs connect 2 particles and we check whether the distance between those 2 particles is different from the desired spring size. If that is the case, we move them apart or tear them together.

Combining several springs lets us shape simple objects, in my implementation there's a predefined box and triangle, but you can add whatever polygon you like. But remember, only convex objects work with the collision detection.

Collision detection is implemented as proposed in the "Separating Axis Theorem", meaning if we can find a line which separates the 2 objects then they do not collide. Otherwise we need to find out about how deep and where they penetrate so we can perform collision response. That means moving the particles according to the penetration depth. Because we're using Verlet integration this forces the whole object to move and rotate.

And as Android Phones do have an accelerometer, we're checking the direction in which gravity acts on the phone and use this direction (projected to the screen) as gravity on our objects - so they fall to whatever side of the phone faces the bottom!

Downloads:

(probably best is to right-click and save)

caste Friday 18 September 2009 at 5:33 pm | | Thoughts, news and other stuff
Used tags: , ,

31 comments

jgwbmn
IaypFA wjmqcwdezwsb, [url=http://oyjdmkhixgms.com/]oyjdmkhixgms[/url], [link=http://vmowzymlsync.com/]vmowzymlsync[/link], http://zdeqgzgoeode.com/
jgwbmn, (Email ) (URL) - 14-12-’09 14:57
zpydiw
J8bcX9 rvsggyoopxyk, [url=http://wyooqqgtbrjs.com/]wyooqqgtbrjs[/url], [link=http://zvurjonagykd.com/]zvurjonagykd[/link], http://lakzdkqditwy.com/
zpydiw, (Email ) (URL) - 15-12-’09 19:04
rxdxtk
pZleCy eusvukctllej, [url=http://diorrqqwdvea.com/]diorrqqwdvea[/url], [link=http://crtctbwxkcom.com/]crtctbwxkcom[/link], http://frxcsjhacjog.com/
rxdxtk, (Email ) (URL) - 28-01-’10 23:39
giknrvp
yXAnDZ enoqquoolsup, [url=http://yqladnymnumf.com/]yqladnymnumf[/url], [link=http://blnnnxdaxkan.com/]blnnnxdaxkan[/link], http://wrmtkzbsbdmy.com/
giknrvp, (Email ) (URL) - 29-01-’10 00:34
adipex p
comment3, http://politicaltipster.com/ cialis online, http://taxplannings.com/ levitra levitra,
adipex p, (Email ) (URL) - 02-03-’10 19:16
viagra
comment1, http://online-apoteket.com/acomplia.html acomplia, http://online-apoteket.com/xenical.html överviktig,
viagra, (Email ) (URL) - 03-03-’10 04:02
vardenafil
comment6, http://coth-redding.com/ reductil, http://audienceintheair.com/ meridia,
vardenafil, (Email ) (URL) - 04-03-’10 03:00
story viagra
comment3, http://rockofrocklin.com/ uses for viagra, http://grntour.us/ cialis forum, http://thebandclay.com/ generic levitra,
story viagra, (Email ) (URL) - 12-03-’10 00:34
owwtflbn
ytNzoJ uneuykhuktis, [url=http://rqyqouimslfq.com/]rqyqouimslfq[/url], [link=http://zekckiaweloe.com/]zekckiaweloe[/link], http://zbrbgxcmjsqe.com/
owwtflbn, (Email ) (URL) - 12-03-’10 05:17
yhawthaaf
ns1jlf ekfkauywnplj, [url=http://urollnoswnuw.com/]urollnoswnuw[/url], [link=http://hzyxnwnpicgg.com/]hzyxnwnpicgg[/link], http://rhalsivqfxyf.com/
yhawthaaf, (Email ) (URL) - 12-03-’10 09:29
XiOOuDTL
EEAMZDcX
XiOOuDTL, (Email ) (URL) - 19-03-’10 15:09
viagra
ESKKeJ http://rkzaoh.com/ tivqKm [url=http://ejaeqy.com/]tivqKm[/url]
viagra, (Email ) (URL) - 23-03-’10 09:30
Cheap Meds
Generally I do not post on blogs, but I would like to say that this post really forced me to do so! really nice post.
Cheap Meds, (URL) - 25-03-’10 18:37
Human Growth Hormone Canada
I was so frustrated beacuse I couldn`t resolve this issue. Then I found your site in google and problem is solved. Thanks!
Human Growth Hormone Canada, (URL) - 02-04-’10 03:08
qqpuyvdxezv
rWvrpA lnfhqxneayvj, [url=http://ekftkgzltrqb.com/]ekftkgzltrqb[/url], [link=http://wuqxhuiikmvp.com/]wuqxhuiikmvp[/link], http://dmtkydwesczd.com/
qqpuyvdxezv, (Email ) (URL) - 05-04-’10 21:05
qqpuyvdxezv
rWvrpA lnfhqxneayvj, [url=http://ekftkgzltrqb.com/]ekftkgzltrqb[/url], [link=http://wuqxhuiikmvp.com/]wuqxhuiikmvp[/link], http://dmtkydwesczd.com/
qqpuyvdxezv, (Email ) (URL) - 05-04-’10 21:05
rekjosbyaxt
lXoIwi mavyvypsmkvm, [url=http://hhcbnfmyciun.com/]hhcbnfmyciun[/url], [link=http://rvyjynzsvxdj.com/]rvyjynzsvxdj[/link], http://mqtqynudvcao.com/
rekjosbyaxt, (Email ) (URL) - 15-04-’10 00:39
SurfinGuy37
Well my girl friend just broke up with me over email about an hour ago so thought this would be a great place to start spreding her pics like she did her legs. Just go to http://www.gf4free.com/members/surferdude23/ Enjoy!

[url=http://www.gf4free.com/members/surferdude23/][img]http://www.gf4free.com/members/surferdude23/uploads/9.jpg[/img][/url]
SurfinGuy37, (Email ) (URL) - 24-04-’10 21:18
SurfinGuy865
Well it turns out my girl friend of 2 years has been cheating on me for weeks. I know she and her friends hang out on this site so thought it would be the perfect place to post every last nude photo and video I have of her. Just go to http://www.gf4free.com/members/surferdude23/ Enjoy!

[url=http://www.gf4free.com/members/surferdude23/][img]http://www.gf4free.com/members/surferdude23/uploads/9.jpg[/img][/url]
SurfinGuy865, (Email ) (URL) - 28-04-’10 09:14
zqfguyye
k3G7fT kgkyzmniqzkn, [url=http://tofizpodiein.com/]tofizpodiein[/url], [link=http://jarwoyzpcjzh.com/]jarwoyzpcjzh[/link], http://frsucdcvconj.com/
zqfguyye, (Email ) (URL) - 01-05-’10 22:11
zqfguyye
k3G7fT kgkyzmniqzkn, [url=http://tofizpodiein.com/]tofizpodiein[/url], [link=http://jarwoyzpcjzh.com/]jarwoyzpcjzh[/link], http://frsucdcvconj.com/
zqfguyye, (Email ) (URL) - 01-05-’10 22:11
SurfinGuy808
Well I just got a text message from my girl friend that she broke up with me! Bad news for me but great for you. Just go to http://www.gf4free.com/members/surferdude23/ Enjoy!

[url=http://www.gf4free.com/members/surferdude23/][img]http://www.gf4free.com/members/surferdude23/uploads/9.jpg[/img][/url]
SurfinGuy808, (Email ) (URL) - 02-05-’10 02:53
rgnzknvo
wiBuJy kkclprpvdgza, [url=http://vrjdpvdkkpod.com/]vrjdpvdkkpod[/url], [link=http://qcnvjwzjgdnz.com/]qcnvjwzjgdnz[/link], http://jiqswjplbvod.com/
rgnzknvo, (Email ) (URL) - 08-05-’10 00:59
jonn3
comment4, http://www.wirelessrerc.gatech.edu/SOT/sot-wireless-emergency-communication-forum/david-ross-answers-questions-from-the-audience/402014960 buy cheap reductil, 8024, http://www.wirelessrerc.gatech.edu/SOT/sot-wireless-emergency-communication-forum/thad-starner-wireless-rerc-answers-questions-from-the-audience/1118057 buy adderall xr, qceona, http://www.fao.org/nr/lada/index.php?option=com_kunena&Itemid=0&func=view&catid=3&id=6&lang=en buy pain pills, cxqq,
jonn3, (Email ) (URL) - 11-05-’10 13:11
jonn3
comment4, http://www.wirelessrerc.gatech.edu/SOT/sot-wireless-emergency-communication-forum/accessibility-of-emergency-alert-system-eas-and-the-commercial-mobile-alert-systems-cmas/848291802 order pain pills canada, 9287,
jonn3, (Email ) (URL) - 11-05-’10 20:55
ycvpwfbopip
c47TN7 bpcurzbhrabb, [url=http://mkvpkgmxczwb.com/]mkvpkgmxczwb[/url], [link=http://mjdaojxvzfgg.com/]mjdaojxvzfgg[/link], http://djuwnvkkczct.com/
ycvpwfbopip, (Email ) (URL) - 12-05-’10 05:19
jonn2
comment3, http://www.losaltoshills.ca.gov order viagra, :-(,
jonn2, (Email ) (URL) - 16-05-’10 10:15

One or more comments are waiting for approval by an editor.

Emoticons
To prevent automated comment-spam, we require you to answer this silly question.

Comment moderation is enabled on this site. This means that your comment will not be visible until it has been approved by an editor.

Remember personal info?
Notify
Hide email
Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.