CLEANUP
This commit is contained in:
parent
1923da2339
commit
01e74fe40e
@ -1,21 +0,0 @@
|
||||
//
|
||||
// Created by sebastian on 29.07.26.
|
||||
//
|
||||
|
||||
#include "Entity.h"
|
||||
|
||||
|
||||
|
||||
engine::Entity::Entity(std::shared_ptr<engine::RawModel> model, glm::vec3 position, glm::vec3 rotation,
|
||||
glm::vec3 scale) : m_model(std::move(model)), m_position(position), m_rotation(rotation), m_scale(scale) {
|
||||
}
|
||||
|
||||
glm::mat4 engine::Entity::getModelMatrix() const {
|
||||
auto modelMatrix = glm::mat4(1.0f);
|
||||
modelMatrix = glm::translate(modelMatrix, m_position);
|
||||
modelMatrix = glm::rotate(modelMatrix, glm::radians(m_rotation.x), {1.0f, 0.0f, 0.0f});
|
||||
modelMatrix = glm::rotate(modelMatrix, glm::radians(m_rotation.y), {0.0f, 1.0f, 0.0f});
|
||||
modelMatrix = glm::rotate(modelMatrix, glm::radians(m_rotation.z), {0.0f, 0.0f, 1.0f});
|
||||
modelMatrix = glm::scale(modelMatrix, m_scale);
|
||||
return modelMatrix;
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
//
|
||||
// Created by sebastian on 29.07.26.
|
||||
//
|
||||
|
||||
#ifndef COLORRACE_ENTITY_H
|
||||
#define COLORRACE_ENTITY_H
|
||||
#include <memory>
|
||||
|
||||
#include "../model/RawModel.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace engine {
|
||||
class Entity {
|
||||
public:
|
||||
explicit Entity(std::shared_ptr<engine::RawModel> model,
|
||||
glm::vec3 position = {0.0f, 0.0f, 0.0f},
|
||||
glm::vec3 rotation = {0.0f, 0.0f, 0.0f},
|
||||
glm::vec3 scale = { 1.0f, 1.0f, 1.0f});
|
||||
|
||||
void setPosition(glm::vec3 position) { m_position = position; };
|
||||
void setRotation(glm::vec3 rotation) { m_rotation = rotation; };
|
||||
void setScale(glm::vec3 scale) {m_scale = scale; };
|
||||
|
||||
[[nodiscard]] const glm::vec3& getPosition() const { return m_position; };
|
||||
[[nodiscard]] const glm::vec3& getRotation() const { return m_rotation; };
|
||||
[[nodiscard]] const glm::vec3& getScale() const { return m_scale; };
|
||||
|
||||
glm::mat4 getModelMatrix() const;
|
||||
RawModel& getModel() const { return *m_model; }
|
||||
|
||||
void increasePosition(glm::vec3 offset) { m_position += offset; }
|
||||
void increaseRotation(glm::vec3 offset) { m_rotation += offset; }
|
||||
void increaseScale(glm::vec3 offset) { m_scale += offset; }
|
||||
|
||||
private:
|
||||
std::shared_ptr<engine::RawModel> m_model;
|
||||
glm::vec3 m_position;
|
||||
glm::vec3 m_rotation;
|
||||
glm::vec3 m_scale;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //COLORRACE_ENTITY_H
|
||||
@ -1,26 +0,0 @@
|
||||
//
|
||||
// Created by sebastian on 29.07.26.
|
||||
//
|
||||
|
||||
#include "RawModel.h"
|
||||
using namespace engine;
|
||||
|
||||
RawModel::RawModel(std::unique_ptr<Vao> vao, int vertexCount, bool isIndexed) : m_vao(std::move(vao)), m_vertexCount(vertexCount), m_isIndexed(isIndexed) {}
|
||||
|
||||
RawModel::RawModel(std::unique_ptr<Vao> vao, int vertexCount) : RawModel(std::move(vao), vertexCount, false) {}
|
||||
|
||||
void RawModel::bind() const {
|
||||
m_vao->bind();
|
||||
}
|
||||
|
||||
void RawModel::unbind() const {
|
||||
m_vao->unbind();
|
||||
}
|
||||
|
||||
void RawModel::draw() const {
|
||||
if (m_isIndexed) {
|
||||
glDrawElements(GL_TRIANGLES, m_vertexCount, GL_UNSIGNED_INT, nullptr);
|
||||
} else {
|
||||
glDrawArrays(GL_TRIANGLES, 0, m_vertexCount);
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
//
|
||||
// Created by sebastian on 29.07.26.
|
||||
//
|
||||
|
||||
#ifndef COLORRACE_RAWMODEL_H
|
||||
#define COLORRACE_RAWMODEL_H
|
||||
#include <memory>
|
||||
|
||||
#include "utils/openglWrapper/openglObjects/Vao.h"
|
||||
|
||||
namespace engine {
|
||||
class RawModel {
|
||||
public:
|
||||
RawModel(std::unique_ptr<Vao> vao, int vertexCount, bool isIndexed);
|
||||
RawModel(std::unique_ptr<Vao> vao, int vertexCount);
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
void draw() const;
|
||||
|
||||
int getVertexCount() const { return m_vertexCount; }
|
||||
bool isIndexed() const { return m_isIndexed; }
|
||||
private:
|
||||
std::unique_ptr<Vao> m_vao;
|
||||
int m_vertexCount;
|
||||
bool m_isIndexed;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif //COLORRACE_RAWMODEL_H
|
||||
@ -1,38 +0,0 @@
|
||||
//
|
||||
// Created by sebastian on 29.07.26.
|
||||
//
|
||||
|
||||
#include "CubeFactory.h"
|
||||
|
||||
std::shared_ptr<engine::RawModel> engine::CubeFactory::createCube() {
|
||||
float vertices[] = {
|
||||
-0.5f, -0.5f, 0.5f, // 0
|
||||
0.5f, -0.5f, 0.5f, // 1
|
||||
0.5f, 0.5f, 0.5f, // 2
|
||||
-0.5f, 0.5f, 0.5f, // 3
|
||||
-0.5f, -0.5f, -0.5f, // 4
|
||||
0.5f, -0.5f, -0.5f, // 5
|
||||
0.5f, 0.5f, -0.5f, // 6
|
||||
-0.5f, 0.5f, -0.5f, // 7
|
||||
};
|
||||
|
||||
unsigned int indices[] = {
|
||||
0, 1, 2, 2, 3, 0, // front
|
||||
1, 5, 6, 6, 2, 1, // right
|
||||
5, 4, 7, 7, 6, 5, // back
|
||||
4, 0, 3, 3, 7, 4, // left
|
||||
3, 2, 6, 6, 7, 3, // top
|
||||
4, 5, 1, 1, 0, 4, // bottom
|
||||
};
|
||||
|
||||
auto vao = Vao::create();
|
||||
|
||||
std::vector<std::unique_ptr<Attribute>> attribs;
|
||||
attribs.push_back(std::make_unique<Vec3Attribute>(0));
|
||||
vao->initDataFeed(vertices, sizeof(vertices), GL_STATIC_DRAW, std::move(attribs));
|
||||
|
||||
vao->createIndexBuffer(indices, 36);
|
||||
vao->unbind();
|
||||
|
||||
return std::make_shared<RawModel>(std::move(vao), 36, true);
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
//
|
||||
// Created by sebastian on 29.07.26.
|
||||
//
|
||||
|
||||
#ifndef COLORRACE_CUBEFACTORY_H
|
||||
#define COLORRACE_CUBEFACTORY_H
|
||||
#include "renderer/model/RawModel.h"
|
||||
|
||||
|
||||
namespace engine::CubeFactory {
|
||||
std::shared_ptr<RawModel> createCube();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif //COLORRACE_CUBEFACTORY_H
|
||||
Loading…
Reference in New Issue
Block a user