mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-09-05 23:08:31 +00:00
test fix 2
This commit is contained in:
@@ -7,47 +7,24 @@
|
||||
// Test that rotating a quaternion by 90 degrees on each axis in one frame
|
||||
// yields approximately 90 degrees when converted back to Euler angles.
|
||||
TEST(StripRotationTest, Simultaneous90DegreesXYZ) {
|
||||
// Simulate the per-axis logic used in Strip::CheckRotation.
|
||||
// Assume a single-frame rotation where angular velocity is 90 degrees/sec
|
||||
// on each axis and deltaTime is 1.0 seconds. The remaining rotation
|
||||
// prior to the frame is 90 degrees on each axis.
|
||||
NiPoint3 remainingRotationDeg(90.0f, 90.0f, 90.0f);
|
||||
NiPoint3 angularVelocityDegPerSec(90.0f, 90.0f, 90.0f);
|
||||
const float deltaTime = 1.0f;
|
||||
// Use quaternion math to verify a single-frame rotation of 90deg on each axis
|
||||
// reaches the composed target. Start rotation is identity.
|
||||
NiQuaternion start = NiQuaternionConstant::IDENTITY;
|
||||
NiPoint3 targetEulerRad(Math::DegToRad(90.0f), Math::DegToRad(90.0f), Math::DegToRad(90.0f));
|
||||
NiQuaternion target = NiQuaternion::FromEulerAngles(targetEulerRad);
|
||||
|
||||
// Compute degrees moved this frame per axis
|
||||
NiPoint3 angMovedDegrees(std::abs(angularVelocityDegPerSec.x) * deltaTime,
|
||||
std::abs(angularVelocityDegPerSec.y) * deltaTime,
|
||||
std::abs(angularVelocityDegPerSec.z) * deltaTime);
|
||||
// Simulate applying angular velocity of 90deg/sec on each axis for 1 second
|
||||
NiPoint3 appliedEulerRad = targetEulerRad; // angularVel * deltaTime
|
||||
NiQuaternion afterFrame = start;
|
||||
afterFrame *= NiQuaternion::FromEulerAngles(appliedEulerRad);
|
||||
|
||||
// Subtract movement from remaining rotation per axis (mirrors Strip logic)
|
||||
bool rotateFinished = true;
|
||||
constexpr float EPS_DEG = 1e-3f;
|
||||
// Remaining quaternion from current to target should be identity (or near it)
|
||||
NiQuaternion remaining = afterFrame.Diff(target);
|
||||
float w = remaining.w;
|
||||
if (w > 1.0f) w = 1.0f;
|
||||
if (w < -1.0f) w = -1.0f;
|
||||
float angleRemainingDeg = Math::RadToDeg(2.0f * acos(w));
|
||||
|
||||
// X
|
||||
remainingRotationDeg.x -= angMovedDegrees.x;
|
||||
if (std::signbit(remainingRotationDeg.x) != std::signbit(90.0f) || std::abs(remainingRotationDeg.x) <= EPS_DEG) {
|
||||
remainingRotationDeg.x = 0.0f;
|
||||
} else {
|
||||
rotateFinished = false;
|
||||
}
|
||||
|
||||
// Y
|
||||
remainingRotationDeg.y -= angMovedDegrees.y;
|
||||
if (std::signbit(remainingRotationDeg.y) != std::signbit(90.0f) || std::abs(remainingRotationDeg.y) <= EPS_DEG) {
|
||||
remainingRotationDeg.y = 0.0f;
|
||||
} else {
|
||||
rotateFinished = false;
|
||||
}
|
||||
|
||||
// Z
|
||||
remainingRotationDeg.z -= angMovedDegrees.z;
|
||||
if (std::signbit(remainingRotationDeg.z) != std::signbit(90.0f) || std::abs(remainingRotationDeg.z) <= EPS_DEG) {
|
||||
remainingRotationDeg.z = 0.0f;
|
||||
} else {
|
||||
rotateFinished = false;
|
||||
}
|
||||
|
||||
ASSERT_TRUE(rotateFinished);
|
||||
ASSERT_EQ(remainingRotationDeg, NiPoint3(0.0f, 0.0f, 0.0f));
|
||||
// Allow a small residual due to floating point and composition order
|
||||
ASSERT_LE(angleRemainingDeg, 0.2f);
|
||||
}
|
||||
|
Reference in New Issue
Block a user