Weird behaviour in a simple code...
Posted: Sat Jun 26, 2010 6:29 am
Hi !
While I'm nearly in holidays, I've tried again this library. I managed to install the library, but I've got a problem when testing it :S .
I just created 4 static shapes in order to set limits to my other bodies. Then I created a triangle and its behaviour is very strange (it sometimes strangely bounces, translates whereas it shouldn't and always finishes by crossing the limits I set...) so I certainly forgot something important in the code.
I also tried to create a second triangle, but even if I set a higher mass to it, it falls at the same velocity than the 1st one :S .
So, let you see my code :
Creation of objects :
And I call cpSpaceStep in my loop.
I don't think the problem comes from the library so I certainly forgot something or such.
Moreover, maybe I don't correctly update the rotation of the objet when I display it (Particularly, I don't know if the angle got by cpBodyGetAngle is clockwise and where the origin is)
Anyone could help me, please ?
Thank you in advance
PS : I'm french, sorry for the possible mistakes...
While I'm nearly in holidays, I've tried again this library. I managed to install the library, but I've got a problem when testing it :S .
I just created 4 static shapes in order to set limits to my other bodies. Then I created a triangle and its behaviour is very strange (it sometimes strangely bounces, translates whereas it shouldn't and always finishes by crossing the limits I set...) so I certainly forgot something important in the code.
I also tried to create a second triangle, but even if I set a higher mass to it, it falls at the same velocity than the 1st one :S .
So, let you see my code :
Creation of objects :
Code: Select all
cpInitChipmunk();
cpSpace* espace = cpSpaceNew();
espace->iterations = 10;
espace->gravity = cpv(0, 50);
// creating a static body
cpBody* corpsStatique = cpBodyNew(INFINITY, INFINITY);
// Creating limits
cpShape *bord1 = cpSegmentShapeNew(corpsStatique, cpv(0,0), cpv(800,0), 0.0f);
cpShape *bord2 = cpSegmentShapeNew(corpsStatique, cpv(800,0), cpv(800,600), 0.0f);
cpShape *bord3 = cpSegmentShapeNew(corpsStatique, cpv(800,600), cpv(0,600), 0.0f);
cpShape *bord4 = cpSegmentShapeNew(corpsStatique, cpv(0,600), cpv(0,0), 0.0f);
bord1->e = 0.9f; bord1->u = 1.0f;
bord2->e = 0.9f; bord2->u = 1.0f;
bord3->e = 0.9f; bord3->u = 1.0f;
bord4->e = 0.9f; bord4->u = 1.0f;
// Adding them to the space
cpSpaceAddStaticShape(espace, bord1);
cpSpaceAddStaticShape(espace, bord2);
cpSpaceAddStaticShape(espace, bord3);
cpSpaceAddStaticShape(espace, bord4);
// Creating a triangle
int num = 3;
cpVect points[] = {
cpv(0,-40),
cpv(-10, 40),
cpv( 10, 40)
};
cpBody *vaisseau = cpBodyNew(5.f, cpMomentForPoly(5.f, num, points, cpvzero));
vaisseau->p = cpv(80, 80);
cpSpaceAddBody(espace, vaisseau);
cpShape* forme = cpPolyShapeNew(vaisseau, num, points, cpvzero);
forme->e = 0.3f; forme->u = 0.8f;
cpSpaceAddShape(espace, forme);
sf::Shape triangle;
for(unsigned int i=0; i<num; i++)
{
triangle.AddPoint(points[i].x, points[i].y, sf::Color::Red);
}
triangle.SetPosition(80, 80);
cpBody *vaisseau2 = cpBodyNew(30.f, cpMomentForPoly(30.f, num, points, cpvzero));
vaisseau2->p = cpv(80, 300);
cpSpaceAddBody(espace, vaisseau2);
cpShape* forme2 = cpPolyShapeNew(vaisseau2, num, points, cpvzero);
forme2->e = 0.3f; forme2->u = 0.8f;
cpSpaceAddShape(espace, forme2);
sf::Shape triangle2;
for(unsigned int i=0; i<num; i++)
{
triangle2.AddPoint(points[i].x, points[i].y, sf::Color::Green);
}
triangle.SetPosition(80, 300);
I don't think the problem comes from the library so I certainly forgot something or such.
Moreover, maybe I don't correctly update the rotation of the objet when I display it (Particularly, I don't know if the angle got by cpBodyGetAngle is clockwise and where the origin is)
Anyone could help me, please ?
Thank you in advance
PS : I'm french, sorry for the possible mistakes...