Calamity Engine 1.0.0
A cross-platform 2D game engine written in C++ and SDL3.
Loading...
Searching...
No Matches
PhysicsBody Class Referenceabstract

#include <physics.hpp>

Inheritance diagram for PhysicsBody:
Component KinematicBody RigidBody StaticBody

Public Member Functions

void exit () override
 
virtual void physicsUpdate ()=0
 
void initialize () override
 
virtual void initCompute ()
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 
b2BodyId getBodyId ()
 
b2ShapeId getShapeId ()
 
- Public Member Functions inherited from Component
virtual ~Component ()=default
 
virtual void update (float deltaTime)
 
virtual void render (std::shared_ptr< Window > window)
 
virtual void input (InputEvent &event)
 
virtual void postLoad ()
 
NodegetNode () const
 
void setNode (Node *n)
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 

Public Attributes

Signal< PhysicsBody * > collisionEnter
 
Signal< PhysicsBody * > collisionExit
 
Signal< PhysicsBody * > collisionHit
 
Signal mouseEntered
 
Signal mouseExited
 
std::shared_ptr< Shapeshape
 

Protected Attributes

bool sensor
 
b2BodyDef bodyDef
 
b2BodyId bodyId
 
b2ShapeId shapeId
 
Transform storedTransform
 

Detailed Description

PhysicsBody

The base PhysicsBody class defines the Shape, functions and signals that are the base of every physics body.

Properties and usages

You can connect callbacks onto the collision signals of the physics body:

physicsBody->collisionEnter.connect([](PhysicsBody *other) {
// do something when this body collides with another body
});
// there are also colisionExit and collisionHit (when the body is hit by another body at terminal velocity).
Definition physics.hpp:58

There are also signals for when the mouse enters and leaves the body, which are very useful for UI elements.

physicsBody->mouseEntered.connect([]() {
// do something when the mouse enters the body
});
// there is also mouseExited for when the mouse leaves the body.

For more information, take a look at the button example.

Member Function Documentation

◆ exit()

void PhysicsBody::exit ( )
overridevirtual

Reimplemented from Component.

◆ getBodyId()

b2BodyId PhysicsBody::getBodyId ( )
inline

◆ getShapeId()

b2ShapeId PhysicsBody::getShapeId ( )
inline

◆ initCompute()

void PhysicsBody::initCompute ( )
virtual

Reimplemented in StaticBody, RigidBody, and KinematicBody.

◆ initialize()

void PhysicsBody::initialize ( )
overridevirtual

Reimplemented from Component.

◆ load()

template<class Archive >
void PhysicsBody::load ( Archive &  ar)
inline

◆ physicsUpdate()

virtual void PhysicsBody::physicsUpdate ( )
pure virtual

Reimplemented from Component.

Implemented in StaticBody, RigidBody, and KinematicBody.

◆ save()

template<class Archive >
void PhysicsBody::save ( Archive &  ar) const
inline

Member Data Documentation

◆ bodyDef

b2BodyDef PhysicsBody::bodyDef
protected

◆ bodyId

b2BodyId PhysicsBody::bodyId
protected

◆ collisionEnter

Signal<PhysicsBody *> PhysicsBody::collisionEnter

◆ collisionExit

Signal<PhysicsBody *> PhysicsBody::collisionExit

◆ collisionHit

Signal<PhysicsBody *> PhysicsBody::collisionHit

◆ mouseEntered

Signal PhysicsBody::mouseEntered

◆ mouseExited

Signal PhysicsBody::mouseExited

◆ sensor

bool PhysicsBody::sensor
protected

◆ shape

std::shared_ptr<Shape> PhysicsBody::shape

◆ shapeId

b2ShapeId PhysicsBody::shapeId
protected

◆ storedTransform

Transform PhysicsBody::storedTransform
protected

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