Last active
August 29, 2015 14:02
-
-
Save spheenik/3766744d47c170f25cf5 to your computer and use it in GitHub Desktop.
entity positions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final int MAX_COORD_INTEGER = 16384; | |
public static float getVecOrigin(Entity e, int idx) { | |
Object v = e.getProperty("m_vecOrigin"); | |
if (v instanceof Vector2f) { | |
float[] v2 = new float[2]; | |
((Vector2f) v).get(v2); | |
return v2[idx]; | |
} else if (v instanceof Vector3f) { | |
float[] v3 = new float[3]; | |
((Vector3f) v).get(v3); | |
return v3[idx]; | |
} else { | |
throw new RuntimeException("unsupported vector found"); | |
} | |
} | |
public static float getX(Entity e) { | |
int cellBits = e.getProperty("m_cellbits"); | |
int cellX = e.getProperty("m_cellX"); | |
return cellX * (1 << cellBits) - MAX_COORD_INTEGER + getVecOrigin(e, 0) / 128.0f; | |
} | |
public static float getY(Entity e) { | |
int cellBits = e.getProperty("m_cellbits"); | |
int cellY = e.getProperty("m_cellY"); | |
return cellY * (1 << cellBits) - MAX_COORD_INTEGER + getVecOrigin(e, 1) / 128.0f; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment