I’m assuming you want to use your movement vector to set a transform somewhere. So you need to convert it into a matrix containing the rotation. If so, you don’t need find any angles. You can create the matrix by hand.
The upper 3x3 part of the matrix contains the rotation. It is defined as 3 vectors (right, up, forward) wich are all perpendicular to each other. Here is how to calculte the vectors:
forward vector - normalize your movement vector
right vector - the cross product between forward and a temporary up vector (0, 1, 0)
up vector - the cross product between the forward and right vector.
Now you plug the 3 vectors into a matrix and use it to set a transform. I don’t remember in wich order or direction (row, column) of the vectors in the matrix so you better look that up.
Btw. Here is the code to convert a vector to euler angles, in case you do need it:
/** Gets the angle of the vector in euler given by the vector (xp, yp, zp).
* (0, 0, 1) is angle (0,0,0).
* The input do not have to be normalized.
*
* The returned x will be in the range [-PI/2, PI/2]
* The returned y will be in the range [0, 2PI]
* @return the out object.
*/
public static final Vector3f getAngleFromVector(double xp, double yp, double zp, Vector3f out) {
// rotation around up axis
double eulery = (Math.PI*2)-getAngleFromVector(zp, xp);
// rotation around rigth axis
double xzLength = Math.sqrt(xp*xp+zp*zp);
double eulerx = getAngleFromVector(xzLength, yp);
if (yp < 0) eulerx = (eulerx-Math.PI*2);
out.set((float)eulerx, (float)eulery, 0);
return out;
}
/** Gets the angle of the vector given by (xp, yp)
*/
public static final double getAngleFromVector(double xp, double yp) {
if ((xp!=0)&&(yp!=0)) {
//Calculate angle of vector
double angle=0;
if (xp!=0) {
if ((xp>=0)&&(yp>=0))
angle=Math.atan(yp/xp);
if ((xp<0)&&(yp>=0))
angle=Math.PI-Math.atan(yp/-xp);
if ((xp<0)&&(yp<0))
angle=Math.PI+Math.atan(-yp/-xp);
if ((xp>=0)&&(yp<0))
angle=Math.PI*2-Math.atan(-yp/xp);
} else {
if (yp>=0)
angle=Math.PI/2;
else
angle=Math.PI+Math.PI/2;
}
return angle;
} else {
if (xp==0 && yp==0) return 0;
if (xp==0 && yp>0) return Math.PI*0.5;
if (xp==0 && yp<0) return -Math.PI*0.5;
if (yp==0 && xp>0) return 0;
else return Math.PI;
}
}