Read sensor data and set camera in snowballs, ref #43
This commit is contained in:
parent
dc813a060e
commit
a7cf55c58e
4 changed files with 69 additions and 9 deletions
|
@ -80,11 +80,15 @@ public:
|
|||
CStereoOVR(const CStereoDeviceInfo &deviceInfo);
|
||||
virtual ~CStereoOVR();
|
||||
|
||||
virtual NLMISC::CQuat getOrientation();
|
||||
|
||||
static void listDevices(std::vector<CStereoDeviceInfo> &devicesOut);
|
||||
static CStereoOVR *createDevice(const CStereoDeviceInfo &deviceInfo);
|
||||
static bool isLibraryInUse();
|
||||
static void releaseLibrary();
|
||||
|
||||
bool isDeviceCreated();
|
||||
|
||||
private:
|
||||
CStereoOVRDevicePtr *m_DevicePtr;
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ CStereoOVRSystem s_StereoOVRSystem;
|
|||
class CStereoOVRDeviceHandle : public NLMISC::CRefCount
|
||||
{
|
||||
public:
|
||||
OVR::DeviceHandle DeviceHandle;
|
||||
OVR::DeviceEnumerator<OVR::HMDDevice> DeviceHandle;
|
||||
};
|
||||
|
||||
sint s_DeviceCounter = 0;
|
||||
|
@ -140,6 +140,8 @@ class CStereoOVRDevicePtr
|
|||
{
|
||||
public:
|
||||
OVR::Ptr<OVR::HMDDevice> HMDDevice;
|
||||
OVR::Ptr<OVR::SensorDevice> SensorDevice;
|
||||
OVR::SensorFusion SensorFusion;
|
||||
};
|
||||
|
||||
CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo)
|
||||
|
@ -147,20 +149,53 @@ CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo)
|
|||
++s_DeviceCounter;
|
||||
m_DevicePtr = new CStereoOVRDevicePtr();
|
||||
|
||||
// CStereoOVRDeviceHandle *handle = static_cast<CStereoOVRDeviceHandle *>(deviceInfo.Factory.getPtr());
|
||||
// OVR::DeviceHandle dh = handle->DeviceHandle;
|
||||
// dh.CreateDevice();
|
||||
CStereoOVRDeviceHandle *handle = static_cast<CStereoOVRDeviceHandle *>(deviceInfo.Factory.getPtr());
|
||||
OVR::DeviceEnumerator<OVR::HMDDevice> dh = handle->DeviceHandle;
|
||||
m_DevicePtr->HMDDevice = dh.CreateDevice();
|
||||
|
||||
if (m_DevicePtr->HMDDevice)
|
||||
{
|
||||
m_DevicePtr->SensorDevice = m_DevicePtr->HMDDevice->GetSensor();
|
||||
m_DevicePtr->SensorFusion.AttachToSensor(m_DevicePtr->SensorDevice);
|
||||
m_DevicePtr->SensorFusion.SetGravityEnabled(true);
|
||||
m_DevicePtr->SensorFusion.SetPredictionEnabled(true);
|
||||
m_DevicePtr->SensorFusion.SetYawCorrectionEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
CStereoOVR::~CStereoOVR()
|
||||
{
|
||||
// ...
|
||||
if (m_DevicePtr->SensorDevice)
|
||||
m_DevicePtr->SensorDevice->Release();
|
||||
m_DevicePtr->SensorDevice.Clear();
|
||||
if (m_DevicePtr->HMDDevice)
|
||||
m_DevicePtr->HMDDevice->Release();
|
||||
m_DevicePtr->HMDDevice.Clear();
|
||||
|
||||
delete m_DevicePtr;
|
||||
m_DevicePtr = NULL;
|
||||
--s_DeviceCounter;
|
||||
}
|
||||
|
||||
NLMISC::CQuat CStereoOVR::getOrientation()
|
||||
{
|
||||
OVR::Quatf quatovr = m_DevicePtr->SensorFusion.GetPredictedOrientation();
|
||||
NLMISC::CMatrix coordsys;
|
||||
float csys[] = {
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, -1.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f,
|
||||
};
|
||||
coordsys.set(csys);
|
||||
NLMISC::CMatrix matovr;
|
||||
matovr.setRot(NLMISC::CQuat(quatovr.x, quatovr.y, quatovr.z, quatovr.w));
|
||||
NLMISC::CMatrix matr;
|
||||
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;
|
||||
return matnel.getRot();
|
||||
}
|
||||
|
||||
void CStereoOVR::listDevices(std::vector<CStereoDeviceInfo> &devicesOut)
|
||||
{
|
||||
s_StereoOVRSystem.Init();
|
||||
|
@ -190,7 +225,7 @@ void CStereoOVR::listDevices(std::vector<CStereoDeviceInfo> &devicesOut)
|
|||
|
||||
CStereoOVR *CStereoOVR::createDevice(const CStereoDeviceInfo &deviceInfo)
|
||||
{
|
||||
return NULL;
|
||||
return new CStereoOVR(deviceInfo);
|
||||
}
|
||||
|
||||
bool CStereoOVR::isLibraryInUse()
|
||||
|
@ -205,6 +240,11 @@ void CStereoOVR::releaseLibrary()
|
|||
s_StereoOVRSystem.Release();
|
||||
}
|
||||
|
||||
bool CStereoOVR::isDeviceCreated()
|
||||
{
|
||||
return m_DevicePtr->HMDDevice != NULL;
|
||||
}
|
||||
|
||||
} /* namespace NL3D */
|
||||
|
||||
/* end of file */
|
||||
|
|
|
@ -108,13 +108,19 @@ void initCamera()
|
|||
break;
|
||||
}
|
||||
}
|
||||
//s_StereoHMD->createDevice(
|
||||
if (deviceInfo)
|
||||
{
|
||||
nlinfo("Create HMD device!");
|
||||
s_StereoHMD = CStereoOVR::createDevice(*deviceInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Set up directly the camera
|
||||
Camera = Scene->getCam();
|
||||
Camera.setTransformMode (UTransformable::DirectMatrix);
|
||||
Camera.setPerspective ((float)Pi/2.f, 1.33f, 0.1f, 1000);
|
||||
Camera.setPerspective((float)Pi/2.f,
|
||||
ConfigFile->getVar("ScreenWidth").asFloat() / ConfigFile->getVar("ScreenHeight").asFloat(),
|
||||
0.1f, 1000.f);
|
||||
Camera.lookAt (CVector(ConfigFile->getVar("StartPoint").asFloat(0),
|
||||
ConfigFile->getVar("StartPoint").asFloat(1),
|
||||
ConfigFile->getVar("StartPoint").asFloat(2)),
|
||||
|
@ -153,11 +159,21 @@ void releaseCamera()
|
|||
Scene->deleteInstance(Snow);
|
||||
VisualCollisionManager->deleteEntity(CamCollisionEntity);
|
||||
|
||||
delete s_StereoHMD;
|
||||
s_StereoHMD = NULL;
|
||||
CStereoOVR::releaseLibrary();
|
||||
}
|
||||
|
||||
void updateCamera()
|
||||
{
|
||||
if (s_StereoHMD)
|
||||
{
|
||||
NLMISC::CQuat hmdOrient = s_StereoHMD->getOrientation();
|
||||
NLMISC::CMatrix camMatrix = Camera.getMatrix();
|
||||
NLMISC::CMatrix hmdMatrix;
|
||||
hmdMatrix.setRot(hmdOrient);
|
||||
Camera.setMatrix(camMatrix * hmdMatrix);
|
||||
}
|
||||
// Set the new position of the snow emitter
|
||||
CMatrix mat = CMatrix::Identity;
|
||||
mat.setPos (Camera.getMatrix().getPos()/*+CVector (0.0f, 0.0f, -10.0f)*/);
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
#define SBCLIENT_DEV_SOUND 0
|
||||
#define SBCLIENT_DEV_STEREO 0
|
||||
#define SBCLIENT_DEV_MEMLEAK 0
|
||||
#define SBCLIENT_DEV_PIXEL_PROGRAM 1
|
||||
#define SBCLIENT_DEV_PIXEL_PROGRAM 0
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue