General implementation question.

Official forum for the Chipmunk2D Physics Library.
Post Reply
joshcryer
Posts: 18
Joined: Wed Sep 26, 2007 8:19 pm
Contact:

General implementation question.

Post by joshcryer »

Hey guys, everything works very well. :D

My code is now condensed by 50% as all my collision detection stuff is out the window. (Of course I understand that Chipmunk itself actually makes the code bigger, but it's not my code, so I don't count it!)

However, I wanted to know if this was a correct way of going about things.

I am using a struct array to store body information (mass, velocity, force, etc), in my own Euler integrated gravity system.

So something like this.

body mybody[numbodies];

mybody.vx += foox; mybody.vy += fooy;

(where foo is part the gravity equation)

What I've done is simply added a cpBody and cpShape pointer to this struct. Then what I do is something like this after running my Eular integrated method:

mybody.mycpBody->v.x = mybody.vx; mybody.mycpBody->v.y = mybody.vy;

I run cpSpaceStep.

Then I push the values back: mybody.vx = mybody.mycpBody->v.x; mybody.vy = mybody.mycpBody->v.y;

Then run the calculation again.

It works great! :) (At least as good as what I had before.) But I'm wondering if there are any caveats I should be worrying about. Also a bit of code cleanup can probably be in order. I think (though I'm not sure) I could run my integration method right on the cpBody (ie, mybody[i].cpBody->v.x += foovx; where foovx is the integrated gravity equation).

Thanks for any input (code style is welcome too of course).
lucas
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am
Contact:

Re: General implementation question.

Post by lucas »

What's wrong with Chipmunk's system (really, tell me, I don't know)?
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
joshcryer
Posts: 18
Joined: Wed Sep 26, 2007 8:19 pm
Contact:

Re: General implementation question.

Post by joshcryer »

Hmm? I don't see anything wrong with it at all. I'm just asking if I'm doing things 'right.' I think I should do UpdateVelocity and UpdatePosition somewhere.

The thing is the manual talks about not using cpSpace if I'm doing my own integrating, but I don't see how to do that without losing the bouncing and stuff. I don't need just collision detection (that's easy!), I also need my objects to bounce around. :)
Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests