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

#include <CUJoint.h>

Inheritance diagram for cugl::physics2::Joint:
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 cugl::physics2::WheelJoint

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
 

Detailed Description

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

Constructor & Destructor Documentation

◆ Joint()

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

◆ ~Joint()

virtual cugl::physics2::Joint::~Joint ( )
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.

Member Function Documentation

◆ activatePhysics()

virtual bool cugl::physics2::Joint::activatePhysics ( b2World &  world)
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.

Parameters
worldBox2D world to store the joint
Returns
true if object allocation succeeded

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.

◆ deactivatePhysics()

void cugl::physics2::Joint::deactivatePhysics ( b2World &  world)
inline

Destroys the Box2D joint if applicable.

This removes the joint from the Box2D world.

Parameters
worldBox2D world that stores the joint

◆ getCollideConnected()

bool cugl::physics2::Joint::getCollideConnected ( )
inline

Returns true if the attached bodies should collide.

Returns
true if the attached bodies should collide.

◆ getJoint()

b2Joint * cugl::physics2::Joint::getJoint ( )
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.

Returns
a (weak) reference to the Box2D joint

◆ getObstacleA()

std::shared_ptr< Obstacle > & cugl::physics2::Joint::getObstacleA ( )
inline

Returns the first obstacle attached to this joint.

Returns
the first obstacle attached to this joint.

◆ getObstacleB()

std::shared_ptr< Obstacle > & cugl::physics2::Joint::getObstacleB ( )
inline

Returns the second obstacle attached to this joint.

Returns
the second obstacle attached to this joint.

◆ getType()

b2JointType cugl::physics2::Joint::getType ( ) const
inline

Returns the type of this joint

Returns
the type of this joint

◆ init()

bool cugl::physics2::Joint::init ( )
inline

Initializes a new physics joint with no obstacles.

You should set the obstacles (and other attributes) before activating this joint.

Returns
true if the obstacle is initialized properly, false otherwise.

◆ initWithObstacles()

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

Initializes a new physics 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 in cugl::physics2::DistanceJoint, cugl::physics2::FrictionJoint, cugl::physics2::PrismaticJoint, cugl::physics2::PulleyJoint, cugl::physics2::RevoluteJoint, cugl::physics2::WeldJoint, and cugl::physics2::WheelJoint.

◆ isDirty()

bool cugl::physics2::Joint::isDirty ( ) const
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.

Returns
true if the shape information must be updated.

◆ isRemoved()

bool cugl::physics2::Joint::isRemoved ( ) const
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.

Returns
true if our object has been flagged for garbage collection

◆ markDirty()

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

Parameters
valuewhether the shape information must be updated.

◆ markRemoved()

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

Parameters
valuewhether our object has been flagged for garbage collection

◆ release()

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.

◆ setCollideConnected()

void cugl::physics2::Joint::setCollideConnected ( bool  flag)
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.

Parameters
flagWhether the attached bodies should collide.

◆ setObstacleA()

void cugl::physics2::Joint::setObstacleA ( const std::shared_ptr< Obstacle > &  obs)
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.

Parameters
obsthe first body attached to this joint.

◆ setObstacleB()

void cugl::physics2::Joint::setObstacleB ( const std::shared_ptr< Obstacle > &  obs)
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.

Parameters
obsthe second obstacle attached to this joint.

Member Data Documentation

◆ _bodyA

std::shared_ptr<Obstacle> cugl::physics2::Joint::_bodyA
protected

The first attached obstacle.

◆ _bodyB

std::shared_ptr<Obstacle> cugl::physics2::Joint::_bodyB
protected

The second attached obstacle.

◆ _collideConnected

bool cugl::physics2::Joint::_collideConnected
protected

Set this flag to true if the attached bodies should collide.

◆ _dirty

bool cugl::physics2::Joint::_dirty
protected

Whether the joint has changed properties and needs to be rebuilt

◆ _joint

b2Joint* cugl::physics2::Joint::_joint
protected

A reference to the joint (nullptr if it is not active)

◆ _remove

bool cugl::physics2::Joint::_remove
protected

Track garbage collection status.

Whether the joint should be removed from the world on next pass

◆ _type

b2JointType cugl::physics2::Joint::_type
protected

The underlying joint type (set automatically for concrete joint types)


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