Problem with rouge bodies

Official forum for the Chipmunk2D Physics Library.
Post Reply
Zaxuhe
Posts: 2
Joined: Sat Oct 27, 2012 6:49 pm
Contact:

Problem with rouge bodies

Post by Zaxuhe »

I have made 2 bodies, a rouge body (floor) and a normal body, when they collide the normal body goes into the rouge body

This is the code

Code: Select all

space_ = cpSpaceNew();
space_->gravity = cpv(0,9.8);

//create 1st shape (rouge)
create_shape_box(0, 0, 100, 100, true);

//create the box that is affected by physics
create_shape_box(0, 400, 100, 100, false);
//function to create shapes
cpShape* game::create_shape_box(float _x, float _y, float _w, float _h, bool _is_static /* = true*/)
{
	//return create_circle(_x, _y, _w);

	int first = 0;

	cpVect vec[4];
	vec[0].x = -_w/2.0f;
	vec[0].y = -_h/2.0f;
	vec[1].x = -_w/2.0f;
	vec[1].y = _h/2.0f;
	vec[2].x = _w/2.0f;
	vec[2].y = _h/2.0f;
	vec[3].x = _w/2.0f;
	vec[3].y = -_h/2.0f;
	

	// Create space to store the convex hull.
	// An alloca(), or a variable length array would be a better, but not always portable choice.
	cpVect *hullVerts = (cpVect *)calloc(4, sizeof(cpVect));
	int hullCount = cpConvexHull(4, vec, hullVerts, &first, 0.0);

	// hullVerts[0] will be equal to verts[first] here.
	// If you don't care, pass NULL instead of the 'first' pointer.

	cpBody *body;
	cpShape *shape;
	

	if (_is_static == false)
	{
		body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, hullCount, hullVerts, cpvzero));
		body = cpSpaceAddBody(space_, body);
		shape = cpPolyShapeNew(body, hullCount, hullVerts, cpvzero);
		shape = cpSpaceAddShape(space_, shape);
	}
	else
	{
		body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, hullCount, hullVerts, cpvzero));
		//body = cpBodyNewStatic();
		//shape = cpPolyShapeNew(body, hullCount, hullVerts, cpvzero);
		shape = cpBoxShapeNew(body, _w, _h);
		//body = cpSpaceAddBody(space_, body);
		cpBodySetPos(body, cpv(_x, _y));
		
		shape = cpSpaceAddShape(space_, shape);
	}
	cpBodySetPos(body, cpv(_x, _y));

	
	cpShapeSetFriction(shape, 0.0f);
	
	free(hullVerts);
	return shape;
}

I attached a gif with the issue
Attachments
cp_error.gif
cp_error.gif (105.48 KiB) Viewed 3501 times
ganesha
Posts: 71
Joined: Mon Sep 06, 2010 1:29 pm
Contact:

Re: Problem with rouge bodies

Post by ganesha »

Have you set up a Collision Handler? If so do you see that the objects actually collide?
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Heise IT-Markt [Crawler] and 3 guests