Vigilante Game Framework  1.0.0.8
A 2D/3D C++ Game Framework using SFML.
Public Types | Public Member Functions | Protected Attributes | List of all members
VPhysicsObject Class Reference

A special object class that represents the physics body that responds to the world and collisions using a specified shape, should be used by adding to VPhysicsGroup. More...

#include <VPhysicsObject.h>

Inheritance diagram for VPhysicsObject:
VBase

Public Types

enum  VObjectShape { CIRCLE, BOX, LINE, CUSTOM }
 The shape of the collision area of the physics object.
 
enum  VObjectType { DYNAMIC, KINEMATIC, STATIC }
 The physics type of the physics object.
 
typedef VBase VSUPERCLASS
 Used to call parent class functions when they are overrided in class.
 

Public Member Functions

 VPhysicsObject (VObject *Object, VObjectType BodyType, VObjectShape Shape=VObjectShape::BOX, std::vector< sf::Vector2f > Verts={})
 
void Initialise (VPhysicsCPSpace *space)
 
VObjectGetBaseObject ()
 
void Deinitialise (VPhysicsCPSpace *space)
 
virtual void Destroy () override
 Destroys the physics data of the object.
 
virtual void Update (float dt) override
 
VPhysicsCPBodyGetBody ()
 
VPhysicsCPShapeGetShape ()
 
VObjectShape GetShapeType ()
 
void SetBodyType (VObjectType bodyType)
 
VObjectType GetBodyType ()
 
float GetDensity ()
 
void SetDensity (float density)
 
float GetFriction ()
 
void SetFriction (float friction)
 
sf::Vector2f GetSurfaceVelocity ()
 
void SetSurfaceVelocity (sf::Vector2f surfaceVelocity)
 
sf::Vector2f GetForce ()
 
void SetForce (sf::Vector2f force)
 
float GetTorque ()
 
void SetTorque (float torque)
 
void ApplyForceAtWorldPoint (sf::Vector2f force, sf::Vector2f point)
 
void ApplyForceAtLocalPoint (sf::Vector2f force, sf::Vector2f point)
 
void ApplyImpulseAtWorldPoint (sf::Vector2f impulse, sf::Vector2f point)
 
void ApplyImpulseAtLocalPoint (sf::Vector2f impulse, sf::Vector2f point)
 
- Public Member Functions inherited from VBase
virtual void Kill ()
 
virtual void Revive ()
 Revives the object by setting both alive and exists back to true.
 
virtual void Draw (sf::RenderTarget &RenderTarget)
 

Protected Attributes

VObjectbaseObject
 The object to apply the angle and position from the physics body.
 
cpBody * body
 The physics body.
 
cpShape * shape
 The shape of the physics body.
 
unsigned int getPolyVertCount
 The amount of vertices of the shape if of type CUSTOM.
 
VObjectShape shapeType
 The type of shape of the physics object.
 
VObjectType bodyType
 The type of body of the physics object.
 

Additional Inherited Members

- Static Public Member Functions inherited from VBase
static const wchar_t * VString (const char *fmt,...)
 
static void VLog (const char *fmt,...)
 
static void VLogError (const char *fmt,...)
 
static void VClearLog ()
 
- Public Attributes inherited from VBase
bool active = true
 Base can be updated using Update if true.
 
bool visible = true
 Base can be rendered using Draw if true.
 
bool alive = true
 Helper member that is mainly used filter out behaviours to objects which aren't alive in the scene.
 
bool exists = true
 Base can be updated and rendered if true, else it would no longer be treated as being part of the scene.
 
VType type = NONE
 Base object type, typically set in the constructor of an inherited object to specify what type it is.
 
uint32_t RefCount = 0
 Counts the amount of times the object is referenced in groups, ensures an object is only destroyed when no longer part of a single group.
 

Detailed Description

A special object class that represents the physics body that responds to the world and collisions using a specified shape, should be used by adding to VPhysicsGroup.

Constructor & Destructor Documentation

◆ VPhysicsObject()

VPhysicsObject::VPhysicsObject ( VObject Object,
VObjectType  BodyType,
VObjectShape  Shape = VObjectShape::BOX,
std::vector< sf::Vector2f >  Verts = {} 
)
Parameters
ObjectThe game object to apply physics towards.
BodyTypeThe type of physics body to set the physics object to.
ShapeThe type of collision shape the object will have. Default is BOX.
VertsIf the shape set is LINE or CUSTOM, this parameter will define the shape in local space (relative to the top-left of the game object).

Member Function Documentation

◆ ApplyForceAtLocalPoint()

void VPhysicsObject::ApplyForceAtLocalPoint ( sf::Vector2f  force,
sf::Vector2f  point 
)

Applys a force towards the phyics body at a point in local space.

Parameters
forceThe force to apply.
pointThe point in local space to apply the force to.

◆ ApplyForceAtWorldPoint()

void VPhysicsObject::ApplyForceAtWorldPoint ( sf::Vector2f  force,
sf::Vector2f  point 
)

Applys a force towards the phyics body at a point in world space.

Parameters
forceThe force to apply.
pointThe point in world space to apply the force to.

◆ ApplyImpulseAtLocalPoint()

void VPhysicsObject::ApplyImpulseAtLocalPoint ( sf::Vector2f  impulse,
sf::Vector2f  point 
)

Applys an impulse towards the phyics body at a point in local space.

Parameters
impulseThe impulse to apply.
pointThe point in local space to apply the force to.

◆ ApplyImpulseAtWorldPoint()

void VPhysicsObject::ApplyImpulseAtWorldPoint ( sf::Vector2f  impulse,
sf::Vector2f  point 
)

Applys an impluse towards the phyics body at a point in world space.

Parameters
impulseThe impulse to apply.
pointThe point in world space to apply the force to.

◆ Deinitialise()

void VPhysicsObject::Deinitialise ( VPhysicsCPSpace space)

Deinitises and removes the physics object from the world.

Parameters
spaceThe physics space to remove the object from.

◆ GetBaseObject()

VObject* VPhysicsObject::GetBaseObject ( )
Returns
Gets the base game object that physics is being applied to.

◆ GetBody()

VPhysicsCPBody* VPhysicsObject::GetBody ( )
Returns
Gets the physics body as a void pointer (so it can be cast to a cpBody if necessary).

◆ GetBodyType()

VObjectType VPhysicsObject::GetBodyType ( )
Returns
The tyoe of physics body of the physics object.

◆ GetDensity()

float VPhysicsObject::GetDensity ( )
Returns
The density of the physics shape.

◆ GetForce()

sf::Vector2f VPhysicsObject::GetForce ( )
Returns
The force of the physics body.

◆ GetFriction()

float VPhysicsObject::GetFriction ( )
Returns
The friction of the physics shape.

◆ GetShape()

VPhysicsCPShape* VPhysicsObject::GetShape ( )
Returns
Gets the physics shape as a void pointer (so it can be cast to a cpShape if necessary).

◆ GetShapeType()

VObjectShape VPhysicsObject::GetShapeType ( )
Returns
The type of shape of the physics object.

◆ GetSurfaceVelocity()

sf::Vector2f VPhysicsObject::GetSurfaceVelocity ( )
Returns
The surface velocity of the physics shape.

◆ GetTorque()

float VPhysicsObject::GetTorque ( )
Returns
The torque of the physics body.

◆ Initialise()

void VPhysicsObject::Initialise ( VPhysicsCPSpace space)

Initialises the physics object.

Parameters
spaceThe physics space to initialise the object to.

◆ SetBodyType()

void VPhysicsObject::SetBodyType ( VObjectType  bodyType)

Set the physics body of the object.

Parameters
bodyTypeThe new phyiscs body type.

◆ SetDensity()

void VPhysicsObject::SetDensity ( float  density)

Sets the shape density.

Parameters
densityThe new density value of the physics shape.

◆ SetForce()

void VPhysicsObject::SetForce ( sf::Vector2f  force)

Sets the force of the physics body.

Parameters
forceThe new force value of the physics body.

◆ SetFriction()

void VPhysicsObject::SetFriction ( float  friction)

Sets the shape friction.

Parameters
frictionThe new friction value of the physics shape.

◆ SetSurfaceVelocity()

void VPhysicsObject::SetSurfaceVelocity ( sf::Vector2f  surfaceVelocity)

Sets the surface velocity of the physics shape.

Parameters
surfaceVelocityThe new surface velocity of the physics shape.

◆ SetTorque()

void VPhysicsObject::SetTorque ( float  torque)

Sets the torque of the physics body.

Parameters
torqueThe new torque of the physics body.

◆ Update()

virtual void VPhysicsObject::Update ( float  dt)
overridevirtual

Updates the physics object.

Parameters
dtThe delta time between the previous and current frame.

Reimplemented from VBase.


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