threejs api 记录

threejs API 记录

mesh.position.distanceTo(camera.position)

获取两个Vector3 之间的距离

camera.lookAt(mesh.position)

摄像机镜头指向 Vector3

mesh.position.normalize()

向量归一化,向量每个坐标值分别除以其长度

用处

  1. 两个单位向量的点积则是他们的夹角余弦值 a⋅b=cos(θ)
  2. 两个单位向量的叉积结果也是一个单位向量,表示垂直于这两个向量的方向
  3. 控制速度,单位向量乘以速度值,可以控制物体以一定的速度移动

new THREE.Clock( autoStart ) 用来跟踪时间

  • autoStart 可选参数,自动启动,默认为true
  • start() 启动时钟
  • stop() 停止时钟
  • getElapsedTime() 返回自时钟启动以来所经过的时间
  • getDelta() 返回自上次调用getDelta方法以来经过的时间,通常在渲染循环中调用以获得两帧之间的时间间隔

物体绕x y z 轴旋转

   mesh.rotation.x = elapsedTime * Math.PI;
   mesh.rotation.y = elapsedTime * Math.PI;
   mesh.rotation.z = elapsedTime * Math.PI;

物体运动轨迹为一个圈圈半径是1

   mesh.position.x = Math.sin(elapsedTime);
   mesh.position.y = Math.cos(elapsedTime);

canvas 全屏展示,更新相机

更新相机矩阵,当canvas尺寸改变时需要更新相机矩阵

 camera.aspect = sizes.width / sizes.height;
 camera.updateProjectionMatrix();
 renderer.setSize(sizes.width, sizes.height);
 enderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
posted @ 2025-03-25 18:13  lence  阅读(49)  评论(0)    收藏  举报