我猜你使用的是纬度,态度点。我计算 phi,theta 如下:
var phi = (90 - varible1) * Math.PI / 180;
var theta = (-variable2) * Math.PI / 180;
var RandomHeightOfLine = 1.5 // Or greater then your point distance to origin
作为向量 =
new THREE.Vector3(RandomHeightOfLine * Math.sin(phi) * Math.cos(theta), RandomHeightOfLine * Math.cos(phi), RandomHeightOfLine * Math.sin(phi) * Math.sin(theta)));
作为点 =
var x = RandomHeightOfLine * Math.sin(phi) * Math.cos(theta);
var y = RandomHeightOfLine * Math.cos(phi);
var z = RandomHeightOfLine * Math.sin(phi) * Math.sin(theta);
controls.target.set( x, y, z );
如果您还想移动相机,我建议使用更大的 RandomHeightOfLine 计算 x2,y2,z2。
如果你想要平滑移动,我建议你使用 TWEEN。
var t;
var t2;
var t3; //Put as Global or use Array, because GC likes to remove Tween objects.
function tweenCamera(position, target, time){
console.log("tween");
updateTween = true;
beforeTweenPos = camera.position.clone();
beforeTweenTarg = controls.target.clone();
t = new TWEEN.Tween( camera.position ).to( {
x: position.x,
y: position.y,
z: position.z}, time )
.easing( TWEEN.Easing.Quadratic.In).start();
t2 = new TWEEN.Tween( camera.up ).to( {
x: 0,
y: 1,
z: 0}, time )
.easing( TWEEN.Easing.Quadratic.In).start();
t3 = new TWEEN.Tween( controls.target ).to( {
x: target.x,
y: target.y,
z: target.z}, time )
.easing( TWEEN.Easing.Quadratic.In)
.onComplete(function () {
updateTween = false;
console.log("Turning off Update Tween");
t = null;
t2 = null;
t3 = null;
}, this).start();
//camera.up = new THREE.Vector3(0,0,1); // If you don't want animation for this. And remove t3.
}
您还应该添加动画更新:
...
lastTimeMsec = lastTimeMsec || nowMsec-1000/60;
deltaMsec = Math.min(200, nowMsec - lastTimeMsec);
lastTimeMsec = nowMsec;
if(updateTween)
{
TWEEN.update(lastTimeMsec); //Comment
} else
{
TWEEN.removeAll();
}
...
补间JS:http://www.createjs.com/tweenjs