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
5 changes: 5 additions & 0 deletions License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2014.09.14 13:35
https://github.com/jdarpinian/npvr

License
BSD, except the np_* code.
Binary file removed bin/npvr.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/install.bat → bin/win32/install.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
regsvr32 npvr.dll
regsvr32 npvr.dll
28 changes: 14 additions & 14 deletions bin/manifest.json → bin/win32/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "npvr",
"version": "1.0.0.0",
"manifest_version": 2,
"description": "NPAPI plugin to expose fun VR devices.",
"offline_enabled": true,
"plugins": [
{
"path": "npvr.dll",
"public": true
}
]
}
{
"name": "npvr",
"version": "1.0.0.0",
"manifest_version": 2,
"description": "NPAPI plugin to expose fun VR devices.",
"offline_enabled": true,

"plugins": [
{
"path": "npvr.dll",
"public": true
}
]
}
Binary file added bin/win32/npvr.dll
Binary file not shown.
File renamed without changes.
2 changes: 1 addition & 1 deletion bin/uninstall.bat → bin/win32/uninstall.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
regsvr32 /u npvr.dll
regsvr32 /u npvr.dll
14 changes: 14 additions & 0 deletions bin/x64/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "npvr",
"version": "1.0.0.0",
"manifest_version": 2,
"description": "NPAPI plugin to expose fun VR devices.",
"offline_enabled": true,

"plugins": [
{
"path": "npvr_64.dll",
"public": true
}
]
}
Binary file added bin/x64/npvr_64.dll
Binary file not shown.
Binary file added bin/x64/sixense_utils_x64.dll
Binary file not shown.
Binary file added bin/x64/sixense_x64.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(vr.configuration(), 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
16 changes: 12 additions & 4 deletions lib/vr.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ function execCommand(commandId, opt_commandData) {


vr.hello = function() {
return execCommand(1);
return execCommand(1);
};

vr.configuration = function () {
return _vr_native_.oculState();
}

/**
* Bitmask values for the sixense controller buttons field.
Expand Down Expand Up @@ -195,7 +198,8 @@ var VRState = function() {
};
this.oculus = {
present: false,
rotation: new Float32Array(4)
rotation: new Float32Array(4),
position: new Float32Array(3)
}
};

Expand Down Expand Up @@ -239,7 +243,7 @@ vr.poll = function(state) {
case 'r':
// Oculus data.
parseOculusChunk(state, deviceChunk);
break;
break;
}
}

Expand Down Expand Up @@ -283,12 +287,16 @@ 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[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
67 changes: 35 additions & 32 deletions src/npvr/ovr_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,46 @@ 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;
}

ovrHmd &OVRManager::GetConfiguration() const {

ovrHmd test = hmd_device_;
return test;
}

11 changes: 5 additions & 6 deletions src/npvr/ovr_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@

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;
ovrHmd &OVRManager::GetConfiguration() const;
private:
OVRManager();
OVR::DeviceManager *device_manager_;
OVR::HMDDevice *hmd_device_;
OVR::SensorFusion *sensor_fusion_;
ovrHmd hmd_device_;
};

} // namespace npvr
Expand Down
Loading