00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __CCAMERA_H_
00034 #define __CCAMERA_H_
00035
00036
00037
00039
00040
00041
00043 #include <math.h>
00044 #if _MSC_VER >= 1300
00045 #include <iostream>
00046 #else
00047 #include <iostream.h>
00048 #endif
00049
00050
00052 #include "GeoGeneric.h"
00053 #include "CP4D.h"
00054 #include "CV4D.h"
00055 #include "CP3D.h"
00056 #include "CV3D.h"
00057 #include "CMat4D.h"
00058 #include "CBoundingBox3D.h"
00059
00060 #ifndef M_PI
00061 #define M_PI 3.14159265358979323846
00062 #endif
00063
00064
00066
00073 class CCamera {
00074
00075 public:
00077 enum CameraType {
00078 orthographic,
00079 perspective
00080 };
00081
00082
00086 CCamera() :
00087 m_CameraType( perspective ),
00088 m_cBBox(CBoundingBox3D(-1, -1, -1, 1, 1, 1)),
00089 m_rdVerAngle(30.0),
00090 m_rdRatio(4.0/3.0),
00091 m_rdNearPlane(0.0001), m_rdFarPlane(10000.0),
00092 m_nVPHeight(480),
00093 m_fValidViewDir(false), m_fValidViewRight(false),
00094 m_cEyePos(CP3D(0,0,-1)),
00095 m_cRefPoint(CP3D(0,0,0)),
00096 m_cViewUp(CV3D(0,1,0)),
00097 m_nTimeStep(0)
00098 {
00099 setEyePos(m_cEyePos);
00100 };
00101
00102
00115 CCamera( double rdEyePosX, double rdEyePosY, double rdEyePosZ,
00116 double rdRefPointX, double rdRefPointY, double rdRefPointZ,
00117 double rdViewUpX, double rdViewUpY, double rdViewUpZ,
00118 const CBoundingBox3D &cBBox=CBoundingBox3D(-1, -1, -1, 1, 1, 1),
00119 double rdVerAngle=30.0, int nVPHeight=480,
00120 double rdRatio=4.0/3.0,
00121 double rdNearPlane=0.0001, double rdFarPlane=10000.0,
00122 int nTimeStep = 0)
00123 : m_CameraType( perspective ),
00124 m_cBBox(cBBox),
00125 m_rdVerAngle(rdVerAngle),
00126 m_rdRatio(rdRatio),
00127 m_rdNearPlane(rdNearPlane), m_rdFarPlane(rdFarPlane),
00128 m_nVPHeight(nVPHeight),
00129 m_fValidViewDir(false), m_fValidViewRight(false),
00130 m_cEyePos(CP3D(rdEyePosX, rdEyePosY, rdEyePosZ)),
00131 m_cRefPoint(CP3D(rdRefPointX, rdRefPointY, rdRefPointZ)),
00132 m_cViewUp(CV3D(rdViewUpX, rdViewUpY, rdViewUpZ)),
00133 m_nTimeStep(nTimeStep)
00134 {
00135 setEyePos(m_cEyePos);
00136 };
00137
00139 CCamera( CP3D cEyePos, CP3D cRefPoint, CV3D cViewUp,
00140 const CBoundingBox3D &cBBox=CBoundingBox3D(-1, -1, -1, 1, 1, 1),
00141 double rdVerAngle=30.0, int nVPHeight=480,
00142 double rdRatio=4.0/3.0,
00143 double rdNearPlane=0.0001, double rdFarPlane=10000.0,
00144 CameraType ctype=perspective,
00145 int nTimeStep = 0)
00146 : m_CameraType( ctype ),
00147 m_cBBox(cBBox),
00148 m_rdVerAngle(rdVerAngle),
00149 m_rdRatio(rdRatio),
00150 m_rdNearPlane(rdNearPlane), m_rdFarPlane(rdFarPlane),
00151 m_nVPHeight(nVPHeight),
00152 m_fValidViewDir(false), m_fValidViewRight(false),
00153 m_cEyePos(cEyePos),
00154 m_cRefPoint(cRefPoint),
00155 m_cViewUp(cViewUp),
00156 m_nTimeStep(nTimeStep)
00157 {
00158 setEyePos(cEyePos);
00159 };
00160
00161
00163
00165 virtual ~CCamera() {};
00166
00173 void rotate(double rdAngle, CV3D cAxis, bool global=true);
00174
00178 void translate(CV3D vDiff);
00179
00181 void setRefPoint(const CP3D &cRefPoint) {
00182 m_fValidViewRight = m_fValidViewDir = false;
00183 m_cRefPoint = cRefPoint;
00184 };
00185
00187 const CP3D& getRefPoint() const {
00188 return m_cRefPoint;
00189 };
00190
00192 void setEyePos(const CP3D &cEyePos);
00193
00195 const CP3D& getEyePos() const {
00196 return m_cEyePos;
00197 };
00198
00200 void setViewUp(const CV3D &cViewUp) {
00201 m_cViewUp = cViewUp;
00202 };
00203
00205 const CV3D& getViewUp() const {
00206 return m_cViewUp;
00207 };
00208
00210
00211 const CV3D& getViewDir() const;
00212
00214
00215 const CV3D& getViewRight() const;
00216
00231 void setHVAngle(double rdHorAngle, double rdVerAngle) {
00232 m_rdVerAngle = rdVerAngle>180.0 ? 180.0 : rdVerAngle;
00233
00234 rdHorAngle = rdHorAngle/180.0*M_PI;
00235 rdVerAngle = rdVerAngle/180.0*M_PI;
00236
00237
00238 m_rdRatio = tan(rdHorAngle)/tan(rdVerAngle);
00239 }
00240
00245 void getHVAngle(double &rdHorAngle, double &rdVerAngle) const {
00246 rdVerAngle = m_rdVerAngle;
00247
00248 rdHorAngle = atan(tan(m_rdVerAngle) * m_rdRatio);
00249
00250 }
00251
00253 void setClipPlanes(double rdNearPlane, double rdFarPlane) {
00254 m_rdNearPlane = rdNearPlane;
00255 m_rdFarPlane = rdFarPlane;
00256 }
00257
00259 void getClipPlanes(double &rdNearPlane, double &rdFarPlane) const {
00260 rdNearPlane = m_rdNearPlane;
00261 rdFarPlane = m_rdFarPlane;
00262 }
00263
00266 void setBoundingBox(const CBoundingBox3D &cBBox, bool fViewAll=true) {
00267 m_cBBox = cBBox;
00268 if (fViewAll)
00269 viewAll();
00270 }
00271
00272
00274 const CBoundingBox3D &getBoundingBox() const {
00275 return m_cBBox;
00276 }
00277
00279 void setCameraType( CameraType type ) {
00280 m_CameraType = type;
00281 };
00282
00284 CameraType getCameraType() const {
00285 return m_CameraType;
00286 };
00287
00297 void getVVolume( double array[6] ) const;
00298
00312 void setVPRes( int nVPWidth, int nVPHeight) {
00313 m_nVPHeight = nVPHeight;
00314
00315 m_rdRatio = double(nVPWidth)/nVPHeight;
00316 }
00317
00319 void getVPRes( int &nVPWidth, int &nVPHeight) const {
00320 nVPHeight = m_nVPHeight;
00321 nVPWidth = int(m_nVPHeight * m_rdRatio);
00322 }
00323
00331 void getVPParams( CP3D &origin, CV3D &xStep, CV3D &yStep, int nXSize, int nYSize) const;
00332
00335 CMat4D getModelview() const;
00336
00338 CMat4D getOrtho() const;
00339
00341 CMat4D getFrustrum() const;
00342
00345 CMat4D getProjection() const;
00346
00349 CMat4D getVPTrans(int nXSize, int nYSize) const;
00350
00353 void setRatio(double rdRatio) {
00354 m_rdRatio = rdRatio;
00355 }
00356
00358 double getRatio() const {
00359 return m_rdRatio;
00360 }
00361
00363 void setFovy(double rdFovy) {
00364 m_rdVerAngle = rdFovy;
00365 }
00366
00368 double getFovy() const {
00369 return m_rdVerAngle;
00370 }
00371
00373 void setVPHeight(int nVPHeight) {
00374 m_nVPHeight = nVPHeight;
00375 }
00376
00378 int getVPHeight() const {
00379 return m_nVPHeight;
00380 }
00381
00383 void setTimeStep(int nTimeStep) {
00384 m_nTimeStep = nTimeStep;
00385 }
00386
00388 int getTimeStep() const {
00389 return m_nTimeStep;
00390 }
00391
00394 void viewAll();
00395
00397 void print();
00398
00400
00401
00403
00404
00405
00406
00407 private:
00409
00411
00413
00415
00416 CameraType m_CameraType;
00417 CBoundingBox3D m_cBBox;
00418
00419
00420 double m_rdVerAngle;
00421 double m_rdRatio;
00422
00423 double m_rdNearPlane;
00424 double m_rdFarPlane;
00425
00426 int m_nVPHeight;
00427
00428 mutable bool m_fValidViewDir;
00429 mutable bool m_fValidViewRight;
00430
00431 CP3D m_cEyePos;
00432 CP3D m_cRefPoint;
00433 CV3D m_cViewUp;
00434
00435 mutable CV3D m_cViewDir;
00436 mutable CV3D m_cViewRight;
00437
00438 int m_nTimeStep;
00439 };
00440
00441 #endif // __CCAMERA_H_
00442