remove -90 degree adjustment (hacky) and add new helper for getting the angle in the XZ plane between two Vector3s
This commit is contained in:
parent
d5472b2701
commit
4f3b8ff2b7
|
@ -7,6 +7,7 @@ import com.badlogic.gdx.math.collision.BoundingBox;
|
||||||
|
|
||||||
public final class MathHelpers {
|
public final class MathHelpers {
|
||||||
static final Vector2 v2tmpA = new Vector2();
|
static final Vector2 v2tmpA = new Vector2();
|
||||||
|
static final Vector2 v2tmpB = new Vector2();
|
||||||
|
|
||||||
public static final float FLOAT_EPSILON = 1.401298E-45f; // smallest floating point value greater then zero
|
public static final float FLOAT_EPSILON = 1.401298E-45f; // smallest floating point value greater then zero
|
||||||
public static final float EPSILON = 0.000001f; //0.0000000001f;
|
public static final float EPSILON = 0.000001f; //0.0000000001f;
|
||||||
|
@ -35,7 +36,7 @@ public final class MathHelpers {
|
||||||
|
|
||||||
public static void getDirectionVector3FromYAxis(float yAxisDegrees, Vector3 result) {
|
public static void getDirectionVector3FromYAxis(float yAxisDegrees, Vector3 result) {
|
||||||
result.y = 0.0f;
|
result.y = 0.0f;
|
||||||
float adjustedAngle = rolloverClamp(yAxisDegrees - 90.0f, 0.0f, 360.0f);
|
float adjustedAngle = rolloverClamp(yAxisDegrees, 0.0f, 360.0f);
|
||||||
getPointOnCircle(1.0f, adjustedAngle, v2tmpA);
|
getPointOnCircle(1.0f, adjustedAngle, v2tmpA);
|
||||||
result.x = v2tmpA.x;
|
result.x = v2tmpA.x;
|
||||||
result.z = v2tmpA.y;
|
result.z = v2tmpA.y;
|
||||||
|
@ -51,6 +52,18 @@ public final class MathHelpers {
|
||||||
result.z = -((float)Math.cos(pitch) * (float)Math.cos(yaw));
|
result.z = -((float)Math.cos(pitch) * (float)Math.cos(yaw));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float getYAngleBetween(Vector3 a, Vector3 b) {
|
||||||
|
v2tmpA.set(a.x, a.z);
|
||||||
|
v2tmpB.set(b.x, b.z);
|
||||||
|
float angle = v2tmpB.sub(v2tmpA)
|
||||||
|
.angle();
|
||||||
|
|
||||||
|
if (angle < 0)
|
||||||
|
angle += 360.0f;
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
public static float getAngleBetween2D(final Vector2 a, final Vector2 b) {
|
public static float getAngleBetween2D(final Vector2 a, final Vector2 b) {
|
||||||
v2tmpA.set(a);
|
v2tmpA.set(a);
|
||||||
v2tmpA.sub(b);
|
v2tmpA.sub(b);
|
||||||
|
|
Loading…
Reference in a new issue