@ -1,39 +0,0 @@ | |||||
/* | |||||
* Copyright (C) 2021 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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_GAME_COMPONENT_SAMARA_HPP | |||||
#define ANTKEEPER_GAME_COMPONENT_SAMARA_HPP | |||||
#include "utility/fundamental-types.hpp" | |||||
namespace game { | |||||
namespace component { | |||||
struct samara | |||||
{ | |||||
float3 direction; | |||||
float angle; | |||||
float chirality; | |||||
}; | |||||
} // namespace component | |||||
} // namespace game | |||||
#endif // ANTKEEPER_GAME_COMPONENT_SAMARA_HPP | |||||
@ -1,40 +0,0 @@ | |||||
/* | |||||
* Copyright (C) 2021 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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_GAME_COMPONENT_SNAP_HPP | |||||
#define ANTKEEPER_GAME_COMPONENT_SNAP_HPP | |||||
#include "geom/ray.hpp" | |||||
namespace game { | |||||
namespace component { | |||||
struct snap | |||||
{ | |||||
geom::ray<float> ray; | |||||
bool relative; | |||||
bool warp; | |||||
bool autoremove; | |||||
}; | |||||
} // namespace component | |||||
} // namespace game | |||||
#endif // ANTKEEPER_GAME_COMPONENT_SNAP_HPP | |||||
@ -1,61 +0,0 @@ | |||||
/* | |||||
* Copyright (C) 2021 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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#include "samara.hpp" | |||||
#include "game/component/transform.hpp" | |||||
#include "game/component/samara.hpp" | |||||
#include "entity/id.hpp" | |||||
#include "math/math.hpp" | |||||
#include "utility/fundamental-types.hpp" | |||||
namespace game { | |||||
namespace system { | |||||
samara::samara(entity::registry& registry): | |||||
updatable(registry) | |||||
{} | |||||
void samara::update(double t, double dt) | |||||
{ | |||||
registry.view<component::samara, component::transform>().each( | |||||
[&](entity::id entity_id, auto& samara, auto& transform) | |||||
{ | |||||
samara.angle += samara.chirality * math::radians(360.0f * 6.0f) * dt; | |||||
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<float>{1, 0, 0, 0}); | |||||
if (transform.local.translation.y() < 0.0f) | |||||
{ | |||||
const float zone = 200.0f; | |||||
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; | |||||
} | |||||
}); | |||||
} | |||||
} // namespace system | |||||
} // namespace game |
@ -1,39 +0,0 @@ | |||||
/* | |||||
* Copyright (C) 2021 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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_GAME_SYSTEM_SAMARA_HPP | |||||
#define ANTKEEPER_GAME_SYSTEM_SAMARA_HPP | |||||
#include "game/system/updatable.hpp" | |||||
namespace game { | |||||
namespace system { | |||||
class samara: public updatable | |||||
{ | |||||
public: | |||||
samara(entity::registry& registry); | |||||
virtual void update(double t, double dt); | |||||
}; | |||||
} // namespace system | |||||
} // namespace game | |||||
#endif // ANTKEEPER_GAME_SYSTEM_SAMARA_HPP | |||||
@ -1,93 +0,0 @@ | |||||
/* | |||||
* Copyright (C) 2021 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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#include "snapping.hpp" | |||||
#include "game/component/collision.hpp" | |||||
#include "game/component/snap.hpp" | |||||
#include "game/component/transform.hpp" | |||||
#include "entity/id.hpp" | |||||
#include "utility/fundamental-types.hpp" | |||||
namespace game { | |||||
namespace system { | |||||
snapping::snapping(entity::registry& registry): | |||||
updatable(registry) | |||||
{} | |||||
void snapping::update(double t, double dt) | |||||
{ | |||||
registry.view<component::transform, component::snap>().each( | |||||
[&](entity::id entity_id, auto& snap_transform, auto& snap) | |||||
{ | |||||
bool intersection = false; | |||||
float a = std::numeric_limits<float>::infinity(); | |||||
float3 pick; | |||||
geom::ray<float> snap_ray = snap.ray; | |||||
if (snap.relative) | |||||
{ | |||||
snap_ray.origin += snap_transform.local.translation; | |||||
snap_ray.direction = snap_transform.local.rotation * snap_ray.direction; | |||||
} | |||||
this->registry.view<component::transform, component::collision>().each( | |||||
[&](entity::id entity_id, auto& collision_transform, auto& collision) | |||||
{ | |||||
// Transform ray into local space of collision component | |||||
math::transform<float> inverse_transform = math::inverse(collision_transform.local); | |||||
float3 origin = inverse_transform * snap_ray.origin; | |||||
float3 direction = math::normalize(math::conjugate(collision_transform.local.rotation) * snap_ray.direction); | |||||
geom::ray<float> transformed_ray = {origin, direction}; | |||||
// Broad phase AABB test | |||||
auto aabb_result = geom::ray_aabb_intersection(transformed_ray, collision.bounds); | |||||
if (!std::get<0>(aabb_result)) | |||||
{ | |||||
return; | |||||
} | |||||
// Narrow phase mesh test | |||||
auto mesh_result = collision.mesh_accelerator.query_nearest(transformed_ray); | |||||
if (mesh_result) | |||||
{ | |||||
intersection = true; | |||||
if (mesh_result->t < a) | |||||
{ | |||||
a = mesh_result->t; | |||||
pick = snap_ray.extrapolate(a); | |||||
} | |||||
} | |||||
}); | |||||
if (intersection) | |||||
{ | |||||
snap_transform.local.translation = pick; | |||||
snap_transform.warp = snap.warp; | |||||
if (snap.autoremove) | |||||
{ | |||||
this->registry.remove<component::snap>(entity_id); | |||||
} | |||||
} | |||||
}); | |||||
} | |||||
} // namespace system | |||||
} // namespace game |
@ -1,40 +0,0 @@ | |||||
/* | |||||
* Copyright (C) 2021 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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_GAME_SYSTEM_SNAPPING_HPP | |||||
#define ANTKEEPER_GAME_SYSTEM_SNAPPING_HPP | |||||
#include "game/system/updatable.hpp" | |||||
namespace game { | |||||
namespace system { | |||||
class snapping: | |||||
public updatable | |||||
{ | |||||
public: | |||||
snapping(entity::registry& registry); | |||||
virtual void update(double t, double dt); | |||||
}; | |||||
} // namespace system | |||||
} // namespace game | |||||
#endif // ANTKEEPER_GAME_SYSTEM_SNAPPING_HPP | |||||