Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Building a frustum Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
GroovNinja

July 18, 1999, 04:06 AM

Me again.. :)

Sorry if this is a stupid question, but i need some help on how to build a frustum to clip my
polys against. I am building a portal engine and i think i know how to build a frustum of
clip planes extending from the camera's position to the edges of a portal poly but i dont
understand how to build the initial frustum that extends from the camera to the edges of the
screen. I mean, where exactly is the edge of the screen? Does it depend on the field of view?

I think this question may be trivial but for some reason my brain is not allowing me to
understand. It does that from time to time :)

Any help on the matter would be greatly appreciated.

GroovNinja

 
MCrack

July 18, 1999, 05:41 PM

Hi

take three 2d points on the screen edge.
for the left screen edge x=0 and y can be found by "invers-project" x
z isn't that important

MCrack


GroovNinja wrote:
>>Me again.. :)
>>
>>Sorry if this is a stupid question, but i need some help on how to build a frustum to clip my
>>polys against. I am building a portal engine and i think i know how to build a frustum of
>>clip planes extending from the camera's position to the edges of a portal poly but i dont
>>understand how to build the initial frustum that extends from the camera to the edges of the
>>screen. I mean, where exactly is the edge of the screen? Does it depend on the field of view?
>>
>>I think this question may be trivial but for some reason my brain is not allowing me to
>>understand. It does that from time to time :)
>>
>>Any help on the matter would be greatly appreciated.
>>
>>GroovNinja

 
Raven

July 18, 1999, 06:09 PM

MCrack wrote:
>>Hi
>>
>>take three 2d points on the screen edge.
>>for the left screen edge x=0 and y can be found by "invers-project" x
>>z isn't that important
>>
>>MCrack

This isn't very useful for portal engines. The more useful method is to find the "eye" and the other two points for the plane lie on the plane of projection. In a perspective projection the eye will be the apex(or center) of projection. To find it you:

1. Take 2 random points(any will do though NOT on the plane of projection)
2. Project them to make them lie on the pop
3. Pass a line between each point and it's projection. you now have two lines(p1-p'1, p2-p'2 where p is a point a p' is its projection)
4. The point where these lines intersect will be the apex of projection or the eye.

You now have 3 points for the frusrum. Each plane is the eye and the edge of the screen. When you want to build a frusrum through a portal each plane is the eye and one of the edges of the portal. Note that you can build portal frusrum with the back-projection method, but it's going to be a little slower(very very little) and trickier.

For completeness I will explain back-projections here:

Back-projection is the inverse of your projection matrix. I will not be using matrices because it's long as hell to invert a matrix. I'll use functions instead.

Say our projection is defined as:

x'=(x/z+1)*HalfRes

Note that this is the default Glide3 projection. x' is the projected x coordinate, x is the 3D x coordinate, z is the 3D z coord and HalfRes is half the x-resolution on the screen

now, a back-projection would be the inverse of this function, ie.

x=(x'/z+1)*HalfRes

Solving for x' yields:

x'=((xz)/HalfRes-z) (I added some brackets to avoid confusion)

This is grade 10 math and should be easy enough to apply to any projection formula. If you want to know how to invert matrices look it up in a linear algebra book. The easiest way is to multiply your matrix on paper by (x,y,z,w) to yield the equation it represents, invert the equation and convert the inverse back to a matrix. If you don't know what an inverse is then: a matrix is a transformation from p to p'. An inverse of a linear transform(matrix) is such a transform that puts p' back to p.

Now back to our topic:) To use your back-projection to find a plane you take 3 points on the edge in 2D and give them different z-coords and apply the b-p. Example for the x=0 edge:

p1.x=0; p1.y=10; p1.z=5; InvertProject(p1);
p2.x=0; p2.y=20; p2.z=10; InvertProject(p2);
p3.x=0; p3.y=30; p3.z=15; InvertProject(p3);

TriangleToPlane(p1,p2,p3);

This will give you the left edge of the screen.

Hope I helped,
- Raven

 
This thread contains 3 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.