Permalink
Browse files

Added WebVR support

  • Loading branch information...
phoboslab committed Feb 2, 2015
1 parent 3123020 commit 11913911afedf2c58d477f1d03ce57575f096f1f
View
@@ -37,8 +37,8 @@ <h1>
</div>
<div class="option">
<input type="checkbox" id="riftStereoMode"/>
<label for="riftStereoMode"><span></span>Oculus Rift Stereo Rendering</label>
– requires the <a href="https://github.com/phoboslab/OculusWeb/releases">OculusWeb Tracking Server</a>
<label for="riftStereoMode"><span></span>Oculus Rift DK2 Stereo Rendering</label>
– requires the <a href="http://blog.tojicode.com/2014/07/bringing-vr-to-chrome.html">Chrome WebVR Build</a>
</div>
</div>
</div>
@@ -124,9 +124,14 @@ EntityPlayer = tpf.Entity.extend({
// If we have a head tracker connected, add its rotation to our own;
// It's a bit of a hack to have this here, but we want to change the
// aim direction of the player with the head movement as well.
var trackerRotation = ig.system.tracker
? ig.system.tracker.getRotation()
: [0,0,0];
var trackerRotation = [0,0,0];
var trackerPosition = [0,0,0];
if( ig.system.renderer instanceof tpf.StereoRenderer ) {
var state = ig.system.renderer.getHMDState();
trackerRotation = state.rotation;
trackerPosition = state.position;
}
this.angle = this.internalAngle + trackerRotation[0];
@@ -198,7 +203,18 @@ EntityPlayer = tpf.Entity.extend({
cy = this.pos.y + this.size.y/2;
ig.system.camera.setRotation( trackerRotation[2], trackerRotation[1], this.angle );
ig.system.camera.setPosition( cx, cy, bobOffset );
// If we have a head tracker connected, we may to adjust the position a bit
if( ig.system.renderer instanceof tpf.StereoRenderer ) {
var tt = trackerPosition;
var a = this.internalAngle;
var ttx = tt[0] * Math.cos(-a) - tt[2] * Math.sin(-a);
var tty = tt[0] * Math.sin(-a) + tt[2] * Math.cos(-a);
ig.system.camera.setPosition( cx + ttx, cy + tty, tt[1] );
}
else {
ig.system.camera.setPosition( cx, cy, bobOffset );
}
},
receiveDamage: function( amount, from ) {
View
@@ -140,6 +140,7 @@ var MyGame = tpf.Game.extend({
ig.input.bind( ig.GAMEPAD.RIGHT_SHOULDER_BOTTOM, 'shoot' );
ig.input.bind( ig.GAMEPAD.LEFT_SHOULDER_BOTTOM, 'run' );
ig.input.bind( ig.GAMEPAD.FACE_1, 'shoot' );
ig.input.bind( ig.GAMEPAD.FACE_4, 'reset-tracking' );
ig.input.bind( ig.GAMEPAD.FACE_3, 'weaponNext' );
ig.input.bind( ig.GAMEPAD.FACE_2, 'weaponPrev' );
},
@@ -192,6 +193,11 @@ var MyGame = tpf.Game.extend({
update: function() {
// Reset tracking position for WebVR on button press
if( ig.input.pressed('reset-tracking') && ig.system.renderer instanceof tpf.StereoRenderer ) {
ig.system.renderer.reset();
}
if( this.menu ) {
// If we have a menu don't update anything else
this.menu.update();
@@ -287,11 +293,13 @@ var MyGame = tpf.Game.extend({
},
drawHud: function() {
ig.system.renderer.hudFreelook = false;
if( this.player ) {
ig.game.hud.draw(this.player, this.player.currentWeapon);
}
if( this.menu ) {
ig.system.renderer.hudFreelook = true;
this.menu.draw();
}
}
@@ -109,7 +109,11 @@ tpf.Game = ig.Game.extend({
ig.system.renderer.clear(!!this.clearColor, true);
this.drawWorld();
var fog = ig.system.renderer.fog;
ig.system.renderer.setFog(false);
this.drawHud();
if( fog ) { ig.system.renderer.setFog( fog.color, fog.near, fog.far ); }
},
drawWorld: function() {
@@ -23,6 +23,7 @@ tpf.Renderer = ig.Class.extend({
wireframe: false,
fog: null,
fullscreenFlags: {},
init: function( canvas ) {
this.canvas = canvas;
Oops, something went wrong.

0 comments on commit 1191391

Please sign in to comment.