diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b6fdd6..17a1613 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG) find_package(OpenAL REQUIRED CONFIG) find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") + # Determine dependencies set(STATIC_LIBS dr_wav diff --git a/src/game/behavior/ebt.cpp b/src/game/behavior/ebt.cpp index 6d8b45e..61d0baf 100644 --- a/src/game/behavior/ebt.cpp +++ b/src/game/behavior/ebt.cpp @@ -40,7 +40,7 @@ status print_eid(context& context) status warp_to(context& context, float x, float y, float z) { auto& transform = context.registry->get(context.entity); - transform.transform.translation = {x, y, z}; + transform.local.translation = {x, y, z}; transform.warp = true; return status::success; } diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index e9c6e41..7c1fcbf 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -75,6 +75,7 @@ #include "game/systems/tool-system.hpp" #include "game/systems/ui-system.hpp" #include "game/systems/vegetation-system.hpp" +#include "game/systems/spatial-system.hpp" #include "game/entity-commands.hpp" #include "utility/paths.hpp" #include "event/event-dispatcher.hpp" @@ -818,7 +819,6 @@ void setup_systems(game_context* ctx) // Setup locomotion system ctx->locomotion_system = new locomotion_system(*ctx->ecs_registry); - ctx->constraint_system = new constraint_system(*ctx->ecs_registry); // Setup pheromone system ctx->pheromones = new pheromone_matrix(); @@ -830,6 +830,12 @@ void setup_systems(game_context* ctx) ctx->pheromones->current = 0; //diffuse(ctx->pheromones); + // Setup spatial system + ctx->spatial_system = new spatial_system(*ctx->ecs_registry); + + // Setup constraint system + ctx->constraint_system = new constraint_system(*ctx->ecs_registry); + // Setup render system ctx->render_system = new ::render_system(*ctx->ecs_registry); ctx->render_system->add_layer(ctx->overworld_scene); @@ -1095,14 +1101,16 @@ void setup_callbacks(game_context* ctx) ctx->locomotion_system->update(t, dt); ctx->camera_system->update(t, dt); ctx->tool_system->update(t, dt); + + ctx->spatial_system->update(t, dt); ctx->constraint_system->update(t, dt); //(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point(); - auto xf = ec::get_transform(*ctx->ecs_registry, ctx->lens_entity); + auto xf = ec::get_world_transform(*ctx->ecs_registry, ctx->lens_entity); ctx->lens_spotlight->look_at(xf.translation, xf.translation + ctx->sun_direct->get_direction(), {0, 1, 0}); - xf = ec::get_transform(*ctx->ecs_registry, ctx->flashlight_entity); + xf = ec::get_world_transform(*ctx->ecs_registry, ctx->flashlight_entity); //ctx->flashlight_spotlight->set_transform(xf); ctx->flashlight_spotlight->look_at(xf.translation, xf.translation + xf.rotation * float3{0, 0, 1}, {0, 0, -1}); diff --git a/src/game/components/parent-component.hpp b/src/game/components/parent-component.hpp new file mode 100644 index 0000000..023ff11 --- /dev/null +++ b/src/game/components/parent-component.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2020 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_ECS_PARENT_COMPONENT_HPP +#define ANTKEEPER_ECS_PARENT_COMPONENT_HPP + +namespace ecs { + +struct parent_component +{ + entt::entity parent; +}; + +} // namespace ecs + +#endif // ANTKEEPER_ECS_PARENT_COMPONENT_HPP diff --git a/src/game/components/transform-component.hpp b/src/game/components/transform-component.hpp index e475206..03cc08b 100644 --- a/src/game/components/transform-component.hpp +++ b/src/game/components/transform-component.hpp @@ -26,7 +26,8 @@ namespace ecs { struct transform_component { - math::transform transform; + math::transform local; + math::transform world; bool warp; }; diff --git a/src/game/entity-commands.cpp b/src/game/entity-commands.cpp index b062a2e..47782b9 100644 --- a/src/game/entity-commands.cpp +++ b/src/game/entity-commands.cpp @@ -22,6 +22,7 @@ #include "game/components/transform-component.hpp" #include "game/components/copy-transform-component.hpp" #include "game/components/snap-component.hpp" +#include "game/components/parent-component.hpp" #include namespace ec { @@ -33,7 +34,7 @@ void translate(entt::registry& registry, entt::entity eid, const float3& transla if (registry.has(eid)) { transform_component& transform = registry.get(eid); - transform.transform.translation += translation; + transform.local.translation += translation; } } @@ -42,7 +43,7 @@ void move_to(entt::registry& registry, entt::entity eid, const float3& position) if (registry.has(eid)) { transform_component& transform = registry.get(eid); - transform.transform.translation = position; + transform.local.translation = position; } } @@ -51,6 +52,7 @@ void warp_to(entt::registry& registry, entt::entity eid, const float3& position) if (registry.has(eid)) { transform_component& transform = registry.get(eid); + transform.local.translation = position; transform.warp = true; } } @@ -60,7 +62,7 @@ void set_transform(entt::registry& registry, entt::entity eid, const math::trans if (registry.has(eid)) { transform_component& component = registry.get(eid); - component.transform = transform; + component.local = transform; component.warp = warp; } } @@ -83,6 +85,14 @@ void assign_render_layers(entt::registry& registry, entt::entity eid, unsigned i model_component model = registry.get(eid); model.layers = layers; registry.replace(eid, model); + + // Apply to child layers + registry.view().each( + [&](auto entity, auto& component) + { + if (component.parent == eid) + assign_render_layers(registry, entity, layers); + }); } } @@ -92,15 +102,33 @@ void bind_transform(entt::registry& registry, entt::entity source_eid, entt::ent registry.assign_or_replace(source_eid, copy_transform); } -math::transform get_transform(entt::registry& registry, entt::entity eid) +math::transform get_local_transform(entt::registry& registry, entt::entity eid) { if (registry.has(eid)) { const transform_component& component = registry.get(eid); - return component.transform; + return component.local; } return math::identity_transform; } +math::transform get_world_transform(entt::registry& registry, entt::entity eid) +{ + if (registry.has(eid)) + { + const transform_component& component = registry.get(eid); + return component.world; + } + + return math::identity_transform; +} + +void parent(entt::registry& registry, entt::entity child, entt::entity parent) +{ + parent_component component; + component.parent = parent; + registry.assign_or_replace(child, component); +} + } // namespace ec diff --git a/src/game/entity-commands.hpp b/src/game/entity-commands.hpp index ea9f2c7..4db74d9 100644 --- a/src/game/entity-commands.hpp +++ b/src/game/entity-commands.hpp @@ -33,7 +33,9 @@ void set_transform(entt::registry& registry, entt::entity eid, const math::trans void place(entt::registry& registry, entt::entity eid, const float2& translation); void assign_render_layers(entt::registry& registry, entt::entity eid, unsigned int layers); void bind_transform(entt::registry& registry, entt::entity source_eid, entt::entity target_eid); -math::transform get_transform(entt::registry& registry, entt::entity eid); +math::transform get_local_transform(entt::registry& registry, entt::entity eid); +math::transform get_world_transform(entt::registry& registry, entt::entity eid); +void parent(entt::registry& registry, entt::entity child, entt::entity parent); } // namespace ec diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index 0280c7f..fdff8d0 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -74,6 +74,7 @@ class texture_2d; class timeline; class tool_system; class ui_system; +class spatial_system; class vegetation_system; class vertex_array; class vertex_buffer; @@ -231,6 +232,7 @@ struct game_context tool_system* tool_system; ui_system* ui_system; vegetation_system* vegetation_system; + spatial_system* spatial_system; // Debug cli* cli; diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index 2f3b210..4d68ebd 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -91,12 +91,11 @@ void play_state_enter(game_context* ctx) lens_archetype->assign(ecs_registry, ctx->lens_entity); brush_archetype->assign(ecs_registry, ctx->brush_entity); - // Create flashlight and light cone, bind light cone to flashlight, and move both to underworld scene + // Create flashlight and light cone, set light cone parent to flashlight, and move both to underworld scene flashlight_archetype->assign(ecs_registry, ctx->flashlight_entity); auto flashlight_light_cone = flashlight_light_cone_archetype->create(ecs_registry); - ec::bind_transform(ecs_registry, flashlight_light_cone, ctx->flashlight_entity); + ec::parent(ecs_registry, flashlight_light_cone, ctx->flashlight_entity); ec::assign_render_layers(ecs_registry, ctx->flashlight_entity, 2); - ec::assign_render_layers(ecs_registry, flashlight_light_cone, 2); // Make lens tool's model instance unculled, so its shadow is always visible. model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity); @@ -105,9 +104,10 @@ void play_state_enter(game_context* ctx) lens_model_instance->set_culling_mask(&ctx->no_cull); } - // Create lens light cone and bind to lens + // Create lens light cone and set its parent to lens auto lens_light_cone = lens_light_cone_archetype->create(ecs_registry); - ec::bind_transform(ecs_registry, lens_light_cone, ctx->lens_entity); + //ec::bind_transform(ecs_registry, lens_light_cone, ctx->lens_entity); + ec::parent(ecs_registry, lens_light_cone, ctx->lens_entity); // Activate lens tool auto& active_tool_component = ecs_registry.get(ctx->lens_entity); @@ -132,9 +132,9 @@ void play_state_enter(game_context* ctx) auto pebble_entity = pebble_archetype->create(ecs_registry); auto& transform = ecs_registry.get(pebble_entity); - transform.transform = math::identity_transform; - transform.transform.rotation = math::angle_axis(math::random(0.0f, math::two_pi), {0, 1, 0}); - transform.transform.scale = float3{1, 1, 1} * math::random(0.75f, 1.25f); + transform.local = math::identity_transform; + transform.local.rotation = math::angle_axis(math::random(0.0f, math::two_pi), {0, 1, 0}); + transform.local.scale = float3{1, 1, 1} * math::random(0.75f, 1.25f); ec::place(ecs_registry, pebble_entity, {x, z}); } @@ -168,10 +168,10 @@ void play_state_enter(game_context* ctx) auto& transform = ecs_registry.get(samara_entity); float zone = 200.0f; - transform.transform = math::identity_transform; - transform.transform.translation.x = math::random(-zone, zone); - transform.transform.translation.y = math::random(50.0f, 150.0f); - transform.transform.translation.z = math::random(-zone, zone); + transform.local = math::identity_transform; + transform.local.translation.x = math::random(-zone, zone); + transform.local.translation.y = math::random(50.0f, 150.0f); + transform.local.translation.z = math::random(-zone, zone); ecs::samara_component samara_component; samara_component.angle = math::random(0.0f, math::radians(360.0f)); @@ -183,7 +183,7 @@ void play_state_enter(game_context* ctx) // Setup camera focal point ecs::transform_component focal_point_transform; - focal_point_transform.transform = math::identity_transform; + focal_point_transform.local = math::identity_transform; focal_point_transform.warp = true; ecs::camera_follow_component focal_point_follow; ecs::snap_component focal_point_snap; diff --git a/src/game/systems/camera-system.cpp b/src/game/systems/camera-system.cpp index 3421077..3725b25 100644 --- a/src/game/systems/camera-system.cpp +++ b/src/game/systems/camera-system.cpp @@ -65,7 +65,7 @@ void camera_system::update(double t, double dt) registry.view().each( [&](auto entity, auto& follow, auto& transform) { - target_focal_point += transform.transform.translation; + target_focal_point += transform.local.translation; ++subject_count; }); if (subject_count > 1) diff --git a/src/game/systems/constraint-system.cpp b/src/game/systems/constraint-system.cpp index 7de2e95..457a5f7 100644 --- a/src/game/systems/constraint-system.cpp +++ b/src/game/systems/constraint-system.cpp @@ -42,13 +42,13 @@ void constraint_system::update(double t, double dt) { if (registry.has(constraint.target)) { - const float3& target_translation = transforms_view.get(constraint.target).transform.translation; + const float3& target_translation = transforms_view.get(constraint.target).world.translation; if (constraint.use_x) - transform.transform.translation.x = (constraint.invert_x) ? -target_translation.x : target_translation.x; + transform.world.translation.x = (constraint.invert_x) ? -target_translation.x : target_translation.x; if (constraint.use_y) - transform.transform.translation.y = (constraint.invert_y) ? -target_translation.y : target_translation.y; + transform.world.translation.y = (constraint.invert_y) ? -target_translation.y : target_translation.y; if (constraint.use_z) - transform.transform.translation.z = (constraint.invert_z) ? -target_translation.z : target_translation.z; + transform.world.translation.z = (constraint.invert_z) ? -target_translation.z : target_translation.z; } } ); @@ -60,7 +60,7 @@ void constraint_system::update(double t, double dt) { if (registry.has(constraint.target)) { - transform.transform.rotation = transforms_view.get(constraint.target).transform.rotation; + transform.world.rotation = transforms_view.get(constraint.target).world.rotation; } } ); @@ -72,13 +72,13 @@ void constraint_system::update(double t, double dt) { if (registry.has(constraint.target)) { - const float3& target_scale = transforms_view.get(constraint.target).transform.scale; + const float3& target_scale = transforms_view.get(constraint.target).world.scale; if (constraint.use_x) - transform.transform.scale.x = target_scale.x; + transform.world.scale.x = target_scale.x; if (constraint.use_y) - transform.transform.scale.y = target_scale.y; + transform.world.scale.y = target_scale.y; if (constraint.use_z) - transform.transform.scale.z = target_scale.z; + transform.world.scale.z = target_scale.z; } } ); @@ -90,7 +90,7 @@ void constraint_system::update(double t, double dt) { if (registry.has(constraint.target)) { - transform.transform = transforms_view.get(constraint.target).transform; + transform.world = transforms_view.get(constraint.target).world; } } ); diff --git a/src/game/systems/render-system.cpp b/src/game/systems/render-system.cpp index e871ea4..34fffbe 100644 --- a/src/game/systems/render-system.cpp +++ b/src/game/systems/render-system.cpp @@ -40,7 +40,7 @@ void render_system::update(double t, double dt) { model_instance* instance = model_instances[entity]; - instance->set_transform(transform.transform); + instance->set_transform(transform.world); if (transform.warp) { diff --git a/src/game/systems/samara-system.cpp b/src/game/systems/samara-system.cpp index 50ad30f..f8e3e16 100644 --- a/src/game/systems/samara-system.cpp +++ b/src/game/systems/samara-system.cpp @@ -36,18 +36,18 @@ void samara_system::update(double t, double dt) { samara.angle += samara.chirality * math::radians(360.0f * 6.0f) * dt; - transform.transform.translation += samara.direction * 20.0f * (float)dt; - transform.transform.rotation = + transform.local.translation += samara.direction * 20.0f * (float)dt; + transform.local.rotation = math::angle_axis(samara.angle, float3{0, 1, 0}) * math::angle_axis(math::radians(20.0f), float3{1, 0, 0}) * ((samara.chirality < 0.0f) ? math::angle_axis(math::radians(180.0f), float3{0, 0, -1}) : math::quaternion{1, 0, 0, 0}); - if (transform.transform.translation.y < 0.0f) + if (transform.local.translation.y < 0.0f) { const float zone = 200.0f; - transform.transform.translation.x = math::random(-zone, zone); - transform.transform.translation.y = math::random(100.0f, 150.0f); - transform.transform.translation.z = math::random(-zone, zone); + transform.local.translation.x = math::random(-zone, zone); + transform.local.translation.y = math::random(100.0f, 150.0f); + transform.local.translation.z = math::random(-zone, zone); transform.warp = true; samara.chirality = (math::random(0.0f, 1.0f) < 0.5f) ? -1.0f : 1.0f; diff --git a/src/game/systems/snapping-system.cpp b/src/game/systems/snapping-system.cpp index 2ab78b5..66d3ad2 100644 --- a/src/game/systems/snapping-system.cpp +++ b/src/game/systems/snapping-system.cpp @@ -41,17 +41,17 @@ void snapping_system::update(double t, double dt) ray snap_ray = snap.ray; if (snap.relative) { - snap_ray.origin += snap_transform.transform.translation; - snap_ray.direction = snap_transform.transform.rotation * snap_ray.direction; + snap_ray.origin += snap_transform.local.translation; + snap_ray.direction = snap_transform.local.rotation * snap_ray.direction; } registry.view().each( [&](auto entity, auto& collision_transform, auto& collision) { // Transform ray into local space of collision component - math::transform inverse_transform = math::inverse(collision_transform.transform); + math::transform inverse_transform = math::inverse(collision_transform.local); float3 origin = inverse_transform * snap_ray.origin; - float3 direction = math::normalize(math::conjugate(collision_transform.transform.rotation) * snap_ray.direction); + float3 direction = math::normalize(math::conjugate(collision_transform.local.rotation) * snap_ray.direction); ray transformed_ray = {origin, direction}; // Broad phase AABB test @@ -76,7 +76,7 @@ void snapping_system::update(double t, double dt) if (intersection) { - snap_transform.transform.translation = pick; + snap_transform.local.translation = pick; snap_transform.warp = snap.warp; if (snap.autoremove) diff --git a/src/game/systems/spatial-system.cpp b/src/game/systems/spatial-system.cpp new file mode 100644 index 0000000..a5fb561 --- /dev/null +++ b/src/game/systems/spatial-system.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2020 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 . + */ + +#include "spatial-system.hpp" +#include "game/components/parent-component.hpp" +#include "game/components/transform-component.hpp" + +using namespace ecs; + +spatial_system::spatial_system(entt::registry& registry): + entity_system(registry) +{} + +void spatial_system::update(double t, double dt) +{ + /// @TODO: sort transforms by parent, for more multi-level hierarchies + + // Process parent transforms first + registry.view().each( + [&](auto entity, auto& transform) + { + if (!registry.has(entity)) + { + transform.world = transform.local; + } + }); + + // Process child transforms second + registry.view().each( + [&](auto entity, auto& transform) + { + if (registry.has(entity)) + { + entt::entity parent = registry.get(entity).parent; + const transform_component& parent_transform = registry.get(parent); + transform.world = parent_transform.world * transform.local; + transform.warp = parent_transform.warp; + } + }); +} diff --git a/src/game/systems/spatial-system.hpp b/src/game/systems/spatial-system.hpp new file mode 100644 index 0000000..d797be7 --- /dev/null +++ b/src/game/systems/spatial-system.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2020 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_SPATIAL_SYSTEM_HPP +#define ANTKEEPER_SPATIAL_SYSTEM_HPP + +#include "entity-system.hpp" + +class spatial_system: + public entity_system +{ +public: + spatial_system(entt::registry& registry); + virtual void update(double t, double dt); +}; + +#endif // ANTKEEPER_SPATIAL_SYSTEM_HPP + diff --git a/src/game/systems/terrain-system.cpp b/src/game/systems/terrain-system.cpp index 6879709..227b76b 100644 --- a/src/game/systems/terrain-system.cpp +++ b/src/game/systems/terrain-system.cpp @@ -55,7 +55,7 @@ void terrain_system::update(double t, double dt) registry.view().each( [this](auto entity, auto& terrain, auto& transform) { - transform.transform.translation = float3{(float)terrain.x * patch_size, 0.0f, (float)terrain.z * patch_size}; + transform.local.translation = float3{(float)terrain.x * patch_size, 0.0f, (float)terrain.z * patch_size}; transform.warp = true; }); } @@ -330,8 +330,8 @@ void terrain_system::on_terrain_construct(entt::registry& registry, entt::entity // Assign the entity a transform component transform_component transform; - transform.transform = math::identity_transform; - transform.transform.translation = float3{(float)component.x * patch_size, 0.0f, (float)component.z * patch_size}; + transform.local = math::identity_transform; + transform.local.translation = float3{(float)component.x * patch_size, 0.0f, (float)component.z * patch_size}; transform.warp = true; registry.assign_or_replace(entity, transform); } diff --git a/src/game/systems/tool-system.cpp b/src/game/systems/tool-system.cpp index aa83f0f..5da265b 100644 --- a/src/game/systems/tool-system.cpp +++ b/src/game/systems/tool-system.cpp @@ -52,6 +52,7 @@ tool_system::tool_system(entt::registry& registry): pick_spring.v = {0.0f, 0.0f, 0.0f}; active_tool = entt::null; + warp = true; } void tool_system::update(double t, double dt) @@ -73,9 +74,9 @@ void tool_system::update(double t, double dt) registry.view().each( [&](auto entity, auto& transform, auto& collision) { - math::transform inverse_transform = math::inverse(transform.transform); + math::transform inverse_transform = math::inverse(transform.local); float3 origin = inverse_transform * pick_origin; - float3 direction = math::normalize(math::conjugate(transform.transform.rotation) * pick_direction); + float3 direction = math::normalize(math::conjugate(transform.local.rotation) * pick_direction); ray transformed_ray = {origin, direction}; // Broad phase AABB test @@ -138,7 +139,7 @@ void tool_system::update(double t, double dt) if (intersection) { - transform.transform.translation = pick_spring.x0 + float3{0, tool.hover_distance, 0}; + transform.local.translation = pick_spring.x0 + float3{0, tool.hover_distance, 0}; } // Interpolate between left and right hand @@ -147,13 +148,20 @@ void tool_system::update(double t, double dt) if (tool.heliotropic) { math::quaternion solar_rotation = math::rotation(float3{0, -1, 0}, sun_direction); - transform.transform.translation = pick_spring.x0 + solar_rotation * float3{0, tool.hover_distance, 0}; + transform.local.translation = pick_spring.x0 + solar_rotation * float3{0, tool.hover_distance, 0}; - transform.transform.rotation = solar_rotation * hand_rotation; + transform.local.rotation = solar_rotation * hand_rotation; } else { - transform.transform.rotation = hand_rotation; + transform.local.rotation = hand_rotation; + } + + if (warp) + { + transform.warp = true; + ec::assign_render_layers(registry, active_tool, 1); + warp = false; } //math::quaternion rotation = math::angle_axis(orbit_cam->get_azimuth() + pick_angle, float3{0, 1, 0}); @@ -203,8 +211,9 @@ void tool_system::set_active_tool(entt::entity entity) { auto& tool = registry.get(active_tool); tool.active = true; - ec::assign_render_layers(registry, active_tool, 1); } + + warp = true; } diff --git a/src/game/systems/tool-system.hpp b/src/game/systems/tool-system.hpp index 4c7cb10..dbdba16 100644 --- a/src/game/systems/tool-system.hpp +++ b/src/game/systems/tool-system.hpp @@ -61,6 +61,7 @@ private: bool pick_enabled; float3 sun_direction; entt::entity active_tool; + bool warp; numeric_spring hand_angle_spring; numeric_spring pick_spring; diff --git a/src/resources/entity-archetype-loader.cpp b/src/resources/entity-archetype-loader.cpp index b2e50f2..e24a992 100644 --- a/src/resources/entity-archetype-loader.cpp +++ b/src/resources/entity-archetype-loader.cpp @@ -156,16 +156,16 @@ static bool load_transform_component(archetype& archetype, const std::vector> component.transform.translation.x; - stream >> component.transform.translation.y; - stream >> component.transform.translation.z; - stream >> component.transform.rotation.w; - stream >> component.transform.rotation.x; - stream >> component.transform.rotation.y; - stream >> component.transform.rotation.z; - stream >> component.transform.scale.x; - stream >> component.transform.scale.y; - stream >> component.transform.scale.z; + stream >> component.local.translation.x; + stream >> component.local.translation.y; + stream >> component.local.translation.z; + stream >> component.local.rotation.w; + stream >> component.local.rotation.x; + stream >> component.local.rotation.y; + stream >> component.local.rotation.z; + stream >> component.local.scale.x; + stream >> component.local.scale.y; + stream >> component.local.scale.z; component.warp = true; archetype.set(component);