ray vs OBB

Started by
1 comment, last by eGamer 18 years, 8 months ago
i have made algorithm for intersecting 3d ray ( p0 + t.K ) with an OBB and it didn't work well here is the code: bool intersect(SOBB& b,SRay3D& s,SVector3D& p) { SRay3D convS; // the ray in b coordinates SVector3D c_c = s.p0 - c; // translate vector // converting the ray elements into ray frame convS.p0.set( c_c.Dot(b.u[0]) , c_c.Dot(b.u[1]) ,c_c.Dot(b.u[2]) ); convS.d.set( s.d.Dot(b.u[0] ) , s.d.Dot(b.u[1]) ,s.d.Dot(b.u[2]) ); // now the converted ray with aabb ( obb is now aabb for new ray ) SAABB ab; ab.min.set(-b.e[0],-b.e[1],-b.e[2]); ab.max.set( b.e[0], b.e[1], b.e[2]); float t; if( ab.intersect(convS,t,p) ) { // re-write the intersection point in world coordinates float x = b.c.x + p.Dot(xAxis); float y = b.c.y + p.Dot(yAxis); float z = b.c.z + p.Dot(zAxis); p.set(x,y,z); return true; } return false; } please help me what is the mistake in my code???
Advertisement
Assuming ab.intersect() works correctly, I would then try replacing these lines:

float x = b.c.x + p.Dot(xAxis);
float y = b.c.y + p.Dot(yAxis);
float z = b.c.z + p.Dot(zAxis);

p.set(x,y,z);

With this:

p = b.c + p.x * b.u[0] + p.y * b.u[1] + p.z * b.u[2];

And see if that doesn't fix the problem.
okay that's exactly my mistake converting back to old frame.
thanks a lot.

This topic is closed to new replies.

Advertisement