-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9227231
commit da9946d
Showing
13 changed files
with
150 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/// @file | ||
/// @brief Component @ref cubos::engine::Transform. | ||
/// @ingroup transform-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Component which stores the transformation matrix of an entity. | ||
/// | ||
/// @ingroup transform-plugin | ||
struct [[cubos::component("cubos/transform", VecStorage)]] Transform | ||
{ | ||
CUBOS_REFLECT; | ||
|
||
glm::mat4 mat = glm::mat4(1.0F); ///< Local to world space matrix. | ||
|
||
/// @brief Get the transformation matrix from local to world space. | ||
/// @return The transformation matrix from local to world space. | ||
glm::mat4 localToWorld() const; | ||
|
||
/// @brief Get the position of the transform. | ||
/// @return The position of the transform. | ||
glm::vec3 position() const; | ||
|
||
/// @brief Set the position of the transform. | ||
/// @param pos The new position. | ||
void position(const glm::vec3& pos); | ||
|
||
/// @brief Translate the transform. | ||
/// @param delta The translation vector. | ||
void translate(const glm::vec3& delta); | ||
|
||
/// @brief Get the rotation of the transform. | ||
/// @return The rotation of the transform. | ||
glm::quat rotation() const; | ||
|
||
/// @brief Get the rotation of the transform as euler angles. | ||
/// @return The rotation of the transform as euler angles. | ||
glm::vec3 eulerRotation() const; | ||
|
||
/// @brief Set the rotation of the transform. | ||
/// @param rot The new rotation. | ||
void rotation(const glm::quat& rot); | ||
|
||
/// @brief Set the rotation of the transform. | ||
/// @param euler The new rotation as euler angles. | ||
void rotation(const glm::vec3& euler); | ||
|
||
/// @brief Rotate the transform. | ||
/// @param delta The rotation quaternion. | ||
void rotate(const glm::quat& delta); | ||
|
||
/// @brief Rotate the transform. | ||
/// @param eulerDelta The rotation as euler angles. | ||
void rotate(const glm::vec3& eulerDelta); | ||
|
||
/// @brief Get the scale of the transform. | ||
/// @return The scale of the transform. | ||
float scale() const; | ||
|
||
/// @brief Set the scale of the transform. | ||
/// @param scale The new scale. | ||
void scale(float scale); | ||
}; | ||
} // namespace cubos::engine |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,15 @@ | ||
#include <cubos/engine/transform/plugin.hpp> | ||
|
||
using cubos::core::ecs::Commands; | ||
using cubos::core::ecs::OptRead; | ||
using cubos::core::ecs::Query; | ||
using cubos::core::ecs::Write; | ||
using namespace cubos::engine; | ||
|
||
static void autoLocalToWorld(Commands cmds, | ||
Query<OptRead<LocalToWorld>, OptRead<Position>, OptRead<Rotation>, OptRead<Scale>> query) | ||
static void updateTransform() | ||
{ | ||
for (auto [entity, localToWorld, position, rotation, scale] : query) | ||
{ | ||
if (!localToWorld && (position || rotation || scale)) | ||
{ | ||
cmds.add(entity, LocalToWorld{}); | ||
} | ||
} | ||
} | ||
|
||
static void applyTransform(Query<Write<LocalToWorld>, OptRead<Position>, OptRead<Rotation>, OptRead<Scale>> query) | ||
{ | ||
for (auto [entity, localToWorld, position, rotation, scale] : query) | ||
{ | ||
localToWorld->mat = glm::mat4(1.0F); | ||
if (position) | ||
{ | ||
localToWorld->mat = glm::translate(localToWorld->mat, position->vec); | ||
} | ||
|
||
if (rotation) | ||
{ | ||
localToWorld->mat *= glm::toMat4(rotation->quat); | ||
} | ||
|
||
if (scale) | ||
{ | ||
localToWorld->mat = glm::scale(localToWorld->mat, glm::vec3(scale->factor)); | ||
} | ||
} | ||
// In the future, parent-child relationships will be handled here. | ||
} | ||
|
||
void cubos::engine::transformPlugin(Cubos& cubos) | ||
{ | ||
cubos.addComponent<Position>(); | ||
cubos.addComponent<Rotation>(); | ||
cubos.addComponent<Scale>(); | ||
cubos.addComponent<LocalToWorld>(); | ||
cubos.addComponent<Transform>(); | ||
|
||
cubos.system(autoLocalToWorld).before("cubos.transform.update"); | ||
cubos.system(applyTransform).tagged("cubos.transform.update"); | ||
cubos.system(updateTransform).tagged("cubos.transform.update"); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <cubos/core/ecs/component/reflection.hpp> | ||
#include <cubos/core/geom/decomposition.hpp> | ||
#include <cubos/core/reflection/external/glm.hpp> | ||
|
||
#include <cubos/engine/transform/transform.hpp> | ||
|
||
using namespace cubos::engine; | ||
|
||
glm::mat4 Transform::localToWorld() const | ||
{ | ||
return mat; | ||
} | ||
|
||
glm::vec3 Transform::position() const | ||
{ | ||
return core::geom::position(mat); | ||
} | ||
|
||
void Transform::position(const glm::vec3& pos) | ||
{ | ||
core::geom::position(mat, pos); | ||
} | ||
|
||
void Transform::translate(const glm::vec3& delta) | ||
{ | ||
core::geom::translate(mat, delta); | ||
} | ||
|
||
glm::quat Transform::rotation() const | ||
{ | ||
return core::geom::rotation(mat); | ||
} | ||
|
||
glm::vec3 Transform::eulerRotation() const | ||
{ | ||
return core::geom::eulerRotation(mat); | ||
} | ||
|
||
void Transform::rotation(const glm::quat& rot) | ||
{ | ||
core::geom::rotation(mat, rot); | ||
} | ||
|
||
void Transform::rotation(const glm::vec3& euler) | ||
{ | ||
core::geom::rotation(mat, euler); | ||
} | ||
|
||
void Transform::rotate(const glm::quat& delta) | ||
{ | ||
core::geom::rotate(mat, delta); | ||
} | ||
|
||
void Transform::rotate(const glm::vec3& eulerDelta) | ||
{ | ||
core::geom::rotate(mat, eulerDelta); | ||
} | ||
|
||
float Transform::scale() const | ||
{ | ||
return core::geom::scale(mat); | ||
} | ||
|
||
void Transform::scale(float scale) | ||
{ | ||
core::geom::scale(mat, scale); | ||
} | ||
|
||
CUBOS_REFLECT_IMPL(cubos::engine::Transform) | ||
{ | ||
return core::ecs::ComponentTypeBuilder<Transform>("cubos::engine::Transform") | ||
.withField("mat", &Transform::mat) | ||
.build(); | ||
} |