KGLLib
camera.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef KGLLIB_CAMERA_H
00019 #define KGLLIB_CAMERA_H
00020
00021
00022 #include "kgllib.h"
00023
00024 #include <Eigen/Geometry>
00025
00026 namespace KGLLib
00027 {
00028
00060 class KGLLIB_EXPORT Camera
00061 {
00062 public:
00063 Camera();
00064 virtual ~Camera();
00065
00071 virtual void applyPerspective();
00078 virtual void applyView(bool reset = true);
00079
00084 virtual void applyViewport();
00085
00089 void setViewport(int x, int y, int width, int height);
00090
00094 void setFoV(float fov);
00099 void setAspect(float aspect);
00111 void setDepthRange(float near, float far);
00112
00116 void setPosition(const Eigen::Vector3f& pos);
00117 void setPosition(float x, float y, float z) { setPosition(Eigen::Vector3f(x, y, z)); }
00122 void setLookAt(const Eigen::Vector3f& lookat);
00123 void setLookAt(float x, float y, float z) { setLookAt(Eigen::Vector3f(x, y, z)); }
00128 void setUp(const Eigen::Vector3f& up);
00129 void setUp(float x, float y, float z) { setUp(Eigen::Vector3f(x, y, z)); }
00135 void setDirection(const Eigen::Vector3f& dir);
00136 void setDirection(float x, float y, float z) { setDirection(Eigen::Vector3f(x, y, z)); }
00137
00138 Eigen::Vector3f position() const { return mPosition; }
00139 Eigen::Vector3f lookAt() const { return mLookAt; }
00140 Eigen::Vector3f up() const { return mUp; }
00141
00154 void setModelviewMatrix(const Eigen::Transform3f& modelview);
00167 void setProjectionMatrix(const Eigen::Transform3f& projection);
00168
00174 Eigen::Transform3f modelviewMatrix() const;
00181 Eigen::Transform3f projectionMatrix() const;
00182
00189 Eigen::Vector3f project(const Eigen::Vector3f& v, bool* ok = 0) const;
00196 Eigen::Vector3f unProject(const Eigen::Vector3f& v, bool* ok = 0) const;
00197
00198 protected:
00199 void recalculateModelviewMatrix();
00200 void recalculateProjectionMatrix();
00201
00202 protected:
00203 Eigen::Vector3f mPosition;
00204 Eigen::Vector3f mLookAt;
00205 Eigen::Vector3f mUp;
00206 float mFoV, mAspect, mDepthNear, mDepthFar;
00207
00208 Eigen::Transform3f mModelviewMatrix;
00209 bool mModelviewMatrixDirty;
00210 Eigen::Transform3f mProjectionMatrix;
00211 bool mProjectionMatrixDirty;
00212 int mViewport[4];
00213 };
00214
00215 }
00216
00217 #endif