Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ACGL
acgl
Commits
4227315b
Commit
4227315b
authored
Oct 15, 2013
by
Robert Menzel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SimpleRiftController now supports Rift SDK 0.2.5
parent
43396bef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
98 deletions
+61
-98
include/ACGL/HardwareSupport/SimpleRiftController.hh
include/ACGL/HardwareSupport/SimpleRiftController.hh
+3
-13
src/ACGL/HardwareSupport/SimpleRiftController.cc
src/ACGL/HardwareSupport/SimpleRiftController.cc
+58
-85
No files found.
include/ACGL/HardwareSupport/SimpleRiftController.hh
View file @
4227315b
...
...
@@ -48,7 +48,7 @@ public:
* the user has to look into at least four very different directions
* for this to work.
*/
SimpleRiftController
(
uint32_t
_riftnumber
=
0
,
bool
_performAutomaticMagneticCalibration
=
true
);
SimpleRiftController
(
uint32_t
_riftnumber
=
0
);
~
SimpleRiftController
();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -73,15 +73,6 @@ public:
//! this can be used as an alternative to updateCamera if the attached camera should not be used.
glm
::
mat3
getCurrentRotation
();
//! start the automatic calibration process, by default this is done in the constructor
void
startMagneticCalibration
();
//! delete the calibration data and work uncalibrated. A new calibration can be started if wanted
void
deactivateMagneticDriftCorrection
();
//! check if the calibration worked
bool
magneticCalibrationDone
();
//! sets the amound of seconds to predict the headmovements into the future
//! default is 0.03f, should be no more than the rendering latency!
void
setPrediction
(
float
_seconds
);
...
...
@@ -202,9 +193,8 @@ private:
OVR
::
Ptr
<
OVR
::
DeviceManager
>
mORManager
;
OVR
::
Ptr
<
OVR
::
HMDDevice
>
mORDevice
;
OVR
::
Ptr
<
OVR
::
SensorDevice
>
mORSensor
;
OVR
::
SensorFusion
mORSensorFusion
;
OVR
::
HMDInfo
mORHMDInfo
;
OVR
::
Util
::
MagCalibration
mMagneticCalibration
;
OVR
::
SensorFusion
*
mORSensorFusion
;
OVR
::
HMDInfo
*
mORHMDInfo
;
// all rotations are relative to the one the Rift started with:
OVR
::
Quatf
mInverseNeutralRotation
;
// as quaternion
...
...
src/ACGL/HardwareSupport/SimpleRiftController.cc
View file @
4227315b
...
...
@@ -12,42 +12,17 @@ using namespace ACGL::OpenGL;
using
namespace
std
;
SimpleRiftController
::
SimpleRiftController
(
uint32_t
_riftnumber
,
bool
_performAutomaticMagneticCalibration
)
SimpleRiftController
::
SimpleRiftController
(
uint32_t
_riftnumber
)
{
mSuccessfulConnected
=
false
;
mDistortionScaleFactor
=
1.0
f
;
// default values from the first devkit:
mORHMDInfo
.
HResolution
=
1280
;
mORHMDInfo
.
VResolution
=
800
;
mORHMDInfo
.
HScreenSize
=
0.14976
f
;
mORHMDInfo
.
VScreenSize
=
0.0935
f
;
mORHMDInfo
.
VScreenCenter
=
mORHMDInfo
.
VScreenSize
*
0.5
f
;
mORHMDInfo
.
DistortionK
[
0
]
=
1.0
f
;
mORHMDInfo
.
DistortionK
[
1
]
=
0.22
f
;
mORHMDInfo
.
DistortionK
[
2
]
=
0.24
f
;
mORHMDInfo
.
EyeToScreenDistance
=
0.041
f
;
mORHMDInfo
.
ChromaAbCorrection
[
0
]
=
0.996
f
;
mORHMDInfo
.
ChromaAbCorrection
[
1
]
=
-
0.004
f
;
mORHMDInfo
.
ChromaAbCorrection
[
2
]
=
1.014
f
;
mORHMDInfo
.
ChromaAbCorrection
[
3
]
=
0.0
f
;
mORHMDInfo
.
LensSeparationDistance
=
0.0635
f
;
mORHMDInfo
.
InterpupillaryDistance
=
0.064
f
;
mORHMDInfo
.
DisplayDeviceName
[
0
]
=
0
;
mUseDistortion
=
true
;
mUseChromaticAberation
=
true
;
mPredictionTime
=
-
1.0
f
;
mFoVMultiplier
=
1.0
f
;
mCamera
=
SharedHMDCamera
();
// set to NULL
attachCamera
(
SharedHMDCamera
(
new
HMDCamera
()
)
);
// attach a blank camera
// set a good default viewport:
glm
::
uvec2
viewport
=
getPhysicalScreenResolution
();
mCamera
->
resize
(
viewport
.
x
/
2
,
viewport
.
y
);
updateCameraFoV
();
// indirectly based on the viewport
debug
()
<<
"try to connect to Oculus Rift via SDK "
<<
OVR_VERSION_STRING
<<
endl
;
if
(
_riftnumber
!=
0
)
{
...
...
@@ -56,6 +31,32 @@ SimpleRiftController::SimpleRiftController( uint32_t _riftnumber, bool _performA
System
::
Init
(
Log
::
ConfigureDefaultLog
(
LogMask_All
)
);
// default values from the first devkit:
mORHMDInfo
=
new
OVR
::
HMDInfo
();
mORHMDInfo
->
HResolution
=
1280
;
mORHMDInfo
->
VResolution
=
800
;
mORHMDInfo
->
HScreenSize
=
0.14976
f
;
mORHMDInfo
->
VScreenSize
=
0.0935
f
;
mORHMDInfo
->
VScreenCenter
=
mORHMDInfo
->
VScreenSize
*
0.5
f
;
mORHMDInfo
->
DistortionK
[
0
]
=
1.0
f
;
mORHMDInfo
->
DistortionK
[
1
]
=
0.22
f
;
mORHMDInfo
->
DistortionK
[
2
]
=
0.24
f
;
mORHMDInfo
->
EyeToScreenDistance
=
0.041
f
;
mORHMDInfo
->
ChromaAbCorrection
[
0
]
=
0.996
f
;
mORHMDInfo
->
ChromaAbCorrection
[
1
]
=
-
0.004
f
;
mORHMDInfo
->
ChromaAbCorrection
[
2
]
=
1.014
f
;
mORHMDInfo
->
ChromaAbCorrection
[
3
]
=
0.0
f
;
mORHMDInfo
->
LensSeparationDistance
=
0.0635
f
;
mORHMDInfo
->
InterpupillaryDistance
=
0.064
f
;
mORHMDInfo
->
DisplayDeviceName
[
0
]
=
0
;
mCamera
=
SharedHMDCamera
();
// set to NULL
attachCamera
(
SharedHMDCamera
(
new
HMDCamera
()
)
);
// attach a blank camera
// set a good default viewport:
glm
::
uvec2
viewport
=
getPhysicalScreenResolution
();
mCamera
->
resize
(
viewport
.
x
/
2
,
viewport
.
y
);
updateCameraFoV
();
// indirectly based on the viewport
mORManager
=
*
DeviceManager
::
Create
();
if
(
!
mORManager
)
{
error
()
<<
"could not create a Rift Device Manager"
<<
endl
;
...
...
@@ -70,7 +71,7 @@ SimpleRiftController::SimpleRiftController( uint32_t _riftnumber, bool _performA
debug
()
<<
"found HMD"
<<
endl
;
if
(
!
mORDevice
->
GetDeviceInfo
(
&
mORHMDInfo
))
{
if
(
!
mORDevice
->
GetDeviceInfo
(
mORHMDInfo
))
{
error
()
<<
"could not get HMD device info"
<<
endl
;
return
;
}
...
...
@@ -84,13 +85,10 @@ SimpleRiftController::SimpleRiftController( uint32_t _riftnumber, bool _performA
return
;
}
mORSensorFusion
.
AttachToSensor
(
mORSensor
);
mORSensorFusion
=
new
OVR
::
SensorFusion
();
mORSensorFusion
->
AttachToSensor
(
mORSensor
);
mSuccessfulConnected
=
true
;
if
(
_performAutomaticMagneticCalibration
)
{
startMagneticCalibration
();
}
}
SimpleRiftController
::~
SimpleRiftController
()
...
...
@@ -98,35 +96,21 @@ SimpleRiftController::~SimpleRiftController()
// setting the reference counted pointers to NULL will call the object destructors:
debug
()
<<
"disconnecting from Oculus Rift..."
<<
endl
;
//mORSensorFusion->AttachToSensor( NULL );
mORSensor
=
NULL
;
mORDevice
=
NULL
;
mORManager
=
NULL
;
mORSensorFusion
.
AttachToSensor
(
NULL
);
delete
mORHMDInfo
;
delete
mORSensorFusion
;
System
::
Destroy
();
// Oculus Rift
}
void
SimpleRiftController
::
startMagneticCalibration
()
{
deactivateMagneticDriftCorrection
();
// in case there was an old calibration already
mMagneticCalibration
.
BeginAutoCalibration
(
mORSensorFusion
);
}
bool
SimpleRiftController
::
magneticCalibrationDone
()
{
return
mMagneticCalibration
.
IsCalibrated
();
}
void
SimpleRiftController
::
deactivateMagneticDriftCorrection
()
{
mMagneticCalibration
.
ClearCalibration
(
mORSensorFusion
);
}
void
SimpleRiftController
::
setPrediction
(
float
_seconds
)
{
if
(
_seconds
>=
0.0
f
)
{
mORSensorFusion
.
SetPrediction
(
_seconds
);
mORSensorFusion
->
SetPrediction
(
_seconds
);
}
else
{
mORSensorFusion
.
SetPrediction
(
0.0
f
,
false
);
mORSensorFusion
->
SetPrediction
(
0.0
f
,
false
);
}
mPredictionTime
=
_seconds
;
}
...
...
@@ -154,12 +138,12 @@ glm::mat3 riftMatrixToGLM( const Matrix4f &_mat4 )
void
SimpleRiftController
::
attachCamera
(
ACGL
::
Scene
::
SharedHMDCamera
_camera
)
{
mCamera
=
_camera
;
mCamera
->
setInterpupillaryDistance
(
mORHMDInfo
.
InterpupillaryDistance
);
mCamera
->
setInterpupillaryDistance
(
mORHMDInfo
->
InterpupillaryDistance
);
updateCameraFoV
();
float
viewCenterH
=
mORHMDInfo
.
HScreenSize
*
0.25
f
;
float
eyeProjectionShift
=
viewCenterH
-
mORHMDInfo
.
LensSeparationDistance
*
0.5
f
;
float
offsetX
=
4.0
f
*
eyeProjectionShift
/
mORHMDInfo
.
HScreenSize
;
float
viewCenterH
=
mORHMDInfo
->
HScreenSize
*
0.25
f
;
float
eyeProjectionShift
=
viewCenterH
-
mORHMDInfo
->
LensSeparationDistance
*
0.5
f
;
float
offsetX
=
4.0
f
*
eyeProjectionShift
/
mORHMDInfo
->
HScreenSize
;
mCamera
->
setProjectionCenterOffset
(
glm
::
vec2
(
offsetX
,
0.0
f
));
mCamera
->
setNeckToEyeVerticalDistance
(
0.12
f
);
...
...
@@ -168,23 +152,12 @@ void SimpleRiftController::attachCamera( ACGL::Scene::SharedHMDCamera _camera )
glm
::
mat3
SimpleRiftController
::
getCurrentRotation
()
{
// magnetic calibration:
if
(
mMagneticCalibration
.
IsAutoCalibrating
())
{
mMagneticCalibration
.
UpdateAutoCalibration
(
mORSensorFusion
);
if
(
mMagneticCalibration
.
IsCalibrated
())
{
Vector3f
mc
=
mMagneticCalibration
.
GetMagCenter
();
debug
()
<<
"mag center "
<<
mc
.
x
<<
" "
<<
mc
.
y
<<
" "
<<
mc
.
z
<<
" found, enabling yaw correction"
<<
endl
;
mORSensorFusion
.
SetYawCorrectionEnabled
(
true
);
}
}
// update orientation:
Quatf
q
;
if
(
mPredictionTime
>
0.0
f
)
{
q
=
mORSensorFusion
.
GetPredictedOrientation
();
q
=
mORSensorFusion
->
GetPredictedOrientation
();
}
else
{
q
=
mORSensorFusion
.
GetOrientation
();
q
=
mORSensorFusion
->
GetOrientation
();
}
q
.
Normalize
();
...
...
@@ -193,7 +166,7 @@ glm::mat3 SimpleRiftController::getCurrentRotation()
q
=
mInverseNeutralRotation
*
q
;
if
(
mORSensorFusion
.
IsYawCorrectionEnabled
())
{
if
(
mORSensorFusion
->
IsYawCorrectionEnabled
())
{
//debug() << "yaw corrected" << endl;
}
...
...
@@ -203,7 +176,7 @@ glm::mat3 SimpleRiftController::getCurrentRotation()
void
SimpleRiftController
::
setNeutralPosition
()
{
mInverseNeutralRotation
=
mORSensorFusion
.
GetOrientation
();
mInverseNeutralRotation
=
mORSensorFusion
->
GetOrientation
();
mInverseNeutralRotation
.
Normalize
();
mInverseNeutralRotation
.
x
*=
-
1.0
;
mInverseNeutralRotation
.
y
*=
-
1.0
;
...
...
@@ -213,7 +186,7 @@ void SimpleRiftController::setNeutralPosition()
void
SimpleRiftController
::
setNeutralYaw
()
{
mInverseNeutralRotation
=
OVR
::
Quatf
();
mORSensorFusion
.
Reset
();
mORSensorFusion
->
Reset
();
}
void
SimpleRiftController
::
updateCamera
()
...
...
@@ -225,8 +198,8 @@ void SimpleRiftController::updateCamera()
void
SimpleRiftController
::
updateCameraFoV
()
{
float
percievedHalfRTDist
=
(
mORHMDInfo
.
VScreenSize
/
2
)
*
mDistortionScaleFactor
;
float
vfov
=
2.0
f
*
atan
(
percievedHalfRTDist
/
mORHMDInfo
.
EyeToScreenDistance
);
float
percievedHalfRTDist
=
(
mORHMDInfo
->
VScreenSize
/
2
)
*
mDistortionScaleFactor
;
float
vfov
=
2.0
f
*
atan
(
percievedHalfRTDist
/
mORHMDInfo
->
EyeToScreenDistance
);
vfov
=
ACGL
::
Math
::
Functions
::
calcRadToDeg
(
vfov
);
vfov
*=
mFoVMultiplier
;
...
...
@@ -239,7 +212,7 @@ void SimpleRiftController::updateCameraFoV()
glm
::
uvec2
SimpleRiftController
::
getPhysicalScreenResolution
()
{
return
glm
::
uvec2
(
mORHMDInfo
.
HResolution
,
mORHMDInfo
.
VResolution
);
return
glm
::
uvec2
(
mORHMDInfo
->
HResolution
,
mORHMDInfo
->
VResolution
);
}
void
SimpleRiftController
::
setDistortionScaleFactor
(
float
_f
)
{
...
...
@@ -274,9 +247,9 @@ glm::vec4 SimpleRiftController::getShaderValue( int v )
// both eyes have the same aspect ratio: hals the windowsize as the image was rendered side by side
float
aspectRatio
=
(
0.5
*
windowSize
.
x
)
/
windowSize
.
y
;
float
lensOffset
=
mORHMDInfo
.
LensSeparationDistance
*
0.5
f
;
float
lensShift
=
mORHMDInfo
.
HScreenSize
*
0.25
f
-
lensOffset
;
float
lensViewportShift
=
4.0
f
*
lensShift
/
mORHMDInfo
.
HScreenSize
;
float
lensOffset
=
mORHMDInfo
->
LensSeparationDistance
*
0.5
f
;
float
lensShift
=
mORHMDInfo
->
HScreenSize
*
0.25
f
-
lensOffset
;
float
lensViewportShift
=
4.0
f
*
lensShift
/
mORHMDInfo
->
HScreenSize
;
float
lensViewportShiftL
=
lensViewportShift
;
float
lensViewportShiftR
=
-
lensViewportShift
;
...
...
@@ -330,20 +303,20 @@ glm::vec4 SimpleRiftController::getScaleIn()
glm
::
vec4
SimpleRiftController
::
getHmdWarpParam
()
{
glm
::
vec4
distortionK
;
distortionK
.
x
=
mORHMDInfo
.
DistortionK
[
0
];
distortionK
.
y
=
mORHMDInfo
.
DistortionK
[
1
];
distortionK
.
z
=
mORHMDInfo
.
DistortionK
[
2
];
distortionK
.
w
=
mORHMDInfo
.
DistortionK
[
3
];
distortionK
.
x
=
mORHMDInfo
->
DistortionK
[
0
];
distortionK
.
y
=
mORHMDInfo
->
DistortionK
[
1
];
distortionK
.
z
=
mORHMDInfo
->
DistortionK
[
2
];
distortionK
.
w
=
mORHMDInfo
->
DistortionK
[
3
];
return
distortionK
;
}
glm
::
vec4
SimpleRiftController
::
getChromAbParam
()
{
glm
::
vec4
chromaK
;
chromaK
.
x
=
mORHMDInfo
.
ChromaAbCorrection
[
0
];
chromaK
.
y
=
mORHMDInfo
.
ChromaAbCorrection
[
1
];
chromaK
.
z
=
mORHMDInfo
.
ChromaAbCorrection
[
2
];
chromaK
.
w
=
mORHMDInfo
.
ChromaAbCorrection
[
3
];
chromaK
.
x
=
mORHMDInfo
->
ChromaAbCorrection
[
0
];
chromaK
.
y
=
mORHMDInfo
->
ChromaAbCorrection
[
1
];
chromaK
.
z
=
mORHMDInfo
->
ChromaAbCorrection
[
2
];
chromaK
.
w
=
mORHMDInfo
->
ChromaAbCorrection
[
3
];
return
chromaK
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment