camera.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_CAMERA_H
00026 #define EIGEN_CAMERA_H
00027 
00028 #include <Eigen/Geometry>
00029 #include <QObject>
00030 // #include <frame.h>
00031 
00032 class Frame
00033 {
00034   public:
00035     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00036     
00037     inline Frame(const Eigen::Vector3f& pos = Eigen::Vector3f::Zero(),
00038                  const Eigen::Quaternionf& o = Eigen::Quaternionf())
00039       : orientation(o), position(pos)
00040     {}
00041     Frame lerp(float alpha, const Frame& other) const
00042     {
00043       return Frame((1.f-alpha)*position + alpha * other.position,
00044                    orientation.slerp(alpha,other.orientation));
00045     }
00046 
00047     Eigen::Quaternionf orientation;
00048     Eigen::Vector3f position;
00049 };
00050 
00051 class Camera
00052 {
00053   public:
00054     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00055 
00056     Camera(void);
00057     
00058     Camera(const Camera& other);
00059     
00060     virtual ~Camera();
00061     
00062     Camera& operator=(const Camera& other);
00063     
00064     void setViewport(uint offsetx, uint offsety, uint width, uint height);
00065     void setViewport(uint width, uint height);
00066     
00067     inline uint vpX(void) const { return mVpX; }
00068     inline uint vpY(void) const { return mVpY; }
00069     inline uint vpWidth(void) const { return mVpWidth; }
00070     inline uint vpHeight(void) const { return mVpHeight; }
00071 
00072     inline float fovY(void) const { return mFovY; }
00073     void setFovY(float value);
00074     
00075     void setPosition(const Eigen::Vector3f& pos);
00076     inline const Eigen::Vector3f& position(void) const { return mFrame.position; }
00077 
00078     void setOrientation(const Eigen::Quaternionf& q);
00079     inline const Eigen::Quaternionf& orientation(void) const { return mFrame.orientation; }
00080 
00081     void setFrame(const Frame& f);
00082     const Frame& frame(void) const { return mFrame; }
00083     
00084     void setDirection(const Eigen::Vector3f& newDirection);
00085     Eigen::Vector3f direction(void) const;
00086     void setUp(const Eigen::Vector3f& vectorUp);
00087     Eigen::Vector3f up(void) const;
00088     Eigen::Vector3f right(void) const;
00089     
00090     void setTarget(const Eigen::Vector3f& target);
00091     inline const Eigen::Vector3f& target(void) { return mTarget; }
00092     
00093     const Eigen::Affine3f& viewMatrix(void) const;
00094     const Eigen::Matrix4f& projectionMatrix(void) const;
00095     
00096     void rotateAroundTarget(const Eigen::Quaternionf& q);
00097     void localRotate(const Eigen::Quaternionf& q);
00098     void zoom(float d);
00099     
00100     void localTranslate(const Eigen::Vector3f& t);
00101     
00103     void activateGL(void);
00104     
00105     Eigen::Vector3f unProject(const Eigen::Vector2f& uv, float depth, const Eigen::Matrix4f& invModelview) const;
00106     Eigen::Vector3f unProject(const Eigen::Vector2f& uv, float depth) const;
00107     
00108   protected:
00109     void updateViewMatrix(void) const;
00110     void updateProjectionMatrix(void) const;
00111 
00112   protected:
00113 
00114     uint mVpX, mVpY;
00115     uint mVpWidth, mVpHeight;
00116 
00117     Frame mFrame;
00118     
00119     mutable Eigen::Affine3f mViewMatrix;
00120     mutable Eigen::Matrix4f mProjectionMatrix;
00121 
00122     mutable bool mViewIsUptodate;
00123     mutable bool mProjIsUptodate;
00124 
00125     // used by rotateAroundTarget
00126     Eigen::Vector3f mTarget;
00127     
00128     float mFovY;
00129     float mNearDist;
00130     float mFarDist;
00131 };
00132 
00133 #endif // EIGEN_CAMERA_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:31