Raytracing

Started by
4 comments, last by Tooko 19 years, 11 months ago
I''m not sure if this is actually what raytracing is but... How can I tell if a line between point a and point b intersects with polygon c? Like, how would I write the following function:

typedef struct { float x,y,z; } VERTOR3;
typedef struct { VECTOR3 Points[3]; } POLYGON;

bool DoesIntersect(VECTOR3 Start, VECTOR3 End, POLYGON Poly, VECTOR3* IntersectionPoint);
 
Where if it returns true IntersectionPoint would be filled with the x,y,z location of where the line intersects with the poly. Yeah.
the future is just like the past, just later. - TANSTAAFL
Advertisement
Ray-Triangle intersection.

Look at Rocket05's post.
1) Find out if the ray reaches the triangle.
2) Use the directions from the original point to the 3 vertices of the polygon, to see if the direction is between those directions. If so, the ray is going to some point in the triangle.


--
You're Welcome,
Rick Wong
- Google | Google for GameDev.net

[edited by - Pipo DeClown on May 20, 2004 8:27:59 AM]
If line/triangle intersections are really important to what you''re doing, and you are going to be doing a lot of them, it might be worth going the extra mile and trying to understand this:

http://www.flipcode.com/tutorials/pluecker/

It may look like gibberish untill you''ve read it 6 times, but boy is it fast!
I''ll put in another plug for using plucker coordinates. They''re a little counterintuitive, but when you get it all worked out, the line/tri test boils down to literally less than ten lines of code. It''s elegant, robust and fast. Definitely recommended over all other methods.

I don''t think many people know this, but the barycentric coordinates for the intersection point can actually be extracted from the plucker dot products, which can also be useful.
I advise you take the time to make a more complete polygon class... Because in a raytracing program, since there are alot of intersection test, its good to precompute some things and have them ready for use...


Looking for a serious game project?
www.xgameproject.com

[edited by - Max_Payne on May 20, 2004 8:51:20 PM]

Looking for a serious game project?
www.xgameproject.com
Well, I really just wrote that for simplicities sake. When I get the basic idea done, I''ll then optimize. Probably add rgba values, tu and tv.. etc.

[edited by - Me about five minutes ago]
the future is just like the past, just later. - TANSTAAFL

This topic is closed to new replies.

Advertisement