From 3ce188c876a8fb143179ecd2ffc68206b2b62b9a Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Wed, 22 Mar 2023 18:33:23 +0800 Subject: [PATCH] Improve 3D transform struct --- src/engine/animation/pose.cpp | 4 +- src/engine/animation/pose.hpp | 2 +- src/engine/math/math.hpp | 4 +- src/engine/math/matrix.hpp | 4 + src/engine/math/quaternion.hpp | 7 + src/engine/math/transform-functions.hpp | 103 -------- src/engine/math/transform-operators.hpp | 63 ----- src/engine/math/transform-type.hpp | 59 ----- src/engine/math/transform.hpp | 235 +++++++++++++++++++ src/engine/physics/kinematics/rigid-body.hpp | 6 +- src/engine/render/context.hpp | 1 - src/engine/render/passes/sky-pass.cpp | 2 +- src/engine/scene/billboard.cpp | 8 +- src/engine/scene/object.hpp | 4 +- src/engine/scene/static-mesh.cpp | 2 +- src/engine/scene/text.cpp | 2 +- src/game/ant/ant-morphogenesis.cpp | 3 +- src/game/ant/ant-swarm.cpp | 2 +- src/game/commands/commands.cpp | 4 +- src/game/commands/commands.hpp | 2 +- src/game/components/transform-component.hpp | 2 +- src/game/loaders/entity-archetype-loader.cpp | 2 +- src/game/spawn.cpp | 4 +- src/game/states/nest-selection-state.cpp | 6 +- src/game/states/nuptial-flight-state.cpp | 4 +- src/game/systems/collision-system.cpp | 1 - src/game/systems/constraint-system.cpp | 4 +- src/game/systems/physics-system.cpp | 1 - 28 files changed, 277 insertions(+), 264 deletions(-) delete mode 100644 src/engine/math/transform-functions.hpp delete mode 100644 src/engine/math/transform-operators.hpp delete mode 100644 src/engine/math/transform-type.hpp create mode 100644 src/engine/math/transform.hpp diff --git a/src/engine/animation/pose.cpp b/src/engine/animation/pose.cpp index f7f6399..2684d61 100644 --- a/src/engine/animation/pose.cpp +++ b/src/engine/animation/pose.cpp @@ -18,8 +18,6 @@ */ #include -#include -#include void concatenate(const pose& bone_space, pose& skeleton_space) { @@ -52,6 +50,6 @@ void matrix_palette(const pose& inverse_bind_pose, const pose& pose, float4x4* p for (auto&& [bone, transform]: pose) { auto index = ::bone_index(bone); - palette[index] = math::matrix_cast(inverse_bind_pose.at(bone) * transform); + palette[index] = (inverse_bind_pose.at(bone) * transform).matrix(); } } diff --git a/src/engine/animation/pose.hpp b/src/engine/animation/pose.hpp index f351621..671f4d6 100644 --- a/src/engine/animation/pose.hpp +++ b/src/engine/animation/pose.hpp @@ -21,7 +21,7 @@ #define ANTKEEPER_ANIMATION_POSE_HPP #include -#include +#include #include #include diff --git a/src/engine/math/math.hpp b/src/engine/math/math.hpp index 8a8620f..d69579e 100644 --- a/src/engine/math/math.hpp +++ b/src/engine/math/math.hpp @@ -28,9 +28,7 @@ namespace math {} #include #include -#include -#include -#include +#include #include #include diff --git a/src/engine/math/matrix.hpp b/src/engine/math/matrix.hpp index 101ca66..5b4d261 100644 --- a/src/engine/math/matrix.hpp +++ b/src/engine/math/matrix.hpp @@ -91,9 +91,13 @@ struct matrix [[nodiscard]] inline constexpr matrix size_cast(std::index_sequence) const noexcept { if constexpr (O == M) + { return {((I < N) ? columns[I] : matrix::identity()[I]) ...}; + } else + { return {((I < N) ? vector(columns[I]) : matrix::identity()[I]) ...}; + } } /** diff --git a/src/engine/math/quaternion.hpp b/src/engine/math/quaternion.hpp index 291d1af..0478159 100644 --- a/src/engine/math/quaternion.hpp +++ b/src/engine/math/quaternion.hpp @@ -151,6 +151,7 @@ struct quaternion * * @return Rotation matrix. */ + /// @{ [[nodiscard]] constexpr explicit operator matrix_type() const noexcept { const T xx = x() * x(); @@ -171,6 +172,12 @@ struct quaternion }; } + [[nodiscard]] inline constexpr matrix_type matrix() const noexcept + { + return matrix_type(*this); + } + /// @} + /** * Casts the quaternion to a 4-element vector, with the real part as the first element and the imaginary part as the following three elements. * diff --git a/src/engine/math/transform-functions.hpp b/src/engine/math/transform-functions.hpp deleted file mode 100644 index c6b16b4..0000000 --- a/src/engine/math/transform-functions.hpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2023 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#ifndef ANTKEEPER_MATH_TRANSFORM_FUNCTIONS_HPP -#define ANTKEEPER_MATH_TRANSFORM_FUNCTIONS_HPP - -#include -#include - -namespace math { - -/** - * Calculates the inverse of a transform. - * - * @param t Transform of which to take the inverse. - */ -template -[[nodiscard]] transform inverse(const transform& t); - -/** - * Converts a transform to a transformation matrix. - * - * @param t Transform. - * @return Matrix representing the transformation described by `t`. - */ -template -[[nodiscard]] matrix matrix_cast(const transform& t); - -/** - * Multiplies two transforms. - * - * @param x First transform. - * @param y Second transform. - * @return Product of the two transforms. - */ -template -[[nodiscard]] transform mul(const transform& x, const transform& y); - -/** - * Multiplies a vector by a transform. - * - * @param t Transform. - * @param v Vector. - * @return Product of the transform and vector. - */ -template -[[nodiscard]] vector mul(const transform& t, const vector& v); - -template -transform inverse(const transform& t) -{ - transform inverse_t; - inverse_t.scale = {T(1) / t.scale.x(), T(1) / t.scale.y(), T(1) / t.scale.z()}; - inverse_t.rotation = conjugate(t.rotation); - inverse_t.translation = negate(mul(inverse_t.rotation, t.translation)); - return inverse_t; -} - -template -matrix matrix_cast(const transform& t) -{ - matrix transformation = matrix(matrix(t.rotation)); - transformation[3] = {t.translation[0], t.translation[1], t.translation[2], T(1)}; - return scale(transformation, t.scale); -} - -template -transform mul(const transform& x, const transform& y) -{ - return - { - mul(x, y.translation), - normalize(mul(x.rotation, y.rotation)), - mul(x.scale, y.scale) - }; -} - -template -vector mul(const transform& t, const vector& v) -{ - return add(t.translation, (mul(t.rotation, mul(v, t.scale)))); -} - -} // namespace math - -#endif // ANTKEEPER_MATH_TRANSFORM_FUNCTIONS_HPP - diff --git a/src/engine/math/transform-operators.hpp b/src/engine/math/transform-operators.hpp deleted file mode 100644 index 61c7b7d..0000000 --- a/src/engine/math/transform-operators.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2023 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#ifndef ANTKEEPER_MATH_TRANSFORM_OPERATORS_HPP -#define ANTKEEPER_MATH_TRANSFORM_OPERATORS_HPP - -#include -#include - -/// @copydoc math::mul(const math::transform&, const math::transform&) -template -[[nodiscard]] math::transform operator*(const math::transform& x, const math::transform& y); - -/// @copydoc math::mul(const math::transform&, const math::vector&) -template -[[nodiscard]] math::vector operator*(const math::transform& t, const math::vector& v); - -/** - * Multiplies two transforms and stores the result in the first transform. - * - * @param x First transform. - * @param y Second transform. - * @return Reference to the first transform. - */ -template -math::transform& operator*=(math::transform& x, const math::transform& y); - -template -inline math::transform operator*(const math::transform& x, const math::transform& y) -{ - return mul(x, y); -} - -template -inline math::vector operator*(const math::transform& t, const math::vector& v) -{ - return mul(t, v); -} - -template -inline math::transform& operator*=(math::transform& x, const math::vector& y) -{ - return (x = x * y); -} - -#endif // ANTKEEPER_MATH_TRANSFORM_OPERATORS_HPP - diff --git a/src/engine/math/transform-type.hpp b/src/engine/math/transform-type.hpp deleted file mode 100644 index f0ef10f..0000000 --- a/src/engine/math/transform-type.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2023 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#ifndef ANTKEEPER_MATH_TRANSFORM_TYPE_HPP -#define ANTKEEPER_MATH_TRANSFORM_TYPE_HPP - -#include -#include - -namespace math { - -/** - * Represents 3D TRS transformation. - * - * @tparam T Scalar type. - */ -template -struct transform -{ - /// Translation vector - vector translation; - - /// Rotation quaternion - quaternion rotation; - - /// Scale vector - vector scale; - - /// Identity transform. - static const transform identity; -}; - -template -const transform transform::identity = -{ - vector::zero(), - quaternion::identity(), - vector::one() -}; - -} // namespace math - -#endif // ANTKEEPER_MATH_TRANSFORM_TYPE_HPP diff --git a/src/engine/math/transform.hpp b/src/engine/math/transform.hpp new file mode 100644 index 0000000..337a94b --- /dev/null +++ b/src/engine/math/transform.hpp @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2023 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_MATH_TRANSFORM_HPP +#define ANTKEEPER_MATH_TRANSFORM_HPP + +#include +#include +#include + +namespace math { + +/** + * 3D transformation. + * + * Transformations are applied in the following order: scale, rotation, translation. + * + * @tparam T Scalar type. + */ +template +struct transform +{ + /// Scalar type. + using scalar_type = T; + + /// Vector type. + using vector_type = vector; + + /// Quaternion type. + using quaternion_type = quaternion; + + /// Transformation matrix type. + using matrix_type = matrix; + + /// Translation vector. + vector_type translation; + + /// Rotation quaternion. + quaternion_type rotation; + + /// Scale vector. + vector_type scale; + + /** + * Constructs a matrix representing the transformation. + * + * @return Transformation matrix. + */ + /// @{ + [[nodiscard]] constexpr explicit operator matrix_type() const noexcept + { + matrix_type matrix = matrix_type(quaternion_type::matrix_type(rotation)); + + matrix[0][0] *= scale[0]; + matrix[0][1] *= scale[0]; + matrix[0][2] *= scale[0]; + + matrix[1][0] *= scale[1]; + matrix[1][1] *= scale[1]; + matrix[1][2] *= scale[1]; + + matrix[2][0] *= scale[2]; + matrix[2][1] *= scale[2]; + matrix[2][2] *= scale[2]; + + matrix[3][0] = translation[0]; + matrix[3][1] = translation[1]; + matrix[3][2] = translation[2]; + + return matrix; + } + + [[nodiscard]] inline constexpr matrix_type matrix() const noexcept + { + return matrix_type(*this); + } + /// @} + + /* + * Type-casts the transform scalars using `static_cast`. + * + * @tparam U Target scalar type. + * + * @return Type-casted transform. + */ + template + [[nodiscard]] inline constexpr explicit operator transform() const noexcept + { + return {math::vector(translation), math::quaternion(rotation), math::vector(scale)}; + } + + /// Returns an identity transform. + [[nodiscard]] static inline constexpr transform identity() noexcept + { + return {vector_type::zero(), quaternion_type::identity(), vector_type::one()}; + } +}; + +/** + * Calculates the inverse of a transform. + * + * @param t Transform of which to take the inverse. + */ +template +[[nodiscard]] transform inverse(const transform& t) noexcept; + +/** + * Combines two transforms. + * + * @param x First transform. + * @param y Second transform. + * + * @return Product of the two transforms. + */ +template +[[nodiscard]] transform mul(const transform& x, const transform& y); + +/** + * Transforms a vector by a transform. + * + * @param t Transform. + * @param v Vector. + * + * @return Transformed vector. + */ +template +[[nodiscard]] constexpr vector mul(const transform& t, const vector& v) noexcept; + +/** + * Transforms a vector by the inverse of a transform. + * + * @param v Vector. + * @param t Transform. + * + * @return Transformed vector. + */ +template +[[nodiscard]] constexpr vector mul(const vector& v, const transform& t) noexcept; + +template +transform inverse(const transform& t) noexcept +{ + transform inverse_t; + + inverse_t.scale = T{1} / t.scale; + inverse_t.rotation = conjugate(t.rotation); + inverse_t.translation = -(inverse_t.rotation * t.translation); + + return inverse_t; +} + +template +transform mul(const transform& x, const transform& y) +{ + return + { + mul(x, y.translation), + normalize(x.rotation * y.rotation), + x.scale * y.scale + }; +} + +template +constexpr vector mul(const transform& t, const vector& v) noexcept +{ + return t.translation + t.rotation * (t.scale * v); +} + +template +inline constexpr vector mul(const vector& v, const transform& t) noexcept +{ + return mul(inverse(t), v); +} + +namespace operators { + +/// @copydoc math::mul(const math::transform&, const math::transform&) +template +[[nodiscard]] inline math::transform operator*(const math::transform& x, const math::transform& y) +{ + return mul(x, y); +} + +/// @copydoc math::mul(const math::transform&, const math::vector&) +template +[[nodiscard]] inline constexpr math::vector operator*(const math::transform& t, const math::vector& v) noexcept +{ + return mul(t, v); +} + +/// @copydoc math::mul(const math::vector&, const math::transform&) +template +[[nodiscard]] inline constexpr math::vector operator*(const math::vector& v, const math::transform& t) noexcept +{ + return mul(v, t); +} + +/** + * Combines two transforms and stores the result in the first transform. + * + * @param x First transform. + * @param y Second transform. + * + * @return Reference to the first transform. + */ +template +inline math::transform& operator*=(math::transform& x, const math::transform& y) +{ + return (x = x * y); +} + +} // namespace operators + +} // namespace math + +// Bring transform operators into global namespace +using namespace math::operators; + +#endif // ANTKEEPER_MATH_TRANSFORM_HPP diff --git a/src/engine/physics/kinematics/rigid-body.hpp b/src/engine/physics/kinematics/rigid-body.hpp index 556066b..661fbe2 100644 --- a/src/engine/physics/kinematics/rigid-body.hpp +++ b/src/engine/physics/kinematics/rigid-body.hpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include namespace physics { @@ -457,10 +457,10 @@ public: private: /// Transformation representing the current state of the rigid body. - math::transform m_current_transform{math::transform::identity}; + math::transform m_current_transform{math::transform::identity()}; /// Transformation representing the previous state of the rigid body. - math::transform m_previous_transform{math::transform::identity}; + math::transform m_previous_transform{math::transform::identity()}; /// Center of mass. math::vector m_center_of_mass{math::vector::zero()}; diff --git a/src/engine/render/context.hpp b/src/engine/render/context.hpp index 61f3ac4..91cc03e 100644 --- a/src/engine/render/context.hpp +++ b/src/engine/render/context.hpp @@ -21,7 +21,6 @@ #define ANTKEEPER_RENDER_CONTEXT_HPP #include -#include #include #include diff --git a/src/engine/render/passes/sky-pass.cpp b/src/engine/render/passes/sky-pass.cpp index 62ee24a..73144b1 100644 --- a/src/engine/render/passes/sky-pass.cpp +++ b/src/engine/render/passes/sky-pass.cpp @@ -318,7 +318,7 @@ void sky_pass::render(render::context& ctx) moon_transform.rotation = moon_rotation_tween.interpolate(ctx.alpha); moon_transform.scale = {moon_radius, moon_radius, moon_radius}; - model = math::matrix_cast(moon_transform); + model = moon_transform.matrix(); float3x3 normal_model = math::transpose(math::inverse(float3x3(model))); rasterizer->use_program(*moon_shader_program); diff --git a/src/engine/scene/billboard.cpp b/src/engine/scene/billboard.cpp index 0af1553..41ec679 100644 --- a/src/engine/scene/billboard.cpp +++ b/src/engine/scene/billboard.cpp @@ -97,7 +97,7 @@ void billboard::render(render::context& ctx) const transform.rotation = math::normalize(math::look_rotation(ctx.camera->get_forward(), ctx.camera->get_up()) * transform.rotation); - m_render_op.transform = math::matrix_cast(transform); + m_render_op.transform = transform.matrix(); break; } @@ -112,7 +112,7 @@ void billboard::render(render::context& ctx) const const auto up = math::cross(look, right); transform.rotation = math::normalize(math::look_rotation(look, up) * transform.rotation); - m_render_op.transform = math::matrix_cast(transform); + m_render_op.transform = transform.matrix(); break; } @@ -140,7 +140,7 @@ void billboard::set_billboard_type(billboard_type type) if (m_billboard_type == scene::billboard_type::flat) { - m_render_op.transform = math::matrix_cast(get_transform()); + m_render_op.transform = get_transform().matrix(); } } @@ -150,7 +150,7 @@ void billboard::transformed() if (m_billboard_type == scene::billboard_type::flat) { - m_render_op.transform = math::matrix_cast(get_transform()); + m_render_op.transform = get_transform().matrix(); } } diff --git a/src/engine/scene/object.hpp b/src/engine/scene/object.hpp index 4efffbb..1dade30 100644 --- a/src/engine/scene/object.hpp +++ b/src/engine/scene/object.hpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -141,7 +141,7 @@ private: */ inline virtual void transformed() {} - transform_type m_transform{transform_type::identity}; + transform_type m_transform{transform_type::identity()}; }; /** diff --git a/src/engine/scene/static-mesh.cpp b/src/engine/scene/static-mesh.cpp index f6b7d89..9918d2a 100644 --- a/src/engine/scene/static-mesh.cpp +++ b/src/engine/scene/static-mesh.cpp @@ -104,7 +104,7 @@ void static_mesh::transformed() { update_bounds(); - const float4x4 transform_matrix = math::matrix_cast(get_transform()); + const float4x4 transform_matrix = get_transform().matrix(); for (auto& operation: m_operations) { operation.transform = transform_matrix; diff --git a/src/engine/scene/text.cpp b/src/engine/scene/text.cpp index a767a1b..c899777 100644 --- a/src/engine/scene/text.cpp +++ b/src/engine/scene/text.cpp @@ -137,7 +137,7 @@ void text::transformed() m_world_bounds.extend(get_transform() * m_local_bounds.corner(i)); } - m_render_op.transform = math::matrix_cast(get_transform()); + m_render_op.transform = get_transform().matrix(); } void text::update_content() diff --git a/src/game/ant/ant-morphogenesis.cpp b/src/game/ant/ant-morphogenesis.cpp index 1be3989..04116de 100644 --- a/src/game/ant/ant-morphogenesis.cpp +++ b/src/game/ant/ant-morphogenesis.cpp @@ -20,7 +20,6 @@ #include "game/ant/ant-morphogenesis.hpp" #include #include -#include #include #include #include @@ -816,7 +815,7 @@ std::unique_ptr ant_morphogenesis(const ant_phenome& phenome) const ::skeleton* hindwings_skeleton = (phenome.wings->present) ? &phenome.wings->hindwings_model->get_skeleton() : nullptr; // Calculate transformations from part space to body space - const math::transform legs_to_body = math::transform::identity; + const math::transform legs_to_body = math::transform::identity(); const math::transform head_to_body = bind_pose_ss.at(*bones.mesosoma) * mesosoma_skeleton.bind_pose.at(mesosoma_skeleton.bone_map.at("head")); const math::transform mandible_l_to_body = bind_pose_ss.at(*bones.head) * head_skeleton.bind_pose.at(head_skeleton.bone_map.at("mandible_l")); const math::transform mandible_r_to_body = bind_pose_ss.at(*bones.head) * head_skeleton.bind_pose.at(head_skeleton.bone_map.at("mandible_r")); diff --git a/src/game/ant/ant-swarm.cpp b/src/game/ant/ant-swarm.cpp index 30d9c80..28374b8 100644 --- a/src/game/ant/ant-swarm.cpp +++ b/src/game/ant/ant-swarm.cpp @@ -64,7 +64,7 @@ entity::id create_ant_swarm(::game& ctx) // Init transform component ::transform_component transform; - transform.local = math::transform::identity; + transform.local = math::transform::identity(); transform.world = transform.local; // Init picking component diff --git a/src/game/commands/commands.cpp b/src/game/commands/commands.cpp index 5428e86..dedc6d3 100644 --- a/src/game/commands/commands.cpp +++ b/src/game/commands/commands.cpp @@ -152,7 +152,7 @@ math::transform get_local_transform(entity::registry& registry, entity::i return transform->local; } - return math::transform::identity; + return math::transform::identity(); } math::transform get_world_transform(entity::registry& registry, entity::id eid) @@ -163,7 +163,7 @@ math::transform get_world_transform(entity::registry& registry, entity::i return transform->world; } - return math::transform::identity; + return math::transform::identity(); } } // namespace command diff --git a/src/game/commands/commands.hpp b/src/game/commands/commands.hpp index 9a9cb8e..0791ddc 100644 --- a/src/game/commands/commands.hpp +++ b/src/game/commands/commands.hpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include /// Commands which operate on entity::id components diff --git a/src/game/components/transform-component.hpp b/src/game/components/transform-component.hpp index c2a7346..15b88c4 100644 --- a/src/game/components/transform-component.hpp +++ b/src/game/components/transform-component.hpp @@ -20,7 +20,7 @@ #ifndef ANTKEEPER_GAME_TRANSFORM_COMPONENT_HPP #define ANTKEEPER_GAME_TRANSFORM_COMPONENT_HPP -#include +#include struct transform_component diff --git a/src/game/loaders/entity-archetype-loader.cpp b/src/game/loaders/entity-archetype-loader.cpp index 9470ac2..76fb032 100644 --- a/src/game/loaders/entity-archetype-loader.cpp +++ b/src/game/loaders/entity-archetype-loader.cpp @@ -219,7 +219,7 @@ static bool load_component_orbit(entity::archetype& archetype, const json& eleme static bool load_component_transform(entity::archetype& archetype, const json& element) { ::transform_component component; - component.local = math::transform::identity; + component.local = math::transform::identity(); if (element.contains("translation")) { diff --git a/src/game/spawn.cpp b/src/game/spawn.cpp index 374268c..be2b8e7 100644 --- a/src/game/spawn.cpp +++ b/src/game/spawn.cpp @@ -29,7 +29,7 @@ entity::id spawn_ant_egg(::game& ctx, const ant_genome& genome, bool fertilized, // Construct transform component transform_component transform_component; - transform_component.local = math::transform::identity; + transform_component.local = math::transform::identity(); transform_component.local.translation = position; transform_component.world = transform_component.local; ctx.entity_registry->emplace<::transform_component>(egg_eid, transform_component); @@ -47,7 +47,7 @@ entity::id spawn_ant_larva(::game& ctx, const ant_genome& genome, const float3& // Construct transform component transform_component transform_component; - transform_component.local = math::transform::identity; + transform_component.local = math::transform::identity(); transform_component.local.translation = position; transform_component.world = transform_component.local; ctx.entity_registry->emplace<::transform_component>(larva_eid, transform_component); diff --git a/src/game/states/nest-selection-state.cpp b/src/game/states/nest-selection-state.cpp index 1586418..8278106 100644 --- a/src/game/states/nest-selection-state.cpp +++ b/src/game/states/nest-selection-state.cpp @@ -102,6 +102,8 @@ nest_selection_state::nest_selection_state(::game& ctx): worker_model = ant_morphogenesis(worker_phenome); debug::log::trace("Generated worker model"); + + // Create floor plane auto floor_archetype = ctx.resource_manager->load("desert-scrub-plane.ent"); @@ -128,7 +130,7 @@ nest_selection_state::nest_selection_state(::game& ctx): // Create worker entity(s) worker_ant_eid = ctx.entity_registry->create(); transform_component worker_transform_component; - worker_transform_component.local = math::transform::identity; + worker_transform_component.local = math::transform::identity(); worker_transform_component.local.translation = {0, 0.5f, -4}; worker_transform_component.world = worker_transform_component.local; ctx.entity_registry->emplace(worker_ant_eid, worker_transform_component); @@ -281,7 +283,7 @@ void nest_selection_state::create_first_person_camera_rig() { // Construct first person camera rig transform component transform_component first_person_camera_rig_transform; - first_person_camera_rig_transform.local = math::transform::identity; + first_person_camera_rig_transform.local = math::transform::identity(); first_person_camera_rig_transform.local.translation = {0, 10, 0}; first_person_camera_rig_transform.world = first_person_camera_rig_transform.local; diff --git a/src/game/states/nuptial-flight-state.cpp b/src/game/states/nuptial-flight-state.cpp index 0b43a16..ba2e50d 100644 --- a/src/game/states/nuptial-flight-state.cpp +++ b/src/game/states/nuptial-flight-state.cpp @@ -250,7 +250,7 @@ void nuptial_flight_state::create_camera_rig() // Construct camera rig focus transform component transform_component camera_rig_focus_transform; - camera_rig_focus_transform.local = math::transform::identity; + camera_rig_focus_transform.local = math::transform::identity(); camera_rig_focus_transform.world = camera_rig_focus_transform.local; // Construct camera rig focus entity @@ -331,7 +331,7 @@ void nuptial_flight_state::create_camera_rig() // Construct camera rig transform component transform_component camera_rig_transform; - camera_rig_transform.local = math::transform::identity; + camera_rig_transform.local = math::transform::identity(); camera_rig_transform.world = camera_rig_transform.local; // Construct camera rig camera component diff --git a/src/game/systems/collision-system.cpp b/src/game/systems/collision-system.cpp index 3b0da65..6ec2dda 100644 --- a/src/game/systems/collision-system.cpp +++ b/src/game/systems/collision-system.cpp @@ -23,7 +23,6 @@ #include "game/components/rigid-body-component.hpp" #include #include -#include #include diff --git a/src/game/systems/constraint-system.cpp b/src/game/systems/constraint-system.cpp index 110e580..8a1ce05 100644 --- a/src/game/systems/constraint-system.cpp +++ b/src/game/systems/constraint-system.cpp @@ -19,9 +19,7 @@ #include "game/systems/constraint-system.hpp" #include "game/components/constraint-stack-component.hpp" -#include -#include - +#include constraint_system::constraint_system(entity::registry& registry): updatable_system(registry) { diff --git a/src/game/systems/physics-system.cpp b/src/game/systems/physics-system.cpp index fa952f0..bcccd09 100644 --- a/src/game/systems/physics-system.cpp +++ b/src/game/systems/physics-system.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include