ARGoS  3
A parallel, multi-engine simulator for swarm robotics
plugins/simulator/visualizations/qt-opengl/qtopengl_camera.h
Go to the documentation of this file.
00001 
00007 #ifndef QTOPENGL_CAMERA_H
00008 #define QTOPENGL_CAMERA_H
00009 
00010 namespace argos {
00011    class CQTOpenGLCamera;
00012 }
00013 
00014 class QPoint;
00015 
00016 #include <QObject>
00017 #include <argos3/core/utility/datatypes/datatypes.h>
00018 #include <argos3/core/utility/math/ray3.h>
00019 #include <argos3/core/utility/configuration/argos_configuration.h>
00020 
00021 #ifdef __APPLE__
00022 #include <gl.h>
00023 #include <glu.h>
00024 #else
00025 #include <GL/gl.h>
00026 #include <GL/glu.h>
00027 #endif
00028 
00029 namespace argos {
00030 
00031    class CQTOpenGLCamera : public QObject {
00032 
00033       Q_OBJECT
00034 
00035    public:
00036 
00037       struct SSettings {
00039          CVector3 Position;
00041          CVector3 Left;
00043          CVector3 Up;
00045          CVector3 Forward;
00047          CVector3 Target;
00049          Real LensFocalLength;
00051          CDegrees YFieldOfView;
00053          Real MotionSensitivity;
00055          Real RotationSensitivity;
00056 
00057          SSettings() :
00058             Position(-2.0f, 0.0f, 2.0f),
00059             Left(CVector3::Y),
00060             Up(CVector3(1.0f, 0.0f, 1.0f).Normalize()),
00061             Forward(CVector3(1.0f, 0.0f, -1.0f).Normalize()),
00062             Target(),
00063             LensFocalLength(0.02f),
00064             MotionSensitivity(0.005),
00065             RotationSensitivity(0.01) {
00066             CalculateYFieldOfView();
00067          }
00068 
00070          void Init(TConfigurationNode& t_tree);
00072          void RotateUpDown(const CRadians& c_angle);
00074          void RotateLeftRight(const CRadians& c_angle);
00076          void RotateLeftRight2(const CRadians& c_angle);
00078          void Translate(const CVector3& c_delta);
00080          void Do();
00082          void CalculateYFieldOfView();
00084          void CalculateSensitivity();
00085       };
00086 
00087    public:
00088 
00089       CQTOpenGLCamera();
00090       ~CQTOpenGLCamera();
00091 
00092       void Init(TConfigurationNode& t_tree);
00093 
00094       inline void Look() {
00095          m_sSettings[m_unActiveSettings].Do();
00096       }
00097 
00098       inline const CVector3& GetPosition() const {
00099          return m_sSettings[m_unActiveSettings].Position;
00100       }
00101 
00102       inline const CVector3& GetTarget() const {
00103          return m_sSettings[m_unActiveSettings].Target;
00104       }
00105 
00106       inline Real GetLensFocalLength() const {
00107          return m_sSettings[m_unActiveSettings].LensFocalLength;
00108       }
00109 
00110       CVector3 GetMousePosInWorld(SInt32 n_x,
00111                                   SInt32 n_y) const;
00112 
00113       CRay3 ProjectRayFromMousePosIntoWorld(SInt32 n_x,
00114                                             SInt32 n_y) const;
00115       
00116       void Rotate(const QPoint& c_delta);
00117 
00118       void Move(SInt32 n_forwards_backwards,
00119                 SInt32 n_sideways,
00120                 SInt32 n_up_down);
00121 
00122       inline SSettings& GetActiveSettings() {
00123          return m_sSettings[m_unActiveSettings];
00124       }
00125 
00126       inline void SetActiveSettings(UInt32 un_settings) {
00127          m_unActiveSettings = un_settings;
00128       }
00129 
00130       inline SSettings& GetSetting(UInt32 n_index) {
00131          return m_sSettings[n_index];
00132       }
00133 
00134    private:
00135 
00136       UInt32 m_unActiveSettings;
00137       SSettings m_sSettings[12];
00138 
00139    };
00140 
00141 }
00142 
00143 #endif
00144