Is getting the width of a cpBody possible? I'm tearing out my hair trying to figure this out.
Get the width of a cpBody
(9 posts) (3 voices)-
Posted 5 months ago #
-
cpBody doesn't have width... Only shapes attached to it may have similar properties...
Posted 5 months ago # -
That's about what I figured. I think I've coded myself into a hole.
Any way to get the attached shape from the cpbody?
Posted 5 months ago # -
Actually you're attaching a body to a shape. So shape has reference to a body. I was little unclear on that in first post...
So everything about ChipMunk simulation is on shapes doing this and doing that. Bodies are only giving physical properties to the shapes, like mass, moment, etc...
Check ChipMunk documentation for more info:
http://code.google.com/p/chipmunk-physics/wiki/Documentation?tm=6Posted 5 months ago # -
you could do this to store the shape in the body:
body->data = shape;and then retrieve it like this:
cpShape* shape = (cpShape*)body->data;Posted 5 months ago # -
That's perfect, thanks for your help.
I do have a question on where you figured that out? Is there better documentation out there somewhere?
Anyways, I wish I could tip both of you for your help!
Posted 5 months ago # -
Hey, although tip for using body->data is OK, it's really not something you should do. Shape already has reference to a body, so why would you cross-reference your body to a shape again? Every chipmunk function that browse through the elements of the simulation, always does it with shapes, e.g. cpSpaceHashEach(space->activeShapes, ....)
So, better look for examples and read documentation. You'll get better understanding of the whole physics simulation model...
Posted 5 months ago # -
I really like the physics model actually. I hacked my way through the http://morethanmachine.com/macdev/?tag=cocos2d and he creates a series of bullet objects that are only aware of the body. At least...as far as I can tell...
I just wanted to be able to use the w, h as well for checking to see if things were heading offstage.
yawn...excuse my ramblings...
Posted 5 months ago # -
Just skimming that article you posted, it'd be easy enough to change the code to use shapes instead of bodies.
The documentation on the google code page as well as looking at the definition of the structs is all I used for learning.
Posted 5 months ago #
Reply
You must log in to post.