Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Engine/cpp/Runtime/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
add_modules_library(Definitions)
add_modules_library(Math)
add_modules_library(IO)
add_modules_library(Memory)
add_modules_library(Logging)
add_modules_library(Containers)
# PIC: these are linked into the shared Runtime library (via Core), so their objects
# must be position-independent - a non-PIC static (e.g. Quaternion::identity) otherwise
# fails to relocate when making the shared object.
add_modules_library(Definitions PIC)
add_modules_library(Math PIC)
add_modules_library(IO PIC)
add_modules_library(Memory PIC)
add_modules_library(Logging PIC)

target_link_libraries(Math PUBLIC Definitions bx)
target_link_libraries(Math PUBLIC Definitions)
target_link_libraries(IO PUBLIC Definitions stb_image)
target_link_libraries(Memory PUBLIC Definitions Math)
target_link_libraries(Logging PUBLIC Definitions)
target_link_libraries(Containers PUBLIC Definitions Memory Math)
18 changes: 17 additions & 1 deletion Engine/cpp/Runtime/Core/Math/Functions.cppm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module;

#include <numbers>
#include <cmath>
#include <concepts>
#include <limits>
Expand Down Expand Up @@ -114,6 +115,21 @@ export namespace draco::math {
return static_cast<T>(std::pow(x, y));
}

// Trigonometry (radians) and square root.
[[nodiscard]] inline f32 sin(f32 x) noexcept { return std::sin(x); }
[[nodiscard]] inline f32 cos(f32 x) noexcept { return std::cos(x); }
[[nodiscard]] inline f32 tan(f32 x) noexcept { return std::tan(x); }
[[nodiscard]] inline f32 acos(f32 x) noexcept { return std::acos(x); }
[[nodiscard]] inline f32 sqrt(f32 x) noexcept { return std::sqrt(x); }

// Approximate comparisons against an epsilon (defaults to CMP_EPSILON).
[[nodiscard]] constexpr bool nearlyEqual(f32 a, f32 b, f32 epsilon = CMP_EPSILON) noexcept {
return abs(a - b) <= epsilon;
}
[[nodiscard]] constexpr bool nearlyZero(f32 v, f32 epsilon = CMP_EPSILON) noexcept {
return abs(v) <= epsilon;
}

template <std::floating_point T>
constexpr T lerp(T from, T to, T weight) noexcept {
return std::lerp(from, to, weight);
Expand Down Expand Up @@ -202,4 +218,4 @@ export namespace draco::math {
T d = (control_1 - start) * T{3.} * omt2 + (control_2 - control_1) * T{6.} * omt * t + (end - control_2) * T{3.} * t2;
return d;
}
}
}
2 changes: 2 additions & 0 deletions Engine/cpp/Runtime/Core/Math/Math.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export import core.defs;
export import core.math.constants;
export import core.math.functions;
export import core.math.types;
export import core.math.matrix4;
export import core.math.quaternion;
export import core.math.transform;
Loading
Loading