Add minimal head model and world scale, ref #43
--HG-- branch : multipass-stereo
This commit is contained in:
parent
0dd8764e45
commit
1fe2b62eb1
7 changed files with 52 additions and 13 deletions
|
@ -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 */
|
||||
|
|
|
@ -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<CStereoDeviceInfo> &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 */
|
||||
|
||||
|
|
|
@ -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<CStereoDeviceInfo> &devicesOut)
|
||||
{
|
||||
s_StereoOVRSystem.Init();
|
||||
|
|
|
@ -119,6 +119,7 @@ void initCamera()
|
|||
{
|
||||
nlinfo("Stereo display device is a HMD");
|
||||
StereoHMD = static_cast<IStereoHMD *>(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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue