Improved accuracy of Quaternion::Normalize
This commit is contained in:
parent
5c11ba83fd
commit
adb9b6e235
@ -58,20 +58,21 @@ float Quaternion::GetLengthSquared(const Quaternion& q) {
|
||||
}
|
||||
|
||||
void Quaternion::Normalize() {
|
||||
float scale = 1.0f / GetLength();
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
z *= scale;
|
||||
w *= scale;
|
||||
float length = GetLength();
|
||||
x /= length;
|
||||
y /= length;
|
||||
z /= length;
|
||||
w /= length;
|
||||
}
|
||||
|
||||
Quaternion Quaternion::Normalize(const Quaternion& q) {
|
||||
Quaternion result;
|
||||
float scale = 1.0f / q.GetLength();
|
||||
result = Quaternion(q.x * scale, q.y * scale, q.z * scale, q.w * scale);
|
||||
float length = q.GetLength();
|
||||
result = Quaternion(q.x / length, q.y / length, q.z / length, q.w / length);
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
float Quaternion::Dot(Quaternion a, Quaternion b) {
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user