12#ifndef TOYMAKERENGINE_SCENECOMPONENTS_H
13#define TOYMAKERENGINE_SCENECOMPONENTS_H
16#include <glm/gtc/quaternion.hpp>
17#include <nlohmann/json.hpp>
137 return !(*
this == other);
260 inline void from_json(
const nlohmann::json& json,
Placement& placement) {
266 if(json.contains(
"inherit_mode")) {
267 placement.mInheritMode = json.at(
"inherit_mode");
270 if(json.contains(
"inherit_components") && json.at(
"inherit_components").is_array()) {
271 placement.mInheritedComponents = 0x0;
272 for(
const auto& component: json.at(
"inherit_components")) {
277 json.at(
"position")[0].get_to(placement.mPosition.x);
278 json.at(
"position")[1].get_to(placement.mPosition.y);
279 json.at(
"position")[2].get_to(placement.mPosition.z);
280 json.at(
"position")[3].get_to(placement.mPosition.w);
282 json.at(
"orientation")[0].get_to(placement.mOrientation.w);
283 json.at(
"orientation")[1].get_to(placement.mOrientation.x);
284 json.at(
"orientation")[2].get_to(placement.mOrientation.y);
285 json.at(
"orientation")[3].get_to(placement.mOrientation.z);
286 placement.
mOrientation = glm::normalize(placement.mOrientation);
288 json.at(
"scale")[0].get_to(placement.mScale.x);
289 json.at(
"scale")[1].get_to(placement.mScale.y);
290 json.at(
"scale")[2].get_to(placement.mScale.z);
294 inline void to_json(nlohmann::json& json,
const Placement& placement) {
295 std::vector<nlohmann::json> inheritComponentList {};
298 inheritComponentList.push_back(translationComponent);
302 inheritComponentList.push_back(rotationComponent);
306 inheritComponentList.push_back(scaleComponent);
310 {
"inherit_mode", placement.mInheritMode},
311 {
"inherit_components", inheritComponentList},
313 placement.mPosition.x,
314 placement.mPosition.y,
315 placement.mPosition.z,
316 placement.mPosition.w,
319 placement.mOrientation.w,
320 placement.mOrientation.x,
321 placement.mOrientation.y,
322 placement.mOrientation.z,
333 inline void to_json(nlohmann::json& json,
const SceneHierarchyData& sceneHierarchyData) {
334 (void)json; (void)sceneHierarchyData;
338 inline void from_json(
const nlohmann::json& json,
SceneHierarchyData& sceneHierarchyData) {
339 (void)json; (void)sceneHierarchyData;
343 inline void to_json(nlohmann::json& json,
const Transform& transform) {
351 inline void from_json(
const nlohmann::json& json,
Transform& transform) {
353 transform.mModelMatrix = glm::mat4{1.f};
371 float simulationProgress
375 .mPosition{ (1.f - simulationProgress) * previousState.
mPosition + simulationProgress * nextState.
mPosition },
377 .mScale{ (1.f - simulationProgress) * previousState.
mScale + simulationProgress * nextState.
mScale }
396 float simulationProgress
420 float simulationProgress
423 (void)simulationProgress;
RangeMapperLinear mProgressLimits
a functor that performs the actual interpolation in the default case
Definition ecs_world.hpp:354
ToyMaker Engine's implementation of an ECS system.
glm::mat4 getScaleMatrix(const glm::mat4 &fromTransform)
Given a transform, returns scale matrix that was used to compose the transform.
Definition util.cpp:43
glm::mat4 getRotationMatrix(const glm::mat4 &fromTransform)
Given a transform, returns rotation matrix that was used to compose the transform.
Definition util.cpp:52
glm::mat4 getTranslationMatrix(const glm::mat4 &fromTransform)
Given a transform, returns translation matrix that was used to compose the transform.
Definition util.cpp:58
T operator()(const T &previousState, const T &nextState, float simulationProgress=1.f) const
Returns an interpolated value for a component between two given states.
Definition ecs_world.hpp:2380
constexpr EntityID kMaxEntities
A user-set constant which limits the number of creatable entities in a single ECS system.
Definition ecs_world.hpp:119
std::uint64_t EntityID
A single unsigned integer used as a name for an entity managed by an ECS system.
Definition ecs_world.hpp:68
uint8_t TransformComponentSet
Field indicating which transform components this object would like to inherit from its parent in the ...
Definition scene_components.hpp:31
TransformComponentOption
The different kinds of values that can be inherited from a transform belonging to a parent.
Definition scene_components.hpp:40
TransformInheritMode
The different kinds of values that can be inherited from a transform belonging to a parent.
Definition scene_components.hpp:56
@ TRANSFORMCOMPONENT_ROTATION
Rotation is inherited from this object's parent.
Definition scene_components.hpp:44
@ TRANSFORMCOMPONENT_SCALE
Scale is inherited from this object's parent.
Definition scene_components.hpp:46
@ TRANSFORMCOMPONENT_TRANSLATION
Translation is inherited from this objects parent.
Definition scene_components.hpp:42
@ PARENT
Transform components are inherited from this object's parent.
Definition scene_components.hpp:58
@ GLOBAL
Definition scene_components.hpp:61
@ CAMERA
This object's transform is specified relative to the view matrix of the active camera in its ECS worl...
Definition scene_components.hpp:63
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:25
A component representing the position, rotation, and scale of an entity.
Definition scene_components.hpp:73
bool operator!=(const Placement &other)
An explicit specification for the inequality operator.
Definition scene_components.hpp:136
bool operator==(const Placement &other)
Compares this placement object to another for equality.
Definition scene_components.hpp:121
glm::quat mOrientation
This entity's orientation, as a glm::quat value.
Definition scene_components.hpp:86
static std::string getComponentTypeName()
Gets the component type string for this component.
Definition scene_components.hpp:112
TransformInheritMode mInheritMode
Field specifying which coordinate system this object's transform is specified relative to.
Definition scene_components.hpp:105
glm::vec4 mPosition
This entity's position.
Definition scene_components.hpp:78
glm::vec3 mScale
Factors along each axis by which geometry should be multiplied and scaled.
Definition scene_components.hpp:92
TransformComponentSet mInheritedComponents
Field specifying which aspects of its parent's transform this object's transform is specified relativ...
Definition scene_components.hpp:99
Component representing hierarchical information related to this entity.
Definition scene_components.hpp:212
static std::string getComponentTypeName()
Gets the component type string associated with this object.
Definition scene_components.hpp:242
EntityID mSibling
The entityID of this entity's next sibling.
Definition scene_components.hpp:227
EntityID mParent
The entityID of this entity's parent.
Definition scene_components.hpp:219
EntityID mChild
The first child of this entity.
Definition scene_components.hpp:235