Skip to content

Instantly share code, notes, and snippets.

@spheenik
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spheenik/3766744d47c170f25cf5 to your computer and use it in GitHub Desktop.
Save spheenik/3766744d47c170f25cf5 to your computer and use it in GitHub Desktop.
entity positions
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