CUGL 2.5
Cornell University Game Library
|
#include <CUDistanceJoint.h>
Public Member Functions | |
DistanceJoint () | |
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 | getLength () const |
void | setLength (float length) |
float | getMinLength () const |
void | setMinLength (float length) |
float | getMaxLength () const |
void | setMaxLength (float length) |
float | getStiffness () const |
void | setStiffness (float value) |
float | getDamping () const |
void | setDamping (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< DistanceJoint > | alloc () |
static std::shared_ptr< DistanceJoint > | allocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB) |
static std::shared_ptr< DistanceJoint > | allocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB, const Vec2 localA, const Vec2 localB) |
Protected Attributes | |
Vec2 | _localAnchorA |
Vec2 | _localAnchorB |
float | _length |
float | _minLength |
float | _maxLength |
float | _stiffness |
float | _damping |
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 distance joint class.
This class requires defining an anchor point on both bodies and the non-zero distance of the distance joint. The definition uses local anchor points so that the initial configuration can violate the constraint slightly. This helps when saving and loading a game.
cugl::physics2::DistanceJoint::DistanceJoint | ( | ) |
Creates a new distance 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 distance 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 distance 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 distance 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 |
Returns the linear damping in N*s/m.
|
inline |
Returns the rest length of this joint.
This value will be clamped to a stable minimum value.
|
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 maximum length of this joint.
This value must be greater than or equal to the minimum value.
|
inline |
Returns the minimum length of this joint.
This value will be clamped to a stable minimum value. It must be less than or equal to the maximum value.
|
inline |
Returns the linear stiffness in N/m.
|
overridevirtual |
Initializes a new distance 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::DistanceJoint::initWithObstacles | ( | const std::shared_ptr< Obstacle > & | obsA, |
const std::shared_ptr< Obstacle > & | obsB, | ||
const Vec2 | localA, | ||
const Vec2 | localB | ||
) |
Initializes a new distance 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 linear damping in N*s/m.
value | the linear damping |
|
inline |
Sets the rest length of this joint.
This value will be clamped to a stable minimum value.
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.
length | the rest length of this joint. |
|
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 maximum length of this joint.
This value must be greater than or equal to the minimum value.
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.
length | the minimum length of this joint. |
|
inline |
Sets the minimum length of this joint.
This value will be clamped to a stable minimum value. It must be less than or equal to the maximum value.
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.
length | the minimum length of this joint. |
|
inline |
Sets the linear stiffness in N/m.
value | the linear stiffness |
|
protected |
The linear damping in N*s/m.
|
protected |
The rest length of this joint. Clamped to a stable minimum value.
|
protected |
The local anchor point relative to obstacle A's origin.
|
protected |
The local anchor point relative to obstacle B's origin.
|
protected |
The maximum length. Must be greater than or equal to the minimum length.
|
protected |
The minimum length. Clamped to a stable minimum value.
|
protected |
The linear stiffness in N/m.