bool OculusVRSensorDevice::process(U32 deviceType, bool generateRotAsAngAxis, bool generateRotAsEuler, bool generateRotationAsAxisEvents, F32 maxAxisRadius) { if(!mIsValid) return false; // Store the current data from the sensor and compare with previous data U32 diff; OculusVRSensorData* currentBuffer = (mPrevData == mDataBuffer[0]) ? mDataBuffer[1] : mDataBuffer[0]; if(!mIsSimulation) { currentBuffer->setData(mSensorFusion, maxAxisRadius); } else { currentBuffer->simulateData(maxAxisRadius); } diff = mPrevData->compare(currentBuffer); // Update the previous data pointer. We do this here in case someone calls our // console functions during one of the input events below. mPrevData = currentBuffer; // Rotation event if(diff & OculusVRSensorData::DIFF_ROT) { if(generateRotAsAngAxis) { INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_ROT, OVR_SENSORROT[mActionCodeIndex], SI_MOVE, currentBuffer->mRotQuat); } if(generateRotAsEuler) { // Convert angles to degrees VectorF angles; for(U32 i=0; i<3; ++i) { angles[i] = mRadToDeg(currentBuffer->mRotEuler[i]); } INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_POS, OVR_SENSORROTANG[mActionCodeIndex], SI_MOVE, angles); } } // Rotation as axis event if(generateRotationAsAxisEvents && diff & OculusVRSensorData::DIFF_ROTAXIS) { if(diff & OculusVRSensorData::DIFF_ROTAXISX) INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_AXIS, OVR_SENSORROTAXISX[mActionCodeIndex], SI_MOVE, currentBuffer->mRotAxis.x); if(diff & OculusVRSensorData::DIFF_ROTAXISY) INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_AXIS, OVR_SENSORROTAXISY[mActionCodeIndex], SI_MOVE, currentBuffer->mRotAxis.y); } return true; }
bool OculusVRSensorDevice::process(U32 deviceType, bool generateRotAsAngAxis, bool generateRotAsEuler, bool generateRotationAsAxisEvents, bool generatePositionEvents, F32 maxAxisRadius, bool generateRawSensor) { if(!mIsValid) return false; // Grab current state ovrTrackingState ts = ovrHmd_GetTrackingState(mDevice, ovr_GetTimeInSeconds()); mLastStatus = ts.StatusFlags; // Store the current data from the sensor and compare with previous data U32 diff; OculusVRSensorData* currentBuffer = (mPrevData == mDataBuffer[0]) ? mDataBuffer[1] : mDataBuffer[0]; currentBuffer->setData(ts, maxAxisRadius); diff = mPrevData->compare(currentBuffer, generateRawSensor); // Update the previous data pointer. We do this here in case someone calls our // console functions during one of the input events below. mPrevData = currentBuffer; // Rotation event if(diff & OculusVRSensorData::DIFF_ROT) { if(generateRotAsAngAxis) { INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_ROT, OVR_SENSORROT[mActionCodeIndex], SI_MOVE, currentBuffer->mRotQuat); } if(generateRotAsEuler) { // Convert angles to degrees VectorF angles; for(U32 i=0; i<3; ++i) { angles[i] = mRadToDeg(currentBuffer->mRotEuler[i]); } INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_POS, OVR_SENSORROTANG[mActionCodeIndex], SI_MOVE, angles); } } // Rotation as axis event if(generateRotationAsAxisEvents && diff & OculusVRSensorData::DIFF_ROTAXIS) { if(diff & OculusVRSensorData::DIFF_ROTAXISX) INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_AXIS, OVR_SENSORROTAXISX[mActionCodeIndex], SI_MOVE, currentBuffer->mRotAxis.x); if(diff & OculusVRSensorData::DIFF_ROTAXISY) INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_AXIS, OVR_SENSORROTAXISY[mActionCodeIndex], SI_MOVE, currentBuffer->mRotAxis.y); } if (generatePositionEvents && diff & OculusVRSensorData::DIFF_POS) { INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_AXIS, OVR_SENSORROTAXISX[mActionCodeIndex], SI_MOVE, currentBuffer->mPosition); } // Raw sensor event if(generateRawSensor && diff & OculusVRSensorData::DIFF_RAW) { if(diff & OculusVRSensorData::DIFF_ACCEL) INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_POS, OVR_SENSORACCELERATION[mActionCodeIndex], SI_MOVE, currentBuffer->mAcceleration); if(diff & OculusVRSensorData::DIFF_ANGVEL) { // Convert angles to degrees VectorF angles; for(U32 i=0; i<3; ++i) { angles[i] = mRadToDeg(currentBuffer->mAngVelocity[i]); } INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_POS, OVR_SENSORANGVEL[mActionCodeIndex], SI_MOVE, angles); } if(diff & OculusVRSensorData::DIFF_MAG) INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_POS, OVR_SENSORMAGNETOMETER[mActionCodeIndex], SI_MOVE, currentBuffer->mMagnetometer); } if (diff & OculusVRSensorData::DIFF_STATUS) { if (Con::isFunction("onOculusStatusUpdate")) { Con::executef("onOculusStatusUpdate", ts.StatusFlags); } } return true; }