mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-06-20 03:36:37 +02:00
remove old transform and velocity components and replace with new decomposed components
focus on 2D for now
This commit is contained in:
12
framework/common_components/src/mm/components/position2d.hpp
Normal file
12
framework/common_components/src/mm/components/position2d.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
struct Position2D {
|
||||
glm::vec2 pos {0.f, 0.f};
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
// used to lift 2D into 3D space. like a z-index in css/svg
|
||||
struct Position2D_ZOffset {
|
||||
float z_offset = 500.f; // default camera allows values to be between 0 and 1000
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
12
framework/common_components/src/mm/components/position3d.hpp
Normal file
12
framework/common_components/src/mm/components/position3d.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
struct Position3D {
|
||||
glm::vec3 pos {0.f, 0.f, 0.f};
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
10
framework/common_components/src/mm/components/rotation2d.hpp
Normal file
10
framework/common_components/src/mm/components/rotation2d.hpp
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
struct Rotation2D {
|
||||
float rot {0.f};
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
12
framework/common_components/src/mm/components/scale2d.hpp
Normal file
12
framework/common_components/src/mm/components/scale2d.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
struct Scale2D {
|
||||
glm::vec2 scale {1.f, 1.f};
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@ -12,5 +13,26 @@ namespace glm {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec3, x, y, z)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec4, x, y, z, w)
|
||||
|
||||
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(mat4x4, [0], y, z, w)
|
||||
inline void to_json(nlohmann::json& nlohmann_json_j, const mat4x4& nlohmann_json_t) {
|
||||
// TODO: make 2d array?
|
||||
nlohmann_json_j = nlohmann::json::array_t{};
|
||||
nlohmann_json_j[0] = nlohmann_json_t[0];
|
||||
nlohmann_json_j[1] = nlohmann_json_t[1];
|
||||
nlohmann_json_j[2] = nlohmann_json_t[2];
|
||||
nlohmann_json_j[3] = nlohmann_json_t[3];
|
||||
}
|
||||
inline void from_json(const nlohmann::json& nlohmann_json_j, mat4x4& nlohmann_json_t) {
|
||||
if (!nlohmann_json_j.is_array()) {
|
||||
//throw nlohmann::json::type_error::create(0, "", nlohmann_json_j);
|
||||
assert(false && "expected array");
|
||||
return; // TODO: dont fail silently
|
||||
}
|
||||
|
||||
nlohmann_json_j.at(0).get_to(nlohmann_json_t[0]);
|
||||
nlohmann_json_j.at(1).get_to(nlohmann_json_t[1]);
|
||||
nlohmann_json_j.at(2).get_to(nlohmann_json_t[2]);
|
||||
nlohmann_json_j.at(3).get_to(nlohmann_json_t[3]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <mm/components/velocity2d.hpp>
|
||||
#include <mm/components/position2d.hpp>
|
||||
|
||||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2D, velocity, rotation)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position2D, pos)
|
||||
} // MM::Components
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <mm/components/transform2d.hpp>
|
||||
#include <mm/components/position2d_zoffset.hpp>
|
||||
|
||||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform2D, position, scale, rotation)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position2D_ZOffset, z_offset)
|
||||
} // MM::Components
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <mm/components/velocity3d.hpp>
|
||||
#include <mm/components/position3d.hpp>
|
||||
|
||||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity3D, velocity, rotation)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position3D, pos)
|
||||
} // MM::Components
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <mm/components/transform3d.hpp>
|
||||
#include <mm/components/rotation2d.hpp>
|
||||
|
||||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform3D, position, scale, rotation)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Rotation2D, rot)
|
||||
} // MM::Components
|
||||
|
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <mm/components/scale2d.hpp>
|
||||
|
||||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Scale2D, scale)
|
||||
} // MM::Components
|
||||
|
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <mm/components/transform4x4.hpp>
|
||||
|
||||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform4x4, trans)
|
||||
} // MM::Components
|
||||
|
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <mm/components/velocity2d_position.hpp>
|
||||
|
||||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DPosition, pos_vel)
|
||||
} // MM::Components
|
||||
|
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <mm/components/velocity2d_position_intent.hpp>
|
||||
|
||||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DPositionIntent, intent)
|
||||
} // MM::Components
|
||||
|
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <mm/components/velocity2d_rotation.hpp>
|
||||
|
||||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DRotation, rot_vel)
|
||||
} // MM::Components
|
||||
|
@ -1,55 +0,0 @@
|
||||
//
|
||||
// Created by FlaXxy on 29.07.2018.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
struct Transform2D {
|
||||
glm::vec2 position {0.0f,0.0f};
|
||||
glm::vec2 scale {1.0f,1.0f};
|
||||
float rotation {0.0f};
|
||||
|
||||
glm::mat3x3 getTransform3(void) const {
|
||||
//return transformationMatrix(scale, rotation, position);
|
||||
glm::mat3x3 res(1);
|
||||
res[2][0] = position.x;
|
||||
res[2][1] = position.y;
|
||||
float const s = sinf(rotation);
|
||||
float const c = cosf(rotation);
|
||||
res[0][0] = scale.x * c;
|
||||
res[0][1] = scale.x * s;
|
||||
res[1][0] = scale.y * -s;
|
||||
res[1][1] = scale.y * c;
|
||||
return res;
|
||||
}
|
||||
|
||||
glm::mat4x4 getTransform4(float z = 500.f) const {
|
||||
//return transformationMatrix(scale, rotation, position);
|
||||
glm::mat4x4 res{1};
|
||||
|
||||
//res[2][0] = position.x;
|
||||
//res[2][1] = position.y;
|
||||
res = glm::translate(res, glm::vec3(position, z));
|
||||
|
||||
//float const s = sinf(rotation);
|
||||
//float const c = cosf(rotation);
|
||||
//res[0][0] = scale.x * c;
|
||||
//res[0][1] = scale.x * s;
|
||||
//res[1][0] = scale.y * -s;
|
||||
//res[1][1] = scale.y * c;
|
||||
res = glm::rotate(res, rotation, glm::vec3(0.f, 0.f, 1.f));
|
||||
|
||||
res = glm::scale(res, glm::vec3(scale, 1.f));
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
//#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
//#include <entt/core/type_traits.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
struct Transform3D {
|
||||
glm::vec3 position {0.0f,0.0f,0.0f};
|
||||
glm::vec3 scale {1.0f,1.0f,1.0f};
|
||||
float rotation {0.0f};
|
||||
|
||||
glm::mat4x4 getTransform4(void) const {
|
||||
//return transformationMatrix(scale, rotation, position);
|
||||
glm::mat4x4 res{1};
|
||||
|
||||
//res[2][0] = position.x;
|
||||
//res[2][1] = position.y;
|
||||
res = glm::translate(res, position);
|
||||
|
||||
//float const s = sinf(rotation);
|
||||
//float const c = cosf(rotation);
|
||||
//res[0][0] = scale.x * c;
|
||||
//res[0][1] = scale.x * s;
|
||||
//res[1][0] = scale.y * -s;
|
||||
//res[1][1] = scale.y * c;
|
||||
res = glm::rotate(res, rotation, glm::vec3(0.f, 0.f, 1.f));
|
||||
|
||||
res = glm::scale(res, scale);
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
} // MM::Components
|
||||
|
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
// tag/flag to track dirty positional data, to reduce computation.
|
||||
struct DirtyTransformTag {};
|
||||
|
||||
struct Transform4x4 {
|
||||
glm::mat4x4 trans {1.f};
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
@ -1,16 +0,0 @@
|
||||
//
|
||||
// Created by FlaXxy on 29.07.2018.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
struct Velocity2D {
|
||||
glm::vec2 velocity;
|
||||
float rotation {0.f};
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
struct Velocity2DPosition {
|
||||
glm::vec2 pos_vel {0.f, 0.f};
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
struct Velocity2DPositionIntent {
|
||||
glm::vec2 intent {0.f, 0.f};
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
struct Velocity2DRotation {
|
||||
float rot_vel {0.f};
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
|
||||
struct Velocity3D {
|
||||
glm::vec3 velocity {0.f, 0.f, 0.f};
|
||||
glm::vec3 rotation {0.f, 0.f, 0.f};
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
Reference in New Issue
Block a user