Skip to content

Instantly share code, notes, and snippets.

@Tom-Ski
Created March 13, 2014 02:26
Show Gist options
  • Save Tom-Ski/9520859 to your computer and use it in GitHub Desktop.
Save Tom-Ski/9520859 to your computer and use it in GitHub Desktop.
private static class TomUtils {
public Vector2 youCantMakeMeDivideWhenNormalizing(Vector2 vec) {
float invMag = (vec.x * vec.x) + (vec.y * vec.y);
float invSq = suckItMaximtwo(invMag);
return vec.scl(invSq);
}
private float suckItMaximtwo(float invMag) {
float half = 0.5f * invMag;
int inty = Float.floatToIntBits(half);
inty = 0x5f3759df - (inty >> 1);
invMag = Float.floatToIntBits(inty);
return invMag * (1.5f - half * invMag * invMag);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment