VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Types | Signals | Public Member Functions | Protected Member Functions | Properties | Friends | List of all members
Body Class Reference

A QObject container for a Box2D b2Body. More...

Inheritance diagram for Body:
QObject CircleBody PolygonBody

Public Types

enum  BodyType { StaticBody = 0, KinematicBody, DynamicBody }
 Overarching category of how this Body interacts with the world. More...
 

Signals

void bodyTypeChanged ()
 Emitted when bodyType changes. More...
 
void activeChanged ()
 Emitted when active changes. More...
 
void linearDampingChanged ()
 Emitted when linearDamping changes. More...
 
void angularDampingChanged ()
 Emitted when angularDamping changes. More...
 
void gravityScaleChanged ()
 Emitted when gravityScale changes. More...
 
void magneticChanged ()
 Emitted when magnetic changes. More...
 
void magneticStrengthChanged ()
 Emitted when magneticStrength changes. More...
 
void positionSet ()
 Emitted when position is set. More...
 
void angleInRadiansSet ()
 Emitted when angleInRadians is set. More...
 
void linearVelocitySet ()
 Emitted when linearVelocity is set. More...
 
void angularVelocitySet ()
 Emitted when angularVelocity is set. More...
 
void sensorChanged ()
 Emitted when sensor changes. More...
 
void densityChanged ()
 Emitted when density changes. More...
 
void frictionChanged ()
 Emitted when friction changes. More...
 
void restitutionChanged ()
 Emitted when restitution changes. More...
 
void jointsChanged ()
 Emitted when joints changes. More...
 
void contactBegun (Body *otherBody, QPointF normal)
 Emitted when a contact begins. More...
 
void contactEnded (Body *otherBody, QPointF normal)
 Emitted when a contact ends. More...
 
void queuedContactBegun (Body *otherBody, QPointF normal)
 Queued version of contactBegun(). More...
 
void queuedContactEnded (Body *otherBody, QPointF normal)
 Queued version of contactEnded(). More...
 

Public Member Functions

 Body (QObject *parent=0)
 Constructs a Body. More...
 
virtual ~Body ()
 Destroys a Body. More...
 
ActorgetActor () const
 Returns actor. More...
 
BodyType getBodyType () const
 Returns bodyType. More...
 
void setBodyType (BodyType value)
 Sets bodyType. More...
 
bool isActive () const
 Returns active. More...
 
void setActive (bool value)
 Sets active. More...
 
float getLinearDamping () const
 Returns linearDamping. More...
 
void setLinearDamping (float value)
 Sets linearDamping. More...
 
float getAngularDamping () const
 Returns angularDamping. More...
 
void setAngularDamping (float value)
 Sets angularDamping. More...
 
float getGravityScale () const
 Returns gravityScale. More...
 
void setGravityScale (float value)
 Sets gravityScale. More...
 
bool isMagnetic () const
 Returns magnetic. More...
 
void setMagnetic (bool value)
 Sets magnetic. More...
 
float getMagneticStrength () const
 Returns magneticStrength. More...
 
void setMagneticStrength (float value)
 Sets magneticStrength. More...
 
QPointF getPosition () const
 Returns position. More...
 
bool isSensor () const
 Returns sensor. More...
 
void setSensor (bool value)
 Sets sensor. More...
 
float getDensity () const
 Returns density. More...
 
void setDensity (float value)
 Sets density. More...
 
float getFriction () const
 Returns friction. More...
 
void setFriction (float value)
 Sets friction. More...
 
float getRestitution () const
 Returns restitution. More...
 
void setRestitution (float value)
 Sets restitution. More...
 
const QList< Joint * > & getJoints () const
 Returns joints as a const QList<Joint*>&. More...
 
QQmlListProperty< JointgetJointListProperty ()
 Returns joints as a QQmlListProperty<Joint>. More...
 
void setJoints (const QList< Joint * > &value)
 Sets joints. More...
 
Q_INVOKABLE JointgetJoint (int index)
 Returns a Joint at a given index. More...
 
Q_INVOKABLE int getJointCount () const
 Returns the number of Joints associated with this Body. More...
 
Q_INVOKABLE void addJoint (Joint *joint)
 Add a Joint to the Body. More...
 
Q_INVOKABLE void removeJoint (Joint *joint)
 Remove a Joint from the Body. More...
 
Q_INVOKABLE void clearJoints ()
 Clear all the Joints owned by this Body. More...
 
Q_INVOKABLE void clearAllAttachedJoints ()
 Destroys all Joints associated with this Body, whether or not this Body is the Joint's parent. More...
 
b2Body * getBody ()
 Returns the b2Body associated with this Body. More...
 
Q_INVOKABLE void applyTorque (float torque)
 Apply torque to the associated b2Body. More...
 
Q_INVOKABLE void applyForceToCenter (const QPointF &force)
 Apply force to the associated b2Body. More...
 
void invalidateTransform ()
 Marks the transform for this Body as dirty. More...
 
virtual void updateBeforePhysics ()
 Called immediately preceding the physics step. More...
 
virtual void updateAfterPhysics ()
 Called immediately following the physics step. More...
 
QList< Body * > getContactedBodies () const
 Returns a QList containing the list of Bodys in contact with this Body. More...
 
void beginContact (Body *otherBody, const QPointF &normal)
 Called when this Body has made contact with another. More...
 
void endContact (Body *otherBody, const QPointF &normal)
 Called when this Body loses contact with another. More...
 
virtual void forEachShape (const std::function< void(b2Shape *)> &func)
 Calls func on the complete set of b2Shapes that represent this Body. More...
 
Setters and Getters for Properties Affected by Physics
void setPosition (const QPointF &value)
 Sets position. More...
 
float getAngleInRadians () const
 Returns angleInRadians. More...
 
void setAngleInRadians (float value)
 Sets angleInRadians. More...
 
QPointF getLinearVelocity () const
 Returns linearVelocity. More...
 
void setLinearVelocity (const QPointF &value)
 Sets linearVelocity. More...
 
float getAngularVelocity () const
 Returns angularVelocity. More...
 
void setAngularVelocity (float value)
 Sets angularVelocity. More...
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
virtual const QMetaObjectmetaObject () const
 
QString objectName () const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const
 
bool blockSignals (bool block)
 
QThreadthread () const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, QFlags< Qt::FindChildOption > options) const
 
QList< T > findChildren (const QString &name, QFlags< Qt::FindChildOption > options) const
 
QList< T > findChildren (const QRegExp &regExp, QFlags< Qt::FindChildOption > options) const
 
QList< T > findChildren (const QRegularExpression &re, QFlags< Qt::FindChildOption > options) const
 
const QObjectList & children () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const
 
bool disconnect (const QObject *receiver, const char *method) const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const
 
bool inherits (const char *className) const
 
void deleteLater ()
 

Protected Member Functions

void invalidateFixtures ()
 Marks the Body's fixtures as dirty and that they need to be recreated. More...
 
void forEachFixture (const std::function< void(b2Fixture *)> &func)
 Applies func to each of the Body's fixtures. More...
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 

Properties

Actor actor
 Actor object associated with this Body. Always the parent in the item hierarchy. More...
 
BodyType bodyType
 BodyType of this Body. More...
 
bool active
 Whether or not the Body takes part in the physics simulation. More...
 
float linearDamping
 Dampens the linearVelocity of the Body. More...
 
float angularDamping
 Dampens the angularVelocity of the Body. More...
 
float gravityScale
 Coefficient on the continuous force of gravity. More...
 
bool magnetic
 Whether or not magnetism is set on for this Body. More...
 
float magneticStrength
 Intensity of the magnetic forces involving this Body. More...
 
bool sensor
 The sensor value for all of this Body's b2Fixtures. More...
 
float density
 The density value for all of this Body's b2Fixtures. More...
 
float friction
 The friction value for all of this Body's b2Fixtures. More...
 
float restitution
 The restitution value for all of this Body's b2Fixtures. More...
 
QQmlListProperty< Jointjoints
 List of Joint objects associated with this Body. More...
 
Properties Affected by Physics

The following group of properties are special in that their values can potentially be modified by the physics simulation. Implicit in this is that the property a user writes to them may not be the same one that is read back at a later time.

Furthermore, each of their respective "property changed" signals are only emitted when the property is explicitly set (i.e. not when they are changed by the physics simulation).

QPointF position
 Positional component of the b2Body's transform. More...
 
float angleInRadians
 Rotational component of the b2Body's transform, in radians. More...
 
QPointF linearVelocity
 The rate which the Bodys position changes. More...
 
float angularVelocity
 The rate which the Bodys angle changes. More...
 
- Properties inherited from QObject
 objectName
 

Friends

class Joint
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 

Detailed Description

A QObject container for a Box2D b2Body.

Along with representing the Box2D object, this class maintains several additional properties including magnetic strength and the concept of uniform fixture properties (e.g. density, restitution, friction, sensor, etc.).

Body objects expect to be a direct child (in the QQuickItem hierarchy) of an Actor. When one places a Body as a child of an Actor, that actor's position and rotation can potentially be modified by this Body as a result of the physics simulation.

Body is a base class. Its subclasses are required to define the b2Fixture objects to be associated with this Body's b2Body.

Note
As in traditional Box2D fashion, setting a property during Box2D physics simulation is prohibited and will result in an assert in DEBUG builds and a no-op in RELEASE builds. In order to be able to set properties while the physics simulation is running (e.g. during contact callbacks), a separate queuing mechanism must be used (e.g. queuing the contact callback, which is already done automatically in C++ and required in QML).

Member Enumeration Documentation

Overarching category of how this Body interacts with the world.

Equivalent to the b2BodyType of this object.

Enumerator
StaticBody 

A non-movable Body.

Equivalent to b2BodyType::b2_staticBody.

KinematicBody 

A movable Body that is not affected by forces or collisions.

Equivalent to b2BodyType::b2_kinematicBody.

DynamicBody 

A movable Body that is affected by forces or collisions.

Equivalent to b2BodyType::b2_dynamicBody.

Constructor & Destructor Documentation

Body::Body ( QObject parent = 0)
explicit

Constructs a Body.

virtual Body::~Body ( )
virtual

Destroys a Body.

Member Function Documentation

void Body::activeChanged ( )
signal

Emitted when active changes.

Q_INVOKABLE void Body::addJoint ( Joint joint)

Add a Joint to the Body.

Parameters
jointJoint to add
void Body::angleInRadiansSet ( )
signal

Emitted when angleInRadians is set.

void Body::angularDampingChanged ( )
signal

Emitted when angularDamping changes.

void Body::angularVelocitySet ( )
signal

Emitted when angularVelocity is set.

Q_INVOKABLE void Body::applyForceToCenter ( const QPointF force)

Apply force to the associated b2Body.

Parameters
forceAmount of force to apply
Q_INVOKABLE void Body::applyTorque ( float  torque)

Apply torque to the associated b2Body.

Note
Positive values result in a counter-clockwise torque.
Parameters
torqueAmount of torque to apply
void Body::beginContact ( Body otherBody,
const QPointF normal 
)

Called when this Body has made contact with another.

Parameters
otherBodyThe other Body with which this one made contact
normalThe normal on otherBody at point of contact
void Body::bodyTypeChanged ( )
signal

Emitted when bodyType changes.

Q_INVOKABLE void Body::clearAllAttachedJoints ( )

Destroys all Joints associated with this Body, whether or not this Body is the Joint's parent.

Note
Destroyed Joints are removed from their parent Body.
Q_INVOKABLE void Body::clearJoints ( )

Clear all the Joints owned by this Body.

void Body::contactBegun ( Body otherBody,
QPointF  normal 
)
signal

Emitted when a contact begins.

Note
Sometimes multiple calls to beginContact are made referring to the same event. In these cases, this signal is still emitted only once.
Parameters
otherBodyThe other Body with which this one made contact
normalThe normal on otherBody at point of contact
void Body::contactEnded ( Body otherBody,
QPointF  normal 
)
signal

Emitted when a contact ends.

Note
Sometimes multiple calls to endContact are made referring to the same event. In these cases, this signal is still emitted only once.
Parameters
otherBodyThe other Body with which this one lost contact
normalThe normal on otherBody at point of contact
void Body::densityChanged ( )
signal

Emitted when density changes.

void Body::endContact ( Body otherBody,
const QPointF normal 
)

Called when this Body loses contact with another.

Parameters
otherBodyThe other Body with which this one lost contact
normalThe normal on otherBody at point of contact
void Body::forEachFixture ( const std::function< void(b2Fixture *)> &  func)
protected

Applies func to each of the Body's fixtures.

Parameters
funcFunction to apply
virtual void Body::forEachShape ( const std::function< void(b2Shape *)> &  func)
inlinevirtual

Calls func on the complete set of b2Shapes that represent this Body.

Parameters
funcFunction to call, which receives the b2Shape as an argument

Reimplemented in PolygonBody, and CircleBody.

void Body::frictionChanged ( )
signal

Emitted when friction changes.

Actor* Body::getActor ( ) const

Returns actor.

float Body::getAngleInRadians ( ) const

Returns angleInRadians.

float Body::getAngularDamping ( ) const

Returns angularDamping.

float Body::getAngularVelocity ( ) const

Returns angularVelocity.

b2Body* Body::getBody ( )
inline

Returns the b2Body associated with this Body.

BodyType Body::getBodyType ( ) const

Returns bodyType.

QList<Body*> Body::getContactedBodies ( ) const

Returns a QList containing the list of Bodys in contact with this Body.

float Body::getDensity ( ) const
inline

Returns density.

float Body::getFriction ( ) const
inline

Returns friction.

float Body::getGravityScale ( ) const

Returns gravityScale.

Q_INVOKABLE Joint* Body::getJoint ( int  index)
inline

Returns a Joint at a given index.

Parameters
indexIndex of Joint to return
Q_INVOKABLE int Body::getJointCount ( ) const
inline

Returns the number of Joints associated with this Body.

QQmlListProperty<Joint> Body::getJointListProperty ( )

Returns joints as a QQmlListProperty<Joint>.

const QList<Joint*>& Body::getJoints ( ) const
inline

Returns joints as a const QList<Joint*>&.

float Body::getLinearDamping ( ) const

Returns linearDamping.

QPointF Body::getLinearVelocity ( ) const

Returns linearVelocity.

float Body::getMagneticStrength ( ) const
inline

Returns magneticStrength.

QPointF Body::getPosition ( ) const

Returns position.

float Body::getRestitution ( ) const
inline

Returns restitution.

void Body::gravityScaleChanged ( )
signal

Emitted when gravityScale changes.

void Body::invalidateFixtures ( )
inlineprotected

Marks the Body's fixtures as dirty and that they need to be recreated.

void Body::invalidateTransform ( )
inline

Marks the transform for this Body as dirty.

This informs updateBeforePhysics() whether it's necessary to set this b2Body's transform.

bool Body::isActive ( ) const

Returns active.

bool Body::isMagnetic ( ) const
inline

Returns magnetic.

bool Body::isSensor ( ) const
inline

Returns sensor.

void Body::jointsChanged ( )
signal

Emitted when joints changes.

void Body::linearDampingChanged ( )
signal

Emitted when linearDamping changes.

void Body::linearVelocitySet ( )
signal

Emitted when linearVelocity is set.

void Body::magneticChanged ( )
signal

Emitted when magnetic changes.

void Body::magneticStrengthChanged ( )
signal

Emitted when magneticStrength changes.

void Body::positionSet ( )
signal

Emitted when position is set.

void Body::queuedContactBegun ( Body otherBody,
QPointF  normal 
)
signal

Queued version of contactBegun().

Rather than triggering immediately, the connected slot will be called in a queued fashion, using Qt::QueuedConnection.

Parameters
otherBodyThe other Body with which this one made contact
normalThe normal on otherBody at point of contact
void Body::queuedContactEnded ( Body otherBody,
QPointF  normal 
)
signal

Queued version of contactEnded().

Rather than triggering immediately, the connected slot will be called in a queued fashion, using Qt::QueuedConnection.

Parameters
otherBodyThe other Body with which this one lost contact
normalThe normal on otherBody at point of contact
Q_INVOKABLE void Body::removeJoint ( Joint joint)

Remove a Joint from the Body.

Parameters
jointJoint to remove
void Body::restitutionChanged ( )
signal

Emitted when restitution changes.

void Body::sensorChanged ( )
signal

Emitted when sensor changes.

void Body::setActive ( bool  value)

Sets active.

Parameters
valueBoolean to set active to
void Body::setAngleInRadians ( float  value)

Sets angleInRadians.

Parameters
valueFloat to set angleInRadians to
void Body::setAngularDamping ( float  value)

Sets angularDamping.

Parameters
valueFloat to set angularDamping to
void Body::setAngularVelocity ( float  value)

Sets angularVelocity.

Parameters
valueFloat to set angularVelocity to
void Body::setBodyType ( BodyType  value)

Sets bodyType.

Parameters
valueBodyType to set bodyType to
void Body::setDensity ( float  value)

Sets density.

Parameters
valueFloat to set density to
void Body::setFriction ( float  value)

Sets friction.

Parameters
valueFloat to set friction to
void Body::setGravityScale ( float  value)

Sets gravityScale.

Parameters
valueFloat to set gravityScale to
void Body::setJoints ( const QList< Joint * > &  value)

Sets joints.

Parameters
valueQList<Joint*> to set joints to
void Body::setLinearDamping ( float  value)

Sets linearDamping.

Parameters
valueFloat to set linearDamping to
void Body::setLinearVelocity ( const QPointF value)

Sets linearVelocity.

Parameters
valueQPointF to set linearVelocity to
void Body::setMagnetic ( bool  value)

Sets magnetic.

Parameters
valueBoolean to set magnetic to
void Body::setMagneticStrength ( float  value)

Sets magneticStrength.

Parameters
valueFloat to set magneticStrength to
void Body::setPosition ( const QPointF value)

Sets position.

Parameters
valueQPointF to set position to
void Body::setRestitution ( float  value)

Sets restitution.

Parameters
valueFloat to set restitution to
void Body::setSensor ( bool  value)

Sets sensor.

Parameters
valueBoolean to set sensor to
virtual void Body::updateAfterPhysics ( )
virtual

Called immediately following the physics step.

Pushes the pertinent Box2D data to this object's data.

virtual void Body::updateBeforePhysics ( )
virtual

Called immediately preceding the physics step.

Pushes this object's data to the Box2D data.

Property Documentation

bool Body::active
readwrite

Whether or not the Body takes part in the physics simulation.

Equivalent to the b2Body's active property.

Actor Body::actor
read

Actor object associated with this Body. Always the parent in the item hierarchy.

float Body::angleInRadians
readwrite

Rotational component of the b2Body's transform, in radians.

float Body::angularDamping
readwrite

Dampens the angularVelocity of the Body.

Equivalent to the b2Body's angular damping property.

float Body::angularVelocity
readwrite

The rate which the Bodys angle changes.

Equivalent to the b2Body's angular velocity.

Note
Positive values result in a counter-clockwise rotation.
BodyType Body::bodyType
readwrite

BodyType of this Body.

float Body::density
readwrite

The density value for all of this Body's b2Fixtures.

float Body::friction
readwrite

The friction value for all of this Body's b2Fixtures.

float Body::gravityScale
readwrite

Coefficient on the continuous force of gravity.

Equivalent to the b2Body's gravity scale property.

QQmlListProperty<Joint> Body::joints
read

List of Joint objects associated with this Body.

float Body::linearDamping
readwrite

Dampens the linearVelocity of the Body.

Equivalent to the b2Body's linear damping property.

QPointF Body::linearVelocity
readwrite

The rate which the Bodys position changes.

Equivalent to the b2Body's linear velocity.

bool Body::magnetic
readwrite

Whether or not magnetism is set on for this Body.

Magnetism is a pseudo-physical effect in the system that causes forces to be applied between all nearby Bodys that have this value set to true. The actual behavior for it defined elsewhere in MagneticAttractorLogic.

float Body::magneticStrength
readwrite

Intensity of the magnetic forces involving this Body.

QPointF Body::position
readwrite

Positional component of the b2Body's transform.

float Body::restitution
readwrite

The restitution value for all of this Body's b2Fixtures.

bool Body::sensor
readwrite

The sensor value for all of this Body's b2Fixtures.

A true value implies that this is a Body which generates contacts but has no restitution forces applied to it or the Body it contacts.