mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-22 14:56:13 +00:00
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);
|
CStereoOVR(const CStereoDeviceInfo &deviceInfo);
|
||||||
virtual ~CStereoOVR();
|
virtual ~CStereoOVR();
|
||||||
|
|
||||||
|
virtual NLMISC::CQuat getOrientation();
|
||||||
|
|
||||||
static void listDevices(std::vector<CStereoDeviceInfo> &devicesOut);
|
static void listDevices(std::vector<CStereoDeviceInfo> &devicesOut);
|
||||||
static CStereoOVR *createDevice(const CStereoDeviceInfo &deviceInfo);
|
static CStereoOVR *createDevice(const CStereoDeviceInfo &deviceInfo);
|
||||||
static bool isLibraryInUse();
|
static bool isLibraryInUse();
|
||||||
static void releaseLibrary();
|
static void releaseLibrary();
|
||||||
|
|
||||||
|
bool isDeviceCreated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CStereoOVRDevicePtr *m_DevicePtr;
|
CStereoOVRDevicePtr *m_DevicePtr;
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ CStereoOVRSystem s_StereoOVRSystem;
|
||||||
class CStereoOVRDeviceHandle : public NLMISC::CRefCount
|
class CStereoOVRDeviceHandle : public NLMISC::CRefCount
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OVR::DeviceHandle DeviceHandle;
|
OVR::DeviceEnumerator<OVR::HMDDevice> DeviceHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
sint s_DeviceCounter = 0;
|
sint s_DeviceCounter = 0;
|
||||||
|
@ -140,6 +140,8 @@ class CStereoOVRDevicePtr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OVR::Ptr<OVR::HMDDevice> HMDDevice;
|
OVR::Ptr<OVR::HMDDevice> HMDDevice;
|
||||||
|
OVR::Ptr<OVR::SensorDevice> SensorDevice;
|
||||||
|
OVR::SensorFusion SensorFusion;
|
||||||
};
|
};
|
||||||
|
|
||||||
CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo)
|
CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo)
|
||||||
|
@ -147,20 +149,53 @@ CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo)
|
||||||
++s_DeviceCounter;
|
++s_DeviceCounter;
|
||||||
m_DevicePtr = new CStereoOVRDevicePtr();
|
m_DevicePtr = new CStereoOVRDevicePtr();
|
||||||
|
|
||||||
// CStereoOVRDeviceHandle *handle = static_cast<CStereoOVRDeviceHandle *>(deviceInfo.Factory.getPtr());
|
CStereoOVRDeviceHandle *handle = static_cast<CStereoOVRDeviceHandle *>(deviceInfo.Factory.getPtr());
|
||||||
// OVR::DeviceHandle dh = handle->DeviceHandle;
|
OVR::DeviceEnumerator<OVR::HMDDevice> dh = handle->DeviceHandle;
|
||||||
// dh.CreateDevice();
|
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()
|
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;
|
delete m_DevicePtr;
|
||||||
m_DevicePtr = NULL;
|
m_DevicePtr = NULL;
|
||||||
--s_DeviceCounter;
|
--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)
|
void CStereoOVR::listDevices(std::vector<CStereoDeviceInfo> &devicesOut)
|
||||||
{
|
{
|
||||||
s_StereoOVRSystem.Init();
|
s_StereoOVRSystem.Init();
|
||||||
|
@ -190,7 +225,7 @@ void CStereoOVR::listDevices(std::vector<CStereoDeviceInfo> &devicesOut)
|
||||||
|
|
||||||
CStereoOVR *CStereoOVR::createDevice(const CStereoDeviceInfo &deviceInfo)
|
CStereoOVR *CStereoOVR::createDevice(const CStereoDeviceInfo &deviceInfo)
|
||||||
{
|
{
|
||||||
return NULL;
|
return new CStereoOVR(deviceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CStereoOVR::isLibraryInUse()
|
bool CStereoOVR::isLibraryInUse()
|
||||||
|
@ -205,6 +240,11 @@ void CStereoOVR::releaseLibrary()
|
||||||
s_StereoOVRSystem.Release();
|
s_StereoOVRSystem.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CStereoOVR::isDeviceCreated()
|
||||||
|
{
|
||||||
|
return m_DevicePtr->HMDDevice != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace NL3D */
|
} /* namespace NL3D */
|
||||||
|
|
||||||
/* end of file */
|
/* end of file */
|
||||||
|
|
|
@ -108,13 +108,19 @@ void initCamera()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//s_StereoHMD->createDevice(
|
if (deviceInfo)
|
||||||
|
{
|
||||||
|
nlinfo("Create HMD device!");
|
||||||
|
s_StereoHMD = CStereoOVR::createDevice(*deviceInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up directly the camera
|
// Set up directly the camera
|
||||||
Camera = Scene->getCam();
|
Camera = Scene->getCam();
|
||||||
Camera.setTransformMode (UTransformable::DirectMatrix);
|
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),
|
Camera.lookAt (CVector(ConfigFile->getVar("StartPoint").asFloat(0),
|
||||||
ConfigFile->getVar("StartPoint").asFloat(1),
|
ConfigFile->getVar("StartPoint").asFloat(1),
|
||||||
ConfigFile->getVar("StartPoint").asFloat(2)),
|
ConfigFile->getVar("StartPoint").asFloat(2)),
|
||||||
|
@ -153,11 +159,21 @@ void releaseCamera()
|
||||||
Scene->deleteInstance(Snow);
|
Scene->deleteInstance(Snow);
|
||||||
VisualCollisionManager->deleteEntity(CamCollisionEntity);
|
VisualCollisionManager->deleteEntity(CamCollisionEntity);
|
||||||
|
|
||||||
|
delete s_StereoHMD;
|
||||||
|
s_StereoHMD = NULL;
|
||||||
CStereoOVR::releaseLibrary();
|
CStereoOVR::releaseLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateCamera()
|
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
|
// Set the new position of the snow emitter
|
||||||
CMatrix mat = CMatrix::Identity;
|
CMatrix mat = CMatrix::Identity;
|
||||||
mat.setPos (Camera.getMatrix().getPos()/*+CVector (0.0f, 0.0f, -10.0f)*/);
|
mat.setPos (Camera.getMatrix().getPos()/*+CVector (0.0f, 0.0f, -10.0f)*/);
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
#define SBCLIENT_DEV_SOUND 0
|
#define SBCLIENT_DEV_SOUND 0
|
||||||
#define SBCLIENT_DEV_STEREO 0
|
#define SBCLIENT_DEV_STEREO 0
|
||||||
#define SBCLIENT_DEV_MEMLEAK 0
|
#define SBCLIENT_DEV_MEMLEAK 0
|
||||||
#define SBCLIENT_DEV_PIXEL_PROGRAM 1
|
#define SBCLIENT_DEV_PIXEL_PROGRAM 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue