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

#include <CUPrismaticJoint.h>

Inheritance diagram for cugl::physics2::PrismaticJoint:
cugl::physics2::Joint

Public Member Functions

 PrismaticJoint ()
 
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)
 
const Vec2getLocalAxisA () const
 
void setLocalAxisA (const Vec2 point)
 
void setLocalAxisA (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 getLowerTranslation () const
 
void setLowerTranslation (float value)
 
float getUpperTranslation () const
 
void setUpperTranslation (float value)
 
float getMaxMotorForce () const
 
void setMaxMotorForce (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< PrismaticJointalloc ()
 
static std::shared_ptr< PrismaticJointallocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB)
 
static std::shared_ptr< PrismaticJointallocWithObstacles (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 prismatic joint class.

This joine requires defining a line of motion using an axis and an anchor point. The definition uses local anchor points and a local axis so that the initial configuration can violate the constraint slightly. The joint translation is zero when the local anchor points coincide in world space. Using local anchors and a local axis helps when saving and loading a game.

Constructor & Destructor Documentation

◆ PrismaticJoint()

cugl::physics2::PrismaticJoint::PrismaticJoint ( )

Creates a new prismatic 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::PrismaticJoint::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< PrismaticJoint > cugl::physics2::PrismaticJoint::alloc ( )
inlinestatic

Returns a newly allocated prismatic joint with default values.

The joint will not have any associated obstacles and so attempting to activate it will fail.

Returns
a newly allocated prismatic joint with default values.

◆ allocWithObstacles() [1/2]

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

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

◆ allocWithObstacles() [2/2]

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

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

◆ enableLimit()

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

◆ getLocalAxisA()

const Vec2 & cugl::physics2::PrismaticJoint::getLocalAxisA ( ) const
inline

Returns the local translation unit axis.

This axis is measured with respect to bodyA.

Returns
the local translation unit axis.

◆ getLowerTranslation()

float cugl::physics2::PrismaticJoint::getLowerTranslation ( ) const
inline

Returns the lower translation limit.

This is usually measured in meters.

Returns
the lower translation limit.

◆ getMaxMotorForce()

float cugl::physics2::PrismaticJoint::getMaxMotorForce ( ) const
inline

Returns the maximum motor torque, usually in N-m.

Returns
the maximum motor torque, usually in N-m.

◆ getMotorSpeed()

float cugl::physics2::PrismaticJoint::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::PrismaticJoint::getReferenceAngle ( ) const
inline

Returns the constrained angle between the bodies.

This value is measured bodyB - bodyA in radians.

Returns
the constrained angle between the bodies.

◆ getUpperTranslation()

float cugl::physics2::PrismaticJoint::getUpperTranslation ( ) const
inline

Returns the upper translation limit.

This is usually measured in meters.

Returns
the upper translation limit.

◆ hasLimit()

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

Returns true if the joint limit is enabled.

Returns
true if the joint limit is enabled.

◆ hasMotor()

bool cugl::physics2::PrismaticJoint::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::PrismaticJoint::initWithObstacles ( const std::shared_ptr< Obstacle > &  obsA,
const std::shared_ptr< Obstacle > &  obsB 
)
overridevirtual

Initializes a new prismatic 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::PrismaticJoint::initWithObstacles ( const std::shared_ptr< Obstacle > &  obsA,
const std::shared_ptr< Obstacle > &  obsB,
const Vec2  localA,
const Vec2  localB 
)

Initializes a new prismatic 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::PrismaticJoint::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::PrismaticJoint::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::PrismaticJoint::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::PrismaticJoint::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

◆ setLocalAxisA() [1/2]

void cugl::physics2::PrismaticJoint::setLocalAxisA ( const Vec2  point)
inline

Sets the local translation unit axis.

This axis is measured with respect to bodyA.

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 translation unit axis.

◆ setLocalAxisA() [2/2]

void cugl::physics2::PrismaticJoint::setLocalAxisA ( float  x,
float  y 
)
inline

Sets the local translation unit axis.

This axis is measured with respect to bodyA.

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 translation unit axis
ythe y-coordinate of the local translation unit axis

◆ setLowerTranslation()

void cugl::physics2::PrismaticJoint::setLowerTranslation ( float  value)
inline

Sets the lower translation limit.

This is usually measured in meters.

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 translation limit.

◆ setMaxMotorForce()

void cugl::physics2::PrismaticJoint::setMaxMotorForce ( float  value)
inline

Sets the maximum motor torque, usually 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::PrismaticJoint::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::PrismaticJoint::setReferenceAngle ( float  value)
inline

Sets the 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 constrained angle between the bodies.

◆ setUpperTranslation()

void cugl::physics2::PrismaticJoint::setUpperTranslation ( float  value)
inline

Sets the upper translation limit.

This is usually measured in meters.

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 translation limit.

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