Sign in to follow this  
VprMatrix89

Back to ray intersection

Recommended Posts

VprMatrix89    100
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?

Share this post


Link to post
Share on other sites
84r    160
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this