diff --git a/CMakeLists.txt b/CMakeLists.txt index 72ca0fb..8ce6573 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,10 @@ option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF) if (OMATH_BUILD_AS_SHARED_LIBRARY) add_library(omath SHARED source/Vector3.cpp) else() - add_library(omath STATIC source/Vector3.cpp) + add_library(omath STATIC source/Vector3.cpp + include/omath/collision/ICollidable.h + include/omath/collision/Cube.h + source/collision/Cube.cpp) endif() add_subdirectory(source) diff --git a/include/omath/collision/Cube.h b/include/omath/collision/Cube.h new file mode 100644 index 0000000..4c43796 --- /dev/null +++ b/include/omath/collision/Cube.h @@ -0,0 +1,22 @@ +// +// Created by vlad on 11/15/2024. +// +#pragma once +#include "ICollidable.h" + +namespace omath::collision +{ + class Cube final : public ICollidable + { + public: + + [[nodiscard]] + bool IsCollideWith(const std::shared_ptr& other) override; + + private: + [[nodiscard]] + bool IsCollideWithCube(const Cube& other); + bool IsCollideWithCapsule(const Cube& other); + + }; +} \ No newline at end of file diff --git a/include/omath/collision/ICollidable.h b/include/omath/collision/ICollidable.h new file mode 100644 index 0000000..6d89464 --- /dev/null +++ b/include/omath/collision/ICollidable.h @@ -0,0 +1,20 @@ +// +// Created by vlad on 11/15/2024. +// +#pragma once +#include "ICollidable.h" +#include + + + +namespace omath::collision +{ + class ICollidable + { + public: + virtual ~ICollidable() = default; + + [[nodiscard]] + virtual bool IsCollideWith(const std::shared_ptr& other) = 0; + }; +} diff --git a/include/omath/collision/LineTracer.hpp b/include/omath/collision/LineTracer.hpp index eb1f8fc..1de6d1e 100644 --- a/include/omath/collision/LineTracer.hpp +++ b/include/omath/collision/LineTracer.hpp @@ -2,7 +2,6 @@ // Created by Orange on 11/13/2024. // #pragma once -#include #include "omath/Vector3.hpp" #include "omath/Triangle3d.hpp" @@ -34,6 +33,6 @@ namespace omath::collision // Realization of Möller–Trumbore intersection algorithm // https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm [[nodiscard]] - static std::optional GetRayHitPoint(const Ray& ray, const Triangle3d& triangle); + static Vector3 GetRayHitPoint(const Ray& ray, const Triangle3d& triangle); }; } diff --git a/source/collision/CMakeLists.txt b/source/collision/CMakeLists.txt index 2904603..c82e0fb 100644 --- a/source/collision/CMakeLists.txt +++ b/source/collision/CMakeLists.txt @@ -1 +1,4 @@ -target_sources(omath PRIVATE LineTracer.cpp) +target_sources(omath PRIVATE + LineTracer.cpp + Cube.cpp +) diff --git a/source/collision/Cube.cpp b/source/collision/Cube.cpp new file mode 100644 index 0000000..e9dcb61 --- /dev/null +++ b/source/collision/Cube.cpp @@ -0,0 +1,13 @@ +// +// Created by vlad on 11/15/2024. +// +#include "omath/collision/Cube.h" + + +namespace omath::collision +{ + bool Cube::IsCollideWith(const std::shared_ptr& other) + { + + } +} diff --git a/source/collision/LineTracer.cpp b/source/collision/LineTracer.cpp index 602b92f..905350b 100644 --- a/source/collision/LineTracer.cpp +++ b/source/collision/LineTracer.cpp @@ -20,7 +20,7 @@ namespace omath::collision return DirectionVector().Normalized(); } - std::optional LineTracer::GetRayHitPoint(const Ray &ray, const Triangle3d &triangle) + Vector3 LineTracer::GetRayHitPoint(const Ray &ray, const Triangle3d &triangle) { constexpr float kEpsilon = std::numeric_limits::epsilon();