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

CCamera.h

Go to the documentation of this file.
00001 /*
00002  * CCamera.h
00003  * $Id: CCamera.h,v 1.1.1.1 2001/06/06 15:36:52 guenth 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  */
00022 
00023 //  Description : Class CCamera
00024 //  Purpose     : Provides funcionality (rotate, move, etc.)
00025 
00026 #ifndef __CCAMERA_H_
00027 #define __CCAMERA_H_
00028 
00029 
00030 // Qt
00032 
00033 
00034 // System
00036 #include <math.h>
00037 #include <iostream.h>
00038 
00039 
00040 // Own
00042 #include "GeoGeneric.h"
00043 #include "CP4D.h"
00044 #include "CV4D.h"
00045 #include "CP3D.h"
00046 #include "CV3D.h"
00047 #include "CMat4D.h"
00048 #include "CBoundingBox3D.h"
00049 
00050 
00052 
00059 class CCamera {
00060 
00061 public:
00063   enum CameraType {
00064     orthographic,       
00065     perspective         
00066   };
00067 
00068 
00072   CCamera() :
00073     m_CameraType( perspective ),
00074     m_cBBox(CBoundingBox3D(-1, -1, -1, 1, 1, 1)),
00075     m_rdVerAngle(30.0),
00076     m_rdRatio(4.0/3.0),
00077     m_rdNearPlane(0.0001), m_rdFarPlane(10000.0),
00078     m_nVPHeight(480),
00079     m_fValidViewDir(false), m_fValidViewRight(false),
00080     m_cEyePos(CP3D(0,0,-1)),
00081     m_cRefPoint(CP3D(0,0,0)),
00082     m_cViewUp(CV3D(0,1,0))
00083     {
00084          setEyePos(m_cEyePos); // updates near/far plane
00085     };
00086 
00087 
00100   CCamera( double rdEyePosX, double rdEyePosY, double rdEyePosZ,
00101            double rdRefPointX, double rdRefPointY, double rdRefPointZ,
00102            double rdViewUpX, double rdViewUpY, double rdViewUpZ,
00103            const CBoundingBox3D &cBBox=CBoundingBox3D(-1, -1, -1, 1, 1, 1),
00104            double rdVerAngle=30.0, int nVPHeight=480,
00105            double rdRatio=4.0/3.0,
00106            double rdNearPlane=0.0001, double rdFarPlane=10000.0)
00107     : m_CameraType( perspective ),
00108       m_cBBox(cBBox),
00109       m_rdVerAngle(rdVerAngle),
00110       m_rdRatio(rdRatio),
00111       m_rdNearPlane(rdNearPlane), m_rdFarPlane(rdFarPlane),
00112       m_nVPHeight(nVPHeight),
00113       m_fValidViewDir(false), m_fValidViewRight(false),
00114       m_cEyePos(CP3D(rdEyePosX, rdEyePosY, rdEyePosZ)),
00115       m_cRefPoint(CP3D(rdRefPointX, rdRefPointY, rdRefPointZ)),
00116       m_cViewUp(CV3D(rdViewUpX, rdViewUpY, rdViewUpZ))
00117     { 
00118          setEyePos(m_cEyePos); // updates near/far plane
00119     };
00120 
00122   CCamera( CP3D cEyePos, CP3D cRefPoint, CV3D cViewUp,
00123            const CBoundingBox3D &cBBox=CBoundingBox3D(-1, -1, -1, 1, 1, 1),
00124            double rdVerAngle=30.0, int nVPHeight=480,
00125            double rdRatio=4.0/3.0,
00126            double rdNearPlane=0.0001, double rdFarPlane=10000.0,
00127            CameraType ctype=perspective)
00128     : m_CameraType( ctype ),
00129       m_cBBox(cBBox),
00130       m_rdVerAngle(rdVerAngle),
00131       m_rdRatio(rdRatio),
00132       m_rdNearPlane(rdNearPlane), m_rdFarPlane(rdFarPlane),
00133       m_nVPHeight(nVPHeight),
00134       m_fValidViewDir(false), m_fValidViewRight(false),
00135       m_cEyePos(cEyePos),
00136       m_cRefPoint(cRefPoint),
00137       m_cViewUp(cViewUp)
00138     {
00139          setEyePos(cEyePos); // updates near/far plane
00140     };
00141 
00142   // Use default copy constructor
00144 
00146   virtual ~CCamera() {};
00147 
00154   void rotate(double rdAngle, CV3D cAxis, bool global=true);
00155 
00159   void translate(CV3D vDiff);
00160 
00162   void setRefPoint(const CP3D &cRefPoint) {
00163     m_fValidViewRight = m_fValidViewDir = false;
00164     m_cRefPoint = cRefPoint;
00165   };
00166 
00168   const CP3D& getRefPoint() const {
00169     return m_cRefPoint;
00170   };
00171 
00173   void setEyePos(const CP3D &cEyePos);
00174 
00176   const CP3D& getEyePos() const {
00177     return m_cEyePos;
00178   };
00179 
00181   void setViewUp(const CV3D &cViewUp) {
00182     m_cViewUp = cViewUp;
00183   };
00184 
00186   const CV3D& getViewUp() const {
00187     return m_cViewUp;
00188   };
00189 
00191   // Same problem as before.
00192   const CV3D& getViewDir() const;
00193 
00195   // Same problem as before.
00196   const CV3D& getViewRight() const;
00197 
00212   void setHVAngle(double rdHorAngle, double rdVerAngle) {
00213     m_rdVerAngle = rdVerAngle>180.0 ? 180.0 : rdVerAngle;
00214 
00215     rdHorAngle = rdHorAngle/180.0*M_PI;
00216     rdVerAngle = rdVerAngle/180.0*M_PI;
00217 
00218     //m_rdRatio = rdHorAngle/rdVerAngle;
00219     m_rdRatio = tan(rdHorAngle)/tan(rdVerAngle);
00220   }
00221 
00226   void getHVAngle(double &rdHorAngle, double &rdVerAngle) const {
00227     rdVerAngle = m_rdVerAngle;
00228     //rdHorAngle = m_rdVerAngle * m_rdRatio;
00229     rdHorAngle = atan(tan(m_rdVerAngle) * m_rdRatio);
00230     //cout << rdHorAngle << "," << rdVerAngle << endl;
00231   }
00232 
00234   void setClipPlanes(double rdNearPlane, double rdFarPlane) {
00235     m_rdNearPlane = rdNearPlane;
00236     m_rdFarPlane = rdFarPlane;
00237   }
00238 
00240   void getClipPlanes(double &rdNearPlane, double &rdFarPlane) const {
00241     rdNearPlane = m_rdNearPlane;
00242     rdFarPlane = m_rdFarPlane;
00243   }
00244 
00247   void setBoundingBox(const CBoundingBox3D &cBBox, bool fViewAll=true) {
00248     m_cBBox = cBBox;
00249     if (fViewAll)
00250       viewAll();
00251   }
00252 
00253 
00255   const CBoundingBox3D &getBoundingBox()  const {
00256      return m_cBBox;
00257   }
00258     
00260   void setCameraType( CameraType type ) {
00261     m_CameraType = type;
00262   };
00263 
00265   CameraType getCameraType() const {
00266     return m_CameraType;
00267   };
00268 
00278   void getVVolume( double array[6] );
00279 
00293   void setVPRes(  int nVPWidth, int nVPHeight) {
00294     m_nVPHeight = nVPHeight;
00295 
00296     m_rdRatio = double(nVPWidth)/nVPHeight;
00297   }
00298 
00300   void getVPRes(  int &nVPWidth, int &nVPHeight) const {
00301     nVPHeight = m_nVPHeight;
00302     nVPWidth = int(m_nVPHeight * m_rdRatio);
00303   }
00304 
00312   void getVPParams( CP3D &origin, CV3D &xStep, CV3D &yStep, int nXSize, int  nYSize);
00313 
00316   CMat4D getModelview();
00317 
00319   CMat4D getOrtho();
00320 
00322   CMat4D getFrustrum();
00323 
00326   CMat4D getProjection();
00327 
00330   CMat4D getVPTrans(int nXSize, int nYSize);
00331 
00334   void setRatio(double rdRatio) {
00335     m_rdRatio = rdRatio;
00336   }
00337 
00339   double getRatio() const {
00340     return m_rdRatio;
00341   }
00342 
00344   void setFovy(double rdFovy) {
00345     m_rdVerAngle = rdFovy;
00346   }
00347 
00349   double getFovy() const {
00350     return m_rdVerAngle;
00351   }
00352 
00354   void setVPHeight(int nVPHeight) {
00355     m_nVPHeight = nVPHeight;
00356   }
00357 
00359   int getVPHeight() const {
00360     return m_nVPHeight;
00361   }
00362 
00365   void viewAll();
00366 
00368   void print();
00369 
00371   //friend ostream& operator<<(ostream&, const CCamera&);
00372 
00374   //friend istream& operator>>(istream&, CCamera&);
00375 
00376 
00377 
00378 private:
00380   // PRIVATE METHODS //
00382 
00384   // PRIVATE MEMBERS //
00386 
00387   CameraType m_CameraType; // holds the current type of the camera
00388   CBoundingBox3D m_cBBox;    // boundingbox of the scene is needed
00389                            // to switch bwtween perspective and orthographic
00390 
00391   double m_rdVerAngle;     // vertical focus angle in degrees
00392   double m_rdRatio;        // ratio between height and width, or hor. and vert. angle
00393 
00394   double m_rdNearPlane;    // distance between eyepoint and near clipplane
00395   double m_rdFarPlane;     // distance between eyepoint and far clipplane
00396 
00397   int m_nVPHeight;         // size of viewplane in y-direction
00398 
00399   mutable bool m_fValidViewDir;    // is true if the m_cViewDir has a valid value
00400   mutable bool m_fValidViewRight;  // is true if the m_cViewRight has a valid value
00401 
00402   CP3D m_cEyePos;
00403   CP3D m_cRefPoint;
00404   CV3D m_cViewUp;
00405 
00406   mutable CV3D m_cViewDir;       // NOTE: Don't use this direct. Use 'getViewDir()' instead.
00407   mutable CV3D m_cViewRight;     // NOTE: Don't use this direct. Use 'getViewRight()' instead.
00408 
00409 };
00410 
00411 #endif // __CCAMERA_H_
00412 

Generated at Thu Oct 4 17:17:24 2001 for QGLViewer by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001