Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/npvr.dll
Binary file not shown.
57 changes: 57 additions & 0 deletions examples/OculusRawData.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<title>NPVR Raw Data</title>
<script src="../lib/vr.js"></script>
</head>
<body>
<canvas id="canvas" width="400" height="600"></canvas>

<script>
var requestAnimationFrame =
window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame;

var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');

vr.wait(function() {
console.log('npvr ready!');

console.log('hello: ' + vr.hello());

var state = vr.createState();
function tick() {
vr.poll(state);

ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = 'black';
ctx.font = '12px monospace';
var w = 8;
var i0 = w * 0, i1 = w * 1, i2 = w * 2, i3 = w * 3;
var h = 12;
var y = 0;

if (state.oculus.present) {
y += h; ctx.fillText('oculus rift detected', 0, y);
y += h; ctx.fillText("Rotations:", i1, y);
y += h; ctx.fillText("X:" + state.oculus.rotation[0], i1, y);
y += h; ctx.fillText("Y:" + state.oculus.rotation[1], i1, y);
y += h; ctx.fillText("Z:" + state.oculus.rotation[2], i1, y);
y += h; ctx.fillText("W:" + state.oculus.rotation[3], i1, y);
y += h; ctx.fillText("Positions:", i1, y);
y += h; ctx.fillText("X:" + state.oculus.position[0], i1, y);
y += h; ctx.fillText("Y:" + state.oculus.position[1], i1, y);
y += h; ctx.fillText("Z:" + state.oculus.position[2], i1, y);
} else {
y += h; ctx.fillText('oculus rift not detected', 0, y);
}

requestAnimationFrame.call(window, tick);
};
requestAnimationFrame.call(window, tick);
});
</script>
</body>
</html>
22 changes: 15 additions & 7 deletions examples/rift_demo.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -151,8 +151,8 @@
controls = new THREE.OculusRiftControls( camera );
scene.add( controls.getObject() );

// var cameraHelper = new THREE.CameraHelper(camera);
// scene.add(cameraHelper);
//var cameraHelper = new THREE.CameraHelper(camera);
//scene.add(cameraHelper);

ray = new THREE.Raycaster();
ray.ray.direction.set( 0, -1, 0 );
Expand Down Expand Up @@ -276,12 +276,20 @@
}

// Poll VR, if it's ready.
if (vr.isReady) {
vr.poll(vrstate);
}
if (vr.isReady) {
vr.poll(vrstate);

camera.position.x = vrstate.oculus.position[0] * 100;
camera.position.y = vrstate.oculus.position[1] * 100 +50;
camera.position.z = vrstate.oculus.position[2] * 100;

camera.rotation.w = vrstate.oculus.rotation[3] * Math.PI;
camera.rotation.y = vrstate.oculus.rotation[1] * Math.PI;
camera.rotation.z = vrstate.oculus.rotation[2] * Math.PI;
camera.rotation.x = vrstate.oculus.rotation[0] * Math.PI;
}
controls.update( Date.now() - time, vr.isReady ? vrstate : null );

//renderer.render( scene, camera );
effect.render( scene, camera );

time = Date.now();
Expand Down
7 changes: 6 additions & 1 deletion lib/vr.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,17 @@ vr.poll = function(state) {
};

function parseOculusChunk(state, data) {
if (data.length == 5) {
if (data.length == 8) {
state.oculus.present = true;
state.oculus.rotation[0] = parseFloat(data[1]);
state.oculus.rotation[1] = parseFloat(data[2]);
state.oculus.rotation[2] = parseFloat(data[3]);
state.oculus.rotation[3] = parseFloat(data[4]);

state.oculus.position = new Array();
state.oculus.position[0] = parseFloat(data[5]);
state.oculus.position[1] = parseFloat(data[6]);
state.oculus.position[2] = parseFloat(data[7]);
} else {
state.oculus.present = false;
}
Expand Down
60 changes: 28 additions & 32 deletions src/npvr/ovr_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,39 @@ OVRManager *OVRManager::Instance() {
}

OVRManager::OVRManager() {
OVR::System::Init();
sensor_fusion_ = new OVR::SensorFusion();
device_manager_ = OVR::DeviceManager::Create();
hmd_device_ = device_manager_->EnumerateDevices<OVR::HMDDevice>().CreateDevice();
if (hmd_device_) {
sensor_fusion_->AttachToSensor(hmd_device_->GetSensor());
}
device_manager_->SetMessageHandler(this);
}
ovr_Initialize();
ovrHmd hmd_devive = ovrHmd_Create(0);
hmd_device_ = hmd_devive;

void OVRManager::OnMessage(const OVR::Message &message) {
switch(message.Type) {
case OVR::MessageType::Message_DeviceRemoved:
// TODO: Verify that the removed device is the one we're using.
if (hmd_device_) {
hmd_device_->Release();
hmd_device_ = NULL;
}
break;
case OVR::MessageType::Message_DeviceAdded:
if (!hmd_device_) {
// TODO: This doesn't work for some reason.
hmd_device_ = device_manager_->EnumerateDevices<OVR::HMDDevice>().CreateDevice();
if (hmd_device_) {
sensor_fusion_->AttachToSensor(hmd_device_->GetSensor());
}
}
break;
default:
break;
}
ovrHmd_ConfigureTracking(hmd_devive, ovrTrackingCap_Orientation |
ovrTrackingCap_MagYawCorrection |
ovrTrackingCap_Position, 0);
}

bool OVRManager::DevicePresent() const {
return hmd_device_;
}

OVR::Quatf &OVRManager::GetOrientation() const {
return sensor_fusion_->GetOrientation();
OVR::Quatf* &OVRManager::GetOrientation() const {

static ovrPosef eyeRenderPose[2];

ovrEyeType eye = hmd_device_->EyeRenderOrder[0];
eyeRenderPose[0] = ovrHmd_GetEyePose(hmd_device_, eye);

OVR::Quatf* orientation = new OVR::Quatf(eyeRenderPose[0].Orientation.x, eyeRenderPose[0].Orientation.y, eyeRenderPose[0].Orientation.z, eyeRenderPose[0].Orientation.w);

return orientation;
}

OVR::Vector3f* &OVRManager::GetPosition() const {

static ovrPosef eyeRenderPose[2];

ovrEyeType eye = hmd_device_->EyeRenderOrder[0];
eyeRenderPose[0] = ovrHmd_GetEyePose(hmd_device_, eye);

OVR::Vector3f* position = new OVR::Vector3f(eyeRenderPose[0].Position.x, eyeRenderPose[0].Position.y, eyeRenderPose[0].Position.z);

return position;
}
10 changes: 4 additions & 6 deletions src/npvr/ovr_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@

namespace npvr {

class OVRManager: public OVR::MessageHandler {
class OVRManager {
public:
static OVRManager *Instance();
bool DevicePresent() const;
OVR::Quatf &GetOrientation() const;
virtual void OnMessage(const OVR::Message &message);
OVR::Quatf* &GetOrientation() const;
OVR::Vector3f* &GetPosition() const;
private:
OVRManager();
OVR::DeviceManager *device_manager_;
OVR::HMDDevice *hmd_device_;
OVR::SensorFusion *sensor_fusion_;
ovrHmd hmd_device_;
};

} // namespace npvr
Expand Down
10 changes: 7 additions & 3 deletions src/npvr/vr_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ void VRObject::PollOculus(std::ostringstream& s) {
OVRManager *manager = OVRManager::Instance();
if (manager->DevicePresent()) {
s << "r,";
OVR::Quatf o = manager->GetOrientation();
s << o.x << "," << o.y << "," << o.z << "," << o.w;
s << "|";
OVR::Quatf* o = manager->GetOrientation();
// Extended with the three position parameters! ==> Attention: Needs update from VR.js
OVR::Vector3f* pos = manager->GetPosition();
s << o->x << "," << o->y << "," << o->z << "," << o->w;
s << "," << pos->x << "," << pos->y << "," << pos->z;

s << "|";
}
}

Expand Down
1 change: 0 additions & 1 deletion third_party/gyp
Submodule gyp deleted from 12d97e