小编Wil*_*sio的帖子

将对象旋转到面部点

我想旋转一个物体面对一个我有点麻烦的点.

所以我开始使用一个基数为零的对象,并在y轴上对齐.

在此输入图像描述

我想旋转它,使对象的顶部朝向目的地

在此输入图像描述

到目前为止,我的过程是:给定轴A

  1. 找到我的位置和我的外观位置之间的距离:D
  2. 创建方向向量:V = D.normalize()
  3. 找到合适的矢量:R = A交叉D.
  4. 找到向上矢量:U = D交叉R
  5. 找到向上和方向之间的角度:ANGLE = acos((U点D)/(U.length*D.length))
  6. 按每个轴上的方向缩放的角度旋转

这是代码表示.我不确定这究竟是什么问题我已经在纸上解决了问题,据我所知,这种方法应该有效,但结果在绘制时完全不正确.如果有人看到任何瑕疵,并指出我正确的方向,那将是伟大的.

    Vector3 distance = new Vector3(from.x, from.y, from.z).sub(to.x, to.y, to.z);
    final Vector3 axis = new Vector3(0, 1, 0);
    final Vector3 direction = distance.clone().normalize();

    final Vector3 right = (axis.clone().cross(direction));
    final Vector3 up = (distance.clone().cross(right));

    float angle = (float) Math.acos((up.dot(direction)/ (up.length() * direction.length()))); 
    bondObject.rotateLocal(angle, direction.x , direction.y, direction.z);
Run Code Online (Sandbox Code Playgroud)

java math 3d rotation

5
推荐指数
1
解决办法
2387
查看次数

标签 统计

3d ×1

java ×1

math ×1

rotation ×1