Page 1 of 1

Cylinders with Newton

Posted: Sun Apr 15, 2007 11:10 am
by Delee
I was going to post this on Newton's forum, but it is impossible to register for, so I have to do it here. Please excuse me if this is not in the correct forum.

Within the following picture, all of the cylinders are at rest. The one at an angle is not moving and identifies the problem.

Image

It appears to me as if Newton is rotating the cylinder in a circular fashion along the Y axis (the flat sides). I tried changing the sizes passed to Newton and I tried modifying the mesh. Initially, my mesh had the cylinder standing up, then I tried it lying down. In both situations, the above resulted.

Does anyone have any ideas as to what might be happening? I am using the following to create the collision area.

Code: Select all

NewtonCollision* collision = NewtonCreateCylinder(nWorld, width, height, NULL);
I have managed to successfully implement spheres, ovals and boxes.

My thanks in advance! :)

Posted: Sun Apr 15, 2007 12:49 pm
by Delee
For further clarification, I turned on debug mode. It appears to be happening to all of the long shapes... rectangles, capsules, cylinders.

Image

I am somewhat stumped as ovoloid shapes work fine. I have tried shifting the mesh around without much success. I am using 3DS max for the meshes.

Posted: Sun Apr 15, 2007 1:13 pm
by roxaz
could you tell me how did you impement viewing debug geometry?

Posted: Sun Apr 15, 2007 1:28 pm
by Delee
I found some code for it on the forums. I'm sorry, I do not remember who wrote it - if it is yours, feel free to yell and scream. :)
Here it is, just to make it easy!

Header

Code: Select all

void showCollision();
void NewtonDebugCollision (const NewtonBody* body, int vertexCount, const float* faceVertec, int id);
void NewtonDebugBody(const NewtonBody* body);
CPP

Code: Select all

void showCollision() {
	matrix4 mat;
	SMaterial material;
	material.Textures[1] = 0;
	material.Lighting = false;
	video_driver -> setTransform(ETS_WORLD, mat);
	video_driver -> setMaterial(material);
	NewtonWorldForEachBodyDo(nWorld, NewtonDebugBody);
}

void NewtonDebugBody(const NewtonBody* body){
	if(!video_driver) return;
	NewtonBodyForEachPolygonDo(body, NewtonDebugCollision);
}

void NewtonDebugCollision(const NewtonBody* body, int vertexCount, const float* FaceArray, int faceId){
	vector3df p0(FaceArray[0], FaceArray[1], FaceArray[2]);
	const SColor c0(0, 0, 255, 0);
	for(int i = 2; i < vertexCount; i ++){
		vector3df p1(FaceArray[(i-1) * 3 + 0], FaceArray[(i-1) * 3 + 1], FaceArray[(i-1) * 3 + 2]);
		vector3df p2(FaceArray[i * 3 + 0], FaceArray[i * 3 + 1], FaceArray[i * 3 + 2]);
		triangle3df t;
		t.set(p1, p2, p0);
		video_driver ->draw3DTriangle(t, c0);
    }
}
Just run showCollision() following your world update or something. Kind of like this.

Code: Select all

while (true) {
    NewtonUpdate(world, t);
    showCollision();
}
I am not sure if that is right, but it works for me.

-

Incidentally, I have sorted out my meshes. My brother (who is the graphical artist in the family), showed me where I went wrong in my pivot points and alignment. :)

Posted: Sun Apr 15, 2007 2:05 pm
by sudi
u have to apply the mesh offset to the newton body....i had the same problem

Posted: Sun Apr 15, 2007 2:42 pm
by roxaz
thanx Delee. i saw almost same code on newton forum, just there stuf was drawn by standart ogl commands and i didnt know how to draw all with irrlicht. thank you one more time ;)