[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - Missing collisions?

Missing collisions?

Official forum for the .

Missing collisions?

Postby juanii » Tue Mar 31, 2009 10:43 am

Hello. I'm new to Chipmunk and full of doubts about how to use it :)
Though this is a simple simulation, it seems to be failing. It's supposed to be viewed from top (this is why gravity is zero). The vehicle goes upward and should collide with the sloped wall above it.
Sorry for the lenght of the code, but I didn't want to miss anything.

// Create a space and set its properties
cpSpace *space = cpSpaceNew();
space->iterations = space->elasticIterations = 10;
space->gravity = cpv(0, 0);
space->damping = 0.2f;

// A sloped wall "above" the vehicle
cpBody *wall = cpBodyNew(INFINITY, INFINITY);
cpShape *wallShape = cpSegmentShapeNew(wall, cpv(170, 1081), cpv(278, 1137), 0);
wallShape->e = wallShape->u = 1.0f;
cpSpaceAddStaticShape(space, wallShape);

// The vehicle has a somehow "sharp" tip but it fails even if it's rectangular
cpVect vehicleVerts[6] = { cpv(-15, 5), cpv(-15, -5), cpv(8, -5), cpv(15, -3), cpv(15, 3), cpv(8, 5) };
cpBody *vehicle = cpBodyNew(10.0f, cpMomentForPoly(10.0f, 6, vehicleVerts, cpvzero));
vehicle->p = cpv(196, 499);
cpBodySetAngle(vehicle, M_PI_2);
cpSpaceAddBody(space, vehicle);

cpShape *vehicleShape = cpPolyShapeNew(vehicle, 6, vehicleVerts, cpvzero);
vehicleShape->e = 1.0f;
vehicleShape->u = 1.5f;
cpSpaceAddShape(space, vehicleShape);


Now we start moving.This event fires 40 times per second (t = 1/40.0f)

// Give the vehicle a push upwards
cpVect impulse = cpv(200, 0);
float tSim = t / 4.0;

// Rotation here doesn't play anything but to give the impulse the upward direction
cpBodyApplyImpulse(vehicle, cpvrotate(impulse, vehicle->a), cpvrotate(cpv(8, 0), vehicle->a));
for (int i = 0; i < 4; i++)
cpSpaceStep(space, tSim);

// update screen


The problem is the vehicle passes _through_ the sloped wall... no matter how little I make tSim, the most I'm getting is a slight change in the vehicle angle, but it still goes through the wall. I tried giving the vehicle a circular shape and it started to work fine, but well... the fact is it _isn't_ a circle :)

Any help on this will be very appreciated.

Regards
juanii
 
Posts: 2
Joined: Tue Mar 31, 2009 10:06 am

Re: Missing collisions?

Postby maximile » Tue Mar 31, 2009 11:53 am

Have you tried reversing the order of the vertices on the vehicle?
maximile
 
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK

Re: Missing collisions?

Postby juanii » Tue Mar 31, 2009 12:27 pm

Do you mean defining it clockwise instead of counter clockwise? No, I didn't... but I've just done it and the first run was successful! :o
Is there a way to know how to define the polygons? is it _always_ clockwise?

Thank you very much!
juanii
 
Posts: 2
Joined: Tue Mar 31, 2009 10:06 am

Re: Missing collisions?

Postby slembcke » Tue Mar 31, 2009 2:25 pm

So this has come up sooooo many times. Not that I blame people for missing it, but I think maybe I should add an assertion to check for concavity and reversed winding. At least then it would fail hard and tell you why.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Missing collisions?

Postby maximile » Tue Mar 31, 2009 6:46 pm

Sounds like a very good idea. I've been playing with Chipmunk for ages and it's still usually trial and error for me whether I get the winding right.

juanii: It's always the same. Counter-clockwise or clockwise depends on how your axes are set up.
maximile
 
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 3 guests

cron