Libgdx:围绕z轴旋转(矩阵变换)

时间:2012-12-01 17:33:12

标签: java matrix libgdx transformation

我基本上想要将以下代码片段(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)

源: https://gamedev.stackexchange.com/questions/33901/how-to-make-an-arrow-land-at-a-specific-position-in-3d-world-space

这是我的方法(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行的旋转部分有关

1 个答案:

答案 0 :(得分:0)

我想它应该是

archer = new Vector3(1,0,1);        
target = new Vector3(4,0,5);