mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Store angles internally as radians
This commit is contained in:
parent
3345796907
commit
884206ce0c
@ -144,20 +144,20 @@ private:
|
|||||||
friend constexpr Angle radians(float angle);
|
friend constexpr Angle radians(float angle);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct from a number of degrees
|
/// \brief Construct from a number of radians
|
||||||
///
|
///
|
||||||
/// This function is internal. To construct angle values,
|
/// This function is internal. To construct angle values,
|
||||||
/// use sf::radians or sf::degrees instead.
|
/// use sf::radians or sf::degrees instead.
|
||||||
///
|
///
|
||||||
/// \param degrees Angle in degrees
|
/// \param radians Angle in radians
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr explicit Angle(float degrees);
|
constexpr explicit Angle(float radians);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float m_degrees{}; //!< Angle value stored as degrees
|
float m_radians{}; //!< Angle value stored as radians
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -187,6 +187,7 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Angle
|
/// \relates Angle
|
||||||
/// \brief Overload of == operator to compare two angle values
|
/// \brief Overload of == operator to compare two angle values
|
||||||
|
/// \note Does not automatically wrap the angle value
|
||||||
///
|
///
|
||||||
/// \param left Left operand (an angle)
|
/// \param left Left operand (an angle)
|
||||||
/// \param right Right operand (an angle)
|
/// \param right Right operand (an angle)
|
||||||
@ -199,6 +200,7 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Angle
|
/// \relates Angle
|
||||||
/// \brief Overload of != operator to compare two angle values
|
/// \brief Overload of != operator to compare two angle values
|
||||||
|
/// \note Does not automatically wrap the angle value
|
||||||
///
|
///
|
||||||
/// \param left Left operand (an angle)
|
/// \param left Left operand (an angle)
|
||||||
/// \param right Right operand (an angle)
|
/// \param right Right operand (an angle)
|
||||||
@ -211,6 +213,7 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Angle
|
/// \relates Angle
|
||||||
/// \brief Overload of < operator to compare two angle values
|
/// \brief Overload of < operator to compare two angle values
|
||||||
|
/// \note Does not automatically wrap the angle value
|
||||||
///
|
///
|
||||||
/// \param left Left operand (an angle)
|
/// \param left Left operand (an angle)
|
||||||
/// \param right Right operand (an angle)
|
/// \param right Right operand (an angle)
|
||||||
@ -223,6 +226,7 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Angle
|
/// \relates Angle
|
||||||
/// \brief Overload of > operator to compare two angle values
|
/// \brief Overload of > operator to compare two angle values
|
||||||
|
/// \note Does not automatically wrap the angle value
|
||||||
///
|
///
|
||||||
/// \param left Left operand (an angle)
|
/// \param left Left operand (an angle)
|
||||||
/// \param right Right operand (an angle)
|
/// \param right Right operand (an angle)
|
||||||
@ -235,6 +239,7 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Angle
|
/// \relates Angle
|
||||||
/// \brief Overload of <= operator to compare two angle values
|
/// \brief Overload of <= operator to compare two angle values
|
||||||
|
/// \note Does not automatically wrap the angle value
|
||||||
///
|
///
|
||||||
/// \param left Left operand (an angle)
|
/// \param left Left operand (an angle)
|
||||||
/// \param right Right operand (an angle)
|
/// \param right Right operand (an angle)
|
||||||
@ -247,6 +252,7 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Angle
|
/// \relates Angle
|
||||||
/// \brief Overload of >= operator to compare two angle values
|
/// \brief Overload of >= operator to compare two angle values
|
||||||
|
/// \note Does not automatically wrap the angle value
|
||||||
///
|
///
|
||||||
/// \param left Left operand (an angle)
|
/// \param left Left operand (an angle)
|
||||||
/// \param right Right operand (an angle)
|
/// \param right Right operand (an angle)
|
||||||
|
@ -35,15 +35,13 @@ namespace sf
|
|||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
constexpr float pi = 3.141592654f;
|
constexpr float pi = 3.141592654f;
|
||||||
|
constexpr float tau = pi * 2.f;
|
||||||
|
|
||||||
constexpr float positiveRemainder(float a, float b)
|
constexpr float positiveRemainder(float a, float b)
|
||||||
{
|
{
|
||||||
assert(b > 0.0f && "Cannot calculate remainder with non-positive divisor");
|
assert(b > 0.f && "Cannot calculate remainder with non-positive divisor");
|
||||||
const float val = a - static_cast<float>(static_cast<int>(a / b)) * b;
|
const float val = a - static_cast<float>(static_cast<int>(a / b)) * b;
|
||||||
if (val >= 0.f)
|
return val >= 0.f ? val : val + b;
|
||||||
return val;
|
|
||||||
else
|
|
||||||
return val + b;
|
|
||||||
}
|
}
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
|
||||||
@ -55,33 +53,33 @@ constexpr Angle::Angle() = default;
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr float Angle::asDegrees() const
|
constexpr float Angle::asDegrees() const
|
||||||
{
|
{
|
||||||
return m_degrees;
|
return m_radians * (180.f / priv::pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr float Angle::asRadians() const
|
constexpr float Angle::asRadians() const
|
||||||
{
|
{
|
||||||
return m_degrees * (priv::pi / 180);
|
return m_radians;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle Angle::wrapSigned() const
|
constexpr Angle Angle::wrapSigned() const
|
||||||
{
|
{
|
||||||
return degrees(priv::positiveRemainder(m_degrees + 180, 360) - 180);
|
return radians(priv::positiveRemainder(m_radians + priv::pi, priv::tau) - priv::pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle Angle::wrapUnsigned() const
|
constexpr Angle Angle::wrapUnsigned() const
|
||||||
{
|
{
|
||||||
return degrees(priv::positiveRemainder(m_degrees, 360));
|
return radians(priv::positiveRemainder(m_radians, priv::tau));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle::Angle(float degrees) : m_degrees(degrees)
|
constexpr Angle::Angle(float radians) : m_radians(radians)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,70 +87,70 @@ constexpr Angle::Angle(float degrees) : m_degrees(degrees)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle degrees(float angle)
|
constexpr Angle degrees(float angle)
|
||||||
{
|
{
|
||||||
return Angle(angle);
|
return Angle(angle * (priv::pi / 180.f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle radians(float angle)
|
constexpr Angle radians(float angle)
|
||||||
{
|
{
|
||||||
return Angle(angle * (180 / priv::pi));
|
return Angle(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr bool operator==(Angle left, Angle right)
|
constexpr bool operator==(Angle left, Angle right)
|
||||||
{
|
{
|
||||||
return left.asDegrees() == right.asDegrees();
|
return left.asRadians() == right.asRadians();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr bool operator!=(Angle left, Angle right)
|
constexpr bool operator!=(Angle left, Angle right)
|
||||||
{
|
{
|
||||||
return left.asDegrees() != right.asDegrees();
|
return left.asRadians() != right.asRadians();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr bool operator<(Angle left, Angle right)
|
constexpr bool operator<(Angle left, Angle right)
|
||||||
{
|
{
|
||||||
return left.asDegrees() < right.asDegrees();
|
return left.asRadians() < right.asRadians();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr bool operator>(Angle left, Angle right)
|
constexpr bool operator>(Angle left, Angle right)
|
||||||
{
|
{
|
||||||
return left.asDegrees() > right.asDegrees();
|
return left.asRadians() > right.asRadians();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr bool operator<=(Angle left, Angle right)
|
constexpr bool operator<=(Angle left, Angle right)
|
||||||
{
|
{
|
||||||
return left.asDegrees() <= right.asDegrees();
|
return left.asRadians() <= right.asRadians();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr bool operator>=(Angle left, Angle right)
|
constexpr bool operator>=(Angle left, Angle right)
|
||||||
{
|
{
|
||||||
return left.asDegrees() >= right.asDegrees();
|
return left.asRadians() >= right.asRadians();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle operator-(Angle right)
|
constexpr Angle operator-(Angle right)
|
||||||
{
|
{
|
||||||
return degrees(-right.asDegrees());
|
return radians(-right.asRadians());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle operator+(Angle left, Angle right)
|
constexpr Angle operator+(Angle left, Angle right)
|
||||||
{
|
{
|
||||||
return degrees(left.asDegrees() + right.asDegrees());
|
return radians(left.asRadians() + right.asRadians());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -166,7 +164,7 @@ constexpr Angle& operator+=(Angle& left, Angle right)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle operator-(Angle left, Angle right)
|
constexpr Angle operator-(Angle left, Angle right)
|
||||||
{
|
{
|
||||||
return degrees(left.asDegrees() - right.asDegrees());
|
return radians(left.asRadians() - right.asRadians());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -180,7 +178,7 @@ constexpr Angle& operator-=(Angle& left, Angle right)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle operator*(Angle left, float right)
|
constexpr Angle operator*(Angle left, float right)
|
||||||
{
|
{
|
||||||
return degrees(left.asDegrees() * right);
|
return radians(left.asRadians() * right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -201,15 +199,15 @@ constexpr Angle& operator*=(Angle& left, float right)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle operator/(Angle left, float right)
|
constexpr Angle operator/(Angle left, float right)
|
||||||
{
|
{
|
||||||
assert(right != 0 && "Angle::operator/ cannot divide by 0");
|
assert(right != 0.f && "Angle::operator/ cannot divide by 0");
|
||||||
return degrees(left.asDegrees() / right);
|
return radians(left.asRadians() / right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle& operator/=(Angle& left, float right)
|
constexpr Angle& operator/=(Angle& left, float right)
|
||||||
{
|
{
|
||||||
assert(right != 0 && "Angle::operator/= cannot divide by 0");
|
assert(right != 0.f && "Angle::operator/= cannot divide by 0");
|
||||||
return left = left / right;
|
return left = left / right;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,23 +215,23 @@ constexpr Angle& operator/=(Angle& left, float right)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr float operator/(Angle left, Angle right)
|
constexpr float operator/(Angle left, Angle right)
|
||||||
{
|
{
|
||||||
assert(right.asDegrees() != 0 && "Angle::operator/ cannot divide by 0");
|
assert(right.asRadians() != 0.f && "Angle::operator/ cannot divide by 0");
|
||||||
return left.asDegrees() / right.asDegrees();
|
return left.asRadians() / right.asRadians();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle operator%(Angle left, Angle right)
|
constexpr Angle operator%(Angle left, Angle right)
|
||||||
{
|
{
|
||||||
assert(right.asDegrees() != 0 && "Angle::operator% cannot modulus by 0");
|
assert(right.asRadians() != 0.f && "Angle::operator% cannot modulus by 0");
|
||||||
return degrees(priv::positiveRemainder(left.asDegrees(), right.asDegrees()));
|
return radians(priv::positiveRemainder(left.asRadians(), right.asRadians()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
constexpr Angle& operator%=(Angle& left, Angle right)
|
constexpr Angle& operator%=(Angle& left, Angle right)
|
||||||
{
|
{
|
||||||
assert(right.asDegrees() != 0 && "Angle::operator%= cannot modulus by 0");
|
assert(right.asRadians() != 0.f && "Angle::operator%= cannot modulus by 0");
|
||||||
return left = left % right;
|
return left = left % right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,11 +44,11 @@ namespace sf::Sensor
|
|||||||
enum class Type
|
enum class Type
|
||||||
{
|
{
|
||||||
Accelerometer, //!< Measures the raw acceleration (m/s^2)
|
Accelerometer, //!< Measures the raw acceleration (m/s^2)
|
||||||
Gyroscope, //!< Measures the raw rotation rates (degrees/s)
|
Gyroscope, //!< Measures the raw rotation rates (radians/s)
|
||||||
Magnetometer, //!< Measures the ambient magnetic field (micro-teslas)
|
Magnetometer, //!< Measures the ambient magnetic field (micro-teslas)
|
||||||
Gravity, //!< Measures the direction and intensity of gravity, independent of device acceleration (m/s^2)
|
Gravity, //!< Measures the direction and intensity of gravity, independent of device acceleration (m/s^2)
|
||||||
UserAcceleration, //!< Measures the direction and intensity of device acceleration, independent of the gravity (m/s^2)
|
UserAcceleration, //!< Measures the direction and intensity of device acceleration, independent of the gravity (m/s^2)
|
||||||
Orientation //!< Measures the absolute 3D orientation (degrees)
|
Orientation //!< Measures the absolute 3D orientation (radians)
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||||
|
@ -324,8 +324,8 @@ void AudioDevice::setCone(const Listener::Cone& cone)
|
|||||||
|
|
||||||
ma_engine_listener_set_cone(&*instance->m_engine,
|
ma_engine_listener_set_cone(&*instance->m_engine,
|
||||||
0,
|
0,
|
||||||
std::clamp(cone.innerAngle.asRadians(), 0.f, degrees(360).asRadians()),
|
std::clamp(cone.innerAngle, Angle::Zero, degrees(360.f)).asRadians(),
|
||||||
std::clamp(cone.outerAngle.asRadians(), 0.f, degrees(360).asRadians()),
|
std::clamp(cone.outerAngle, Angle::Zero, degrees(360.f)).asRadians(),
|
||||||
cone.outerGain);
|
cone.outerGain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ private:
|
|||||||
Vector3f position{0, 0, 0};
|
Vector3f position{0, 0, 0};
|
||||||
Vector3f direction{0, 0, -1};
|
Vector3f direction{0, 0, -1};
|
||||||
Vector3f velocity{0, 0, 0};
|
Vector3f velocity{0, 0, 0};
|
||||||
Listener::Cone cone{degrees(360), degrees(360), 1};
|
Listener::Cone cone{degrees(360.f), degrees(360.f), 1};
|
||||||
Vector3f upVector{0, 1, 0};
|
Vector3f upVector{0, 1, 0};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ struct SavedSettings
|
|||||||
float minGain{0.f};
|
float minGain{0.f};
|
||||||
float maxGain{1.f};
|
float maxGain{1.f};
|
||||||
float rollOff{1.f};
|
float rollOff{1.f};
|
||||||
float innerAngle{degrees(360).asRadians()};
|
float innerAngle{degrees(360.f).asRadians()};
|
||||||
float outerAngle{degrees(360).asRadians()};
|
float outerAngle{degrees(360.f).asRadians()};
|
||||||
float outerGain{0.f};
|
float outerGain{0.f};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,8 +88,8 @@ void SoundSource::setCone(const Cone& cone)
|
|||||||
{
|
{
|
||||||
if (auto* sound = static_cast<ma_sound*>(getSound()))
|
if (auto* sound = static_cast<ma_sound*>(getSound()))
|
||||||
ma_sound_set_cone(sound,
|
ma_sound_set_cone(sound,
|
||||||
std::clamp(cone.innerAngle, degrees(0), degrees(360)).asRadians(),
|
std::clamp(cone.innerAngle, Angle::Zero, degrees(360.f)).asRadians(),
|
||||||
std::clamp(cone.outerAngle, degrees(0), degrees(360)).asRadians(),
|
std::clamp(cone.outerAngle, Angle::Zero, degrees(360.f)).asRadians(),
|
||||||
cone.outerGain);
|
cone.outerGain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ std::size_t CircleShape::getPointCount() const
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector2f CircleShape::getPoint(std::size_t index) const
|
Vector2f CircleShape::getPoint(std::size_t index) const
|
||||||
{
|
{
|
||||||
const Angle angle = static_cast<float>(index) / static_cast<float>(m_pointCount) * degrees(360) - degrees(90);
|
const Angle angle = static_cast<float>(index) / static_cast<float>(m_pointCount) * degrees(360.f) - degrees(90.f);
|
||||||
return Vector2f(m_radius, m_radius) + Vector2f(m_radius, angle);
|
return Vector2f(m_radius, m_radius) + Vector2f(m_radius, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,11 +34,6 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
unsigned int deviceMotionEnabledCount = 0;
|
unsigned int deviceMotionEnabledCount = 0;
|
||||||
|
|
||||||
float toDegrees(float radians)
|
|
||||||
{
|
|
||||||
return sf::radians(radians).asDegrees();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,10 +140,10 @@ Vector3f SensorImpl::update()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Sensor::Type::Gyroscope:
|
case Sensor::Type::Gyroscope:
|
||||||
// Rotation rates are given in rad/s, convert to deg/s
|
// Rotation rates are given in rad/s
|
||||||
value.x = toDegrees(static_cast<float>(manager.gyroData.rotationRate.x));
|
value.x = static_cast<float>(manager.gyroData.rotationRate.x);
|
||||||
value.y = toDegrees(static_cast<float>(manager.gyroData.rotationRate.y));
|
value.y = static_cast<float>(manager.gyroData.rotationRate.y);
|
||||||
value.z = toDegrees(static_cast<float>(manager.gyroData.rotationRate.z));
|
value.z = static_cast<float>(manager.gyroData.rotationRate.z);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Sensor::Type::Magnetometer:
|
case Sensor::Type::Magnetometer:
|
||||||
@ -166,10 +161,10 @@ Vector3f SensorImpl::update()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Sensor::Type::Orientation:
|
case Sensor::Type::Orientation:
|
||||||
// Absolute rotation (Euler) angles are given in radians, convert to degrees
|
// Absolute rotation (Euler) angles are given in radians
|
||||||
value.x = toDegrees(static_cast<float>(manager.deviceMotion.attitude.yaw));
|
value.x = static_cast<float>(manager.deviceMotion.attitude.yaw);
|
||||||
value.y = toDegrees(static_cast<float>(manager.deviceMotion.attitude.pitch));
|
value.y = static_cast<float>(manager.deviceMotion.attitude.pitch);
|
||||||
value.z = toDegrees(static_cast<float>(manager.deviceMotion.attitude.roll));
|
value.z = static_cast<float>(manager.deviceMotion.attitude.roll);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -34,11 +34,11 @@ TEST_CASE("[Graphics] sf::Transformable")
|
|||||||
CHECK(transformable.getPosition() == sf::Vector2f(3, 4));
|
CHECK(transformable.getPosition() == sf::Vector2f(3, 4));
|
||||||
|
|
||||||
transformable.setRotation(sf::degrees(3.14f));
|
transformable.setRotation(sf::degrees(3.14f));
|
||||||
CHECK(transformable.getRotation() == sf::degrees(3.14f));
|
CHECK(transformable.getRotation() == Approx(sf::degrees(3.14f)));
|
||||||
transformable.setRotation(sf::degrees(540));
|
transformable.setRotation(sf::degrees(540));
|
||||||
CHECK(transformable.getRotation() == sf::degrees(180));
|
CHECK(transformable.getRotation() == Approx(sf::degrees(180)));
|
||||||
transformable.setRotation(sf::degrees(-72));
|
transformable.setRotation(sf::degrees(-72));
|
||||||
CHECK(transformable.getRotation() == sf::degrees(288));
|
CHECK(transformable.getRotation() == Approx(sf::degrees(288)));
|
||||||
|
|
||||||
transformable.setScale({5, 6});
|
transformable.setScale({5, 6});
|
||||||
CHECK(transformable.getScale() == sf::Vector2f(5, 6));
|
CHECK(transformable.getScale() == sf::Vector2f(5, 6));
|
||||||
@ -102,15 +102,15 @@ TEST_CASE("[Graphics] sf::Transformable")
|
|||||||
sf::Transformable transformable;
|
sf::Transformable transformable;
|
||||||
CHECK(transformable.getRotation() == sf::Angle::Zero);
|
CHECK(transformable.getRotation() == sf::Angle::Zero);
|
||||||
transformable.rotate(sf::degrees(15));
|
transformable.rotate(sf::degrees(15));
|
||||||
CHECK(transformable.getRotation() == sf::degrees(15));
|
CHECK(transformable.getRotation() == Approx(sf::degrees(15)));
|
||||||
transformable.rotate(sf::degrees(360));
|
transformable.rotate(sf::degrees(360));
|
||||||
CHECK(transformable.getRotation() == sf::degrees(15));
|
CHECK(transformable.getRotation() == Approx(sf::degrees(15)));
|
||||||
transformable.rotate(sf::degrees(-25));
|
transformable.rotate(sf::degrees(-25));
|
||||||
CHECK(transformable.getRotation() == sf::degrees(350));
|
CHECK(transformable.getRotation() == Approx(sf::degrees(350)));
|
||||||
transformable.rotate(sf::degrees(-720));
|
transformable.rotate(sf::degrees(-720));
|
||||||
CHECK(transformable.getRotation() == sf::degrees(350));
|
CHECK(transformable.getRotation() == Approx(sf::degrees(350)));
|
||||||
transformable.rotate(sf::degrees(-370));
|
transformable.rotate(sf::degrees(-370));
|
||||||
CHECK(transformable.getRotation() == sf::degrees(340));
|
CHECK(transformable.getRotation() == Approx(sf::degrees(340)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("scale()")
|
SECTION("scale()")
|
||||||
|
@ -76,13 +76,13 @@ TEST_CASE("[Graphics] sf::View")
|
|||||||
{
|
{
|
||||||
sf::View view;
|
sf::View view;
|
||||||
view.setRotation(sf::degrees(-345));
|
view.setRotation(sf::degrees(-345));
|
||||||
CHECK(view.getRotation() == sf::degrees(15));
|
CHECK(view.getRotation() == Approx(sf::degrees(15)));
|
||||||
CHECK(view.getTransform() ==
|
CHECK(view.getTransform() ==
|
||||||
Approx(sf::Transform(0.00193185f, 0.000517638f, -1.22474f, 0.000517638f, -0.00193185f, 0.707107f, 0, 0, 1)));
|
Approx(sf::Transform(0.00193185f, 0.000517638f, -1.22474f, 0.000517638f, -0.00193185f, 0.707107f, 0, 0, 1)));
|
||||||
CHECK(view.getInverseTransform() ==
|
CHECK(view.getInverseTransform() ==
|
||||||
Approx(sf::Transform(482.963f, 129.41f, 500, 129.41f, -482.963f, 500, 0, 0, 1)));
|
Approx(sf::Transform(482.963f, 129.41f, 500, 129.41f, -482.963f, 500, 0, 0, 1)));
|
||||||
view.setRotation(sf::degrees(400));
|
view.setRotation(sf::degrees(400));
|
||||||
CHECK(view.getRotation() == sf::degrees(40));
|
CHECK(view.getRotation() == Approx(sf::degrees(40)));
|
||||||
CHECK(view.getTransform() ==
|
CHECK(view.getTransform() ==
|
||||||
Approx(sf::Transform(0.00153209f, 0.00128558f, -1.40883f, 0.00128558f, -0.00153209f, 0.123257f, 0, 0, 1)));
|
Approx(sf::Transform(0.00153209f, 0.00128558f, -1.40883f, 0.00128558f, -0.00153209f, 0.123257f, 0, 0, 1)));
|
||||||
CHECK(view.getInverseTransform() ==
|
CHECK(view.getInverseTransform() ==
|
||||||
@ -140,7 +140,7 @@ TEST_CASE("[Graphics] sf::View")
|
|||||||
sf::View view;
|
sf::View view;
|
||||||
view.setRotation(sf::degrees(45));
|
view.setRotation(sf::degrees(45));
|
||||||
view.rotate(sf::degrees(-15));
|
view.rotate(sf::degrees(-15));
|
||||||
CHECK(view.getRotation() == sf::degrees(30));
|
CHECK(view.getRotation() == Approx(sf::degrees(30)));
|
||||||
CHECK(view.getTransform() ==
|
CHECK(view.getTransform() ==
|
||||||
Approx(sf::Transform(0.00173205f, 0.001f, -1.36603f, 0.001f, -0.00173205f, 0.366025f, 0, 0, 1)));
|
Approx(sf::Transform(0.00173205f, 0.001f, -1.36603f, 0.001f, -0.00173205f, 0.366025f, 0, 0, 1)));
|
||||||
CHECK(view.getInverseTransform() == Approx(sf::Transform(433.013f, 250, 500, 250, -433.013f, 500, 0, 0, 1)));
|
CHECK(view.getInverseTransform() == Approx(sf::Transform(433.013f, 250, 500, 250, -433.013f, 500, 0, 0, 1)));
|
||||||
|
@ -25,33 +25,33 @@ TEST_CASE("[System] sf::Angle")
|
|||||||
SECTION("wrapSigned()")
|
SECTION("wrapSigned()")
|
||||||
{
|
{
|
||||||
STATIC_CHECK(sf::Angle::Zero.wrapSigned() == sf::Angle::Zero);
|
STATIC_CHECK(sf::Angle::Zero.wrapSigned() == sf::Angle::Zero);
|
||||||
STATIC_CHECK(sf::degrees(0).wrapSigned() == sf::degrees(0));
|
CHECK(sf::degrees(0).wrapSigned() == Approx(sf::degrees(0)));
|
||||||
STATIC_CHECK(sf::degrees(1).wrapSigned() == sf::degrees(1));
|
CHECK(sf::degrees(1).wrapSigned() == Approx(sf::degrees(1)));
|
||||||
STATIC_CHECK(sf::degrees(-1).wrapSigned() == sf::degrees(-1));
|
CHECK(sf::degrees(-1).wrapSigned() == Approx(sf::degrees(-1)));
|
||||||
STATIC_CHECK(sf::degrees(90).wrapSigned() == sf::degrees(90));
|
CHECK(sf::degrees(90).wrapSigned() == Approx(sf::degrees(90)));
|
||||||
STATIC_CHECK(sf::degrees(-90).wrapSigned() == sf::degrees(-90));
|
CHECK(sf::degrees(-90).wrapSigned() == Approx(sf::degrees(-90)));
|
||||||
STATIC_CHECK(sf::degrees(180).wrapSigned() == sf::degrees(-180));
|
CHECK(sf::degrees(180).wrapSigned() == Approx(sf::degrees(-180)));
|
||||||
STATIC_CHECK(sf::degrees(-180).wrapSigned() == sf::degrees(-180));
|
CHECK(sf::degrees(-180).wrapSigned() == Approx(sf::degrees(-180)));
|
||||||
STATIC_CHECK(sf::degrees(360).wrapSigned() == sf::degrees(0));
|
CHECK(sf::degrees(360).wrapSigned() == Approx(sf::degrees(0)));
|
||||||
STATIC_CHECK(sf::degrees(-360).wrapSigned() == sf::degrees(0));
|
CHECK(sf::degrees(-360).wrapSigned() == Approx(sf::degrees(0)));
|
||||||
STATIC_CHECK(sf::degrees(720).wrapSigned() == sf::degrees(0));
|
CHECK(sf::degrees(720).wrapSigned() == Approx(sf::degrees(0)));
|
||||||
STATIC_CHECK(sf::degrees(-720).wrapSigned() == sf::degrees(0));
|
CHECK(sf::degrees(-720).wrapSigned() == Approx(sf::degrees(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("wrapUnsigned()")
|
SECTION("wrapUnsigned()")
|
||||||
{
|
{
|
||||||
STATIC_CHECK(sf::Angle::Zero.wrapUnsigned() == sf::Angle::Zero);
|
STATIC_CHECK(sf::Angle::Zero.wrapUnsigned() == sf::Angle::Zero);
|
||||||
STATIC_CHECK(sf::degrees(0).wrapUnsigned() == sf::degrees(0));
|
CHECK(sf::degrees(0).wrapUnsigned() == Approx(sf::degrees(0)));
|
||||||
STATIC_CHECK(sf::degrees(1).wrapUnsigned() == sf::degrees(1));
|
CHECK(sf::degrees(1).wrapUnsigned() == Approx(sf::degrees(1)));
|
||||||
STATIC_CHECK(sf::degrees(-1).wrapUnsigned() == sf::degrees(359));
|
CHECK(sf::degrees(-1).wrapUnsigned() == Approx(sf::degrees(359)));
|
||||||
STATIC_CHECK(sf::degrees(90).wrapUnsigned() == sf::degrees(90));
|
CHECK(sf::degrees(90).wrapUnsigned() == Approx(sf::degrees(90)));
|
||||||
STATIC_CHECK(sf::degrees(-90).wrapUnsigned() == sf::degrees(270));
|
CHECK(sf::degrees(-90).wrapUnsigned() == Approx(sf::degrees(270)));
|
||||||
STATIC_CHECK(sf::degrees(180).wrapUnsigned() == sf::degrees(180));
|
CHECK(sf::degrees(180).wrapUnsigned() == Approx(sf::degrees(180)));
|
||||||
STATIC_CHECK(sf::degrees(-180).wrapUnsigned() == sf::degrees(180));
|
CHECK(sf::degrees(-180).wrapUnsigned() == Approx(sf::degrees(180)));
|
||||||
STATIC_CHECK(sf::degrees(360).wrapUnsigned() == sf::degrees(0));
|
CHECK(sf::degrees(360).wrapUnsigned() == Approx(sf::degrees(0)));
|
||||||
STATIC_CHECK(sf::degrees(-360).wrapUnsigned() == sf::degrees(0));
|
CHECK(sf::degrees(-360).wrapUnsigned() == Approx(sf::degrees(0)));
|
||||||
STATIC_CHECK(sf::degrees(720).wrapUnsigned() == sf::degrees(0));
|
CHECK(sf::degrees(720).wrapUnsigned() == Approx(sf::degrees(0)));
|
||||||
STATIC_CHECK(sf::degrees(-720).wrapUnsigned() == sf::degrees(0));
|
CHECK(sf::degrees(-720).wrapUnsigned() == Approx(sf::degrees(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("degrees()")
|
SECTION("degrees()")
|
||||||
@ -185,7 +185,7 @@ TEST_CASE("[System] sf::Angle")
|
|||||||
{
|
{
|
||||||
sf::Angle angle = sf::degrees(-15);
|
sf::Angle angle = sf::degrees(-15);
|
||||||
angle += sf::degrees(15);
|
angle += sf::degrees(15);
|
||||||
CHECK(angle == sf::degrees(0));
|
CHECK(angle == Approx(sf::degrees(0)));
|
||||||
angle += sf::radians(10);
|
angle += sf::radians(10);
|
||||||
CHECK(angle == sf::radians(10));
|
CHECK(angle == sf::radians(10));
|
||||||
}
|
}
|
||||||
@ -202,7 +202,7 @@ TEST_CASE("[System] sf::Angle")
|
|||||||
{
|
{
|
||||||
sf::Angle angle = sf::degrees(15);
|
sf::Angle angle = sf::degrees(15);
|
||||||
angle -= sf::degrees(15);
|
angle -= sf::degrees(15);
|
||||||
CHECK(angle == sf::degrees(0));
|
CHECK(angle == Approx(sf::degrees(0)));
|
||||||
angle -= sf::radians(10);
|
angle -= sf::radians(10);
|
||||||
CHECK(angle == sf::radians(-10));
|
CHECK(angle == sf::radians(-10));
|
||||||
}
|
}
|
||||||
@ -210,19 +210,19 @@ TEST_CASE("[System] sf::Angle")
|
|||||||
SECTION("operator*")
|
SECTION("operator*")
|
||||||
{
|
{
|
||||||
STATIC_CHECK(sf::radians(0) * 10 == sf::Angle::Zero);
|
STATIC_CHECK(sf::radians(0) * 10 == sf::Angle::Zero);
|
||||||
STATIC_CHECK(sf::degrees(10) * 2.5f == sf::degrees(25));
|
CHECK(sf::degrees(10) * 2.5f == Approx(sf::degrees(25)));
|
||||||
STATIC_CHECK(sf::degrees(100) * 10.0f == sf::degrees(1000));
|
CHECK(sf::degrees(100) * 10.0f == Approx(sf::degrees(1000)));
|
||||||
|
|
||||||
STATIC_CHECK(10 * sf::radians(0) == sf::Angle::Zero);
|
STATIC_CHECK(10 * sf::radians(0) == sf::Angle::Zero);
|
||||||
STATIC_CHECK(2.5f * sf::degrees(10) == sf::degrees(25));
|
CHECK(2.5f * sf::degrees(10) == Approx(sf::degrees(25)));
|
||||||
STATIC_CHECK(10.0f * sf::degrees(100) == sf::degrees(1000));
|
CHECK(10.0f * sf::degrees(100) == Approx(sf::degrees(1000)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("operator*=")
|
SECTION("operator*=")
|
||||||
{
|
{
|
||||||
sf::Angle angle = sf::degrees(1);
|
sf::Angle angle = sf::degrees(1);
|
||||||
angle *= 10;
|
angle *= 10;
|
||||||
CHECK(angle == sf::degrees(10));
|
CHECK(angle == Approx(sf::degrees(10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("operator/")
|
SECTION("operator/")
|
||||||
@ -240,24 +240,24 @@ TEST_CASE("[System] sf::Angle")
|
|||||||
{
|
{
|
||||||
sf::Angle angle = sf::degrees(60);
|
sf::Angle angle = sf::degrees(60);
|
||||||
angle /= 5;
|
angle /= 5;
|
||||||
CHECK(angle == sf::degrees(12));
|
CHECK(angle == Approx(sf::degrees(12)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("operator%")
|
SECTION("operator%")
|
||||||
{
|
{
|
||||||
STATIC_CHECK(sf::Angle::Zero % sf::radians(0.5f) == sf::Angle::Zero);
|
STATIC_CHECK(sf::Angle::Zero % sf::radians(0.5f) == sf::Angle::Zero);
|
||||||
STATIC_CHECK(sf::radians(10) % sf::radians(1) == sf::radians(0));
|
STATIC_CHECK(sf::radians(10) % sf::radians(1) == sf::radians(0));
|
||||||
STATIC_CHECK(sf::degrees(90) % sf::degrees(30) == sf::degrees(0));
|
CHECK(sf::degrees(90) % sf::degrees(30) == Approx(sf::degrees(0)));
|
||||||
STATIC_CHECK(sf::degrees(90) % sf::degrees(40) == sf::degrees(10));
|
CHECK(sf::degrees(90) % sf::degrees(40) == Approx(sf::degrees(10)));
|
||||||
STATIC_CHECK(sf::degrees(-90) % sf::degrees(30) == sf::degrees(0));
|
CHECK(sf::degrees(-90) % sf::degrees(30) == Approx(sf::degrees(0)));
|
||||||
STATIC_CHECK(sf::degrees(-90) % sf::degrees(40) == sf::degrees(30));
|
CHECK(sf::degrees(-90) % sf::degrees(40) == Approx(sf::degrees(30)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("operator%=")
|
SECTION("operator%=")
|
||||||
{
|
{
|
||||||
sf::Angle angle = sf::degrees(59);
|
sf::Angle angle = sf::degrees(59);
|
||||||
angle %= sf::degrees(10);
|
angle %= sf::degrees(10);
|
||||||
CHECK(angle == sf::degrees(9));
|
CHECK(angle == Approx(sf::degrees(9)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("operator _deg")
|
SECTION("operator _deg")
|
||||||
|
@ -77,7 +77,7 @@ bool operator==(const sf::Vector3f& lhs, const Approx<sf::Vector3f>& rhs)
|
|||||||
|
|
||||||
bool operator==(const sf::Angle& lhs, const Approx<sf::Angle>& rhs)
|
bool operator==(const sf::Angle& lhs, const Approx<sf::Angle>& rhs)
|
||||||
{
|
{
|
||||||
return lhs.asDegrees() == Approx(rhs.value.asDegrees());
|
return lhs.asRadians() == Approx(rhs.value.asRadians());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::byte> loadIntoMemory(const std::filesystem::path& path)
|
std::vector<std::byte> loadIntoMemory(const std::filesystem::path& path)
|
||||||
|
Loading…
Reference in New Issue
Block a user