Browse Source

Remove old transform class

master
Riyyi 4 years ago
parent
commit
6fb114cbd4
  1. 25
      inferno/src/inferno/application.cpp
  2. 61
      inferno/src/inferno/component/transform.cpp
  3. 51
      inferno/src/inferno/component/transform.h
  4. 11
      inferno/src/inferno/render/renderer.cpp
  5. 10
      inferno/src/inferno/render/renderer.h
  6. 4
      inferno/src/inferno/scene/scene.cpp

25
inferno/src/inferno/application.cpp

@ -1,6 +1,5 @@
#include "inferno/application.h"
#include "inferno/assertions.h"
#include "inferno/component/transform.h"
#include "inferno/core.h"
#include "inferno/event/applicationevent.h"
#include "inferno/event/event.h"
@ -15,6 +14,8 @@
#include "inferno/render/renderer.h"
#include "inferno/render/shader.h"
#include "inferno/render/texture.h"
#include "inferno/scene/components.h"
#include "inferno/scene/entity.h"
#include "inferno/scene/scene.h"
#include "inferno/settings.h"
#include "inferno/time.h"
@ -86,17 +87,15 @@ namespace Inferno {
1.0f, 1.0f, 1.0f, 1.0f,
};
Transform cube({0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f});
cube.update();
Entity quad = m_scene->createEntity("Quad");
Transform cube2({1.1f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f});
cube2.update();
Entity quad2 = m_scene->createEntity("Quad 2");
auto& quad2Transform = quad2.get<TransformComponent>();
quad2Transform.translate.x = 1.1f;
Transform cube3({2.2f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f});
cube3.update();
Transform cube4({0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f});
cube4.update();
Entity quad3 = m_scene->createEntity("Quad 3");
auto& quad3Transform = quad3.get<TransformComponent>();
quad3Transform.translate.x = 2.2f;
std::array<CharacterVertex, Renderer::vertexPerQuad> character;
@ -172,9 +171,9 @@ namespace Inferno {
Renderer2D::the().beginScene(m_scene->cameraProjectionView()); // camera, lights, environment
RendererCharacter::the().beginScene();
Renderer2D::the().drawQuad(std::make_shared<Transform>(cube), colors);
Renderer2D::the().drawQuad(std::make_shared<Transform>(cube2), { 0.5f, 0.6f, 0.8f, 1.0f }, m_texture);
Renderer2D::the().drawQuad(std::make_shared<Transform>(cube3), { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2);
Renderer2D::the().drawQuad(quad.get<TransformComponent>(), colors);
Renderer2D::the().drawQuad(quad2.get<TransformComponent>(), { 0.5f, 0.6f, 0.8f, 1.0f }, m_texture);
Renderer2D::the().drawQuad(quad3.get<TransformComponent>(), { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2);
RendererCharacter::the().drawCharacter(character, {1,1,1,1}, f->texture());

61
inferno/src/inferno/component/transform.cpp

@ -1,61 +0,0 @@
#include <glm/ext/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale, glm::radians
#include "inferno/component/transform.h"
namespace Inferno {
void Transform::update()
{
// Identity matrix
m_transform = glm::mat4(1.0f);
// Translate
m_transform = glm::translate(m_transform, m_translate);
// Rotate
m_transform = glm::rotate(m_transform, glm::radians(m_rotate.x), {1.0, 0.0, 0.0});
m_transform = glm::rotate(m_transform, glm::radians(m_rotate.y), {0.0, 1.0, 0.0});
m_transform = glm::rotate(m_transform, glm::radians(m_rotate.z), {0.0, 0.0, 1.0});
// Scale
m_transform = glm::scale(m_transform, m_scale);
}
// ----------------------------------------
const LogStream& operator<<(const LogStream& stream, const Transform& value)
{
stream << "transform "
<< value.translate() << " t\n "
<< value.rotate() << " r\n "
<< value.scale() << " s";
return stream;
}
const LogStream& operator<<(const LogStream& stream, const glm::vec2& value)
{
stream << "{ " << value.x << ", " << value.y << ", " << " }";
return stream;
}
const LogStream& operator<<(const LogStream& stream, const glm::vec3& value)
{
stream << "{ " << value.x << ", " << value.y << ", " << value.z << " }";
return stream;
}
const LogStream& operator<<(const LogStream& stream, const glm::vec4& value)
{
stream << "{ " << value.x << ", " << value.y << ", " << value.z << ", " << value.w << " }";
return stream;
}
const LogStream& operator<<(const LogStream& stream, const glm::mat4& value)
{
stream << "mat4 "
<< value[0] << "\n " << value[1] << "\n "
<< value[2] << "\n " << value[3];
return stream;
}
}

51
inferno/src/inferno/component/transform.h

@ -1,51 +0,0 @@
#ifndef TRANSFORM_H
#define TRANSFORM_H
#include <glm/ext/matrix_float4x4.hpp> // glm::mat4
#include <glm/ext/vector_float3.hpp> // glm::vec3
#include "inferno/log.h"
namespace Inferno {
class Transform {
public:
Transform() {}
Transform(glm::vec3 translate, glm::vec3 rotate, glm::vec3 scale)
: m_translate(translate), m_rotate(rotate), m_scale(scale) {}
virtual ~Transform() {}
virtual void update();
void setTranslate(glm::vec3 translate) { m_translate = translate; }
void setRotate(glm::vec3 rotation) { m_rotate = rotation; }
void setScale(glm::vec3 scale) { m_scale = scale; }
void setTransform(glm::mat4 transform) { m_transform = transform; }
void setTranslate(float x, float y, float z) { m_translate = { x, y, z }; }
void setRotate(float x, float y, float z) { m_rotate = { x, y, z }; }
void setScale(float x, float y, float z) { m_scale = { x, y, z }; }
const glm::vec3& translate() const { return m_translate; }
const glm::vec3& rotate() const { return m_rotate; }
const glm::vec3& scale() const { return m_scale; }
const glm::mat4& transform() const { return m_transform; }
private:
glm::vec3 m_translate;
glm::vec3 m_rotate;
glm::vec3 m_scale;
glm::mat4 m_transform;
};
// ----------------------------------------
const LogStream& operator<<(const LogStream& stream, const Transform& value);
const LogStream& operator<<(const LogStream& stream, const glm::vec2& value);
const LogStream& operator<<(const LogStream& stream, const glm::vec3& value);
const LogStream& operator<<(const LogStream& stream, const glm::vec4& value);
const LogStream& operator<<(const LogStream& stream, const glm::mat4& value);
}
#endif // TRANSFORM_H

11
inferno/src/inferno/render/renderer.cpp

@ -4,7 +4,6 @@
#include <glad/glad.h>
#include "inferno/assertions.h"
#include "inferno/component/transform.h"
#include "inferno/render/buffer.h"
#include "inferno/render/renderer.h"
#include "inferno/render/shader.h"
@ -196,22 +195,22 @@ namespace Inferno {
nextBatch();
}
void Renderer2D::drawQuad(std::shared_ptr<Transform> transform, glm::vec4 color)
void Renderer2D::drawQuad(const TransformComponent& transform, glm::vec4 color)
{
drawQuad(transform, color, nullptr);
}
void Renderer2D::drawQuad(std::shared_ptr<Transform> transform, glm::mat4 color)
void Renderer2D::drawQuad(const TransformComponent& transform, glm::mat4 color)
{
drawQuad(transform, color, nullptr);
}
void Renderer2D::drawQuad(std::shared_ptr<Transform> transform, glm::vec4 color, std::shared_ptr<Texture> texture)
void Renderer2D::drawQuad(const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture)
{
drawQuad(transform, glm::mat4(color, color, color, color), texture);
}
void Renderer2D::drawQuad(std::shared_ptr<Transform> transform, glm::mat4 color, std::shared_ptr<Texture> texture)
void Renderer2D::drawQuad(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture)
{
// Create a new batch if the quad limit has been reached
if (m_quadIndex >= quadCount) {
@ -226,7 +225,7 @@ namespace Inferno {
// Add the quads 4 vertices
for (uint32_t i = 0; i < vertexPerQuad; i++) {
m_vertexBufferPtr->position = transform->transform() * m_vertexPositions[i];
m_vertexBufferPtr->position = transform.transform * m_vertexPositions[i];
m_vertexBufferPtr->color = color[i];
m_vertexBufferPtr->textureCoordinates = textureCoordinates[i];
m_vertexBufferPtr->textureIndex = (float)textureUnitIndex;

10
inferno/src/inferno/render/renderer.h

@ -9,6 +9,8 @@
#include "glm/ext/vector_float3.hpp" // glm::vec3
#include "glm/ext/vector_float4.hpp" // glm::vec4
#include "inferno/scene/components.h"
namespace Inferno {
class Camera;
@ -95,10 +97,10 @@ namespace Inferno {
void beginScene(glm::mat4 cameraProjectionView);
void endScene();
void drawQuad(std::shared_ptr<Transform> transform, glm::vec4 color);
void drawQuad(std::shared_ptr<Transform> transform, glm::mat4 color);
void drawQuad(std::shared_ptr<Transform> transform, glm::vec4 color, std::shared_ptr<Texture> texture);
void drawQuad(std::shared_ptr<Transform> transform, glm::mat4 color, std::shared_ptr<Texture> texture);
void drawQuad(const TransformComponent& transform, glm::vec4 color);
void drawQuad(const TransformComponent& transform, glm::mat4 color);
void drawQuad(const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture);
void drawQuad(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture);
static inline Renderer2D& the() { return *s_instance; }

4
inferno/src/inferno/scene/scene.cpp

@ -32,8 +32,8 @@ namespace Inferno {
Entity camera = createEntity("Camera Entity");
camera.add<PerspectiveCameraComponent>();
auto& cameraTransform = camera.get<TransformComponent>();
cameraTransform.translate = { 0.0f, 0.0f, 1.0f };
cameraTransform.rotate = { 0.0f, 0.0f, -1.0f };
cameraTransform.translate.z = 1.0f;
cameraTransform.rotate.z = -1.0f;
}
void Scene::update(float deltaTime)

Loading…
Cancel
Save