获得移动摄像机的速度

Get the speed of a moving camera

本文关键字:速度 摄像机 移动      更新时间:2023-09-26

假设摄像机正在从一个位置移动到另一个位置,或者假设摄像机正在遵循曲线轨迹(通过在样条曲线上获取点并在每次渲染中将位置复制到摄像机)。

我们如何计算透视相机的速度?

简单和肮脏,你可以设置一个相机或任何其他对象的位置作为测量对象来监控它的速度:

var DebugSpeedometer = (function() {
    var lastMeasurement = 0,
        currentSpeed = 0;
    var lastMeasurementPosition = new THREE.Vector3(),
        distance = new THREE.Vector3();
    return {
        update: function( measureObject, timeStep ){
            if( lastMeasurement + timeStep < clock.getElapsedTime() ) {
                lastMeasurement = clock.getElapsedTime();
                distance = measureObject.getWorldPosition().distanceTo( lastMeasurementPosition );
                currentSpeed = distance / timeStep;
                lastMeasurementPosition = measureObject.getWorldPosition();
             }
             return currentSpeed;
        }
    };
})();
// globals
var clock = new THREE.Clock();
var speedoMeter = new DebugSpeedometer();

在你的update函数中:

console.log( speedoMeter.update( camera, 1 ) );