-
Notifications
You must be signed in to change notification settings - Fork 2
/
GLCamera.h
158 lines (126 loc) · 4.42 KB
/
GLCamera.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/***************************************************************************
* GLCamera.h
*
* Thu Jun 29 22:46:35 2006
* Copyright 2006 N. Sharjith
* sharjith@gmail.com
****************************************************************************/
/**********************************************************************
//Part of this code is taken from "camera" tutorial written by Philipp Crocoll
//Contact:
//philipp.crocoll@web.de
//www.codecolony.de
**********************************************************************/
#ifndef _GLCAMERA_H
#define _GLCAMERA_H
#ifdef WIN32
#include <windows.h>
#endif
#include <QMatrix4x4>
#include <QQuaternion>
#include <iostream>
using namespace std;
#ifndef PI
#define PI 3.1415926535897932384626433832795
#endif
#define PIdiv180 (PI/180.0)
/////////////////////////////////
//Note: All angles in degrees //
/////////////////////////////////
// CGLCamera
class GLCamera
{
public:
enum class ViewProjection
{
TOP_VIEW = 0,
BOTTOM_VIEW = (TOP_VIEW + 1),
FRONT_VIEW = (BOTTOM_VIEW + 1),
REAR_VIEW = (FRONT_VIEW + 1),
LEFT_VIEW = (REAR_VIEW + 1),
RIGHT_VIEW = (LEFT_VIEW + 1),
NE_ISOMETRIC_VIEW = (RIGHT_VIEW + 1),
SE_ISOMETRIC_VIEW = (NE_ISOMETRIC_VIEW + 1),
NW_ISOMETRIC_VIEW = (SE_ISOMETRIC_VIEW + 1),
SW_ISOMETRIC_VIEW = (NW_ISOMETRIC_VIEW + 1),
DIMETRIC_VIEW = (SW_ISOMETRIC_VIEW + 1),
TRIMETRIC_VIEW = (DIMETRIC_VIEW + 1)
};
enum class ProjectionType
{
ORTHOGRAPHIC = 0,
PERSPECTIVE = (ORTHOGRAPHIC + 1)
};
GLCamera();
GLCamera(float width, float height, float range, float fov);
void setScreenSize(float w, float h);
QPoint getScreenSize() const;
float getAspectRatio() const;
void setFOV(float fov);
float getFOV() const;
void setViewRange(float range);
float getViewRange() const;
void setProjectionType(ProjectionType proj);
ProjectionType getProjectionType() const;
void resetAll(void);
void updateViewMatrix(void);
void updateProjectionMatrix(void);
void rotateX(float iAngle);
float getRotatedX() const { return _rotatedX; }
void rotateY(float iAngle);
float getRotatedY() const { return _rotatedY; }
void rotateZ(float iAngle);
float getRotatedZ() const { return _rotatedZ; }
void move(float iDX, float iDY, float iDZ);
void moveForward(float iDist);
void moveUpward(float iDist);
void moveAcross(float iDist);
void setZoom(float iFactor);
float getZoom() const { return _zoomValue; }
void setView(ViewProjection iProj);
void setView(QVector3D viewPos, QVector3D viewDir, QVector3D upDir, QVector3D rightDir);
void setPosition(float iX, float iY, float iZ);
void setPosition(QVector3D pos);
QVector3D getViewDir() const { return _viewDir; }
QVector3D getRightVector() const { return _rightVector; }
QVector3D getUpVector() const { return _upVector; }
QVector3D getPosition() const { return _position; }
void setViewMatrix(QMatrix4x4 mat);
QMatrix4x4 getViewMatrix() const { return _viewMatrix; }
void computeStereoViewProjectionMatrices(int width, int height, float IOD, float depthZ, bool left_eye);
void setProjectionMatrix(QMatrix4x4 mat);
QMatrix4x4 getProjectionMatrix() const { return _projectionMatrix; }
void getRotationAngles(float* oPitch, float* oYaw, float* oRoll);
/*static QQuaternion quaternionFromMatrix(QMatrix4x4 m);
static void quatToEuler(const QQuaternion& quat, float *rotx, float *roty, float *rotz);*/
private:
QVector3D _viewDir;
QVector3D _rightVector;
QVector3D _upVector;
QVector3D _position;
float _width;
float _height;
float _viewRange;
float _FOV;
float _rotatedX, _rotatedY, _rotatedZ, _zoomValue;
ViewProjection _viewProj;
ProjectionType _projectionType;
QMatrix4x4 _projectionMatrix;
QMatrix4x4 _viewMatrix;
};
#endif /* _GLCAMERA_H */