From 9631e860c50c2123b96d1a44ce241eb7002b8414 Mon Sep 17 00:00:00 2001 From: Skittles Date: Sun, 14 Jun 2026 13:18:11 -0700 Subject: [PATCH] Simple Ray class --- src/core/CMakeLists.txt | 6 +++++- src/core/Ray.cpp | 12 ++++++++++++ src/core/Ray.hpp | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/core/Ray.cpp create mode 100644 src/core/Ray.hpp diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 687d971..adcf63d 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -3,8 +3,12 @@ set(target project_core) add_library(${target} core.cpp core.hpp + Ray.cpp + Ray.hpp ) target_compile_features(${target} PRIVATE cxx_std_23) -# target_link_libraries(${target} PRIVATE) \ No newline at end of file +target_include_directories(${target} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +target_link_libraries(${target} PUBLIC Eigen3::Eigen) \ No newline at end of file diff --git a/src/core/Ray.cpp b/src/core/Ray.cpp new file mode 100644 index 0000000..a48c936 --- /dev/null +++ b/src/core/Ray.cpp @@ -0,0 +1,12 @@ +#include "Ray.hpp" + +core::Ray::Ray(const Eigen::Vector3d &origin, const Eigen::Vector3d &direction) + : origin_(origin), direction_(direction) {} + +const Eigen::Vector3d &core::Ray::origin() const { return origin_; } + +const Eigen::Vector3d &core::Ray::direction() const { return direction_; } + +Eigen::Vector3d core::Ray::pointAt(const double t) const { + return origin_ + (t * direction_); +} diff --git a/src/core/Ray.hpp b/src/core/Ray.hpp new file mode 100644 index 0000000..c3424ff --- /dev/null +++ b/src/core/Ray.hpp @@ -0,0 +1,26 @@ +#ifndef RAY_HPP +#define RAY_HPP + +#include + +namespace core { + +class Ray { +public: + Ray(const Eigen::Vector3d &origin, const Eigen::Vector3d &direction); + ~Ray() = default; + + const Eigen::Vector3d &origin() const; + + const Eigen::Vector3d &direction() const; + + Eigen::Vector3d pointAt(const double t) const; + +private: + Eigen::Vector3d origin_; + Eigen::Vector3d direction_; +}; + +} // namespace core + +#endif