hi!
To solve triangle-ray intersection I need:
vec3 ray_start,ray_vector; // is ray (or line segment)
vec3 v1,v2,v3; // are triangle corners
From there i get:
v1 + r*(v2-v1) + s*(v3-v1) = ray_start + t*ray_vector
There I need to solve r,s and t. I need to know all r,s and t for my collision system (I think so

).
If 0<=r,s,r+s,t<=1 then I know that my ray intersects triangle (I think so

).
To solve it? That's little problem. How to do it fast? (Of course I use octree or similar tree too speed it up)
I got this:
vec3 p = ray_start;
vec3 d = -ray_vector;
vec3 s2 = v2-v1;
vec3 s3 = v3-v1;
vec3 o = p-v1;
So the same equitation is simpler:
r*s2 + s*s3 + t*d = o
Then I get:
r*s2.x + s*s3.x + t*d.x = o.x
r*s2.y + s*s3.y + t*d.y = o.y
r*s2.z + s*s3.z + t*d.z = o.z
That is:
| s2.x s3.x d.x | | r | | o.x |
| s2.y s3.y d.y | X | s | = | o.y |
| s2.z s3.z d.z | | t | | o.z |
Shorter:
M X T = O
Solving:
T = (M^) X O // where M^ is inverted M
Right?
But I don't think matrix inversion is very effective here, what do you think? Is it?
Another way is to take pen and paper and start combining opening those equitations.
First solve for example t, then s and finally r. I'm afraid I'll go wrong somewhere. Maybe I try it.
The good point is that when I have solved t I can stop doing more work if is t<0 or t>1.
Is this the way to do it quick, really quick?
I have only found tuts that show how to do it slow

Using plane, you know

Don't know why I aactually wrote this

If anyone can help somewhere? I don't think using matrix here is good. In any case I'll take pen and paper and start solwing it progressively. Maybe I'll tell something if I get somthing working

bye!
[edited by - stefu on June 18, 2002 5:34:30 PM]