-
-
Save Tom-Ski/9520859 to your computer and use it in GitHub Desktop.
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 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