Archived

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

DanG

Working with a plane for 3D clipping

Recommended Posts

I am working on my first major 3D project, a first person "game engine" that draws some walls and lets you walk around. Right now the graphics take to long to draw because there is no clipping going on, but i want to change that. My idea is to have a plane perpendicular to straight ahead so that i can not draw points that are behind the plane, but i don''t know the math as i''ve only had Linear Algebra. Here is what i have learned through google and the questions remaining, so correct what i say if i am wrong: Equation of a plane is Ax + By + Cz + D = 0 The normal to the plane is (A,B,C) a point (x1,y1,z1) is on the plane if it substitutes into the equation to form 0 = 0 if A*x1 + B*y1 + C*z1 + D > 0 then the point is on one side, and if < 0 than its on the other. You can determine a plane with three non colinear points, or the plane''s normal vector and a single point. if you have say the normal vector (0,0,1) and the point (0,0,0) you would have the XY plane. BUT, how do you get D into the equation? I don''t see HOW you use the vector and point to get the plane, because i don''t understand what D IS? thanks for any help. RELIGION IS THE ROOT OF ALL EVIL

Share this post


Link to post
Share on other sites
If you have a plane described by vector u (ux, uy, uz) and normal vector n (nx, ny, nz) and point a (ax, ay, az) then:

k = n . u
d = (nx * ax) + (ny * ay) + (nz * az)

If d < k, the point is behind the plane, if d = k, the point is on the plane and if d > k, the point is in front of the plane.

I''m not that great at math myself , but I think that should work.

Game: The Adventure (tm).
-------------------------

Share this post


Link to post
Share on other sites
Thanks! One question. I still don''t understand really what the dot product (k = n.u) returns? One place said it was the area of the paralelagram defined by using the two vectors as sides, but this makes absolutley no sense to me. Would anyone care to explain?

RELIGION IS THE ROOT OF ALL EVIL

Share this post


Link to post
Share on other sites
The dot product of vectors a and b is |a||b|cos(theta) where theta is the angle between them. It is not the area of a parallelagram, that is the magnitude of the cross product. The magnitude of the cross product is |a||b|sin(theta) where theta is the same angle. The area of a parallelagram is the base times the height. If you draw a parallelagram and break it into a rectangle and two right triangles then the length of the two lines you drew are the height. You can work out geometrically that that length is the length of one side times the sin of the angle opposite the line you drew. The base is the length of the other side.

The dot product is a scalar and the cross product is a vector. The dot product is the sum of the product of the corresponding components. So (xa,ya,za).(xb,yb,zb)=xa*xb+ya*yb+za*zb. That makes it rather easy to calculate the cosine of the angle between two vectors, i.e. (a.b)/(|a||b|). Also if the magnitude of one vector is one then it gives you an easy way to project one vector along another. So using the example above of the parallelagram then if a was the hypontheneous of your triangle then you could normalize b by u=b*1/|b| which would make u a vector with length one pointing in the same direction as b. Then a.u would be the component of a along u or b, i.e. the length of the third side of your triangle. Then a.u*u would be the projection of a along b, i.e. a vector that when positioned in the corner opposite the line you drew would point in the direction of b and end at the line you drew. One use of that is finding the closest point on a line to a point. The cross product can be used to find the distance of a point from a line.

Share this post


Link to post
Share on other sites