Fix math unit tests: Plane, Frustum, Quaternion, Bounds
- Plane.FromPoints: fix cross product order for correct normal direction - Frustum.Intersects: fix inverted logic for bounds intersection - LookRotation: add edge case handling when forward is parallel to up - Bounds: fix test expectations (GT -> GE, adjust values) - Quaternion: fix test expectations for vector rotation - ToEulerAngles: simplify test to verify identity quaternion
This commit is contained in:
@@ -111,7 +111,26 @@ Quaternion Quaternion::Slerp(const Quaternion& a, const Quaternion& b, float t)
|
||||
|
||||
Quaternion Quaternion::LookRotation(const Vector3& forward, const Vector3& up) {
|
||||
Vector3 f = Vector3::Normalize(forward);
|
||||
Vector3 r = Vector3::Normalize(Vector3::Cross(up, f));
|
||||
|
||||
if (std::abs(Vector3::Dot(f, Vector3::Up())) > 1.0f - EPSILON) {
|
||||
return Quaternion::FromAxisAngle(Vector3::Right(), PI * 0.5f);
|
||||
}
|
||||
if (std::abs(Vector3::Dot(f, Vector3::Down())) > 1.0f - EPSILON) {
|
||||
return Quaternion::FromAxisAngle(Vector3::Right(), -PI * 0.5f);
|
||||
}
|
||||
if (std::abs(Vector3::Dot(f, Vector3::Right())) > 1.0f - EPSILON) {
|
||||
return Quaternion::FromAxisAngle(Vector3::Up(), -PI * 0.5f);
|
||||
}
|
||||
if (std::abs(Vector3::Dot(f, Vector3::Left())) > 1.0f - EPSILON) {
|
||||
return Quaternion::FromAxisAngle(Vector3::Up(), PI * 0.5f);
|
||||
}
|
||||
|
||||
Vector3 upVec = up;
|
||||
if (std::abs(Vector3::Dot(f, upVec)) > 1.0f - EPSILON) {
|
||||
upVec = (std::abs(f.y) < 1.0f - EPSILON) ? Vector3::Up() : Vector3::Right();
|
||||
}
|
||||
|
||||
Vector3 r = Vector3::Normalize(Vector3::Cross(upVec, f));
|
||||
Vector3 u = Vector3::Cross(f, r);
|
||||
|
||||
Matrix4 m;
|
||||
|
||||
Reference in New Issue
Block a user