22 #include <QQmlListProperty>
525 virtual void forEachShape(
const std::function<
void(b2Shape*)>& func) { (void) func; }
659 b2BodyDef getBodyDef();
660 b2FixtureDef getFixtureDef();
661 void addFixtures(b2FixtureDef* def);
662 void createFixtures();
663 void destroyFixtures();
670 void registerAttachedJoint(
Joint* joint);
671 void unregisterAttachedJoint(
Joint* joint);
681 mutable Actor* mActor =
nullptr;
683 b2Body* mBody =
nullptr;
684 bool mFixturesDirty =
true;
685 bool mTransformDirty =
true;
687 bool mMagnetic =
false;
688 float mMagneticStrength = 1.0f;
690 bool mIsSensor =
false;
691 float mDensity = 1.0f;
692 float mFriction = 0.3f;
693 float mRestitution = 0.3f;
699 Q_DECLARE_METATYPE(
Body*)
Q_INVOKABLE void addJoint(Joint *joint)
Add a Joint to the Body.
void beginContact(Body *otherBody, const QPointF &normal)
Called when this Body has made contact with another.
float density
The density value for all of this Body's b2Fixtures.
Definition: Body.h:173
float getGravityScale() const
Returns gravityScale.
Q_INVOKABLE void clearAllAttachedJoints()
Destroys all Joints associated with this Body, whether or not this Body is the Joint's parent...
QQmlListProperty< Joint > joints
List of Joint objects associated with this Body.
Definition: Body.h:188
bool active
Whether or not the Body takes part in the physics simulation.
Definition: Body.h:75
void queuedContactEnded(Body *otherBody, QPointF normal)
Queued version of contactEnded().
float getAngleInRadians() const
Returns angleInRadians.
void bodyTypeChanged()
Emitted when bodyType changes.
void setLinearDamping(float value)
Sets linearDamping.
void magneticStrengthChanged()
Emitted when magneticStrength changes.
void setAngularVelocity(float value)
Sets angularVelocity.
float getDensity() const
Returns density.
Definition: Body.h:382
bool magnetic
Whether or not magnetism is set on for this Body.
Definition: Body.h:108
A QObject container for a Box2D b2Body.
Definition: Body.h:57
A movable Body that is affected by forces or collisions.
Definition: Body.h:219
Q_INVOKABLE Joint * getJoint(int index)
Returns a Joint at a given index.
Definition: Body.h:432
void frictionChanged()
Emitted when friction changes.
void invalidateTransform()
Marks the transform for this Body as dirty.
Definition: Body.h:486
float linearDamping
Dampens the linearVelocity of the Body.
Definition: Body.h:83
float magneticStrength
Intensity of the magnetic forces involving this Body.
Definition: Body.h:114
bool isMagnetic() const
Returns magnetic.
Definition: Body.h:295
Q_INVOKABLE void applyForceToCenter(const QPointF &force)
Apply force to the associated b2Body.
float getAngularVelocity() const
Returns angularVelocity.
Q_INVOKABLE void applyTorque(float torque)
Apply torque to the associated b2Body.
const QList< Joint * > & getJoints() const
Returns joints as a const QList&.
Definition: Body.h:415
float getMagneticStrength() const
Returns magneticStrength.
Definition: Body.h:306
void setActive(bool value)
Sets active.
void setAngleInRadians(float value)
Sets angleInRadians.
void positionSet()
Emitted when position is set.
void sensorChanged()
Emitted when sensor changes.
Q_INVOKABLE void removeJoint(Joint *joint)
Remove a Joint from the Body.
void angleInRadiansSet()
Emitted when angleInRadians is set.
float angularVelocity
The rate which the Bodys angle changes.
Definition: Body.h:156
QQmlListProperty< Joint > getJointListProperty()
Returns joints as a QQmlListProperty.
BodyType
Overarching category of how this Body interacts with the world.
Definition: Body.h:198
virtual void updateAfterPhysics()
Called immediately following the physics step.
void gravityScaleChanged()
Emitted when gravityScale changes.
void setSensor(bool value)
Sets sensor.
QPointF getLinearVelocity() const
Returns linearVelocity.
void forEachFixture(const std::function< void(b2Fixture *)> &func)
Applies func to each of the Body's fixtures.
Body(QObject *parent=0)
Constructs a Body.
QVariant property(const char *name) const
void setAngularDamping(float value)
Sets angularDamping.
QPointF linearVelocity
The rate which the Bodys position changes.
Definition: Body.h:147
float angleInRadians
Rotational component of the b2Body's transform, in radians.
Definition: Body.h:139
void setMagnetic(bool value)
Sets magnetic.
Q_INVOKABLE int getJointCount() const
Returns the number of Joints associated with this Body.
Definition: Body.h:437
void contactEnded(Body *otherBody, QPointF normal)
Emitted when a contact ends.
void linearDampingChanged()
Emitted when linearDamping changes.
QPointF getPosition() const
Returns position.
virtual ~Body()
Destroys a Body.
void angularDampingChanged()
Emitted when angularDamping changes.
void setDensity(float value)
Sets density.
A non-movable Body.
Definition: Body.h:205
QList< Body * > getContactedBodies() const
Returns a QList containing the list of Bodys in contact with this Body.
bool sensor
The sensor value for all of this Body's b2Fixtures.
Definition: Body.h:168
QPointF position
Positional component of the b2Body's transform.
Definition: Body.h:133
void densityChanged()
Emitted when density changes.
bool isActive() const
Returns active.
void setBodyType(BodyType value)
Sets bodyType.
void setJoints(const QList< Joint * > &value)
Sets joints.
void setFriction(float value)
Sets friction.
void setLinearVelocity(const QPointF &value)
Sets linearVelocity.
float gravityScale
Coefficient on the continuous force of gravity.
Definition: Body.h:99
void setPosition(const QPointF &value)
Sets position.
void endContact(Body *otherBody, const QPointF &normal)
Called when this Body loses contact with another.
b2Body * getBody()
Returns the b2Body associated with this Body.
Definition: Body.h:466
float friction
The friction value for all of this Body's b2Fixtures.
Definition: Body.h:178
void invalidateFixtures()
Marks the Body's fixtures as dirty and that they need to be recreated.
Definition: Body.h:531
float getFriction() const
Returns friction.
Definition: Body.h:393
A movable Body that is not affected by forces or collisions.
Definition: Body.h:212
void setGravityScale(float value)
Sets gravityScale.
void restitutionChanged()
Emitted when restitution changes.
Q_INVOKABLE void clearJoints()
Clear all the Joints owned by this Body.
float getAngularDamping() const
Returns angularDamping.
Actor actor
Actor object associated with this Body. Always the parent in the item hierarchy.
Definition: Body.h:63
float angularDamping
Dampens the angularVelocity of the Body.
Definition: Body.h:91
void setRestitution(float value)
Sets restitution.
Representation of an entity within the Game scene.
Definition: Actor.h:40
BodyType bodyType
BodyType of this Body.
Definition: Body.h:68
float getLinearDamping() const
Returns linearDamping.
virtual void forEachShape(const std::function< void(b2Shape *)> &func)
Calls func on the complete set of b2Shapes that represent this Body.
Definition: Body.h:525
bool isSensor() const
Returns sensor.
Definition: Body.h:371
void setMagneticStrength(float value)
Sets magneticStrength.
void queuedContactBegun(Body *otherBody, QPointF normal)
Queued version of contactBegun().
void jointsChanged()
Emitted when joints changes.
A constraint between two Bodys.
Definition: Joint.h:28
virtual void updateBeforePhysics()
Called immediately preceding the physics step.
Actor * getActor() const
Returns actor.
float getRestitution() const
Returns restitution.
Definition: Body.h:404
float restitution
The restitution value for all of this Body's b2Fixtures.
Definition: Body.h:183
void magneticChanged()
Emitted when magnetic changes.
void contactBegun(Body *otherBody, QPointF normal)
Emitted when a contact begins.
BodyType getBodyType() const
Returns bodyType.
void activeChanged()
Emitted when active changes.
void linearVelocitySet()
Emitted when linearVelocity is set.
void angularVelocitySet()
Emitted when angularVelocity is set.