Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ime::DistanceJoint Class Referencefinal

Constrains two points on two rigid bodies to remain at a fixed distance from each other. More...

#include <DistanceJoint.h>

Inheritance diagram for ime::DistanceJoint:
ime::Joint ime::Object

Public Types

using Ptr = std::unique_ptr< Joint >
 Unique joint pointer. More...
 

Public Member Functions

std::string getClassName () const override
 Get the name of this class. More...
 
float setRestLength (float length)
 Set the rest length. More...
 
float getRestLength () const
 Get the rest length. More...
 
float setMinimumLength (float minLength)
 Set the minimum length. More...
 
float getMinimumLength () const
 Get the minimum length. More...
 
float setMaxLength (float maxLength)
 Set the maximum length. More...
 
float getMaximumLength () const
 Get the maximum length. More...
 
float getCurrentLength () const
 Get the current length. More...
 
Vector2f getBodyALocalAnchorPoint () const
 Get the anchor point on body A in local coordinates. More...
 
Vector2f getBodyAWorldAnchorPoint () const override
 Get the anchor point on body A in world coordinates. More...
 
Vector2f getBodyBLocalAnchorPoint () const
 Get the anchor point on body B in local coordinates. More...
 
Vector2f getBodyBWorldAnchorPoint () const override
 Get the anchor point on body B in world coordinates. More...
 
JointType getType () const override
 Get the type of the joint. More...
 
RigidBodygetBodyA () override
 Get the first body attached to ths joint. More...
 
const RigidBodygetBodyA () const override
 
RigidBodygetBodyB () override
 Get the second body attached to ths joint. More...
 
const RigidBodygetBodyB () const override
 
Vector2f getReactionForce (float fpsLimit) const override
 Get the reaction force on body B at the joint anchor. More...
 
float getReactionTorque (float fpsLimit) const override
 Get the reaction torque on body B. More...
 
PropertyContainergetUserData () override
 Get the application specific Joint data. More...
 
const PropertyContainergetUserData () const override
 
bool canBodiesCollide () const override
 Check if the joint bodies can collide with each other or not. More...
 
b2Joint * getInternalJoint () override
 
const b2Joint * getInternalJoint () const override
 
 ~DistanceJoint () override
 Destructor. More...
 
std::string getClassType () const override
 Get the name of this class. More...
 
void setTag (const std::string &tag)
 Assign the object an alias. More...
 
const std::string & getTag () const
 Get the tag assigned to the object. More...
 
unsigned int getObjectId () const
 Get the unique id of the object. More...
 
int onPropertyChange (const std::string &property, const Callback< Property > &callback, bool oneTime=false)
 Add an event listener to a specific property change event. More...
 
int onPropertyChange (const Callback< Property > &callback, bool oneTime=false)
 Add an event listener to any property change event. More...
 
void suspendedEventListener (int id, bool suspend)
 Pause or resume execution of an event listener. More...
 
bool isEventListenerSuspended (int id) const
 Check if an event listener is suspended or not. More...
 
bool removeEventListener (const std::string &event, int id)
 Remove an event listener from an event. More...
 
bool removeEventListener (int id)
 Remove an event listener. More...
 
int onDestruction (const Callback<> &callback)
 Add a destruction listener. More...
 
bool isSameObjectAs (const Object &other) const
 Check if another object is the same instance as this object. More...
 

Protected Member Functions

void emitChange (const Property &property)
 Dispatch a property change event. More...
 
void emitDestruction ()
 Emit a destruction event. More...
 

Protected Attributes

EventEmitter eventEmitter_
 Event dispatcher. More...
 

Friends

class PhysicsEngine
 Needs access to constructor. More...
 

Detailed Description

Constrains two points on two rigid bodies to remain at a fixed distance from each other.

When you specify a distance joint the two bodies should already be in place. Then you specify the two anchor points in world coordinates. The first anchor point is connected to body 1, and the second anchor point is connected to body 2. These points imply the length of the distance constraint

Definition at line 79 of file DistanceJoint.h.

Member Typedef Documentation

◆ Ptr

using ime::DistanceJoint::Ptr = std::unique_ptr<Joint>

Unique joint pointer.

Definition at line 81 of file DistanceJoint.h.

Constructor & Destructor Documentation

◆ ~DistanceJoint()

ime::DistanceJoint::~DistanceJoint ( )
override

Destructor.

Member Function Documentation

◆ canBodiesCollide()

bool ime::DistanceJoint::canBodiesCollide ( ) const
overridevirtual

Check if the joint bodies can collide with each other or not.

Returns
True if the bodies can collide with each other, otherwise false

Implements ime::Joint.

◆ emitChange()

void ime::Object::emitChange ( const Property property)
protectedinherited

Dispatch a property change event.

Parameters
propertyThe property that changed

This function will invoke all the event listeners of the specified property

See also
emit

◆ emitDestruction()

void ime::Object::emitDestruction ( )
protectedinherited

Emit a destruction event.

Note
This function must be the first statement in the definition of a destructor to avoid undefined behavior. In addition, note that destruction listeners are invoked once. Therefore, multiple classes in a hierarchy may call this function but the class that makes the call first will be the one that invokes the destruction listeners

◆ getBodyA() [1/2]

const RigidBody * ime::DistanceJoint::getBodyA ( ) const
overridevirtual

Implements ime::Joint.

◆ getBodyA() [2/2]

RigidBody * ime::DistanceJoint::getBodyA ( )
overridevirtual

Get the first body attached to ths joint.

Returns
The first body attached to this joint

Implements ime::Joint.

◆ getBodyALocalAnchorPoint()

Vector2f ime::DistanceJoint::getBodyALocalAnchorPoint ( ) const

Get the anchor point on body A in local coordinates.

Returns
The anchor point in local coordinates

◆ getBodyAWorldAnchorPoint()

Vector2f ime::DistanceJoint::getBodyAWorldAnchorPoint ( ) const
overridevirtual

Get the anchor point on body A in world coordinates.

Returns
The anchor point in world coordinates

Implements ime::Joint.

◆ getBodyB() [1/2]

const RigidBody * ime::DistanceJoint::getBodyB ( ) const
overridevirtual

Implements ime::Joint.

◆ getBodyB() [2/2]

RigidBody * ime::DistanceJoint::getBodyB ( )
overridevirtual

Get the second body attached to ths joint.

Returns
The second body attached to this joint

Implements ime::Joint.

◆ getBodyBLocalAnchorPoint()

Vector2f ime::DistanceJoint::getBodyBLocalAnchorPoint ( ) const

Get the anchor point on body B in local coordinates.

Returns
The anchor point on body B in local coordinates

◆ getBodyBWorldAnchorPoint()

Vector2f ime::DistanceJoint::getBodyBWorldAnchorPoint ( ) const
overridevirtual

Get the anchor point on body B in world coordinates.

Returns
The anchor point on body B in world coordinates

Implements ime::Joint.

◆ getClassName()

std::string ime::DistanceJoint::getClassName ( ) const
overridevirtual

Get the name of this class.

Returns
The name of this class

Implements ime::Object.

◆ getClassType()

std::string ime::Joint::getClassType ( ) const
overridevirtualinherited

Get the name of this class.

Returns
The name of this class

Note that this function is only implemented by child classes of Object which also serve as a base class for other classes

See also
Object::getClassType and Object::getClassName

Reimplemented from ime::Object.

◆ getCurrentLength()

float ime::DistanceJoint::getCurrentLength ( ) const

Get the current length.

Returns
The current length

◆ getInternalJoint() [1/2]

const b2Joint * ime::DistanceJoint::getInternalJoint ( ) const
overridevirtual

Implements ime::Joint.

◆ getInternalJoint() [2/2]

b2Joint * ime::DistanceJoint::getInternalJoint ( )
overridevirtual

Implements ime::Joint.

◆ getMaximumLength()

float ime::DistanceJoint::getMaximumLength ( ) const

Get the maximum length.

Returns
The maximum length

By default the maximum length is

◆ getMinimumLength()

float ime::DistanceJoint::getMinimumLength ( ) const

Get the minimum length.

Returns
The minimum length

By default, the maximum length is the maximum float value on your computer (Very large number)

◆ getObjectId()

unsigned int ime::Object::getObjectId ( ) const
inherited

Get the unique id of the object.

Returns
The unique id of the object

Note that each instance of ime::Object has a unique id

See also
setTag

◆ getReactionForce()

Vector2f ime::DistanceJoint::getReactionForce ( float  fpsLimit) const
overridevirtual

Get the reaction force on body B at the joint anchor.

Parameters
fpsLimitThe games Frames Per Second limit
Returns
The reaction force on Body B at the joint anchor in Newtons (N)

Implements ime::Joint.

◆ getReactionTorque()

float ime::DistanceJoint::getReactionTorque ( float  fpsLimit) const
overridevirtual

Get the reaction torque on body B.

Parameters
fpsLimitThe games Frames Per Second limit
Returns
The reaction torque on body B in N*m

Implements ime::Joint.

◆ getRestLength()

float ime::DistanceJoint::getRestLength ( ) const

Get the rest length.

Returns
The rest length

◆ getTag()

const std::string & ime::Object::getTag ( ) const
inherited

Get the tag assigned to the object.

Returns
The tag of the object
See also
setTag

◆ getType()

JointType ime::DistanceJoint::getType ( ) const
overridevirtual

Get the type of the joint.

Returns
The type of the joint

Implements ime::Joint.

◆ getUserData() [1/2]

const PropertyContainer & ime::DistanceJoint::getUserData ( ) const
overridevirtual

Implements ime::Joint.

◆ getUserData() [2/2]

PropertyContainer & ime::DistanceJoint::getUserData ( )
overridevirtual

Get the application specific Joint data.

Returns
Application specific joint data

This data is extracted from the JointDefinition

Implements ime::Joint.

◆ isEventListenerSuspended()

bool ime::Object::isEventListenerSuspended ( int  id) const
inherited

Check if an event listener is suspended or not.

Parameters
idThe identification number of the listener to be checked
Returns
True if suspended, otherwise false

This function also returns false if the specified event listener does not exist

See also
suspendedEventListener

◆ isSameObjectAs()

bool ime::Object::isSameObjectAs ( const Object other) const
inherited

Check if another object is the same instance as this object.

Parameters
otherThe object to compare against this object
Returns
True if other is the same instance as this object, otherwise false

◆ onDestruction()

int ime::Object::onDestruction ( const Callback<> &  callback)
inherited

Add a destruction listener.

Parameters
callbackFunction to be executed when the object is destroyed
Returns
The unique id of the destruction listener

The destruction listener is called when the object reaches the end of its lifetime. Note that an object may have multiple destruction listeners registered to it

Warning
It's not advised to call virtual functions in the destruction callback as some parts of the object may have already been destroyed by the time the callback is invoked. In such an event, the behavior is undefined
See also
removeEventListener

◆ onPropertyChange() [1/2]

int ime::Object::onPropertyChange ( const Callback< Property > &  callback,
bool  oneTime = false 
)
inherited

Add an event listener to any property change event.

Parameters
callbackThe function to be executed when any property changes
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The unique id of the event listener

When unsubscribing the any property change event handler, you must pass "propertyChange" as the name of the event

See also
onPropertyChange(const std::string&, const ime::Callback<ime::Property>&)

◆ onPropertyChange() [2/2]

int ime::Object::onPropertyChange ( const std::string &  property,
const Callback< Property > &  callback,
bool  oneTime = false 
)
inherited

Add an event listener to a specific property change event.

Parameters
propertyThe name of the property to add an event listener to
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
callbackThe function to be executed when the property changes
Returns
The unique id of the event listener

A property change event is triggered by any function that begins with set, where the the text after set is the name of the property. For example, the setTag() function, modifies the tag property of the object, thus will generate a "tag" change event each time it is called

Note that multiple event listeners may be registered to the same property change event. In addition, when adding a property change event listener, the name of the property must be in lowercase.

// Prints the tag of the player object to the console everytime it changes
player.onPropertyChange("tag", [](const Property& property) {
cout << "New tag: " << property.getValue<std::string>() << endl;
});
...
//Sets tag = "player1" and invokes event listener(s)
player.setTag("player1");
See also
unsubscribe and onPropertyChange(const ime::Callback<ime::Property>&)

◆ removeEventListener() [1/2]

bool ime::Object::removeEventListener ( const std::string &  event,
int  id 
)
inherited

Remove an event listener from an event.

Parameters
eventThe name of the event to remove an event listener from
idThe unique id of the event listener to be removed
Returns
True if the event listener was removed or false if the event or the event listener is does not exist
// Display the tag of the object to console every time it changes
auto tagChangeId = object.onPropertyChange("tag", [](ime::Property tag) {
std::cout << name.getValue<std::string>() << std::endl;
});
// Stop displaying the tag of the object when it changes
object.removeEventListener("tag", tagChangeId);
Class that can store a value of any type.
Definition: Property.h:38

◆ removeEventListener() [2/2]

bool ime::Object::removeEventListener ( int  id)
inherited

Remove an event listener.

Parameters
idThe id of the event listener to be removed
Returns
True if the event listener was removed or false if no such handler exists

◆ setMaxLength()

float ime::DistanceJoint::setMaxLength ( float  maxLength)

Set the maximum length.

Parameters
maxLengthThe new maximum length
Returns
The clamped length

◆ setMinimumLength()

float ime::DistanceJoint::setMinimumLength ( float  minLength)

Set the minimum length.

Parameters
minLengthThe new minimum length
Returns
The clamped length

By default the minimum length is 0.0f

◆ setRestLength()

float ime::DistanceJoint::setRestLength ( float  length)

Set the rest length.

Parameters
lengthThe rest length to set
Returns
The clamped length

◆ setTag()

void ime::Object::setTag ( const std::string &  tag)
inherited

Assign the object an alias.

Parameters
tagThe alias of the object

This function is useful if you want to refer to the object by a tag instead of its object id. Unlike an object id, multiple objects may have the same tag

By default, the tag is an empty string

See also
getObjectId

◆ suspendedEventListener()

void ime::Object::suspendedEventListener ( int  id,
bool  suspend 
)
inherited

Pause or resume execution of an event listener.

Parameters
idThe event listeners unique identification number
suspendTrue to suspend/pause or false to unsuspend/resume
See also
isEventListenerSuspended

Friends And Related Function Documentation

◆ PhysicsEngine

friend class PhysicsEngine
friend

Needs access to constructor.

Definition at line 250 of file DistanceJoint.h.

Member Data Documentation

◆ eventEmitter_

EventEmitter ime::Object::eventEmitter_
protectedinherited

Event dispatcher.

Definition at line 289 of file Object.h.


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