Debug IPhysics

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
MM2_23
Posts: 12
Joined: Sun Jan 07, 2007 3:24 am

Debug IPhysics

Post by MM2_23 »

This is to the IPhysics users or to those who have integrated Newton into their game. I'm trying to show the collision geometry but in the newton tutorials it uses openGL. I don't want to include openGL in my code but for fun I tried anyway by linking the library files and adding the headers. It still doesn't work. Do I have to initialize openGL manually even though I'm creating my irrlicht device with the openGL tag? I know that it is running the debug code since it greatly slows down my game (frame rate drops to 15) but still no debug lines show up.

But its not only newton geometry I'm having trouble with, I can't get bounding boxes to display around my AnimatedMeshX either. How would I use irrlicht+newton code to display this debugging information without using glBegin(GL_LINES) or anything other than irrlicht draw3Dbox and stuff like that.

Here is the code I'm using from the newton sdk tutorial 8:
void DebugShowGeometryCollision (const NewtonBody* body, int vertexCount, const dFloat* faceVertec, int id)
{
int i;

i = vertexCount - 1;
vector3df p0 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
for (i = 0; i < vertexCount; i ++) {
vector3df p1 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
vector3df (p0.X, p0.Y, p0.Z);
vector3df (p1.X, p1.Y, p1.Z);
p0 = p1;
}

}
void DebugShowBodyCollision(const NewtonBody* body){
NewtonBodyForEachPolygonDo(body, DebugShowGeometryCollision);
}
And this final chunk of code is where I think I'm having the problem. I think that the lines are being generated but just aren't being drawn to the screen because I'm using openGL code (which I'm not very familiar with btw).
void DebugShowCollision ()
{
glDisable (GL_LIGHTING);
glDisable(GL_TEXTURE_2D);

glColor3f(1.0f, 1.0f, 0.0f);
glBegin(GL_LINES);
NewtonWorldForEachBodyDo (physics.getWorld(), DebugShowBodyCollision);
glColor3f(1.0f, 1.0f, 1.0f);

glEnd();
}
I am placing DebugShowCollision in my game loop just before my irrlicht driver->endScene();

Is there a way to convert that openGL code to irrlicht code using the irrlicht driver (if that makes sense). For example: instead of glBegin(GL_LINES); theres something like driver->draw2Dline from irrlicht?

[/quote]
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Have you seen the Newton demo on my website? You may be able to glean a few interesting things from the source.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You don't have any code in DebugShowGeometryCollision() to draw lines. Actually, the code in there is doing nothing other than creating a bunch of temporary vectors.
MM2_23
Posts: 12
Joined: Sun Jan 07, 2007 3:24 am

Post by MM2_23 »

Sio,

I checked out the source and it's a very clean implementation and I finally did get a bounding box to display around my terrain but I tried the same thing on my AnimatedMeshX scene node that has my mesh and my meshes convex hull collision geometry attached to it and I can't get a bounding box to display.

But the bounding box isn't really the hard part I guess. I'm looking more to having every polygon of the mesh or collision geometry to be outlined. Your code doesn't do that Sio.

vitek,

DebugShowGeometryCollision is (I thought) just a function to pass the vectors to newtons NewtonBodyForEachPolygonDo and then it's the openGL code that's supposed to draw it.

EDIT: I got the collision geometry to display by sticking driver->draw3dline() inside the DebugShowGeometryCollision(); and I passed the two vectors p0 and p1 as the start and end points of draw3dline and it worked (dropped me to 2 frames a second).

And like I suspected the collision geometry doesn't match up with my terrain perfectly(It's pretty close though). I generated the terrain from a height map with extreme deformation. I'm sure that if I changed the height map to make nice rolling hills it will be fine.

1.)The weird part is that when I rotate my camera, all the geometry jumps around at certain angles (the mesh stays put). Even the bounding box around the terrain jumps. At one angle the corner of the box(at the origin) is right about my meshes head (where my scene not for my animatedmeshx is). What could be causing this?? Rounding error (because my terrain is huge 9000X9000 approximately)?

2.)Also, all the lines show up black and sometimes change to grey depending on the angle of the camera even though I'm using SColor to make them blue. I can't make sense of any of this. I knew something was off.
MM2_23
Posts: 12
Joined: Sun Jan 07, 2007 3:24 am

Post by MM2_23 »

and even worse it looks like my convex hull geometry falls faster than my mesh when gravity is applied.
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

mm_23 why are you reinventing the wheel here? I have already included debugging in my last release of iphysics, no need to do it.
MM2_23
Posts: 12
Joined: Sun Jan 07, 2007 3:24 am

Post by MM2_23 »

Last time I checked your version didn't download right for me so I just waited but never got around to downloading it. Now I did and looked over your code and it's pretty much exactly the same as how I implemented dynamic meshes and the debug code (except now my lines actually show up in color since I forgot to set the material). If there is going to be more development on IPhysics I am planning on deleting my code and just using the new IPhysics but if our implementations are the same then I don't see how it's going to fix the problems I'm having right now.

I've switched my heightmap and generated a different terrain and now my character sits on the terrain but when it moves up a slope it slides through the mesh and falls through (unless I do it little step by little step in which case the terrain slowly pushes my character back ontop of the mesh. It's like newton is lagging behind the irrlicht rendering). Yes I've set the mass matrix and inertial values but that doesn't seem to fix it.

Also I'm not using the Settransform callback to update my position. Instead the 3rd person camera system I'm using is designed to move the irrlicht node and not the newton body so I turned off the setTransform callback and placed some code in the game loop where the relativetransformationmatrix of the irrlicht node is applied to the newtonbody matrix. So what's happening is that my node moves and then the newton body follows. Not sure why this would be causing all my problems though.

EDIT: some other people are having the same slide through the terrain problem as me on the newton forum: http://newtondynamics.com/forum/viewtopic.php?t=3141
Post Reply