Skip to content

二、位移、速度、加速度(向量)

更新: 12/19/2025字数: 0 字阅读: 0 分钟

javascript
const v = new THREE.Vector3(10,0,10);//物体运动速度
const clock = new THREE.Clock();//时钟对象
// 渲染循环
function render() {
    const spt = clock.getDelta();//两帧渲染时间间隔(秒)
    // 在spt时间内,以速度v运动的位移量
    const dis = v.clone().multiplyScalar(spt);
    // 网格模型当前的位置加上spt时间段内运动的位移量
    mesh.position.add(dis);
    renderer.render(scene, camera);
    requestAnimationFrame(render);
}
render();

javascript
// 物体初始位置
mesh.position.set(0,100,0);
javascript
//物体初始速度
const v = new THREE.Vector3(30,0,0);
javascript
//重力加速度
const g = new THREE.Vector3(0, -9.8, 0);

  • 速度v = 加速度g x 时间t
  • 位移x = 速度v x 时间t
javascript
const v = new THREE.Vector3(30, 0, 0);//物体初始速度
const clock = new THREE.Clock();//时钟对象
const g = new THREE.Vector3(0, -9.8, 0);
// 渲染循环
function render() {
  if (mesh.position.y > 0) {
    const spt = clock.getDelta();//两帧渲染时间间隔(秒)
    //spV:重力加速度在时间spt内对速度的改变
    const spV = g.clone().multiplyScalar(spt);
    v.add(spV);//v = v + spV  更新当前速度
    // 在spt时间内,以速度v运动的位移量
    const dis = v.clone().multiplyScalar(spt);
    // 网格模型当前的位置加上spt时间段内运动的位移量
    mesh.position.add(dis);
  }
  renderer.render(scene, camera);
  requestAnimationFrame(render);
}
render();