PlayRho
1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
|
|
This is the googletest
based unit testing file for the interfaces to playrho::d2::TargetJointConf
.
#include "UnitTests.hpp"
#include <PlayRho/Dynamics/Joints/TargetJointConf.hpp>
#include <PlayRho/Dynamics/Joints/Joint.hpp>
#include <PlayRho/Dynamics/Contacts/ConstraintSolverConf.hpp>
#include <PlayRho/Dynamics/Contacts/BodyConstraint.hpp>
#include <PlayRho/Dynamics/StepConf.hpp>
#include <PlayRho/Dynamics/World.hpp>
#include <stdexcept>
{
const auto value =
Length2(19_m, -9_m);
}
{
const auto value =
Force(19_N);
}
{
const auto value = 19_Hz;
}
{
const auto value =
Real(0.4);
}
{
case 4:
break;
case 8:
break;
case 16:
break;
default:
FAIL();
break;
}
}
#if 0
TEST(TargetJoint, IsOkay)
{
ASSERT_FALSE(Joint::IsOkay(def));
def.bodyA =
static_cast<BodyID>(1u);
def.bodyB =
static_cast<BodyID>(2u);
ASSERT_TRUE(Joint::IsOkay(def));
EXPECT_TRUE(TargetJoint::IsOkay(def));
EXPECT_TRUE(TargetJoint::IsOkay(def));
EXPECT_FALSE(TargetJoint::IsOkay(def));
}
#endif
TEST(TargetJoint, DefaultInitialized)
{
}
{
const auto bB = world.CreateBody();
def.bodyB = bB;
def.localAnchorB =
Length2(-1.4_m, -2_m);
def.maxForce = 3_N;
def.frequency = 67_Hz;
def.dampingRatio =
Real(0.8);
const auto joint =
Joint{def};
}
{
const auto bB = world.CreateBody();
def.bodyB = bB;
def.localAnchorB =
Length2(-1.4_m, -2_m);
def.maxForce = 3_N;
def.frequency = 67_Hz;
def.dampingRatio =
Real(0.8);
const auto joint =
Joint{def};
}
{
const auto bB = world.CreateBody();
def.bodyB = bB;
def.target =
Length2(-1.4_m, -2_m);
const auto newOrigin =
Length2{1_m, 1_m};
EXPECT_EQ(
GetTarget(joint), def.target - newOrigin);
}
{
def.bodyB = bB;
def.target =
Length2(-1.4_m, -2_m);
def.localAnchorB =
Length2(+2.0_m, -1_m);
def.maxForce = 3_N;
def.frequency = 67_Hz;
def.dampingRatio =
Real(0.8);
const auto joint =
Joint{def};
EXPECT_EQ(def.bodyA, got.bodyA);
EXPECT_EQ(def.bodyB, got.bodyB);
EXPECT_EQ(def.target, got.target);
EXPECT_EQ(def.localAnchorB, got.localAnchorB);
EXPECT_EQ(def.maxForce, got.maxForce);
EXPECT_EQ(def.frequency, got.frequency);
EXPECT_EQ(def.dampingRatio, got.dampingRatio);
}
{
EXPECT_EQ(mass[0][0], 0_kg);
EXPECT_EQ(mass[0][1], 0_kg);
EXPECT_EQ(mass[1][0], 0_kg);
EXPECT_EQ(mass[1][1], 0_kg);
}
{
std::vector<BodyConstraint> bodies;
EXPECT_THROW(
InitVelocity(def, bodies, step, conf), std::out_of_range);
}
{
std::vector<BodyConstraint> bodies;
bodies.push_back(
BodyConstraint{invMass, invRotI, localCenter, position, velocity});
def.frequency = 0_Hz;
def.gamma =
Real(5) / 1_kg;
EXPECT_EQ(def.gamma,
Real(0) / 1_kg);
def.frequency = 1_Hz;
def.gamma =
Real(5) / 1_kg;
EXPECT_EQ(def.gamma,
Real(0) / 1_kg);
}
{
std::vector<BodyConstraint> bodies;
EXPECT_THROW(
SolveVelocity(def, bodies, step), std::out_of_range);
}
{
std::vector<BodyConstraint> bodies;
auto result = false;
EXPECT_EQ(result, true);
}
{
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
}
{
{
EXPECT_FALSE(conf != conf);
}
}
{
EXPECT_STREQ(
GetName(GetTypeID<TargetJointConf>()),
"d2::TargetJointConf");
}
{
const auto frequencyA = 67_Hz;
const auto frequencyB = 2_Hz;
}
constexpr auto & UseMaxForce(NonNegative< Force > v) noexcept
Use value for max force.
Definition: TargetJointConf.hpp:80
constexpr auto GetMaxForce(const FrictionJointConf &object) noexcept
Free function for getting the max force value of the given configuration.
Definition: FrictionJointConf.hpp:177
BodyID CreateBody(const BodyConf &def=GetDefaultBodyConf())
Creates a rigid body with the given configuration.
Definition: World.cpp:161
Name space for 2-dimensionally related PlayRho names.
Definition: AABB.cpp:34
BodyID bodyA
1st attached body.
Definition: JointConf.hpp:36
Length2 localAnchorB
Anchor point.
Definition: TargetJointConf.hpp:105
constexpr void SetFrequency(DistanceJointConf &object, NonNegative< Frequency > value) noexcept
Free function for setting the frequency value of the given configuration.
Definition: DistanceJointConf.hpp:205
PLAYRHO_QUANTITY(boost::units::si::force) Force
Force quantity.
Definition: Units.hpp:244
const char * GetName(Manifold::Type type) noexcept
Gets a unique name for the given manifold type.
Definition: Manifold.cpp:788
Constraint for a body.
Definition: BodyConstraint.hpp:36
bool SolvePosition(const DistanceJointConf &object, std::vector< BodyConstraint > &bodies, const ConstraintSolverConf &conf)
Solves the position constraint.
Definition: DistanceJointConf.cpp:194
Name space for all PlayRho related names.
Definition: AABB.cpp:33
Constraint solver configuration data.
Definition: ConstraintSolverConf.hpp:33
NonNegative< Real > dampingRatio
The damping ratio. 0 = no damping, 1 = critical damping.
Definition: TargetJointConf.hpp:121
Definition of an independent and simulatable "world".
Definition: World.hpp:129
Length2 GetAnchorB(const World &world, JointID id)
Get the anchor point on body-B in world coordinates.
Definition: WorldJoint.cpp:216
Mass22 GetEffectiveMassMatrix(const TargetJointConf &object, const BodyConstraint &body) noexcept
Gets the effective mass matrix for the given configuration and body information.
Definition: TargetJointConf.cpp:51
constexpr bool ShiftOrigin(DistanceJointConf &, Length2) noexcept
Shifts the origin notion of the given configuration.
Definition: DistanceJointConf.hpp:177
BodyID GetBodyB(const Contact &contact) noexcept
Gets the body B ID of the given contact.
Definition: Contact.hpp:588
bool GetCollideConnected(const Joint &object) noexcept
Gets collide connected.
Definition: Joint.hpp:293
BodyID GetBodyA(const Contact &contact) noexcept
Gets the body A ID of the given contact.
Definition: Contact.hpp:581
constexpr BodyConf & UseLocation(Length2 l) noexcept
Use the given location.
Definition: BodyConf.hpp:172
bool SolveVelocity(DistanceJointConf &object, std::vector< BodyConstraint > &bodies, const StepConf &)
Solves velocity constraint.
Definition: DistanceJointConf.cpp:164
Length2 target
The initial world target point. This is assumed to coincide with the body anchor initially.
Definition: TargetJointConf.hpp:102
Length2 GetLocalAnchorB(const Joint &object)
Get the anchor point on body-B in local coordinates.
Definition: Joint.cpp:96
NonNegative< Force > maxForce
Max force.
Definition: TargetJointConf.hpp:113
constexpr auto & UseFrequency(NonNegative< Frequency > v) noexcept
Use value for frequency.
Definition: TargetJointConf.hpp:87
Length2 GetTarget(const Joint &object)
Gets the given joint's target property if it has one.
Definition: Joint.cpp:459
NonNegative< Frequency > frequency
Frequency.
Definition: TargetJointConf.hpp:118
constexpr auto InvalidBodyID
Invalid body ID value.
Definition: BodyID.hpp:33
PLAYRHO_QUANTITY(boost::units::si::angular_momentum) AngularMomentum
Angular momentum quantity.
Definition: Units.hpp:304
Step configuration.
Definition: StepConf.hpp:42
Frequency GetFrequency(const Joint &object)
Gets the frequency of the joint if it has this property.
Definition: Joint.cpp:407
PLAYRHO_QUANTITY(playrho::units::si::inverse_moment_of_inertia) InvRotInertia
Inverse rotational inertia quantity.
Definition: Units.hpp:282
constexpr AngularMomentum GetAngularReaction(const DistanceJointConf &) noexcept
Gets the current angular reaction for the given configuration.
Definition: DistanceJointConf.hpp:170
float Real
Real-number type.
Definition: Real.hpp:69
Configuration for a body.
Definition: BodyConf.hpp:50
TargetJointConf GetTargetJointConf(const Joint &joint)
Gets the definition data for the given joint.
Definition: TargetJointConf.cpp:46
detail::IndexingNamedType< BodyCounter, struct BodyIdentifier > BodyID
Identifier for bodies.
Definition: BodyID.hpp:30
2-D velocity related data structure.
Definition: Velocity.hpp:38
Real GetDampingRatio(const Joint &object)
Gets the given joint's damping ratio property if it has one.
Definition: Joint.cpp:389
2-D positional data structure.
Definition: Position.hpp:37
Vector.
Definition: Vector.hpp:49
constexpr auto & UseDampingRatio(NonNegative< Real > v) noexcept
Use value for damping ratio.
Definition: TargetJointConf.hpp:94
void InitVelocity(DistanceJointConf &object, std::vector< BodyConstraint > &bodies, const StepConf &step, const ConstraintSolverConf &)
Initializes velocity constraint data based on the given solver data.
Definition: DistanceJointConf.cpp:80
Target joint definition.
Definition: TargetJointConf.hpp:48
constexpr Momentum2 GetLinearReaction(const DistanceJointConf &object) noexcept
Gets the current linear reaction for the given configuration.
Definition: DistanceJointConf.hpp:163
constexpr d2::AABB GetInvalid() noexcept
Gets an invalid AABB value.
Definition: AABB.hpp:484
PLAYRHO_QUANTITY(playrho::units::si::inverse_mass) InvMass
Inverse mass quantity.
Definition: Units.hpp:191
constexpr auto & UseTarget(Length2 v) noexcept
Use value for target.
Definition: TargetJointConf.hpp:62
A joint-like constraint on one or more bodies.
Definition: Joint.hpp:144
Vector2< Length > Length2
2-element vector of Length quantities.
Definition: Vector2.hpp:43