Skip to content

Instantly share code, notes, and snippets.

@pollend
Last active July 1, 2022 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pollend/9ff37774fca94146ff25652c3ff802e4 to your computer and use it in GitHub Desktop.
Save pollend/9ff37774fca94146ff25652c3ff802e4 to your computer and use it in GitHub Desktop.
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "AzCore/Debug/Trace.h"
#include "AzCore/Math/MathStringConversions.h"
#include "AzCore/Math/Sfmt.h"
#include "AzCore/Math/Vector3.h"
#include "AzCore/UnitTest/TestTypes.h"
#include <MCore/Source/AzCoreConversions.h>
#include <AzTest/AzTest.h>
#include <MCore/Source/DualQuaternion.h>
#include <iostream>
#include <random>
namespace MCore
{
MATCHER_P(IsClose, expected, "")
{
AZ_UNUSED(result_listener);
if (arg.IsClose(expected))
{
return true;
}
return false;
}
// TEST(DualQuaternionTests, ToTransform)
// {
// const AZ::Vector3 translation(0.15f, -1.8f, 0.23f);
// const AZ::Quaternion rotation(0.72f, -0.48f, -0.24f, 0.44f);
// const DualQuaternion dualQuaternion = DualQuaternion::ConvertFromRotationTranslation(rotation, translation);
// const AZ::Transform transform = dualQuaternion.ToTransform();
// EXPECT_TRUE(transform.GetBasisX().IsClose(AZ::Vector3(0.424f, -0.9024f, 0.0768f)));
// EXPECT_TRUE(transform.GetBasisY().IsClose(AZ::Vector3(-0.48f, -0.152f, 0.864f)));
// EXPECT_TRUE(transform.GetBasisZ().IsClose(AZ::Vector3(-0.768f, -0.4032f, -0.4976f)));
// EXPECT_TRUE(transform.GetTranslation().IsClose(translation));
// }
class AngleTestFixture
: public UnitTest::ScopedAllocatorSetupFixture {
};
TEST_F(AngleTestFixture, ToAngleTest)
{
std::uniform_real_distribution<float> unif;
std::mt19937_64 rng(100);
for(int x = 0; x < 1000; x++) {
float angle = unif(rng);
AZ::Vector3 v1 = AZ::Vector3(unif(rng), unif(rng), unif(rng)).GetNormalized();
// MCore::CreateFromAxisAndAngle(v1, angle);
AZ_Error("ToAngleTest", false, "angle1: %s angle2: %s",
AZStd::to_string(AZ::Quaternion::CreateFromAxisAngle(v1, angle)).c_str(),
AZStd::to_string(MCore::CreateFromAxisAndAngle(v1, angle)).c_str()
);
EXPECT_THAT(MCore::CreateFromAxisAndAngle(v1, angle), IsClose(AZ::Quaternion::CreateFromAxisAngle(v1, angle)));
}
}
} // namespace MCore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment