Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "phys.hpp"
- namespace rg {
- namespace phys {
- Body::Body(World& world) : m_world(world), m_pos(), m_aabb() {}
- Body::~Body() {
- m_world.free_body(this);
- }
- World::World() {}
- World::~World() {}
- void World::step(const unit_t& seconds) {
- for (auto& body : m_bodies) {
- body->pos().x += body->velocity().x * seconds;
- body->pos().y += body->velocity().y * seconds;
- std::cout << "Body #" << static_cast<void*>(body.get()) << " x:" << body->pos().x << " y:" << body->pos().y << std::endl;
- }
- }
- std::shared_ptr<Body> World::create_body() {
- // auto body = std::make_shared<Body>(*this);
- std::shared_ptr<Body> body (new Body(*this));
- m_bodies.push_back(body);
- std::cout << "Body created at " << body.get() << std::endl;
- for (auto b : m_bodies) {
- std::cout << "\tNow there are " << b.get() << std::endl;
- }
- return body;
- }
- void World::free_body(const Body* body) {
- std::cout << "Free body at " << body << std::endl;
- m_bodies.remove_if([body](const std::shared_ptr<Body>& ptr) { return ptr.get() == body; });
- }
- }
- }
Add Comment
Please, Sign In to add comment