Archived

This topic is now archived and is closed to further replies.

Raytracing

This topic is 5027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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.

Share on other sites
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

[edited by - Pipo DeClown on May 20, 2004 8:27:59 AM]

Share on other sites
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!

Share on other sites
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.

Share on other sites
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]

Share on other sites
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]