使用 radius/diameter 而不是 x、y、z 来平移相机?

Translating camera with radius/diameter instead of x,y,z?

所以我有这个示例,如下所示,我想知道是否可以通过更改半径和直径而不是使用 x、y、z 位置(矢量)来平移相机。现在我使用立方体,但我基本上想添加第二个摄像头。

既然我知道 0,0,0(原点)在哪里,有没有办法通过设置直径半径或任何需要的东西来平移立方体并将其锁定在原点?

我用什么来移动立方体(Three.js)

var posX,posY,posZ;
var scene, camera, render;
var cubeMesh,cube_Geometry, cube_Material;

class myWorld{
    /* ... Setup World ... */
    //excecute cube();
    /* ... Set/Get positions (xyz) ... */

    cube(){
        cube_Geometry = new THREE.BoxGeometry(20, 20, 20);
        cube_Material = new THREE.MeshNormalMaterial();
        cube_Mesh = new THREE.Mesh(cube_Geometry, cube_Material);
        cube_Mesh.position.set(0, 100, 100);
        scene.add(cube_Mesh);
    }

    animate(){ //loop function
        //THREE.Mesh.position.set (Three.js)
        cube_Mesh.position.set(posX, posY, posZ);
    }
}

我想达到的目标:

使用Spherical and setFromSpherical:

var r = 10;
var theta = 310 * (Math.PI / 180); /// 310 degree to radians

var sphericalPos = new THREE.Spherical(r, 0, theta);
cube_Mesh.position.setFromSpherical(sphericalPos);
// or just do cube_Mesh.position.setFromSphericalCoords(radius, phi, theta)

Spherical(radius: Float, phi: Float, theta : Float)

  • radius - the radius, or the Euclidean distance (straight-line distance) from the point to the origin. Default is 1.0.
  • phi - polar angle from the y (up) axis. Default is 0.
  • theta - equator angle around the y (up) axis. Default is 0.

The poles (phi) are at the positive and negative y axis. The equator (theta) starts at positive z.