-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
25 changed files
with
253 additions
and
87 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 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 |
---|---|---|
|
@@ -15,7 +15,7 @@ jobs: | |
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: DeterminateSystems/nix-installer-action@v14 | ||
- uses: DeterminateSystems/nix-installer-action@v16 | ||
- uses: DeterminateSystems/magic-nix-cache-action@v8 | ||
|
||
- uses: mozilla-actions/[email protected] | ||
|
@@ -27,7 +27,7 @@ jobs: | |
- name: coverage | ||
run: nix develop --command just coverage | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v4 | ||
uses: codecov/codecov-action@v5 | ||
with: | ||
files: build/coverage.info | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
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 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,7 @@ | ||
coverage: | ||
status: | ||
project: false | ||
ignore: | ||
- "examples" | ||
- "tools" | ||
- "subprojects" |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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 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 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,12 +1,21 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <flecs.h> | ||
|
||
#include "scene.hpp" | ||
namespace wren::scene::components { | ||
|
||
namespace wren::scene { | ||
struct Base { | ||
Base() = default; | ||
Base(const Base &) = default; | ||
Base(Base &&) = delete; | ||
auto operator=(const Base &) -> Base & = default; | ||
auto operator=(Base &&) -> Base & = delete; | ||
virtual ~Base() = default; | ||
|
||
// virtual void init(const flecs::world &world) = 0; | ||
}; | ||
|
||
// void iterate_known_components(const Scene& scene, entt::entity entity, | ||
// std::function<void()>); | ||
|
||
} | ||
} // namespace wren::scene::components |
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,40 @@ | ||
#pragma once | ||
|
||
#include <flecs.h> | ||
|
||
#include <memory> | ||
#include <optional> | ||
#include <wren/math/vector.hpp> | ||
#include <wren/scene/components/transform.hpp> | ||
|
||
#include "../components.hpp" | ||
|
||
namespace wren::scene::components { | ||
|
||
struct Collider : public Base { | ||
using Ptr = std::shared_ptr<Collider>; | ||
|
||
[[nodiscard]] virtual auto raycast(const Transform& transform, | ||
const math::Vec3f& origin, | ||
const math::Vec3f& direction) const | ||
-> std::optional<math::Vec3f> = 0; | ||
}; | ||
|
||
struct BoxCollider2D : public Collider { | ||
static void init(const flecs::world& world) { | ||
static bool inited = false; | ||
if (!inited) { | ||
inited = true; | ||
world.component<BoxCollider2D::Ptr>().is_a<Collider>(); | ||
} | ||
} | ||
|
||
[[nodiscard]] auto raycast(const Transform& transform, | ||
const math::Vec3f& origin, | ||
const math::Vec3f& direction) const | ||
-> std::optional<math::Vec3f> override; | ||
|
||
math::Vec2f size; | ||
}; | ||
|
||
} // namespace wren::scene::components |
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 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 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 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 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 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,26 @@ | ||
#include "scene/components/collider.hpp" | ||
|
||
namespace wren::scene::components { | ||
|
||
auto BoxCollider2D::raycast(const Transform& transform, | ||
const math::Vec3f& origin, | ||
const math::Vec3f& direction) const | ||
-> std::optional<math::Vec3f> { | ||
math::Vec3f normal = | ||
math::Quaternionf{transform.rotation}.to_mat() * math::Vec3f{0, 0, 1}; | ||
|
||
float denominator = normal.dot(direction); | ||
if (std::abs(denominator) < 0.0001) { | ||
return {}; | ||
} | ||
|
||
float t = normal.dot(transform.position - origin) / denominator; | ||
if (t < 0) { | ||
// Intersection points is behind the ray's origin | ||
return {}; | ||
} | ||
|
||
return origin + direction * t; | ||
} | ||
|
||
} // namespace wren::scene::components |
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 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 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,21 @@ | ||
#pragma once | ||
|
||
#include <flecs.h> | ||
|
||
#include <wren/math/vector.hpp> | ||
|
||
namespace wren::physics { | ||
|
||
struct RayHit { | ||
bool hit = false; | ||
math::Vec3f point; | ||
}; | ||
|
||
struct Ray { | ||
math::Vec3f origin; | ||
math::Vec3f direction; | ||
}; | ||
|
||
auto raycast(const flecs::world& world, const Ray& ray, RayHit& hit) -> bool; | ||
|
||
} // namespace wren::physics |
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,12 @@ | ||
wren_physics = static_library( | ||
'wren_physics', | ||
'src/ray.cpp', | ||
dependencies: [wren_dep, flecs], | ||
include_directories: ['include/wren', 'include/wren/physics'], | ||
) | ||
wren_physics_dep = declare_dependency( | ||
include_directories: 'include', | ||
link_with: wren_physics, | ||
) | ||
|
||
subdir('tests') |
Oops, something went wrong.