#include "UnitTests.hpp"
#include <PlayRho/Dynamics/Joints/MotorJointConf.hpp>
#include <PlayRho/Dynamics/Joints/Joint.hpp>
#include <PlayRho/Dynamics/BodyConf.hpp>
#include <PlayRho/Dynamics/World.hpp>
#include <PlayRho/Dynamics/WorldBody.hpp>
#include <PlayRho/Dynamics/WorldJoint.hpp>
#include <PlayRho/Dynamics/WorldFixture.hpp>
#include <PlayRho/Dynamics/WorldMisc.hpp>
#include <PlayRho/Dynamics/StepConf.hpp>
#include <PlayRho/Collision/Shapes/DiskShapeConf.hpp>
{
case 4:
break;
case 8:
break;
case 16:
break;
default:
FAIL();
break;
}
}
{
EXPECT_EQ(def.collideConnected, false);
EXPECT_EQ(def.linearOffset, (
Length2{}));
EXPECT_EQ(def.angularOffset, 0_deg);
EXPECT_EQ(def.maxForce, 1_N);
EXPECT_EQ(def.maxTorque, 1_Nm);
EXPECT_EQ(def.correctionFactor,
Real(0.3));
}
{
const auto bodyA =
static_cast<BodyID>(0x1);
const auto bodyB =
static_cast<BodyID>(0x2);
const auto collideConnected = true;
const auto linearOffset =
Length2{2_m, 3_m};
const auto angularOffset = 33_rad;
const auto maxForce = 22_N;
const auto maxTorque = 31_Nm;
const auto correctionFactor =
Real(0.44f);
.UseAngularOffset(angularOffset)
.UseMaxForce(maxForce)
.UseMaxTorque(maxTorque)
.UseCorrectionFactor(correctionFactor);
EXPECT_EQ(def.bodyA, bodyA);
EXPECT_EQ(def.bodyB, bodyB);
EXPECT_EQ(def.collideConnected, collideConnected);
EXPECT_EQ(def.linearOffset, linearOffset);
EXPECT_EQ(def.angularOffset, angularOffset);
EXPECT_EQ(def.maxForce, maxForce);
EXPECT_EQ(def.maxTorque, maxTorque);
EXPECT_EQ(def.correctionFactor, correctionFactor);
}
TEST(MotorJoint, Construction)
{
EXPECT_EQ(
GetType(world, jointID), GetTypeID<MotorJointConf>());
EXPECT_EQ(
GetBodyA(world, jointID), def.bodyA);
EXPECT_EQ(
GetBodyB(world, jointID), def.bodyB);
const auto conf = TypeCast<MotorJointConf>(
GetJoint(world, jointID));
}
{
const auto newOrigin =
Length2{1_m, 1_m};
}
{
auto conf = TypeCast<MotorJointConf>(
GetJoint(world, jointID));
ASSERT_EQ(
Real(0.3), def.correctionFactor);
EXPECT_NO_THROW(
SetJoint(world, jointID, conf));
auto conf2 = TypeCast<MotorJointConf>(
GetJoint(world, jointID));
}
{
ASSERT_EQ(
GetType(world, jointID), GetTypeID<MotorJointConf>());
ASSERT_EQ(
GetBodyA(world, jointID), def.bodyA);
ASSERT_EQ(
GetBodyB(world, jointID), def.bodyB);
const auto conf = TypeCast<MotorJointConf>(
GetJoint(world, jointID));
EXPECT_EQ(cdef.bodyA, b0);
EXPECT_EQ(cdef.bodyB, b1);
EXPECT_EQ(cdef.collideConnected, false);
EXPECT_EQ(cdef.linearOffset, (
Length2{}));
EXPECT_EQ(cdef.angularOffset, 0_deg);
EXPECT_EQ(cdef.maxForce, 1_N);
EXPECT_EQ(cdef.maxTorque, 1_Nm);
EXPECT_EQ(cdef.correctionFactor,
Real(0.3));
}
TEST(MotorJoint, WithDynamicCircles)
{
const auto p1 =
Length2{-1_m, 0_m};
const auto p2 =
Length2{+1_m, 0_m};
stepConf.doWarmStart = false;
}
{
const auto p1 =
Length2{-1_m, 0_m};
const auto p2 =
Length2{+1_m, 0_m};
const auto linearOffset =
Length2{2_m, 1_m};
ASSERT_NE(jd.linearOffset, linearOffset);
}
{
const auto p1 =
Length2{-1_m, 0_m};
const auto p2 =
Length2{+1_m, 0_m};
}
{
EXPECT_EQ(conf.angularMass, rotInertia);
}
{
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
}
{
{
EXPECT_FALSE(conf != conf);
}
}
{
EXPECT_STREQ(
GetName(GetTypeID<MotorJointConf>()),
"d2::MotorJointConf");
}