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/sceneroot.cpp"
|
||||||
|
|
||||||
"src/components/component.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/camera.cpp"
|
||||||
"src/components/mesh_renderer.cpp"
|
"src/components/mesh_renderer.cpp"
|
||||||
"src/components/text_ui_renderer.cpp"
|
"src/components/text_ui_renderer.cpp"
|
||||||
@ -45,11 +45,11 @@ add_library(${PROJECT_NAME} SHARED
|
|||||||
|
|
||||||
"include/input.hpp"
|
"include/input.hpp"
|
||||||
|
|
||||||
|
"include/transform.hpp"
|
||||||
"include/object.hpp"
|
"include/object.hpp"
|
||||||
"include/sceneroot.hpp"
|
"include/sceneroot.hpp"
|
||||||
|
|
||||||
"include/components/component.hpp"
|
"include/components/component.hpp"
|
||||||
"include/components/transform.hpp"
|
|
||||||
"include/components/camera.hpp"
|
"include/components/camera.hpp"
|
||||||
"include/components/mesh_renderer.hpp"
|
"include/components/mesh_renderer.hpp"
|
||||||
"include/components/text_ui_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 <glm/mat4x4.hpp>
|
||||||
|
|
||||||
|
#include "transform.hpp"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -79,10 +81,13 @@ public:
|
|||||||
// Ignores 'Transform'
|
// Ignores 'Transform'
|
||||||
void getAllSubComponents(struct CompList& compList, glm::mat4 t);
|
void getAllSubComponents(struct CompList& compList, glm::mat4 t);
|
||||||
|
|
||||||
|
Transform transform;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int s_object_count;
|
static int s_object_count;
|
||||||
int m_id = s_object_count;
|
int m_id = s_object_count;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
std::list<std::unique_ptr<Object>> m_children{};
|
std::list<std::unique_ptr<Object>> m_children{};
|
||||||
std::list<std::unique_ptr<Component>> m_components{};
|
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) {
|
if (std::is_base_of<Component, T>::value == false) {
|
||||||
throw std::runtime_error("deleteComponent() error: specified type is not a subclass of 'Component'");
|
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) {
|
for (auto itr = m_components.begin(); itr != m_components.end(); ++itr) {
|
||||||
if (dynamic_cast<T*>((*itr).get()) != nullptr) {
|
if (dynamic_cast<T*>((*itr).get()) != nullptr) {
|
||||||
m_components.erase(itr);
|
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 "object.hpp"
|
||||||
|
|
||||||
#include "components/transform.hpp"
|
|
||||||
#include "components/camera.hpp"
|
#include "components/camera.hpp"
|
||||||
#include "components/mesh_renderer.hpp"
|
#include "components/mesh_renderer.hpp"
|
||||||
#include "components/text_ui_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)
|
res(*things.resMan)
|
||||||
{
|
{
|
||||||
s_object_count++;
|
s_object_count++;
|
||||||
// all objects come with at least a transform component
|
|
||||||
createComponent<components::Transform>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::~Object()
|
Object::~Object()
|
||||||
@ -98,16 +95,16 @@ void Object::getAllSubComponents(struct CompList& compList, glm::mat4 parentTran
|
|||||||
|
|
||||||
glm::mat4 objTransform{1.0f};
|
glm::mat4 objTransform{1.0f};
|
||||||
|
|
||||||
auto t = getComponent<Transform>();
|
auto t = transform;
|
||||||
|
|
||||||
// rotation
|
// rotation
|
||||||
objTransform = glm::mat4_cast(t->rotation);
|
objTransform = glm::mat4_cast(t.rotation);
|
||||||
|
|
||||||
// position
|
// position
|
||||||
reinterpret_cast<glm::vec3&>(objTransform[3]) = t->position;
|
reinterpret_cast<glm::vec3&>(objTransform[3]) = t.position;
|
||||||
|
|
||||||
// scale (effectively applied first
|
// scale (effectively applied first
|
||||||
objTransform = glm::scale(objTransform, t->scale);
|
objTransform = glm::scale(objTransform, t.scale);
|
||||||
|
|
||||||
const glm::mat4 newTransform = parentTransform * objTransform;
|
const glm::mat4 newTransform = parentTransform * objTransform;
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include "components/custom.hpp"
|
#include "components/custom.hpp"
|
||||||
#include "components/camera.hpp"
|
#include "components/camera.hpp"
|
||||||
#include "components/transform.hpp"
|
|
||||||
#include "components/mesh_renderer.hpp"
|
#include "components/mesh_renderer.hpp"
|
||||||
#include "components/text_ui_renderer.hpp"
|
#include "components/text_ui_renderer.hpp"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user