Problem: Objects not colliding

Official forum for the Chipmunk2D Physics Library.
Post Reply
ignitedPotato
Posts: 7
Joined: Tue Jan 05, 2010 10:56 am
Contact:

Problem: Objects not colliding

Post by ignitedPotato »

Hi everyone,

I'm writing on a small programm that loads pictures from a folder and shows them in fullscreen. Now I want the pictures to be thrown around by the user like on photoshopexpress.com.
This is not my first chipmunk app but this time I'm facing a problem..

My testwindow is 1280x800.. the BoundingBoxes of the StaticShapes around the window look like this:
(l, b, r, t)
-10 , -5 , 0 , 805
-5 , -10 , 1285 , 0
1280 , -5 , 1290 , 805
-5 , 800 , 1285 , 810
My Chipmunk init:

Code: Select all

cpInitChipmunk();

cpBody *staticBody;
staticBody = cpBodyNew(INFINITY, INFINITY);

space = cpSpaceNew();
space->elasticIterations = 10;
space->gravity = cpv(00, 100);
cpShape *shape;

cpSpaceResizeStaticHash(space, 30.0f, 1000);
cpSpaceResizeActiveHash(space, 30.0f, 1000);
I'm initializing the staticShapes like this:

Code: Select all

shape = cpSegmentShapeNew(staticBody, cpv(-5,0), cpv(-5,hge->System_GetState(HGE_SCREENHEIGHT)), 5.0f);
shape->e = 1.0; shape->u = 1.0;
shape->collision_type = 0;
shape->layers = NOT_GRABABLE_MASK;
cpSpaceAddStaticShape(space, shape);
Now I've got a list that I fill with all bodys for the images:

Code: Select all

QList<cpBody*> picBodies; 
(It's QT... simple list)

Filling like this (shortened):

Code: Select all

for(int i = 0; i < picSprites.count(); ++i)
        {
            cpBody *tempBody;
            tempBody = cpBodyNew(1.0f, 1.0f);
            tempBody->p = cpv(posX, posY); //PosX and PosY hace automatically calculated values so the pictures fit into the Window

            picBodies << tempBody;

            // Now the shape from above
            shape = cpSegmentShapeNew(cpSpaceAddBody(space, picBodies.last()), cpv(a1,a2), cpv(b1,b2), thick); //a1,a2,b1,b2 and thick are also automatically calculated

            shape->e = 0.8; shape->u = 0.3;
            shape->collision_type = 1;
            cpSpaceAddShape(space, shape);
        }
If I load a sample picture.. it's BoundingBox looks like this for example:
20 , 20 , 129.8 , 197.3

Anyways.. the picture flys through the staticShapes..
I've searched about 5h for the mistake but I didn't find any..

Have you got any ideas?

I can also post the full code with the automation code.. it's just that it contains QT stuff...
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: Problem: Objects not colliding

Post by viblo »

Segments dont generate collisions with other line segments.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
ignitedPotato
Posts: 7
Joined: Tue Jan 05, 2010 10:56 am
Contact:

Re: Problem: Objects not colliding

Post by ignitedPotato »

So I need to use poly?
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: Problem: Objects not colliding

Post by viblo »

ignitedPotato wrote:So I need to use poly?
Yes, exactly.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
ignitedPotato
Posts: 7
Joined: Tue Jan 05, 2010 10:56 am
Contact:

Re: Problem: Objects not colliding

Post by ignitedPotato »

Thanks alot!
Now everything works fine :-)
Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests