Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2009-09-28 14:19:20 +0400
committerJoshua Leung <aligorith@gmail.com>2009-09-28 14:19:20 +0400
commit7d2fd5449e21b533f9aeb6f5f79af5e2396a8063 (patch)
treed146b4680f3123a112238bffb875fd632b1e4931 /source/blender/blenkernel/intern/armature.c
parent981afef08e051d00e955526c1c79b8dd01d4bdd5 (diff)
Durian Feature Request: Rotation Modes for Objects
This (biggish) commit generalises the rotation modes functionality added for Bones, allowing Objects to use the various Euler Rotation orders, Axis-Angle, and Quaternion rotation representations. I've also cleaned up the nomenclature of the rotation-related settings so that the naming styles are more consistent with each other. Unfortunately, this will break all files involving object or bone rotation animation made in 2.5 versions (2.4x will still get correctly converted). General Notes: * By default, Objects still default to using Eulers, while Bones will use Quaternions by default still. * I've fixed all areas that I'm currently aware of to work with these changes. However, there are probably a few places where I've missed a few changes (i.e. auto-keyframing will need attention later). * Removed the old "IPO-Keys" stuff from Transform code. I'm unlikely to restore this in the near future, and trying to fix that to include support for this commit would have been too much work.
Diffstat (limited to 'source/blender/blenkernel/intern/armature.c')
-rw-r--r--source/blender/blenkernel/intern/armature.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index b2368451414..6220835a620 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -1279,6 +1279,65 @@ void armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float
Mat4MulMat4(delta_mat, pose_mat, imat);
}
+/* **************** Rotation Mode Conversions ****************************** */
+/* Used for Objects and Pose Channels, since both can have multiple rotation representations */
+
+/* Called from RNA when rotation mode changes
+ * - the result should be that the rotations given in the provided pointers have had conversions
+ * applied (as appropriate), such that the rotation of the element hasn't 'visually' changed
+ *
+ * - as in SDNA data, quat is used to store quaternions AND axis-angle rotations...
+ */
+void BKE_rotMode_change_values (float quat[4], float eul[3], short oldMode, short newMode)
+{
+ /* check if any change - if so, need to convert data */
+ if (newMode > 0) { /* to euler */
+ if (oldMode == ROT_MODE_AXISANGLE) {
+ /* axis-angle to euler */
+ AxisAngleToEulO(&quat[1], quat[0], eul, newMode);
+ }
+ else if (oldMode == ROT_MODE_QUAT) {
+ /* quat to euler */
+ QuatToEulO(quat, eul, newMode);
+ }
+ /* else { no conversion needed } */
+ }
+ else if (newMode == ROT_MODE_QUAT) { /* to quat */
+ if (oldMode == ROT_MODE_AXISANGLE) {
+ /* axis angle to quat */
+ float q[4];
+
+ /* copy to temp var first, since quats and axis-angle are stored in same place */
+ QuatCopy(q, quat);
+ AxisAngleToQuat(q, &quat[1], quat[0]);
+ }
+ else if (oldMode > 0) {
+ /* euler to quat */
+ EulOToQuat(eul, oldMode, quat);
+ }
+ /* else { no conversion needed } */
+ }
+ else { /* to axis-angle */
+ if (oldMode > 0) {
+ /* euler to axis angle */
+ EulOToAxisAngle(eul, oldMode, &quat[1], &quat[0]);
+ }
+ else if (oldMode == ROT_MODE_QUAT) {
+ /* quat to axis angle */
+ float q[4];
+
+ /* copy to temp var first, since quats and axis-angle are stored in same place */
+ QuatCopy(q, quat);
+ QuatToAxisAngle(q, &quat[1], &quat[0]);
+ }
+
+ /* when converting to axis-angle, we need a special exception for the case when there is no axis */
+ if (IS_EQ(quat[1], quat[2]) && IS_EQ(quat[2], quat[3])) {
+ /* for now, rotate around y-axis then (so that it simply becomes the roll) */
+ quat[2]= 1.0f;
+ }
+ }
+}
/* **************** The new & simple (but OK!) armature evaluation ********* */
@@ -1591,7 +1650,7 @@ void chan_calc_mat(bPoseChannel *chan)
/* euler rotations (will cause gimble lock, but this can be alleviated a bit with rotation orders) */
EulOToMat3(chan->eul, chan->rotmode, rmat);
}
- else if (chan->rotmode == PCHAN_ROT_AXISANGLE) {
+ else if (chan->rotmode == ROT_MODE_AXISANGLE) {
/* axis-angle - stored in quaternion data, but not really that great for 3D-changing orientations */
AxisAngleToMat3(&chan->quat[1], chan->quat[0], rmat);
}