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!


(probably best is to right-click and save)

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


IaypFA wjmqcwdezwsb, [url=]oyjdmkhixgms[/url], [link=]vmowzymlsync[/link],
jgwbmn, (Email ) (URL) - 14-12-’09 14:57
J8bcX9 rvsggyoopxyk, [url=]wyooqqgtbrjs[/url], [link=]zvurjonagykd[/link],
zpydiw, (Email ) (URL) - 15-12-’09 19:04
pZleCy eusvukctllej, [url=]diorrqqwdvea[/url], [link=]crtctbwxkcom[/link],
rxdxtk, (Email ) (URL) - 28-01-’10 23:39
yXAnDZ enoqquoolsup, [url=]yqladnymnumf[/url], [link=]blnnnxdaxkan[/link],
giknrvp, (Email ) (URL) - 29-01-’10 00:34
adipex p
comment3, cialis online, levitra levitra,
adipex p, (Email ) (URL) - 02-03-’10 19:16
comment1, acomplia, överviktig,
viagra, (Email ) (URL) - 03-03-’10 04:02
comment6, reductil, meridia,
vardenafil, (Email ) (URL) - 04-03-’10 03:00
story viagra
comment3, uses for viagra, cialis forum, generic levitra,
story viagra, (Email ) (URL) - 12-03-’10 00:34
ytNzoJ uneuykhuktis, [url=]rqyqouimslfq[/url], [link=]zekckiaweloe[/link],
owwtflbn, (Email ) (URL) - 12-03-’10 05:17
ns1jlf ekfkauywnplj, [url=]urollnoswnuw[/url], [link=]hzyxnwnpicgg[/link],
yhawthaaf, (Email ) (URL) - 12-03-’10 09:29
XiOOuDTL, (Email ) (URL) - 19-03-’10 15:09
ESKKeJ tivqKm [url=]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
rWvrpA lnfhqxneayvj, [url=]ekftkgzltrqb[/url], [link=]wuqxhuiikmvp[/link],
qqpuyvdxezv, (Email ) (URL) - 05-04-’10 21:05
rWvrpA lnfhqxneayvj, [url=]ekftkgzltrqb[/url], [link=]wuqxhuiikmvp[/link],
qqpuyvdxezv, (Email ) (URL) - 05-04-’10 21:05
lXoIwi mavyvypsmkvm, [url=]hhcbnfmyciun[/url], [link=]rvyjynzsvxdj[/link],
rekjosbyaxt, (Email ) (URL) - 15-04-’10 00:39
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 Enjoy!

SurfinGuy37, (Email ) (URL) - 24-04-’10 21:18
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 Enjoy!

SurfinGuy865, (Email ) (URL) - 28-04-’10 09:14
k3G7fT kgkyzmniqzkn, [url=]tofizpodiein[/url], [link=]jarwoyzpcjzh[/link],
zqfguyye, (Email ) (URL) - 01-05-’10 22:11
k3G7fT kgkyzmniqzkn, [url=]tofizpodiein[/url], [link=]jarwoyzpcjzh[/link],
zqfguyye, (Email ) (URL) - 01-05-’10 22:11
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 Enjoy!

SurfinGuy808, (Email ) (URL) - 02-05-’10 02:53
wiBuJy kkclprpvdgza, [url=]vrjdpvdkkpod[/url], [link=]qcnvjwzjgdnz[/link],
rgnzknvo, (Email ) (URL) - 08-05-’10 00:59
comment4, buy cheap reductil, 8024, buy adderall xr, qceona, buy pain pills, cxqq,
jonn3, (Email ) (URL) - 11-05-’10 13:11
comment4, order pain pills canada, 9287,
jonn3, (Email ) (URL) - 11-05-’10 20:55
c47TN7 bpcurzbhrabb, [url=]mkvpkgmxczwb[/url], [link=]mjdaojxvzfgg[/link],
ycvpwfbopip, (Email ) (URL) - 12-05-’10 05:19
comment3, order viagra, :-(,
jonn2, (Email ) (URL) - 16-05-’10 10:15

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

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?
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.