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

#include <CUMouseJoint.h>

Inheritance diagram for cugl::physics2::MouseJoint:
cugl::physics2::Joint

Public Member Functions

 MouseJoint ()
 
const Vec2 getTarget () const
 
void setTarget (const Vec2 pos)
 
void setTarget (float x, float y)
 
float getMaxForce () const
 
void setMaxForce (float value)
 
float getStiffness () const
 
void setStiffness (float value)
 
float getDamping () const
 
void setDamping (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< MouseJointalloc ()
 
static std::shared_ptr< MouseJointallocWithObstacles (const std::shared_ptr< Obstacle > &obsA, const std::shared_ptr< Obstacle > &obsB)
 

Protected Attributes

Vec2 _target
 
float _maxForce
 
float _stiffness
 
float _damping
 
- 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 mouse joint class.

This requires a world target point, tuning parameters, and the time step. The first obstacle in the mouse joint is generally ignored, except as a frame of reference.

Constructor & Destructor Documentation

◆ MouseJoint()

cugl::physics2::MouseJoint::MouseJoint ( )

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

Returns a newly allocated mouse 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< MouseJoint > cugl::physics2::MouseJoint::allocWithObstacles ( const std::shared_ptr< Obstacle > &  obsA,
const std::shared_ptr< Obstacle > &  obsB 
)
inlinestatic

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

◆ getDamping()

float cugl::physics2::MouseJoint::getDamping ( ) const
inline

Returns the linear damping in N*s/m.

Returns
the linear damping in N*s/m.

◆ getMaxForce()

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

Returns the maximum constraint force that can be exerted to move the body.

The body moved is the second obstacle. This force is usually expressed as some multiple of the weight (multiplier * mass * gravity).

Returns
the maximum constraint force that can be exerted to move the body.

◆ getStiffness()

float cugl::physics2::MouseJoint::getStiffness ( ) const
inline

Returns the linear stiffness in N/m.

Returns
the linear stiffness in N/m.

◆ getTarget()

const Vec2 cugl::physics2::MouseJoint::getTarget ( ) const
inline

Returns the initial world target point.

This is assumed to coincide with the body anchor initially.

Returns
the initial world target point.

◆ setDamping()

void cugl::physics2::MouseJoint::setDamping ( float  value)
inline

Sets the linear damping in N*s/m.

Parameters
valuethe linear damping

◆ setMaxForce()

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

Sets the maximum constraint force that can be exerted to move the body.

The body moved is the second obstacle. This force is usually expressed as some multiple of the weight (multiplier * mass * gravity).

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 force that can be exerted

◆ setStiffness()

void cugl::physics2::MouseJoint::setStiffness ( float  value)
inline

Sets the linear stiffness in N/m.

Parameters
valuethe linear stiffness

◆ setTarget() [1/2]

void cugl::physics2::MouseJoint::setTarget ( const Vec2  pos)
inline

Sets the initial world target point.

This is assumed to coincide with the body anchor initially.

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 initial world target point

◆ setTarget() [2/2]

void cugl::physics2::MouseJoint::setTarget ( float  x,
float  y 
)
inline

Sets the initial world target point.

This is assumed to coincide with the body anchor initially.

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 initial world target point
ythe y-coordinate of the initial world target point

Member Data Documentation

◆ _damping

float cugl::physics2::MouseJoint::_damping
protected

The linear damping in N*s/m

◆ _maxForce

float cugl::physics2::MouseJoint::_maxForce
protected

The maximum constraint force that can be exerted

◆ _stiffness

float cugl::physics2::MouseJoint::_stiffness
protected

The linear stiffness in N/m

◆ _target

Vec2 cugl::physics2::MouseJoint::_target
protected

The initial world target point.


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