Browse Source

Implement transform and camera system into scene

master
Riyyi 4 years ago
parent
commit
c599486ff5
  1. 54
      inferno/src/inferno/scene/scene.cpp
  2. 11
      inferno/src/inferno/scene/scene.h

54
inferno/src/inferno/scene/scene.cpp

@ -2,20 +2,53 @@
#include "inferno/scene/components.h" #include "inferno/scene/components.h"
#include "inferno/scene/entity.h" #include "inferno/scene/entity.h"
#include "inferno/scene/scene.h" #include "inferno/scene/scene.h"
#include "inferno/systems/camera.h"
#include "inferno/systems/transform.h"
namespace Inferno { namespace Inferno {
Scene::Scene() Scene::Scene()
{
initialize();
}
Scene::~Scene()
{
destroy();
}
void Scene::initialize()
{ {
m_registry = std::make_shared<entt::registry>(); m_registry = std::make_shared<entt::registry>();
Entity entity = createEntity("Test Entity"); TransformSystem* transformSystem = new TransformSystem();
transformSystem->initialize();
TransformSystem::the().setRegistry(m_registry);
dbg() << entity.get<TagComponent>(); CameraSystem* cameraSystem = new CameraSystem();
cameraSystem->initialize();
CameraSystem::the().setRegistry(m_registry);
if (entity) { Entity camera = createEntity("Camera Entity");
dbg() << "Entity is valid"; camera.add<PerspectiveCameraComponent>();
} auto& cameraTransform = camera.get<TransformComponent>();
cameraTransform.translate = { 0.0f, 0.0f, 1.0f };
cameraTransform.rotate = { 0.0f, 0.0f, -1.0f };
}
void Scene::update(float deltaTime)
{
TransformSystem::the().update();
CameraSystem::the().update();
}
void Scene::render()
{
}
void Scene::destroy()
{
TransformSystem::the().destroy();
} }
Entity Scene::createEntity(const std::string& name) Entity Scene::createEntity(const std::string& name)
@ -37,4 +70,15 @@ namespace Inferno {
return Entity(m_registry, handle); return Entity(m_registry, handle);
} }
glm::mat4 Scene::cameraProjectionView()
{
auto view = m_registry->view<TransformComponent, PerspectiveCameraComponent>();
for(auto&& [entity, transform, perspective] : view.each()) {
return perspective.projection * transform.transform;
}
return glm::mat4 { 1.0f };
}
} }

11
inferno/src/inferno/scene/scene.h

@ -5,20 +5,29 @@
#include <memory> // std::shared_ptr #include <memory> // std::shared_ptr
#include "entt/entity/registry.hpp" // entt::entity, entt::registry #include "entt/entity/registry.hpp" // entt::entity, entt::registry
#include "glm/ext/matrix_float4x4.hpp" // glm::mat4
namespace Inferno { namespace Inferno {
class Camera;
class Entity; class Entity;
class Scene { class Scene {
public: public:
Scene(); Scene();
virtual ~Scene() = default; virtual ~Scene();
void initialize();
void update(float deltaTime);
void render();
void destroy();
Entity createEntity(const std::string& name = ""); Entity createEntity(const std::string& name = "");
Entity createEntity(entt::entity handle); Entity createEntity(entt::entity handle);
Entity createEntity(uint32_t handle); Entity createEntity(uint32_t handle);
glm::mat4 cameraProjectionView();
private: private:
std::shared_ptr<entt::registry> m_registry; std::shared_ptr<entt::registry> m_registry;
}; };

Loading…
Cancel
Save