PDA

View Full Version : calculating clipping planes...

timmie
02-17-2003, 10:52 AM
This is probably an easy question, but I'll ask it anyway http://www.opengl.org/discussion_boards/ubb/smile.gif

How can I calculate the plane equation between 2 arbitrary points (plane is always going to be perfectly vertical) given my viewpoint position?

This only has to be in 2d (you can ignore the y [up] axis).

Thanks!

antipop
02-19-2003, 05:20 AM
Originally posted by timmie:
This is probably an easy question, but I'll ask it anyway http://www.opengl.org/discussion_boards/ubb/smile.gif

How can I calculate the plane equation between 2 arbitrary points (plane is always going to be perfectly vertical) given my viewpoint position?

This only has to be in 2d (you can ignore the y [up] axis).

Thanks!

Depends. If the vector between these two points are parallell to the up vector, you can't find a suitable plane.

Otherwise, let the vector between your points be V. Then, the plane normal N is N = V x (V x UP), where x is the cross-product.

[This message has been edited by antipop (edited 02-19-2003).]

Ysaneya
02-19-2003, 06:35 AM
You can define a plane in 3D by a normal and one point; so if your normal is up (0, 1, 0), you just need one point in 3D to define the plane.

The concept of a plane in 2D is beyond me though. I'm also not sure to understand how the viewpoint position is a variable.

If you're looking for a 3D plane that intersects the XZ plane along the line defined by your two 2D points (let's call them (x1,z1) and (x2,z2), then you can create it from these 3 points for example:

- (x1, 0, z1)
- (x2, 0, z2)
- (x2, 1, z2)

Y.

timmie
02-19-2003, 09:50 AM
Hmm, a bit of elaboration, I guess...

The map data I'm using is 2D (Doom engine) and I want to set up a clip plane aligned with a given line. The reason for this is I am implementing mirrors (ala Duke3D) and want to set up a clipping plane so only things on the far side of the mirror are drawn.
http://members.shaw.ca/timstump/images/zdoomgl_37.jpg (kinda dark, but you get the idea)

How the mirror works is I basically just move the viewpoint to the virtual location/orientation in the mirror and draw the scene again.

The problem is, sometimes I get things coming through the mirror (mostly due to mapping errors, since the same bizarre things happen in software mode).

Not a big deal, really, since the problems aren't really the engines fault, but I'd still like to minimize them.

Miguel_dup1
02-19-2003, 10:48 PM
Would a reflective cubemap do the trick for ya????

Originally posted by timmie:
Hmm, a bit of elaboration, I guess...

The map data I'm using is 2D (Doom engine) and I want to set up a clip plane aligned with a given line. The reason for this is I am implementing mirrors (ala Duke3D) and want to set up a clipping plane so only things on the far side of the mirror are drawn.
http://members.shaw.ca/timstump/images/zdoomgl_37.jpg (kinda dark, but you get the idea)

How the mirror works is I basically just move the viewpoint to the virtual location/orientation in the mirror and draw the scene again.

The problem is, sometimes I get things coming through the mirror (mostly due to mapping errors, since the same bizarre things happen in software mode).

Not a big deal, really, since the problems aren't really the engines fault, but I'd still like to minimize them.

antipop
02-20-2003, 01:26 AM
Originally posted by timmie:
Hmm, a bit of elaboration, I guess...

The map data I'm using is 2D (Doom engine)

This should be quite straight-forward: Your points (in 3D) is p1 and p2.

Plane equation:
N.x *x + N.y *y + N.z *z + D = 0

To find the values:

v1 = p2-p1;
v2 = up (from modelview matrix)
N = v1 X v2 // Maybe normalize it?
D = -(N.x*p1.x + N.y*p1.y + N.z*p2.z)

timmie
02-20-2003, 11:19 PM
Would a reflective cubemap do the trick for ya????

Probably, but right now it still runs on a Voodoo3 (which a surprising number of people still use, to my chagrin) http://www.opengl.org/discussion_boards/ubb/smile.gif

Oh, and thanks for the info, antipop!