fshake3d  0.0.1
FreeformDensity3DSurfaceEditor
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
transform_Projection.cpp
Go to the documentation of this file.
00001 #include "transform_Projection.hpp"
00002 #include "math_transform.hpp"
00003 
00004 Projection::Projection(ProjectionType type)
00005 : mZSize(200.0)
00006 {
00007   setProjectionType(type);
00008 }
00009 
00010 void Projection::computeTransform()
00011 {
00012   switch(mProjectionType)
00013   {
00014   case ProjectionType_PERSPECTIVE:
00015     mTransform = makeTransformPerspective(mFOVY, mAspect, mZNear, mZFar);
00016     break;
00017   case ProjectionType_ORTHO:
00018     mTransform = makeTransformOrtho(-mSize[0]*0.5, mSize[0]*0.5,-mSize[1]*0.5,mSize[1]*0.5,mZNear,mZFar);
00019     break;
00020   }
00021 }
00022 
00023 void Projection::computeInverse()
00024 {
00025   switch(mProjectionType)
00026   {
00027   case ProjectionType_PERSPECTIVE:
00028     mInverse = makeInversePerspective(mFOVY, mAspect, mZNear, mZFar);
00029     break;
00030   case ProjectionType_ORTHO:
00031     mInverse = makeInverseOrtho(-mSize[0]*0.5, mSize[0]*0.5,-mSize[1]*0.5,mSize[1]*0.5,mZNear,mZFar);
00032     break;
00033   }
00034 }
00035 
00036 void Projection::setProjectionType(ProjectionType pt)
00037 {
00038   mProjectionType = pt;
00039   // setup default values for projection type
00040   switch(mProjectionType)
00041   {
00042   case ProjectionType_ORTHO:
00043     mZNear =  0.1;
00044     mZFar  =  mZNear + mZSize;
00045     break;
00046   case ProjectionType_PERSPECTIVE:
00047     setFOVY(45.0);
00048     break;
00049   }
00050 }
00051 
00052 /*
00053 void Projection::setViewSize(double size)
00054 {
00055   double s = size * 0.5;
00056   mZNear = s / tan(mFOVY*0.5);
00057   mZFar  = mZNear + mZSize;
00058 }
00059 */
00060 
00061 
00062 void Projection::setAspect(double aspect)
00063 { 
00064   mAspect = aspect; 
00065 }
00066 
00067 void Projection::setViewSize(const Vec2d& size) 
00068 { 
00069   mSize = size;
00070   switch(mProjectionType)
00071   {
00072   case ProjectionType_PERSPECTIVE:
00073     {
00074       double s = Math::Min(size[0],size[1]);
00075       mZNear = 0.3; // tan(Math::deg2Rad(mFOVY)*0.5) * s;
00076       mZFar  = mZNear + mZSize;
00077     }
00078     break;
00079   }
00080 }
00081 
00082 
00083 const Vec2d& Projection::getViewSize() const 
00084 { 
00085   return mSize; 
00086 }
00087 
00088 void Projection::setViewWidth(double w) 
00089 { 
00090   setViewSize( Vec2d(w,w/mAspect ) ); 
00091 }
00092 
00093 double Projection::getViewWidth() const 
00094 { 
00095   return mSize[0]; 
00096 }
00097 
00098 void Projection::setViewHeight(double h) 
00099 { 
00100   setViewSize( Vec2d(h*mAspect,h) ); 
00101 }
00102 
00103 double Projection::getViewHeight() const 
00104 { 
00105   return mSize[1]; 
00106 }
00107 
00108 void         Projection::setFOVY(double angle) 
00109 {    
00110   mFOVY  = angle; 
00111   //  mZNear = ( sqrt( pow(mSize[1]*0.5,2)*2 ) ) / tan(Math::deg2Rad(mFOVY));
00112   // mZFar  = mZNear + 200.0;
00113   // mZNear = 0.1;
00114   // mZFar  = mZNear+mZSize;
00115 }
00116 
00117 double Projection::getFOVY() const 
00118 { 
00119   return mFOVY; 
00120 }
00121 
00122 /*
00123 const int* Projection::getGLViewport() 
00124 {
00125   return mGLViewport;
00126 }
00127 */
00128 
00129 double Projection::getZNear() const 
00130 {
00131   return mZNear;
00132 }
00133 
00134 double Projection::getZFar() const 
00135 {
00136   return mZFar;
00137 }
00138 
00139 /*
00140 void Projection::computeTransformGL()
00141 {
00142   glPushAttrib(GL_TRANSFORM_BIT);
00143   glMatrixMode(GL_MODELVIEW);  
00144   glPushMatrix();
00145   glLoadIdentity();
00146   switch(mProjectionType)
00147   {
00148   case ProjectionType_ORTHO:
00149     glOrtho(-mSize[0]*0.5, mSize[0]*0.5,-mSize[1]*0.5,mSize[1]*0.5,mZNear,mZFar);
00150     break;
00151   case ProjectionType_PERSPECTIVE:
00152     gluPerspective(mFOVY, mAspect, mZNear, mZFar);
00153     break;
00154   }
00155   double d[16];
00156   glGetDoublev(GL_MODELVIEW_MATRIX, reinterpret_cast<GLdouble*>(d ) );
00157   mTransform.set( mProjMatrix );  
00158   glPopMatrix();
00159   glPopAttrib();
00160 }
00161 */
00162 
00163 #if 0
00164 ProjectionOrtho::ProjectionOrtho()
00165 {
00166 }
00167 
00168 void ProjectionOrtho::computeTransform(Matrix44d& m)
00169 {
00170   m = makeTransformOrtho(mpMin[0],mpMax[0],mpMin[1],mpMax[1],mpMin[2],mpMax[3]);
00171 }
00172 
00173 void ProjectionOrtho::computeInverse(Matrix44d& m)
00174 {
00175   m = makeInverseOrtho(mpMin[0],mpMax[0],mpMin[1],mpMax[1],mpMin[2],mpMax[3]);
00176 }
00177 
00178 void ProjectionOrtho::setAABox(const AABoxd& aabox)
00179 {
00180   mAABox = aabox;
00181 }
00182 
00183 
00184 #endif
00185 
00186 /*
00187 void Projection::setupViewport()
00188 {
00189   glGetIntegerv(GL_VIEWPORT, &mGLViewport[0]);
00190 }
00191 */
00192 
00193 #if 0
00194 void Projection::setupProjection()
00195 {
00196   // setupViewport();
00197   glMatrixMode(GL_PROJECTION);  
00198   glLoadIdentity();
00199   switch(mProjectionType)
00200   {
00201   case ProjectionType_ORTHO:
00202     glOrtho(-mSize[0]*0.5, mSize[0]*0.5,-mSize[1]*0.5,mSize[1]*0.5,mZNear,mZFar);
00203     break;
00204   case ProjectionType_PERSPECTIVE:
00205     gluPerspective(mFOVY, mAspect, mZNear, mZFar);
00206     break;
00207   }
00208   glGetDoublev(GL_PROJECTION_MATRIX, reinterpret_cast<GLdouble*>( &mProjMatrix[0] ) );
00209   mTransform.set( mProjMatrix );
00210 }
00211 #endif
00212 
00213 #if 0
00214 void ProjectionPerspective::computeTransformMatrix(Matrix44d& m)
00215 {
00216   m = makeTransformPerspective(mFOVY,mAspect,mZNear,mZFar);
00217 }
00218 void ProjectionOrtho::computeTransformMatrix(Matrix44d& m)
00219 {
00220   m = makeTransformOrtho(mAABox.getMin()[0],mAABox.getMax()[0],mAABox.getMin()[1],mAABox.getMax()[1],mAABox.getMin()[2],mAABox.getMax()[2]);
00221 }
00222 
00223 
00224 #endif