Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float InvSqrt(float x) {
- float xhalf = 0.5f * x;
- int32_t i = *(int32_t*)&x; // Bit-level hacking
- i = 0x5f3759df - (i >> 1);
- x = *(float*)&i;
- x = x * (1.5f - xhalf * x * x); // One iteration of Newton's method
- return x;
- }
- float DistanceApproximated(const Vector3& left, const Vector3& right) {
- float difx = left.x - right.x;
- float dify = left.y - right.y;
- float difz = left.z - right.z;
- float squaredDistance = difx * difx + dify * dify + difz * difz;
- return squaredDistance * InvSqrt(squaredDistance);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement