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 #ifndef __CCAMERA_H_
00027 #define __CCAMERA_H_
00028
00029
00030
00032
00033
00034
00036
00037 #include <iostream.h>
00038
00039
00040
00042
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);
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);
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);
00140 };
00141
00142
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
00192 const CV3D& getViewDir() const;
00193
00195
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
00219 m_rdRatio = tan(rdHorAngle)/tan(rdVerAngle);
00220 }
00221
00226 void getHVAngle(double &rdHorAngle, double &rdVerAngle) const {
00227 rdVerAngle = m_rdVerAngle;
00228
00229 rdHorAngle = atan(tan(m_rdVerAngle) * m_rdRatio);
00230
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
00372
00374
00375
00376
00377
00378 private:
00380
00382
00384
00386
00387 CameraType m_CameraType;
00388 CBoundingBox3D m_cBBox;
00389
00390
00391 double m_rdVerAngle;
00392 double m_rdRatio;
00393
00394 double m_rdNearPlane;
00395 double m_rdFarPlane;
00396
00397 int m_nVPHeight;
00398
00399 mutable bool m_fValidViewDir;
00400 mutable bool m_fValidViewRight;
00401
00402 CP3D m_cEyePos;
00403 CP3D m_cRefPoint;
00404 CV3D m_cViewUp;
00405
00406 mutable CV3D m_cViewDir;
00407 mutable CV3D m_cViewRight;
00408
00409 };
00410
00411 #endif // __CCAMERA_H_
00412