diff --git a/code/nel/include/nel/3d/stereo_hmd.h b/code/nel/include/nel/3d/stereo_hmd.h index bbb80368e..95c159cfd 100644 --- a/code/nel/include/nel/3d/stereo_hmd.h +++ b/code/nel/include/nel/3d/stereo_hmd.h @@ -52,14 +52,18 @@ public: /// Get the HMD orientation virtual NLMISC::CQuat getOrientation() const = 0; - - /// Set the head model, eye position relative to orientation point - // virtual void setEyePosition(const NLMISC::CVector &v) = 0; - /// Get the head model, eye position relative to orientation point - // virtual const NLMISC::CVector &getEyePosition() const = 0; + /// Get GUI center (1 = width, 1 = height, 0 = center) virtual void getInterface2DShift(uint cid, float &x, float &y, float distance) const = 0; + /// Set the head model, eye position relative to orientation point + virtual void setEyePosition(const NLMISC::CVector &v) = 0; + /// Get the head model, eye position relative to orientation point + virtual const NLMISC::CVector &getEyePosition() const = 0; + + /// Set the scale of the game in units per meter + virtual void setScale(float s) = 0; + }; /* class IStereoHMD */ } /* namespace NL3D */ diff --git a/code/nel/include/nel/3d/stereo_ovr.h b/code/nel/include/nel/3d/stereo_ovr.h index be3880bef..770dd97c1 100644 --- a/code/nel/include/nel/3d/stereo_ovr.h +++ b/code/nel/include/nel/3d/stereo_ovr.h @@ -117,9 +117,18 @@ public: /// Get the HMD orientation virtual NLMISC::CQuat getOrientation() const; + /// Get GUI center (1 = width, 1 = height, 0 = center) virtual void getInterface2DShift(uint cid, float &x, float &y, float distance) const; + /// Set the head model, eye position relative to orientation point + virtual void setEyePosition(const NLMISC::CVector &v); + /// Get the head model, eye position relative to orientation point + virtual const NLMISC::CVector &getEyePosition() const; + + /// Set the scale of the game in units per meter + virtual void setScale(float s); + static void listDevices(std::vector &devicesOut); static bool isLibraryInUse(); @@ -150,6 +159,8 @@ private: NLMISC::CQuadUV m_BarrelQuadLeft; NLMISC::CQuadUV m_BarrelQuadRight; CPixelProgram *m_PixelProgram; + NLMISC::CVector m_EyePosition; + float m_Scale; }; /* class CStereoOVR */ diff --git a/code/nel/src/3d/stereo_ovr.cpp b/code/nel/src/3d/stereo_ovr.cpp index a5397e77f..f3534a10c 100644 --- a/code/nel/src/3d/stereo_ovr.cpp +++ b/code/nel/src/3d/stereo_ovr.cpp @@ -165,7 +165,7 @@ public: OVR::HMDInfo HMDInfo; }; -CStereoOVR::CStereoOVR(const CStereoOVRDeviceHandle *handle) : m_Stage(0), m_SubStage(0), m_OrientationCached(false), m_Driver(NULL), m_BarrelTexU(NULL), m_PixelProgram(NULL) +CStereoOVR::CStereoOVR(const CStereoOVRDeviceHandle *handle) : m_Stage(0), m_SubStage(0), m_OrientationCached(false), m_Driver(NULL), m_BarrelTexU(NULL), m_PixelProgram(NULL), m_EyePosition(0.0f, 0.09f, 0.15f), m_Scale(1.0f) { ++s_DeviceCounter; m_DevicePtr = new CStereoOVRDevicePtr(); @@ -433,8 +433,8 @@ void CStereoOVR::getCurrentFrustum(uint cid, NL3D::UCamera *camera) const void CStereoOVR::getCurrentMatrix(uint cid, NL3D::UCamera *camera) const { CMatrix translate; - if (m_Stage % 2) translate.translate(CVector(m_DevicePtr->HMDInfo.InterpupillaryDistance * -0.5f, 0.f, 0.f)); - else translate.translate(CVector(m_DevicePtr->HMDInfo.InterpupillaryDistance * 0.5f, 0.f, 0.f)); + if (m_Stage % 2) translate.translate(CVector((m_DevicePtr->HMDInfo.InterpupillaryDistance * m_Scale) * -0.5f, 0.f, 0.f)); + else translate.translate(CVector((m_DevicePtr->HMDInfo.InterpupillaryDistance * m_Scale) * 0.5f, 0.f, 0.f)); camera->setTransformMode(NL3D::UTransformable::DirectMatrix); camera->setMatrix(m_CameraMatrix[cid] * translate); } @@ -594,6 +594,8 @@ void CStereoOVR::getInterface2DShift(uint cid, float &x, float &y, float distanc { #if 0 + // todo: take into account m_EyePosition + NLMISC::CVector vector = CVector(0.f, -distance, 0.f); NLMISC::CQuat rot = getOrientation(); rot.invert(); @@ -616,11 +618,12 @@ void CStereoOVR::getInterface2DShift(uint cid, float &x, float &y, float distanc #elif 1 // Alternative method + // todo: take into account m_EyePosition NLMISC::CVector vec = CVector(0.f, -distance, 0.f); NLMISC::CVector ipd; - if (m_Stage % 2) ipd = CVector(m_DevicePtr->HMDInfo.InterpupillaryDistance * -0.5f, 0.f, 0.f); - else ipd = CVector(m_DevicePtr->HMDInfo.InterpupillaryDistance * 0.5f, 0.f, 0.f); + if (m_Stage % 2) ipd = CVector((m_DevicePtr->HMDInfo.InterpupillaryDistance * m_Scale) * -0.5f, 0.f, 0.f); + else ipd = CVector((m_DevicePtr->HMDInfo.InterpupillaryDistance * m_Scale) * 0.5f, 0.f, 0.f); NLMISC::CQuat rot = getOrientation(); @@ -640,6 +643,22 @@ void CStereoOVR::getInterface2DShift(uint cid, float &x, float &y, float distanc #endif } +void CStereoOVR::setEyePosition(const NLMISC::CVector &v) +{ + m_EyePosition = v; +} + +const NLMISC::CVector &CStereoOVR::getEyePosition() const +{ + return m_EyePosition; +} + +void CStereoOVR::setScale(float s) +{ + m_EyePosition = m_EyePosition * (s / m_Scale); + m_Scale = s; +} + void CStereoOVR::listDevices(std::vector &devicesOut) { s_StereoOVRSystem.Init(); diff --git a/code/snowballs2/client/src/camera.cpp b/code/snowballs2/client/src/camera.cpp index 92216fe98..ebb4827ab 100644 --- a/code/snowballs2/client/src/camera.cpp +++ b/code/snowballs2/client/src/camera.cpp @@ -119,6 +119,7 @@ void initCamera() { nlinfo("Stereo display device is a HMD"); StereoHMD = static_cast(StereoDisplay); + StereoHMD->setScale(3.0f); // snowballs is about 4 units per meter } StereoDisplay->setDriver(Driver); // move after driver creation, move stereodisplay before driver creation } @@ -189,7 +190,9 @@ void updateCamera() NLMISC::CMatrix camMatrix = Camera.getMatrix(); NLMISC::CMatrix hmdMatrix; hmdMatrix.setRot(hmdOrient); - Camera.setMatrix(camMatrix * hmdMatrix); + NLMISC::CMatrix posMatrix; // minimal head modeling, will be changed in the future + posMatrix.translate(StereoHMD->getEyePosition()); + Camera.setMatrix((camMatrix * hmdMatrix) * posMatrix); } // Set the new position of the snow emitter CMatrix mat = CMatrix::Identity; diff --git a/code/snowballs2/client/src/commands.cpp b/code/snowballs2/client/src/commands.cpp index e6e7a0086..6d9b23085 100644 --- a/code/snowballs2/client/src/commands.cpp +++ b/code/snowballs2/client/src/commands.cpp @@ -388,7 +388,7 @@ void updateCommands() if (StereoHMD) { float xshift, yshift; - StereoHMD->getInterface2DShift(0, xshift, yshift, 1.f); + StereoHMD->getInterface2DShift(0, xshift, yshift, 4.f); // snap to pixels xshift = ((float)(sint32)(xshift * width)) / width; yshift = ((float)(sint32)(yshift * height)) / height; diff --git a/code/snowballs2/client/src/compass.cpp b/code/snowballs2/client/src/compass.cpp index e01173f66..9cc6fac57 100644 --- a/code/snowballs2/client/src/compass.cpp +++ b/code/snowballs2/client/src/compass.cpp @@ -98,7 +98,7 @@ void updateCompass () if (StereoHMD) { float xshift, yshift; - StereoHMD->getInterface2DShift(0, xshift, yshift, 1.f); + StereoHMD->getInterface2DShift(0, xshift, yshift, 4.f); x += xshift; y += yshift; } diff --git a/code/snowballs2/client/src/snowballs_client.cpp b/code/snowballs2/client/src/snowballs_client.cpp index c510af7ec..ea0bc2648 100644 --- a/code/snowballs2/client/src/snowballs_client.cpp +++ b/code/snowballs2/client/src/snowballs_client.cpp @@ -933,6 +933,8 @@ void renderInformation() TextContext->setColor(CRGBA(255, 255, 255, 255)); TextContext->setFontSize(14); TextContext->printfAt(0.01f, 0.99f, "%.2f(%.2f)fps %.3fs", FramesPerSecondSmooth, FramesPerSecond, (float)LocalTimeDelta); + CVector camPos = Camera.getMatrix().getPos(); + TextContext->printfAt(0.01f, 0.89f, "CAM POS: %.3f %.3f %.3f", camPos.x, camPos.y, camPos.z); // one more frame FpsGraph.addValue(1.0f);