Back to ray intersection

Started by
0 comments, last by 84r 15 years, 8 months ago
I can't get the intersection to work. The D3D function I copied does work, but it only returns a bool true or false. I made a function for ray-plane intersection and to me it seems correct, and it probably is, but I would like someone to confirm this for me so I can single my problem. It goes like this.. *P is the output intersection. P0 is the ray orgin. V is the ray vector. N is the plane normal. P1 is a point on the plane. Used for getting d. void RAY_PLANE( POINT *P, POINT P0, VECTOR V, VECTOR N, POINT P1 ){ float d = bcDOT(&N,&P1); float Vd = bcDOT(&V,&N); float V0 = -1*(bcDOT(&P0,&N) + d) ; float t = V0 / Vd; P->x = (V.x * t)+P0.x; P->y = (V.y * t)+P0.y; P->z = (V.z * t)+P0.z; } Does this seem right?
Advertisement
I think "float V0 = -1*(bcDOT(&P0,&N) + d);" should be "float V0 = d - bcDOT(&P0,&N);". Or just change "float d = bcDOT(&N,&P1);" to "float d = -bcDOT(&N,&P1);"

My code for Ray-Plane-Intersection is:

t = (dist - dot(n,p))/dot(n,d);
intersection = p+d*t;

where:
dist = distance from origin to plane (n dot point on plane)
n = normal of plane
p = ray position
d = ray direction

This topic is closed to new replies.

Advertisement