CUGL 2.5
Cornell University Game Library
|
#include <CUGearJoint.h>
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< GearJoint > | alloc () |
static std::shared_ptr< GearJoint > | allocWithJoints (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 |
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.
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).
|
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 gear joint with default values.
The joint will not have any associated prismatic/revolute joints and so attempting to activate it will fail.
|
inlinestatic |
Returns a newly allocated gear joint with the given prismatic/revolute joints.
All other attributes will be at their default values.
joint1 | The first prismatic/revolute joint to use |
joint2 | The second prismatic/revolute joint to use |
|
inline |
Returns the first prismatic/revolute joint
|
inline |
Returns the second prismatic/revolute joint
|
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.
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.
joint1 | The first prismatic/revolute joint to use |
joint2 | The second prismatic/revolute joint to use |
|
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.
value | the gear ratio |
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.
joint | the first prismatic/revolute joint |
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.
joint | the second prismatic/revolute joint |
|
protected |
The first revolute/prismatic joint attached to the gear joint.
|
protected |
The second revolute/prismatic joint attached to the gear joint.
|
protected |
The gear ratio.