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
00044 #include <iostream.h>
00045
00046
00047
00049
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);
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);
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);
00152 };
00153
00154
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
00204 const CV3D& getViewDir() const;
00205
00207
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
00231 m_rdRatio = tan(rdHorAngle)/tan(rdVerAngle);
00232 }
00233
00238 void getHVAngle(double &rdHorAngle, double &rdVerAngle) const {
00239 rdVerAngle = m_rdVerAngle;
00240
00241 rdHorAngle = atan(tan(m_rdVerAngle) * m_rdRatio);
00242
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
00394
00396
00397
00398
00399
00400 private:
00402
00404
00406
00408
00409 CameraType m_CameraType;
00410 CBoundingBox3D m_cBBox;
00411
00412
00413 double m_rdVerAngle;
00414 double m_rdRatio;
00415
00416 double m_rdNearPlane;
00417 double m_rdFarPlane;
00418
00419 int m_nVPHeight;
00420
00421 mutable bool m_fValidViewDir;
00422 mutable bool m_fValidViewRight;
00423
00424 CP3D m_cEyePos;
00425 CP3D m_cRefPoint;
00426 CV3D m_cViewUp;
00427
00428 mutable CV3D m_cViewDir;
00429 mutable CV3D m_cViewRight;
00430
00431 int m_nTimeStep;
00432 };
00433
00434 #endif // __CCAMERA_H_
00435