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

#include <CURevoluteJoint.h>

Inheritance diagram for cugl::physics2::RevoluteJoint:
cugl::physics2::Joint

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 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 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< RevoluteJointalloc ()
 
static std::shared_ptr< RevoluteJointallocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB)
 
static std::shared_ptr< RevoluteJointallocWithObstacles (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
 

Detailed Description

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:

  1. you might not know where the center of mass will be.
  2. if you add/remove shapes from a body and recompute the mass, the joints will be broken.

Constructor & Destructor Documentation

◆ RevoluteJoint()

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

Member Function Documentation

◆ activatePhysics()

virtual bool cugl::physics2::RevoluteJoint::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< RevoluteJoint > cugl::physics2::RevoluteJoint::alloc ( )
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.

Returns
a newly allocated revolute joint with default values.

◆ allocWithObstacles() [1/2]

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

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

◆ allocWithObstacles() [2/2]

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

Returns a newly allocated revolute 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 revolute joint with the given obstacles and anchors

◆ enableLimit()

void cugl::physics2::RevoluteJoint::enableLimit ( bool  value)
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.

Parameters
valueWhether to enable the joint limit

◆ enableMotor()

void cugl::physics2::RevoluteJoint::enableMotor ( bool  value)
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.

Parameters
valueWhether to enable the joint motor

◆ getLocalAnchorA()

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

◆ getLowerAngle()

float cugl::physics2::RevoluteJoint::getLowerAngle ( ) const
inline

Returns the lower angle limit in radians.

Returns
the lower angle limit.

◆ getMaxMotorTorque()

float cugl::physics2::RevoluteJoint::getMaxMotorTorque ( ) const
inline

Returns the maximum motor torque to achiece the desired speed.

This value is usually measured in N-m.

Returns
the maximum motor torque.

◆ getMotorSpeed()

float cugl::physics2::RevoluteJoint::getMotorSpeed ( ) const
inline

Returns the desired motor speed in radians per second.

Returns
the desired motor speed in radians per second.

◆ getReferenceAngle()

float cugl::physics2::RevoluteJoint::getReferenceAngle ( ) const
inline

Returns the initial constrained angle between the bodies.

This value is measured bodyB - bodyA in radians.

Returns
the initial constrained angle between the bodies.

◆ getUpperAngle()

float cugl::physics2::RevoluteJoint::getUpperAngle ( ) const
inline

Returns the upper angle limit in radians.

Returns
the upper angle limit.

◆ hasLimit()

bool cugl::physics2::RevoluteJoint::hasLimit ( ) const
inline

Returns true if the joint limit is enabled.

Returns
true if the joint limit is enabled.

◆ hasMotor()

bool cugl::physics2::RevoluteJoint::hasMotor ( ) const
inline

Returns true if the joint motor is enabled.

Returns
true if the joint motor is enabled.

◆ initWithObstacles() [1/2]

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

Initializes a new revolute 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::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.

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.

◆ setLocalAnchorA() [1/2]

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

◆ setLowerAngle()

void cugl::physics2::RevoluteJoint::setLowerAngle ( float  value)
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.

Parameters
valuethe lower angle limit.

◆ setMaxMotorTorque()

void cugl::physics2::RevoluteJoint::setMaxMotorTorque ( float  value)
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.

Parameters
valuethe maximum motor torque

◆ setMotorSpeed()

void cugl::physics2::RevoluteJoint::setMotorSpeed ( float  value)
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.

Parameters
valuethe desired motor speed

◆ setReferenceAngle()

void cugl::physics2::RevoluteJoint::setReferenceAngle ( float  value)
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.

Parameters
valuethe initial constrained angle

◆ setUpperAngle()

void cugl::physics2::RevoluteJoint::setUpperAngle ( float  value)
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.

Parameters
valuethe upper angle limit.

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