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

#include <physics.hpp>

Inheritance diagram for KinematicBody:
PhysicsBody Component

Public Member Functions

 KinematicBody ()
 
 KinematicBody (const std::shared_ptr< Shape > &shape)
 
void physicsUpdate () override
 
void initCompute () override
 
void setLinearVelocity (Vector2 vel) const
 
void applyForce (Vector2 force) const
 
void applyImpulse (Vector2 impulse) const
 
Vector2 getLinearVelocity () const
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 
- Public Member Functions inherited from PhysicsBody
void exit () override
 
void initialize () override
 
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)
 

Additional Inherited Members

- Public Attributes inherited from PhysicsBody
Signal< PhysicsBody * > collisionEnter
 
Signal< PhysicsBody * > collisionExit
 
Signal< PhysicsBody * > collisionHit
 
Signal mouseEntered
 
Signal mouseExited
 
std::shared_ptr< Shapeshape
 
- Protected Attributes inherited from PhysicsBody
bool sensor
 
b2BodyDef bodyDef
 
b2BodyId bodyId
 
b2ShapeId shapeId
 
Transform storedTransform
 

Detailed Description

KinematicBody

The KinematicBody component is a type of PhysicsBody. The main difference between KinematicBody and any other physics body is that it does not move, at all, unless it is moved by a force or impulse or its linear velocity.

Like any other physics body, once it is attached to a node, you must not move the node through its transform property.

Example usage:

std::shared_ptr<Node> myNode = std::make_shared<Node>();
std::shared_ptr<Shape> myShape = std::make_shared<CircleShape>(20.0f); // Create a circle with a 20 pixel radius
std::shared_ptr<KinematicBody> kinematicBody = std::make_shared<KinematicBody>(myShape);
myNode->addComponent(kinematicBody);
myNode->addComponent(std::make_shared<ShapeSprite>(myShape)); // also add a ShapeSprite for rendering!
// later on, after the node is initialized, you can move the kinematic body by setting the linear velocity or applying impulses/forces:
kinematicBody->setLinearVelocity(Vector2{100.0f, 100.0f});
Definition definitions.hpp:77

For more insight regarding anything physics related, the physics example and node tree example also utilize staticbodies!

Constructor & Destructor Documentation

◆ KinematicBody() [1/2]

KinematicBody::KinematicBody ( )

◆ KinematicBody() [2/2]

KinematicBody::KinematicBody ( const std::shared_ptr< Shape > &  shape)
explicit

Member Function Documentation

◆ applyForce()

void KinematicBody::applyForce ( Vector2  force) const

◆ applyImpulse()

void KinematicBody::applyImpulse ( Vector2  impulse) const

◆ getLinearVelocity()

Vector2 KinematicBody::getLinearVelocity ( ) const

◆ initCompute()

void KinematicBody::initCompute ( )
overridevirtual

Reimplemented from PhysicsBody.

◆ load()

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

◆ physicsUpdate()

void KinematicBody::physicsUpdate ( )
overridevirtual

Implements PhysicsBody.

◆ save()

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

◆ setLinearVelocity()

void KinematicBody::setLinearVelocity ( Vector2  vel) const

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