[ODE] Adding local normals to dContactGeom

Joost van Dongen tsgoo at hotmail.com
Sun Jan 29 15:18:16 MST 2006


Hello all!

For a game I am making, I need to know the local normals of the two geoms 
that collide at a certain point, not just the collisionplane normal as ODE 
gives it to me. To get this, I added two vectors, normal1 and normal2, to 
the struct dContactGeom in ODE.

To fill in these two normals, I will need to add a lot of code to all the 
collision-functions for different combinations of objects, but for now I am 
only trying to get this right for dCollideSTL, which does trimesh against 
sphere collisions (in the file collision_trimesh_sphere.cpp). To get the 
normal for the triangle, I figured I could just use the cross-product of the 
vertices, as is already calculated in that function. However, when I use 
this, the normals I get are clearly not normal to the faces (ignoring the 
fact that they are also not normalised, which does not matter to me right 
now). I have visualised them in-game and they seem quite random. Some seem 
normal to the surface, others seem parallel to the surface, others seem just 
randomly oriented.

Can someone tell me where I am going wrong here? Below is the code that I 
edited. The lines I added are marked, all others are unaltered from ODE.

			dReal Depth;
			float u, v;
			if (!GetContactData(Position, Radius, v0, vu, vv, Depth, u, v)){
				continue;	// Sphere doesnt hit triangle
			}
			dReal w = REAL(1.0) - u - v;

			if (Depth < REAL(0.0)){
				Depth = REAL(0.0);
			}

			dContactGeom* Contact = SAFECONTACT(Flags, Contacts, OutTriCount, 
Stride);

			Contact->pos[0] = (v0[0] * w) + (v1[0] * u) + (v2[0] * v);
			Contact->pos[1] = (v0[1] * w) + (v1[1] * u) + (v2[1] * v);
			Contact->pos[2] = (v0[2] * w) + (v1[2] * u) + (v2[2] * v);
			Contact->pos[3] = REAL(0.0);

			dVector4 Plane;
			dCROSS(Plane, =, vv, vu);	// Reversed
			Contact->normal1[0] = Plane[0]; //ADDED BY OOGST
			Contact->normal1[1] = Plane[1]; //ADDED BY OOGST
			Contact->normal1[2] = Plane[2]; //ADDED BY OOGST
			Contact->normal1[3] = REAL(0.0); //ADDED BY OOGST
			Plane[3] = dDOT(Plane, v0);	// Using normal as plane.

Thanks in advance,
Joost "Oogst" van Dongen




More information about the ODE mailing list