From 5ed832536af420f6e6e62d844e3135c21f06bbe2 Mon Sep 17 00:00:00 2001 From: Panos Karabelas Date: Wed, 22 Jan 2025 07:53:16 +0000 Subject: [PATCH] [math] removed unnecessary functions (std provides them) --- editor/Widgets/Profiler.h | 10 ++-- editor/Widgets/Properties.cpp | 4 +- editor/Widgets/RenderOptions.cpp | 2 +- editor/Widgets/TextureViewer.cpp | 4 +- runtime/Core/GeometryProcessing.h | 10 ++-- runtime/Core/Timer.cpp | 2 +- runtime/Core/pch.h | 1 + runtime/Game/Car.cpp | 44 ++++++++-------- runtime/Input/InputGamepad.cpp | 4 +- runtime/Math/BoundingBox.cpp | 42 ++++++++-------- runtime/Math/Frustum.cpp | 2 +- runtime/Math/Helper.h | 30 +---------- runtime/Math/Matrix.h | 61 +++++++++++------------ runtime/Math/Quaternion.h | 34 ++++++------- runtime/Math/Ray.cpp | 18 +++---- runtime/Math/Rectangle.h | 8 +-- runtime/Math/Vector2.h | 6 +-- runtime/Math/Vector3.h | 20 ++++---- runtime/Math/Vector4.h | 14 ++---- runtime/Profiling/Profiler.cpp | 12 ++--- runtime/Profiling/TimeBlock.cpp | 2 +- runtime/RHI/Vulkan/Vulkan_CommandList.cpp | 4 +- runtime/RHI/Vulkan/Vulkan_Device.cpp | 2 +- runtime/RHI/Vulkan/Vulkan_Pipeline.cpp | 2 +- runtime/RHI/Vulkan/Vulkan_SwapChain.cpp | 4 +- runtime/Rendering/Color.cpp | 14 +++--- runtime/Rendering/Font/Font.cpp | 6 +-- runtime/Rendering/Renderer.cpp | 6 +-- runtime/Rendering/Renderer_Passes.cpp | 8 +-- runtime/Rendering/Renderer_Primitives.cpp | 22 ++++---- runtime/Resource/Import/FontImporter.cpp | 12 +++-- runtime/World/Components/AudioSource.cpp | 8 +-- runtime/World/Components/Camera.cpp | 26 +++++----- runtime/World/Components/Camera.h | 2 +- runtime/World/Components/Constraint.cpp | 8 +-- runtime/World/Components/Light.cpp | 4 +- runtime/World/Components/Light.h | 2 +- runtime/World/Components/PhysicsBody.cpp | 26 +++++----- runtime/World/Components/Terrain.cpp | 6 +-- runtime/World/Entity.cpp | 6 +-- 40 files changed, 232 insertions(+), 266 deletions(-) diff --git a/editor/Widgets/Profiler.h b/editor/Widgets/Profiler.h index 6ddc169fd..b82c18b72 100644 --- a/editor/Widgets/Profiler.h +++ b/editor/Widgets/Profiler.h @@ -21,11 +21,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #pragma once -//= INCLUDES =========== +//= INCLUDES ====== #include "Widget.h" -#include "Math/Helper.h" #include -//====================== +#include +//================= struct Timings { @@ -33,8 +33,8 @@ struct Timings void AddSample(const float sample) { - m_min = spartan::math::helper::Min(m_min, sample); - m_max = spartan::math::helper::Max(m_max, sample); + m_min = std::min(m_min, sample); + m_max = std::max(m_max, sample); m_sum += sample; m_sample_count++; m_avg = float(m_sum / static_cast(m_sample_count)); diff --git a/editor/Widgets/Properties.cpp b/editor/Widgets/Properties.cpp index b8659f781..7c39a0cbe 100644 --- a/editor/Widgets/Properties.cpp +++ b/editor/Widgets/Properties.cpp @@ -252,7 +252,7 @@ void Properties::ShowLight(shared_ptr light) const static vector types = { "Directional", "Point", "Spot" }; float intensity = light->GetIntensityLumens(); float temperature_kelvin = light->GetTemperature(); - float angle = light->GetAngle() * math::helper::RAD_TO_DEG * 2.0f; + float angle = light->GetAngle() * math::RAD_TO_DEG * 2.0f; bool shadows = light->GetFlag(spartan::LightFlags::Shadows); bool shadows_transparent = light->GetFlag(spartan::LightFlags::ShadowsTransparent); bool shadows_screen_space = light->GetFlag(spartan::LightFlags::ShadowsScreenSpace); @@ -362,7 +362,7 @@ void Properties::ShowLight(shared_ptr light) const //= MAP =================================================================================================================== if (intensity != light->GetIntensityLumens()) light->SetIntensity(intensity); - if (angle != light->GetAngle() * math::helper::RAD_TO_DEG * 0.5f) light->SetAngle(angle * math::helper::DEG_TO_RAD * 0.5f); + if (angle != light->GetAngle() * math::RAD_TO_DEG * 0.5f) light->SetAngle(angle * math::DEG_TO_RAD * 0.5f); if (range != light->GetRange()) light->SetRange(range); if (m_colorPicker_light->GetColor() != light->GetColor()) light->SetColor(m_colorPicker_light->GetColor()); if (temperature_kelvin != light->GetTemperature()) light->SetTemperature(temperature_kelvin); diff --git a/editor/Widgets/RenderOptions.cpp b/editor/Widgets/RenderOptions.cpp index fcfed483a..f07cb0f17 100644 --- a/editor/Widgets/RenderOptions.cpp +++ b/editor/Widgets/RenderOptions.cpp @@ -133,7 +133,7 @@ namespace ImGui::InputFloat("", &value, step, 0.0f, format); ImGui::PopItemWidth(); ImGui::PopID(); - value = math::helper::Clamp(value, min, max); + value = math::Clamp(value, min, max); // Only update if changed if (Renderer::GetOption(render_option) != value) diff --git a/editor/Widgets/TextureViewer.cpp b/editor/Widgets/TextureViewer.cpp index b45d48444..f2fc57a3e 100644 --- a/editor/Widgets/TextureViewer.cpp +++ b/editor/Widgets/TextureViewer.cpp @@ -169,7 +169,7 @@ void TextureViewer::OnTickVisible() ImGui::PushItemWidth(85 * spartan::Window::GetDpiScale()); ImGui::InputInt("Mip", &mip_level); ImGui::PopItemWidth(); - mip_level = math::helper::Clamp(mip_level, 0, static_cast(texture_current->GetMipCount()) - 1); + mip_level = math::Clamp(mip_level, 0, static_cast(texture_current->GetMipCount()) - 1); } // array level control @@ -179,7 +179,7 @@ void TextureViewer::OnTickVisible() ImGui::PushItemWidth(85 * spartan::Window::GetDpiScale()); ImGui::InputInt("Array", &array_level); ImGui::PopItemWidth(); - array_level = math::helper::Clamp(array_level, 0, static_cast(texture_current->GetDepth()) - 1); + array_level = math::Clamp(array_level, 0, static_cast(texture_current->GetDepth()) - 1); } ImGui::BeginGroup(); diff --git a/runtime/Core/GeometryProcessing.h b/runtime/Core/GeometryProcessing.h index 3d057ab40..84830f8ef 100644 --- a/runtime/Core/GeometryProcessing.h +++ b/runtime/Core/GeometryProcessing.h @@ -164,8 +164,8 @@ namespace spartan::geometry_processing Vector3 tangent = Vector3(1, 0, 0); vertices->emplace_back(Vector3(0, radius, 0), Vector2::Zero, normal, tangent); - const float phiStep = helper::PI / stacks; - const float thetaStep = 2.0f * helper::PI / slices; + const float phiStep = PI / stacks; + const float thetaStep = 2.0f * PI / slices; for (int i = 1; i <= stacks - 1; i++) { @@ -181,7 +181,7 @@ namespace spartan::geometry_processing Vector3 t = Vector3(-radius * sin(phi) * sin(theta), 0, radius * sin(phi) * cos(theta)).Normalized(); Vector3 n = p.Normalized(); - Vector2 uv = Vector2(theta / (helper::PI * 2), phi / helper::PI); + Vector2 uv = Vector2(theta / (PI * 2), phi / PI); vertices->emplace_back(p, uv, n, t); } } @@ -233,7 +233,7 @@ namespace spartan::geometry_processing { const float y = -0.5f * height + i * stackHeight; const float r = radiusBottom + i * radiusStep; - const float dTheta = 2.0f * helper::PI / slices; + const float dTheta = 2.0f * PI / slices; for (int j = 0; j <= slices; j++) { const float c = cos(j * dTheta); @@ -270,7 +270,7 @@ namespace spartan::geometry_processing // Build top cap int baseIndex = (int)vertices->size(); float y = 0.5f * height; - const float dTheta = 2.0f * helper::PI / slices; + const float dTheta = 2.0f * PI / slices; Vector3 normal; Vector3 tangent; diff --git a/runtime/Core/Timer.cpp b/runtime/Core/Timer.cpp index f16775c2a..82e56c538 100644 --- a/runtime/Core/Timer.cpp +++ b/runtime/Core/Timer.cpp @@ -88,7 +88,7 @@ namespace spartan } // clamp to a minimum of 10 FPS to avoid unresponsiveness - fps_in = math::helper::Clamp(fps_in, fps_min, fps_max); + fps_in = math::Clamp(fps_in, fps_min, fps_max); if (fps_limit == fps_in) return; diff --git a/runtime/Core/pch.h b/runtime/Core/pch.h index 105ddff0e..3f048e0be 100644 --- a/runtime/Core/pch.h +++ b/runtime/Core/pch.h @@ -54,6 +54,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include //=========================== //= RUNTIME ========================= diff --git a/runtime/Game/Car.cpp b/runtime/Game/Car.cpp index 2d30a1a8c..8d99ae84f 100644 --- a/runtime/Game/Car.cpp +++ b/runtime/Game/Car.cpp @@ -96,7 +96,7 @@ namespace spartan constexpr float brake_ramp_speed = 5000.0f; // rate at which brake force increases (human pressing the brake and vehicle applying brake pads) // steering - constexpr float steering_angle_max = 40.0f * math::helper::DEG_TO_RAD; // the maximum steering angle of the front wheels + constexpr float steering_angle_max = 40.0f * math::DEG_TO_RAD; // the maximum steering angle of the front wheels constexpr float steering_return_speed = 5.0f; // the speed at which the steering wheel returns to the center // aerodynamics @@ -141,12 +141,12 @@ namespace spartan oss << fixed << setprecision(2); oss << "Wheel: " << wheel_name << "\n"; - oss << "Steering: " << static_cast(wheel_info.m_steering) * math::helper::RAD_TO_DEG << " deg\n"; + oss << "Steering: " << static_cast(wheel_info.m_steering) * math::RAD_TO_DEG << " deg\n"; oss << "Angular velocity: " << static_cast(wheel_info.m_deltaRotation * 0.5f) / static_cast(Physics::GetTimeStepInternalSec()) << " rad/s\n"; oss << "Torque: " << wheel_info.m_engineForce << " N\n"; oss << "Suspension length: " << wheel_info.m_raycastInfo.m_suspensionLength << " m\n"; oss << "Slip ratio: " << parameters.pacejka_slip_ratio[wheel_index] << " ( Fz: " << parameters.pacejka_fz[wheel_index] << " N ) \n"; - oss << "Slip angle: " << parameters.pacejka_slip_angle[wheel_index] * math::helper::RAD_TO_DEG << " ( Fx: " << parameters.pacejka_fx[wheel_index] << " N ) \n"; + oss << "Slip angle: " << parameters.pacejka_slip_angle[wheel_index] * math::RAD_TO_DEG << " ( Fx: " << parameters.pacejka_fx[wheel_index] << " N ) \n"; return oss.str(); } @@ -166,7 +166,7 @@ namespace spartan oss.clear(); oss << fixed << setprecision(2); - oss << "Speed: " << math::helper::Abs(speed) << " Km/h\n"; // meters per second + oss << "Speed: " << abs(speed) << " Km/h\n"; // meters per second oss << "Torque: " << parameters.engine_torque << " N·m \n"; // Newton meters oss << "RPM: " << parameters.engine_rpm << " rpm\n"; // revolutions per minute, not an SI unit, but commonly used oss << "Gear: " << parameters.gear << "\n"; // gear has no unit @@ -221,13 +221,13 @@ namespace spartan else // reverse { // in reverse, both velocities are negative, so we take their absolute values - numerator = math::helper::Abs(velocity_vehicle) - math::helper::Abs(velocity_wheel); + numerator = abs(velocity_vehicle) - abs(velocity_wheel); } - float denominator = math::helper::Max(math::helper::Abs(velocity_wheel), math::helper::SMALL_FLOAT); + float denominator = max(abs(velocity_wheel), math::SMALL_FLOAT); float slip_ratio = numerator / denominator; - return math::helper::Clamp(slip_ratio, -1.0f, 1.0f); + return math::Clamp(slip_ratio, -1.0f, 1.0f); } float compute_slip_angle(const btVector3& wheel_forward, const btVector3& wheel_side, const btVector3& vehicle_velocity) @@ -241,9 +241,9 @@ namespace spartan if (vehicle_velocity.length() < 0.05f) return 0.0f; - float v_z = math::helper::Abs(vehicle_velocity.dot(wheel_forward)); - float v_x = math::helper::Abs(vehicle_velocity.dot(wheel_side)); - float slip_angle = atan2(v_x, v_z + math::helper::SMALL_FLOAT); + float v_z = abs(vehicle_velocity.dot(wheel_forward)); + float v_x = abs(vehicle_velocity.dot(wheel_side)); + float slip_angle = atan2(v_x, v_z + math::SMALL_FLOAT); return slip_angle; } @@ -262,7 +262,7 @@ namespace spartan } else // slip angle { - slip *= math::helper::RAD_TO_DEG; // to degrees + slip *= math::RAD_TO_DEG; // to degrees } // coefficients from the pacejka '94 model @@ -285,10 +285,10 @@ namespace spartan // compute the parameters for the Pacejka ’94 formula float Fz = normal_load; float C = b0; - float D = Fz * (b1 * Fz + b2) + math::helper::SMALL_FLOAT; + float D = Fz * (b1 * Fz + b2) + math::SMALL_FLOAT; float BCD = (b3 * Fz * Fz + b4 * Fz) * exp(-b5 * Fz); float B = BCD / (C * D); - float E = (b6 * Fz * Fz + b7 * Fz + b8) * (1 - b13 * math::helper::Sign(slip + (b9 * Fz + b10))); + float E = (b6 * Fz * Fz + b7 * Fz + b8) * (1 - b13 * math::Sign(slip + (b9 * Fz + b10))); float H = b9 * Fz + b10; float V = b11 * Fz + b12; float Bx1 = B * (slip + H); @@ -496,10 +496,10 @@ namespace spartan { btWheelInfo* wheel_info = ¶meters.vehicle->getWheelInfo(0); float wheel_angular_velocity = wheel_info->m_deltaRotation / static_cast(Timer::GetDeltaTimeSec()); - float wheel_rpm = (wheel_angular_velocity * 60.0f) / (2.0f * math::helper::PI); + float wheel_rpm = (wheel_angular_velocity * 60.0f) / (2.0f * math::PI); float target_rpm = tuning::engine_idle_rpm + wheel_rpm * parameters.gear_ratio * tuning::gearbox_final_drive; - target_rpm *= math::helper::Abs(parameters.throttle); - target_rpm = math::helper::Clamp(target_rpm, tuning::engine_idle_rpm, tuning::engine_max_rpm); + target_rpm *= abs(parameters.throttle); + target_rpm = math::Clamp(target_rpm, tuning::engine_idle_rpm, tuning::engine_max_rpm); const float rev_up_down_speed = 0.1f; parameters.engine_rpm = lerp(parameters.engine_rpm, target_rpm, rev_up_down_speed); @@ -669,7 +669,7 @@ namespace spartan // compute engine torque and/or breaking force { // determine when to stop breaking - if (math::helper::Abs(GetSpeedMetersPerSecond()) < 0.1f) + if (abs(GetSpeedMetersPerSecond()) < 0.1f) { m_parameters.break_until_opposite_torque = false; } @@ -719,7 +719,7 @@ namespace spartan } // lerp to new steering angle - real life vehicles don't snap their wheels to the target angle - m_parameters.steering_angle = math::helper::Lerp(m_parameters.steering_angle, steering_angle_target, tuning::steering_return_speed * delta_time_sec); + m_parameters.steering_angle = math::Lerp(m_parameters.steering_angle, steering_angle_target, tuning::steering_return_speed * delta_time_sec); // set the steering angle m_parameters.vehicle->setSteeringValue(m_parameters.steering_angle, tuning::wheel_fl); @@ -780,11 +780,11 @@ namespace spartan if (breaking > 0.0f) { - m_parameters.break_force = math::helper::Min(m_parameters.break_force + tuning::brake_ramp_speed * delta_time_sec * breaking, tuning::brake_force_max); + m_parameters.break_force = min(m_parameters.break_force + tuning::brake_ramp_speed * delta_time_sec * breaking, tuning::brake_force_max); } else { - m_parameters.break_force = math::helper::Max(m_parameters.break_force - tuning::brake_ramp_speed * delta_time_sec, 0.0f); + m_parameters.break_force = max(m_parameters.break_force - tuning::brake_ramp_speed * delta_time_sec, 0.0f); } float bullet_brake_force = m_parameters.break_force * 0.03f; @@ -806,7 +806,7 @@ namespace spartan // steering wheel if (m_parameters.transform_steering_wheel) { - m_parameters.transform_steering_wheel->SetRotationLocal(Quaternion::FromEulerAngles(0.0f, 0.0f, -m_parameters.steering_angle * math::helper::RAD_TO_DEG)); + m_parameters.transform_steering_wheel->SetRotationLocal(Quaternion::FromEulerAngles(0.0f, 0.0f, -m_parameters.steering_angle * math::RAD_TO_DEG)); } // wheels @@ -826,7 +826,7 @@ namespace spartan float x, y, z; transform_bt.getRotation().getEulerZYX(x, y, z); float steering_angle_rad = m_parameters.vehicle->getSteeringValue(wheel_index); - Quaternion rotation = Quaternion::FromEulerAngles(z * math::helper::RAD_TO_DEG, steering_angle_rad * math::helper::RAD_TO_DEG, 0.0f); + Quaternion rotation = Quaternion::FromEulerAngles(z * math::RAD_TO_DEG, steering_angle_rad * math::RAD_TO_DEG, 0.0f); transform->SetRotationLocal(rotation); } } diff --git a/runtime/Input/InputGamepad.cpp b/runtime/Input/InputGamepad.cpp index 298f31197..bec446f14 100644 --- a/runtime/Input/InputGamepad.cpp +++ b/runtime/Input/InputGamepad.cpp @@ -104,8 +104,8 @@ namespace spartan if (!gamepad.is_connected) return false; - Uint16 low_frequency_rumble = static_cast(helper::Clamp(left_motor_speed, 0.0f, 1.0f) * 65535); // convert [0, 1] to [0, 65535] - Uint16 high_frequency_rumble = static_cast(helper::Clamp(right_motor_speed, 0.0f, 1.0f) * 65535); // convert [0, 1] to [0, 65535] + Uint16 low_frequency_rumble = static_cast(Clamp(left_motor_speed, 0.0f, 1.0f) * 65535); // convert [0, 1] to [0, 65535] + Uint16 high_frequency_rumble = static_cast(Clamp(right_motor_speed, 0.0f, 1.0f) * 65535); // convert [0, 1] to [0, 65535] Uint32 duration_ms = 0xFFFFFFFF; if (SDL_GameControllerRumble(static_cast(gamepad.sdl_pointer), low_frequency_rumble, high_frequency_rumble, duration_ms) == -1) diff --git a/runtime/Math/BoundingBox.cpp b/runtime/Math/BoundingBox.cpp index 3d847de63..8457303ea 100644 --- a/runtime/Math/BoundingBox.cpp +++ b/runtime/Math/BoundingBox.cpp @@ -47,13 +47,13 @@ namespace spartan::math for (uint32_t i = 0; i < point_count; i++) { - m_max.x = helper::Max(m_max.x, points[i].x); - m_max.y = helper::Max(m_max.y, points[i].y); - m_max.z = helper::Max(m_max.z, points[i].z); + m_max.x = std::max(m_max.x, points[i].x); + m_max.y = std::max(m_max.y, points[i].y); + m_max.z = std::max(m_max.z, points[i].z); - m_min.x = helper::Min(m_min.x, points[i].x); - m_min.y = helper::Min(m_min.y, points[i].y); - m_min.z = helper::Min(m_min.z, points[i].z); + m_min.x = std::min(m_min.x, points[i].x); + m_min.y = std::min(m_min.y, points[i].y); + m_min.z = std::min(m_min.z, points[i].z); } } @@ -64,13 +64,13 @@ namespace spartan::math for (uint32_t i = 0; i < vertex_count; i++) { - m_max.x = helper::Max(m_max.x, vertices[i].pos[0]); - m_max.y = helper::Max(m_max.y, vertices[i].pos[1]); - m_max.z = helper::Max(m_max.z, vertices[i].pos[2]); + m_max.x = std::max(m_max.x, vertices[i].pos[0]); + m_max.y = std::max(m_max.y, vertices[i].pos[1]); + m_max.z = std::max(m_max.z, vertices[i].pos[2]); - m_min.x = helper::Min(m_min.x, vertices[i].pos[0]); - m_min.y = helper::Min(m_min.y, vertices[i].pos[1]); - m_min.z = helper::Min(m_min.z, vertices[i].pos[2]); + m_min.x = std::min(m_min.x, vertices[i].pos[0]); + m_min.y = std::min(m_min.y, vertices[i].pos[1]); + m_min.z = std::min(m_min.z, vertices[i].pos[2]); } } @@ -115,9 +115,9 @@ namespace spartan::math const Vector3 extent_old = GetExtents(); const Vector3 extend_new = Vector3 ( - helper::Abs(transform.m00) * extent_old.x + helper::Abs(transform.m10) * extent_old.y + helper::Abs(transform.m20) * extent_old.z, - helper::Abs(transform.m01) * extent_old.x + helper::Abs(transform.m11) * extent_old.y + helper::Abs(transform.m21) * extent_old.z, - helper::Abs(transform.m02) * extent_old.x + helper::Abs(transform.m12) * extent_old.y + helper::Abs(transform.m22) * extent_old.z + abs(transform.m00) * extent_old.x + abs(transform.m10) * extent_old.y + abs(transform.m20) * extent_old.z, + abs(transform.m01) * extent_old.x + abs(transform.m11) * extent_old.y + abs(transform.m21) * extent_old.z, + abs(transform.m02) * extent_old.x + abs(transform.m12) * extent_old.y + abs(transform.m22) * extent_old.z ); return BoundingBox(center_new - extend_new, center_new + extend_new); @@ -125,13 +125,13 @@ namespace spartan::math void BoundingBox::Merge(const BoundingBox& box) { - m_min.x = helper::Min(m_min.x, box.m_min.x); - m_min.y = helper::Min(m_min.y, box.m_min.y); - m_min.z = helper::Min(m_min.z, box.m_min.z); + m_min.x = std::min(m_min.x, box.m_min.x); + m_min.y = std::min(m_min.y, box.m_min.y); + m_min.z = std::min(m_min.z, box.m_min.z); - m_max.x = helper::Max(m_max.x, box.m_max.x); - m_max.y = helper::Max(m_max.y, box.m_max.y); - m_max.z = helper::Max(m_max.z, box.m_max.z); + m_max.x = std::max(m_max.x, box.m_max.x); + m_max.y = std::max(m_max.y, box.m_max.y); + m_max.z = std::max(m_max.z, box.m_max.z); } bool BoundingBox::Contains(const Vector3& point) const diff --git a/runtime/Math/Frustum.cpp b/runtime/Math/Frustum.cpp index 5283621c1..84b7835f5 100644 --- a/runtime/Math/Frustum.cpp +++ b/runtime/Math/Frustum.cpp @@ -154,7 +154,7 @@ namespace spartan::math return Intersection::Outside; // else if the distance is between +- radius, then we intersect - if (static_cast(helper::Abs(distance)) < radius) + if (static_cast(abs(distance)) < radius) return Intersection::Intersects; } diff --git a/runtime/Math/Helper.h b/runtime/Math/Helper.h index 6d5aacd3c..7dbbddfd2 100644 --- a/runtime/Math/Helper.h +++ b/runtime/Math/Helper.h @@ -35,10 +35,7 @@ namespace spartan::math Inside, Intersects }; -} -namespace spartan::math::helper -{ constexpr float SMALL_FLOAT = std::numeric_limits::min(); // the smallest value that can be represented while maintaining the standard format of floating-point numbers constexpr float EPSILON = std::numeric_limits::epsilon(); // the smallest change detectable in calculations around the number 1.0 constexpr float INFINITY_ = std::numeric_limits::infinity(); @@ -66,28 +63,9 @@ namespace spartan::math::helper template constexpr T Lerp(T lhs, T rhs, U t) { return lhs * (static_cast(1) - t) + rhs * t; } - // Returns the absolute value - template - constexpr T Abs(T value) { return value >= static_cast(0) ? value : -value; } - // Check for equality but allow for a small error template - constexpr bool Equals(T lhs, T rhs, T error = std::numeric_limits::epsilon()) { return lhs + error >= rhs && lhs - error <= rhs; } - - template - constexpr T Max(T a, T b) { return a > b ? a : b; } - - template - constexpr T Max3(T a, T b, T c) { return Max(a, Max(b, c)); } - - template - constexpr T Min(T a, T b) { return a < b ? a : b; } - - template - constexpr T Min3(T a, T b, T c) { return Min(a, Min(b, c)); } - - template - constexpr T Sqrt(T x) { return sqrt(x); } + constexpr bool EqualsWithError(T lhs, T rhs, T error = std::numeric_limits::epsilon()) { return lhs + error >= rhs && lhs - error <= rhs; } template constexpr T Floor(T x) { return floor(x); } @@ -101,12 +79,6 @@ namespace spartan::math::helper template constexpr T Tan(T x) { return tan(x); } - template - constexpr T Cos(T x) { return cos(x); } - - template - constexpr T Sin(T x) { return sin(x); } - template constexpr int Sign(T x) { return (static_cast(0) < x) - (x < static_cast(0)); } diff --git a/runtime/Math/Matrix.h b/runtime/Math/Matrix.h index b43f480ae..47baa426e 100644 --- a/runtime/Math/Matrix.h +++ b/runtime/Math/Matrix.h @@ -168,28 +168,28 @@ namespace spartan::math static Quaternion RotationMatrixToQuaternion(const Matrix& mRot) { Quaternion quaternion; - float sqrt; + float sqrt_; float half; const float scale = mRot.m00 + mRot.m11 + mRot.m22; if (scale > 0.0f) { - sqrt = helper::Sqrt(scale + 1.0f); - quaternion.w = sqrt * 0.5f; - sqrt = 0.5f / sqrt; + sqrt_ = sqrt(scale + 1.0f); + quaternion.w = sqrt_ * 0.5f; + sqrt_ = 0.5f / sqrt_; - quaternion.x = (mRot.m12 - mRot.m21) * sqrt; - quaternion.y = (mRot.m20 - mRot.m02) * sqrt; - quaternion.z = (mRot.m01 - mRot.m10) * sqrt; + quaternion.x = (mRot.m12 - mRot.m21) * sqrt_; + quaternion.y = (mRot.m20 - mRot.m02) * sqrt_; + quaternion.z = (mRot.m01 - mRot.m10) * sqrt_; return quaternion; } if ((mRot.m00 >= mRot.m11) && (mRot.m00 >= mRot.m22)) { - sqrt = helper::Sqrt(1.0f + mRot.m00 - mRot.m11 - mRot.m22); - half = 0.5f / sqrt; + sqrt_ = sqrt(1.0f + mRot.m00 - mRot.m11 - mRot.m22); + half = 0.5f / sqrt_; - quaternion.x = 0.5f * sqrt; + quaternion.x = 0.5f * sqrt_; quaternion.y = (mRot.m01 + mRot.m10) * half; quaternion.z = (mRot.m02 + mRot.m20) * half; quaternion.w = (mRot.m12 - mRot.m21) * half; @@ -198,22 +198,22 @@ namespace spartan::math } if (mRot.m11 > mRot.m22) { - sqrt = helper::Sqrt(1.0f + mRot.m11 - mRot.m00 - mRot.m22); - half = 0.5f / sqrt; + sqrt_ = sqrt(1.0f + mRot.m11 - mRot.m00 - mRot.m22); + half = 0.5f / sqrt_; quaternion.x = (mRot.m10 + mRot.m01) * half; - quaternion.y = 0.5f * sqrt; + quaternion.y = 0.5f * sqrt_; quaternion.z = (mRot.m21 + mRot.m12) * half; quaternion.w = (mRot.m20 - mRot.m02) * half; return quaternion; } - sqrt = helper::Sqrt(1.0f + mRot.m22 - mRot.m00 - mRot.m11); - half = 0.5f / sqrt; + sqrt_ = sqrt(1.0f + mRot.m22 - mRot.m00 - mRot.m11); + half = 0.5f / sqrt_; quaternion.x = (mRot.m20 + mRot.m02) * half; quaternion.y = (mRot.m21 + mRot.m12) * half; - quaternion.z = 0.5f * sqrt; + quaternion.z = 0.5f * sqrt_; quaternion.w = (mRot.m01 - mRot.m10) * half; return quaternion; @@ -230,9 +230,9 @@ namespace spartan::math __m128 row2 = _mm_setr_ps(m20, m21, m22, 0.0f); // Calculate signs (using scalar math as it's only done once per row) - float xs = (helper::Sign(m00 * m01 * m02 * m03) < 0) ? -1.0f : 1.0f; - float ys = (helper::Sign(m10 * m11 * m12 * m13) < 0) ? -1.0f : 1.0f; - float zs = (helper::Sign(m20 * m21 * m22 * m23) < 0) ? -1.0f : 1.0f; + float xs = (Sign(m00 * m01 * m02 * m03) < 0) ? -1.0f : 1.0f; + float ys = (Sign(m10 * m11 * m12 * m13) < 0) ? -1.0f : 1.0f; + float zs = (Sign(m20 * m21 * m22 * m23) < 0) ? -1.0f : 1.0f; // Square each component __m128 square0 = _mm_mul_ps(row0, row0); @@ -251,18 +251,18 @@ namespace spartan::math // Extract results and apply signs return Vector3( - xs * helper::Sqrt(_mm_cvtss_f32(square0)), - ys * helper::Sqrt(_mm_cvtss_f32(square1)), - zs * helper::Sqrt(_mm_cvtss_f32(square2)) + xs * sqrt(_mm_cvtss_f32(square0)), + ys * sqrt(_mm_cvtss_f32(square1)), + zs * sqrt(_mm_cvtss_f32(square2)) ); #else - const int xs = (helper::Sign(m00 * m01 * m02 * m03) < 0) ? -1 : 1; - const int ys = (helper::Sign(m10 * m11 * m12 * m13) < 0) ? -1 : 1; - const int zs = (helper::Sign(m20 * m21 * m22 * m23) < 0) ? -1 : 1; + const int xs = (Sign(m00 * m01 * m02 * m03) < 0) ? -1 : 1; + const int ys = (Sign(m10 * m11 * m12 * m13) < 0) ? -1 : 1; + const int zs = (Sign(m20 * m21 * m22 * m23) < 0) ? -1 : 1; return Vector3( - static_cast(xs) * helper::Sqrt(m00 * m00 + m01 * m01 + m02 * m02), - static_cast(ys) * helper::Sqrt(m10 * m10 + m11 * m11 + m12 * m12), - static_cast(zs) * helper::Sqrt(m20 * m20 + m21 * m21 + m22 * m22) + static_cast(xs) * Sqrt(m00 * m00 + m01 * m01 + m02 * m02), + static_cast(ys) * Sqrt(m10 * m10 + m11 * m11 + m12 * m12), + static_cast(zs) * Sqrt(m20 * m20 + m21 * m21 + m22 * m22) ); #endif } @@ -315,7 +315,7 @@ namespace spartan::math static Matrix CreatePerspectiveFieldOfViewLH(float fov_y_radians, float aspect_ratio, float near_plane, float far_plane) { - const float tan_half_fovy = helper::Tan(fov_y_radians / 2); + const float tan_half_fovy = Tan(fov_y_radians / 2); const float f = 1.0f / tan_half_fovy; const float range_inv = 1.0f / (far_plane - near_plane); @@ -481,7 +481,6 @@ namespace spartan::math bool operator!=(const Matrix& rhs) const { return !(*this == rhs); } - // Test for equality with another matrix with epsilon. bool Equals(const Matrix& rhs) { const float* data_left = Data(); @@ -489,7 +488,7 @@ namespace spartan::math for (unsigned i = 0; i < 16; ++i) { - if (!helper::Equals(data_left[i], data_right[i])) + if (!EqualsWithError(data_left[i], data_right[i])) return false; } diff --git a/runtime/Math/Quaternion.h b/runtime/Math/Quaternion.h index fc5887c06..673ea0677 100644 --- a/runtime/Math/Quaternion.h +++ b/runtime/Math/Quaternion.h @@ -120,7 +120,7 @@ namespace spartan::math const Vector3 normEnd = end.Normalized(); const float d = normStart.Dot(normEnd); - if (d > -1.0f + helper::EPSILON) + if (d > -1.0f + EPSILON) { const Vector3 c = normStart.Cross(normEnd); const float s = sqrtf((1.0f + d) * 2.0f); @@ -135,12 +135,12 @@ namespace spartan::math else { Vector3 axis = Vector3::Right.Cross(normStart); - if (axis.Length() < helper::EPSILON) + if (axis.Length() < EPSILON) { axis = Vector3::Up.Cross(normStart); } - return FromAngleAxis(180.0f * helper::DEG_TO_RAD, axis); + return FromAngleAxis(180.0f * DEG_TO_RAD, axis); } } @@ -150,7 +150,7 @@ namespace spartan::math const Vector3 forward = direction.Normalized(); Vector3 v = forward.Cross(up_direction); - if (v.LengthSquared() >= helper::SMALL_FLOAT) + if (v.LengthSquared() >= SMALL_FLOAT) { v.Normalize(); const Vector3 up = v.Cross(forward); @@ -213,9 +213,9 @@ namespace spartan::math void Normalize() { const auto length_squared = LengthSquared(); - if (!helper::Equals(length_squared, 1.0f) && length_squared > 0.0f) + if (!EqualsWithError(length_squared, 1.0f) && length_squared > 0.0f) { - const auto length_inverted = 1.0f / helper::Sqrt(length_squared); + const auto length_inverted = 1.0f / sqrt(length_squared); x *= length_inverted; y *= length_inverted; z *= length_inverted; @@ -226,9 +226,9 @@ namespace spartan::math Quaternion Normalized() const { const auto length_squared = LengthSquared(); - if (!helper::Equals(length_squared, 1.0f) && length_squared > 0.0f) + if (!EqualsWithError(length_squared, 1.0f) && length_squared > 0.0f) { - const auto length_inverted = 1.0f / helper::Sqrt(length_squared); + const auto length_inverted = 1.0f / sqrt(length_squared); return (*this) * length_inverted; } else @@ -244,7 +244,7 @@ namespace spartan::math { return Conjugate(); } - else if (length_squared >= helper::SMALL_FLOAT) + else if (length_squared >= SMALL_FLOAT) { return Conjugate() * (1.0f / length_squared); } @@ -266,7 +266,7 @@ namespace spartan::math ( -90.0f, 0.0f, - -atan2f(2.0f * (x * z - w * y), 1.0f - 2.0f * (y * y + z * z)) * helper::RAD_TO_DEG + -atan2f(2.0f * (x * z - w * y), 1.0f - 2.0f * (y * y + z * z)) * RAD_TO_DEG ); } @@ -276,21 +276,21 @@ namespace spartan::math ( 90.0f, 0.0f, - atan2f(2.0f * (x * z - w * y), 1.0f - 2.0f * (y * y + z * z)) * helper::RAD_TO_DEG + atan2f(2.0f * (x * z - w * y), 1.0f - 2.0f * (y * y + z * z)) * RAD_TO_DEG ); } return Vector3 ( - asinf(check) * helper::RAD_TO_DEG, - atan2f(2.0f * (x * z + w * y), 1.0f - 2.0f * (x * x + y * y)) * helper::RAD_TO_DEG, - atan2f(2.0f * (x * y + w * z), 1.0f - 2.0f * (x * x + z * z)) * helper::RAD_TO_DEG + asinf(check) * RAD_TO_DEG, + atan2f(2.0f * (x * z + w * y), 1.0f - 2.0f * (x * x + y * y)) * RAD_TO_DEG, + atan2f(2.0f * (x * y + w * z), 1.0f - 2.0f * (x * x + z * z)) * RAD_TO_DEG ); } // euler angles to quaternion (input in degrees) - static Quaternion FromEulerAngles(const Vector3& rotation) { return FromYawPitchRoll(rotation.y * helper::DEG_TO_RAD, rotation.x * helper::DEG_TO_RAD, rotation.z * helper::DEG_TO_RAD); } - static Quaternion FromEulerAngles(float rotationX, float rotationY, float rotationZ) { return FromYawPitchRoll(rotationY * helper::DEG_TO_RAD, rotationX * helper::DEG_TO_RAD, rotationZ * helper::DEG_TO_RAD); } + static Quaternion FromEulerAngles(const Vector3& rotation) { return FromYawPitchRoll(rotation.y * DEG_TO_RAD, rotation.x * DEG_TO_RAD, rotation.z * DEG_TO_RAD); } + static Quaternion FromEulerAngles(float rotationX, float rotationY, float rotationZ) { return FromYawPitchRoll(rotationY * DEG_TO_RAD, rotationX * DEG_TO_RAD, rotationZ * DEG_TO_RAD); } // Returns yaw in degrees float Yaw() const { return ToEulerAngles().y; } @@ -335,7 +335,7 @@ namespace spartan::math // Equality bool operator==(const Quaternion& rhs) const { return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w; } bool operator!=(const Quaternion& rhs) const { return !(*this == rhs); } - bool Equals(const Quaternion& rhs) const { return helper::Equals(x, rhs.x) && helper::Equals(y, rhs.y) && helper::Equals(z, rhs.z) && helper::Equals(w, rhs.w); } + bool Equals(const Quaternion& rhs) const { return EqualsWithError(x, rhs.x) && EqualsWithError(y, rhs.y) && EqualsWithError(z, rhs.z) && EqualsWithError(w, rhs.w); } std::string ToString() const; float x, y, z, w; diff --git a/runtime/Math/Ray.cpp b/runtime/Math/Ray.cpp index df0f24310..51d9cc897 100644 --- a/runtime/Math/Ray.cpp +++ b/runtime/Math/Ray.cpp @@ -39,13 +39,13 @@ namespace spartan::math { // If undefined, no hit (infinite distance) if (box == BoundingBox::Undefined) - return helper::INFINITY_; + return INFINITY_; // check for ray origin being inside the box if (box.Intersects(m_origin) == Intersection::Inside) return 0.0f; - float distance = helper::INFINITY_; + float distance = INFINITY_; // Check for intersecting in the X-direction if (m_origin.x < box.GetMin().x && m_direction.x > 0.0f) @@ -131,7 +131,7 @@ namespace spartan::math float Ray::HitDistance(const Plane& plane, Vector3* intersection_point /*= nullptr*/) const { float d = plane.normal.Dot(m_direction); - if (helper::Abs(d) >= helper::SMALL_FLOAT) + if (abs(d) >= SMALL_FLOAT) { float t = -(plane.normal.Dot(m_origin) + plane.d) / d; if (t >= 0.0f) @@ -144,12 +144,12 @@ namespace spartan::math } else { - return helper::INFINITY_; + return INFINITY_; } } else { - return helper::INFINITY_; + return INFINITY_; } } @@ -165,7 +165,7 @@ namespace spartan::math Vector3 p(m_direction.Cross(edge2)); float det = edge1.Dot(p); - if (det >= helper::SMALL_FLOAT) + if (det >= SMALL_FLOAT) { // Calculate u & v parameters and test Vector3 t(m_origin - v1); @@ -193,7 +193,7 @@ namespace spartan::math } } - return helper::INFINITY_; + return INFINITY_; } float Ray::HitDistance(const Sphere& sphere) const @@ -213,7 +213,7 @@ namespace spartan::math // No solution if (d < 0.0f) - return helper::INFINITY_; + return INFINITY_; // Get the nearer solution float dSqrt = sqrtf(d); @@ -250,7 +250,7 @@ namespace spartan::math float d2121 = p21.Dot(p21); float d = d2121 * d4343 - d4321 * d4321; - if (helper::Abs(d) < helper::SMALL_FLOAT) + if (abs(d) < SMALL_FLOAT) return m_origin; float n = d1343 * d4321 - d1321 * d4343; diff --git a/runtime/Math/Rectangle.h b/runtime/Math/Rectangle.h index 1a9393af8..336ae5bd4 100644 --- a/runtime/Math/Rectangle.h +++ b/runtime/Math/Rectangle.h @@ -86,10 +86,10 @@ namespace spartan void Merge(const Vector2& point) { - left = math::helper::Min(left, point.x); - top = math::helper::Min(top, point.y); - right = math::helper::Max(right, point.x); - bottom = math::helper::Max(bottom, point.y); + left = std::min(left, point.x); + top = std::min(top, point.y); + right = std::max(right, point.x); + bottom = std::max(bottom, point.y); } bool Intersects(const Rectangle& other) const diff --git a/runtime/Math/Vector2.h b/runtime/Math/Vector2.h index c37c82baf..7fb3001a2 100644 --- a/runtime/Math/Vector2.h +++ b/runtime/Math/Vector2.h @@ -129,14 +129,10 @@ namespace spartan::math } //=================================================================================== - // Returns the length - [[nodiscard]] float Length() const { return helper::Sqrt(x * x + y * y); } - // Returns the squared length + [[nodiscard]] float Length() const { return sqrt(x * x + y * y); } [[nodiscard]] float LengthSquared() const { return x * x + y * y; } - // Returns the distance between to vectors static inline float Distance(const Vector2& a, const Vector2& b) { return (b - a).Length(); } - // Returns the squared distance between to vectors static inline float DistanceSquared(const Vector2& a, const Vector2& b) { return (b - a).LengthSquared(); } bool operator==(const Vector2& b) const diff --git a/runtime/Math/Vector3.h b/runtime/Math/Vector3.h index f155e65d4..c6a8de52a 100644 --- a/runtime/Math/Vector3.h +++ b/runtime/Math/Vector3.h @@ -68,7 +68,7 @@ namespace spartan::math void Normalize() { const auto length_squared = LengthSquared(); - if (!helper::Equals(length_squared, 1.0f) && length_squared > 0.0f) + if (!EqualsWithError(length_squared, 1.0f) && length_squared > 0.0f) { #ifdef __AVX2__ // load x, y, z into an AVX vector (set w component to 0) @@ -89,7 +89,7 @@ namespace spartan::math z = _mm_cvtss_f32(_mm_shuffle_ps(vec, vec, _MM_SHUFFLE(2, 2, 2, 2))); #else // fallback to scalar path - const auto length_inverted = 1.0f / helper::Sqrt(length_squared); + const auto length_inverted = 1.0f / Sqrt(length_squared); x *= length_inverted; y *= length_inverted; z *= length_inverted; @@ -109,12 +109,12 @@ namespace spartan::math bool IsNormalized() const { static const float THRESH_VECTOR_NORMALIZED = 0.01f; - return (helper::Abs(1.f - LengthSquared()) < THRESH_VECTOR_NORMALIZED); + return (abs(1.0f - LengthSquared()) < THRESH_VECTOR_NORMALIZED); } float Max() { - return helper::Max3(x, y, z); + return std::max(std::max(x, y), z); } [[nodiscard]] static float Dot(const Vector3& v1, const Vector3& v2) @@ -155,7 +155,7 @@ namespace spartan::math return _mm_cvtss_f32(length); #else // Fallback to scalar path - return helper::Sqrt(x * x + y * y + z * z); + return Sqrt(x * x + y * y + z * z); #endif } @@ -183,7 +183,7 @@ namespace spartan::math if (sqrmag > max_length * max_length) { - const float mag = helper::Sqrt(sqrmag); + const float mag = sqrt(sqrmag); // these intermediate variables force the intermediate result to be // of float precision. without this, the intermediate result can be of higher @@ -201,9 +201,9 @@ namespace spartan::math void FindBestAxisVectors(Vector3& Axis1, Vector3& Axis2) const { - const float NX = helper::Abs(x); - const float NY = helper::Abs(y); - const float NZ = helper::Abs(z); + const float NX = abs(x); + const float NY = abs(y); + const float NZ = abs(z); // find best basis vectors if (NZ > NX && NZ > NY) Axis1 = Vector3(1, 0, 0); @@ -236,7 +236,7 @@ namespace spartan::math } // return absolute vector - [[nodiscard]] Vector3 Abs() const { return Vector3(helper::Abs(x), helper::Abs(y), helper::Abs(z)); } + [[nodiscard]] Vector3 Abs() const { return Vector3(abs(x), abs(y), abs(z)); } // linear interpolation with another vector Vector3 Lerp(const Vector3& v, float t) const { return *this * (1.0f - t) + v * t; } diff --git a/runtime/Math/Vector4.h b/runtime/Math/Vector4.h index a237c5ec0..042b76d40 100644 --- a/runtime/Math/Vector4.h +++ b/runtime/Math/Vector4.h @@ -96,18 +96,15 @@ namespace spartan::math return Vector4(x / rhs, y / rhs, z / rhs, w / rhs); } - // Returns the length - [[nodiscard]] float Length() const { return helper::Sqrt(x * x + y * y + z * z + w * w); } - // Returns the squared length + [[nodiscard]] float Length() const { return sqrt(x * x + y * y + z * z + w * w); } [[nodiscard]] float LengthSquared() const { return x * x + y * y + z * z + w * w; } - // Normalize void Normalize() { const auto length_squared = LengthSquared(); - if (!helper::Equals(length_squared, 1.0f) && length_squared > 0.0f) + if (!EqualsWithError(length_squared, 1.0f) && length_squared > 0.0f) { - const auto length_inverted = 1.0f / helper::Sqrt(length_squared); + const auto length_inverted = 1.0f / sqrt(length_squared); x *= length_inverted; y *= length_inverted; z *= length_inverted; @@ -115,13 +112,12 @@ namespace spartan::math } }; - // Return normalized vector [[nodiscard]] Vector4 Normalized() const { const auto length_squared = LengthSquared(); - if (!helper::Equals(length_squared, 1.0f) && length_squared > 0.0f) + if (!EqualsWithError(length_squared, 1.0f) && length_squared > 0.0f) { - const auto length_inverted = 1.0f / helper::Sqrt(length_squared); + const auto length_inverted = 1.0f / sqrt(length_squared); return (*this) * length_inverted; } else diff --git a/runtime/Profiling/Profiler.cpp b/runtime/Profiling/Profiler.cpp index 935d49035..c97e4fe91 100644 --- a/runtime/Profiling/Profiler.cpp +++ b/runtime/Profiling/Profiler.cpp @@ -186,19 +186,19 @@ namespace spartan // cpu time_cpu_avg = (time_cpu_avg * weight_history) + time_cpu_last * weight_delta; - time_cpu_min = math::helper::Min(time_cpu_min, time_cpu_last); - time_cpu_max = math::helper::Max(time_cpu_max, time_cpu_last); + time_cpu_min = min(time_cpu_min, time_cpu_last); + time_cpu_max = max(time_cpu_max, time_cpu_last); // gpu time_gpu_avg = (time_gpu_avg * weight_history) + time_gpu_last * weight_delta; - time_gpu_min = math::helper::Min(time_gpu_min, time_gpu_last); - time_gpu_max = math::helper::Max(time_gpu_max, time_gpu_last); + time_gpu_min = min(time_gpu_min, time_gpu_last); + time_gpu_max = max(time_gpu_max, time_gpu_last); // frame time_frame_last = static_cast(Timer::GetDeltaTimeMs()); time_frame_avg = (time_frame_avg * weight_history) + time_frame_last * weight_delta; - time_frame_min = math::helper::Min(time_frame_min, time_frame_last); - time_frame_max = math::helper::Max(time_frame_max, time_frame_last); + time_frame_min = min(time_frame_min, time_frame_last); + time_frame_max = max(time_frame_max, time_frame_last); // fps m_fps = 1000.0f / time_frame_avg; diff --git a/runtime/Profiling/TimeBlock.cpp b/runtime/Profiling/TimeBlock.cpp index e9a460223..54d95e218 100644 --- a/runtime/Profiling/TimeBlock.cpp +++ b/runtime/Profiling/TimeBlock.cpp @@ -45,7 +45,7 @@ namespace spartan m_parent = parent; m_tree_depth = FindTreeDepth(this); m_type = type; - m_max_tree_depth = math::helper::Max(m_max_tree_depth, m_tree_depth); + m_max_tree_depth = max(m_max_tree_depth, m_tree_depth); if (cmd_list) { diff --git a/runtime/RHI/Vulkan/Vulkan_CommandList.cpp b/runtime/RHI/Vulkan/Vulkan_CommandList.cpp index 43e406722..220d63f2f 100644 --- a/runtime/RHI/Vulkan/Vulkan_CommandList.cpp +++ b/runtime/RHI/Vulkan/Vulkan_CommandList.cpp @@ -1452,10 +1452,10 @@ namespace spartan uint64_t start = queries::timestamp::data[index_timestamp]; uint64_t end = queries::timestamp::data[index_timestamp + 1]; - uint64_t duration = math::helper::Clamp(end - start, 0, numeric_limits::max()); + uint64_t duration = math::Clamp(end - start, 0, numeric_limits::max()); float duration_ms = static_cast(duration * RHI_Device::PropertyGetTimestampPeriod() * 1e-6f); - return math::helper::Clamp(duration_ms, 0.0f, numeric_limits::max()); + return math::Clamp(duration_ms, 0.0f, numeric_limits::max()); } void RHI_CommandList::BeginOcclusionQuery(const uint64_t entity_id) diff --git a/runtime/RHI/Vulkan/Vulkan_Device.cpp b/runtime/RHI/Vulkan/Vulkan_Device.cpp index ac0cf2db0..0546390cc 100644 --- a/runtime/RHI/Vulkan/Vulkan_Device.cpp +++ b/runtime/RHI/Vulkan/Vulkan_Device.cpp @@ -148,7 +148,7 @@ namespace spartan // choose the version which is supported by both the sdk and the driver uint32_t sdk_version = VK_HEADER_VERSION_COMPLETE; - app_info.apiVersion = helper::Min(sdk_version, driver_version); + app_info.apiVersion = min(sdk_version, driver_version); // 1.3 the minimum required version as we are using extensions from 1.3 if (app_info.apiVersion < VK_API_VERSION_1_3) diff --git a/runtime/RHI/Vulkan/Vulkan_Pipeline.cpp b/runtime/RHI/Vulkan/Vulkan_Pipeline.cpp index eea1fba90..640c67b5e 100644 --- a/runtime/RHI/Vulkan/Vulkan_Pipeline.cpp +++ b/runtime/RHI/Vulkan/Vulkan_Pipeline.cpp @@ -280,7 +280,7 @@ namespace spartan rasterizer_state.cullMode = vulkan_cull_mode[static_cast(RHI_CullMode::Back)]; rasterizer_state.frontFace = VK_FRONT_FACE_CLOCKWISE; rasterizer_state.depthBiasEnable = m_state.rasterizer_state->GetDepthBias() != 0.0f ? VK_TRUE : VK_FALSE; - rasterizer_state.depthBiasConstantFactor = math::helper::Floor(m_state.rasterizer_state->GetDepthBias() * (float)(1 << 24)); + rasterizer_state.depthBiasConstantFactor = math::Floor(m_state.rasterizer_state->GetDepthBias() * (float)(1 << 24)); rasterizer_state.depthBiasClamp = m_state.rasterizer_state->GetDepthBiasClamp(); rasterizer_state.depthBiasSlopeFactor = m_state.rasterizer_state->GetDepthBiasSlopeScaled(); } diff --git a/runtime/RHI/Vulkan/Vulkan_SwapChain.cpp b/runtime/RHI/Vulkan/Vulkan_SwapChain.cpp index 4e51cb48a..fada0cdac 100644 --- a/runtime/RHI/Vulkan/Vulkan_SwapChain.cpp +++ b/runtime/RHI/Vulkan/Vulkan_SwapChain.cpp @@ -241,8 +241,8 @@ namespace spartan SP_ASSERT_MSG(is_format_and_color_space_supported(surface, &m_format, color_space), "The surface doesn't support the requested format"); // clamp size between the supported min and max - m_width = math::helper::Clamp(m_width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width); - m_height = math::helper::Clamp(m_height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height); + m_width = math::Clamp(m_width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width); + m_height = math::Clamp(m_height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height); // swap chain VkSwapchainKHR swap_chain; diff --git a/runtime/Rendering/Color.cpp b/runtime/Rendering/Color.cpp index 43356fa68..1e508f134 100644 --- a/runtime/Rendering/Color.cpp +++ b/runtime/Rendering/Color.cpp @@ -55,7 +55,7 @@ namespace spartan { r = 255; g = temp; - g = 99.4708025861f * math::helper::Log(g) - 161.1195681661f; + g = 99.4708025861f * math::Log(g) - 161.1195681661f; if (temp <= 19) { @@ -64,22 +64,22 @@ namespace spartan else { b = temp - 10.0f; - b = 138.5177312231f * math::helper::Log(b) - 305.0447927307f; + b = 138.5177312231f * math::Log(b) - 305.0447927307f; } } else { r = temp - 60.0f; - r = A_R * math::helper::Pow(r, B_R); + r = A_R * math::Pow(r, B_R); g = temp - 60.0f; - g = A_G * math::helper::Pow(g, B_G); + g = A_G * math::Pow(g, B_G); b = 255; } // Clamp RGB values to [0, 1] - r = math::helper::Clamp(r / 255.0f, 0.0f, 1.0f); - g = math::helper::Clamp(g / 255.0f, 0.0f, 1.0f); - b = math::helper::Clamp(b / 255.0f, 0.0f, 1.0f); + r = math::Clamp(r / 255.0f, 0.0f, 1.0f); + g = math::Clamp(g / 255.0f, 0.0f, 1.0f); + b = math::Clamp(b / 255.0f, 0.0f, 1.0f); } Color::Color(const float r, const float g, const float b, const float a /*= 1.0f*/) diff --git a/runtime/Rendering/Font/Font.cpp b/runtime/Rendering/Font/Font.cpp index 6a134e216..fbba25540 100644 --- a/runtime/Rendering/Font/Font.cpp +++ b/runtime/Rendering/Font/Font.cpp @@ -74,8 +74,8 @@ namespace spartan // find max character height (todo, actually get spacing from FreeType) for (const auto& char_info : m_glyphs) { - m_char_max_width = helper::Max(char_info.second.width, m_char_max_width); - m_char_max_height = helper::Max(char_info.second.height, m_char_max_height); + m_char_max_width = max(char_info.second.width, m_char_max_width); + m_char_max_height = max(char_info.second.height, m_char_max_height); } SP_LOG_INFO("Loading \"%s\" took %d ms", FileSystem::GetFileNameFromFilePath(file_path).c_str(), static_cast(timer.GetElapsedTimeMs())); @@ -168,7 +168,7 @@ namespace spartan void Font::SetSize(const uint32_t size) { - m_font_size = helper::Clamp(size, 8, 50); + m_font_size = Clamp(size, 8, 50); } void Font::UpdateVertexAndIndexBuffers(RHI_CommandList* cmd_list) diff --git a/runtime/Rendering/Renderer.cpp b/runtime/Rendering/Renderer.cpp index 5aa2b544e..730a156ef 100644 --- a/runtime/Rendering/Renderer.cpp +++ b/runtime/Rendering/Renderer.cpp @@ -660,16 +660,16 @@ namespace spartan // anisotropy if (option == Renderer_Option::Anisotropy) { - value = helper::Clamp(value, 0.0f, 16.0f); + value = Clamp(value, 0.0f, 16.0f); } // shadow resolution else if (option == Renderer_Option::ShadowResolution) { - value = helper::Clamp(value, static_cast(resolution_shadow_min), static_cast(RHI_Device::PropertyGetMaxTexture2dDimension())); + value = Clamp(value, static_cast(resolution_shadow_min), static_cast(RHI_Device::PropertyGetMaxTexture2dDimension())); } else if (option == Renderer_Option::ResolutionScale) { - value = helper::Clamp(value, 0.5f, 1.0f); + value = Clamp(value, 0.5f, 1.0f); } } diff --git a/runtime/Rendering/Renderer_Passes.cpp b/runtime/Rendering/Renderer_Passes.cpp index 5a93e51f3..a941c1218 100644 --- a/runtime/Rendering/Renderer_Passes.cpp +++ b/runtime/Rendering/Renderer_Passes.cpp @@ -1397,8 +1397,8 @@ namespace spartan const uint32_t resolution_x = tex_environment->GetWidth() >> mip_level; const uint32_t resolution_y = tex_environment->GetHeight() >> mip_level; cmd_list->Dispatch( - static_cast(math::helper::Ceil(static_cast(resolution_y) / thread_group_count)), - static_cast(math::helper::Ceil(static_cast(resolution_y) / thread_group_count)) + static_cast(math::Ceil(static_cast(resolution_y) / thread_group_count)), + static_cast(math::Ceil(static_cast(resolution_y) / thread_group_count)) ); m_environment_mips_to_filter_count--; @@ -1545,8 +1545,8 @@ namespace spartan // Blend uint32_t thread_group_count = 8; - uint32_t thread_group_count_x_ = static_cast(math::helper::Ceil(static_cast(mip_width_large) / thread_group_count)); - uint32_t thread_group_count_y_ = static_cast(math::helper::Ceil(static_cast(mip_height_height) / thread_group_count)); + uint32_t thread_group_count_x_ = static_cast(math::Ceil(static_cast(mip_width_large) / thread_group_count)); + uint32_t thread_group_count_y_ = static_cast(math::Ceil(static_cast(mip_height_height) / thread_group_count)); cmd_list->Dispatch(thread_group_count_x_, thread_group_count_y_); } } diff --git a/runtime/Rendering/Renderer_Primitives.cpp b/runtime/Rendering/Renderer_Primitives.cpp index 2eea15df2..bbae08a45 100644 --- a/runtime/Rendering/Renderer_Primitives.cpp +++ b/runtime/Rendering/Renderer_Primitives.cpp @@ -72,14 +72,14 @@ namespace spartan return; // Need at least 4 segments - segment_count = helper::Max(segment_count, 4); + segment_count = max(segment_count, static_cast(4)); vector points; points.reserve(segment_count + 1); points.resize(segment_count + 1); // Compute points on circle - float angle_step = math::helper::PI_2 / (float)segment_count; + float angle_step = math::PI_2 / (float)segment_count; for (uint32_t i = 0; i <= segment_count; i++) { float angle = (float)i * angle_step; @@ -107,10 +107,10 @@ namespace spartan void Renderer::DrawSphere(const Vector3& center, float radius, uint32_t segment_count, const Color& color /*= DEBUG_COLOR*/) { // Need at least 4 segments - segment_count = helper::Max(segment_count, 4); + segment_count = max(segment_count, static_cast(4)); Vector3 Vertex1, Vertex2, Vertex3, Vertex4; - const float AngleInc = 2.f * helper::PI / float(segment_count); + const float AngleInc = 2.f * PI / float(segment_count); uint32_t NumSegmentsY = segment_count; float Latitude = AngleInc; uint32_t NumSegmentsX; @@ -120,8 +120,8 @@ namespace spartan while (NumSegmentsY--) { - SinY2 = helper::Sin(Latitude); - CosY2 = helper::Cos(Latitude); + SinY2 = sin(Latitude); + CosY2 = cos(Latitude); Vertex1 = Vector3(SinY1, 0.0f, CosY1) * radius + center; Vertex3 = Vector3(SinY2, 0.0f, CosY2) * radius + center; @@ -130,8 +130,8 @@ namespace spartan NumSegmentsX = segment_count; while (NumSegmentsX--) { - SinX = helper::Sin(Longitude); - CosX = helper::Cos(Longitude); + SinX = sin(Longitude); + CosX = cos(Longitude); Vertex2 = Vector3((CosX * SinY1), (SinX * SinY1), CosY1) * radius + center; Vertex4 = Vector3((CosX * SinY2), (SinX * SinY2), CosY2) * radius + center; @@ -151,7 +151,7 @@ namespace spartan void Renderer::DrawDirectionalArrow(const Vector3& start, const Vector3& end, float arrow_size, const Color& color /*= DEBUG_COLOR*/) { - arrow_size = helper::Max(0.1f, arrow_size); + arrow_size = max(0.1f, arrow_size); DrawLine(start, end, color, color); @@ -170,7 +170,7 @@ namespace spartan TM.m20 = Up.x; TM.m21 = Up.y; TM.m22 = Up.z; // since dir is x direction, my arrow will be pointing +y, -x and -y, -x - float arrow_sqrt = helper::Sqrt(arrow_size); + float arrow_sqrt = sqrt(arrow_size); Vector3 arrow_pos; DrawLine(end, end + TM * Vector3(-arrow_sqrt, arrow_sqrt, 0), color, color); DrawLine(end, end + TM * Vector3(-arrow_sqrt, -arrow_sqrt, 0), color, color); @@ -232,7 +232,7 @@ namespace spartan { // tan(angle) = opposite/adjacent // opposite = adjacent * tan(angle) - float opposite = light->GetRange() * math::helper::Tan(light->GetAngle()); + float opposite = light->GetRange() * math::Tan(light->GetAngle()); Vector3 pos_end_center = light->GetEntity()->GetForward() * light->GetRange(); Vector3 pos_end_up = pos_end_center + light->GetEntity()->GetUp() * opposite; diff --git a/runtime/Resource/Import/FontImporter.cpp b/runtime/Resource/Import/FontImporter.cpp index 793f6f767..d763f76f7 100644 --- a/runtime/Resource/Import/FontImporter.cpp +++ b/runtime/Resource/Import/FontImporter.cpp @@ -25,7 +25,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "../../RHI/RHI_Texture.h" #include "../../Rendering/Font/Font.h" SP_WARNINGS_OFF -#include "freetype/ftstroke.h" +#include +#include +#include SP_WARNINGS_ON //==================================== @@ -222,9 +224,9 @@ namespace spartan if (!load_glyph(face, char_code)) continue; - FT_Bitmap* bitmap = &face->glyph->bitmap; - width = helper::Max(width, bitmap->width); - height = helper::Max(height, bitmap->rows); + FT_Bitmap* bitmap = &face->glyph->bitmap; + width = max(width, bitmap->width); + height = max(height, bitmap->rows); } *max_width = width + outline_size * 2; @@ -239,7 +241,7 @@ namespace spartan const uint32_t glyph_count = GLYPH_END - GLYPH_START; const uint32_t glyphs_per_row = ATLAS_WIDTH / max_width; - const uint32_t row_count = static_cast(helper::Ceil(float(glyph_count) / float(glyphs_per_row))); + const uint32_t row_count = static_cast(Ceil(float(glyph_count) / float(glyphs_per_row))); *atlas_width = ATLAS_WIDTH; *atlas_height = max_height * row_count; diff --git a/runtime/World/Components/AudioSource.cpp b/runtime/World/Components/AudioSource.cpp index b93cdea20..15940b044 100644 --- a/runtime/World/Components/AudioSource.cpp +++ b/runtime/World/Components/AudioSource.cpp @@ -196,7 +196,7 @@ namespace spartan // Priority for the channel, from 0 (most important) // to 256 (least important), default = 128. - m_priority = static_cast(helper::Clamp(priority, 0, 255)); + m_priority = static_cast(Clamp(priority, 0, 255)); m_audio_clip->SetPriority(m_priority); } @@ -205,7 +205,7 @@ namespace spartan if (!m_audio_clip) return; - m_volume = helper::Clamp(volume, 0.0f, 1.0f); + m_volume = Clamp(volume, 0.0f, 1.0f); m_audio_clip->SetVolume(m_volume); } @@ -214,7 +214,7 @@ namespace spartan if (!m_audio_clip) return; - m_pitch = helper::Clamp(pitch, 0.0f, 3.0f); + m_pitch = Clamp(pitch, 0.0f, 3.0f); m_audio_clip->SetPitch(m_pitch); } @@ -224,7 +224,7 @@ namespace spartan return; // Pan level, from -1.0 (left) to 1.0 (right). - m_pan = helper::Clamp(pan, -1.0f, 1.0f); + m_pan = Clamp(pan, -1.0f, 1.0f); m_audio_clip->SetPan(m_pan); } diff --git a/runtime/World/Components/Camera.cpp b/runtime/World/Components/Camera.cpp index 9b39913dd..ce8ada9be 100644 --- a/runtime/World/Components/Camera.cpp +++ b/runtime/World/Components/Camera.cpp @@ -99,7 +99,7 @@ namespace spartan void Camera::SetNearPlane(const float near_plane) { - float near_plane_limited = helper::Max(near_plane, 0.01f); + float near_plane_limited = max(near_plane, 0.01f); if (m_near_plane != near_plane_limited) { @@ -122,7 +122,7 @@ namespace spartan float Camera::GetFovHorizontalDeg() const { - return helper::RadiansToDegrees(m_fov_horizontal_rad); + return RadiansToDegrees(m_fov_horizontal_rad); } float Camera::GetFovVerticalRad() const @@ -132,7 +132,7 @@ namespace spartan void Camera::SetFovHorizontalDeg(const float fov) { - m_fov_horizontal_rad = helper::DegreesToRadians(fov); + m_fov_horizontal_rad = DegreesToRadians(fov); SetFlag(CameraFlags::IsDirty, true); } @@ -192,7 +192,7 @@ namespace spartan float distance = ray.HitDistance(aabb); // Don't store hit data if there was no hit - if (distance == helper::INFINITY_) + if (distance == INFINITY_) continue; hits.emplace_back( @@ -414,7 +414,7 @@ namespace spartan const Vector2 mouse_delta = Input::GetMouseDelta() * m_mouse_sensitivity; // lerp to it - m_mouse_smoothed = helper::Lerp(m_mouse_smoothed, mouse_delta, helper::Saturate(1.0f - m_mouse_smoothing)); + m_mouse_smoothed = Lerp(m_mouse_smoothed, mouse_delta, Saturate(1.0f - m_mouse_smoothing)); // accumulate rotation m_first_person_rotation += m_mouse_smoothed; @@ -426,11 +426,11 @@ namespace spartan } // clamp rotation along the x-axis (but not exactly at 90 degrees, this is to avoid a gimbal lock) - m_first_person_rotation.y = helper::Clamp(m_first_person_rotation.y, -80.0f, 80.0f); + m_first_person_rotation.y = Clamp(m_first_person_rotation.y, -80.0f, 80.0f); // compute rotation - const Quaternion xQuaternion = Quaternion::FromAngleAxis(m_first_person_rotation.x * helper::DEG_TO_RAD, Vector3::Up); - const Quaternion yQuaternion = Quaternion::FromAngleAxis(m_first_person_rotation.y * helper::DEG_TO_RAD, Vector3::Right); + const Quaternion xQuaternion = Quaternion::FromAngleAxis(m_first_person_rotation.x * DEG_TO_RAD, Vector3::Up); + const Quaternion yQuaternion = Quaternion::FromAngleAxis(m_first_person_rotation.y * DEG_TO_RAD, Vector3::Right); const Quaternion rotation = xQuaternion * yQuaternion; // rotate @@ -476,7 +476,7 @@ namespace spartan // Clamp float min = -movement_acceleration + 0.1f; // prevent it from negating or zeroing the acceleration, see translation calculation float max = movement_acceleration * 2.0f; // an empirically chosen max - m_movement_scroll_accumulator = helper::Clamp(m_movement_scroll_accumulator, min, max); + m_movement_scroll_accumulator = Clamp(m_movement_scroll_accumulator, min, max); } // translation @@ -539,7 +539,7 @@ namespace spartan // compute drag factor float drag_coefficient = 0.34f; - float frontal_area = std::pow(helper::PI * m_physics_body_to_control->GetCapsuleRadius(), 2.0f); + float frontal_area = std::pow(PI * m_physics_body_to_control->GetCapsuleRadius(), 2.0f); float linear_velocity_y = water_density * m_physics_body_to_control->GetLinearVelocity().y; float drag_force_y = 0.5f * water_density * linear_velocity_y * linear_velocity_y * drag_coefficient; @@ -595,7 +595,7 @@ namespace spartan // lerp duration in seconds // 2.0 seconds + [0.0 - 2.0] seconds based on distance // Something is not right with the duration... - const float lerp_duration = 2.0f + helper::Clamp(m_lerp_to_target_distance * 0.01f, 0.0f, 2.0f); + const float lerp_duration = 2.0f + Clamp(m_lerp_to_target_distance * 0.01f, 0.0f, 2.0f); // alpha m_lerp_to_target_alpha += static_cast(Timer::GetDeltaTimeSec()) / lerp_duration; @@ -610,7 +610,7 @@ namespace spartan // rotation if (m_lerp_to_target_r) { - const Quaternion interpolated_rotation = Quaternion::Lerp(GetEntity()->GetRotation(), m_lerp_to_target_rotation, helper::Clamp(m_lerp_to_target_alpha, 0.0f, 1.0f)); + const Quaternion interpolated_rotation = Quaternion::Lerp(GetEntity()->GetRotation(), m_lerp_to_target_rotation, Clamp(m_lerp_to_target_alpha, 0.0f, 1.0f)); GetEntity()->SetRotation(interpolated_rotation); } @@ -649,7 +649,7 @@ namespace spartan m_lerp_to_target_rotation = Quaternion::FromLookRotation(entity->GetPosition() - m_lerp_to_target_position).Normalized(); m_lerp_to_target_distance = Vector3::Distance(m_lerp_to_target_position, GetEntity()->GetPosition()); - const float lerp_angle = acosf(Quaternion::Dot(m_lerp_to_target_rotation.Normalized(), GetEntity()->GetRotation().Normalized())) * helper::RAD_TO_DEG; + const float lerp_angle = acosf(Quaternion::Dot(m_lerp_to_target_rotation.Normalized(), GetEntity()->GetRotation().Normalized())) * RAD_TO_DEG; m_lerp_to_target_p = m_lerp_to_target_distance > 0.1f ? true : false; m_lerp_to_target_r = lerp_angle > 1.0f ? true : false; diff --git a/runtime/World/Components/Camera.h b/runtime/World/Components/Camera.h index 82c15283b..00da34229 100644 --- a/runtime/World/Components/Camera.h +++ b/runtime/World/Components/Camera.h @@ -147,7 +147,7 @@ namespace spartan float m_aperture = 2.8f; // aperture value in f-stop. Controls the amount of light, depth of field and chromatic aberration float m_shutter_speed = 1.0f / 60.0f; // length of time for which the camera shutter is open (sec). Also controls the amount of motion blur float m_iso = 500.0f; // sensitivity to light - float m_fov_horizontal_rad = math::helper::DegreesToRadians(90.0f); + float m_fov_horizontal_rad = math::DegreesToRadians(90.0f); float m_near_plane = 0.1f; float m_far_plane = 4000.0f; ProjectionType m_projection_type = Projection_Perspective; diff --git a/runtime/World/Components/Constraint.cpp b/runtime/World/Components/Constraint.cpp index 36fea9905..f416bcdfb 100644 --- a/runtime/World/Components/Constraint.cpp +++ b/runtime/World/Components/Constraint.cpp @@ -369,7 +369,7 @@ namespace spartan case HINGE_CONSTRAINT_TYPE: { auto* hinge_constraint = dynamic_cast(m_constraint); - hinge_constraint->setLimit(m_lowLimit.x * helper::DEG_TO_RAD, m_highLimit.x * helper::DEG_TO_RAD); + hinge_constraint->setLimit(m_lowLimit.x * DEG_TO_RAD, m_highLimit.x * DEG_TO_RAD); } break; @@ -377,16 +377,16 @@ namespace spartan { auto* slider_constraint = dynamic_cast(m_constraint); slider_constraint->setUpperLinLimit(m_highLimit.x); - slider_constraint->setUpperAngLimit(m_highLimit.y * helper::DEG_TO_RAD); + slider_constraint->setUpperAngLimit(m_highLimit.y * DEG_TO_RAD); slider_constraint->setLowerLinLimit(m_lowLimit.x); - slider_constraint->setLowerAngLimit(m_lowLimit.y * helper::DEG_TO_RAD); + slider_constraint->setLowerAngLimit(m_lowLimit.y * DEG_TO_RAD); } break; case CONETWIST_CONSTRAINT_TYPE: { auto* cone_twist_constraint = dynamic_cast(m_constraint); - cone_twist_constraint->setLimit(m_highLimit.y * helper::DEG_TO_RAD, m_highLimit.y * helper::DEG_TO_RAD, m_highLimit.x * helper::DEG_TO_RAD); + cone_twist_constraint->setLimit(m_highLimit.y * DEG_TO_RAD, m_highLimit.y * DEG_TO_RAD, m_highLimit.x * DEG_TO_RAD); } break; diff --git a/runtime/World/Components/Light.cpp b/runtime/World/Components/Light.cpp index bd4efd26a..0b593d166 100644 --- a/runtime/World/Components/Light.cpp +++ b/runtime/World/Components/Light.cpp @@ -391,7 +391,7 @@ namespace spartan void Light::SetRange(float range) { - range = helper::Clamp(range, 0.0f, numeric_limits::max()); + range = Clamp(range, 0.0f, numeric_limits::max()); if (range == m_range) return; @@ -401,7 +401,7 @@ namespace spartan void Light::SetAngle(float angle) { - angle = helper::Clamp(angle, 0.0f, math::helper::PI_2); + angle = Clamp(angle, 0.0f, math::PI_2); if (angle == m_angle_rad) return; diff --git a/runtime/World/Components/Light.h b/runtime/World/Components/Light.h index 33e043d00..add1b94ab 100644 --- a/runtime/World/Components/Light.h +++ b/runtime/World/Components/Light.h @@ -157,7 +157,7 @@ namespace spartan Color m_color_rgb = Color::standard_black;; float m_temperature_kelvin = 0.0f; float m_range = 0.0f; - float m_angle_rad = math::helper::DEG_TO_RAD * 30.0f; + float m_angle_rad = math::DEG_TO_RAD * 30.0f; uint32_t m_index = 0; bool m_filtering_pending = false; float m_time_since_last_filtering_sec = 0.0f; diff --git a/runtime/World/Components/PhysicsBody.cpp b/runtime/World/Components/PhysicsBody.cpp index f77bfa6e6..2e1d8d271 100644 --- a/runtime/World/Components/PhysicsBody.cpp +++ b/runtime/World/Components/PhysicsBody.cpp @@ -246,7 +246,7 @@ namespace spartan void PhysicsBody::SetMass(float mass) { - m_mass = helper::Max(mass, 0.0f); + m_mass = max(mass, 0.0f); // if the shape doesn't exist, the physics body hasn't been initialized yet // so don't do anything and allow the user to set whatever properties they want @@ -689,9 +689,9 @@ namespace spartan return; m_size = bounding_box; - m_size.x = helper::Clamp(m_size.x, helper::SMALL_FLOAT, INFINITY); - m_size.y = helper::Clamp(m_size.y, helper::SMALL_FLOAT, INFINITY); - m_size.z = helper::Clamp(m_size.z, helper::SMALL_FLOAT, INFINITY); + m_size.x = Clamp(m_size.x, SMALL_FLOAT, INFINITY); + m_size.y = Clamp(m_size.y, SMALL_FLOAT, INFINITY); + m_size.z = Clamp(m_size.z, SMALL_FLOAT, INFINITY); } void PhysicsBody::SetShapeType(PhysicsShape type, const bool replicate_hierarchy) @@ -760,7 +760,7 @@ namespace spartan Vector3 hit_position = Physics::RayCastFirstHitPosition(ray_start, ray_end); - bool is_scalable = helper::Abs(hit_position.y - min_y) <= max_scalable_height; + bool is_scalable = abs(hit_position.y - min_y) <= max_scalable_height; bool is_above = hit_position.y > min_y; return (is_scalable && is_above) ? hit_position : Vector3::Infinity; @@ -778,10 +778,10 @@ namespace spartan float cylinder_height = capsule_shape->getHalfHeight() * 2.0f; // compute the volume of the cylindrical part - float cylinder_volume = math::helper::PI * radius * radius * cylinder_height; + float cylinder_volume = math::PI * radius * radius * cylinder_height; // compute the volume of the hemispherical ends - float hemisphere_volume = (4.0f / 3.0f) * math::helper::PI * std::pow(radius, 3.0f); + float hemisphere_volume = (4.0f / 3.0f) * math::PI * std::pow(radius, 3.0f); // total volume is the sum of the cylinder and two hemispheres return cylinder_volume + hemisphere_volume; @@ -818,20 +818,20 @@ namespace spartan case PhysicsShape::Sphere: m_shape = new btSphereShape(size.x * 0.5f); - volume = (4.0f / 3.0f) * helper::PI * powf(size.x * 0.5f, 3); // (4/3)πr³ + volume = (4.0f / 3.0f) * PI * powf(size.x * 0.5f, 3); // (4/3)πr³ break; case PhysicsShape::Cylinder: m_shape = new btCylinderShape(vector_to_bt(size * 0.5f)); - volume = helper::PI * powf(size.x * 0.5f, 2) * size.y; // πr²h + volume = PI * powf(size.x * 0.5f, 2) * size.y; // πr²h break; case PhysicsShape::Capsule: { - float radius = helper::Max(size.x, size.z) * 0.5f; + float radius = max(size.x, size.z) * 0.5f; float height = size.y - 2.0f * radius; // exclude spherical caps from the cylindrical height - float sphere_volume = (4.0f / 3.0f) * helper::PI * powf(radius, 3); // spherical caps - float cylinder_volume = helper::PI * powf(radius, 2) * height; // cylindrical body + float sphere_volume = (4.0f / 3.0f) * PI * powf(radius, 3); // spherical caps + float cylinder_volume = PI * powf(radius, 2) * height; // cylindrical body volume = sphere_volume + cylinder_volume; m_shape = new btCapsuleShape(radius, size.y); break; @@ -839,7 +839,7 @@ namespace spartan case PhysicsShape::Cone: m_shape = new btConeShape(size.x * 0.5f, size.y); - volume = (1.0f / 3.0f) * helper::PI * powf(size.x * 0.5f, 2) * size.y; // (1/3)πr²h + volume = (1.0f / 3.0f) * PI * powf(size.x * 0.5f, 2) * size.y; // (1/3)πr²h break; case PhysicsShape::StaticPlane: diff --git a/runtime/World/Components/Terrain.cpp b/runtime/World/Components/Terrain.cpp index ca24674cc..ecc4a93b1 100644 --- a/runtime/World/Components/Terrain.cpp +++ b/runtime/World/Components/Terrain.cpp @@ -538,21 +538,21 @@ namespace spartan if (terrain_prop == TerrainProp::Tree) { - max_slope = 30.0f * math::helper::DEG_TO_RAD; + max_slope = 30.0f * math::DEG_TO_RAD; rotate_match_surface_normal = false; // trees tend to grow upwards, towards the sun terrain_offset = -0.5f; } if (terrain_prop == TerrainProp::Plant) { - max_slope = 40.0f * math::helper::DEG_TO_RAD; + max_slope = 40.0f * math::DEG_TO_RAD; rotate_match_surface_normal = true; // small plants tend to grow towards the sun but they can have some wonky angles due to low mass terrain_offset = 0.0f; } if (terrain_prop == TerrainProp::Grass) { - max_slope = 40.0f * math::helper::DEG_TO_RAD; + max_slope = 40.0f * math::DEG_TO_RAD; rotate_match_surface_normal = true; terrain_offset = -0.9f; } diff --git a/runtime/World/Entity.cpp b/runtime/World/Entity.cpp index f50642b06..83adc9fe9 100644 --- a/runtime/World/Entity.cpp +++ b/runtime/World/Entity.cpp @@ -431,9 +431,9 @@ namespace spartan m_scale_local = scale; // a scale of 0 will cause a division by zero when decomposing the world transform matrix - m_scale_local.x = (m_scale_local.x == 0.0f) ? helper::SMALL_FLOAT : m_scale_local.x; - m_scale_local.y = (m_scale_local.y == 0.0f) ? helper::SMALL_FLOAT : m_scale_local.y; - m_scale_local.z = (m_scale_local.z == 0.0f) ? helper::SMALL_FLOAT : m_scale_local.z; + m_scale_local.x = (m_scale_local.x == 0.0f) ? SMALL_FLOAT : m_scale_local.x; + m_scale_local.y = (m_scale_local.y == 0.0f) ? SMALL_FLOAT : m_scale_local.y; + m_scale_local.z = (m_scale_local.z == 0.0f) ? SMALL_FLOAT : m_scale_local.z; UpdateTransform(); }