addition + correct drawing modes

This commit is contained in:
arthur.jamet
2021-06-02 14:33:52 +02:00
parent 1cc6907ff0
commit ef0c323d94
8 changed files with 38 additions and 18 deletions
+11 -6
View File
@@ -9,6 +9,7 @@
#include <System/Renderer/Render2DScreenSystem.hpp>
#include <System/Renderer/Renderer2DSystem.hpp>
#include <Model/Model.hpp>
#include <Drawables/3D/Cube.hpp>
#include <Drawables/2D/Rectangle.hpp>
#include <TraceLog.hpp>
#include <System/Renderer/Renderer3DSystem.hpp>
@@ -34,27 +35,31 @@ namespace BBM
void enableRaylib(WAL::Wal &wal)
{
RAY::TraceLog::setLevel(LOG_WARNING);
RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE);
//RAY::TraceLog::setLevel(LOG_WARNING);
RAY::Window &window = RAY::Window::getInstance(800, 600, "Bomberman", FLAG_WINDOW_RESIZABLE);
wal.addSystem<Renderer3DSystem<RAY3D::Model>>();
wal.addSystem<RenderScreenSystem>(window)
.addSystem<Renderer3DSystem<RAY3D::Cube>>()
.addSystem<Renderer3DSystem<RAY3D::Model>>();
wal.addSystem<Render2DScreenSystem>(window)
.addSystem<Renderer2DSystem<RAY2D::Rectangle>>();
wal.addSystem<RenderScreenSystem>(window);
}
std::shared_ptr<WAL::Scene> loadGameScene()
{
auto scene = std::make_shared<WAL::Scene>();
scene->addEntity("cube")
.addComponent<PositionComponent>(10, 10, 0)
.addComponent<Drawable2DComponent<RAY2D::Rectangle>>(Vector2f(), Vector2f(10, 10), GREEN);
scene->addEntity("cube2")
.addComponent<PositionComponent>()
.addComponent<Drawable2DComponent<RAY2D::Rectangle>>(Vector2f(), Vector2f(10, 10), RED);
.addComponent<Drawable3DComponent<RAY3D::Cube>>(Vector3f(), Vector3f(1, 1, 1), RED);
scene->addEntity("player")
.addComponent<PositionComponent>()
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"));
scene->addEntity("camera")
.addComponent<PositionComponent>(10, 10, 10)
.addComponent<PositionComponent>(10, 10, 15)
.addComponent<CameraComponent>();
return scene;
}
@@ -8,12 +8,14 @@ namespace BBM
{
Render2DScreenSystem::Render2DScreenSystem(RAY::Window &window)
: WAL::System({}),
_window(window),
_camera(RAY::Vector2(10, 10), RAY::Vector2(), 0)
_window(window)
{}
void Render2DScreenSystem::onSelfUpdate()
{
this->_window.useCamera(this->_camera);
EndMode3D();
printf("EndMode3D\n");
DrawText("Try selecting the box with mouse!", 10, 10, 20, WHITE);
//this->_window.unuseCamera();
}
}
@@ -13,9 +13,6 @@ namespace BBM
{
//! @brief The window to render on
RAY::Window &_window;
//! @brief The camera used to render.
RAY::Camera::Camera2D _camera;
public:
//! @brief A method called after all entities that this system manage has been updated.
//! @note render on screen here
+11 -3
View File
@@ -15,18 +15,26 @@ namespace BBM
}),
_window(window),
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE)
{}
{
this->_camera.setMode(CAMERA_FREE);
}
void RenderScreenSystem::onSelfUpdate()
{
this->_window.draw();
//this->_window.draw();
//EndMode2D();
EndDrawing();
this->_camera.update();
BeginDrawing();
this->_window.clear();
this->_window.useCamera(this->_camera);
BeginMode3D(this->_camera);
printf("BeginMode3D\n");
}
void RenderScreenSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime)
{
const auto &pos = entity.getComponent<PositionComponent>();
_camera.setPosition(pos.position);
//this->_camera.update();
}
}
+2 -1
View File
@@ -35,7 +35,8 @@ namespace BBM
auto &pos = entity.getComponent<PositionComponent>();
comp.member.setPosition({pos.getX(), pos.getY()});
comp.member.drawOn(this->_window);
this->_window.draw(comp.member);
printf("Drawing smth\n");
}
//! @brief default copy ctor
+1 -1
View File
@@ -35,7 +35,7 @@ namespace BBM
auto &pos = entity.getComponent<PositionComponent>();
comp.member.setPosition(static_cast<RAY::Vector3>(pos.position));
comp.member.drawOn(this->_window);
this->_window.draw(comp.member);
}
//! @brief Default copy ctor