CUGL 2.5
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::physics2::DistanceJoint Class Reference

#include <CUDistanceJoint.h>

Inheritance diagram for cugl::physics2::DistanceJoint:
cugl::physics2::Joint

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 Vec2getLocalAnchorA () const
 
void setLocalAnchorA (const Vec2 point)
 
void setLocalAnchorA (float x, float y)
 
const Vec2getLocalAnchorB () 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< DistanceJointalloc ()
 
static std::shared_ptr< DistanceJointallocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB)
 
static std::shared_ptr< DistanceJointallocWithObstacles (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DistanceJoint()

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).

Member Function Documentation

◆ activatePhysics()

virtual bool cugl::physics2::DistanceJoint::activatePhysics ( b2World &  world)
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.

Parameters
worldBox2D world to store the joint
Returns
true if object allocation succeeded

Reimplemented from cugl::physics2::Joint.

◆ alloc()

static std::shared_ptr< DistanceJoint > cugl::physics2::DistanceJoint::alloc ( )
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.

Returns
a newly allocated distance joint with default values.

◆ allocWithObstacles() [1/2]

static std::shared_ptr< DistanceJoint > cugl::physics2::DistanceJoint::allocWithObstacles ( const std::shared_ptr< Obstacle > &  obsA,
const std::shared_ptr< Obstacle > &  obsB 
)
inlinestatic

Returns a newly allocated distance joint with the given obstacles.

All other attributes will be at their default values.

Parameters
obsAThe first obstacle to join
obsBThe second obstacle to join
Returns
a newly allocated distance joint with the given obstacles.

◆ allocWithObstacles() [2/2]

static std::shared_ptr< DistanceJoint > cugl::physics2::DistanceJoint::allocWithObstacles ( const std::shared_ptr< Obstacle > &  obsA,
const std::shared_ptr< Obstacle > &  obsB,
const Vec2  localA,
const Vec2  localB 
)
inlinestatic

Returns a newly allocated distance joint with the given obstacles and anchors

All other attributes will be at their default values.

Parameters
obsAThe first obstacle to join
obsBThe second obstacle to join
localAThe local anchor of the first obstacle
localBThe local anchor of the second obstacle
Returns
a newly allocated distance joint with the given obstacles and anchors

◆ getDamping()

float cugl::physics2::DistanceJoint::getDamping ( ) const
inline

Returns the linear damping in N*s/m.

Returns
the linear damping in N*s/m.

◆ getLength()

float cugl::physics2::DistanceJoint::getLength ( ) const
inline

Returns the rest length of this joint.

This value will be clamped to a stable minimum value.

Returns
the rest length of this joint.

◆ getLocalAnchorA()

const Vec2 & cugl::physics2::DistanceJoint::getLocalAnchorA ( ) const
inline

Returns the local anchor point relative to obstacle A's origin.

Returns
the local anchor point relative to obstacle A's origin.

◆ getLocalAnchorB()

const Vec2 & cugl::physics2::DistanceJoint::getLocalAnchorB ( ) const
inline

Returns the local anchor point relative to obstacle B's origin.

Returns
the local anchor point relative to obstacle B's origin.

◆ getMaxLength()

float cugl::physics2::DistanceJoint::getMaxLength ( ) const
inline

Returns the maximum length of this joint.

This value must be greater than or equal to the minimum value.

Returns
the minimum length of this joint.

◆ getMinLength()

float cugl::physics2::DistanceJoint::getMinLength ( ) const
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.

Returns
the minimum length of this joint.

◆ getStiffness()

float cugl::physics2::DistanceJoint::getStiffness ( ) const
inline

Returns the linear stiffness in N/m.

Returns
the linear stiffness in N/m.

◆ initWithObstacles() [1/2]

bool cugl::physics2::DistanceJoint::initWithObstacles ( const std::shared_ptr< Obstacle > &  obsA,
const std::shared_ptr< Obstacle > &  obsB 
)
overridevirtual

Initializes a new distance joint with the given obstacles.

All other attributes will be at their default values.

Parameters
obsAThe first obstacle to join
obsBThe second obstacle to join
Returns
true if the obstacle is initialized properly, false otherwise.

Reimplemented from cugl::physics2::Joint.

◆ initWithObstacles() [2/2]

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.

Parameters
obsAThe first obstacle to join
obsBThe second obstacle to join
localAThe local anchor of the first obstacle
localBThe local anchor of the second obstacle
Returns
true if the obstacle is initialized properly, false otherwise.

◆ setDamping()

void cugl::physics2::DistanceJoint::setDamping ( float  value)
inline

Sets the linear damping in N*s/m.

Parameters
valuethe linear damping

◆ setLength()

void cugl::physics2::DistanceJoint::setLength ( float  length)
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.

Parameters
lengththe rest length of this joint.

◆ setLocalAnchorA() [1/2]

void cugl::physics2::DistanceJoint::setLocalAnchorA ( const Vec2  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.

Parameters
pointthe local anchor point

◆ setLocalAnchorA() [2/2]

void cugl::physics2::DistanceJoint::setLocalAnchorA ( float  x,
float  y 
)
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.

Parameters
xthe x-coordinate of the local anchor point
ythe y-coordinate of the local anchor point

◆ setLocalAnchorB() [1/2]

void cugl::physics2::DistanceJoint::setLocalAnchorB ( const Vec2  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.

Parameters
pointthe local anchor point

◆ setLocalAnchorB() [2/2]

void cugl::physics2::DistanceJoint::setLocalAnchorB ( float  x,
float  y 
)
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.

Parameters
xthe x-coordinate of the local anchor point
ythe y-coordinate of the local anchor point

◆ setMaxLength()

void cugl::physics2::DistanceJoint::setMaxLength ( float  length)
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.

Parameters
lengththe minimum length of this joint.

◆ setMinLength()

void cugl::physics2::DistanceJoint::setMinLength ( float  length)
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.

Parameters
lengththe minimum length of this joint.

◆ setStiffness()

void cugl::physics2::DistanceJoint::setStiffness ( float  value)
inline

Sets the linear stiffness in N/m.

Parameters
valuethe linear stiffness

Member Data Documentation

◆ _damping

float cugl::physics2::DistanceJoint::_damping
protected

The linear damping in N*s/m.

◆ _length

float cugl::physics2::DistanceJoint::_length
protected

The rest length of this joint. Clamped to a stable minimum value.

◆ _localAnchorA

Vec2 cugl::physics2::DistanceJoint::_localAnchorA
protected

The local anchor point relative to obstacle A's origin.

◆ _localAnchorB

Vec2 cugl::physics2::DistanceJoint::_localAnchorB
protected

The local anchor point relative to obstacle B's origin.

◆ _maxLength

float cugl::physics2::DistanceJoint::_maxLength
protected

The maximum length. Must be greater than or equal to the minimum length.

◆ _minLength

float cugl::physics2::DistanceJoint::_minLength
protected

The minimum length. Clamped to a stable minimum value.

◆ _stiffness

float cugl::physics2::DistanceJoint::_stiffness
protected

The linear stiffness in N/m.


The documentation for this class was generated from the following file: