question
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: question
Are you doing something like this?
A shape *must* be attached to a body before it can be added to a space. You either need to pass the body to the cp*ShapeNew() function, or set it afterwards using cpShapeSetBody() function.
Why do you want the body to be NULL?
Code: Select all
cpShape *shape = cpCircleShapeNew(NULL, 5.0, cpvzero);
Why do you want the body to be NULL?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 8
- Joined: Thu Mar 14, 2013 1:21 pm
- Contact:
Re: question
Because you say "For shapes used for queries that aren’t attached to bodies, you can also use cpShapeUpdate()" and "You can either create a body/shape pair before querying, or you can create a shape passing NULL for the body and position the shape using cpShapeUpdate() to set the position and rotation of the shape.".slembcke wrote: Why do you want the body to be NULL?
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: question
The only function a shape with a NULL body has is to be used with queries. If you want to add it to a space and simulate it, you must attach it to a body first. You might want to do something like this perhaps:
If you are looking for a way to control a shape without it being attached to a body, you cannot do that. For that you need to use a rogue body. http://chipmunk-physics.net/release/Chi ... ougeStatic
Code: Select all
cpShape *shape = cpShape*New(...);
cpShapeUpdate(shape, position, rotation);
cpBool colliding = cpSpaceShapeQuery(space, shape, NULL, NULL);
if(!colliding){
cpBody *body = cpBodyNew(...);
cpBodySetPosition(body, position);
cpbodySetAngle(body, rotation);
cpSpaceAddBody(space, body);
cpShapeSetBody(shape, body);
cpSpaceAddShape(space, shape);
} else {
cpShapeFree(shape);
}
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 8
- Joined: Thu Mar 14, 2013 1:21 pm
- Contact:
Re: question
Thanks. I got it.
-
- Posts: 1
- Joined: Tue May 06, 2014 6:43 am
- Contact:
Re: question
And by that you mean its only function is as the query shape, right? I.e. I can't use cpShapeUpdate to place a whole bunch of NULL body shapes and then cpSpaceShapeQuery them with another NULL body shape? (I tried and it didn't seem to work.)slembcke wrote:The only function a shape with a NULL body has is to be used with queries.
In my contraption building game I have a set of shapes used for the physics simulation and a different set of shapes used for collision checking when placing new building elements. I can think of two alternatives to NULL body shapes:
1. Add the non-physics shapes to the same space, but set them as sensor shapes so they don't affect physics collisions.
2. Add the non-physics shapes to a different space, which is never stepped, and manually position and reindex them each frame (or at least each frame that a shape query needs to be performed).
Which is better for performance? Or is there an even better third option?
Who is online
Users browsing this forum: Bing [Bot] and 23 guests