mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
Change the transform component to a struct
This commit is contained in:
parent
18751a3728
commit
a61367721c
@ -16,7 +16,7 @@ add_library(${PROJECT_NAME} SHARED
|
||||
"src/sceneroot.cpp"
|
||||
|
||||
"src/components/component.cpp"
|
||||
"src/components/transform.cpp" # TODO move functionality into "Object" class
|
||||
# TODO move functionality into "Object" class
|
||||
"src/components/camera.cpp"
|
||||
"src/components/mesh_renderer.cpp"
|
||||
"src/components/text_ui_renderer.cpp"
|
||||
@ -45,11 +45,11 @@ add_library(${PROJECT_NAME} SHARED
|
||||
|
||||
"include/input.hpp"
|
||||
|
||||
"include/transform.hpp"
|
||||
"include/object.hpp"
|
||||
"include/sceneroot.hpp"
|
||||
|
||||
"include/components/component.hpp"
|
||||
"include/components/transform.hpp"
|
||||
"include/components/camera.hpp"
|
||||
"include/components/mesh_renderer.hpp"
|
||||
"include/components/text_ui_renderer.hpp"
|
||||
|
@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#include "component.hpp"
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace components {
|
||||
|
||||
class ENGINE_API Transform : public Component {
|
||||
|
||||
// Scale, rotate (XYZ), translate
|
||||
|
||||
private:
|
||||
glm::mat4 m_transformMatrix{1.0f};
|
||||
|
||||
public:
|
||||
Transform(Object*);
|
||||
~Transform() override;
|
||||
|
||||
glm::vec3 position{0.0f};
|
||||
glm::quat rotation{};
|
||||
glm::vec3 scale{1.0f};
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
|
||||
#include "transform.hpp"
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -79,10 +81,13 @@ public:
|
||||
// Ignores 'Transform'
|
||||
void getAllSubComponents(struct CompList& compList, glm::mat4 t);
|
||||
|
||||
Transform transform;
|
||||
|
||||
private:
|
||||
static int s_object_count;
|
||||
int m_id = s_object_count;
|
||||
std::string m_name;
|
||||
|
||||
std::list<std::unique_ptr<Object>> m_children{};
|
||||
std::list<std::unique_ptr<Component>> m_components{};
|
||||
|
||||
@ -125,9 +130,6 @@ template<class T> void Object::deleteComponent()
|
||||
if (std::is_base_of<Component, T>::value == false) {
|
||||
throw std::runtime_error("deleteComponent() error: specified type is not a subclass of 'Component'");
|
||||
}
|
||||
if (std::is_same<T, components::Transform>::value) {
|
||||
throw std::runtime_error("deleteComponent() error: attempt to remove the 'Transform' component");
|
||||
}
|
||||
for (auto itr = m_components.begin(); itr != m_components.end(); ++itr) {
|
||||
if (dynamic_cast<T*>((*itr).get()) != nullptr) {
|
||||
m_components.erase(itr);
|
||||
|
17
include/transform.hpp
Normal file
17
include/transform.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
|
||||
struct ENGINE_API Transform {
|
||||
|
||||
// Scale, rotate (XYZ), translate
|
||||
|
||||
glm::vec3 position{0.0f};
|
||||
glm::quat rotation{};
|
||||
glm::vec3 scale{1.0f};
|
||||
|
||||
};
|
@ -1,16 +0,0 @@
|
||||
#include "components/transform.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace components {
|
||||
|
||||
Transform::Transform(Object* parent) : Component(parent, TypeEnum::TRANSFORM)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Transform::~Transform()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
#include "object.hpp"
|
||||
|
||||
#include "components/transform.hpp"
|
||||
#include "components/camera.hpp"
|
||||
#include "components/mesh_renderer.hpp"
|
||||
#include "components/text_ui_renderer.hpp"
|
||||
@ -18,8 +17,6 @@ Object::Object(std::string name, Object* parent, SceneRoot& root, struct GameIO
|
||||
res(*things.resMan)
|
||||
{
|
||||
s_object_count++;
|
||||
// all objects come with at least a transform component
|
||||
createComponent<components::Transform>();
|
||||
}
|
||||
|
||||
Object::~Object()
|
||||
@ -98,16 +95,16 @@ void Object::getAllSubComponents(struct CompList& compList, glm::mat4 parentTran
|
||||
|
||||
glm::mat4 objTransform{1.0f};
|
||||
|
||||
auto t = getComponent<Transform>();
|
||||
auto t = transform;
|
||||
|
||||
// rotation
|
||||
objTransform = glm::mat4_cast(t->rotation);
|
||||
objTransform = glm::mat4_cast(t.rotation);
|
||||
|
||||
// position
|
||||
reinterpret_cast<glm::vec3&>(objTransform[3]) = t->position;
|
||||
reinterpret_cast<glm::vec3&>(objTransform[3]) = t.position;
|
||||
|
||||
// scale (effectively applied first
|
||||
objTransform = glm::scale(objTransform, t->scale);
|
||||
objTransform = glm::scale(objTransform, t.scale);
|
||||
|
||||
const glm::mat4 newTransform = parentTransform * objTransform;
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "components/custom.hpp"
|
||||
#include "components/camera.hpp"
|
||||
#include "components/transform.hpp"
|
||||
#include "components/mesh_renderer.hpp"
|
||||
#include "components/text_ui_renderer.hpp"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user