/
vrconfig.h
227 lines (191 loc) · 6.52 KB
/
vrconfig.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/** @file vrconfig.h Virtual reality configuration.
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright (c) 2013 Christopher Bruns <cmbruns@rotatingpenguin.com>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 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 Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBAPPFW_VRCONFIG_H
#define LIBAPPFW_VRCONFIG_H
#include <de/OculusRift>
#include <de/Matrix>
namespace de {
/**
* Virtual reality configuration settings.
*/
class LIBAPPFW_PUBLIC VRConfig
{
public:
/**
* Stereoscopic 3D rendering mode. This enumeration determines the integer value in
* the console variable.
*/
enum StereoMode
{
Mono, // 0
GreenMagenta,
RedCyan,
LeftOnly,
RightOnly,
TopBottom, // 5
SideBySide,
Parallel,
CrossEye,
OculusRift,
RowInterleaved, // 10 // NOT IMPLEMENTED YET
ColumnInterleaved, // NOT IMPLEMENTED YET
Checkerboard, // NOT IMPLEMENTED YET
QuadBuffered,
NUM_STEREO_MODES
};
public:
VRConfig();
/**
* Sets the current stereoscopic rendering mode.
*
* @param newMode Rendering mode.
*/
void setMode(StereoMode newMode);
/**
* Sets the distance from the eye to the screen onto which projection is being
* done. This used when calculating a frustum-shifted projection matrix.
* This is not used with Oculus Rift.
*
* @param distance Distance.
*/
void setScreenDistance(float distance);
/**
* Sets the height of the eye in map units. This is used to determine how big an
* eye shift is needed.
*
* @param eyeHeightInMapUnits Height of the eye in map units, measured from the
* "ground".
*/
void setEyeHeightInMapUnits(float eyeHeightInMapUnits);
/**
* Sets the currently used physical IPD. This is used to determine how big an
* eye shift is needed.
*
* @param ipd IPD in mm.
*/
void setInterpupillaryDistance(float ipd);
/**
* Sets the height of the player in the real world. This is used as a scaling
* factor to convert physical units to map units.
*
* @param heightInMeters Height of the player in meters.
*/
void setPhysicalPlayerHeight(float heightInMeters);
enum Eye {
NeitherEye,
LeftEye,
RightEye
};
/**
* Sets the eye currently used for rendering a frame. In stereoscopic modes,
* the frame is drawn twice; once for each eye.
*
* @param eye Eye to render. In non-stereoscopic modes, NeitherEye is used.
*/
void setCurrentEye(Eye eye);
/**
* Enables or disables projection frustum shifting.
*
* @param enable @c true to enable.
*/
void enableFrustumShift(bool enable = true);
/**
* Sets the number of multisampling samples used in the offscreen framebuffer
* where Oculus Rift frames are first drawn. This framebuffer is typically some
* multiple of the Oculus Rift display resolution.
*
* @param samples Number of samples to use for multisampling the Oculus Rift
* framebuffer.
*/
void setRiftFramebufferSampleCount(int samples);
/**
* Sets the eyes-swapped mode.
*
* @param swapped @c true to swap left and right (default: false).
*/
void setSwapEyes(bool swapped);
void setDominantEye(float value);
/**
* Currently active stereo rendering mode.
*/
StereoMode mode() const;
float screenDistance() const;
/**
* Determines if the current stereoscopic rendering mode needs support from
* the graphics hardware for quad-buffering (left/right back and front
* buffers stored and drawn separately).
*/
bool needsStereoGLFormat() const;
float interpupillaryDistance() const;
float eyeHeightInMapUnits() const;
float physicalPlayerHeight() const;
/**
* Local viewpoint relative eye position in map units.
*/
float eyeShift() const;
/**
* Determines if frustum shift is enabled.
*/
bool frustumShift() const;
bool swapEyes() const;
float dominantEye() const;
/// Multisampling used in unwarped Rift framebuffer.
int riftFramebufferSampleCount() const;
float viewAspect(Vector2f const &viewPortSize) const;
/**
* Calculates a vertical field of view angle based on a horizontal FOV angle,
* view port size, and the current VR configuration.
*
* @param horizFovDegrees Field of view horizontally, in degrees.
* @param viewPortSize Size of the viewport in pixels.
*
* @return Vertical field of view, in degrees.
*/
float verticalFieldOfView(float horizFovDegrees, Vector2f const &viewPortSize) const;
/**
* Produces a projection matrix suitable for the current VR configuration.
*
* @param fovDegrees Horizontal field of view angle.
* @param viewPortSize Size of the viewport in pixels.
* @param nearClip Distance of the near clipping plane.
* @param farClip Distance of the far clipping plane.
*
* @return Projection matrix.
*/
Matrix4f projectionMatrix(float fovDegrees,
Vector2f const &viewPortSize,
float nearClip, float farClip) const;
de::OculusRift &oculusRift();
de::OculusRift const &oculusRift() const;
public:
/**
* Determines if the VR mode will be applying a transformation to window contents
* that displaces the content from its "actual" location.
*
* @param mode Mode.
*
* @return @c true, if contents will change position on screen.
*/
static bool modeAppliesDisplacement(StereoMode mode);
static bool modeNeedsStereoGLFormat(StereoMode mode);
private:
DENG2_PRIVATE(d)
};
} // namespace de
#endif // LIBAPPFW_VRCONFIG_H