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::GearJoint Class Reference

#include <CUGearJoint.h>

Inheritance diagram for cugl::physics2::GearJoint:
cugl::physics2::Joint

Public Member Functions

 GearJoint ()
 
bool initWithJoints (const std::shared_ptr< Joint > &joint1, const std::shared_ptr< Joint > &joint2)
 
const std::shared_ptr< Joint > & getJoint1 () const
 
void setJoint1 (const std::shared_ptr< Joint > &joint)
 
const std::shared_ptr< Joint > & getJoint2 () const
 
void setJoint2 (const std::shared_ptr< Joint > &joint)
 
float getRatio () const
 
void setGearRatio (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< GearJointalloc ()
 
static std::shared_ptr< GearJointallocWithJoints (const std::shared_ptr< Joint > &joint1, const std::shared_ptr< Joint > &joint2)
 

Protected Attributes

std::shared_ptr< Joint_joint1
 
std::shared_ptr< Joint_joint2
 
float _ratio
 
- 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 gear joint class.

This definition requires two existing revolute or prismatic joints (any combination will work). The second body on the input joints must both be dynamic.

You specify a gear ratio to bind the motions together:

 coordinate1 + ratio * coordinate2 = constant

The ratio can be negative or positive. If one joint is a revolute joint and the other joint is a prismatic joint, then the ratio will have units of length or units of 1/length.

WARNING: You have to manually destroy the gear joint if joint1 or joint2 is destroyed.

Constructor & Destructor Documentation

◆ GearJoint()

cugl::physics2::GearJoint::GearJoint ( )

Creates a new gear joint with no joints

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::GearJoint::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< GearJoint > cugl::physics2::GearJoint::alloc ( )
inlinestatic

Returns a newly allocated gear joint with default values.

The joint will not have any associated prismatic/revolute joints and so attempting to activate it will fail.

Returns
a newly allocated gear joint with default values.

◆ allocWithJoints()

static std::shared_ptr< GearJoint > cugl::physics2::GearJoint::allocWithJoints ( const std::shared_ptr< Joint > &  joint1,
const std::shared_ptr< Joint > &  joint2 
)
inlinestatic

Returns a newly allocated gear joint with the given prismatic/revolute joints.

All other attributes will be at their default values.

Parameters
joint1The first prismatic/revolute joint to use
joint2The second prismatic/revolute joint to use
Returns
a newly allocated gear joint with the given prismatic/revolute joints.

◆ getJoint1()

const std::shared_ptr< Joint > & cugl::physics2::GearJoint::getJoint1 ( ) const
inline

Returns the first prismatic/revolute joint

Returns
the first prismatic/revolute joint

◆ getJoint2()

const std::shared_ptr< Joint > & cugl::physics2::GearJoint::getJoint2 ( ) const
inline

Returns the second prismatic/revolute joint

Returns
the second prismatic/revolute joint

◆ getRatio()

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

Returns the gear ratio.

You specify a gear ratio to bind the motions together:

 coordinate1 + ratio * coordinate2 = constant

The ratio can be negative or positive. If one joint is a revolute joint and the other joint is a prismatic joint, then the ratio will have units of length or units of 1/length.

Returns
the gear ratio.

◆ initWithJoints()

bool cugl::physics2::GearJoint::initWithJoints ( const std::shared_ptr< Joint > &  joint1,
const std::shared_ptr< Joint > &  joint2 
)

Initializes a new gear joint with the given prismatic/revolute joints.

All other attributes will be at their default values.

Parameters
joint1The first prismatic/revolute joint to use
joint2The second prismatic/revolute joint to use
Returns
true if the obstacle is initialized properly, false otherwise.

◆ setGearRatio()

void cugl::physics2::GearJoint::setGearRatio ( float  value)
inline

Sets the gear ratio.

You specify a gear ratio to bind the motions together:

 coordinate1 + ratio * coordinate2 = constant

The ratio can be negative or positive. If one joint is a revolute joint and the other joint is a prismatic joint, then the ratio will have units of length or units of 1/length.

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 gear ratio

◆ setJoint1()

void cugl::physics2::GearJoint::setJoint1 ( const std::shared_ptr< Joint > &  joint)

Sets the first prismatic/revolute joint

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
jointthe first prismatic/revolute joint

◆ setJoint2()

void cugl::physics2::GearJoint::setJoint2 ( const std::shared_ptr< Joint > &  joint)

Sets the second prismatic/revolute joint

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
jointthe second prismatic/revolute joint

Member Data Documentation

◆ _joint1

std::shared_ptr<Joint> cugl::physics2::GearJoint::_joint1
protected

The first revolute/prismatic joint attached to the gear joint.

◆ _joint2

std::shared_ptr<Joint> cugl::physics2::GearJoint::_joint2
protected

The second revolute/prismatic joint attached to the gear joint.

◆ _ratio

float cugl::physics2::GearJoint::_ratio
protected

The gear ratio.


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