Forum Discussion
EisernSchild
13 years agoExplorer
Skyrim Rift Headtracking Source Code
Here is the (short) Source Code for my Skyrim Rift Headtracking Mod i posted.
Maybe someone is interested or has better Ideas he would share. The mod simply takes Rift Input pitch and yaw to parse it to the game console. I can now play Skyrim using my XBox Controller and Headtracking. No Head roll so far.
The Mod uses Skyrim Script Dragon, can be found here:
http://alexander.sannybuilder.com/skyrim/scriptdragon/
Maybe someone is interested or has better Ideas he would share. The mod simply takes Rift Input pitch and yaw to parse it to the game console. I can now play Skyrim using my XBox Controller and Headtracking. No Head roll so far.
The Mod uses Skyrim Script Dragon, can be found here:
http://alexander.sannybuilder.com/skyrim/scriptdragon/
/*
OCULUS RIFT HEAD TRACKING SCRIPT PLUGIN
by Eisern Schild
*/
// Skyrim Script
#include "common\skyscript.h"
#include "common\obscript.h"
#include "common\types.h"
#include "common\enums.h"
#include "common\plugin.h"
// Math
#include <math.h>
// Oculus Rift
#include "OVR.h"
#define CONFIG_FILE "RiftHeadTracking.ini"
#define SCR_NAME "Oculus Rift Head Tracking Mod"
using namespace OVR;
void main()
{
// Oculus Rift variables
Ptr<DeviceManager> pManager;
Ptr<HMDDevice> pHMD;
Ptr<SensorDevice> pSensor;
SensorFusion FusionResult;
HMDInfo Info;
bool InfoLoaded;
// Init the Rift
System::Init();
pManager = *DeviceManager::Create();
pHMD = *pManager->EnumerateDevices<HMDDevice>().CreateDevice();
if (pHMD)
{
InfoLoaded = pHMD->GetDeviceInfo(&Info);
pSensor = *pHMD->GetSensor();
}
else
{
pSensor = *pManager->EnumerateDevices<SensorDevice>().CreateDevice();
}
if (pSensor)
{
FusionResult.AttachToSensor(pSensor);
PrintNote("Oculus Rift Head Tracking started.");
}
else
{
PrintNote("No Oculus Rift Head Tracking Sensor found !!!");
return;
}
// execute some rift specific console commands,
// first change field-of-view by .ini file
int fov = IniReadInt(CONFIG_FILE, "main", "fov", 0);
char ini[64]; ZeroMemory(&ini[0], 64);
sprintf_s(ini, "fov %d", fov);
ExecuteConsoleCommand(ini, 0);
float rotationY = 0.0f;
float oldAngleZ = ObjectReference::GetAngleZ((TESObjectREFR *)Game::GetPlayer());
while (TRUE)
{
// get the player actor
CActor *player = Game::GetPlayer();
// get the Rift orientation
Quatf quaternion = FusionResult.GetOrientation();
float yaw, pitch, roll;
quaternion.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&yaw, &pitch, &roll);
// get the current rotation of the player actor
float angleZ = ObjectReference::GetAngleZ((TESObjectREFR *)player);
// correct controller based rotation
rotationY+=angleZ-oldAngleZ;
if (rotationY > 180.0f) rotationY-=360.0f;
if (rotationY < -180.0f) rotationY+=360.0f;
// parse to console
char command[64];
ZeroMemory(&command[0], 64);
sprintf_s(command, "player.SetAngle X %f", -RadToDegree(pitch));
ExecuteConsoleCommand(command, 0);
/*sprintf_s(command, "player.SetAngle Y %f", -RadToDegree(roll));
ExecuteConsoleCommand(command, 0);*/
sprintf_s(command, "player.SetAngle Z %f", -RadToDegree(yaw)+rotationY);
ExecuteConsoleCommand(command, 0);
oldAngleZ = -RadToDegree(yaw)+rotationY;
Wait(20); // In order to switch between script threads Wait() must be called anyway
}
pSensor.Clear();
pHMD.Clear();
pManager.Clear();
System::Destroy();
}
2 Replies
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 3 years agoAnonymous
- 2 years ago
- 13 years ago