How to Add Positional Tracking to the Oculus Tuscany Demo with the Razer Hydra
Before you begin you’ll need:
Visual Studio (Express) 10 and the Direct X SDK (June 2010)
1. Get the Oculus SDK: here.
Get the Sixense SDK: here.
2. Compile and test the samples. In this case we are using the OculusWorldDemo as our starting point.
3. Load the OculusSDK\Samples\LibOVR_Samples_Msvc2010.sln file and make sure OculusWorldDemo is the Startup Project.
4. Add the include directories and libraries for Razer. OculusWorldDemo > Properties: C/C++ > General > Additional Include Directories: (Add) C:\dev\SixenseSDK_062612\include (or wherever you installed SDK) Linker > General.>Additional Library Directories: (Add) C:\dev\SixenseSDK_062612\lib\win32\release_dll (or debug_dll if you are in debug mode) Linker > Input > Additonal Dependencies: (Add) sixense.lib sixense_utils.lib
5. Add header files to top of OculusWorldDemo.cpp
[csharp]
#include
#include <sixense_math.hpp>
#include <sixense_utils/button_states.hpp>
#include <sixense_utils/event_triggers.hpp>
#include <sixense_utils/controller_manager/controller_manager.hpp>
[/csharp]
6. Add some protected variables to the OculusWorldDemoApp class:
[csharp]
sixenseAllControllerData acd;
float hand_lf_x, hand_lf_y, hand_lf_z,hand_rt_x, hand_rt_y, hand_rt_z;
float hand_rt_offset_x,hand_rt_offset_y, hand_rt_offset_z;
float hand_lf_offset_x,hand_lf_offset_y, hand_lf_offset_z;
[/csharp]
7. Find ..
[csharp]OculusWorldDemoApp::OnStartup[/csharp]
..and add the Hydra setup to the end:
[csharp]
// Init sixense
sixenseInit();
// Init the controller manager. This makes sure the controllers are present,
//assigned to left and right hands, and that
// the hemisphere calibration is complete.
sixenseUtils::getTheControllerManager()>
setGameType(
sixenseUtils::ControllerManager::ONE_PLAYER_TWO_CONTROLLER );
[/csharp]
8. Find ..
[csharp]void OculusWorldDemoApp::OnIdle()[/csharp]
..and add this to the end of the ,csharp]if(pSensor)[/csharp] block:
[csharp]
float scale = .0015f;
//read the left controller and save the position values
hand_lf_x = scale * acd.controllers[1].pos[0] ;
hand_lf_y = scale * acd.controllers[1].pos[1] ;
hand_lf_z = scale * acd.controllers[1].pos[2] ;
hand_lf_offset_y += scale *acd.controllers[1].joystick_y ;
hand_lf_offset_x += acd.controllers[0].joystick_x * acd.controllers[0].joystick_x * (acd.controllers[0].joystick_x > 0 .1 : .1) ;
hand_lf_offset_z += acd.controllers[0].joystick_y * acd.controllers[0].joystick_y * (acd.controllers[0].joystick_y > 0 ? . 1 : .1);
[/csharp]
9. Farther down in:
[csharp]OculusWorldDemoApp::OnIdle()[/csharp]
..right before the command:
[csharp]View = Matrix4f::LookAtRH(shiftedEyePos, shiftedEyePos + forward, up);[/csharp]
..insert the hydra’s offset values to the eye position:
[csharp]
//calculate the player’s body rotation
Matrix4f yawRotate = Matrix4f::RotationY(Player.BodyYaw);
//get the hydra’s offset from the last reset position
Vector3f eye_hydra ( hand_lf_offset_x – hand_lf_x , hand_lf_y – hand_lf_offset_y, hand_lf_offset_z – hand_lf_z );
// adjust for body rotation so looking forward is always forward
Vector3f eye_orientationVector = yawRotate.Transform(eye_hydra);
//add new eye position to the base eye postion
shiftedEyePos += eye_orientationVector;
[/csharp]
You can download the compiled binary and the source below:
Download HydraHeadTracker.zip Here
Disclaimer: Files are downloaded at the users own risk, RoadToVR accept no liability to any damage done as a result of use or misuse of the file(s) provided.
NOTES for the download: The right hydra stick moves the player, holding down the trigger toggles between rotate mode and strafe mode.
Pressing the left bumper resets the head tracker so if you need to move more forward just lean back and repress the bumper.
A huge “thank you!” to Tony for his hard work and allowing us to share his work. You can discuss this article further over on our Developer Forums. You can catch Tony over at his YouTube channel here.