Skip to content

Commit

Permalink
slight modification to camera code in Planet demo
Browse files Browse the repository at this point in the history
  • Loading branch information
erichlof committed Aug 18, 2018
1 parent 5ad42c1 commit 0669ff8
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion Planet_Rendering.html
Expand Up @@ -74,7 +74,61 @@
<script src="js/three.min.js"> </script>
<script src="js/pathTracingCommon.js"> </script>
<script src="js/threex.keyboardstate.js"> </script>
<script src="js/FirstPersonCameraControls.js"> </script>
<!-- <script src="js/FirstPersonCameraControls.js"> </script> -->
<script>
// this demo's camera code requires a slight change to yawObject.rotation, as seen below
var FirstPersonCameraControls = function ( camera ) {

camera.rotation.set( 0, 0, 0 );
var pitchObject = new THREE.Object3D();
pitchObject.add( camera );
var yawObject = new THREE.Object3D();
yawObject.add( pitchObject );
var movementX = 0;
var movementY = 0;
var onMouseMove = function ( event ) {
movementX = event.movementX || event.mozMovementX || 0;
movementY = event.movementY || event.mozMovementY || 0;
/// yawObject.rotation.y -= movementX * 0.002;
yawObject.rotateOnWorldAxis(yawObject.up, -movementX * 0.002);
pitchObject.rotation.x -= movementY * 0.002;
// clamp the camera's vertical movement (around the x-axis) to the scene's 'ceiling' and 'floor'
pitchObject.rotation.x = Math.max( - PI_2, Math.min( PI_2, pitchObject.rotation.x ) );
};
document.addEventListener( 'mousemove', onMouseMove, false );
this.getObject = function () {
return yawObject;
};
this.getYawObject = function () {
return yawObject;
};
this.getPitchObject = function () {
return pitchObject;
};
this.getDirection = function() {
var te = pitchObject.matrixWorld.elements;
return function( v ) {
v.set( te[ 8 ], te[ 9 ], te[ 10 ] ).negate();
return v;
};
}();
this.getUpVector = function() {
var te = pitchObject.matrixWorld.elements;
return function( v ) {
v.set( te[ 4 ], te[ 5 ], te[ 6 ] );
return v;
};
}();
this.getRightVector = function() {
var te = pitchObject.matrixWorld.elements;
return function( v ) {
v.set( te[ 0 ], te[ 1 ], te[ 2 ] );
return v;
};
}();
};
</script>

<script src="js/MobileJoystickControls.js"> </script>
<script src="js/stats.min.js"> </script>

Expand Down

0 comments on commit 0669ff8

Please sign in to comment.