ChirpSim
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
PushableObject Class Reference

The PushableObject class represents a physical object that other objects can push around. More...

#include <pushableobject.h>

Inheritance diagram for PushableObject:
Inheritance graph

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...
 
- Public Member Functions inherited from PhysicalObject
 PhysicalObject ()
 
virtual ~PhysicalObject ()
 

Private Member Functions

void ComputeBoundingRect ()
 
void applyFriction ()
 

Private Attributes

b2Body * _body
 
QRectF _boundingRect
 

Friends

PhysicalObjectpushableObjectFactory (World *world, const QJsonObject &obj)
 chirpFactory follows the PhysicalObject FactoryFunction, creating the PushableObject object from a QJsonObject. More...
 

Detailed Description

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:

wall.png

Constructor & Destructor Documentation

PushableObject::PushableObject ( b2World *  world,
QList< QList< QPointF > >  hulls,
float  density,
QPointF  position,
float  angle 
)
explicit

Constructor creating an PushableObject object based on a number of parameters.

Parameters
worldWorld for the pushable object to be created in.
hullsList 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.
Note
Vertices must be in counterclockwise order, and must form a convex hull.
Parameters
densityDensity of the object. Decides the mass of the body based on the area of the shapes.
positionStarting position of the pushable object.
angleStarting 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().

Here is the call graph for this function:

PushableObject::~PushableObject ( )

Member Function Documentation

void PushableObject::applyFriction ( )
private

Referenced by step().

Here is the caller graph for this function:

b2Body* PushableObject::body ( ) const
inlinevirtual

Simple getter for _body field. From the PhysicalObject interface class.

Returns
Physical representation of object used by b2World 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.

Returns
bounding rectangle.

References _boundingRect.

void PushableObject::ComputeBoundingRect ( )
private

References _body, and _boundingRect.

Referenced by PushableObject().

Here is the caller graph for this function:

QGraphicsItem* PushableObject::item ( ) const
inlinevirtual

Simple getter for returning QGraphicsItem connected to this object. From the PhysicalObject interface class.

Returns
this casted to a non-const pointer.

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().

Here is the call graph for this function:

void PushableObject::step ( float  dt)
virtual

step updates the position of the object as it gets pushed around.

Parameters
dttime in seconds passed since last step.

Reimplemented from PhysicalObject.

References applyFriction().

Here is the call graph for this function:

void PushableObject::stepGraphics ( )
virtual

Updates the viewable model of the object to reflect the current world state.

Reimplemented from PhysicalObject.

References _body, and RADTODEG.

Friends And Related Function Documentation

PhysicalObject* pushableObjectFactory ( World world,
const QJsonObject &  obj 
)
friend

chirpFactory follows the PhysicalObject FactoryFunction, creating the PushableObject object from a QJsonObject.

See Also
physicalobjectfactory.h
Parameters
worldWorld to put the physical object model in.
objJsonObject containing the parameters for the object.
Returns
A constructed PushableObject object.

Member Data Documentation

b2Body* PushableObject::_body
private
QRectF PushableObject::_boundingRect
private

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