56 inline static bool interpolate(
float currentAngle,
float targetAngle,
float timePassedSeconds,
float degreesPerSeconds,
float& interpolatedAngle) {
57 currentAngle = Math::absmod(currentAngle, 360.0f);
58 targetAngle = Math::absmod(targetAngle, 360.0f);
59 auto targetRotationAngleA = targetAngle;
60 auto targetRotationAngleB = targetAngle - 360.0f;
61 auto targetRotationAngleC = targetAngle + 360.0f;
62 if (Math::abs(targetRotationAngleA - currentAngle) < Math::abs(targetRotationAngleB - currentAngle) &&
63 Math::abs(targetRotationAngleA - currentAngle) < Math::abs(targetRotationAngleC - currentAngle)) {
64 targetAngle = targetRotationAngleA;
66 if (Math::abs(targetRotationAngleB - currentAngle) < Math::abs(targetRotationAngleA - currentAngle) &&
67 Math::abs(targetRotationAngleB - currentAngle) < Math::abs(targetRotationAngleC - currentAngle)) {
68 targetAngle = targetRotationAngleB;
70 if (Math::abs(targetRotationAngleC - currentAngle) < Math::abs(targetRotationAngleA - currentAngle) &&
71 Math::abs(targetRotationAngleC - currentAngle) < Math::abs(targetRotationAngleB - currentAngle)) {
72 targetAngle = targetRotationAngleC;
74 if (Math::abs(Math::absmod(currentAngle, 360.0f) - Math::absmod(targetAngle, 360.0f)) < 0.49f) {
75 interpolatedAngle = targetAngle;
78 auto rotationAdd = timePassedSeconds * degreesPerSeconds * Math::sign(targetAngle - currentAngle);
79 if (currentAngle < targetAngle && currentAngle + rotationAdd > targetAngle) {
80 currentAngle = targetAngle;
82 if (currentAngle > targetAngle && currentAngle + rotationAdd < targetAngle) {
83 currentAngle = targetAngle;
85 currentAngle+= rotationAdd;
87 interpolatedAngle = currentAngle;
132 this->axis = rotation.
axis;
133 this->angle = rotation.
angle;
145 auto angle = 2.0f * Math::acos(q[3]) / 3.1415927f * 180.0f;
148 auto s = Math::sqrt(1.0f - q[3] * q[3]);
152 axis.
set(q[0] / s, q[1] / s, q[2] / s);
static const Rotation fromQuaternion(const Quaternion &quaternion)
Returns rotation from a quaternion.
void setAngle(const float angle)
const Quaternion & getQuaternion() const
void fromRotation(const Rotation &rotation)
From rotation.
static STATIC_DLL_IMPEXT Vector3 Y_AXIS
Rotation(const Vector3 &axis, float angle)
Public constructor.
static bool interpolate(float currentAngle, float targetAngle, float timePassedSeconds, float degreesPerSeconds, float &interpolatedAngle)
Interpolate from given rotation to target rotation taking time passed in seconds and rotation degrees...
Rotation()
Public constructor.
void setAxis(const Vector3 &axis)
Set axis.
const Vector3 & getAxis() const
void update()
Computes rotation matrix.
const float getAngle() const
static STATIC_DLL_IMPEXT Vector3 X_AXIS
static STATIC_DLL_IMPEXT Vector3 Z_AXIS
Quaternion class representing quaternion mathematical structure and operations with x,...
Quaternion & identity()
Creates identity quaternion.
Quaternion & rotate(const Vector3 &axis, float angle)
Creates rotation quaternion.
Quaternion clone() const
Clones this quaternion.
Quaternion & normalize()
Normalizes this quaternion.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
#define STATIC_DLL_IMPEXT