CUGL 2.5
Cornell University Game Library
|
#include <CURevoluteJoint.h>
Public Member Functions | |
RevoluteJoint () | |
bool | initWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB) override |
bool | initWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB, const Vec2 localA, const Vec2 localB) |
const Vec2 & | getLocalAnchorA () const |
void | setLocalAnchorA (const Vec2 point) |
void | setLocalAnchorA (float x, float y) |
const Vec2 & | getLocalAnchorB () const |
void | setLocalAnchorB (const Vec2 point) |
void | setLocalAnchorB (float x, float y) |
float | getReferenceAngle () const |
void | setReferenceAngle (float value) |
bool | hasLimit () const |
void | enableLimit (bool value) |
bool | hasMotor () const |
void | enableMotor (bool value) |
float | getLowerAngle () const |
void | setLowerAngle (float value) |
float | getUpperAngle () const |
void | setUpperAngle (float value) |
float | getMaxMotorTorque () const |
void | setMaxMotorTorque (float value) |
float | getMotorSpeed () const |
void | setMotorSpeed (float value) |
virtual bool | activatePhysics (b2World &world) override |
Public Member Functions inherited from cugl::physics2::Joint | |
Joint () | |
virtual | ~Joint () |
bool | init () |
virtual bool | initWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB) |
b2JointType | getType () const |
void | setObstacleA (const std::shared_ptr< Obstacle > &obs) |
std::shared_ptr< Obstacle > & | getObstacleA () |
void | setObstacleB (const std::shared_ptr< Obstacle > &obs) |
std::shared_ptr< Obstacle > & | getObstacleB () |
bool | getCollideConnected () |
void | setCollideConnected (bool flag) |
void | release () |
bool | isRemoved () const |
void | markRemoved (bool value) |
bool | isDirty () const |
void | markDirty (bool value) |
b2Joint * | getJoint () |
virtual bool | activatePhysics (b2World &world) |
void | deactivatePhysics (b2World &world) |
Static Public Member Functions | |
static std::shared_ptr< RevoluteJoint > | alloc () |
static std::shared_ptr< RevoluteJoint > | allocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB) |
static std::shared_ptr< RevoluteJoint > | allocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB, const Vec2 localA, const Vec2 localB) |
Additional Inherited Members | |
Protected Attributes inherited from cugl::physics2::Joint | |
b2Joint * | _joint |
b2JointType | _type |
std::shared_ptr< Obstacle > | _bodyA |
std::shared_ptr< Obstacle > | _bodyB |
bool | _collideConnected |
bool | _remove |
Track garbage collection status. | |
bool | _dirty |
The revolute joint class.
This joint requires defining an anchor point where the bodies are joined. The definition uses local anchor points so that the initial configuration can violate the constraint slightly. You also need to specify the initial relative angle for joint limits. This helps when saving and loading a game.
The local anchor points are measured from the body's origin rather than the center of mass because:
cugl::physics2::RevoluteJoint::RevoluteJoint | ( | ) |
Creates a new revolute joint with no obstacles
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead (in this case, in one of the subclasses).
|
overridevirtual |
Creates the Box2d joint, adding it to the world.
Calling this method activates the physics of the associated obstacles, if necessary.
Implementations of this method should NOT retain ownership of the Box2D world. That is a tight coupling that we should avoid.
world | Box2D world to store the joint |
Reimplemented from cugl::physics2::Joint.
|
inlinestatic |
Returns a newly allocated revolute joint with default values.
The joint will not have any associated obstacles and so attempting to activate it will fail.
|
inlinestatic |
Returns a newly allocated revolute joint with the given obstacles.
All other attributes will be at their default values.
obsA | The first obstacle to join |
obsB | The second obstacle to join |
|
inlinestatic |
Returns a newly allocated revolute joint with the given obstacles and anchors
All other attributes will be at their default values.
obsA | The first obstacle to join |
obsB | The second obstacle to join |
localA | The local anchor of the first obstacle |
localB | The local anchor of the second obstacle |
|
inline |
Enables/disables the joint limit.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
value | Whether to enable the joint limit |
|
inline |
Enables/disables the joint motor.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
value | Whether to enable the joint motor |
|
inline |
Returns the local anchor point relative to obstacle A's origin.
|
inline |
Returns the local anchor point relative to obstacle B's origin.
|
inline |
Returns the lower angle limit in radians.
|
inline |
Returns the maximum motor torque to achiece the desired speed.
This value is usually measured in N-m.
|
inline |
Returns the desired motor speed in radians per second.
|
inline |
Returns the initial constrained angle between the bodies.
This value is measured bodyB - bodyA in radians.
|
inline |
Returns the upper angle limit in radians.
|
inline |
Returns true if the joint limit is enabled.
|
inline |
Returns true if the joint motor is enabled.
|
overridevirtual |
Initializes a new revolute joint with the given obstacles.
All other attributes will be at their default values.
obsA | The first obstacle to join |
obsB | The second obstacle to join |
Reimplemented from cugl::physics2::Joint.
bool cugl::physics2::RevoluteJoint::initWithObstacles | ( | const std::shared_ptr< Obstacle > & | obsA, |
const std::shared_ptr< Obstacle > & | obsB, | ||
const Vec2 | localA, | ||
const Vec2 | localB | ||
) |
Initializes a new revolute joint with the given obstacles and anchors
All other attributes will be at their default values.
obsA | The first obstacle to join |
obsB | The second obstacle to join |
localA | The local anchor of the first obstacle |
localB | The local anchor of the second obstacle |
|
inline |
Sets the local anchor point relative to obstacle A's origin.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
point | the local anchor point |
|
inline |
Sets the local anchor point relative to obstacle A's origin.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
x | the x-coordinate of the local anchor point |
y | the y-coordinate of the local anchor point |
|
inline |
Sets the local anchor point relative to obstacle B's origin.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
point | the local anchor point |
|
inline |
Sets the local anchor point relative to obstacle B's origin.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
x | the x-coordinate of the local anchor point |
y | the y-coordinate of the local anchor point |
|
inline |
Sets the lower angle limit in radians.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
value | the lower angle limit. |
|
inline |
Sets the maximum motor torqueto achiece the desired speed.
This value is usually measured in N-m.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
value | the maximum motor torque |
|
inline |
Sets the desired motor speed in radians per second.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
value | the desired motor speed |
|
inline |
Sets the initial constrained angle between the bodies.
This value is measured bodyB - bodyA in radians.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
value | the initial constrained angle |
|
inline |
Sets the upper angle limit in radians.
If this method is called while the joint is active, then the joint will be marked as dirty. It will need to be deactivated and reactivated to work properly.
value | the upper angle limit. |