Physics - simple-entertainment/simplicity GitHub Wiki

Simplicity does not provide any physics implementations, it only provides interfaces. To include physics in your game you'll need to use one of the physics plugins like Bullet or PhysX. Alternatively you could create your own!

Bodies are Components!

If you want a body to be included in physics calculations, just add it to an entity!

std::unique_ptr<Entity> entity(new Entity);
std::unique_ptr<Body> body = // Some body...
entity->addUniqueComponent(move(body));
Simplicity::getScene()->addEntity(move(entity));

Bodies and the Physics Factory

Bodies need to be constructed using the physics factory since the implementation of a body is dependent on the physics plugin being used e.g. Bullet or PhysX.

Body::Material material;
// Set-up the material as needed...
std::unique_ptr<Model> model = // Some model...
Matrix44 transform;
// Set the position and orientation...
bool dynamic = true;
std::unique_ptr<Body> body = PhysicsFactory::getInstance()->createBody(material, model.get(), transform, dynamic);

Applying Forces

Just by creating a body as shown above and adding it to an entity you've got physics working! Woo hoo! Want to push things around?

Vector3 force(10.0f, 0.0f, 0.0f);
Vector3 position(0.0f, 0.0f, 0.0f);
body->applyForce(force, position); // Apply the given force to the center of the body.
⚠️ **GitHub.com Fallback** ⚠️