Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

glt/project.cpp

Go to the documentation of this file.
00001 #include "project.h"
00002 
00015 #include <cassert>
00016 #include <iosfwd>
00017 using namespace std;
00018 
00019 GltOrtho::GltOrtho()
00020 : _left(-1.0), _right(1.0), _bottom(-1.0), _top(1.0), _zNear(-10.0), _zFar(10.0)
00021 {
00022 }
00023 
00024 GltOrtho::~GltOrtho()
00025 {
00026 }
00027 
00028 void 
00029 GltOrtho::set()
00030 {
00031     glMatrixMode(GL_PROJECTION);
00032     glLoadIdentity();
00033     glOrtho(_left,_right,_bottom,_top,_zNear,_zFar);
00034     glMatrixMode(GL_MODELVIEW);
00035 }
00036 
00037 void 
00038 GltOrtho::set(int width,int height)
00039 {
00040     GLdouble x = 1.0;
00041     GLdouble y = 1.0;
00042 
00043     if (width!=0 && height!=0)
00044     {
00045         if (width>height)
00046             x = GLdouble(width)/GLdouble(height);
00047         else
00048             y = GLdouble(height)/GLdouble(width);
00049     }
00050 
00051     _left   = -x;
00052     _right  =  x;
00053     _bottom = -y;
00054     _top    =  y;
00055     set();
00056 }
00057 
00058 GLdouble &GltOrtho::left()   { return _left;   }
00059 GLdouble &GltOrtho::right()  { return _right;  }
00060 GLdouble &GltOrtho::bottom() { return _bottom; }
00061 GLdouble &GltOrtho::top()    { return _top;    }
00062 GLdouble &GltOrtho::zNear()  { return _zNear;  }
00063 GLdouble &GltOrtho::zFar()   { return _zFar;   }
00064 
00065 const GLdouble &GltOrtho::left()   const { return _left;   }
00066 const GLdouble &GltOrtho::right()  const { return _right;  }
00067 const GLdouble &GltOrtho::bottom() const { return _bottom; }
00068 const GLdouble &GltOrtho::top()    const { return _top;    }
00069 const GLdouble &GltOrtho::zNear()  const { return _zNear;  }
00070 const GLdouble &GltOrtho::zFar()   const { return _zFar;   }
00071 
00072 bool 
00073 GltOrtho::tile(GltOrtho &frust,const int dx,const int dy,const int n) const
00074 {
00075     if (dx<1 || dy<1 || n<0 || n>=dx*dy)
00076     {
00077         frust = *this;
00078         return false;
00079     }
00080 
00081     const int px = n%dx;
00082     const int py = n/dx;
00083 
00084     const GLdouble width  = (_right-_left)/dx;
00085     const GLdouble height = (_top-_bottom)/dy;
00086     
00087     assert(py<=dy);
00088 
00089     if (py<dy)
00090     {
00091         frust._left = frust._right  = _left   + width*px;
00092         frust._top  = frust._bottom = _bottom + height*py;
00093     
00094         frust._right += width;
00095         frust._top   += height;
00096 
00097         frust._zNear = _zNear;
00098         frust._zFar  = _zFar;
00099 
00100         return true;
00101     }
00102     else
00103         return false;
00104 }
00105 
00107 
00108 
00109 GltFrustum::GltFrustum()
00110 : _left(-1.0), _right(1.0), _bottom(-1.0), _top(1.0), _zNear(1.0), _zFar(10.0)
00111 {
00112 }
00113 
00114 GltFrustum::~GltFrustum()
00115 {
00116 }
00117 
00118 void 
00119 GltFrustum::set()
00120 {
00121     assert(_zNear>0.0);
00122     assert(_zFar>0.0);
00123 
00124     glMatrixMode(GL_PROJECTION);
00125     glLoadIdentity();
00126     glFrustum(_left,_right,_bottom,_top,_zNear,_zFar);
00127     glMatrixMode(GL_MODELVIEW);
00128 }
00129 
00130 void 
00131 GltFrustum::set(int width,int height)
00132 {
00133     GLdouble x = 1.0;
00134     GLdouble y = 1.0;
00135 
00136     if (width!=0 && height!=0)
00137     {
00138         if (width>height)
00139             x = GLdouble(width)/GLdouble(height);
00140         else
00141             y = GLdouble(height)/GLdouble(width);
00142     }
00143 
00144     _left   = -x;
00145     _right  =  x;
00146     _bottom = -y;
00147     _top    =  y;
00148     set();
00149 }
00150 
00151 GLdouble &GltFrustum::left()   { return _left;   }
00152 GLdouble &GltFrustum::right()  { return _right;  }
00153 GLdouble &GltFrustum::bottom() { return _bottom; }
00154 GLdouble &GltFrustum::top()    { return _top;    }
00155 GLdouble &GltFrustum::zNear()  { return _zNear;  }
00156 GLdouble &GltFrustum::zFar()   { return _zFar;   }
00157 
00158 const GLdouble &GltFrustum::left()   const { return _left;   }
00159 const GLdouble &GltFrustum::right()  const { return _right;  }
00160 const GLdouble &GltFrustum::bottom() const { return _bottom; }
00161 const GLdouble &GltFrustum::top()    const { return _top;    }
00162 const GLdouble &GltFrustum::zNear()  const { return _zNear;  }
00163 const GLdouble &GltFrustum::zFar()   const { return _zFar;   }
00164 
00165 bool 
00166 GltFrustum::tile(GltFrustum &frust,const int dx,const int dy,const int n) const
00167 {
00168     if (dx<1 || dy<1 || n<0 || n>=dx*dy)
00169     {
00170         frust = *this;
00171         return false;
00172     }
00173 
00174     const int px = n%dx;
00175     const int py = n/dx;
00176 
00177     const GLdouble width  = (_right-_left)/dx;
00178     const GLdouble height = (_top-_bottom)/dy;
00179     
00180     assert(py<=dy);
00181 
00182     if (py<dy)
00183     {
00184         frust._left = frust._right  = _left   + width*px;
00185         frust._top  = frust._bottom = _bottom + height*py;
00186     
00187         frust._right += width;
00188         frust._top   += height;
00189 
00190         frust._zNear = _zNear;
00191         frust._zFar  = _zFar;
00192 
00193         return true;
00194     }
00195     else
00196         return false;
00197 }
00198 

Generated on Tue Nov 5 11:11:03 2002 for GLT by doxygen1.2.18