diff --git a/examples/nand/main.cpp b/examples/nand/main.cpp index 97c9984..da42109 100644 --- a/examples/nand/main.cpp +++ b/examples/nand/main.cpp @@ -4,6 +4,11 @@ #include #include #include +#include +#include +#include + +namespace components = wren::scene::components; auto initialize(const std::shared_ptr& app) -> wren::expected { @@ -38,7 +43,7 @@ auto initialize(const std::shared_ptr& app) return {}; } -void update(); +void update(const std::shared_ptr& scene); auto main() -> int { spdlog::set_level(spdlog::level::debug); @@ -57,19 +62,27 @@ auto main() -> int { return EXIT_FAILURE; } - app->add_callback_to_phase(wren::CallbackPhase::Update, []() { update(); }); + const auto scene = wren::scene::Scene::create(); + + auto quad = scene->create_entity("Quad"); + quad.add_component( + new components::BoxCollider2D()); + auto& collider = quad.get_component(); + + app->add_callback_to_phase(wren::CallbackPhase::Update, + [scene]() { update(scene); }); app->run(); return EXIT_SUCCESS; } -void update() { - // TODO Raycasting here - +void update(const std::shared_ptr& scene) { wren::physics::RayHit hit; wren::physics::Ray ray; - if (wren::physics::raycast(ray, hit)) { + ray.origin = wren::math::Vec3f{100, 0, 1}; + ray.direction = wren::math::Vec3f{0, 0, -1}; + if (wren::physics::raycast(scene->world(), ray, hit)) { spdlog::info("Hit object"); } } diff --git a/wren/src/scene/components/collider.cpp b/wren/src/scene/components/collider.cpp index d41fb49..32209bb 100644 --- a/wren/src/scene/components/collider.cpp +++ b/wren/src/scene/components/collider.cpp @@ -20,6 +20,8 @@ auto BoxCollider2D::raycast(const Transform& transform, return {}; } + // TODO Check if the collision is within the bounds of the plane + return origin + direction * t; }