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

#include <CUMotorJoint.h>

Inheritance diagram for cugl::physics2::MotorJoint:
cugl::physics2::Joint

Public Member Functions

 MotorJoint ()
 
const Vec2 getLinearOffset () const
 
void setLinearOffset (const Vec2 pos)
 
void setLinearOffset (float x, float y)
 
float getAngularOffset () const
 
void setAngularOffset (float value)
 
float getMaxForce () const
 
void setMaxForce (float value)
 
float getMaxTorque () const
 The maximum motor torque in N-m.
 
void setMaxTorque (float value)
 
float getCorrectionFactor () const
 
void setCorrectionFactor (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< MotorJointalloc ()
 
static std::shared_ptr< MotorJointallocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB)
 

Protected Attributes

Vec2 _linearOffset
 
float _angularOffset
 
float _maxForce
 
float _maxTorque
 
float _correctionFactor
 
- 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 motor joint class.

Constructor & Destructor Documentation

◆ MotorJoint()

cugl::physics2::MotorJoint::MotorJoint ( )

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

Returns a newly allocated motor joint with default values.

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

Returns
a newly allocated motor joint with default values.

◆ allocWithObstacles()

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

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

◆ getAngularOffset()

float cugl::physics2::MotorJoint::getAngularOffset ( ) const
inline

Returns the bodyB angle minus bodyA angle in radians.

Returns
the bodyB angle minus bodyA angle in radians.

◆ getCorrectionFactor()

float cugl::physics2::MotorJoint::getCorrectionFactor ( ) const
inline

Returns the position correction factor in the range [0,1].

Returns
the position correction factor in the range [0,1].

◆ getLinearOffset()

const Vec2 cugl::physics2::MotorJoint::getLinearOffset ( ) const
inline

Returns the position of bodyB minus the position of bodyA.

The value is measured in meters, with respect to bodyA's frame.

Returns
the position of bodyB minus the position of bodyA.

◆ getMaxForce()

float cugl::physics2::MotorJoint::getMaxForce ( ) const
inline

Returns the maximum motor force in N.

Returns
the maximum motor force in N.

◆ getMaxTorque()

float cugl::physics2::MotorJoint::getMaxTorque ( ) const
inline

The maximum motor torque in N-m.

Returns the maximum motor torque in N-m.

Returns
the maximum motor torque in N-m.

◆ setAngularOffset()

void cugl::physics2::MotorJoint::setAngularOffset ( float  value)
inline

Sets the bodyB angle minus bodyA angle 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 bodyB angle minus bodyA angle in radians.

◆ setCorrectionFactor()

void cugl::physics2::MotorJoint::setCorrectionFactor ( float  value)
inline

Sets the position correction factor in the range [0,1].

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 position correction factor

◆ setLinearOffset() [1/2]

void cugl::physics2::MotorJoint::setLinearOffset ( const Vec2  pos)
inline

Sets the position of bodyB minus the position of bodyA.

The value is measured in meters, with respect to bodyA's frame.

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
posthe position of bodyB minus the position of bodyA.

◆ setLinearOffset() [2/2]

void cugl::physics2::MotorJoint::setLinearOffset ( float  x,
float  y 
)
inline

Sets the position of bodyB minus the position of bodyA.

The value is measured in meters, with respect to bodyA's frame.

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 position of bodyB minus that of bodyA.
ythe y-coordinate of the position of bodyB minus that of bodyA.

◆ setMaxForce()

void cugl::physics2::MotorJoint::setMaxForce ( float  value)
inline

Sets the maximum motor force in N.

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 force

◆ setMaxTorque()

void cugl::physics2::MotorJoint::setMaxTorque ( float  value)
inline

Sets the maximum motor torque 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

Member Data Documentation

◆ _angularOffset

float cugl::physics2::MotorJoint::_angularOffset
protected

The bodyB angle minus bodyA angle in radians.

◆ _correctionFactor

float cugl::physics2::MotorJoint::_correctionFactor
protected

Position correction factor in the range [0,1].

◆ _linearOffset

Vec2 cugl::physics2::MotorJoint::_linearOffset
protected

The position of bodyB minus the position of bodyA, in bodyA's frame, in meters.

◆ _maxForce

float cugl::physics2::MotorJoint::_maxForce
protected

The maximum motor force in N.

◆ _maxTorque

float cugl::physics2::MotorJoint::_maxTorque
protected

The maximum motor torque in N-m.


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