1 // This file is part of Eigen, a lightweight C++ template library
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef EIGEN_CAMERA_H
11 #define EIGEN_CAMERA_H
13 #include <Eigen/Geometry>
20 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
22 inline Frame(const Eigen::Vector3f
& pos
= Eigen::Vector3f::Zero(),
23 const Eigen::Quaternionf
& o
= Eigen::Quaternionf())
24 : orientation(o
), position(pos
)
26 Frame
lerp(float alpha
, const Frame
& other
) const
28 return Frame((1.f
-alpha
)*position
+ alpha
* other
.position
,
29 orientation
.slerp(alpha
,other
.orientation
));
32 Eigen::Quaternionf orientation
;
33 Eigen::Vector3f position
;
39 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43 Camera(const Camera
& other
);
47 Camera
& operator=(const Camera
& other
);
49 void setViewport(uint offsetx
, uint offsety
, uint width
, uint height
);
50 void setViewport(uint width
, uint height
);
52 inline uint
vpX(void) const { return mVpX
; }
53 inline uint
vpY(void) const { return mVpY
; }
54 inline uint
vpWidth(void) const { return mVpWidth
; }
55 inline uint
vpHeight(void) const { return mVpHeight
; }
57 inline float fovY(void) const { return mFovY
; }
58 void setFovY(float value
);
60 void setPosition(const Eigen::Vector3f
& pos
);
61 inline const Eigen::Vector3f
& position(void) const { return mFrame
.position
; }
63 void setOrientation(const Eigen::Quaternionf
& q
);
64 inline const Eigen::Quaternionf
& orientation(void) const { return mFrame
.orientation
; }
66 void setFrame(const Frame
& f
);
67 const Frame
& frame(void) const { return mFrame
; }
69 void setDirection(const Eigen::Vector3f
& newDirection
);
70 Eigen::Vector3f
direction(void) const;
71 void setUp(const Eigen::Vector3f
& vectorUp
);
72 Eigen::Vector3f
up(void) const;
73 Eigen::Vector3f
right(void) const;
75 void setTarget(const Eigen::Vector3f
& target
);
76 inline const Eigen::Vector3f
& target(void) { return mTarget
; }
78 const Eigen::Affine3f
& viewMatrix(void) const;
79 const Eigen::Matrix4f
& projectionMatrix(void) const;
81 void rotateAroundTarget(const Eigen::Quaternionf
& q
);
82 void localRotate(const Eigen::Quaternionf
& q
);
85 void localTranslate(const Eigen::Vector3f
& t
);
87 /** Setup OpenGL matrices and viewport */
88 void activateGL(void);
90 Eigen::Vector3f
unProject(const Eigen::Vector2f
& uv
, float depth
, const Eigen::Matrix4f
& invModelview
) const;
91 Eigen::Vector3f
unProject(const Eigen::Vector2f
& uv
, float depth
) const;
94 void updateViewMatrix(void) const;
95 void updateProjectionMatrix(void) const;
100 uint mVpWidth
, mVpHeight
;
104 mutable Eigen::Affine3f mViewMatrix
;
105 mutable Eigen::Matrix4f mProjectionMatrix
;
107 mutable bool mViewIsUptodate
;
108 mutable bool mProjIsUptodate
;
110 // used by rotateAroundTarget
111 Eigen::Vector3f mTarget
;
118 #endif // EIGEN_CAMERA_H