Project client loading screens into 3D space for HMD

--HG--
branch : multipass-stereo
This commit is contained in:
kaetemi 2014-08-07 18:49:05 +02:00
parent 38a418503d
commit 38abf2193f
3 changed files with 290 additions and 164 deletions

View file

@ -168,6 +168,7 @@ public:
private:
ovrHmd m_DevicePtr;
bool m_DebugDevice;
int m_Stage;
int m_SubStage;

View file

@ -175,6 +175,7 @@ CStereoOVR::CStereoOVR(const CStereoOVRDeviceFactory *factory) : m_DevicePtr(NUL
return;
}
m_DebugDevice = factory->DebugDevice;
if (factory->DebugDevice) m_DevicePtr = ovrHmd_CreateDebug(factory->DebugDeviceType);
else m_DevicePtr = ovrHmd_Create(factory->DeviceIndex);
@ -448,6 +449,9 @@ bool CStereoOVR::attachToDisplay()
{
nldebug("OVR: Attach to display '%s'", m_DevicePtr->DisplayDeviceName);
if (m_DebugDevice)
return false;
if (!m_AttachedDisplay)
{
m_Driver->getCurrentScreenMode(m_OriginalMode);
@ -792,7 +796,7 @@ void CStereoOVR::setInterfaceMatrix(const NL3D::CMatrix &matrix)
void CStereoOVR::renderGUI()
{
m_Driver->setModelMatrix(m_InterfaceCameraMatrix);
/*
{
NLMISC::CLine line(NLMISC::CVector(0, 5, 2), NLMISC::CVector(0, 5, 3));
@ -808,6 +812,41 @@ void CStereoOVR::renderGUI()
m_Driver->deleteMaterial(mat);
}
{
NL3D::UMaterial mat = m_Driver->createMaterial();
mat.setZWrite(false);
mat.setZFunc(UMaterial::always); // Not nice!
mat.setDoubleSided(true);
mat.setBlend(false);
NLMISC::CLine line;
mat.setColor(NLMISC::CRGBA::Red);
line = NLMISC::CLine(NLMISC::CVector(0, 3, -3), NLMISC::CVector(0, 3, 3)); // YPos
m_Driver->drawLine(line, mat);
mat.setColor(NLMISC::CRGBA::Green);
line = NLMISC::CLine(NLMISC::CVector(3, 0, -3), NLMISC::CVector(3, 0, 3)); // XPos
m_Driver->drawLine(line, mat);
mat.setColor(NLMISC::CRGBA::Magenta);
line = NLMISC::CLine(NLMISC::CVector(0, -3, -3), NLMISC::CVector(0, -3, 3)); // YNeg
m_Driver->drawLine(line, mat);
mat.setColor(NLMISC::CRGBA::Cyan);
line = NLMISC::CLine(NLMISC::CVector(-3, 0, -3), NLMISC::CVector(-3, 0, 3)); // XNeg
m_Driver->drawLine(line, mat);
mat.setColor(NLMISC::CRGBA::Blue);
line = NLMISC::CLine(NLMISC::CVector(0, -3, 3), NLMISC::CVector(0, 3, 3)); // ZPos
m_Driver->drawLine(line, mat);
mat.setColor(NLMISC::CRGBA::Blue);
line = NLMISC::CLine(NLMISC::CVector(0, -3, -3), NLMISC::CVector(0, 3, -3)); // ZNeg
m_Driver->drawLine(line, mat);
m_Driver->deleteMaterial(mat);
}
*/
{
nlassert(m_GUITexture);
@ -910,6 +949,24 @@ void CStereoOVR::renderGUI()
// m_Driver->drawQuad(quadUV, umat);
m_Driver->deleteMaterial(umat);
/*{
// nldebug("Render GUI lines");
NL3D::UMaterial rmat = m_Driver->createMaterial();
rmat.setZWrite(false);
rmat.setZFunc(UMaterial::always); // Not nice!
rmat.setDoubleSided(true);
rmat.setColor(NLMISC::CRGBA::Red);
rmat.setBlend(false);
m_Driver->setPolygonMode(UDriver::Line);
driver->activeVertexBuffer(vb);
driver->activeIndexBuffer(ib);
driver->renderTriangles(*rmat.getObjectPtr(), 0, nbQuads * 2);
m_Driver->setPolygonMode(UDriver::Filled);
m_Driver->deleteMaterial(rmat);
}*/
}
}
@ -1131,6 +1188,7 @@ NLMISC::CQuat CStereoOVR::getOrientation() const
}
else
{
if (!m_DebugDevice)
nlwarning("OVR: No orientation returned");
// return old orientation
m_OrientationCached = true;

View file

@ -33,6 +33,7 @@
#include "client_cfg.h"
#include "bg_downloader_access.h"
#include "nel/misc/system_utils.h"
#include "nel/3d/stereo_hmd.h"
using namespace std;
using namespace NLMISC;
@ -173,17 +174,70 @@ void CProgress::internalProgress (float value)
if (Driver->AsyncListener.isKeyPushed (KeyUP))
selectTipsOfTheDay (TipsOfTheDayIndex+1);
// Create camera for stereo mode
bool stereoHMD = StereoHMD && !MainCam.empty() && (MainCam.getTransformMode() == UCamera::RotQuat);
CVector oldPos;
CQuat oldQuat;
if (stereoHMD)
{
MainCam.getPos(oldPos);
MainCam.getRotQuat(oldQuat);
StereoHMD->setInterfaceMatrix(CMatrix()); // identity
NLMISC::CQuat hmdOrient = StereoHMD->getOrientation();
NLMISC::CMatrix camMatrix;
camMatrix.identity();
NLMISC::CMatrix hmdMatrix;
hmdMatrix.setRot(hmdOrient);
NLMISC::CMatrix posMatrix; // minimal head modeling, will be changed in the future
posMatrix.translate(StereoHMD->getEyePosition());
NLMISC::CMatrix mat = ((camMatrix * hmdMatrix) * posMatrix);
MainCam.setPos(mat.getPos());
MainCam.setRotQuat(mat.getRot());
StereoDisplay->updateCamera(0, &MainCam);
}
uint i = 0;
while ((!stereoHMD && i == 0) || (stereoHMD && StereoDisplay->nextPass()))
{
++i;
if (stereoHMD)
{
// modify cameras for stereo display
const CViewport &vp = StereoDisplay->getCurrentViewport();
Driver->setViewport(vp);
StereoDisplay->getCurrentMatrix(0, &MainCam);
StereoDisplay->getCurrentFrustum(0, &MainCam);
// begin current pass
StereoDisplay->beginRenderTarget();
nldebug("Cam pos: %f, %f, %f", MainCam.getPos().x, MainCam.getPos().y, MainCam.getPos().z);
}
if (!stereoHMD || StereoDisplay->wantClear())
{
Driver->clearBuffers(CRGBA(0, 0, 0, 0));
}
if (stereoHMD && StereoDisplay->wantScene())
{
Driver->setMatrixMode3D(MainCam);
}
if (!stereoHMD || StereoDisplay->wantInterface2D())
{
nldebug("Draw progress 2D");
// Font factor
float fontFactor = 1;
if (Driver->getWindowHeight() > 0)
fontFactor = (float)Driver->getWindowHeight() / 600.f;
fontFactor *= _FontFactor;
// Set 2d view.
Driver->setMatrixMode2D11();
Driver->clearBuffers (CRGBA(0,0,0,0));
// Display the loading background.
drawLoadingBitmap (value);
drawLoadingBitmap(value);
// temporary values for conversions
float x, y, width, height;
@ -354,6 +408,19 @@ void CProgress::internalProgress (float value)
}
}
}
}
if (stereoHMD)
{
StereoDisplay->endRenderTarget();
}
} /* stereo loop */
if (stereoHMD)
{
MainCam.setPos(oldPos);
MainCam.setRotQuat(oldQuat);
}
// Clamp
clamp (value, 0.f, 1.f);