Skip to content

Commit

Permalink
Ability to set custom distortion scale. If not set OculusDevice will …
Browse files Browse the repository at this point in the history
…use default distortion scale value.
  • Loading branch information
bjornblissing committed Aug 28, 2013
1 parent 1896da4 commit ad6c6e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ int main( int argc, char** argv )
}

// Open the HMD
OculusDevice* oculusDevice = new OculusDevice;
// Set the scaling of the texture, using the recommend 25% from the SDK
oculusDevice->setScaleFactor(1.25f);
OculusDevice* oculusDevice = new OculusDevice();
oculusDevice->setCustomScaleFactor(1.25f);
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();

if (!wsi) {
Expand Down
12 changes: 10 additions & 2 deletions src/oculusdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

#include "oculusdevice.h"

OculusDevice::OculusDevice() : m_deviceManager(0), m_hmdDevice(0), m_hmdInfo(0), m_sensorFusion(0),
m_scaleFactor(1.0f), m_nearClip(0.3f), m_farClip(5000.0f), m_predictionDelta(0.03f)

OculusDevice::OculusDevice() :
m_deviceManager(0), m_hmdDevice(0), m_hmdInfo(0), m_sensorFusion(0),
m_useCustomScaleFactor(false), m_customScaleFactor(1.0f),
m_nearClip(0.3f), m_farClip(5000.0f), m_predictionDelta(0.03f)
{
// Init Oculus HMD
OVR::System::Init(OVR::Log::ConfigureDefaultLog(OVR::LogMask_All));
Expand Down Expand Up @@ -258,6 +261,11 @@ void OculusDevice::setSensorPredictionEnabled(bool prediction)

float OculusDevice::distortionScale() const
{
// Disable distortion scale calculation and use user suppied value instead
if (m_useCustomScaleFactor) {
return m_customScaleFactor;
}

float lensShift = hScreenSize() * 0.25f - lensSeparationDistance() * 0.5f;
float lensViewportShift = 4.0f * lensShift / hScreenSize();
float fitRadius = fabs(-1 - lensViewportShift);
Expand Down
7 changes: 4 additions & 3 deletions src/oculusdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class OculusDevice {
osg::Vec2f scale() const;
osg::Vec2f scaleIn() const;

void setScaleFactor(float scaleFactor) { m_scaleFactor = scaleFactor; }
float scaleFactor() const { return m_scaleFactor; }
float scaleFactor() const { return distortionScale(); }

float aspectRatio() const { return float (hScreenResolution()/2) / float (vScreenResolution()); }
osg::Quat getOrientation() const;
Expand All @@ -56,6 +55,7 @@ class OculusDevice {

void setSensorPredictionEnabled(bool prediction);
void setSensorPredictionDelta(float delta) { m_predictionDelta = delta; }
void setCustomScaleFactor(const float& customScaleFactor) { m_useCustomScaleFactor = true; m_customScaleFactor = customScaleFactor; }

protected:
float viewCenter() const { return hScreenSize() * 0.25f; }
Expand All @@ -66,7 +66,8 @@ class OculusDevice {
OVR::HMDDevice* m_hmdDevice;
OVR::HMDInfo* m_hmdInfo;
OVR::SensorFusion* m_sensorFusion;
float m_scaleFactor;
bool m_useCustomScaleFactor;
float m_customScaleFactor;
float m_nearClip;
float m_farClip;
float m_predictionDelta;
Expand Down

0 comments on commit ad6c6e7

Please sign in to comment.