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

A special VGroup that sets up a physics world and updates VPhysicsObjects. It doesn't handle rendering except for debugging, nor does it update the VObject. More...

#include <VPhysicsGroup.h>

Inheritance diagram for VPhysicsGroup:
VGroup VBase

Public Types

enum  VPhysicsCallbackType { BEGIN, PRESOLVE, POSTSOLVE, SEPARATE }
 The types of collision callback. More...
 
typedef VGroup VSUPERCLASS
 Used to call parent class functions when they are overrided in class.
 
- Public Types inherited from VGroup
typedef VBase VSUPERCLASS
 Used to call parent class functions when they are overrided in class.
 

Public Member Functions

 VPhysicsGroup (unsigned int Amount=0)
 
VPhysicsObjectAddObject (VObject *Object, VPhysicsObject::VObjectType BodyType, VPhysicsObject::VObjectShape Shape=VPhysicsObject::BOX, std::vector< sf::Vector2f > Verts={})
 
bool RemoveObject (VObject *Object)
 
VPhysicsJointBaseAddJoint (VPhysicsJointBase *Joint)
 
bool RemoveJoint (VPhysicsJointBase *Joint)
 
virtual void Destroy () override
 Destroys all VPhysicsObjects, this has no effect on the VObject that's attached to them.
 
virtual void Update (float dt) override
 
int GetIterations ()
 
void SetIterations (int Iterations)
 
sf::Vector2f GetGravity ()
 
void SetGravity (sf::Vector2f Gravity)
 
float GetDamping ()
 
void SetDamping (float Damping)
 
float GetIdleSpeedThreshold ()
 
void SetIdleSpeedThreshold (float IdleSpeedThreshold)
 
float GetSleepTimeThreshold ()
 
void SetSleepTimeThreshold (float SleepTimeThreshold)
 
float GetCollisionSlop ()
 
void SetCollisionSlop (float CollisionSlop)
 
float GetCollisionBias ()
 
void SetCollisionBias (float CollisionBias)
 
unsigned int GetCollisionPersistence ()
 
void SetCollisionPersistence (unsigned int CollisionPersistence)
 
VPhysicsCPBodyGetBody ()
 
void SetCollisionCallback (VObject *a, VObject *b, const std::function< bool(VPhysicsObject *, VPhysicsObject *)> &callback, VPhysicsCallbackType type, bool persist=false)
 
void SetCollisionCallback (VPhysicsObject *a, VPhysicsObject *b, const std::function< bool(VPhysicsObject *, VPhysicsObject *)> &callback, VPhysicsCallbackType type, bool persist=false)
 
void SetConstraintCallback (VPhysicsJointBase *joint, const std::function< void(VPhysicsJointBase *, VPhysicsObject *, VPhysicsObject *)> &callback, VPhysicsCallbackType type, bool persist=false)
 
virtual bool ProcessCallback (VPhysicsCPArbiter *arb, VPhysicsCPSpace *space, VPhysicsCallbackType type)
 
virtual void ProcessCallback (VPhysicsCPConstraint *constraint, VPhysicsCPSpace *space, VPhysicsCallbackType type)
 
- Public Member Functions inherited from VGroup
 VGroup (unsigned int maxSize=0)
 
int Length ()
 
VBaseAdd (VBase *object)
 
VBaseRemove (VBase *object, bool splice=false)
 
VBaseFirstAvailable ()
 
int FirstNULL ()
 
VBaseFirstExisting ()
 
VBaseFirstAlive ()
 
VBaseFirstDead ()
 
int CountAlive (bool Recursive=false)
 
int CountDead (bool Recursive=false)
 
VBaseGetRandom (int min=0, int max=0)
 
void ForEach (std::function< void(VBase *)> function, bool recursive=false)
 
void ForEachAlive (std::function< void(VBase *)> function, bool recursive=false)
 
void ForEachDead (std::function< void(VBase *)> function, bool recursive=false)
 
void ForEachExists (std::function< void(VBase *)> function, bool recursive=false)
 
VBaseGetGroupItem (int index)
 
template<class T >
T * GetGroupItemAsType (int index)
 
int GetIndexOfItem (VBase *object)
 
void OrganiseNULLS ()
 Sort nullptr members to the bottom of the group.
 
void Swap (int a, int b)
 
void Sort (std::function< bool(VBase *, VBase *)> func)
 
void Reverse ()
 Reverse order of group.
 
void Clear ()
 Clears the whole group (does not destroy any of the members, that must be done using the Destroy method).
 
virtual void Kill () override
 Kills all living objects before killing the group itself.
 
virtual void Revive () override
 Revives all dead objects before reviving the group itself.
 
virtual void Draw (sf::RenderTarget &RenderTarget) override
 

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.
 
- Protected Attributes inherited from VGroup
std::vector< VBase * > members
 VBase List.
 
int length = 0
 Current amount of members in the list.
 
unsigned int MaxSize = 0
 Maximum Size of the list, used if VGroup is set to have a fixed size.
 

Detailed Description

A special VGroup that sets up a physics world and updates VPhysicsObjects. It doesn't handle rendering except for debugging, nor does it update the VObject.

Member Enumeration Documentation

◆ VPhysicsCallbackType

The types of collision callback.

Enumerator
BEGIN 

Two shapes have just touched. Callbacks of this type can return a false boolean value to ignore the collision.

PRESOLVE 

The shapes are touching. Callbacks of this type can return a false boolean value to ignore the collision.

POSTSOLVE 

The shapes are touching and have been processed.

SEPARATE 

Two shapes are no longer touching for the first time.

Constructor & Destructor Documentation

◆ VPhysicsGroup()

VPhysicsGroup::VPhysicsGroup ( unsigned int  Amount = 0)
Parameters
AmountThe fixed length of the group. If 0, then the VGroup has no limit in size.

Member Function Documentation

◆ AddJoint()

VPhysicsJointBase* VPhysicsGroup::AddJoint ( VPhysicsJointBase Joint)

This functions adds a VPhysicsJointBase object to the physics world.

Parameters
JointThe Physics Joint to add into the scene, it must be already set up with both physics objects.
Returns
VPhysicsJointBase created from this function, or nullptr if creation failed.

◆ AddObject()

VPhysicsObject* VPhysicsGroup::AddObject ( VObject Object,
VPhysicsObject::VObjectType  BodyType,
VPhysicsObject::VObjectShape  Shape = VPhysicsObject::BOX,
std::vector< sf::Vector2f >  Verts = {} 
)

This functions adds a VPhysicsObject to the group. This should be used instead of the Add function unless you want to set up a VPhysicsObject yourself.

Parameters
ObjectThe game object you wish to apply physics to.
BodyTypeThis sets what type of physics body the object should have, see VObjectType for which types.
ShapeThis sets what shape the collider should have.
VertsIf Shape is set to either LINE or SHAPE, these set the points of the shape. These should be set relative to the top left of the shape.
Returns
VPhysicsObject created from this function, or nullptr if creation failed.

◆ GetBody()

VPhysicsCPBody* VPhysicsGroup::GetBody ( )
Returns
A pointer to the static body of the physics world, useful if you want to pin a physics object to the scene itself.

◆ GetCollisionBias()

float VPhysicsGroup::GetCollisionBias ( )
Returns
The bias percentage of overlap remaining unfixed after a second. Default is calculated as (1 - 0.1)^60

◆ GetCollisionPersistence()

unsigned int VPhysicsGroup::GetCollisionPersistence ( )
Returns
The number of frames/steps to keep collision solutions. Default is 3.

◆ GetCollisionSlop()

float VPhysicsGroup::GetCollisionSlop ( )
Returns
The amount of overlap between shapes that is allowed. Default is 0.1.

◆ GetDamping()

float VPhysicsGroup::GetDamping ( )
Returns
The general damping applied when objects collide. Default is 1.

◆ GetGravity()

sf::Vector2f VPhysicsGroup::GetGravity ( )
Returns
The gravity set for both axis in pixels per second (e.g. sf::Vector(0.0f, 910.0f is down). Default is 0.

◆ GetIdleSpeedThreshold()

float VPhysicsGroup::GetIdleSpeedThreshold ( )
Returns
The speed threshold to determine when a physics object should be idle. Default value is 0.

◆ GetIterations()

int VPhysicsGroup::GetIterations ( )
Returns
The accuracy of the collision iterative solver.

◆ GetSleepTimeThreshold()

float VPhysicsGroup::GetSleepTimeThreshold ( )
Returns
The time threshold to determine when a physics object should sleep. Default value is 0.

◆ ProcessCallback() [1/2]

virtual bool VPhysicsGroup::ProcessCallback ( VPhysicsCPArbiter arb,
VPhysicsCPSpace space,
VPhysicsCallbackType  type 
)
virtual

This function is called to process all the callbacks, this should only be overridden if you want to manipulate the collision response directly.

Parameters
arbThe collision arbiter, which essentially holds all the collision response infomation between two shapes.
spaceThe Physics world the collision took place in (always the one created in VPhysicsGroup).
typeThe type of callback to process.
Returns
A boolean value for the begin and presolve callbacks.

◆ ProcessCallback() [2/2]

virtual void VPhysicsGroup::ProcessCallback ( VPhysicsCPConstraint constraint,
VPhysicsCPSpace space,
VPhysicsCallbackType  type 
)
virtual

This function is called to process all the callbacks, this should only be overridden if you want to manipulate the collision response directly.

Parameters
constraintThe collision arbiter, which essentially holds all the collision response infomation between two shapes.
spaceThe Physics world the collision took place in (always the one created in VPhysicsGroup).
typeThe type of callback to process.

◆ RemoveJoint()

bool VPhysicsGroup::RemoveJoint ( VPhysicsJointBase Joint)

Removes the VPhysicsJointBase from the group and destroys it.

Parameters
JointThe physics joint you wish to be removed.

◆ RemoveObject()

bool VPhysicsGroup::RemoveObject ( VObject Object)

Removes the VPhysicsObject from the group based on it's attached VObject and destroys it, useful if you no longer have the VPhysicsObject at hand.

Parameters
ObjectThe game object that you wish to remove the physics from.

◆ SetCollisionBias()

void VPhysicsGroup::SetCollisionBias ( float  CollisionBias)
Parameters
CollisionBiasThe bias percentage of overlap remaining unfixed after a second.

◆ SetCollisionCallback() [1/2]

void VPhysicsGroup::SetCollisionCallback ( VObject a,
VObject b,
const std::function< bool(VPhysicsObject *, VPhysicsObject *)> &  callback,
VPhysicsCallbackType  type,
bool  persist = false 
)

Collision callbacks act slightly differently from VCollision. Here you can set the collision between specific objects, their callback, when the callback should be applied and whether you want the collision to be active forever or deactivated after being called once.

Parameters
aThe first object to test collisions with for the callback.
bThe second object to test collisions with for the callback. Setting this to nullptr will apply the callback between object a and anything else.
callbackThe function to call if the collision takes place, the two parameters are VPhysicsObject so you can adjust the collision properties and access the VObject at the same time.
typeThe type of collision callback to set (see VPhysicsCallbackType).
persistIf true, this callback will remain active for the duration of the space, otherwise this callback will be removed after one call. This way you aren't required to call it on each update.

◆ SetCollisionCallback() [2/2]

void VPhysicsGroup::SetCollisionCallback ( VPhysicsObject a,
VPhysicsObject b,
const std::function< bool(VPhysicsObject *, VPhysicsObject *)> &  callback,
VPhysicsCallbackType  type,
bool  persist = false 
)

Collision callbacks act slightly differently from VCollision. Here you can set the collision between specific objects, their callback, when the callback should be applied and whether you want the collision to be active forever or deactivated after being called once.

Parameters
aThe first object to test collisions with for the callback.
bThe second object to test collisions with for the callback. Setting this to nullptr will apply the callback between object a and anything else.
callbackThe function to call if the collision takes place, the two parameters are VPhysicsObject so you can adjust the collision properties and access the VObject at the same time.
typeThe type of collision callback to set (see VPhysicsCallbackType).
persistIf true, this callback will remain active for the duration of the space, otherwise this callback will be removed after one call. This way you aren't required to call it on each update.

◆ SetCollisionPersistence()

void VPhysicsGroup::SetCollisionPersistence ( unsigned int  CollisionPersistence)
Parameters
CollisionPersistenceThe number of frames/steps to keep collision solutions.

◆ SetCollisionSlop()

void VPhysicsGroup::SetCollisionSlop ( float  CollisionSlop)
Parameters
CollisionSlopThe amount of overlap between shapes that is allowed.

◆ SetConstraintCallback()

void VPhysicsGroup::SetConstraintCallback ( VPhysicsJointBase joint,
const std::function< void(VPhysicsJointBase *, VPhysicsObject *, VPhysicsObject *)> &  callback,
VPhysicsCallbackType  type,
bool  persist = false 
)

Here you can set callbacks for the pre and post solve conditions of a joint.

Parameters
jointThe joint to test the callback with.
callbackThe function to call if the joint is applied, the parameters are the VPhysicsJointBase and two VPhysicsObject so you can modify the joints or the objects.
typeThe type of callback to set (see VPhysicsCallbackType). BEGIN and SEPARATE are ignored.
persistIf true, this callback will remain active for the duration of the space, otherwise this callback will be removed after one call. This way you aren't required to call it on each update.

◆ SetDamping()

void VPhysicsGroup::SetDamping ( float  Damping)
Parameters
DampingThe general damping applied when objects collide

◆ SetGravity()

void VPhysicsGroup::SetGravity ( sf::Vector2f  Gravity)
Parameters
GravityThe gravity set for both axis in pixels per second (e.g. sf::Vector(0.0f, 910.0f is down).

◆ SetIdleSpeedThreshold()

void VPhysicsGroup::SetIdleSpeedThreshold ( float  IdleSpeedThreshold)
Parameters
IdleSpeedThresholdThe speed threshold to determine when a physics object should be idle.

◆ SetIterations()

void VPhysicsGroup::SetIterations ( int  Iterations)
Parameters
IterationsThe accuracy of the collision iterative solver in number of iterations.

◆ SetSleepTimeThreshold()

void VPhysicsGroup::SetSleepTimeThreshold ( float  SleepTimeThreshold)
Parameters
SleepTimeThresholdThe time threshold to determine when a physics object should sleep.

◆ Update()

virtual void VPhysicsGroup::Update ( float  dt)
overridevirtual

Updates all the VPhysicsObjects.

Parameters
dtDelta Time

Reimplemented from VGroup.


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