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 "inversproject" 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(p1p'1, p2p'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 backprojection method, but it's going to be a little slower(very very little) and trickier.
For completeness I will explain backprojections here:
Backprojection 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 xresolution on the screen
now, a backprojection would be the inverse of this function, ie.
x=(x'/z+1)*HalfRes
Solving for x' yields:
x'=((xz)/HalfResz) (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 backprojection to find a plane you take 3 points on the edge in 2D and give them different zcoords and apply the bp. 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
