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-10-08 04:57:00 +0400
committerJoshua Leung <aligorith@gmail.com>2009-10-08 04:57:00 +0400
commit475ab5ceb4875eb37dd761f7a71ff569dd493395 (patch)
treea545c13c1ea502e60b4c64fb56756c8a3432ed83 /source/blender/blenkernel
parentfd511eb984a23b63b373e171666667c8213579c0 (diff)
Rotation Modes Bugfix:
Animating rotations using different rotation modes should now work more often than before. Previously, quaternion and axis-angle values were stored in the same variable in DNA, but that was causing problems with other animation curves overwriting the values and causing the rotations to not work as expected. There are still some issues, but I'll track those down later tonight
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_armature.h2
-rw-r--r--source/blender/blenkernel/intern/action.c10
-rw-r--r--source/blender/blenkernel/intern/armature.c28
-rw-r--r--source/blender/blenkernel/intern/object.c8
4 files changed, 22 insertions, 26 deletions
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index e5d0c4274b3..8f109034e3e 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -104,7 +104,7 @@ void armature_loc_pose_to_bone(struct bPoseChannel *pchan, float *inloc, float *
void armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float arm_mat[][4]);
/* Rotation Mode Conversions - Used for PoseChannels + Objects... */
-void BKE_rotMode_change_values(float quat[4], float eul[3], short oldMode, short newMode);
+void BKE_rotMode_change_values(float quat[4], float eul[3], float axis[3], float *angle, short oldMode, short newMode);
/* B-Bone support */
typedef struct Mat4 {
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 7be763eae9d..25f539a1992 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -446,7 +446,7 @@ bPoseChannel *verify_pose_channel(bPose* pose, const char* name)
strncpy(chan->name, name, 31);
/* init vars to prevent math errors */
- chan->quat[0] = 1.0f;
+ chan->quat[0] = chan->rotAxis[1]= 1.0f;
chan->size[0] = chan->size[1] = chan->size[2] = 1.0f;
chan->limitmin[0]= chan->limitmin[1]= chan->limitmin[2]= -180.0f;
@@ -607,6 +607,8 @@ static void copy_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *chan
VECCOPY(pchan->loc, chan->loc);
VECCOPY(pchan->size, chan->size);
VECCOPY(pchan->eul, chan->eul);
+ VECCOPY(pchan->rotAxis, chan->rotAxis);
+ pchan->rotAngle= chan->rotAngle;
QUATCOPY(pchan->quat, chan->quat);
pchan->rotmode= chan->rotmode;
Mat4CpyMat4(pchan->chan_mat, (float(*)[4])chan->chan_mat);
@@ -975,14 +977,16 @@ void rest_pose(bPose *pose)
memset(pose->stride_offset, 0, sizeof(pose->stride_offset));
memset(pose->cyclic_offset, 0, sizeof(pose->cyclic_offset));
- for (pchan=pose->chanbase.first; pchan; pchan= pchan->next){
+ for (pchan=pose->chanbase.first; pchan; pchan= pchan->next) {
for (i=0; i<3; i++) {
pchan->loc[i]= 0.0f;
pchan->quat[i+1]= 0.0f;
pchan->eul[i]= 0.0f;
pchan->size[i]= 1.0f;
+ pchan->rotAxis[i]= 0.0f;
}
- pchan->quat[0]= 1.0f;
+ pchan->quat[0]= pchan->rotAxis[1]= 1.0f;
+ pchan->rotAngle= 0.0f;
pchan->flag &= ~(POSE_LOC|POSE_ROT|POSE_SIZE);
}
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 6220835a620..a0abe780273 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -1285,16 +1285,14 @@ void armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float
/* 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)
+void BKE_rotMode_change_values (float quat[4], float eul[3], float *axis, float angle[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);
+ AxisAngleToEulO(axis, *angle, eul, newMode);
}
else if (oldMode == ROT_MODE_QUAT) {
/* quat to euler */
@@ -1305,11 +1303,7 @@ void BKE_rotMode_change_values (float quat[4], float eul[3], short oldMode, shor
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]);
+ AxisAngleToQuat(quat, axis, *angle);
}
else if (oldMode > 0) {
/* euler to quat */
@@ -1317,24 +1311,20 @@ void BKE_rotMode_change_values (float quat[4], float eul[3], short oldMode, shor
}
/* else { no conversion needed } */
}
- else { /* to axis-angle */
+ else if (newMode == ROT_MODE_AXISANGLE) { /* 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]);
+ QuatToAxisAngle(quat, axis, angle);
}
/* 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])) {
+ if (IS_EQ(axis[0], axis[1]) && IS_EQ(axis[1], axis[2])) {
/* for now, rotate around y-axis then (so that it simply becomes the roll) */
- quat[2]= 1.0f;
+ axis[1]= 1.0f;
}
}
}
@@ -1651,8 +1641,8 @@ void chan_calc_mat(bPoseChannel *chan)
EulOToMat3(chan->eul, chan->rotmode, rmat);
}
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);
+ /* axis-angle - not really that great for 3D-changing orientations */
+ AxisAngleToMat3(chan->rotAxis, chan->rotAngle, rmat);
}
else {
/* quats are normalised before use to eliminate scaling issues */
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index ddf7e7ff4a3..89757533fb8 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1041,6 +1041,8 @@ Object *add_object(struct Scene *scene, int type)
* but rotations default to quaternions
*/
ob->rotmode= ROT_MODE_EUL;
+ /* axis-angle must not have a 0,0,0 axis, so set y-axis as default... */
+ ob->rotAxis[1]= ob->drotAxis[1]= 1.0f;
base= scene_add_base(scene, ob);
scene_select_base(scene, base);
@@ -1602,9 +1604,9 @@ void object_rot_to_mat3(Object *ob, float mat[][3])
EulOToMat3(ob->drot, ob->rotmode, dmat);
}
else if (ob->rotmode == ROT_MODE_AXISANGLE) {
- /* axis-angle - stored in quaternion data, but not really that great for 3D-changing orientations */
- AxisAngleToMat3(&ob->quat[1], ob->quat[0], rmat);
- AxisAngleToMat3(&ob->dquat[1], ob->dquat[0], dmat);
+ /* axis-angle - not really that great for 3D-changing orientations */
+ AxisAngleToMat3(ob->rotAxis, ob->rotAngle, rmat);
+ AxisAngleToMat3(ob->drotAxis, ob->drotAngle, dmat);
}
else {
/* quats are normalised before use to eliminate scaling issues */