chore: rename transform to Transform
This commit is contained in:
@ -9,7 +9,7 @@ namespace Core {
|
|||||||
struct ENGINE_API batch {
|
struct ENGINE_API batch {
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
public:
|
public:
|
||||||
// requires transform component
|
// requires Transform component
|
||||||
struct item {
|
struct item {
|
||||||
unsigned int batchId;
|
unsigned int batchId;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include "engine/export.h"
|
#include "engine/export.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
struct ENGINE_API transform {
|
struct ENGINE_API Transform {
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec3 rotation;
|
glm::vec3 rotation;
|
||||||
glm::vec3 scale;
|
glm::vec3 scale;
|
||||||
|
|||||||
@ -67,7 +67,7 @@ void Renderer::ApplyLights(Shader &shader) {
|
|||||||
size_t lightIndex = 0;
|
size_t lightIndex = 0;
|
||||||
for (auto entity : lights) {
|
for (auto entity : lights) {
|
||||||
auto &l = m_scene->m_registry.get<light>(entity);
|
auto &l = m_scene->m_registry.get<light>(entity);
|
||||||
auto &transf = m_scene->m_registry.get<transform>(entity);
|
auto &transf = m_scene->m_registry.get<Transform>(entity);
|
||||||
|
|
||||||
shader.setInt("lights[" + std::to_string(lightIndex) + "].type", static_cast<int>(l.type));
|
shader.setInt("lights[" + std::to_string(lightIndex) + "].type", static_cast<int>(l.type));
|
||||||
shader.setVec3("lights[" + std::to_string(lightIndex) + "].position", transf.position);
|
shader.setVec3("lights[" + std::to_string(lightIndex) + "].position", transf.position);
|
||||||
@ -111,8 +111,8 @@ void Renderer::EnsureShadowResources(light& l) {
|
|||||||
void Renderer::UpdateView() {
|
void Renderer::UpdateView() {
|
||||||
auto camView = m_scene->m_registry.view<camera>();
|
auto camView = m_scene->m_registry.view<camera>();
|
||||||
auto camTransform = camView.size() > 0 ?
|
auto camTransform = camView.size() > 0 ?
|
||||||
m_scene->m_registry.get<transform>(camView.back()) :
|
m_scene->m_registry.get<Transform>(camView.back()) :
|
||||||
transform {glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.f, 1.f, 1.f)};
|
Transform {glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.f, 1.f, 1.f)};
|
||||||
|
|
||||||
m_view = glm::lookAt(
|
m_view = glm::lookAt(
|
||||||
camTransform.position,
|
camTransform.position,
|
||||||
@ -149,7 +149,7 @@ void Renderer::RenderScene(Shader &shader) {
|
|||||||
models.reserve(batchItems.size());
|
models.reserve(batchItems.size());
|
||||||
|
|
||||||
for (auto item : batchItems) {
|
for (auto item : batchItems) {
|
||||||
auto &t = m_scene->m_registry.get<transform>(item);
|
auto &t = m_scene->m_registry.get<Transform>(item);
|
||||||
glm::mat4 rotation = glm::yawPitchRoll(t.rotation.y, t.rotation.x, t.rotation.z);
|
glm::mat4 rotation = glm::yawPitchRoll(t.rotation.y, t.rotation.x, t.rotation.z);
|
||||||
auto itemModel = glm::translate(glm::mat4(1.f), t.position) * rotation;
|
auto itemModel = glm::translate(glm::mat4(1.f), t.position) * rotation;
|
||||||
models.push_back(itemModel);
|
models.push_back(itemModel);
|
||||||
@ -165,7 +165,7 @@ void Renderer::RenderScene(Shader &shader) {
|
|||||||
}
|
}
|
||||||
shader.setBool("u_isInstanced", false);
|
shader.setBool("u_isInstanced", false);
|
||||||
|
|
||||||
for (auto [entity, transf, mesh] : m_scene->m_registry.view<transform, mesh>(entt::exclude<batch, batch::item>).each()) {
|
for (auto [entity, transf, mesh] : m_scene->m_registry.view<Transform, mesh>(entt::exclude<batch, batch::item>).each()) {
|
||||||
if (mesh.object == nullptr) {
|
if (mesh.object == nullptr) {
|
||||||
std::cerr << "WARN: Entity doesn't have a mesh to render" << std::endl;
|
std::cerr << "WARN: Entity doesn't have a mesh to render" << std::endl;
|
||||||
return;
|
return;
|
||||||
@ -206,7 +206,7 @@ void Renderer::Render() {
|
|||||||
|
|
||||||
glCullFace(GL_FRONT);
|
glCullFace(GL_FRONT);
|
||||||
|
|
||||||
const auto lights = m_scene->m_registry.view<light, transform>();
|
const auto lights = m_scene->m_registry.view<light, Transform>();
|
||||||
|
|
||||||
for (auto [_, l, t] : lights.each()) {
|
for (auto [_, l, t] : lights.each()) {
|
||||||
// TODO: support other light types when ready
|
// TODO: support other light types when ready
|
||||||
|
|||||||
@ -36,20 +36,20 @@ public:
|
|||||||
|
|
||||||
Object* lightObj = Object::LoadFile("./assets/common/sphere/sphere.obj");
|
Object* lightObj = Object::LoadFile("./assets/common/sphere/sphere.obj");
|
||||||
lightEntity = scene->CreateEntity();
|
lightEntity = scene->CreateEntity();
|
||||||
lightEntity.AddComponent<transform>(glm::vec3(5.f, 5.f, 5.f), glm::vec3(0.f));
|
lightEntity.AddComponent<Transform>(glm::vec3(5.f, 5.f, 5.f), glm::vec3(0.f));
|
||||||
lightEntity.AddComponent<light>(light::LightType::DIRECTIONAL, glm::vec3(1.f, 1.f, 1.f), 1.5f);
|
lightEntity.AddComponent<light>(light::LightType::DIRECTIONAL, glm::vec3(1.f, 1.f, 1.f), 1.5f);
|
||||||
lightEntity.AddComponent<mesh>(std::shared_ptr<Object>(lightObj));
|
lightEntity.AddComponent<mesh>(std::shared_ptr<Object>(lightObj));
|
||||||
assert(lightEntity.HasComponent<mesh>() && "light doesn't have any mesh!");
|
assert(lightEntity.HasComponent<mesh>() && "light doesn't have any mesh!");
|
||||||
|
|
||||||
cameraEntity = scene->CreateEntity();
|
cameraEntity = scene->CreateEntity();
|
||||||
cameraEntity.AddComponent<camera>();
|
cameraEntity.AddComponent<camera>();
|
||||||
cameraEntity.AddComponent<transform>(glm::vec3(0.f, 2.f, 2.f));
|
cameraEntity.AddComponent<Transform>(glm::vec3(0.f, 2.f, 2.f));
|
||||||
assert(cameraEntity.HasComponent<camera>() && "Camera doesn't have required 'camera' component");
|
assert(cameraEntity.HasComponent<camera>() && "Camera doesn't have required 'camera' component");
|
||||||
assert(cameraEntity.HasComponent<transform>() && "Camera doesn't have 'transform' component");
|
assert(cameraEntity.HasComponent<Transform>() && "Camera doesn't have 'transform' component");
|
||||||
|
|
||||||
Object* targetObj = Object::LoadFile("./assets/wizard/wizard.obj");
|
Object* targetObj = Object::LoadFile("./assets/wizard/wizard.obj");
|
||||||
modelEntity = scene->CreateEntity();
|
modelEntity = scene->CreateEntity();
|
||||||
modelEntity.AddComponent<transform>(glm::vec3(0.f, 0.0f, 0.f));
|
modelEntity.AddComponent<Transform>(glm::vec3(0.f, 0.0f, 0.f));
|
||||||
modelEntity.AddComponent<mesh>(std::shared_ptr<Object>(targetObj));
|
modelEntity.AddComponent<mesh>(std::shared_ptr<Object>(targetObj));
|
||||||
modelEntity.AddComponent<rotate>();
|
modelEntity.AddComponent<rotate>();
|
||||||
assert(modelEntity.HasComponent<mesh>() && "model doesn't have any mesh!");
|
assert(modelEntity.HasComponent<mesh>() && "model doesn't have any mesh!");
|
||||||
@ -70,14 +70,14 @@ public:
|
|||||||
float y = static_cast<float>(rand()) / RAND_MAX * 10.f; // range [0, 10]
|
float y = static_cast<float>(rand()) / RAND_MAX * 10.f; // range [0, 10]
|
||||||
float z = static_cast<float>(rand()) / RAND_MAX * 200.f - 100.f; // range [-100, 100]
|
float z = static_cast<float>(rand()) / RAND_MAX * 200.f - 100.f; // range [-100, 100]
|
||||||
|
|
||||||
cubeEntity.AddComponent<transform>(glm::vec3(x, y, z));
|
cubeEntity.AddComponent<Transform>(glm::vec3(x, y, z));
|
||||||
cubeEntity.AddComponent<rotate>();
|
cubeEntity.AddComponent<rotate>();
|
||||||
cubeEntity.AddComponent<batch::item>(cubeBatch.id());
|
cubeEntity.AddComponent<batch::item>(cubeBatch.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
Object* floorObj = Object::LoadFile("./assets/common/plane/plane.obj");
|
Object* floorObj = Object::LoadFile("./assets/common/plane/plane.obj");
|
||||||
auto floorEntt = scene->CreateEntity();
|
auto floorEntt = scene->CreateEntity();
|
||||||
floorEntt.AddComponent<transform>(glm::vec3(0.f));
|
floorEntt.AddComponent<Transform>(glm::vec3(0.f));
|
||||||
floorEntt.AddComponent<mesh>(std::shared_ptr<Object>(floorObj));
|
floorEntt.AddComponent<mesh>(std::shared_ptr<Object>(floorObj));
|
||||||
assert(floorEntt.HasComponent<mesh>() && "floor doesn't have any mesh component!");
|
assert(floorEntt.HasComponent<mesh>() && "floor doesn't have any mesh component!");
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ public:
|
|||||||
if (Input::IsKeyPressed(SDL_SCANCODE_SPACE)) velocity.y += 1.f;
|
if (Input::IsKeyPressed(SDL_SCANCODE_SPACE)) velocity.y += 1.f;
|
||||||
if (Input::IsKeyPressed(SDL_SCANCODE_LSHIFT)) velocity.y -= 1.f;
|
if (Input::IsKeyPressed(SDL_SCANCODE_LSHIFT)) velocity.y -= 1.f;
|
||||||
|
|
||||||
auto& camTransform = cameraEntity.GetComponent<transform>();
|
auto& camTransform = cameraEntity.GetComponent<Transform>();
|
||||||
camTransform.position += velocity * (float)dt * 2.5f; // speed is e.g. 2.5f
|
camTransform.position += velocity * (float)dt * 2.5f; // speed is e.g. 2.5f
|
||||||
camTransform.rotation = cameraViewDirection;
|
camTransform.rotation = cameraViewDirection;
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ public:
|
|||||||
|
|
||||||
// Update the directional light in the registry
|
// Update the directional light in the registry
|
||||||
auto& l = lightEntity.GetComponent<light>();
|
auto& l = lightEntity.GetComponent<light>();
|
||||||
auto& t = lightEntity.GetComponent<transform>();
|
auto& t = lightEntity.GetComponent<Transform>();
|
||||||
if (l.type == light::LightType::DIRECTIONAL) {
|
if (l.type == light::LightType::DIRECTIONAL) {
|
||||||
// "position" for directional light often stores direction vector
|
// "position" for directional light often stores direction vector
|
||||||
// If your system instead uses transform.rotation, adjust accordingly
|
// If your system instead uses transform.rotation, adjust accordingly
|
||||||
|
|||||||
Reference in New Issue
Block a user