/* * 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 . */ #include "entity/commands.hpp" #include "game/component/model.hpp" #include "game/component/transform.hpp" #include "game/component/parent.hpp" #include "game/component/celestial-body.hpp" #include "game/component/terrain.hpp" #include "math/quaternion.hpp" #include namespace entity { namespace command { void translate(entity::registry& registry, entity::id eid, const float3& translation) { const game::component::transform* transform = registry.try_get(eid); if (transform) { registry.patch ( eid, [&translation](auto& transform) { transform.local.translation += translation; } ); } } void rotate(entity::registry& registry, entity::id eid, float angle, const float3& axis) { const game::component::transform* transform = registry.try_get(eid); if (transform) { registry.patch ( eid, [angle, &axis](auto& transform) { transform.local.rotation = math::normalize(math::angle_axis(angle, axis) * transform.local.rotation); } ); } } void move_to(entity::registry& registry, entity::id eid, const float3& position) { const game::component::transform* transform = registry.try_get(eid); if (transform) { registry.patch ( eid, [&position](auto& transform) { transform.local.translation = position; } ); } } void warp_to(entity::registry& registry, entity::id eid, const float3& position) { const game::component::transform* transform = registry.try_get(eid); if (transform) { registry.patch ( eid, [&position](auto& transform) { transform.local.translation = position; transform.warp = true; } ); } } void set_scale(entity::registry& registry, entity::id eid, const float3& scale) { const game::component::transform* transform = registry.try_get(eid); if (transform) { registry.patch ( eid, [&scale](auto& transform) { transform.local.scale = scale; } ); } } void set_transform(entity::registry& registry, entity::id eid, const math::transform& transform, bool warp) { const game::component::transform* transform_component = registry.try_get(eid); if (transform_component) { registry.patch ( eid, [&other_transform = transform, warp](auto& transform) { transform.local = other_transform; transform.warp = warp; } ); } } void place(entity::registry& registry, entity::id eid, entity::id celestial_body_id, double altitude, double latitude, double longitude) { /* if (registry.has(eid)) { double x = 0.0; double y = altitude; double z = 0.0; if (registry.has(celestial_body_id)) { const game::component::celestial_body& celestial_body = registry.get(celestial_body_id); x = longitude * math::two_pi * celestial_body.radius; z = -latitude * math::two_pi * celestial_body.radius; if (registry.has(celestial_body_id)) { const game::component::terrain& terrain = registry.get(celestial_body_id); if (terrain.elevation != nullptr) { y += terrain.elevation(latitude, longitude); } } } game::component::transform& transform = registry.get(eid); transform.local.translation = math::vector(double3{x, y, z}); transform.warp = true; } */ } void assign_render_layers(entity::registry& registry, entity::id eid, unsigned int layers) { const game::component::model* model = registry.try_get(eid); if (model) { registry.patch ( eid, [layers](auto& model) { model.layers = layers; } ); } } math::transform get_local_transform(entity::registry& registry, entity::id eid) { const game::component::transform* transform = registry.try_get(eid); if (transform) { return transform->local; } return math::transform::identity; } math::transform get_world_transform(entity::registry& registry, entity::id eid) { const game::component::transform* transform = registry.try_get(eid); if (transform) { return transform->world; } return math::transform::identity; } } // namespace command } // namespace entity