Permalink
Browse files

little play with device orientation

  • Loading branch information...
1 parent 14fc5d9 commit c6d955595252036cea104108105747373e1724c1 @jeromeetienne committed Mar 2, 2013
@@ -3,19 +3,21 @@
<body><script>
require(['tquery.deviceorientation'], function(){
var world = tQuery.createWorld().boilerplate().start();
- var object = tQuery.createTorus().addTo(world);
+ var object = tQuery.createTorusKnot().addTo(world);
tQuery.createAxis().addTo(object);
world.removeCameraControls();
world.loop().hook(function(){
var orientation = tQuery.deviceOrientation();
+// TODO put that directly on the THREEx
+// with useragent sniffing for mac detection
// for macbook
//object.rotation( -orientation.angleY(), orientation.angleX(), orientation.angleZ() );
- object.rotation( -orientation.angleY(), 0, orientation.angleZ() );
+ //object.rotation( -orientation.angleY(), 0, orientation.angleZ() );
// for ipad
- // object.rotation( -orientation.angleZ(), orientation.angleY(), -orientation.angleX() );
+ object.rotation( -orientation.angleZ(), orientation.angleY(), -orientation.angleX() );
// no idea why it is different, nor what is the theorical value
})
@@ -6,7 +6,9 @@ THREEx.DeviceOrientationState = function()
// to store the current state
this._state = { x: 0, y: 0, z: 0 };
- this._$callback = function(event){ this._onDeviceOrientation(event); }.bind(this);
+ this._$callback = function(event){
+ this._onDeviceOrientation(event);
+ }.bind(this);
// bind events
// - spec http://dev.w3.org/geo/api/spec-source-orientation.html
@@ -22,6 +24,10 @@ THREEx.DeviceOrientationState.prototype.destroy = function()
window.removeEventListener('deviceorientation', this._$callback);
}
+//////////////////////////////////////////////////////////////////////////////////
+// //
+//////////////////////////////////////////////////////////////////////////////////
+
/**
* to process the keyboard dom event
*/
@@ -25,10 +25,12 @@ var THREEx = THREEx || {};
*/
THREEx.WindowResize = function(renderer, camera){
var callback = function(){
+ var renderW = window.innerWidth;
+ var renderH = window.innerHeight;
// notify the renderer of the size change
- renderer.setSize( window.innerWidth, window.innerHeight );
+ renderer.setSize( renderW, renderH );
// update the camera
- camera.aspect = window.innerWidth / window.innerHeight;
+ camera.aspect = renderW / renderH;
camera.updateProjectionMatrix();
}
// bind the resize event
@@ -41,7 +43,13 @@ THREEx.WindowResize = function(renderer, camera){
stop : function(){
window.removeEventListener('resize', callback);
},
- resize : callback,
+ /**
+ * to manually trigger a resize
+ * @type {[type]}
+ */
+ trigger : function(){
+ callback();
+ },
};
}

0 comments on commit c6d9555

Please sign in to comment.