PerspProj.cc

Go to the documentation of this file.
00001 #include <gra/camera/PerspProj.h>
00002 
00003 using namespace gra;
00004 
00005 PerspProj::PerspProj(double left,
00006                      double right,
00007                      double bottom,
00008                      double top,
00009                      double nr,
00010                      double fr)
00011     : Projection(left, right, bottom, top, nr, fr)
00012 {
00013     if (_left == _right) {
00014         cerr << "PerspProj(): invalid left and right clipping planes;" << endl;
00015         cerr << "             switching to -1, 1" << endl;
00016         _left = -1.0;
00017         _right = 1.0;
00018     }
00019 
00020     if (_bottom == _top) {
00021         cerr << "PerspProj(): invalid bottom and top clipping planes;" << endl;
00022         cerr << "             switching to -1, 1" << endl;
00023         _bottom = -1.0;
00024         _top = 1.0;
00025     }
00026 
00027     if (_near == _far) {
00028         cerr << "PerspProj(): invalid near and far clipping planes;" << endl;
00029         cerr << "             switching to 1, 10" << endl;
00030         _near = 1.0;
00031         _far = 10.0;
00032     }
00033 
00034     if (_near <= 0.0) {
00035         cerr << "PerspProj(): near clipping plane mus be positive;" << endl;
00036         cerr << "             switching to 1" << endl;
00037         _near = 1.0;
00038     }
00039 
00040     if (_far <= 0.0) {
00041         cerr << "PerspProj(): far clipping plane mus be positive;" << endl;
00042         cerr << "             switching to 10" << endl;
00043         _far = 10.0;
00044     }
00045 
00046     float rl = _right - _left;
00047     float tb = _top   - _bottom;
00048     float fn = _far   - _near;
00049     float n2 = 2 * _near;
00050 
00051     _projMat.set(n2/rl, 0.0,   (_right+_left)/rl, 0.0,
00052                  0.0,   n2/tb, (_top+_bottom)/tb, 0.0,
00053                  0.0,   0.0,   (-_far-_near)/fn,  -(n2*_far)/fn,
00054                  0.0,   0.0,   -1.0,              0.0);
00055 }
00056 
00057 Projection* PerspProj::clone() const
00058 {
00059     return new PerspProj(*this);
00060 }
00061 
00062 Vector3 PerspProj::getProjectionDirection(const Vector2& point)
00063 {
00064     Vector3 pdir(_left + point.x, _bottom + point.y, -_near);
00065     pdir.normalize();
00066     return pdir;
00067 }

Generated on Tue Nov 21 15:11:42 2006 for gra by  doxygen 1.4.6