【问题标题】:Translating camera with radius/diameter instead of x,y,z?用半径/直径而不是x,y,z平移相机?
【发布时间】:2019-06-25 14:57:58
【问题描述】:

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

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

我用什么来移动 Cube (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);
    }
}

我想要达到的目标:

【问题讨论】:

  • 另外,在 Y 轴 上这不应低于 0。在这种情况下最好把它排除在外
  • “改变半径和直径”是什么意思?
  • 我已经为你更新了我的问题。但它可能必须与 cos & sin 相关。不是数学家
  • 您似乎想根据极坐标更新位置
  • 好吧,我明天看看,我告诉你

标签: javascript math three.js translate radius


【解决方案1】:

使用SphericalsetFromSpherical

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)

球形(半径:浮点数,phi:浮点数,θ:浮点数)

  • radius - 从点到原点的半径或欧几里得距离(直线距离)。默认值为 1.0。
  • phi - y(向上)轴的极角。默认值为 0。
  • theta - 围绕 y(向上)轴的赤道角。默认值为 0。

极点 (phi) 位于 y 轴的正负。赤道 (theta) 从正 z 开始。

【讨论】:

  • 非常感谢您的回答。如果我使用THREE.Spherical(camera_RT_Radius, theta, 0),这对我很有用,如GIF 所示。但不在我想要的轴上。请注意,第三个滑块现在什么都不做,我希望立方体在 Y 轴上(围绕房子)旋转。
  • @LoizosVasileiou theta,最后一个参数将围绕y(上)轴旋转。
猜你喜欢
  • 2010-11-25
  • 2013-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多