00001 /* MAINATINER: Martin */ 00002 00003 #ifndef _CAMERA_H 00004 #define _CAMERA_H 00005 00006 #include "SDL_opengl.h" 00007 #include "frustum.h" 00008 00009 00010 class Camera 00011 { 00012 00013 public: 00014 00015 struct Perspective { 00016 GLdouble 00017 fovx, 00018 aspect, 00019 zNear, 00020 zFar; 00021 }; 00022 00023 Camera(void); 00024 Camera(const GLVector3d & pos, const GLVector3d & ref, const GLVector3d & up); 00025 virtual ~Camera(void); 00026 00027 inline GLVector3d& getPos(GLVector3d &pos) const; 00028 inline GLVector3d& getDir(GLVector3d &dir) const; 00029 inline GLVector3d& getRef(GLVector3d &ref) const; 00030 inline GLVector3d& getUp (GLVector3d &up ) const; 00031 00032 inline GLVector3d getPos() const; 00033 inline GLVector3d getDir() const; 00034 inline GLVector3d getRef() const; 00035 inline GLVector3d getUp () const; 00036 00037 inline void setPos(const GLVector3d &pos); 00038 inline void setDir(const GLVector3d &dir); 00039 inline void setRef(const GLVector3d &ref); 00040 inline void setUp (const GLVector3d &up); 00041 00042 void setPerspective(const GLdouble fovx, const GLdouble aspect, const GLdouble zNear, const GLdouble zFar); 00043 00044 void computeLookAt(GLMatrix4d &m); 00045 void computePerspective(GLMatrix4d &m); 00046 void computeFrustum(); 00047 Frustum getFrustum() const { 00048 return mFrustum; 00049 } 00050 00051 void gluLookAt(); 00052 void gluPerspective(); 00053 00054 void setView(); 00055 00056 protected: 00057 00058 GLVector3d mPosition; 00059 GLVector3d mReferencePoint; 00060 GLVector3d mUpVector; 00061 Frustum mFrustum; 00062 00063 private: 00064 00065 Perspective mPerspective; 00066 bool mPerspectiveChanged; 00067 }; 00068 00069 GLVector3d& Camera::getPos(GLVector3d &pos) const { return pos = mPosition; } 00070 GLVector3d& Camera::getDir(GLVector3d &dir) const { return dir = mReferencePoint - mPosition; } 00071 GLVector3d& Camera::getRef(GLVector3d &ref) const { return ref = mReferencePoint; } 00072 GLVector3d& Camera::getUp (GLVector3d &up) const { return up = mUpVector; } 00073 00074 GLVector3d Camera::getPos() const { GLVector3d tmp; getPos(tmp); return tmp; } 00075 GLVector3d Camera::getDir() const { GLVector3d tmp; getDir(tmp); return tmp; } 00076 GLVector3d Camera::getRef() const { GLVector3d tmp; getRef(tmp); return tmp; } 00077 GLVector3d Camera::getUp () const { GLVector3d tmp; getUp(tmp); return tmp; } 00078 00079 void Camera::setPos(const GLVector3d &pos) { mPosition = pos; } 00080 void Camera::setDir(const GLVector3d &dir) { mReferencePoint = mPosition + dir; } 00081 void Camera::setRef(const GLVector3d &ref) { mReferencePoint = ref; } 00082 void Camera::setUp (const GLVector3d &up) { mUpVector = up; } 00083 00084 #endif // _CAMERA_H
1.4.5