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::RevoluteJointConf
.
#include "UnitTests.hpp"
#include <PlayRho/Dynamics/Joints/RevoluteJointConf.hpp>
#include <PlayRho/Dynamics/Joints/Joint.hpp>
#include <PlayRho/Dynamics/World.hpp>
#include <PlayRho/Dynamics/WorldBody.hpp>
#include <PlayRho/Dynamics/WorldJoint.hpp>
#include <PlayRho/Dynamics/WorldMisc.hpp>
#include <PlayRho/Dynamics/WorldFixture.hpp>
#include <PlayRho/Dynamics/StepConf.hpp>
#include <PlayRho/Dynamics/BodyConf.hpp>
#include <PlayRho/Collision/Shapes/DiskShapeConf.hpp>
#include <PlayRho/Collision/Shapes/PolygonShapeConf.hpp>
#include <cstring>
{
case 4:
break;
case 8:
break;
case 16:
break;
default:
FAIL();
break;
}
}
TEST(RevoluteJoint, Construction)
{
jd.bodyB = b1;
jd.collideConnected = true;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
jd.enableLimit = true;
jd.enableMotor = true;
jd.maxMotorTorque = 1_Nm;
jd.lowerAngle = 33_deg;
jd.upperAngle = 40_deg;
jd.referenceAngle = 45_deg;
EXPECT_EQ(
GetType(joint), GetTypeID<RevoluteJointConf>());
}
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
}
TEST(RevoluteJoint, EnableMotorInWorld)
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
const auto newValue = 5_Nm;
stepConf.doWarmStart = false;
stepConf.doWarmStart = true;
stepConf.doWarmStart = true;
}
TEST(RevoluteJoint, MotorSpeed)
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
}
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
jd.enableLimit = false;
ASSERT_EQ(
GetLimitState(world, joint), LimitState::e_inactiveLimit);
EXPECT_EQ(
GetLimitState(world, joint), LimitState::e_inactiveLimit);
EXPECT_EQ(
GetLimitState(world, joint), LimitState::e_inactiveLimit);
}
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
const auto upperValue = +5_deg;
const auto lowerValue = -8_deg;
}
TEST(RevoluteJoint, MaxMotorTorque)
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
const auto newValue = 5_Nm;
stepConf.doWarmStart = false;
}
TEST(RevoluteJoint, MovesDynamicCircles)
{
const auto p1 =
Length2{-1_m, 0_m};
const auto p2 =
Length2{+1_m, 0_m};
.UseLocation(p1)
.UseLocation(p2)
jd.bodyB = b2;
}
TEST(RevoluteJoint, LimitEnabledDynamicCircles)
{
const auto p1 =
Length2{-1_m, 0_m};
const auto p2 =
Length2{+1_m, 0_m};
.UseLocation(p1)
.UseLocation(p2)
jd.enableLimit = true;
ASSERT_EQ(jd.lowerAngle, 0_deg);
ASSERT_EQ(jd.upperAngle, 0_deg);
ASSERT_EQ(
GetLimitState(world, joint), LimitState::e_inactiveLimit);
ASSERT_EQ(
GetAngle(world, joint), 0_deg);
EXPECT_EQ(
GetAngle(world, joint), 0_deg);
EXPECT_EQ(
GetLimitState(world, joint), LimitState::e_atLowerLimit);
EXPECT_EQ(
GetLimitState(world, joint), LimitState::e_atUpperLimit);
}
TEST(RevoluteJoint, DynamicJoinedToStaticStaysPut)
{
const auto p2 =
Length2{0_m, -2_m};
for (auto i = 0; i < 1000; ++i) {
}
for (auto i = 0; i < 10; ++i) {
}
}
{
conf.UseCollideConnected(true);
conf.referenceAngle = 20_deg;
conf.enableLimit = true;
conf.lowerAngle = 10_deg;
conf.upperAngle = 30_deg;
conf.enableMotor = true;
conf.motorSpeed = 3_rpm;
EXPECT_EQ(result.bodyA, conf.bodyA);
EXPECT_EQ(result.bodyB, conf.bodyB);
EXPECT_EQ(result.collideConnected, conf.collideConnected);
EXPECT_EQ(result.localAnchorA, conf.localAnchorA);
EXPECT_EQ(result.localAnchorB, conf.localAnchorB);
EXPECT_EQ(result.impulse, conf.impulse);
EXPECT_EQ(result.angularMotorImpulse, conf.angularMotorImpulse);
EXPECT_EQ(result.referenceAngle, conf.referenceAngle);
EXPECT_EQ(result.enableLimit, conf.enableLimit);
EXPECT_EQ(result.lowerAngle, conf.lowerAngle);
EXPECT_EQ(result.upperAngle, conf.upperAngle);
EXPECT_EQ(result.enableMotor, conf.enableMotor);
EXPECT_EQ(result.motorSpeed, conf.motorSpeed);
}
{
EXPECT_NO_THROW(angle =
GetAngle(world, conf));
EXPECT_EQ(angle, 0_deg);
}
{
EXPECT_EQ(angularVelocity, 0_rpm);
}
{
}
{
EXPECT_EQ(conf.angularMass, rotInertia);
}
{
}
{
}
{
}
{
}
{
}
{
}
{
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
}
{
{
EXPECT_FALSE(conf != conf);
}
}
{
EXPECT_STREQ(
GetName(GetTypeID<RevoluteJointConf>()),
"d2::RevoluteJointConf");
}
@ Static
Static body type.
constexpr auto RadianPerSquareSecond
Radian per square second unit of angular acceleration.
Definition: Units.hpp:394
constexpr auto MeterPerSquareSecond
Meter per square second unit of linear acceleration.
Definition: Units.hpp:345
constexpr BodyConf & UseType(BodyType t) noexcept
Use the given type.
Definition: BodyConf.hpp:166
BodyID CreateBody(const BodyConf &def=GetDefaultBodyConf())
Creates a rigid body with the given configuration.
Definition: World.cpp:161
PolygonShapeConf & SetAsBox(Length hx, Length hy) noexcept
Sets the vertices to represent an axis-aligned box centered on the local origin.
Definition: PolygonShapeConf.cpp:42
PLAYRHO_QUANTITY(boost::units::si::torque) Torque
Torque quantity.
Definition: Units.hpp:255
Name space for 2-dimensionally related PlayRho names.
Definition: AABB.cpp:34
BodyID bodyA
1st attached body.
Definition: JointConf.hpp:36
UnitVec GetLocalYAxisA(const Joint &object)
Gets the given joint's local Y axis A if its type supports that.
Definition: Joint.cpp:242
bool IsLimitEnabled(const Joint &object)
Gets the specified joint's limit property if it supports one.
Definition: Joint.cpp:534
constexpr auto InvalidJointID
Invalid joint ID value.
Definition: JointID.hpp:33
Angle GetAngularUpperLimit(const Joint &object)
Gets the upper joint limit.
Definition: Joint.cpp:515
AngularMomentum GetAngularMotorImpulse(const Joint &object)
Gets the angular motor impulse of the joint if it has this property.
Definition: Joint.cpp:447
bool IsAwake(const Body &body) noexcept
Gets the awake/asleep state of this body.
Definition: Body.hpp:808
Time deltaTime
Delta time.
Definition: StepConf.hpp:53
const char * GetName(Manifold::Type type) noexcept
Gets a unique name for the given manifold type.
Definition: Manifold.cpp:788
constexpr ConcreteConf & UseDensity(NonNegative< AreaDensity > value) noexcept
Uses the given density.
Definition: ShapeConf.hpp:111
constexpr auto & GetX(T &value)
Gets the "X" element of the given value - i.e. the first element.
Definition: Math.hpp:66
Name space for all PlayRho related names.
Definition: AABB.cpp:33
void SetMaxMotorTorque(Joint &object, Torque value)
Sets the given joint's max motor torque if its type supports that.
Definition: Joint.cpp:363
AngularVelocity GetAngularVelocity(const Body &body) noexcept
Gets the angular velocity.
Definition: Body.hpp:1178
Length2 GetLocalAnchorA(const Joint &object)
Get the anchor point on body-A in local coordinates.
Definition: Joint.cpp:62
constexpr auto RadianPerSecond
Radian per second unit of angular velocity.
Definition: Units.hpp:384
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
constexpr auto NewtonMeterSecond
Newton meter second unit of angular momentum.
Definition: Units.hpp:418
Length2 localAnchorA
Local anchor point relative to body A's origin.
Definition: RevoluteJointConf.hpp:118
InvRotInertia GetInvRotInertia(const Body &body) noexcept
Gets the inverse rotational inertia of the body.
Definition: Body.hpp:979
constexpr auto NewtonMeter
Newton meter unit of torque.
Definition: Units.hpp:408
void EnableMotor(Joint &object, bool value)
Enables the specified joint's motor property if it supports one.
Definition: Joint.cpp:575
constexpr bool ShiftOrigin(DistanceJointConf &, Length2) noexcept
Shifts the origin notion of the given configuration.
Definition: DistanceJointConf.hpp:177
Torque GetMotorTorque(const Joint &joint, Frequency inv_dt)
Gets the current motor torque for the given joint given the inverse time step.
Definition: Joint.hpp:791
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
void UnsetAwake(Body &body) noexcept
Sets this body to asleep if sleeping is allowed.
Definition: Body.hpp:837
Angle GetReferenceAngle(const Joint &object)
Gets the reference angle of the joint if it has one.
Definition: Joint.cpp:215
bool IsEnabled(const Body &body) noexcept
Gets the enabled/disabled state of the body.
Definition: Body.hpp:771
LimitState GetLimitState(const Joint &object)
Definition: Joint.cpp:631
Polygon shape configuration.
Definition: PolygonShapeConf.hpp:42
bool IsMotorEnabled(const Joint &object)
Gets the specified joint's motor property value if it supports one.
Definition: Joint.cpp:560
constexpr auto Meter
Meter unit of Length.
Definition: Units.hpp:337
Length GetLinearUpperLimit(const Joint &object)
Gets the upper linear joint limit.
Definition: Joint.cpp:487
UnitVec GetLocalXAxisA(const Joint &object)
Gets the given joint's local X axis A if its type supports that.
Definition: Joint.cpp:230
Torque GetMaxMotorTorque(const Joint &object)
Gets the given joint's max motor torque if its type supports that.
Definition: Joint.cpp:351
JointID CreateJoint(WorldImpl &world, const Joint &def)
Creates a new joint.
Definition: WorldImplJoint.cpp:47
Momentum GetLinearMotorImpulse(const Joint &object)
Definition: Joint.cpp:664
void Destroy(World &world, BodyID id)
Destroys the identified body.
Definition: WorldBody.cpp:73
Angle GetAngularLowerLimit(const Joint &object)
Gets the lower joint limit.
Definition: Joint.cpp:506
Length2 localAnchorB
Local anchor point relative to body B's origin.
Definition: RevoluteJointConf.hpp:121
Length2 GetLocalAnchorB(const Joint &object)
Get the anchor point on body-B in local coordinates.
Definition: Joint.cpp:96
Angle GetAngle(const UnitVec value)
Gets the angle of the given unit vector.
Definition: Math.hpp:718
bool enableMotor
Flag to enable the joint motor.
Definition: RevoluteJointConf.hpp:146
PLAYRHO_QUANTITY(boost::units::si::angular_momentum) AngularMomentum
Angular momentum quantity.
Definition: Units.hpp:304
Step configuration.
Definition: StepConf.hpp:42
AngularVelocity GetMotorSpeed(const Joint &object)
Gets the given joint's motor speed if its type supports that.
Definition: Joint.cpp:254
constexpr auto EarthlyGravity
Earthly gravity in 2-dimensions.
Definition: Vector2.hpp:154
void SetAngularLimits(Joint &object, Angle lower, Angle upper)
Sets the joint limits.
Definition: Joint.cpp:524
RotInertia GetAngularMass(const Joint &object)
Gets the given joint's angular mass.
Definition: Joint.cpp:287
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
FixtureID CreateFixture(World &world, FixtureConf def, bool resetMassData)
Creates a fixture within the specified world.
Definition: WorldFixture.cpp:48
float Real
Real-number type.
Definition: Real.hpp:69
constexpr DiskShapeConf & UseRadius(NonNegative< Length > r) noexcept
Uses the given value as the radius.
Definition: DiskShapeConf.hpp:65
Force GetMaxMotorForce(const Joint &object)
Gets the given joint's max motor force if its type supports that.
Definition: Joint.cpp:332
Configuration for a body.
Definition: BodyConf.hpp:50
constexpr Length2 GetLocation(const Transformation &value) noexcept
Gets the location information from the given transformation.
Definition: Transformation.hpp:69
detail::IndexingNamedType< BodyCounter, struct BodyIdentifier > BodyID
Identifier for bodies.
Definition: BodyID.hpp:30
2-D velocity related data structure.
Definition: Velocity.hpp:38
constexpr auto SquareRadian
Square radian unit type.
Definition: Units.hpp:379
void SetMotorSpeed(Joint &object, AngularVelocity value)
Sets the given joint's motor speed if its type supports that.
Definition: Joint.cpp:269
Vector.
Definition: Vector.hpp:49
Length2 GetAnchorA(const World &world, JointID id)
Get the anchor point on body-A in world coordinates.
Definition: WorldJoint.cpp:208
void SetAwake(Body &body) noexcept
Awakens this body.
Definition: Body.hpp:822
TypeID GetType(const Shape &shape) noexcept
Gets the type info of the use of the given shape.
Definition: Shape.hpp:329
constexpr Momentum2 GetLinearReaction(const DistanceJointConf &object) noexcept
Gets the current linear reaction for the given configuration.
Definition: DistanceJointConf.hpp:163
PLAYRHO_QUANTITY(boost::units::si::moment_of_inertia) RotInertia
Rotational inertia quantity.
Definition: Units.hpp:274
2-D acceleration related data structure.
Definition: Acceleration.hpp:33
RevoluteJointConf GetRevoluteJointConf(const Joint &joint)
Gets the definition data for the given joint.
Definition: RevoluteJointConf.cpp:102
RotInertia angularMass
Effective mass for motor/limit angular constraint.
Definition: RevoluteJointConf.hpp:157
A joint-like constraint on one or more bodies.
Definition: Joint.hpp:144
Shape.
Definition: Shape.hpp:183
constexpr auto & GetY(T &value)
Gets the "Y" element of the given value - i.e. the second element.
Definition: Math.hpp:73
PLAYRHO_QUANTITY(boost::units::si::plane_angle) Angle
Angle quantity.
Definition: Units.hpp:215
Vector2< Length > Length2
2-element vector of Length quantities.
Definition: Vector2.hpp:43
BodyCounter GetWorldIndex(const World &world, BodyID id) noexcept
Gets the world index for the given body.
Definition: WorldBody.cpp:202
void SetAccelerations(World &world, Acceleration acceleration) noexcept
Sets the accelerations of all the world's bodies to the given value.
Definition: WorldBody.cpp:558
Angle referenceAngle
Reference angle.
Definition: RevoluteJointConf.hpp:134
StepStats Step(WorldImpl &world, const StepConf &conf)
Steps the given world the specified amount.
Definition: WorldImplMisc.cpp:85
Length GetLinearLowerLimit(const Joint &object)
Gets the lower linear joint limit.
Definition: Joint.cpp:478
void EnableLimit(Joint &object, bool value)
Enables the specified joint's limit property if it supports one.
Definition: Joint.cpp:546
Velocity GetVelocity(const Body &body, Time h) noexcept
Gets the velocity of the body after the given time accounting for the body's acceleration and capped ...
Definition: Body.cpp:221
Revolute joint definition.
Definition: RevoluteJointConf.hpp:64
@ e_inactiveLimit
Inactive limit.
PLAYRHO_QUANTITY(boost::units::si::angular_velocity) AngularVelocity
Angular velocity quantity.
Definition: Units.hpp:225
Disk shape configuration.
Definition: DiskShapeConf.hpp:42