场景的移动
1.改变相机的位置,让物体移动
function animation()
{
//renderer.clear();
camera.position.x =camera.position.x +1;
renderer.render(scene, camera);
requestAnimationFrame(animation);
}
2.改变物体自身的位置,让物体移动
function animation()
{
mesh.position.x-=1;
renderer.render(scene, camera);
requestAnimationFrame(animation);
}
3.fps
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
document.getElementById('canvas-frame').appendChild(stats.domElement);
//调用stats.update()函数来统计时间和帧数,这个函数已经被封装好了
相机
1.在Threejs中相机的表示是THREE.Camera,它是相机的抽象基类,其子类有两种相机,分别是正投影相机THREE.OrthographicCamera和透视投影相机THREE.PerspectiveCamera。
2.正投影相机(平行投影)
//l,r,t,b,n,f
var camera = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, 1, 1000 );
scene.add( camera );
3.透视投影相机
//PerspectiveCamera( fov, aspect, near, far )
//视角fov:眼睛睁开的角度
//近平面near:眼睛距离近处的距离
//远平面far
//纵横比aspect:实际窗口的纵横比,即宽度除以高度
var camera = new THREE.PerspectiveCamera( 45, width / height, 1, 1000 );
scene.add( camera );