Page 1 of 1

Problem: Objects not colliding

Posted: Tue Jan 05, 2010 11:26 am
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...

Re: Problem: Objects not colliding

Posted: Tue Jan 05, 2010 1:20 pm
by viblo
Segments dont generate collisions with other line segments.

Re: Problem: Objects not colliding

Posted: Tue Jan 05, 2010 2:32 pm
by ignitedPotato
So I need to use poly?

Re: Problem: Objects not colliding

Posted: Tue Jan 05, 2010 4:40 pm
by viblo
ignitedPotato wrote:So I need to use poly?


Yes, exactly.

Re: Problem: Objects not colliding

Posted: Wed Jan 06, 2010 5:21 pm
by ignitedPotato
Thanks alot!
Now everything works fine :-)