我基本上想要将以下代码片段(Y轴向上)复制到libgdx:
let archer = Vector3d(1.0,0.0,1.0)
let target = Vector3d(4.0,0.0,5.0)
let travel = target - archer
let transform = Matrix4d.CreateTranslation(-archer) *
Matrix4d.CreateRotationY(Math.Atan2(travel.Z,travel.X))
Vector3d.Transform(archer, transform) // transforms archer to (0,0,0)
Vector3d.Transform(target, transform) // transforms target to (5,0,0)
这是我的方法(Z轴向上):
archer = new Vector3(1,1,0);
target = new Vector3(4,5,0);
Vector3 travel = new Vector3(target).sub(new Vector3(archer));
float degree = (float) Math.toDegrees(Math.atan2(travel.y, travel.x));
Matrix4 transform = new Matrix4().setToTranslation(new Vector3(archer).mul(-1));
transform.mul(new Matrix4().rotate(0, 0, 1, degree));//in my case Z-Axis is up !
archer.mul(transform); //-1.2,0.39999998,0 should be: 0,0,0
target.mul(transform); //-2.6000001,5.2,0.0 should be: 5,0,0
我收到错误的结果,我找不到我的错误,但我想这与第6行的旋转部分有关
答案 0 :(得分:0)
我想它应该是
archer = new Vector3(1,0,1);
target = new Vector3(4,0,5);