mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-23 07:36:16 +00:00
Add 2D interface shifting calculations, see #43
This commit is contained in:
parent
78ae99731d
commit
1b8ddaa87b
5 changed files with 52 additions and 3 deletions
|
@ -95,6 +95,8 @@ public:
|
||||||
/// Gets the current viewport
|
/// Gets the current viewport
|
||||||
virtual const NL3D::CViewport &getCurrentViewport() const;
|
virtual const NL3D::CViewport &getCurrentViewport() const;
|
||||||
/// Gets the current camera frustum
|
/// Gets the current camera frustum
|
||||||
|
virtual const NL3D::CFrustum &getCurrentFrustum() const;
|
||||||
|
/// Gets the current camera frustum
|
||||||
virtual void getCurrentFrustum(NL3D::UCamera *camera) const;
|
virtual void getCurrentFrustum(NL3D::UCamera *camera) const;
|
||||||
/// Gets the current camera matrix
|
/// Gets the current camera matrix
|
||||||
virtual void getCurrentMatrix(NL3D::UCamera *camera) const;
|
virtual void getCurrentMatrix(NL3D::UCamera *camera) const;
|
||||||
|
@ -119,6 +121,8 @@ public:
|
||||||
|
|
||||||
/// Get the HMD orientation
|
/// Get the HMD orientation
|
||||||
virtual NLMISC::CQuat getOrientation() const;
|
virtual NLMISC::CQuat getOrientation() const;
|
||||||
|
/// Get GUI center (1 = width, 1 = height, 0 = center) (todo: move to CStereoHMD)
|
||||||
|
void getInterface2DShift(float &x, float &y, float distance);
|
||||||
|
|
||||||
|
|
||||||
static void listDevices(std::vector<CStereoDeviceInfo> &devicesOut);
|
static void listDevices(std::vector<CStereoDeviceInfo> &devicesOut);
|
||||||
|
@ -140,6 +144,8 @@ private:
|
||||||
CFrustum m_LeftFrustum;
|
CFrustum m_LeftFrustum;
|
||||||
CFrustum m_RightFrustum;
|
CFrustum m_RightFrustum;
|
||||||
CMatrix m_CameraMatrix;
|
CMatrix m_CameraMatrix;
|
||||||
|
mutable bool m_OrientationCached;
|
||||||
|
mutable NLMISC::CQuat m_OrientationCache;
|
||||||
|
|
||||||
}; /* class CStereoOVR */
|
}; /* class CStereoOVR */
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ public:
|
||||||
OVR::HMDInfo HMDInfo;
|
OVR::HMDInfo HMDInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo) : m_Stage(0)
|
CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo) : m_Stage(0), m_OrientationCached(false)
|
||||||
{
|
{
|
||||||
++s_DeviceCounter;
|
++s_DeviceCounter;
|
||||||
m_DevicePtr = new CStereoOVRDevicePtr();
|
m_DevicePtr = new CStereoOVRDevicePtr();
|
||||||
|
@ -270,6 +270,7 @@ bool CStereoOVR::nextPass()
|
||||||
case 6:
|
case 6:
|
||||||
m_Stage = 0;
|
m_Stage = 0;
|
||||||
// present
|
// present
|
||||||
|
m_OrientationCached = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,6 +281,12 @@ const NL3D::CViewport &CStereoOVR::getCurrentViewport() const
|
||||||
else return m_RightViewport;
|
else return m_RightViewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NL3D::CFrustum &CStereoOVR::getCurrentFrustum() const
|
||||||
|
{
|
||||||
|
if (m_Stage % 2) return m_LeftFrustum;
|
||||||
|
else return m_RightFrustum;
|
||||||
|
}
|
||||||
|
|
||||||
void CStereoOVR::getCurrentFrustum(NL3D::UCamera *camera) const
|
void CStereoOVR::getCurrentFrustum(NL3D::UCamera *camera) const
|
||||||
{
|
{
|
||||||
if (m_Stage % 2) camera->setFrustum(m_LeftFrustum);
|
if (m_Stage % 2) camera->setFrustum(m_LeftFrustum);
|
||||||
|
@ -360,6 +367,9 @@ void CStereoOVR::endInterface2D()
|
||||||
|
|
||||||
NLMISC::CQuat CStereoOVR::getOrientation() const
|
NLMISC::CQuat CStereoOVR::getOrientation() const
|
||||||
{
|
{
|
||||||
|
if (m_OrientationCached)
|
||||||
|
return m_OrientationCache;
|
||||||
|
|
||||||
OVR::Quatf quatovr = m_DevicePtr->SensorFusion.GetPredictedOrientation();
|
OVR::Quatf quatovr = m_DevicePtr->SensorFusion.GetPredictedOrientation();
|
||||||
NLMISC::CMatrix coordsys;
|
NLMISC::CMatrix coordsys;
|
||||||
float csys[] = {
|
float csys[] = {
|
||||||
|
@ -374,7 +384,24 @@ NLMISC::CQuat CStereoOVR::getOrientation() const
|
||||||
NLMISC::CMatrix matr;
|
NLMISC::CMatrix matr;
|
||||||
matr.rotateX(NLMISC::Pi * 0.5f); // fix this properly... :) (note: removing this allows you to use rift while lying down)
|
matr.rotateX(NLMISC::Pi * 0.5f); // fix this properly... :) (note: removing this allows you to use rift while lying down)
|
||||||
NLMISC::CMatrix matnel = matr * matovr * coordsys;
|
NLMISC::CMatrix matnel = matr * matovr * coordsys;
|
||||||
return matnel.getRot();
|
NLMISC::CQuat finalquat = matnel.getRot();
|
||||||
|
m_OrientationCache = finalquat;
|
||||||
|
m_OrientationCached = true;
|
||||||
|
return finalquat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get GUI shift (todo: move to CStereoHMD)
|
||||||
|
void CStereoOVR::getInterface2DShift(float &x, float &y, float distance)
|
||||||
|
{
|
||||||
|
NLMISC::CVector vector = CVector(0.f, -distance, 0.f);
|
||||||
|
NLMISC::CQuat rot = getOrientation();
|
||||||
|
rot.invert();
|
||||||
|
NLMISC::CMatrix mat;
|
||||||
|
mat.rotate(rot);
|
||||||
|
mat.translate(vector);
|
||||||
|
CVector proj = getCurrentFrustum().project(mat.getPos());
|
||||||
|
x = proj.x - 0.5f;
|
||||||
|
y = proj.y - 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CStereoOVR::listDevices(std::vector<CStereoDeviceInfo> &devicesOut)
|
void CStereoOVR::listDevices(std::vector<CStereoDeviceInfo> &devicesOut)
|
||||||
|
|
|
@ -42,7 +42,6 @@ namespace SBCLIENT {
|
||||||
extern NL3D::UCamera Camera;
|
extern NL3D::UCamera Camera;
|
||||||
extern NL3D::UCamera SkyCamera;
|
extern NL3D::UCamera SkyCamera;
|
||||||
extern NL3D::UVisualCollisionEntity *CamCollisionEntity;
|
extern NL3D::UVisualCollisionEntity *CamCollisionEntity;
|
||||||
extern NL3D::CStereoOVR *StereoHMD;
|
|
||||||
extern NL3D::UScene *SkyScene;
|
extern NL3D::UScene *SkyScene;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <nel/3d/u_3d_mouse_listener.h>
|
#include <nel/3d/u_3d_mouse_listener.h>
|
||||||
#include <nel/3d/u_material.h>
|
#include <nel/3d/u_material.h>
|
||||||
#include <nel/3d/u_landscape.h>
|
#include <nel/3d/u_landscape.h>
|
||||||
|
#include <nel/3d/stereo_ovr.h>
|
||||||
|
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "snowballs_client.h"
|
#include "snowballs_client.h"
|
||||||
|
@ -374,6 +375,9 @@ void updateCommands()
|
||||||
uint32 _width, _height;
|
uint32 _width, _height;
|
||||||
Driver->getWindowSize(_width, _height);
|
Driver->getWindowSize(_width, _height);
|
||||||
float width = (float)_width, height = (float)_height;
|
float width = (float)_width, height = (float)_height;
|
||||||
|
NL3D::CViewport vp = Driver->getViewport();
|
||||||
|
width *= vp.getWidth();
|
||||||
|
height *= vp.getHeight();
|
||||||
float CommandsLineHeight = CommandsFontSize / height;
|
float CommandsLineHeight = CommandsFontSize / height;
|
||||||
float CommandsBoxX = ((float)(sint32)(SBCLIENT::CommandsBoxX * width)) / width;
|
float CommandsBoxX = ((float)(sint32)(SBCLIENT::CommandsBoxX * width)) / width;
|
||||||
float CommandsBoxWidth = ((float)(sint32)(SBCLIENT::CommandsBoxWidth * width)) / width;
|
float CommandsBoxWidth = ((float)(sint32)(SBCLIENT::CommandsBoxWidth * width)) / width;
|
||||||
|
@ -381,6 +385,17 @@ void updateCommands()
|
||||||
float CommandsBoxHeight = ((float)(sint32)((CommandsNbLines + 1) * CommandsLineHeight * width)) / width;
|
float CommandsBoxHeight = ((float)(sint32)((CommandsNbLines + 1) * CommandsLineHeight * width)) / width;
|
||||||
float CommandsBoxBorderX = ((float)(sint32)(SBCLIENT::CommandsBoxBorder * width)) / width;
|
float CommandsBoxBorderX = ((float)(sint32)(SBCLIENT::CommandsBoxBorder * width)) / width;
|
||||||
float CommandsBoxBorderY = ((float)(sint32)(SBCLIENT::CommandsBoxBorder * height)) / height;
|
float CommandsBoxBorderY = ((float)(sint32)(SBCLIENT::CommandsBoxBorder * height)) / height;
|
||||||
|
if (StereoHMD)
|
||||||
|
{
|
||||||
|
float xshift, yshift;
|
||||||
|
StereoHMD->getInterface2DShift(xshift, yshift, 1.0f);
|
||||||
|
// snap to pixels
|
||||||
|
xshift = ((float)(sint32)(xshift * width)) / width;
|
||||||
|
yshift = ((float)(sint32)(yshift * height)) / height;
|
||||||
|
// adjust
|
||||||
|
CommandsBoxX += xshift;
|
||||||
|
CommandsBoxY += yshift;
|
||||||
|
}
|
||||||
|
|
||||||
// Display the background
|
// Display the background
|
||||||
Driver->setMatrixMode2D11 ();
|
Driver->setMatrixMode2D11 ();
|
||||||
|
|
|
@ -42,6 +42,7 @@ namespace NL3D {
|
||||||
class UScene;
|
class UScene;
|
||||||
class UTextContext;
|
class UTextContext;
|
||||||
class ULandscape;
|
class ULandscape;
|
||||||
|
class CStereoOVR;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace SBCLIENT {
|
namespace SBCLIENT {
|
||||||
|
@ -58,6 +59,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NL3D::UDriver *Driver;
|
extern NL3D::UDriver *Driver;
|
||||||
|
extern NL3D::CStereoOVR *StereoHMD;
|
||||||
extern NL3D::UScene *Scene;
|
extern NL3D::UScene *Scene;
|
||||||
extern NL3D::UTextContext *TextContext;
|
extern NL3D::UTextContext *TextContext;
|
||||||
extern NLMISC::CConfigFile *ConfigFile;
|
extern NLMISC::CConfigFile *ConfigFile;
|
||||||
|
|
Loading…
Reference in a new issue