Skip to main content
gamedev.net
🔒 Locked

Ray Intersection Problem

Started by jonbell 5 replies 900+ views
Original Post
jonbell
jonbell
I have my Ray / Tri intersection test working but I now have a new problem as i bi-product. If my ray strikes a triangle in a model there is also a good chance that the ray will be long enough to strike a second triangle that is directly behind and parellel to the first polgon the ray hit. I need a way of determining which tri is closest to the rays origin. Measuring the distance to each tri''s plane intersection point won''t work i think (prove me wrong please) so i have come up with this : fTriDist = LineSegLength(RayEndPoint, Tri[0]) + LineSegLength(RayEndPoint, Tri[1]) + LineSegLength(RayEndPoint, Tri[2]) / 3; This will work for some polgons but not all. What if you have a large tri which is closest to the ray but has one vertex far away from the ray. This will screw up the scoring system above. How can i best tell the closest triangle to any given point?
emptyhead
emptyhead
If your ray is R(t)=O+D*t then just compare the t values of all the intersections to find the smallest non-negative value, that is your closest intersection.
:wq!
jonbell
jonbell
Ah very good, thx man but what about finding an actual distance value?

[edited by - jonbell on May 26, 2003 8:09:57 AM]
Basiror
Basiror
how about learning the basics of vector maths?

there are tons of articles about simple things like that
http://www.8ung.at/basiror/theironcross.html
jonbell
jonbell
Well the distance from a point to a triangle is not a trivial calculation to do in real time. Where do you measure it to? Calculating the centre of a triangle and then measuring the vector from the point to the centre is not something you can do thousands of time every second.

"how about learning the basics of vector maths?"

How about learning some manners you fucking arsehole.
oliii
oliii
well, if you got your ray intersection a triangle working, you''re pretty much there.

you need the triangle plane equation.

Say triangle is (V0, V1, V2)

Normal of triangle is N = ((V1 - V0) x (V2 - V1)) (you should have it already)

your ray equation is P = O + S . t

and P is also on the plane if P * N = (N * V0)

so you have two equations, and you need t.

replace P in the second equation by (O + S . t), and you''ll get

t = ((V0 - O) . N) / (S . N)

I just don;t understand how you managed to get a ray/triangle intersection test working without doing the above calculation, let alone without knowing how to find the intersection of a ray and a plane

Everything is better with Metal.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.