Skip to main content
GameDev.net gamedev.net
🔒 Locked

Ray Tracing - Plane

Started by luongoFan Nov 23, 2004 at 4:48 PM 2 replies 1.2k views
Original Post
luongoFan
luongoFan
Hi, Im new to openGL, and had a question I hope someone can help me with. I have a maze, each wall which is made out of a Polygon. I want to implement some type of collision detection, either a bounding box, or ray tracing. I have read neHes site, as well as two others on ray tracing but I am still unsure on how you obtain the Plane information. You want to test if the ray intersects the plane, and then if that point is on the polygon, but how do you make a plane perpendicular to the polygon (wall)? Hope that was clear Thanks Edit: May have posted this in the wrong forum, if a mod would kindly move it to the correct one, it would be appreciated.
Bradsco
Bradsco
I'm assuming that since you're using the term polygon, you have the vertices for your triangles or quads. Using those you need the get the normal of the plane (polygon) and it's distance from the origin. Compare that against your point.
I set the clouds in motion, turn up light and sound...Activate the window, and watch the world go 'round
luongoFan
luongoFan
When I create each polygon, using glVertex3f(), and I also supply the normal for each polygon using glNormal().

When you say get the point from the origin. Is that the origin of the centre of the player?

My camera is on the person so to say, fisrt person.

Thanks

Edit: If I cannot use the normal specified using glNormal() how would I go about calculating it?
aleks_1661
aleks_1661
What you need to use is the plane equation.

X-------------------+|                   ||   +-----------+   || c |           |   ||   +-----------+   ||                   |+-------------------+   < this is your world, lines are walls                          c is your character (xyz) X is the origin                                    (0,0,0)


for a plane with surface normal N and distance from the origin D;
the distance between the plane and the point [xyz] is given by

(N.x * x) + (N.y * y) + (N.z * x) + D

if distace == 0 point is on plane > 0 is above the plane and <0 is below the plane.

To calculate the normal of the plane you need 3 points that lie apon it.

calculation is roughly...

v1 = point2 - point1;
v2 = point3 - point1;
N = crossproduct( v1, v2 );
normalise( N );
D = dotproduct( N, point1 );

check out this site, jsut found it quickly in google, may be of use
http://easyweb.easynet.co.uk/~mrmeanie/plane/planes.htm

To use this in collision detection you just compare the distance from the plane to the character. the simplest method is to imagine a sphere around the character. if the distance to the plane is less than the radius of the sphere then there is a colision. the next step up is AABB's (axis aligned bounding boxes). likely to fit the object better.

hope this helped.
Twitter: [twitter]CaffinePwrdAl[/twitter] Website: (Closed for maintainance and god knows what else)

Topic Locked

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

Sign in to reply to this topic.