Dep/g3d: Add direct yaw/pitch/roll conversions to G3D::Quat

This commit is contained in:
luis
2026-09-06 23:40:43 -03:00
parent fd8e6a2cc6
commit 041934821b
3 changed files with 25 additions and 0 deletions
+1
View File
@@ -33,3 +33,4 @@ G3D-v9.0 hotfix20.diff - 2026-05-07 - gcc build fix on windows
G3D-v9.0 hotfix21.diff - 2026-05-07 - gcc 16 warning fix G3D-v9.0 hotfix21.diff - 2026-05-07 - gcc 16 warning fix
G3D-v9.0 hotfix22.diff - 2026-09-06 - Remove unused data members from G3D::Ray G3D-v9.0 hotfix22.diff - 2026-09-06 - Remove unused data members from G3D::Ray
G3D-v9.0 hotfix23.diff - 2026-09-06 - Make G3D::Plane destructor not virtual G3D-v9.0 hotfix23.diff - 2026-09-06 - Make G3D::Plane destructor not virtual
G3D-v9.0 hotfix24.diff - 2026-09-06 - Add direct yaw/pitch/roll conversions to G3D::Quat
+4
View File
@@ -214,6 +214,10 @@ public:
void toRotationMatrix( void toRotationMatrix(
Matrix3& rot) const; Matrix3& rot) const;
static Quat fromYPRAngles(float fYAngle, float fPAngle, float fRAngle);
void toYPRAngles(float& fYAngle, float& fPAngle, float& fRAngle) const;
private: private:
/** \param maxAngle Maximum angle of rotation allowed. If a larger rotation is required, the angle of rotation applied is clamped to maxAngle */ /** \param maxAngle Maximum angle of rotation allowed. If a larger rotation is required, the angle of rotation applied is clamped to maxAngle */
Quat slerp Quat slerp
+20
View File
@@ -160,6 +160,26 @@ void Quat::toRotationMatrix(
rot = Matrix3(*this); rot = Matrix3(*this);
} }
Quat Quat::fromYPRAngles(float fYAngle, float fPAngle, float fRAngle)
{
float angles[3] = { fRAngle * 0.5f, fPAngle * 0.5f, fYAngle * 0.5f };
float s[3] = { sinf(angles[0]), sinf(angles[1]), sinf(angles[2]) };
float c[3] = { cosf(angles[0]), cosf(angles[1]), cosf(angles[2]) };
return Quat(
s[0] * c[1] * c[2] - c[0] * s[1] * s[2],
c[0] * s[1] * c[2] + s[0] * c[1] * s[2],
c[0] * c[1] * s[2] - s[0] * s[1] * c[2],
c[0] * c[1] * c[2] + s[0] * s[1] * s[2]
);
}
void Quat::toYPRAngles(float& fYAngle, float& fPAngle, float& fRAngle) const
{
fYAngle = atan2f(2.0f * (w * z + x * y), 1.0f - 2.0f * (y * y + z * z));
fPAngle = asinf(clamp(2.0f * (w * y - z * x), -1.0f, 1.0f));
fRAngle = atan2f(2.0f * (w * x + y * z), 1.0f - 2.0f * (x * x + y * y));
}
Quat Quat::slerp Quat Quat::slerp
(const Quat& _quat1, (const Quat& _quat1,