Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OGLCamera.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 /*
17  *
18  *
19  *
20  *
21  */
22 
23 #ifndef __O_GLCAMERA__
24 #define __O_GLCAMERA__
25 
26 #include "Tympan/core/smartptr.h"
27 #include <qmatrix4x4.h>
28 #include <qvector3d.h>
29 
30 #if _WIN32
31  #include <windows.h>
32 #endif //_WIN32
33 
34 #include <GL/gl.h>
35 #include <GL/glu.h>
36 #include "NxVec3.h"
38 
39 typedef enum
40 {
43  FREE
45 
46 class OGLCamera
47 {
48 
49 public:
50  OGLCamera(const QVector3D& _from, const QVector3D& _to, const QVector3D& _up, int w, int h,
51  CameraType eCameraType);
52  CameraType cameraType() const;
53  void setCameraType(CameraType eCameraType);
54  void moveFront();
55  void moveBack();
56  void moveUp();
57  void moveDown();
58  void moveLeft();
59  void moveRight();
60  void move(const QVector3D& _direction);
61  void moveFront(NxReal _distance);
62  void moveBack(NxReal _distance);
63  void moveUp(NxReal _distance);
64  void moveDown(NxReal _distance);
65  void moveLeft(NxReal _distance);
66  void moveRight(NxReal _distance);
67  void setDistanceStep(NxReal _magnitudeStepUp, NxReal _magnitudeStepFront, NxReal _magnitudeStepLeft);
68  void setAllAngleStep(NxReal _angle);
69  void setAngleStep(NxReal _stepAngleUpDown, NxReal _stepAngleLeftRight, NxReal _stepAngleSide);
70  const QVector3D& from() const;
71  void setFrom(const QVector3D& _from);
72  const QVector3D& to() const;
73  void setTo(const QVector3D& _to);
74  void setUp(const QVector3D& _up);
75  void setFromToUp(const QVector3D& _from, const QVector3D& _to, const QVector3D& _up);
76  const QVector3D& front() const;
77  void setDistanceFromToLockFrom(NxReal _distanceFromTo);
78  void setDistanceFromToLockTo(NxReal _distanceFromTo);
79  void setModeLock(bool _modeLockUpDown, bool _modeLockLeftRight, bool _modeLockSide);
80  void setSize(int w, int h);
81  void calculateStepVectors();
82  void zoom(double zoomFactor);
83  void azimuth(NxReal _angle);
84  void elevation(NxReal _angle);
85  void roll(NxReal _angle);
86  void resetZoom(int w = -1, int h = -1);
87  void resetTranslation();
88  void setTranslation(double x, double y, double z);
89  void getTranslation(double& x, double& y, double& z);
90  void resetRotations();
91  void setDefaultZoomFactor(double defaultZoomFactor);
92  void getPosition(double& x, double& y, double& z) const;
93 
94  const QMatrix4x4& viewMatrix() const;
95  const QMatrix4x4& projectionMatrix() const;
96 
97 private:
98  QVector3D // points:
101 
102  // normalized vectors:
103  QVector3D _up, _left, _front;
104  // balanced vectors:
107  // distance and vector from - to :
109  QVector3D fromTo;
110 
112 
114 
115  int m_w, m_h;
118  QVector3D m_translate;
119 
120  // Cached matrices
121  mutable bool _viewMatrixDirty;
123  mutable QMatrix4x4 _viewMatrix;
124  mutable QMatrix4x4 _projectionMatrix;
125 
127  {
128  _projectionMatrixDirty = true;
129  }
130  void invalidateViewMatrix() const
131  {
132  _viewMatrixDirty = true;
133  }
134 
135  void updateProjectionMatrix() const;
136  void updateViewMatrix() const;
137 };
138 
139 // Smart pointer sur OGLCamera.
141 
142 #endif // __O_GLCAMERA__
All base classes related to 3D manipulation.
#define NxReal
Definition: NxVec3.h:20
SmartPtr< OGLCamera > LPOGLCamera
Definition: OGLCamera.h:140
CameraType
Definition: OGLCamera.h:40
@ PERSPECTIVE
Definition: OGLCamera.h:42
@ PARALLEL
Definition: OGLCamera.h:41
@ FREE
Definition: OGLCamera.h:43
QVector3D flyFrom
Definition: OGLCamera.h:105
void setTo(const QVector3D &_to)
Definition: OGLCamera.cpp:281
QVector3D flyTo
Definition: OGLCamera.h:105
void setUp(const QVector3D &_up)
Definition: OGLCamera.cpp:289
bool _viewMatrixDirty
Definition: OGLCamera.h:121
double m_angleAz
Definition: OGLCamera.h:116
QVector3D stepUp
Definition: OGLCamera.h:105
void setDefaultZoomFactor(double defaultZoomFactor)
Definition: OGLCamera.cpp:453
void moveDown()
Definition: OGLCamera.cpp:150
void setFromToUp(const QVector3D &_from, const QVector3D &_to, const QVector3D &_up)
Definition: OGLCamera.cpp:296
double m_angleEl
Definition: OGLCamera.h:116
double m_zoomFactor
Definition: OGLCamera.h:116
void setAngleStep(NxReal _stepAngleUpDown, NxReal _stepAngleLeftRight, NxReal _stepAngleSide)
Definition: OGLCamera.cpp:256
void move(const QVector3D &_direction)
Definition: OGLCamera.cpp:97
void elevation(NxReal _angle)
Definition: OGLCamera.cpp:403
void azimuth(NxReal _angle)
Definition: OGLCamera.cpp:396
QMatrix4x4 _projectionMatrix
Definition: OGLCamera.h:124
QVector3D flyFront
Definition: OGLCamera.h:105
void setAllAngleStep(NxReal _angle)
Definition: OGLCamera.cpp:251
double m_angleRo
Definition: OGLCamera.h:116
NxReal stepAngleLeftRight
Definition: OGLCamera.h:106
void roll(NxReal _angle)
Definition: OGLCamera.cpp:410
void setModeLock(bool _modeLockUpDown, bool _modeLockLeftRight, bool _modeLockSide)
Definition: OGLCamera.cpp:334
NxReal magnitudeStepLeft
Definition: OGLCamera.h:113
void updateViewMatrix() const
Definition: OGLCamera.cpp:498
void zoom(double zoomFactor)
Definition: OGLCamera.cpp:373
void getTranslation(double &x, double &y, double &z)
Definition: OGLCamera.cpp:474
void resetTranslation()
Definition: OGLCamera.cpp:446
void moveRight()
Definition: OGLCamera.cpp:180
void invalidateProjectionMatrix() const
Definition: OGLCamera.h:126
const QVector3D & front() const
Definition: OGLCamera.cpp:313
NxReal stepAngleSide
Definition: OGLCamera.h:106
void setFrom(const QVector3D &_from)
Definition: OGLCamera.cpp:268
void setCameraType(CameraType eCameraType)
Definition: OGLCamera.cpp:85
NxReal magnitudeStepUp
Definition: OGLCamera.h:113
void calculateStepVectors()
Definition: OGLCamera.cpp:341
bool modeLockSide
Definition: OGLCamera.h:111
void resetZoom(int w=-1, int h=-1)
Definition: OGLCamera.cpp:417
void resetRotations()
Definition: OGLCamera.cpp:458
void moveLeft()
Definition: OGLCamera.cpp:165
void getPosition(double &x, double &y, double &z) const
Definition: OGLCamera.cpp:481
OGLCamera(const QVector3D &_from, const QVector3D &_to, const QVector3D &_up, int w, int h, CameraType eCameraType)
Definition: OGLCamera.cpp:37
QVector3D stepFront
Definition: OGLCamera.h:105
NxReal stepAngleUpDown
Definition: OGLCamera.h:106
QVector3D flyLeft
Definition: OGLCamera.h:105
QVector3D _front
Definition: OGLCamera.h:103
void setTranslation(double x, double y, double z)
Definition: OGLCamera.cpp:467
QMatrix4x4 _viewMatrix
Definition: OGLCamera.h:123
const QVector3D & from() const
Definition: OGLCamera.cpp:263
QVector3D _from
Definition: OGLCamera.h:99
CameraType cameraType() const
Definition: OGLCamera.cpp:92
CameraType m_eCameraType
Definition: OGLCamera.h:117
void setSize(int w, int h)
Definition: OGLCamera.cpp:78
QVector3D stepLeft
Definition: OGLCamera.h:105
QVector3D flyFromTo
Definition: OGLCamera.h:105
bool modeLockLeftRight
Definition: OGLCamera.h:111
QVector3D m_translate
Definition: OGLCamera.h:118
QVector3D _up
Definition: OGLCamera.h:103
double m_defaultZoomFactor
Definition: OGLCamera.h:116
NxReal distanceFromTo
Definition: OGLCamera.h:108
void setDistanceStep(NxReal _magnitudeStepUp, NxReal _magnitudeStepFront, NxReal _magnitudeStepLeft)
Definition: OGLCamera.cpp:237
NxReal magnitudeStepFront
Definition: OGLCamera.h:113
QVector3D _left
Definition: OGLCamera.h:103
bool _projectionMatrixDirty
Definition: OGLCamera.h:122
QVector3D flyUp
Definition: OGLCamera.h:105
const QVector3D & to() const
Definition: OGLCamera.cpp:276
void setDistanceFromToLockTo(NxReal _distanceFromTo)
Definition: OGLCamera.cpp:326
void setDistanceFromToLockFrom(NxReal _distanceFromTo)
Definition: OGLCamera.cpp:318
const QMatrix4x4 & projectionMatrix() const
Definition: OGLCamera.cpp:567
void updateProjectionMatrix() const
Definition: OGLCamera.cpp:537
void moveBack()
Definition: OGLCamera.cpp:120
void moveFront()
Definition: OGLCamera.cpp:105
const QMatrix4x4 & viewMatrix() const
Definition: OGLCamera.cpp:558
QVector3D _to
Definition: OGLCamera.h:100
QVector3D fromTo
Definition: OGLCamera.h:109
void moveUp()
Definition: OGLCamera.cpp:135
void invalidateViewMatrix() const
Definition: OGLCamera.h:130
bool modeLockUpDown
Definition: OGLCamera.h:111