LP-311 Remove basic/advanced stabilization tab auto-switch (autotune/txpid lock issues)
[librepilot.git] / ground / gcs / src / libs / eigen / demos / opengl / camera.h
blob15714d2e6deec85cfedfbebbf301f541942aa7b7
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
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>
14 #include <QObject>
15 // #include <frame.h>
17 class Frame
19 public:
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;
36 class Camera
38 public:
39 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
41 Camera(void);
43 Camera(const Camera& other);
45 virtual ~Camera();
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);
83 void zoom(float d);
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;
93 protected:
94 void updateViewMatrix(void) const;
95 void updateProjectionMatrix(void) const;
97 protected:
99 uint mVpX, mVpY;
100 uint mVpWidth, mVpHeight;
102 Frame mFrame;
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;
113 float mFovY;
114 float mNearDist;
115 float mFarDist;
118 #endif // EIGEN_CAMERA_H