2012-12-01 32 views
2

我basicly要复制下面的代码片段(Y轴是向上)以libgdx:Libgdx:绕Z轴(矩阵变换)

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

回答

0

我想这应该是

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