Files
Seele/src/Engine/Scene/Scene.cpp
T

61 lines
1.7 KiB
C++
Raw Normal View History

2020-05-05 01:51:13 +02:00
#include "Scene.h"
#include "Components/PrimitiveComponent.h"
2020-09-19 14:36:50 +02:00
#include "Components/PrimitiveUniformBufferLayout.h"
2020-05-05 01:51:13 +02:00
#include "Material/MaterialInstance.h"
#include "Material/Material.h"
2020-09-19 14:36:50 +02:00
#include "Graphics/Graphics.h"
2020-05-05 01:51:13 +02:00
using namespace Seele;
2020-09-19 14:36:50 +02:00
Scene::Scene(Gfx::PGraphics graphics)
: graphics(graphics)
2020-05-05 01:51:13 +02:00
{
2021-01-19 15:30:00 +01:00
lightEnv.directionalLights[0].color = Vector4(1, 0, 0, 1);
lightEnv.directionalLights[0].direction = Vector4(1, 1, 0, 1);
lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1);
lightEnv.numDirectionalLights = 1;
lightEnv.numPointLights = 0;
2021-03-31 12:18:16 +02:00
srand((unsigned int)time(NULL));
2020-05-05 01:51:13 +02:00
}
Scene::~Scene()
{
}
void Scene::tick(float deltaTime)
{
for (auto actor : rootActors)
{
actor->tick(deltaTime);
}
}
void Scene::addActor(PActor actor)
{
rootActors.add(actor);
actor->notifySceneAttach(this);
}
void Scene::addPrimitiveComponent(PPrimitiveComponent comp)
{
primitives.add(comp);
2020-10-14 01:49:43 +02:00
for(auto& batch : comp->staticMeshes)
2020-09-19 14:36:50 +02:00
{
PrimitiveUniformBuffer data;
data.actorWorldPosition = Vector4(comp->getTransform().getPosition(), 1);
data.localToWorld = comp->getRenderMatrix();
data.worldToLocal = glm::inverse(data.localToWorld);
UniformBufferCreateInfo createInfo;
createInfo.resourceData.data = reinterpret_cast<uint8*>(&data);
createInfo.resourceData.owner = Gfx::QueueType::GRAPHICS;
createInfo.resourceData.size = sizeof(data);
createInfo.bDynamic = true;
2020-09-19 14:36:50 +02:00
Gfx::PUniformBuffer uniformBuffer = graphics->createUniformBuffer(createInfo);
for(auto& element : batch.elements)
{
element.uniformBuffer = uniformBuffer;
}
staticMeshes.add(batch);
}
2020-05-05 01:51:13 +02:00
}