   Ray to Plane distance collision detection
  Sigh, I am trying to do this on my own using some books I have, but I am at my minds end....I have a track that I have planes setup on each segment to do a sphere collision against to see if the object is above the track or below it, so I can adjust the objects position to be on the track correctly.What I want to do is have some function that takes the current objects position and the plane do some math on these two values and return the distance from the plane, can be neg or pos I will move the objects center by this amount... What I have isn't working.T GetDistance(const vec3<T>& v){return plane.x * v.x +   plane.y * v.y +   plane.z * v.z +   plane.w;}
  What is the format of your plane vector? The distance should be v.n - n.x0, where x0 is a point on the plane   ;Quote:Original post by gpu_femWhat is the format of your plane vector? The distance should be v.n - n.x0, where x0 is a point on the planeHi gpu_fem,here is how I am setting the plane from a triangle void CreatePlaneFromTriangle(const vec3<T>& v1, const vec3<T>& v2, const vec3<T>& v3){vec3<T> normal, e1, e2;e1 = v3 - v1;e2 = v2 - v1;e1.Normalize();e2.Normalize();normal = NX::MATH::vec3<T>::Cross(e1, e2);normal.Normalize();plane.Set(normal, -(plane.x * v1.x + plane.y * v1.y + plane.z * v1.z));};  You haveplane.Set(normal, -(plane.x * v1.x + plane.y * v1.y + plane.z * v1.z));Doesn't this not set plane.x,plane.y, plane.z until inside the Set method?  Aren't they undefined.  In other words, I think it should beplane.Set(normal, -(normal.x * v1.x + normal.y * v1.y + normal.z * v1.z));Also, if this is performance critical code, you might consider removing the lines (sorry I don't know how to quote, I am new)e1.Normalize();e2.Normalize();This shouldn't be necessary, because you normalize the cross product. (In other words, the magnitude of e1 and e2 do not affect the direction of n, only its magnitude).   ;  yes, usually you need the position of the object, a point in the plane and the plane normal: Distance_To_Plane = Dot((object.position - plane.point), plane.normal)   ;Quote:Original post by gpu_femYou haveplane.Set(normal, -(plane.x * v1.x + plane.y * v1.y + plane.z * v1.z));Doesn't this not set plane.x,plane.y, plane.z until inside the Set method?  Aren't they undefined.  In other words, I think it should beplane.Set(normal, -(normal.x * v1.x + normal.y * v1.y + normal.z * v1.z));Also, if this is performance critical code, you might consider removing the lines (sorry I don't know how to quote, I am new)e1.Normalize();e2.Normalize();This shouldn't be necessary, because you normalize the cross product. (In other words, the magnitude of e1 and e2 do not affect the direction of n, only its magnitude).Hey I think that was the problem can't believe I missed that plane vs. the normal variable being used... SighThanks a million I will try it and see that resolves my issues.++ BTW   