Commit 209bb0a3 authored by Ken Martin's avatar Ken Martin

some tweaks and fixes for VR

A few tweaks and fixes as detailed below.

Remove the use of a physical scale factor in
computing the camera transforms. Instead use the
distance from the focal point to the camera as a
metric. That distance will be mapped into one
meter in the physical space. This fits the model
of a camera dolly.

This has the advantage of removing the scale factor that
was being added into the World to View matrix. We generally
assume there is not a scale in the world to view matrix and
that was causing some issues with some shaders (such as imposters)

Fix an issue where the scale was being added to the NormalMatrix
The normal matrix should never have a scale.

Adjust the scaling interaction to scale about a meter above the
floor. This is more intuitive than scaling from the floor as an
origin.

Fix a bug in the Oculus code when a buffer submission failed with
a resubmit success error code.
parent 1cb5a963
Pipeline #24789 passed with stage
......@@ -322,8 +322,7 @@ void vtkInteractorStyle3D::Dolly()
double *trans = rwi->GetPhysicalTranslation(
this->CurrentRenderer->GetActiveCamera());
double scale = rwi->GetPhysicalScale(
this->CurrentRenderer->GetActiveCamera());
double distance = this->CurrentRenderer->GetActiveCamera()->GetDistance();
// move at a max rate of 0.1 meters per frame in HMD space
// this works out to about 10 meters per second
......@@ -335,9 +334,9 @@ void vtkInteractorStyle3D::Dolly()
float *tpos = rwi->GetTouchPadPosition();
rwi->SetPhysicalTranslation(
this->CurrentRenderer->GetActiveCamera(),
trans[0]-vdir[0]*0.05*tpos[1]/scale,
trans[1]-vdir[1]*0.05*tpos[1]/scale,
trans[2]-vdir[2]*0.05*tpos[1]/scale);
trans[0]-vdir[0]*0.05*tpos[1]*distance,
trans[1]-vdir[1]*0.05*tpos[1]*distance,
trans[2]-vdir[2]*0.05*tpos[1]*distance);
if (this->AutoAdjustCameraClippingRange)
{
......@@ -365,8 +364,39 @@ void vtkInteractorStyle3D::OnPinch()
double dyf = this->Interactor->GetScale()/this->Interactor->GetLastScale();
double scale = rwi->GetPhysicalScale(camera);
rwi->SetPhysicalScale(camera, scale*dyf);
double *trans = rwi->GetPhysicalTranslation(
this->CurrentRenderer->GetActiveCamera());
double distance = camera->GetDistance();
double *dop = camera->GetDirectionOfProjection();
double *pos = camera->GetPosition();
double hmd[3];
hmd[0] = (pos[0] + trans[0])/distance;
hmd[1] = (pos[1] + trans[1])/distance;
hmd[2] = (pos[2] + trans[2])/distance;
double newDistance = distance/dyf;
rwi->SetPhysicalTranslation(camera,
trans[0], trans[1] - distance + newDistance, trans[2]);
trans = rwi->GetPhysicalTranslation(camera);
double newPos[3];
newPos[0] = hmd[0]*newDistance - trans[0];
newPos[1] = hmd[1]*newDistance - trans[1];
newPos[2] = hmd[2]*newDistance - trans[2];
camera->SetFocalPoint(
newPos[0] + dop[0]*newDistance,
newPos[1] + dop[1]*newDistance,
newPos[2] + dop[2]*newDistance);
camera->SetPosition(
newPos[0],
newPos[1],
newPos[2]);
if (this->AutoAdjustCameraClippingRange)
{
this->CurrentRenderer->ResetCameraClippingRange();
}
}
......@@ -391,14 +421,14 @@ void vtkInteractorStyle3D::OnPan()
double *trans = rwi->GetTranslation3D();
double *ptrans = rwi->GetPhysicalTranslation(camera);
double scale = rwi->GetPhysicalScale(camera);
double distance = camera->GetDistance();
rwi->SetPhysicalTranslation(camera,
ptrans[0] - this->AppliedTranslation[0] + trans[0]/scale,
ptrans[1] - this->AppliedTranslation[1] + trans[1]/scale,
ptrans[2] - this->AppliedTranslation[2] + trans[2]/scale);
this->AppliedTranslation[0] = trans[0]/scale;
this->AppliedTranslation[1] = trans[1]/scale;
this->AppliedTranslation[2] = trans[2]/scale;
ptrans[0] - this->AppliedTranslation[0] + trans[0]*distance,
ptrans[1] - this->AppliedTranslation[1] + trans[1]*distance,
ptrans[2] - this->AppliedTranslation[2] + trans[2]*distance);
this->AppliedTranslation[0] = trans[0]*distance;
this->AppliedTranslation[1] = trans[1]*distance;
this->AppliedTranslation[2] = trans[2]*distance;
// clean up
if (this->Interactor->GetLightFollowCamera())
......
......@@ -207,12 +207,6 @@ public:
vtkSetVector2Macro(TouchPadPosition,float);
vtkGetVector2Macro(TouchPadPosition,float);
// Description:
// Set/Get the optional scale to map world coordinates into the
// 3D physical space (meters).
virtual void SetPhysicalScale(vtkCamera *, double) {};
virtual double GetPhysicalScale(vtkCamera *) { return 1.0; };
// Description:
// Set/Get the optional translation to map world coordinates into the
// 3D physical space (meters, 0,0,0).
......@@ -233,9 +227,7 @@ protected:
int StartedMessageLoop;
float TouchPadPosition[2];
double Translation3D[3];
double LastTranslation3D[23];
double PhysicalScale;
double PhysicalTranslation;
double LastTranslation3D[3];
bool Done; // is the event loop done running
......
......@@ -31,17 +31,24 @@
#include "vtkCullerCollection.h"
#include "vtkLight.h"
#include "vtkOculusCamera.h"
#include "vtkOculusRenderer.h"
#include "vtkOculusRenderWindow.h"
#include "vtkOculusRenderWindowInteractor.h"
//----------------------------------------------------------------------------
int TestDragon(int argc, char *argv[])
{
vtkNew<vtkActor> actor;
vtkNew<vtkRenderer> renderer;
vtkNew<vtkOculusRenderer> renderer;
renderer->SetBackground(0.2, 0.3, 0.4);
vtkNew<vtkRenderWindow> renderWindow;
vtkNew<vtkOculusRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer.Get());
renderer->AddActor(actor.Get());
vtkNew<vtkRenderWindowInteractor> iren;
vtkNew<vtkOculusRenderWindowInteractor> iren;
iren->SetRenderWindow(renderWindow.Get());
vtkNew<vtkOculusCamera> cam;
renderer->SetActiveCamera(cam.Get());
// crazy frame rate requirement
// need to look into that at some point
......@@ -56,8 +63,9 @@ int TestDragon(int argc, char *argv[])
light->SetPosition(0.0, 1.0, 0.3);
renderer->AddLight(light.Get());
const char* fileName = vtkTestUtilities::ExpandDataFileName(argc, argv,
"Data/dragon.ply");
const char* fileName =
vtkTestUtilities::ExpandDataFileName(
argc, argv, "Data/dragon.ply");
vtkNew<vtkPLYReader> reader;
reader->SetFileName(fileName);
reader->Update();
......
......@@ -34,13 +34,11 @@ vtkOculusCamera::vtkOculusCamera()
this->RightWCDCMatrix = vtkMatrix4x4::New();
this->RightWCVCMatrix = vtkMatrix4x4::New();
this->RightNormalMatrix = vtkMatrix3x3::New();
this->RightVCDCMatrix = vtkMatrix4x4::New();
this->LeftEyeTCDCMatrix = vtkMatrix4x4::New();
this->RightEyeTCDCMatrix = vtkMatrix4x4::New();
this->Scale = 1.0;
this->Translation[0] = 0.0;
this->Translation[1] = 0.0;
this->Translation[2] = 0.0;
......@@ -65,7 +63,6 @@ vtkOculusCamera::~vtkOculusCamera()
this->RightWCDCMatrix->Delete();
this->RightWCVCMatrix->Delete();
this->RightNormalMatrix->Delete();
this->RightVCDCMatrix->Delete();
this->LeftEyeTCDCMatrix->Delete();
......@@ -78,16 +75,17 @@ void vtkOculusCamera::GetHMDEyePoses(vtkRenderer *ren)
vtkOculusRenderWindow::SafeDownCast(ren->GetRenderWindow());
ovrVector3f *eyeOffsets = win->GetHMDToEyeViewOffsets();
double distance = this->GetDistance();
this->LeftEyePose->Identity();
this->LeftEyePose->SetElement(0, 3, -eyeOffsets[0].x);
this->LeftEyePose->SetElement(1, 3, -eyeOffsets[0].y);
this->LeftEyePose->SetElement(2, 3, -eyeOffsets[0].z);
this->LeftEyePose->SetElement(0, 3, -eyeOffsets[0].x*distance);
this->LeftEyePose->SetElement(1, 3, -eyeOffsets[0].y*distance);
this->LeftEyePose->SetElement(2, 3, -eyeOffsets[0].z*distance);
this->RightEyePose->Identity();
this->RightEyePose->SetElement(0, 3, -eyeOffsets[1].x);
this->RightEyePose->SetElement(1, 3, -eyeOffsets[1].y);
this->RightEyePose->SetElement(2, 3, -eyeOffsets[1].z);
this->RightEyePose->SetElement(0, 3, -eyeOffsets[1].x*distance);
this->RightEyePose->SetElement(1, 3, -eyeOffsets[1].y*distance);
this->RightEyePose->SetElement(2, 3, -eyeOffsets[1].z*distance);
}
void vtkOculusCamera::GetHMDEyeProjections(vtkRenderer *ren)
......@@ -96,8 +94,8 @@ void vtkOculusCamera::GetHMDEyeProjections(vtkRenderer *ren)
vtkOculusRenderWindow::SafeDownCast(ren->GetRenderWindow());
ovrMatrix4f proj = ovrMatrix4f_Projection(win->GetOVRLayer().Fov[0],
this->ClippingRange[0]*this->Scale,
this->ClippingRange[1]*this->Scale,
this->ClippingRange[0],
this->ClippingRange[1],
0);
for(int i = 0; i < 4; ++i)
......@@ -109,8 +107,8 @@ void vtkOculusCamera::GetHMDEyeProjections(vtkRenderer *ren)
}
proj = ovrMatrix4f_Projection(win->GetOVRLayer().Fov[1],
this->ClippingRange[0]*this->Scale,
this->ClippingRange[1]*this->Scale,
this->ClippingRange[0],
this->ClippingRange[1],
0);
for(int i = 0; i < 4; ++i)
......@@ -130,33 +128,34 @@ void vtkOculusCamera::Render(vtkRenderer *ren)
vtkOculusRenderWindow *win =
vtkOculusRenderWindow::SafeDownCast(ren->GetRenderWindow());
// make sure clipping range is not crazy
// with Oculus we know we are in meters so
// we can use that knowledge to make the
// clipping range reasonable
double nRange[2];
this->GetClippingRange(nRange);
nRange[0] = nRange[0]*this->Scale;
nRange[1] = nRange[1]*this->Scale;
// to see controllers etc make sure near is around 20 cm
// people tend to go cross eyed at 20 cm so we use that
// as a limit
nRange[0] = 0.10;
// to see transmitters make sure far is at least 6 meters
if (nRange[1] < 6.0)
{
nRange[1] = 6.0;
}
// make sure far is not crazy far > 500m
if (nRange[1] > 500.0)
{
nRange[1] = 500.0;
}
this->SetClippingRange(nRange[0]/this->Scale, nRange[1]/this->Scale);
// if were on a stereo renderer draw to special parts of screen
if (this->LeftEye)
{
// make sure clipping range is not crazy
// we know we are in meters so
// we can use that knowledge to make the
// clipping range reasonable
double nRange[2];
this->GetClippingRange(nRange);
double distance = this->GetDistance();
nRange[0] = nRange[0]/distance;
nRange[1] = nRange[1]/distance;
// to see controllers etc make sure near is around 10 cm
// people tend to go cross eyed at +10 cm from HMD so we use that
// as a limit
nRange[0] = 0.1;
// to see transmitters make sure far is at least 6 meters
if (nRange[1] < 6.0)
{
nRange[1] = 6.0;
}
// make sure far is not crazy far > 100m
if (nRange[1] > 100.0)
{
nRange[1] = 100.0;
}
this->SetClippingRange(nRange[0]*distance, nRange[1]*distance);
// Left Eye
ovrRecti vp = win->GetOVRLayer().Viewport[0];
glViewport(vp.Pos.x, vp.Pos.y, vp.Size.w, vp.Size.h);
......@@ -186,8 +185,6 @@ void vtkOculusCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
this->RightEyePose = vtkMatrix4x4::New();
this->LeftEyeProjection = vtkMatrix4x4::New();
this->RightEyeProjection = vtkMatrix4x4::New();
this->GetHMDEyePoses(ren);
}
// has the camera changed?
......@@ -195,32 +192,24 @@ void vtkOculusCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
this->MTime > this->KeyMatrixTime ||
ren->GetMTime() > this->KeyMatrixTime)
{
this->GetHMDEyePoses(ren);
this->GetHMDEyeProjections(ren);
// build both eye views, faster to do it all at once as
// some calculations are shared
// first apply the scale
this->WCVCMatrix->Zero();
this->WCVCMatrix->Element[0][0] = this->Scale;
this->WCVCMatrix->Element[1][1] = this->Scale;
this->WCVCMatrix->Element[2][2] = this->Scale;
this->WCVCMatrix->Element[3][3] = 1.0;
vtkMatrix4x4::Multiply4x4(this->WCVCMatrix,
this->GetModelViewTransformMatrix(),this->WCVCMatrix);
vtkMatrix4x4::Multiply4x4(this->RightEyePose, this->WCVCMatrix, this->RightWCVCMatrix);
vtkMatrix4x4::Multiply4x4(this->LeftEyePose, this->WCVCMatrix, this->WCVCMatrix);
vtkMatrix4x4 *w2v = this->GetModelViewTransformMatrix();
vtkMatrix4x4::Multiply4x4(this->RightEyePose, w2v, this->RightWCVCMatrix);
vtkMatrix4x4::Multiply4x4(this->LeftEyePose, w2v, this->WCVCMatrix);
for(int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
this->NormalMatrix->SetElement(i, j, this->WCVCMatrix->GetElement(i, j));
this->RightNormalMatrix->SetElement(i, j, this->RightWCVCMatrix->GetElement(i, j));
}
}
this->NormalMatrix->Invert();
this->RightNormalMatrix->Invert();
this->WCVCMatrix->Transpose();
this->RightWCVCMatrix->Transpose();
......@@ -242,7 +231,7 @@ void vtkOculusCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
else
{
wcvc = this->RightWCVCMatrix;
normMat = this->RightNormalMatrix;
normMat = this->NormalMatrix;
vcdc = this->RightEyeProjection;
wcdc = this->RightWCDCMatrix;
}
......
......@@ -46,12 +46,6 @@ public:
// to device coordinates. Used for rendering devices.
virtual void GetTrackingToDCMatrix(vtkMatrix4x4 *&TCDCMatrix);
// Description:
// Set/Get the scale to map world coordinates into the
// Oculus physical space (meters).
vtkSetMacro(Scale,double);
vtkGetMacro(Scale,double);
// Description:
// Set/Get the translation to map world coordinates into the
// Oculus physical space (meters, 0,0,0).
......@@ -74,7 +68,6 @@ protected:
vtkMatrix4x4 *RightWCDCMatrix;
vtkMatrix4x4 *RightWCVCMatrix;
vtkMatrix3x3 *RightNormalMatrix;
vtkMatrix4x4 *RightVCDCMatrix;
vtkMatrix4x4 *LeftEyeTCDCMatrix;
......@@ -82,7 +75,6 @@ protected:
// used to scale and/or translate the
// View to the HMD space
double Scale;
double Translation[3];
vtkNew<vtkTransform> PoseTransform;
......
......@@ -199,7 +199,7 @@ void vtkOculusRenderWindow::UpdateHMDMatrixPose()
this->HMDTransform->Identity();
double *trans = cam->GetTranslation();
this->HMDTransform->Translate(-trans[0],-trans[1],-trans[2]);
double scale = 1.0/cam->GetScale();
double scale = cam->GetDistance();
this->HMDTransform->Scale(scale,scale,scale);
this->HMDTransform->Concatenate(elems);
......@@ -270,6 +270,10 @@ void vtkOculusRenderWindow::Frame(void)
// Submit frame with one layer we have.
ovrLayerHeader* layers = &this->OVRLayer.Header;
ovrResult result = ovr_SubmitFrame(this->Session, 0, nullptr, &layers, 1);
while (result == ovrSuccess_NotVisible)
{
result = ovr_SubmitFrame(this->Session, 0, nullptr, &layers, 1);
}
if (result != ovrSuccess)
{
vtkWarningMacro("failed to submit frame");
......
......@@ -48,20 +48,6 @@ vtkOculusRenderWindowInteractor::~vtkOculusRenderWindowInteractor()
{
}
void vtkOculusRenderWindowInteractor::SetPhysicalScale(vtkCamera *camin, double s)
{
vtkOculusCamera *cam =
static_cast<vtkOculusCamera *>(camin);
cam->SetScale(s);
}
double vtkOculusRenderWindowInteractor::GetPhysicalScale(vtkCamera *camin)
{
vtkOculusCamera *cam =
static_cast<vtkOculusCamera *>(camin);
return cam->GetScale();
}
void vtkOculusRenderWindowInteractor::SetPhysicalTranslation(vtkCamera *camin, double t1, double t2, double t3)
{
vtkOculusCamera *cam =
......
......@@ -59,12 +59,6 @@ public:
// callbacks. They allow for the Style to invoke them.
virtual void ExitCallback();
// Description:
// Set/Get the optional scale to map world coordinates into the
// 3D physical space (meters).
virtual void SetPhysicalScale(vtkCamera *, double);
virtual double GetPhysicalScale(vtkCamera *);
// Description:
// Set/Get the optional translation to map world coordinates into the
// 3D physical space (meters, 0,0,0).
......
......@@ -152,7 +152,6 @@ void vtkOculusRenderer::ResetCamera(double bounds[6])
// the center of the world to be in front of the user
vtkOculusCamera *cam = vtkOculusCamera::SafeDownCast(this->ActiveCamera);
cam->SetTranslation(-center[0],-center[1],-center[2]-distance);
cam->SetScale(1.0/distance);
}
// Alternative version of ResetCamera(bounds[6]);
......
......@@ -38,6 +38,11 @@
#include "vtkLight.h"
#include "vtkOpenVRRenderer.h"
#include "vtkOpenVRCamera.h"
#include "vtkOpenVRRenderWindow.h"
#include "vtkOpenVRRenderWindowINteractor.h"
// #include "vtkLODPointCloudMapper.h"
// #include "vtkXMLMultiBlockDataReader.h"
......@@ -45,13 +50,15 @@
int TestDragon(int argc, char *argv[])
{
vtkNew<vtkActor> actor;
vtkNew<vtkRenderer> renderer;
vtkNew<vtkOpenVRRenderer> renderer;
renderer->SetBackground(0.2, 0.3, 0.4);
vtkNew<vtkRenderWindow> renderWindow;
vtkNew<vtkOpenVRRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer.Get());
renderer->AddActor(actor.Get());
vtkNew<vtkRenderWindowInteractor> iren;
vtkNew<vtkOpenVRRenderWindowInteractor> iren;
iren->SetRenderWindow(renderWindow.Get());
vtkNew<vtkOpenVRCamera> cam;
renderer->SetActiveCamera(cam.Get());
// crazy frame rate requirement
// need to look into that at some point
......
......@@ -35,13 +35,11 @@ vtkOpenVRCamera::vtkOpenVRCamera()
this->RightWCDCMatrix = vtkMatrix4x4::New();
this->RightWCVCMatrix = vtkMatrix4x4::New();
this->RightNormalMatrix = vtkMatrix3x3::New();
this->RightVCDCMatrix = vtkMatrix4x4::New();
this->LeftEyeTCDCMatrix = vtkMatrix4x4::New();
this->RightEyeTCDCMatrix = vtkMatrix4x4::New();
this->Scale = 1.0;
this->Translation[0] = 0.0;
this->Translation[1] = 0.0;
this->Translation[2] = 0.0;
......@@ -69,7 +67,6 @@ vtkOpenVRCamera::~vtkOpenVRCamera()
this->RightWCDCMatrix->Delete();
this->RightWCVCMatrix->Delete();
this->RightNormalMatrix->Delete();
this->RightVCDCMatrix->Delete();
this->LeftEyeTCDCMatrix->Delete();
......@@ -83,27 +80,19 @@ void vtkOpenVRCamera::GetHMDEyePoses(vtkRenderer *ren)
vr::IVRSystem *hMD = win->GetHMD();
double distance = this->GetDistance();
vr::HmdMatrix34_t matEye = hMD->GetEyeToHeadTransform( vr::Eye_Left );
this->LeftEyePose->Identity();
for(int i = 0; i < 3; ++i)
{
for (int j = 0; j < 4; ++j)
{
this->LeftEyePose->SetElement(i, j, matEye.m[i][j]);
}
this->LeftEyePose->SetElement(i, 3, -matEye.m[i][3]*distance);
}
matEye = hMD->GetEyeToHeadTransform( vr::Eye_Right );
this->RightEyePose->Identity();
for(int i = 0; i < 3; ++i)
{
for (int j = 0; j < 4; ++j)
{
this->RightEyePose->SetElement(i, j, matEye.m[i][j]);
}
this->RightEyePose->SetElement(i, 3, -matEye.m[i][3]*distance);
}
this->RightEyePose->Invert();
this->LeftEyePose->Invert();
}
void vtkOpenVRCamera::GetHMDEyeProjections(vtkRenderer *ren)
......@@ -113,12 +102,10 @@ void vtkOpenVRCamera::GetHMDEyeProjections(vtkRenderer *ren)
vr::IVRSystem *hMD = win->GetHMD();
// recall we have to apply a scale here
// from world to oepnvr
vr::HmdMatrix44_t mat =
hMD->GetProjectionMatrix( vr::Eye_Left,
this->ClippingRange[0]*this->Scale,
this->ClippingRange[1]*this->Scale, vr::API_OpenGL);
this->ClippingRange[0],
this->ClippingRange[1], vr::API_OpenGL);
for(int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
......@@ -129,8 +116,8 @@ void vtkOpenVRCamera::GetHMDEyeProjections(vtkRenderer *ren)
mat =
hMD->GetProjectionMatrix( vr::Eye_Right,
this->ClippingRange[0]*this->Scale,
this->ClippingRange[1]*this->Scale, vr::API_OpenGL);
this->ClippingRange[0],
this->ClippingRange[1], vr::API_OpenGL);
for(int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
......@@ -153,33 +140,34 @@ void vtkOpenVRCamera::Render(vtkRenderer *ren)
int renSize[2];
win->GetRenderBufferSize(renSize[0],renSize[1]);
// make sure clipping range is not crazy
// with OpenVR we know we are in meters so
// we can use that knowledge to make the
// clipping range reasonable
double nRange[2];
this->GetClippingRange(nRange);
nRange[0] = nRange[0]*this->Scale;
nRange[1] = nRange[1]*this->Scale;
// to see controllers etc make sure near is around 20 cm
// people tend to go cross eyed at 20 cm so we use that
// as a limit
nRange[0] = 0.20;
// to see transmitters make sure far is at least 6 meters
if (nRange[1] < 6.0)
{
nRange[1] = 6.0;
}
// make sure far is not crazy far > 500m
if (nRange[1] > 500.0)
{
nRange[1] = 500.0;
}
this->SetClippingRange(nRange[0]/this->Scale, nRange[1]/this->Scale);
// if were on a stereo renderer draw to special parts of screen
if (this->LeftEye)
{
// make sure clipping range is not crazy
// with OpenVR we know we are in meters so
// we can use that knowledge to make the
// clipping range reasonable
double nRange[2];
this->GetClippingRange(nRange);
double distance = this->GetDistance();
nRange[0] = nRange[0]/distance;
nRange[1] = nRange[1]/distance;
// to see controllers etc make sure near is around 10 cm
// people tend to go cross eyed at +10 cm from HMD so we use that
// as a limit
nRange[0] = 0.1;
// to see transmitters make sure far is at least 6 meters
if (nRange[1] < 6.0)
{
nRange[1] = 6.0;
}
// make sure far is not crazy far > 100m
if (nRange[1] > 100.0)
{
nRange[1] = 100.0;
}
this->SetClippingRange(nRange[0]*distance, nRange[1]*distance);
// Left Eye
if (win->GetMultiSamples())
{
......@@ -217,8 +205,6 @@ void vtkOpenVRCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
this->RightEyePose = vtkMatrix4x4::New();
this->LeftEyeProjection = vtkMatrix4x4::New();
this->RightEyeProjection = vtkMatrix4x4::New();
this->GetHMDEyePoses(ren);
}
// has the camera changed?
......@@ -226,32 +212,24 @@ void vtkOpenVRCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
this->MTime > this->KeyMatrixTime ||
ren->GetMTime() > this->KeyMatrixTime)
{
this->GetHMDEyePoses(ren);
this->GetHMDEyeProjections(ren);
// build both eye views, faster to do it all at once as
// some calculations are shared
// first apply the scale
this->WCVCMatrix->Zero();
this->WCVCMatrix->Element[0][0] = this->Scale;
this->WCVCMatrix->Element[1][1] = this->Scale;
this->WCVCMatrix->Element[2][2] = this->Scale;
this->WCVCMatrix->Element[3][3] = 1.0;
vtkMatrix4x4::Multiply4x4(this->WCVCMatrix,
this->GetModelViewTransformMatrix(),this->WCVCMatrix);
vtkMatrix4x4::Multiply4x4(this->RightEyePose, this->WCVCMatrix, this->RightWCVCMatrix);
vtkMatrix4x4::Multiply4x4(this->LeftEyePose, this->WCVCMatrix, this->WCVCMatrix);
vtkMatrix4x4 *w2v = this->GetModelViewTransformMatrix();
vtkMatrix4x4::Multiply4x4(this->RightEyePose, w2v, this->RightWCVCMatrix);
vtkMatrix4x4::Multiply4x4(this->LeftEyePose, w2v, this->WCVCMatrix);
for(int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
this->NormalMatrix->SetElement(i, j, this->WCVCMatrix->GetElement(i, j));
this->RightNormalMatrix->SetElement(i, j, this->RightWCVCMatrix->GetElement(i, j));
this->NormalMatrix->SetElement(i, j, w2v->GetElement(i, j));
}
}
this->NormalMatrix->Invert();
this->RightNormalMatrix->Invert();
this->WCVCMatrix->Transpose();
this->RightWCVCMatrix->Transpose();
......@@ -263,7 +241,7 @@ void vtkOpenVRCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
this->PoseTransform->Identity();
double *trans = this->Translation;
this->PoseTransform->Translate(-trans[0],-trans[1],-trans[2]);
double scale = 1.0/this->Scale;
double scale = this->GetDistance();
this->PoseTransform->Scale(scale,scale,scale);
this->LeftEyeTCDCMatrix->DeepCopy(this->PoseTransform->GetMatrix());
this->LeftEyeTCDCMatrix->Transpose();
......@@ -289,7 +267,7 @@ void vtkOpenVRCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
else
{
wcvc = this->RightWCVCMatrix;
normMat = this->RightNormalMatrix;
normMat = this->NormalMatrix;
vcdc = this->RightEyeProjection;
wcdc = this->RightWCDCMatrix;
}
......
......@@ -46,12 +46,6 @@ public:
// to device coordinates. Used for rendering devices.
virtual void GetTrackingToDCMatrix(vtkMatrix4x4 *&TCDCMatrix);
// Description:
// Set/Get the scale to map world coordinates into the
// OpenVR physical space (meters).
vtkSetMacro(Scale,double);
vtkGetMacro(Scale,double);
// Description:
// Set/Get the translation to map world coordinates into the
// OpenVR physical space (meters, 0,0,0).
......@@ -74,15 +68,13 @@ protected:
vtkMatrix4x4 *RightWCDCMatrix;
vtkMatrix4x4 *RightWCVCMatrix;
vtkMatrix3x3 *RightNormalMatrix;
vtkMatrix4x4 *RightVCDCMatrix;
vtkMatrix4x4 *LeftEyeTCDCMatrix;
vtkMatrix4x4 *RightEyeTCDCMatrix;
// used to scale and/or translate the
// used to translate the
// View to the HMD space
double Scale;
double Translation[3];
vtkNew<vtkTransform> PoseTransform;
......
......@@ -531,19 +531,6 @@ void vtkOpenVRRenderWindow::UpdateHMDMatrixPose()
// update the camera values based on the pose
if ( this->TrackedDevicePose[vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid )
{
double elems[16];
for (int j = 0; j < 3; j++)
{
for (int i = 0; i < 4; i++)
{
elems[i+j*4] = this->TrackedDevicePose[vr::k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking.m[j][i];
}
}
elems[12] = 0.0;
elems[13] = 0.0;
elems[14] = 0.0;
elems[15] = 1.0;
vtkRenderer *ren;