Shape Query

Official forum for the Chipmunk2D Physics Library.
ShiftZ
Posts: 114
Joined: Sat Mar 07, 2009 7:23 am
Contact:

Re: Shape Query

Post by ShiftZ »

Is there a case where layers are insufficient?
Why layers? Why not groups? For example, all sensors include in one sensor-group, and then query with sensor-group argument (this will exclude collisions with sensor-group right?)

It's not a right way when sensor uses it's own layer to sens. Sensor must sens other layers.
There are only 32 layers, each sensor type will require a whole layer, otherwise it would be mess with shape layers, and who sens who.
ShiftZ
Posts: 114
Joined: Sat Mar 07, 2009 7:23 am
Contact:

Re: Shape Query

Post by ShiftZ »

Well, sensor-group works well. Anyway group property for sensor shape is usless for anything else.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Shape Query

Post by slembcke »

Hrm. I see what you mean. In the demo application I use one of the layer bits to mean a shape is queryable, but this does not work in general as all queryable objects will always collide. I guess I hadn't thought this through in a broader sense.

So...

You are probably right that it's probably pretty rare to want sensors returned from cpSpace*QueryFirst(). I'll change it so that it skips them. In the case where you would actually want to return a sensor from the cpSpace*QueryFirst(), it's a simple matter of copy/pasting a few lines of code from cpSpace.c. I guess I'll just leave that as an exercise to the user.

Until then I guess you have a workaround.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ShiftZ
Posts: 114
Joined: Sat Mar 07, 2009 7:23 am
Contact:

Re: Shape Query

Post by ShiftZ »

slembcke
i know you have planned to include shape query interface in 5.3.3. Is it still coming?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Shape Query

Post by slembcke »

Oh, It's done actually. I just forgot to add it to the documentation. Whoops :oops:
http://code.google.com/p/chipmunk-physi ... ?r=677#187

Code: Select all

typedef void (*cpSpaceShapeQueryFunc)(cpShape *shape, cpContactPointSet *points, void *data);
cpBool cpSpaceShapeQuery(cpSpace *space, cpShape *shape, cpSpaceShapeQueryFunc func, void *data);
cpSpaceShapeQuery() queries the given shape against the space returning true if there are any overlapping shapes and calling the callback for each one. You can pass NULL as the query function if you only need the boolean value. The cpContactPointSet structure is fairly new, but is documented in the cpArbiter section of the documentation.

The shape you pass to cpSpaceShapeQuery() needs to be fully set up and attached to a body. You can just allocate the shape and body on the stack if you just want to make a quick shape query:

Code: Select all

// Must use the specific shape type here so enough stack space is allocated
cpCircleShape circle;
cpCircleShapeInit(&circle, &space.staticBody, 4.0f, cpv(offsetX, offsetY));
circle.shape.layers = layers;
circle.shape.group = group;

cpSpaceShapeQuery(space, (cpShape *)&circle, queryCallback, callbackData);
It's a little messy to do so I'm going to make functions like cpSpaceCircleQuery(), etc that hide this extra work. They just haven't gotten written yet.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ShiftZ
Posts: 114
Joined: Sat Mar 07, 2009 7:23 am
Contact:

Re: Shape Query

Post by ShiftZ »

Too late. i have found a better soultion.
Actually cpSpaceHashQuery is pretty usefull for game mechanics in very different aspects.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests