Hi,
I have this problem with chipmunk:
It doesn't seem to take into account polygon shapes added to static objects. I have created a rectangle using cpPolyShapeNew, and added a circle object to my scene. The problem is that it doesn't seem to care at all about the rectangle. However when I add a static line shape, then in this case everything works and collision is detected.
The other issue with polygonal shapes is when adding a rectangle using cpPolyShapeNew to dynamic objects, in this case collision/physics is very badly handled and the rectangle penetrates the object with some modification to the angles, but it ends passing through!
All these simulation were done with (e=0; u = 0), (e = 1; u = 1), (e=0, u=1)
Is there something wrong, or is it simply that polygon shapes are not fully implemented ?
Regards
Polygon shapes as static objects collision fails
-
- Posts: 3
- Joined: Sat Feb 20, 2010 8:51 am
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Polygon shapes as static objects collision fails
What version of chipmunk are you using? It sounds like you have a bad winding to me. Newer versions of chipmunk thow errors if you try to use a bad winding.
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: 3
- Joined: Sat Feb 20, 2010 8:51 am
- Contact:
Re: Polygon shapes as static objects collision fails
I am using SVN version (latest), what is bad winding ? If (CW/CCW) then I tried both and didn't work either
here is the code for init and step
here is the code for init and step
Code: Select all
void init_game()
{
g_space = cpSpaceNew();
g_space->iterations = 10;
g_space->gravity = cpv(0, 1000);
g_border = cpBodyNew(INFINITY, INFINITY);
g_border->p = cpv(320, 240);
cpVect pts[4] = {
cpv(-300, -200),
cpv(300, -200),
cpv(300, 200),
cpv(-300, 200)
};
// level border
cpShape* border = cpSpaceAddStaticShape(g_space, cpPolyShapeNew(g_border, 4, pts, cpvzero));
border->e = 0.0; border->u = 1.0; border->collision_type = 0;
/*border = cpSpaceAddStaticShape(g_space, shape_line(g_border, vec2(40, 440), vec2(600, 440)));
border->e = 0.0; border->u = 1.0; border->collision_type = 0;
*/
border = cpSpaceAddStaticShape(g_space, cpCircleShapeNew(g_border, 30, cpv(0, 100)));
border->e = 0.0; border->u = 1.0; border->collision_type = 0;
cpBody * player = cpSpaceAddBody(g_space, cpBodyNew(10.0, INFINITY));
player->p = cpv(320, 240);
player->a = -M_PI / 4;
cpShape *p_shape = cpCircleShapeNew(player, 18, cpvzero);
p_shape->e = 0.0; p_shape->u = 1.0; p_shape->collision_type = 0;
cpBody *zonk_body = cpSpaceAddBody(g_space, cpBodyNew(100, 100));
zonk_body->p = cpv(100, 100);
zonk_body->a = 0;
cpShape *z_shape = cpCircleShapeNew(zonk_body, 18, cpvzero);
z_shape->e = 0.0; z_shape->u = 1.0; z_shape->collision_type = 0;
cpSpaceAddShape(g_space, z_shape);
// new zonk object
zonk_body = cpSpaceAddBody(g_space, cpBodyNew(100, 100));
zonk_body->p = cpv(320, 100);
zonk_body->a = 0.1;
cpVect verts[4] = {
cpv(-10, -10),
cpv(10, -10),
cpv(10, 10),
cpv(-10, 10)
};
z_shape = cpPolyShapeNew(zonk_body, 4, verts, cpvzero);
z_shape->e = 0.0; z_shape->u = 1.0; z_shape->collision_type = 0;
cpSpaceAddShape(g_space, z_shape);
cpSpaceAddShape(g_space, p_shape);
}
void update_game()
{
//for( int i = 0; i < 3; i++ )
cpSpaceStep(g_space, 1.0/190.0);
}
-
- Posts: 3
- Joined: Sat Feb 20, 2010 8:51 am
- Contact:
Re: Polygon shapes as static objects collision fails
Finally got the problem solved. What I have been missing is indeed the winding. Seems like chipmunk consider the interior of a convex polygon completely solid, so it seems that I cannot place objects inside convex
Is there any way to do that (placing objects inside convex polygons) ?
If we have to limit to line segments, is the collision between segments handled when the segments are dynamic ?
Regards
Is there any way to do that (placing objects inside convex polygons) ?
If we have to limit to line segments, is the collision between segments handled when the segments are dynamic ?
Regards
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Polygon shapes as static objects collision fails
The only limitation with segment shapes is that they don't yet collide with other segment shapes. If you want to make a hollow shape, it works fine to make it out of segments. If you need the outside to collide with other segments, you'll have to make a separate inside and outside shape and use layers or groups to let you put objects inside of it.
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/
Who is online
Users browsing this forum: No registered users and 3 guests