![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUJoint.h>
Public Member Functions | |
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) |
Protected Attributes | |
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 base joint class.
This is an extension of the Box2d b2Joint class to make it easier to use with the Obstacle
. Like that class, we combine the definition and the joint itself into a single class.
This class stores the base attributes for a joint, as well as the methods for managing physics and garbage collection. However, there is type information, and you should never instantiate objects of the class. Use one of the subclasses instead.
Many of the method comments in this class are taken from the Box2d manual by Erin Catto (2011).
cugl::physics2::Joint::Joint | ( | ) |
Creates a new physics 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).
|
virtual |
Deletes this physics joint and all of its resources.
We have to make the destructor public so that we can polymorphically delete physics objects. Note that we do not allow an joint to be deleted while physics is still active. Doing so will result in an error.
|
inlinevirtual |
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 in cugl::physics2::DistanceJoint, cugl::physics2::FrictionJoint, cugl::physics2::GearJoint, cugl::physics2::MotorJoint, cugl::physics2::MouseJoint, cugl::physics2::PrismaticJoint, cugl::physics2::PulleyJoint, cugl::physics2::RevoluteJoint, cugl::physics2::WeldJoint, and cugl::physics2::WheelJoint.
|
inline |
Destroys the Box2D joint if applicable.
This removes the joint from the Box2D world.
world | Box2D world that stores the joint |
|
inline |
Returns true if the attached bodies should collide.
|
inline |
Returns a (weak) reference to the Box2D joint
You use this joint to access Box2D primitives. As a weak reference, this physics obstacle does not transfer ownership of this body. In addition, the value may be a nullptr.
|
inline |
Returns the first obstacle attached to this joint.
|
inline |
Returns the second obstacle attached to this joint.
|
inline |
Returns the type of this joint
|
inline |
Initializes a new physics joint with no obstacles.
You should set the obstacles (and other attributes) before activating this joint.
|
virtual |
Initializes a new physics joint with the given obstacles.
All other attributes will be at their default values.
obsA | The first obstacle to join |
obsB | The second obstacle to join |
Reimplemented in cugl::physics2::DistanceJoint, cugl::physics2::FrictionJoint, cugl::physics2::PrismaticJoint, cugl::physics2::PulleyJoint, cugl::physics2::RevoluteJoint, cugl::physics2::WeldJoint, and cugl::physics2::WheelJoint.
|
inline |
Returns true if the shape information must be updated.
The joint must wait for collisions to complete before it can be reset. Reseting the joint is managed by ObstacleWorld
.
|
inline |
Returns true if our object has been flagged for garbage collection
A garbage collected object will be removed from the physics world at the next time step.
|
inline |
Sets whether the shape information must be updated.
The joint must wait for collisions to complete before it can be reset. Reseting the joint is managed by ObstacleWorld
.
value | whether the shape information must be updated. |
|
inline |
Sets whether our object has been flagged for garbage collection
A garbage collected object will be removed from the physics world at the next time step.
value | whether our object has been flagged for garbage collection |
void cugl::physics2::Joint::release | ( | ) |
Instructs the object to release its Box2d joint.
This method is required when a joint is deleted in response to a deletion of one of its bodies.
|
inline |
Sets the flag for whether the attached bodies should collide.
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.
flag | Whether the attached bodies should collide. |
|
inline |
Sets the first obstacle attached to this 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.
obs | the first body attached to this joint. |
|
inline |
Sets the second obstacle attached to this 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.
obs | the second obstacle attached to this joint. |
|
protected |
The first attached obstacle.
|
protected |
The second attached obstacle.
|
protected |
Set this flag to true if the attached bodies should collide.
|
protected |
Whether the joint has changed properties and needs to be rebuilt
|
protected |
A reference to the joint (nullptr if it is not active)
|
protected |
Track garbage collection status.
Whether the joint should be removed from the world on next pass
|
protected |
The underlying joint type (set automatically for concrete joint types)