From 2bd93c5da8d5193b9d98630bb1c284991bd3da37 Mon Sep 17 00:00:00 2001 From: spog Date: Sun, 11 Jun 2006 12:45:44 +0000 Subject: [PATCH] fixed arbitrary rotation git-svn-id: https://zerowing.idsoftware.com/svn/radiant/GtkRadiant/trunk@83 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- CHANGES | 4 ++++ libs/math/quaternion.h | 18 ++++++++++++++++++ radiant/select.cpp | 21 +++++++++++++++++---- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 1a4295d8..86d43918 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,10 @@ This is the changelog for developers, != changelog for the end user that we distribute with the binaries. (see changelog) +11/06/2006 +SPoG +- Fixed arbitrary rotation X and Y axes appearing to be transposed. + 04/06/2006 SPoG - Fixed crash when deleting items from Build menu. diff --git a/libs/math/quaternion.h b/libs/math/quaternion.h index 7bd42cb1..d91ad62a 100644 --- a/libs/math/quaternion.h +++ b/libs/math/quaternion.h @@ -60,6 +60,24 @@ inline Quaternion quaternion_for_axisangle(const Vector3& axis, double angle) return Quaternion(axis[0] * sa, axis[1] * sa, axis[2] * sa, static_cast(cos(angle))); } +inline Quaternion quaternion_for_x(double angle) +{ + angle *= 0.5; + return Quaternion(static_cast(sin(angle)), 0, 0, static_cast(cos(angle))); +} + +inline Quaternion quaternion_for_y(double angle) +{ + angle *= 0.5; + return Quaternion(0, static_cast(sin(angle)), 0, static_cast(cos(angle))); +} + +inline Quaternion quaternion_for_z(double angle) +{ + angle *= 0.5; + return Quaternion(0, 0, static_cast(sin(angle)), static_cast(cos(angle))); +} + inline Quaternion quaternion_inverse(const Quaternion& quaternion) { return Quaternion(vector3_negated(vector4_to_vector3(quaternion)), quaternion[3]); diff --git a/radiant/select.cpp b/radiant/select.cpp index 9709c179..496d96a4 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -756,8 +756,20 @@ void Selection_destroy() #include #include + inline Quaternion quaternion_for_euler_xyz_degrees(const Vector3& eulerXYZ) { +#if 0 + return quaternion_for_matrix4_rotation(matrix4_rotation_for_euler_xyz_degrees(eulerXYZ)); +#elif 0 + return quaternion_multiplied_by_quaternion( + quaternion_multiplied_by_quaternion( + quaternion_for_z(degrees_to_radians(eulerXYZ[2])), + quaternion_for_y(degrees_to_radians(eulerXYZ[1])) + ), + quaternion_for_x(degrees_to_radians(eulerXYZ[0])) + ); +#elif 1 double cx = cos(degrees_to_radians(eulerXYZ[0] * 0.5)); double sx = sin(degrees_to_radians(eulerXYZ[0] * 0.5)); double cy = cos(degrees_to_radians(eulerXYZ[1] * 0.5)); @@ -766,11 +778,12 @@ inline Quaternion quaternion_for_euler_xyz_degrees(const Vector3& eulerXYZ) double sz = sin(degrees_to_radians(eulerXYZ[2] * 0.5)); return Quaternion( - static_cast(cx * sy * cz - sx * cy * sz), - static_cast(cx * sy * sz + sx * cy * cz), - static_cast(cx * cy * sz - sx * sy * cz), - static_cast(cx * cy * cz + sx * sy * sz) + cz * cy * sx - sz * sy * cx, + cz * sy * cx + sz * cy * sx, + sz * cy * cx - cz * sy * sx, + cz * cy * cx + sz * sy * sx ); +#endif } struct RotateDialog -- 2.39.2