Skip to content

Commit

Permalink
[math] some minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Jan 22, 2025
1 parent 118ec28 commit ba1c37d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion runtime/Game/Car.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::Lerp<float>(m_parameters.steering_angle, steering_angle_target, tuning::steering_return_speed * delta_time_sec);
m_parameters.steering_angle = math::lerp<float>(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);
Expand Down
8 changes: 2 additions & 6 deletions runtime/Math/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#pragma once

//= INCLUDES ====
#include <cmath>
#include <limits>
#include <random>
//===============

Expand All @@ -46,13 +44,11 @@ namespace spartan::math
constexpr float deg_to_rad = pi / 180.0f;
constexpr float rad_to_deg = 180.0f / pi;

inline float cot(float x) { return cos(x) / sin(x); }

template <typename T>
constexpr T saturate(T x) { return clamp<T>(x, static_cast<T>(0), static_cast<T>(1)); }
constexpr T saturate(T x) { return std::clamp<T>(x, static_cast<T>(0), static_cast<T>(1)); }

template <class T, class U>
constexpr T Lerp(T lhs, T rhs, U t) { return lhs * (static_cast<U>(1) - t) + rhs * t; }
constexpr T lerp(T lhs, T rhs, U t) { return lhs * (static_cast<U>(1) - t) + rhs * t; }

template <class T>
constexpr bool approximate_equals(T lhs, T rhs, T error = std::numeric_limits<T>::epsilon()) { return lhs + error >= rhs && lhs - error <= rhs; }
Expand Down
2 changes: 1 addition & 1 deletion runtime/World/Components/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ namespace spartan
const Vector2 mouse_delta = Input::GetMouseDelta() * m_mouse_sensitivity;

// lerp to it
m_mouse_smoothed = Lerp(m_mouse_smoothed, mouse_delta, 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;
Expand Down

0 comments on commit ba1c37d

Please sign in to comment.