mirror of
https://github.com/orange-cpp/omath.git
synced 2026-08-08 14:02:06 +00:00
Compare commits
3 Commits
fdcb7845cf
...
0a3b10022f
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a3b10022f | |||
| 935f69426c | |||
| 9eb4dd1155 |
@@ -12,15 +12,21 @@ namespace omath::algorithm
|
||||
[[nodiscard]]
|
||||
Vector2<float> world_to_radar(const Camera& camera, const Vector3<FloatingType>& position, const FloatingType scale)
|
||||
{
|
||||
auto look_at_angles = camera.calc_look_at_angles(position);
|
||||
auto current_angles = camera.get_view_angles();
|
||||
|
||||
auto yaw = look_at_angles.yaw - current_angles.yaw + decltype(current_angles.yaw)::from_degrees(180);
|
||||
auto right_yaw = camera.calc_look_at_angles(camera.get_origin() + camera.get_abs_right()).yaw
|
||||
- current_angles.yaw + decltype(current_angles.yaw)::from_degrees(180);
|
||||
const auto right_scale = right_yaw.sin() < 0 ? -1.f : 1.f;
|
||||
const auto look_at_angles = camera.calc_look_at_angles(position);
|
||||
const auto current_angles = camera.get_view_angles();
|
||||
|
||||
return omath::Vector2<float>(static_cast<float>(yaw.sin()) * right_scale, yaw.cos())
|
||||
static const auto sign = [&camera, ¤t_angles]
|
||||
{
|
||||
auto right_yaw = current_angles.yaw
|
||||
- camera.calc_look_at_angles(camera.get_origin() + camera.get_abs_right()).yaw
|
||||
- decltype(current_angles.yaw)::from_degrees(90);
|
||||
return right_yaw.cos() < 0 ? -1.f : 1.f;
|
||||
}();
|
||||
|
||||
const auto yaw = current_angles.yaw - look_at_angles.yaw - decltype(current_angles.yaw)::from_degrees(90);
|
||||
|
||||
return omath::Vector2<float>(static_cast<float>(yaw.cos()) * sign, static_cast<float>(yaw.sin()))
|
||||
* (camera.get_origin().distance_to(position) * scale);
|
||||
}
|
||||
} // namespace omath::algorithm
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Angle operator+(const Angle& other) noexcept
|
||||
constexpr Angle operator+(const Angle& other) const noexcept
|
||||
{
|
||||
if constexpr (flags == AngleFlags::Normalized)
|
||||
return Angle{angles::wrap_angle(m_angle + other.m_angle, min, max)};
|
||||
@@ -140,7 +140,7 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Angle operator-(const Angle& other) noexcept
|
||||
constexpr Angle operator-(const Angle& other) const noexcept
|
||||
{
|
||||
return operator+(-other);
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ TEST(UnitTestAngle, Formatter_PrintsDegreesWithSuffix)
|
||||
|
||||
TEST(UnitTestAngle, BinaryPlus_ReturnsWrappedSum)
|
||||
{
|
||||
Angle<> a = Deg::from_degrees(350.0f);
|
||||
const Angle<> a = Deg::from_degrees(350.0f);
|
||||
const Deg b = Deg::from_degrees(20.0f);
|
||||
const Deg c = a + b; // expect 10°
|
||||
EXPECT_FLOAT_EQ(c.as_degrees(), 10.0f);
|
||||
@@ -191,7 +191,7 @@ TEST(UnitTestAngle, BinaryPlus_ReturnsWrappedSum)
|
||||
|
||||
TEST(UnitTestAngle, BinaryMinus_ReturnsWrappedDiff)
|
||||
{
|
||||
Angle<> a = Deg::from_degrees(10.0f);
|
||||
const Angle<> a = Deg::from_degrees(10.0f);
|
||||
const Deg b = Deg::from_degrees(30.0f);
|
||||
const Deg c = a - b; // expect 340°
|
||||
EXPECT_FLOAT_EQ(c.as_degrees(), 340.0f);
|
||||
|
||||
Reference in New Issue
Block a user