16
German corner / Re: Berechnung Rotation
« on: November 26, 2013, 08:42:20 am »
Irgendwie bin ich zu blöde
Was mach ich falsch?
Was mach ich falsch?
Code: [Select]
public void lookAt(SimpleCord pos) {
SimpleVector startVector = this.getRotationPivot();
SimpleVector endVector = new SimpleVector(pos.X * 2, startVector.y, pos.Y * 2);
Matrix mat = startVector.getRotationMatrix(endVector);
float angle = deriveAngle(mat);
rotateY(angle);
Log.w("ANGLE", Float.toString(angle));
}
public float deriveAngle(Matrix mat) {
float y = (float) Math.asin(Math.min(1f, Math.max(-1f, -mat.get(0, 2))));
float zd = mat.getZAxis().z;
if (zd < 0) {
y = (float) (Math.PI / 2f + (Math.PI / 2f - y));
}
return y;
}