collisions are working ok with user defined offsets

This commit is contained in:
Clément Le Bihan
2021-06-07 23:37:51 +02:00
parent 8203532d52
commit 65af11f3f9
7 changed files with 85 additions and 31 deletions

View File

@@ -10,13 +10,16 @@
#include "Component/Renderer/Drawable2DComponent.hpp"
#include "Drawables/ADrawable3D.hpp"
#include "Component/Collision/CollisionComponent.hpp"
namespace BBM
{
RenderSystem::RenderSystem(WAL::Wal &wal, RAY::Window &window, bool debugMode)
: System(wal),
_window(window),
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE),
_debugMode(debugMode)
_window(window),
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE),
_debugMode(debugMode)
{
this->_window.setFPS(this->FPS);
}
@@ -29,6 +32,26 @@ namespace BBM
this->_window.useCamera(this->_camera);
for (auto &[_, pos, drawable] : this->_wal.scene->view<PositionComponent, Drawable3DComponent>()) {
if (_.getName() == "cube") {
auto col = _.getComponent<CollisionComponent>();
DrawCubeWires({pos.position.x, pos.position.y, pos.position.z},
col.bound.x,
col.bound.y,
col.bound.z,
WHITE);
DrawPoint3D({pos.position.x, pos.position.y, pos.position.z}, BLUE);
DrawPoint3D({pos.position.x + col.bound.x, pos.position.y + col.bound.y, pos.position.z + col.bound.z}, BLUE);
}
if (_.getName() == "player") {
auto col = _.getComponent<CollisionComponent>();
DrawCubeWires({pos.position.x, pos.position.y, pos.position.z},
col.bound.x,
col.bound.y,
col.bound.z,
WHITE);
DrawPoint3D({pos.position.x, pos.position.y, pos.position.z}, BLUE);
DrawPoint3D({pos.position.x + col.bound.x, pos.position.y + col.bound.y, pos.position.z + col.bound.z}, BLUE);
}
drawable.drawable->setPosition(pos.position);
drawable.drawable->drawOn(this->_window);
}
@@ -44,7 +67,8 @@ namespace BBM
this->_window.endDrawing();
}
void RenderSystem::onUpdate(WAL::ViewEntity<CameraComponent, PositionComponent> &entity, std::chrono::nanoseconds dtime)
void
RenderSystem::onUpdate(WAL::ViewEntity<CameraComponent, PositionComponent> &entity, std::chrono::nanoseconds dtime)
{
const auto &pos = entity.get<PositionComponent>();
const auto &cam = entity.get<CameraComponent>();