// // Created by tv on 30.04.23. // #ifndef SPOONTOOL_TRANSFORM_H #define SPOONTOOL_TRANSFORM_H #include #include #include #include "glm/ext/vector_float3.hpp" #include "glm/ext/matrix_transform.hpp" #include #include #include #include struct Transform{ inline Transform(): Position(0,0,0), Scale(1,1,1), Rotation(0,0,0), LastPosition(0,0,0), LastScale(0,0,0), LastRotation(0,0,0){} inline Transform(Vector3 pos, Vector3 scale, Vector3 rot): Position(pos), Scale(scale), Rotation(rot), LastPosition(0,0,0), LastScale(0,0,0), LastRotation(0,0,0){} inline void updateMatricies() { glm::vec3& pos = *(glm::vec3*)&Position; glm::vec3& rot = *(glm::vec3*)&Rotation; glm::vec3& scale = *(glm::vec3*)&Scale; glm::mat4 translationMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,pos.y,pos.z)); glm::mat4 rotationMatrixZ = glm::rotate(glm::mat4(1),glm::radians(rot.z), glm::vec3(0,0,1)); glm::mat4 rotationMatrixY = glm::rotate(rotationMatrixZ,glm::radians(rot.y), glm::vec3(0,1,0)); rotationMatrix = glm::rotate(rotationMatrixY,glm::radians(rot.x), glm::vec3(1,0,0)); glm::mat4 scaleMatrix = glm::scale(glm::mat4(1),scale); matrix = translationMatrix * rotationMatrix * scaleMatrix; } inline void recalcMatriciesIfNeeded() { if( Position != LastPosition || Scale != LastScale || Rotation != LastRotation ) { updateMatricies(); LastPosition = Position; LastScale = Scale; LastRotation = Rotation; } } Vector3 Position,Scale,Rotation; glm::mat4 matrix, rotationMatrix; void InsertIntoYaml(YAML::Emitter &Emitter); private: Vector3 LastPosition,LastScale,LastRotation; }; #endif //SPOONTOOL_TRANSFORM_H