The PushableObject class represents a physical object that other objects can push around. More...
#include <pushableobject.h>
Public Member Functions | |
PushableObject (b2World *world, QList< QList< QPointF > > hulls, float density, QPointF position, float angle) | |
Constructor creating an PushableObject object based on a number of parameters. More... | |
~PushableObject () | |
QRectF | boundingRect () const |
boundingRect returns the computed bounding rectangle used for drawing and redrawing the object. From the QGraphicsItem abstract base class. More... | |
void | paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
paint Draws the object for display. From the QGraphicsItem abstract base class. More... | |
b2Body * | body () const |
Simple getter for _body field. From the PhysicalObject interface class. More... | |
QGraphicsItem * | item () const |
Simple getter for returning QGraphicsItem connected to this object. From the PhysicalObject interface class. More... | |
void | step (float dt) |
step updates the position of the object as it gets pushed around. More... | |
void | stepGraphics () |
Updates the viewable model of the object to reflect the current world state. More... | |
![]() | |
PhysicalObject () | |
virtual | ~PhysicalObject () |
Private Member Functions | |
void | ComputeBoundingRect () |
void | applyFriction () |
Private Attributes | |
b2Body * | _body |
QRectF | _boundingRect |
Friends | |
PhysicalObject * | pushableObjectFactory (World *world, const QJsonObject &obj) |
chirpFactory follows the PhysicalObject FactoryFunction, creating the PushableObject object from a QJsonObject. More... | |
The PushableObject class represents a physical object that other objects can push around.
The PushableObject class represents a physical object that other objects can push around. It implements a very basic friction model to stop it from just sliding off if nudged at all.
The pushable object in simulation:
|
explicit |
Constructor creating an PushableObject object based on a number of parameters.
world | World for the pushable object to be created in. |
hulls | List of hulls forming the shape of the object. Each hull forms a separate collision mesh, allowing simulation of a concave hull through making them a series of convex hulls. |
density | Density of the object. Decides the mass of the body based on the area of the shapes. |
position | Starting position of the pushable object. |
angle | Starting angle of the pushable object. |
Creates a physical model of the pushable object with Box2D and sets up the drawing of the object.
References _body, ComputeBoundingRect(), DEGTORAD, and QPointFTob2Vec2().
PushableObject::~PushableObject | ( | ) |
|
private |
|
inlinevirtual |
Simple getter for _body field. From the PhysicalObject interface class.
Implements PhysicalObject.
References _body.
QRectF PushableObject::boundingRect | ( | ) | const |
boundingRect returns the computed bounding rectangle used for drawing and redrawing the object. From the QGraphicsItem abstract base class.
References _boundingRect.
|
private |
References _body, and _boundingRect.
Referenced by PushableObject().
|
inlinevirtual |
Simple getter for returning QGraphicsItem connected to this object. From the PhysicalObject interface class.
Implements PhysicalObject.
void PushableObject::paint | ( | QPainter * | painter, |
const QStyleOptionGraphicsItem * | option, | ||
QWidget * | widget | ||
) |
paint Draws the object for display. From the QGraphicsItem abstract base class.
References _body, and genericPaint().
|
virtual |
step updates the position of the object as it gets pushed around.
dt | time in seconds passed since last step. |
Reimplemented from PhysicalObject.
References applyFriction().
|
virtual |
Updates the viewable model of the object to reflect the current world state.
Reimplemented from PhysicalObject.
|
friend |
chirpFactory follows the PhysicalObject FactoryFunction, creating the PushableObject object from a QJsonObject.
world | World to put the physical object model in. |
obj | JsonObject containing the parameters for the object. |
|
private |
Referenced by body(), ComputeBoundingRect(), paint(), PushableObject(), and stepGraphics().
|
private |
Referenced by boundingRect(), and ComputeBoundingRect().