# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/Camera.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #ifndef Camera_INCLUDE_ONCE
    00033 #define Camera_INCLUDE_ONCE
    00034
    00035 #include <vlCore/checks.hpp>
    00036 #include <vlCore/math3D.hpp>
    00037 #include <vlCore/Vector4.hpp>
    00038 #include <vlGraphics/RenderTarget.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   // Camera
    00048   //-----------------------------------------------------------------------------
    00050   class VLGRAPHICS_EXPORT Camera: public Object
    00051   {
    00052   public:
    00053     virtual const char* className() { return "vl::Camera"; }
    00054
    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     void setFrustum(const Frustum& frustum) { mFrustum = frustum; }
    00114
    00116     const Frustum& frustum() const { return mFrustum; }
    00117
    00119     Frustum& frustum() { return mFrustum; }
    00120
    00122     void setViewport(Viewport* viewport) { mViewport = viewport; }
    00123
    00125     Viewport* viewport() { return mViewport.get(); }
    00126
    00128     const Viewport* viewport() const { return mViewport.get(); }
    00129
    00131     void followTransform(Transform* transform) { mFollowTransform = transform; }
    00132
    00134     const Transform* followedTransform() const { return mFollowTransform.get(); }
    00135
    00137     Transform* followedTransform() { return mFollowTransform.get(); }
    00138
    00140     void setViewMatrix(const mat4& mat) { mViewMatrix = mat; mInverseViewMatrix = mat; mInverseViewMatrix.invert(); }
    00141
    00143     const mat4& viewMatrix() const { return mViewMatrix; }
    00144
    00146     void setInverseViewMatrix(const mat4& mat) { mInverseViewMatrix = mat; mViewMatrix = mat; mViewMatrix.invert(); }
    00147
    00149     const mat4& inverseViewMatrix() const { return mInverseViewMatrix; }
    00150
    00155     void setProjectionMatrix(const mat4& mat) { mProjectionMatrix = mat;  mFOV = mNearPlane = mFarPlane  = -1; }
    00156
    00158     const mat4& projectionMatrix() const { return mProjectionMatrix; }
    00159
    00162     void setProjectionAsPerspective();
    00163
    00166     void setProjectionAsPerspective(Real fov, Real near, Real far);
    00167
    00171     void setProjectionAsFrustum(Real left, Real right, Real bottom, Real top, Real near, Real far);
    00172
    00183     void setProjectionAsOrtho(Real offset=-0.5f);
    00184
    00195     void setProjectionAsOrtho2D(Real offset=-0.5f);
    00196
    00201     void setViewMatrixAsLookAt( const vec3& eye, const vec3& center, const vec3& up);
    00202
    00208     void getViewMatrixAsLookAt( vec3& eye, vec3& look, vec3& up, vec3& right) const;
    00209
    00211     bool project(const vec4& in_world, vec4& out_viewp) const;
    00212
    00219     bool unproject(const vec3& in_viewp, vec4& out_world) const;
    00220
    00222     bool unproject(std::vector<vec3>& points) const;
    00223
    00231     Ray computeRay(int viewp_x, int viewp_y);
    00232
    00234     Frustum computeRayFrustum(int viewp_x, int viewp_y);
    00235
    00241     void adjustView(const AABB& aabb, const vec3& dir, const vec3& up, Real bias=1.0f);
    00242
    00243   protected:
    00244     mat4 mViewMatrix;
    00245     mat4 mInverseViewMatrix;
    00246     mat4 mProjectionMatrix;
    00247     ref<Viewport> mViewport;
    00248     Frustum mFrustum;
    00249     ref<Transform> mFollowTransform;
    00250     Real mFOV;
    00251     Real mNearPlane;
    00252     Real mFarPlane;
    00253   };
    00254 }
    00255
    00256 #endif

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:23.
Permission is granted to use this page to write and publish articles regarding Visualization Library.