link to the jsfiddle of this question
如何重新定位在原点创建的对象以遵循向量的方向?
我的小提琴显示了一个均匀分布的精灵球体。然后我创建一个均匀分布的精灵圆盘(圆圈)。我的目标是将光盘定位在球体外部,匹配从原点生成的方向>球体物体。
我相信我的问题源于我在原点创建光盘精灵,然后尝试使用translateOnAxis
重新定位。
相关代码。
disc_objects
包含一些精灵;
direction
是THREE.Vector3
,其来自原点>指向一个球体。我需要帮助将disc_object对齐到那个方向。
for (var i = 0, l = disc_objects.length; i < l; i++) {
// Vogel's method of Fermat's spiral (Phyllotaxis)
// http://blog.marmakoide.org/?p=1
var theta = i * golden_angle;
var r = Math.sqrt(i) / Math.sqrt(l);
// all points are created around origin
disc_objects[i].position.x = r * Math.cos(theta);
disc_objects[i].position.y = r * Math.sin(theta);
disc_objects[i].position.multiplyScalar(distance);
// translate the arranged disc points to the random_point
// adds disc twice as far away as ranom_point on sphere
disc_objects[i].translateOnAxis(direction, distance * 2);
scene.add(disc_objects[i]);
}
答案 0 :(得分:1)
parent = new THREE.Object3D();
parent.position.add(direction.clone().multiplyScalar(distance * 2));
parent.lookAt(vector);
scene.add(parent);
现在当我添加光盘点时,它们是相对于父级的,正确“查看”原点。