未验证 提交 24511738 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #15650 from Mugen87/dev26

FirstPersonControls: Added .lookAt()
......@@ -34,9 +34,6 @@ THREE.FirstPersonControls = function ( object, domElement ) {
this.mouseX = 0;
this.mouseY = 0;
this.lat = 0;
this.lon = 0;
this.moveForward = false;
this.moveBackward = false;
this.moveLeft = false;
......@@ -47,6 +44,17 @@ THREE.FirstPersonControls = function ( object, domElement ) {
this.viewHalfX = 0;
this.viewHalfY = 0;
// private variables
var lat = 0;
var lon = 0;
var lookDirection = new THREE.Vector3();
var spherical = new THREE.Spherical();
var target = new THREE.Vector3();
//
if ( this.domElement !== document ) {
this.domElement.setAttribute( 'tabindex', - 1 );
......@@ -181,6 +189,26 @@ THREE.FirstPersonControls = function ( object, domElement ) {
};
this.lookAt = function ( x, y, z ) {
if ( x.isVector3 ) {
target.copy( x );
} else {
target.set( x, y, z );
}
this.object.lookAt( target );
setOrientation( this );
return this;
};
this.update = function () {
var targetPosition = new THREE.Vector3();
......@@ -229,13 +257,13 @@ THREE.FirstPersonControls = function ( object, domElement ) {
}
this.lon -= this.mouseX * actualLookSpeed;
if ( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed * verticalLookRatio;
lon -= this.mouseX * actualLookSpeed;
if ( this.lookVertical ) lat -= this.mouseY * actualLookSpeed * verticalLookRatio;
this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
lat = Math.max( - 85, Math.min( 85, lat ) );
var phi = THREE.Math.degToRad( 90 - this.lat );
var theta = THREE.Math.degToRad( this.lon );
var phi = THREE.Math.degToRad( 90 - lat );
var theta = THREE.Math.degToRad( lon );
if ( this.constrainVertical ) {
......@@ -295,6 +323,20 @@ THREE.FirstPersonControls = function ( object, domElement ) {
}
function setOrientation( controls ) {
var quaternion = controls.object.quaternion;
lookDirection.set( 0, 0, - 1 ).applyQuaternion( quaternion );
spherical.setFromVector3( lookDirection );
lat = 90 - THREE.Math.radToDeg( spherical.phi );
lon = THREE.Math.radToDeg( spherical.theta );
}
this.handleResize();
setOrientation( this );
};
......@@ -90,6 +90,9 @@
controls.movementSpeed = 100;
controls.lookSpeed = 0.1;
controls.lookAt( 500, 500, 500 );
// add a skybox background
var cubeTextureLoader = new THREE.CubeTextureLoader();
......
......@@ -85,29 +85,25 @@
container = document.createElement( 'div' );
document.body.appendChild( container );
// SCENE CAMERA
// CAMERA
camera = new THREE.PerspectiveCamera( 23, SCREEN_WIDTH / SCREEN_HEIGHT, NEAR, FAR );
camera.position.set( 700, 50, 1900 );
// SCENE
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x59472b );
scene.fog = new THREE.Fog( 0x59472b, 1000, FAR );
controls = new THREE.FirstPersonControls( camera );
controls.lookSpeed = 0.0125;
controls.movementSpeed = 500;
controls.noFly = false;
controls.lookVertical = true;
controls.constrainVertical = true;
controls.verticalMin = 1.5;
controls.verticalMax = 2.0;
controls.lon = 250;
controls.lat = 30;
// SCENE
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x59472b );
scene.fog = new THREE.Fog( 0x59472b, 1000, FAR );
controls.lookAt( scene.position );
// LIGHTS
......
......@@ -81,29 +81,25 @@
container = document.createElement( 'div' );
document.body.appendChild( container );
// SCENE CAMERA
// CAMERA
camera = new THREE.PerspectiveCamera( 23, SCREEN_WIDTH / SCREEN_HEIGHT, NEAR, FAR );
camera.position.set( 700, 50, 1900 );
// SCENE
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x59472b );
scene.fog = new THREE.Fog( 0x59472b, 1000, FAR );
controls = new THREE.FirstPersonControls( camera );
controls.lookSpeed = 0.0125;
controls.movementSpeed = 500;
controls.noFly = false;
controls.lookVertical = true;
controls.constrainVertical = true;
controls.verticalMin = 1.5;
controls.verticalMax = 2.0;
controls.lon = 250;
controls.lat = 30;
// SCENE
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x59472b );
scene.fog = new THREE.Fog( 0x59472b, 1000, FAR );
controls.lookAt( scene.position );
// LIGHTS
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册