Cylinders with Newton

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Delee
Posts: 18
Joined: Sat Apr 14, 2007 8:36 am

Cylinders with Newton

Post 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! :)
Delee
Posts: 18
Joined: Sat Apr 14, 2007 8:36 am

Post 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.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

could you tell me how did you impement viewing debug geometry?
Delee
Posts: 18
Joined: Sat Apr 14, 2007 8:36 am

Post 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. :)
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

u have to apply the mesh offset to the newton body....i had the same problem
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post 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 ;)
Post Reply