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

#include <CUPulleyJoint.h>

Inheritance diagram for cugl::physics2::PulleyJoint:
cugl::physics2::Joint

Public Member Functions

 PulleyJoint ()
 
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 groundA, const Vec2 groundB)
 
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)
 
const Vec2getGroundAnchorA () const
 
void setGroundAnchorA (const Vec2 point)
 
void setGroundAnchorA (float x, float y)
 
const Vec2getGroundAnchorB () const
 
void setGroundAnchorB (const Vec2 point)
 
void setGroundAnchorB (float x, float y)
 
float getLengthA () const
 
void setLengthA (float value)
 
float getLengthB () const
 
void setLengthB (float value)
 
float getRatio () const
 
void setRatio (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< PulleyJointalloc ()
 
static std::shared_ptr< PulleyJointallocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB)
 
static std::shared_ptr< PulleyJointallocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB, const Vec2 groundA, const Vec2 groundB)
 

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
 

Detailed Description

The pulley joint class.

This class requires two ground anchors, two dynamic body anchor points, and a pulley ratio.

Constructor & Destructor Documentation

◆ PulleyJoint()

cugl::physics2::PulleyJoint::PulleyJoint ( )

Creates a new pulley 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::PulleyJoint::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< PulleyJoint > cugl::physics2::PulleyJoint::alloc ( )
inlinestatic

Returns a newly allocated pulley joint with default values.

The joint will not have any associated obstacles and so attempting to activate it will fail.

Returns
a newly allocated pulley joint with default values.

◆ allocWithObstacles() [1/2]

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

Returns a newly allocated pulley 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 pulley joint with the given obstacles.

◆ allocWithObstacles() [2/2]

static std::shared_ptr< PulleyJoint > cugl::physics2::PulleyJoint::allocWithObstacles ( const std::shared_ptr< Obstacle > &  obsA,
const std::shared_ptr< Obstacle > &  obsB,
const Vec2  groundA,
const Vec2  groundB 
)
inlinestatic

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

The ground anchors are specified in world coordinate, not local coordinates. All other attributes will be at their default values.

Parameters
obsAThe first obstacle to join
obsBThe second obstacle to join
groundAThe ground anchor of the first obstacle
groundBThe ground anchor of the second obstacle
Returns
a newly allocated pulley joint with the given obstacles and anchors

◆ getGroundAnchorA()

const Vec2 & cugl::physics2::PulleyJoint::getGroundAnchorA ( ) const
inline

Returns the ground anchor point for obstacle A's in world coordinate.

Returns
the ground anchor point for obstacle A's in world coordinate.

◆ getGroundAnchorB()

const Vec2 & cugl::physics2::PulleyJoint::getGroundAnchorB ( ) const
inline

Returns the ground anchor point for obstacle A's in world coordinate.

Returns
the ground anchor point for obstacle A's in world coordinate.

◆ getLengthA()

float cugl::physics2::PulleyJoint::getLengthA ( ) const
inline

Returns the reference length for the segment attached to bodyA.

Returns
the reference length for the segment attached to bodyA.

◆ getLengthB()

float cugl::physics2::PulleyJoint::getLengthB ( ) const
inline

Returns the reference length for the segment attached to bodyB.

Returns
the reference length for the segment attached to bodyB.

◆ getLocalAnchorA()

const Vec2 & cugl::physics2::PulleyJoint::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::PulleyJoint::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.

◆ getRatio()

float cugl::physics2::PulleyJoint::getRatio ( ) const
inline

Returns the pulley ratio.

This value is used to simulate a block-and-tackle.

Returns
the pulley ratio.

◆ initWithObstacles() [1/2]

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

Initializes a new pulley 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::PulleyJoint::initWithObstacles ( const std::shared_ptr< Obstacle > &  obsA,
const std::shared_ptr< Obstacle > &  obsB,
const Vec2  groundA,
const Vec2  groundB 
)

Initializes a new pulley joint with the given obstacles and anchors

The ground anchors are specified in world coordinate, not local coordinates. All other attributes will be at their default values.

Parameters
obsAThe first obstacle to join
obsBThe second obstacle to join
groundAThe ground anchor of the first obstacle
groundBThe ground anchor of the second obstacle
Returns
true if the obstacle is initialized properly, false otherwise.

◆ setGroundAnchorA() [1/2]

void cugl::physics2::PulleyJoint::setGroundAnchorA ( const Vec2  point)
inline

Sets the ground anchor point for obstacle A's in world coordinate.

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 ground anchor point

◆ setGroundAnchorA() [2/2]

void cugl::physics2::PulleyJoint::setGroundAnchorA ( float  x,
float  y 
)
inline

Sets the ground anchor point for obstacle A's in world coordinate.

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 ground anchor point
ythe y-coordinate of the ground anchor point

◆ setGroundAnchorB() [1/2]

void cugl::physics2::PulleyJoint::setGroundAnchorB ( const Vec2  point)
inline

Sets the ground anchor point for obstacle A's in world coordinate.

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 ground anchor point

◆ setGroundAnchorB() [2/2]

void cugl::physics2::PulleyJoint::setGroundAnchorB ( float  x,
float  y 
)
inline

Sets the ground anchor point for obstacle A's in world coordinate.

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 ground anchor point
ythe y-coordinate of the ground anchor point

◆ setLengthA()

void cugl::physics2::PulleyJoint::setLengthA ( float  value)
inline

Sets the reference length for the segment attached to bodyA.

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
valuethe reference length for the segment attached to bodyA.

◆ setLengthB()

void cugl::physics2::PulleyJoint::setLengthB ( float  value)
inline

Sets the reference length for the segment attached to bodyB.

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
valuethe reference length for the segment attached to bodyB.

◆ setLocalAnchorA() [1/2]

void cugl::physics2::PulleyJoint::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::PulleyJoint::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::PulleyJoint::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::PulleyJoint::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

◆ setRatio()

void cugl::physics2::PulleyJoint::setRatio ( float  value)
inline

Returns the pulley ratio.

This value is used to simulate a block-and-tackle.

Parameters
valuethe pulley ratio.

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