Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

CCamera.h

Go to the documentation of this file.
00001 /*
00002  * CCamera.h
00003  * $Id: CCamera.h,v 1.4 2002/11/13 14:09:28 gwetekam Exp $
00004  *
00005  * Copyright (C) 1999, 2000 Markus Janich
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * As a special exception to the GPL, the QGLViewer authors (Markus
00022  * Janich, Michael Meissner, Richard Guenther, Alexander Buck and Thomas
00023  * Woerner) give permission to link this program with Qt (non-)commercial
00024  * edition, and distribute the resulting executable, without including
00025  * the source code for the Qt (non-)commercial edition in the source
00026  * distribution.
00027  *
00028  */
00029 
00030 //  Description : Class CCamera
00031 //  Purpose     : Provides funcionality (rotate, move, etc.)
00032 
00033 #ifndef __CCAMERA_H_
00034 #define __CCAMERA_H_
00035 
00036 
00037 // Qt
00039 
00040 
00041 // System
00043 #include <math.h>
00044 #include <iostream.h>
00045 
00046 
00047 // Own
00049 #include "GeoGeneric.h"
00050 #include "CP4D.h"
00051 #include "CV4D.h"
00052 #include "CP3D.h"
00053 #include "CV3D.h"
00054 #include "CMat4D.h"
00055 #include "CBoundingBox3D.h"
00056 
00057 
00059 
00066 class CCamera {
00067 
00068 public:
00070   enum CameraType {
00071     orthographic,       
00072     perspective         
00073   };
00074 
00075 
00079   CCamera() :
00080     m_CameraType( perspective ),
00081     m_cBBox(CBoundingBox3D(-1, -1, -1, 1, 1, 1)),
00082     m_rdVerAngle(30.0),
00083     m_rdRatio(4.0/3.0),
00084     m_rdNearPlane(0.0001), m_rdFarPlane(10000.0),
00085     m_nVPHeight(480),
00086     m_fValidViewDir(false), m_fValidViewRight(false),
00087     m_cEyePos(CP3D(0,0,-1)),
00088     m_cRefPoint(CP3D(0,0,0)),
00089     m_cViewUp(CV3D(0,1,0)),
00090     m_nTimeStep(0)
00091     {
00092          setEyePos(m_cEyePos); // updates near/far plane
00093     };
00094 
00095 
00108   CCamera( double rdEyePosX, double rdEyePosY, double rdEyePosZ,
00109            double rdRefPointX, double rdRefPointY, double rdRefPointZ,
00110            double rdViewUpX, double rdViewUpY, double rdViewUpZ,
00111            const CBoundingBox3D &cBBox=CBoundingBox3D(-1, -1, -1, 1, 1, 1),
00112            double rdVerAngle=30.0, int nVPHeight=480,
00113            double rdRatio=4.0/3.0,
00114            double rdNearPlane=0.0001, double rdFarPlane=10000.0,
00115            int nTimeStep = 0)
00116     : m_CameraType( perspective ),
00117       m_cBBox(cBBox),
00118       m_rdVerAngle(rdVerAngle),
00119       m_rdRatio(rdRatio),
00120       m_rdNearPlane(rdNearPlane), m_rdFarPlane(rdFarPlane),
00121       m_nVPHeight(nVPHeight),
00122       m_fValidViewDir(false), m_fValidViewRight(false),
00123       m_cEyePos(CP3D(rdEyePosX, rdEyePosY, rdEyePosZ)),
00124       m_cRefPoint(CP3D(rdRefPointX, rdRefPointY, rdRefPointZ)),
00125       m_cViewUp(CV3D(rdViewUpX, rdViewUpY, rdViewUpZ)),
00126      m_nTimeStep(nTimeStep)
00127     { 
00128          setEyePos(m_cEyePos); // updates near/far plane
00129     };
00130 
00132   CCamera( CP3D cEyePos, CP3D cRefPoint, CV3D cViewUp,
00133            const CBoundingBox3D &cBBox=CBoundingBox3D(-1, -1, -1, 1, 1, 1),
00134            double rdVerAngle=30.0, int nVPHeight=480,
00135            double rdRatio=4.0/3.0,
00136            double rdNearPlane=0.0001, double rdFarPlane=10000.0,
00137            CameraType ctype=perspective,
00138            int nTimeStep = 0)
00139     : m_CameraType( ctype ),
00140       m_cBBox(cBBox),
00141       m_rdVerAngle(rdVerAngle),
00142       m_rdRatio(rdRatio),
00143       m_rdNearPlane(rdNearPlane), m_rdFarPlane(rdFarPlane),
00144       m_nVPHeight(nVPHeight),
00145       m_fValidViewDir(false), m_fValidViewRight(false),
00146       m_cEyePos(cEyePos),
00147       m_cRefPoint(cRefPoint),
00148       m_cViewUp(cViewUp),
00149      m_nTimeStep(nTimeStep)
00150     {
00151          setEyePos(cEyePos); // updates near/far plane
00152     };
00153 
00154   // Use default copy constructor
00156 
00158   virtual ~CCamera() {};
00159 
00166   void rotate(double rdAngle, CV3D cAxis, bool global=true);
00167 
00171   void translate(CV3D vDiff);
00172 
00174   void setRefPoint(const CP3D &cRefPoint) {
00175     m_fValidViewRight = m_fValidViewDir = false;
00176     m_cRefPoint = cRefPoint;
00177   };
00178 
00180   const CP3D& getRefPoint() const {
00181     return m_cRefPoint;
00182   };
00183 
00185   void setEyePos(const CP3D &cEyePos);
00186 
00188   const CP3D& getEyePos() const {
00189     return m_cEyePos;
00190   };
00191 
00193   void setViewUp(const CV3D &cViewUp) {
00194     m_cViewUp = cViewUp;
00195   };
00196 
00198   const CV3D& getViewUp() const {
00199     return m_cViewUp;
00200   };
00201 
00203   // Same problem as before.
00204   const CV3D& getViewDir() const;
00205 
00207   // Same problem as before.
00208   const CV3D& getViewRight() const;
00209 
00224   void setHVAngle(double rdHorAngle, double rdVerAngle) {
00225     m_rdVerAngle = rdVerAngle>180.0 ? 180.0 : rdVerAngle;
00226 
00227     rdHorAngle = rdHorAngle/180.0*M_PI;
00228     rdVerAngle = rdVerAngle/180.0*M_PI;
00229 
00230     //m_rdRatio = rdHorAngle/rdVerAngle;
00231     m_rdRatio = tan(rdHorAngle)/tan(rdVerAngle);
00232   }
00233 
00238   void getHVAngle(double &rdHorAngle, double &rdVerAngle) const {
00239     rdVerAngle = m_rdVerAngle;
00240     //rdHorAngle = m_rdVerAngle * m_rdRatio;
00241     rdHorAngle = atan(tan(m_rdVerAngle) * m_rdRatio);
00242     //cout << rdHorAngle << "," << rdVerAngle << endl;
00243   }
00244 
00246   void setClipPlanes(double rdNearPlane, double rdFarPlane) {
00247     m_rdNearPlane = rdNearPlane;
00248     m_rdFarPlane = rdFarPlane;
00249   }
00250 
00252   void getClipPlanes(double &rdNearPlane, double &rdFarPlane) const {
00253     rdNearPlane = m_rdNearPlane;
00254     rdFarPlane = m_rdFarPlane;
00255   }
00256 
00259   void setBoundingBox(const CBoundingBox3D &cBBox, bool fViewAll=true) {
00260     m_cBBox = cBBox;
00261     if (fViewAll)
00262       viewAll();
00263   }
00264 
00265 
00267   const CBoundingBox3D &getBoundingBox()  const {
00268      return m_cBBox;
00269   }
00270     
00272   void setCameraType( CameraType type ) {
00273     m_CameraType = type;
00274   };
00275 
00277   CameraType getCameraType() const {
00278     return m_CameraType;
00279   };
00280 
00290   void getVVolume( double array[6] ) const;
00291 
00305   void setVPRes(  int nVPWidth, int nVPHeight) {
00306     m_nVPHeight = nVPHeight;
00307 
00308     m_rdRatio = double(nVPWidth)/nVPHeight;
00309   }
00310 
00312   void getVPRes(  int &nVPWidth, int &nVPHeight) const {
00313     nVPHeight = m_nVPHeight;
00314     nVPWidth = int(m_nVPHeight * m_rdRatio);
00315   }
00316 
00324   void getVPParams( CP3D &origin, CV3D &xStep, CV3D &yStep, int nXSize, int  nYSize) const;
00325 
00328   CMat4D getModelview() const;
00329 
00331   CMat4D getOrtho() const;
00332 
00334   CMat4D getFrustrum() const;
00335 
00338   CMat4D getProjection() const;
00339 
00342   CMat4D getVPTrans(int nXSize, int nYSize) const;
00343 
00346   void setRatio(double rdRatio) {
00347     m_rdRatio = rdRatio;
00348   }
00349 
00351   double getRatio() const {
00352     return m_rdRatio;
00353   }
00354 
00356   void setFovy(double rdFovy) {
00357     m_rdVerAngle = rdFovy;
00358   }
00359 
00361   double getFovy() const {
00362     return m_rdVerAngle;
00363   }
00364 
00366   void setVPHeight(int nVPHeight) {
00367     m_nVPHeight = nVPHeight;
00368   }
00369 
00371   int getVPHeight() const {
00372     return m_nVPHeight;
00373   }
00374 
00376   void setTimeStep(int nTimeStep) {
00377      m_nTimeStep = nTimeStep;
00378   }
00379 
00381   int getTimeStep() const {
00382      return m_nTimeStep;
00383   }
00384 
00387   void viewAll();
00388 
00390   void print();
00391 
00393   //friend ostream& operator<<(ostream&, const CCamera&);
00394 
00396   //friend istream& operator>>(istream&, CCamera&);
00397 
00398 
00399 
00400 private:
00402   // PRIVATE METHODS //
00404 
00406   // PRIVATE MEMBERS //
00408 
00409   CameraType m_CameraType; // holds the current type of the camera
00410   CBoundingBox3D m_cBBox;    // boundingbox of the scene is needed
00411                            // to switch bwtween perspective and orthographic
00412 
00413   double m_rdVerAngle;     // vertical focus angle in degrees
00414   double m_rdRatio;        // ratio between height and width, or hor. and vert. angle
00415 
00416   double m_rdNearPlane;    // distance between eyepoint and near clipplane
00417   double m_rdFarPlane;     // distance between eyepoint and far clipplane
00418 
00419   int m_nVPHeight;         // size of viewplane in y-direction
00420 
00421   mutable bool m_fValidViewDir;    // is true if the m_cViewDir has a valid value
00422   mutable bool m_fValidViewRight;  // is true if the m_cViewRight has a valid value
00423 
00424   CP3D m_cEyePos;
00425   CP3D m_cRefPoint;
00426   CV3D m_cViewUp;
00427 
00428   mutable CV3D m_cViewDir;       // NOTE: Don't use this direct. Use 'getViewDir()' instead.
00429   mutable CV3D m_cViewRight;     // NOTE: Don't use this direct. Use 'getViewRight()' instead.
00430 
00431   int m_nTimeStep;
00432 };
00433 
00434 #endif // __CCAMERA_H_
00435 

Generated on Wed Mar 5 18:23:25 2003 for QGLViewer by doxygen1.3-rc3