Actionscript/Flash Convertion

Official forum for the Chipmunk2D Physics Library.
Post Reply
rje
Posts: 9
Joined: Tue Jan 08, 2008 4:54 pm
Contact:

Actionscript/Flash Convertion

Post by rje »

First - great library. I spent some time trying to understand Box2d - then gave up, and found Chipmunk much easier to figure out. Its been a while since I looked at C, so to fully understand it I'm converting it to Actionscript 3 (its a bit like Java if your not familiar with the language).

I've got a basic demo running:
- poly/poly collisions
- contact point & arbiters
- rigid body dynamics
- basic engine

I've fully OO'ed it - once its working I'll optimize it for Actionscript (a fun job, that will i part require manual inlining of all vector operations :shock: )

A very very (very) basic demo of this is here: http://home.planet.nl/~borst595/pEngine.html

Next task - get that spacial hashing working.....
Last edited by rje on Thu Jan 10, 2008 4:32 pm, edited 1 time in total.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Actionscript/Flash Convertion

Post by slembcke »

Very cool! Will be cool to see what you can do with it.
(a fun job, that will i part require manual inlining of all vector operations :shock: )
Fun. Yes... :P
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
rje
Posts: 9
Joined: Tue Jan 08, 2008 4:54 pm
Contact:

Re: Actionscript/Flash Convertion

Post by rje »

Thanks. I'm looking forward to seeing how fast/usable I can make it. Have you any thoughts on ports? you want me to maintain a svn repository?

I'm obviously going to be looking quite deep into the code. If I notice anything I think can be optimized, do you want me to let you know? for example...

- you loop over the vertices twice in cpPolyShapeCacheData (once to transform the verticies, the second to compute the BB). You could just compute the BB as you transform the vertices.
- when you test for a point inside a polygon, you could test it against the target BB first for a fast out.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Actionscript/Flash Convertion

Post by slembcke »

Regardless of what I think, you should have your code in some sort of version control. :p

Of course I'd be open to suggestions. (even more so if it comes with a patch ;))

Good calls on the poly stuff. I added notes in the source to try those out. I'll have to do some profiling.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
rje
Posts: 9
Joined: Tue Jan 08, 2008 4:54 pm
Contact:

Re: Actionscript/Flash Convertion

Post by rje »

I think I'm missing something. When you integrate the forces on the static body (infinite mass therefore i_mass=0) to update the velocity you use:

body->v = cpvadd(cpvmult(body->v, damping), cpvmult(cpvadd(gravity, cpvmult(body->f, body->m_inv)), dt));

This stops gravity being scaled by i_mass=0 therefore moves the body....?

I understand why you dont want this to happen most of the time because gravity is not affected by the mass of the object, however I dont want my static body to move. I have a work around of course but I'm not sure if its screwing up something else...
rje
Posts: 9
Joined: Tue Jan 08, 2008 4:54 pm
Contact:

Re: Actionscript/Flash Convertion

Post by rje »

I get it.... you don't add the static body to the simulated space.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Actionscript/Flash Convertion

Post by slembcke »

Yep. That's the key.

I've implemented integration callbacks for bodies now that allow you set per body integration rules. That way you'll be able to add static bodies to the space and provide a function that doesn't apply gravity to them. This will let you do other fancy things with static bodies as well without needing to add code to the update loop.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
rje
Posts: 9
Joined: Tue Jan 08, 2008 4:54 pm
Contact:

Re: Actionscript/Flash Convertion

Post by rje »

So, a new demo is up at the same page:

http://home.planet.nl/~borst595/pEngine.html

There is no broad phase here, in fact the code is about as un-optimized as it can be. Left click to shoot a block into the scene (fires towards the mouse position).

I HIGHLY recommend you upgrade to the most recent Flash player (you can check it here http://www.adobe.com/products/flash/about/ you want version 9,0,115,0
rje
Posts: 9
Joined: Tue Jan 08, 2008 4:54 pm
Contact:

Re: Actionscript/Flash Convertion

Post by rje »

So, the conversion is mostly done - I have to get the joints working, but before that I might generalize the constraint system.

The code is available at http://code.google.com/p/glaze/

I undertook this as part of a larger 2D game engine project for Actionsctipt 3, hence the name change, where applicable all copyrights have been retained and I've tried to point people back to this, the original project as much as possible.

There was obviously some major re-factoring going on here:
- Almost all arrays were replaced with linked lists
- All vector math was inlined
- Some of the collision system was reworked
- The broad-phase is a kind-of sweep/sort instead of the spacial hash

Demos can be found at http://home.planet.nl/~borst595/glaze.html
Post Reply

Who is online

Users browsing this forum: Heise IT-Markt [Crawler] and 7 guests