prepare support for VR

This commit is contained in:
erwin coumans 2016-05-19 09:19:36 -07:00
parent 876c9e57fe
commit b961545292
3 changed files with 41 additions and 5 deletions

View File

@ -6,6 +6,8 @@ struct CommonCameraInterface
virtual void getCameraProjectionMatrix(float m[16])const = 0; virtual void getCameraProjectionMatrix(float m[16])const = 0;
virtual void getCameraViewMatrix(float m[16]) const = 0; virtual void getCameraViewMatrix(float m[16]) const = 0;
virtual void setVRCamera(const float viewMat[16], const float projectionMatrix[16])=0;
virtual void getCameraTargetPosition(float pos[3]) const = 0; virtual void getCameraTargetPosition(float pos[3]) const = 0;
virtual void getCameraPosition(float pos[3]) const = 0; virtual void getCameraPosition(float pos[3]) const = 0;

View File

@ -16,7 +16,8 @@ struct SimpleCameraInternalData
m_pitch(0), m_pitch(0),
m_aspect(1), m_aspect(1),
m_frustumZNear(0.01), m_frustumZNear(0.01),
m_frustumZFar(1000) m_frustumZFar(1000),
m_enableVR(false)
{ {
} }
b3Vector3 m_cameraTargetPosition; b3Vector3 m_cameraTargetPosition;
@ -32,6 +33,11 @@ struct SimpleCameraInternalData
float m_aspect; float m_aspect;
float m_frustumZNear; float m_frustumZNear;
float m_frustumZFar; float m_frustumZFar;
bool m_enableVR;
float m_viewMatrixVR[16];
float m_projectionMatrixVR[16];
}; };
@ -46,7 +52,15 @@ SimpleCamera::~SimpleCamera()
delete m_data; delete m_data;
} }
void SimpleCamera::setVRCamera(const float viewMat[16], const float projectionMatrix[16])
{
m_data->m_enableVR = true;
for (int i=0;i<16;i++)
{
m_data->m_viewMatrixVR[i] = viewMat[i];
m_data->m_projectionMatrixVR[i] = projectionMatrix[i];
}
}
static void b3CreateFrustum( static void b3CreateFrustum(
@ -171,7 +185,7 @@ void SimpleCamera::update()
break; break;
default: default:
{ {
b3Assert(0); //b3Assert(0);
return; return;
} }
}; };
@ -209,11 +223,29 @@ void SimpleCamera::update()
void SimpleCamera::getCameraProjectionMatrix(float projectionMatrix[16]) const void SimpleCamera::getCameraProjectionMatrix(float projectionMatrix[16]) const
{ {
b3CreateFrustum(-m_data->m_aspect * m_data->m_frustumZNear, m_data->m_aspect * m_data->m_frustumZNear, -m_data->m_frustumZNear,m_data->m_frustumZNear, m_data->m_frustumZNear, m_data->m_frustumZFar,projectionMatrix); if (m_data->m_enableVR)
{
for (int i=0;i<16;i++)
{
projectionMatrix[i] = m_data->m_projectionMatrixVR[i];
}
} else
{
b3CreateFrustum(-m_data->m_aspect * m_data->m_frustumZNear, m_data->m_aspect * m_data->m_frustumZNear, -m_data->m_frustumZNear,m_data->m_frustumZNear, m_data->m_frustumZNear, m_data->m_frustumZFar,projectionMatrix);
}
} }
void SimpleCamera::getCameraViewMatrix(float viewMatrix[16]) const void SimpleCamera::getCameraViewMatrix(float viewMatrix[16]) const
{ {
b3CreateLookAt(m_data->m_cameraPosition,m_data->m_cameraTargetPosition,m_data->m_cameraUp,viewMatrix); if (m_data->m_enableVR)
{
for (int i=0;i<16;i++)
{
viewMatrix[i] = m_data->m_viewMatrixVR[i];
}
} else
{
b3CreateLookAt(m_data->m_cameraPosition,m_data->m_cameraTargetPosition,m_data->m_cameraUp,viewMatrix);
}
} }
void SimpleCamera::getCameraTargetPosition(double pos[3]) const void SimpleCamera::getCameraTargetPosition(double pos[3]) const

View File

@ -14,6 +14,8 @@ struct SimpleCamera : public CommonCameraInterface
virtual void getCameraProjectionMatrix(float m[16]) const; virtual void getCameraProjectionMatrix(float m[16]) const;
virtual void getCameraViewMatrix(float m[16]) const; virtual void getCameraViewMatrix(float m[16]) const;
virtual void setVRCamera(const float viewMat[16], const float projectionMatrix[16]);
virtual void getCameraTargetPosition(float pos[3]) const; virtual void getCameraTargetPosition(float pos[3]) const;
virtual void getCameraPosition(float pos[3]) const; virtual void getCameraPosition(float pos[3]) const;