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
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef Camera_INCLUDE_ONCE
00033 #define Camera_INCLUDE_ONCE
00034
00035 #include <vlCore/checks.hpp>
00036 #include <vlCore/math_utils.hpp>
00037 #include <vlCore/Vector4.hpp>
00038 #include <vlGraphics/Framebuffer.hpp>
00039 #include <vlGraphics/Viewport.hpp>
00040 #include <vlGraphics/Frustum.hpp>
00041 #include <vlCore/Ray.hpp>
00042
00043 namespace vl
00044 {
00045 class AABB;
00046
00047
00048
00050 class VLGRAPHICS_EXPORT Camera: public Object
00051 {
00052 VL_INSTRUMENT_CLASS(vl::Camera, Object)
00053
00054 public:
00056 Camera();
00057
00065 void computeNearFarOptimizedProjMatrix(const Sphere& scene_bounding_sphere);
00066
00070 void computeFrustumPlanes();
00071
00073 void applyModelViewMatrix(const mat4& model_matrix) const;
00074
00076 void applyViewMatrix() const;
00077
00079 void applyProjMatrix() const;
00080
00083 real aspectRatio() const
00084 {
00085 if (viewport())
00086 return (real)viewport()->width()/viewport()->height();
00087 else
00088 return 0;
00089 }
00090
00093 void setFOV(real fov) { mFOV = fov; }
00094
00096 real fov() const { return mFOV; }
00097
00100 void setNearPlane(real nearplane) { mNearPlane = nearplane; }
00101
00103 real nearPlane() const { return mNearPlane; }
00104
00107 void setFarPlane(real farplane) { mFarPlane = farplane; }
00108
00110 real farPlane() const { return mFarPlane; }
00111
00113 real left() const { return mLeft; }
00114 void setLeft(real v) { mLeft = v; }
00115
00117 real right() const { return mRight; }
00118 void setRight(real v) { mRight = v; }
00119
00121 real bottom() const { return mBottom; }
00122 void setBottom(real v) { mBottom = v; }
00123
00125 real top() const { return mTop; }
00126 void setTop(real v) { mTop = v; }
00127
00129 void setFrustum(const Frustum& frustum) { mFrustum = frustum; }
00130
00132 const Frustum& frustum() const { return mFrustum; }
00133
00135 Frustum& frustum() { return mFrustum; }
00136
00138 void setViewport(Viewport* viewport) { mViewport = viewport; }
00139
00141 Viewport* viewport() { return mViewport.get(); }
00142
00144 const Viewport* viewport() const { return mViewport.get(); }
00145
00147 void bindTransform(Transform* transform) { mBoundTransform = transform; }
00148
00150 const Transform* boundTransform() const { return mBoundTransform.get(); }
00151
00153 Transform* boundTransform() { return mBoundTransform.get(); }
00154
00157 void setViewMatrix(const mat4& mat) { mViewMatrix = mat; mViewMatrix.getInverse(mModelingMatrix); }
00158
00161 const mat4& viewMatrix() const { return mViewMatrix; }
00162
00165 void setModelingMatrix(const mat4& mat) { mModelingMatrix = mat; mModelingMatrix.getInverse(mViewMatrix); }
00166
00169 const mat4& modelingMatrix() const { return mModelingMatrix; }
00170
00172 void setProjectionMatrix(const mat4& mat, EProjectionMatrixType proj_type) { mProjectionMatrix = mat; mProjectionType = proj_type; }
00173
00175 const mat4& projectionMatrix() const { return mProjectionMatrix; }
00176
00178 EProjectionMatrixType projectionMatrixType() const { return mProjectionType; }
00179
00182 void setProjectionPerspective();
00183
00186 void setProjectionPerspective(real fov, real near, real far);
00187
00198 void setProjectionFrustum(real left, real right, real bottom, real top, real znear, real zfar);
00199
00206 void setProjectionOrtho(real left, real right, real bottom, real top, real znear, real zfar);
00207
00214 void setProjectionOrtho();
00215
00224 void setProjectionOrtho(real offset);
00225
00230 void setViewMatrixLookAt(const vec3& eye, const vec3& at, const vec3& up);
00231
00237 void getViewMatrixAsLookAt(vec3& eye, vec3& at, vec3& up, vec3& right) const;
00238
00240 bool project(const vec4& in_world, vec4& out_viewp) const;
00241
00248 bool unproject(const vec3& in_viewp, vec4& out_world) const;
00249
00251 bool unproject(std::vector<vec3>& points) const;
00252
00260 Ray computeRay(int viewp_x, int viewp_y);
00261
00263 Frustum computeRayFrustum(int viewp_x, int viewp_y);
00264
00270 void adjustView(const AABB& aabb, const vec3& dir, const vec3& up, real bias=1.0f);
00271
00272 protected:
00273 mat4 mViewMatrix;
00274 mat4 mModelingMatrix;
00275 mat4 mProjectionMatrix;
00276 ref<Viewport> mViewport;
00277 Frustum mFrustum;
00278 ref<Transform> mBoundTransform;
00279 real mFOV;
00280 real mLeft, mRight, mBottom, mTop;
00281 real mNearPlane;
00282 real mFarPlane;
00283 EProjectionMatrixType mProjectionType;
00284 };
00285 }
00286
00287 #endif