Add minimal head model and world scale, ref #43

This commit is contained in:
kaetemi 2013-07-03 05:21:32 +02:00
parent 783c15b072
commit d700d01c6a
7 changed files with 52 additions and 13 deletions

View file

@ -53,13 +53,17 @@ public:
/// Get the HMD orientation /// Get the HMD orientation
virtual NLMISC::CQuat getOrientation() const = 0; 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) /// Get GUI center (1 = width, 1 = height, 0 = center)
virtual void getInterface2DShift(uint cid, float &x, float &y, float distance) const = 0; 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 */ }; /* class IStereoHMD */
} /* namespace NL3D */ } /* namespace NL3D */

View file

@ -117,9 +117,18 @@ 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) /// Get GUI center (1 = width, 1 = height, 0 = center)
virtual void getInterface2DShift(uint cid, float &x, float &y, float distance) const; 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 void listDevices(std::vector<CStereoDeviceInfo> &devicesOut);
static bool isLibraryInUse(); static bool isLibraryInUse();
@ -150,6 +159,8 @@ private:
NLMISC::CQuadUV m_BarrelQuadLeft; NLMISC::CQuadUV m_BarrelQuadLeft;
NLMISC::CQuadUV m_BarrelQuadRight; NLMISC::CQuadUV m_BarrelQuadRight;
CPixelProgram *m_PixelProgram; CPixelProgram *m_PixelProgram;
NLMISC::CVector m_EyePosition;
float m_Scale;
}; /* class CStereoOVR */ }; /* class CStereoOVR */

View file

@ -165,7 +165,7 @@ public:
OVR::HMDInfo HMDInfo; 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; ++s_DeviceCounter;
m_DevicePtr = new CStereoOVRDevicePtr(); 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 void CStereoOVR::getCurrentMatrix(uint cid, NL3D::UCamera *camera) const
{ {
CMatrix translate; CMatrix translate;
if (m_Stage % 2) 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 * 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->setTransformMode(NL3D::UTransformable::DirectMatrix);
camera->setMatrix(m_CameraMatrix[cid] * translate); camera->setMatrix(m_CameraMatrix[cid] * translate);
} }
@ -594,6 +594,8 @@ void CStereoOVR::getInterface2DShift(uint cid, float &x, float &y, float distanc
{ {
#if 0 #if 0
// todo: take into account m_EyePosition
NLMISC::CVector vector = CVector(0.f, -distance, 0.f); NLMISC::CVector vector = CVector(0.f, -distance, 0.f);
NLMISC::CQuat rot = getOrientation(); NLMISC::CQuat rot = getOrientation();
rot.invert(); rot.invert();
@ -616,11 +618,12 @@ void CStereoOVR::getInterface2DShift(uint cid, float &x, float &y, float distanc
#elif 1 #elif 1
// Alternative method // Alternative method
// todo: take into account m_EyePosition
NLMISC::CVector vec = CVector(0.f, -distance, 0.f); NLMISC::CVector vec = CVector(0.f, -distance, 0.f);
NLMISC::CVector ipd; NLMISC::CVector ipd;
if (m_Stage % 2) 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 * 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(); NLMISC::CQuat rot = getOrientation();
@ -640,6 +643,22 @@ void CStereoOVR::getInterface2DShift(uint cid, float &x, float &y, float distanc
#endif #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) void CStereoOVR::listDevices(std::vector<CStereoDeviceInfo> &devicesOut)
{ {
s_StereoOVRSystem.Init(); s_StereoOVRSystem.Init();

View file

@ -119,6 +119,7 @@ void initCamera()
{ {
nlinfo("Stereo display device is a HMD"); nlinfo("Stereo display device is a HMD");
StereoHMD = static_cast<IStereoHMD *>(StereoDisplay); 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 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 camMatrix = Camera.getMatrix();
NLMISC::CMatrix hmdMatrix; NLMISC::CMatrix hmdMatrix;
hmdMatrix.setRot(hmdOrient); 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 // Set the new position of the snow emitter
CMatrix mat = CMatrix::Identity; CMatrix mat = CMatrix::Identity;

View file

@ -388,7 +388,7 @@ void updateCommands()
if (StereoHMD) if (StereoHMD)
{ {
float xshift, yshift; float xshift, yshift;
StereoHMD->getInterface2DShift(0, xshift, yshift, 1.f); StereoHMD->getInterface2DShift(0, xshift, yshift, 4.f);
// snap to pixels // snap to pixels
xshift = ((float)(sint32)(xshift * width)) / width; xshift = ((float)(sint32)(xshift * width)) / width;
yshift = ((float)(sint32)(yshift * height)) / height; yshift = ((float)(sint32)(yshift * height)) / height;

View file

@ -98,7 +98,7 @@ void updateCompass ()
if (StereoHMD) if (StereoHMD)
{ {
float xshift, yshift; float xshift, yshift;
StereoHMD->getInterface2DShift(0, xshift, yshift, 1.f); StereoHMD->getInterface2DShift(0, xshift, yshift, 4.f);
x += xshift; x += xshift;
y += yshift; y += yshift;
} }

View file

@ -933,6 +933,8 @@ void renderInformation()
TextContext->setColor(CRGBA(255, 255, 255, 255)); TextContext->setColor(CRGBA(255, 255, 255, 255));
TextContext->setFontSize(14); TextContext->setFontSize(14);
TextContext->printfAt(0.01f, 0.99f, "%.2f(%.2f)fps %.3fs", FramesPerSecondSmooth, FramesPerSecond, (float)LocalTimeDelta); 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 // one more frame
FpsGraph.addValue(1.0f); FpsGraph.addValue(1.0f);