- some parts of the code to remove rotation were not removing axis/angle rotation...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 2 Feb 2011 00:40:55 +0000 (00:40 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 2 Feb 2011 00:40:55 +0000 (00:40 +0000)
- use BLI_math functions for removing rotations from objects and pose channels.
- add unit_axis_angle() to avoid setting the Y axis inline anywhere rotation needs removing.

source/blender/blenkernel/intern/action.c
source/blender/blenkernel/intern/object.c
source/blender/blenlib/BLI_math_rotation.h
source/blender/blenlib/BLI_math_vector.h
source/blender/blenlib/intern/math_rotation.c
source/blender/blenlib/intern/math_vector_inline.c
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/poseobject.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_transform.c

index 08b57ba18a3340ace3d7122de149e40cd590ea18..3bfdbdc4fc972a3bc3903010af69ef820c346faf 100644 (file)
@@ -424,7 +424,8 @@ bPoseChannel *verify_pose_channel(bPose *pose, const char *name)
        
        BLI_strncpy(chan->name, name, sizeof(chan->name));
        /* init vars to prevent math errors */
-       chan->quat[0] = chan->rotAxis[1]= 1.0f;
+       unit_qt(chan->quat);
+       unit_axis_angle(chan->rotAxis, &chan->rotAngle);
        chan->size[0] = chan->size[1] = chan->size[2] = 1.0f;
        
        chan->limitmin[0]= chan->limitmin[1]= chan->limitmin[2]= -180.0f;
@@ -1041,7 +1042,6 @@ void extract_pose_from_pose(bPose *pose, const bPose *src)
 void rest_pose(bPose *pose)
 {
        bPoseChannel *pchan;
-       int i;
        
        if (!pose)
                return;
@@ -1050,16 +1050,12 @@ void rest_pose(bPose *pose)
        memset(pose->cyclic_offset, 0, sizeof(pose->cyclic_offset));
        
        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]= pchan->rotAxis[1]= 1.0f;
-               pchan->rotAngle= 0.0f;
-               
+               zero_v3(pchan->loc);
+               zero_v3(pchan->eul);
+               unit_qt(pchan->quat);
+               unit_axis_angle(pchan->rotAxis, &pchan->rotAngle);
+               pchan->size[0]= pchan->size[1]= pchan->size[2]= 1.0f;
+
                pchan->flag &= ~(POSE_LOC|POSE_ROT|POSE_SIZE);
        }
 }
index 625410324a365719829e8b5d389b09a652a4eede..5704814e97b9d9cdae6da8caf4ff09208bf15628 100644 (file)
@@ -1013,10 +1013,13 @@ Object *add_only_object(int type, const char *name)
         * 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;
-       /* quaternions should be 1,0,0,0 by default.... */
-       ob->quat[0]= ob->dquat[0]= 1.0f;
+
+       unit_axis_angle(ob->rotAxis, &ob->rotAngle);
+       unit_axis_angle(ob->drotAxis, &ob->drotAngle);
+
+       unit_qt(ob->quat);
+       unit_qt(ob->dquat);
+
        /* rotation locks should be 4D for 4 component rotations by default... */
        ob->protectflag = OB_LOCK_ROT4D;
        
index c3efc64b9d61e8d2a44a28578eea2790d8a00848..7d0b8dfeaf36bde5252952a1f9cc8d3c7246fa40 100644 (file)
@@ -39,6 +39,7 @@ extern "C" {
 /* stored in (w, x, y, z) order                                              */
 
 /* init */
+void unit_axis_angle(float axis[3], float *angle);
 void unit_qt(float q[4]);
 void copy_qt_qt(float q[4], const float a[4]);
 
index 5a5d518940d18b42d2561878ca0045671bf4c3ea..4d8a4f2bbafa774efe01a713be57d65dfeaba769 100644 (file)
@@ -84,6 +84,7 @@ MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f);
 
 MINLINE void negate_v3(float r[3]);
 MINLINE void negate_v3_v3(float r[3], const float a[3]);
+MINLINE void negate_v4(float r[4]);
 
 MINLINE float dot_v2v2(const float a[2], const float b[2]);
 MINLINE float dot_v3v3(const float a[3], const float b[3]);
index 28a37d9675ad84a97d849eae0c19bbfba364bc6e..2038121e3f2fad85286600e2647784426266cf73 100644 (file)
 /* used to test is a quat is not normalized */
 #define QUAT_EPSILON 0.0001
 
-void unit_qt(float *q)
+/* convenience, avoids setting Y axis everywhere */
+void unit_axis_angle(float axis[3], float *angle)
+{
+       axis[0]= 0.0f;
+       axis[1]= 1.0f;
+       axis[2]= 0.0f;
+       *angle= 0.0f;
+}
+
+
+void unit_qt(float q[4])
 {
        q[0]= 1.0f;
        q[1]= q[2]= q[3]= 0.0f;
index 8f00e7b6d0c59cb432f3a0dc9ef85bc5a1cc7a48..a01455c8df061cb27b7a253961f703ec896d2068 100644 (file)
@@ -282,6 +282,14 @@ MINLINE void negate_v3_v3(float r[3], const float a[3])
        r[2]= -a[2];
 }
 
+MINLINE void negate_v4(float r[4])
+{
+       r[0]= -r[0];
+       r[1]= -r[1];
+       r[2]= -r[2];
+       r[3]= -r[3];
+}
+
 MINLINE float dot_v2v2(const float a[2], const float b[2])
 {
        return a[0]*b[0] + a[1]*b[1];
index 3a7e10698cf50f160210361d9a1ca6a9f6fc123e..5e54cbf63450891824b18ed9a087eb9d3b0b1707 100644 (file)
@@ -688,10 +688,11 @@ static int apply_armature_pose2bones_exec (bContext *C, wmOperator *op)
                }
                
                /* clear transform values for pchan */
-               pchan->loc[0]= pchan->loc[1]= pchan->loc[2]= 0.0f;
-               pchan->eul[0]= pchan->eul[1]= pchan->eul[2]= 0.0f;
-               pchan->quat[1]= pchan->quat[2]= pchan->quat[3]= 0.0f;
-               pchan->quat[0]= pchan->size[0]= pchan->size[1]= pchan->size[2]= 1.0f;
+               zero_v3(pchan->loc);
+               zero_v3(pchan->eul);
+               unit_qt(pchan->quat);
+               unit_axis_angle(pchan->rotAxis, &pchan->rotAngle);
+               pchan->size[0]= pchan->size[1]= pchan->size[2]= 1.0f;
                
                /* set anim lock */
                curbone->flag |= BONE_UNKEYED;
@@ -5049,11 +5050,10 @@ static void pchan_clear_rot(bPoseChannel *pchan)
                }
                else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
                        /* by default, make rotation of 0 radians around y-axis (roll) */
-                       pchan->rotAxis[0]=pchan->rotAxis[2]=pchan->rotAngle= 0.0f;
-                       pchan->rotAxis[1]= 1.0f;
+                       unit_axis_angle(pchan->rotAxis, &pchan->rotAngle);
                }
                else {
-                       pchan->eul[0]= pchan->eul[1]= pchan->eul[2]= 0.0f;
+                       zero_v3(pchan->eul);
                }
        }
 }
index 6c1adcb2ccb2e7eeaa03825e35ffab9050c5c573..2913f001d48197d3f71cacd40c230d9f04869d70 100644 (file)
@@ -1892,11 +1892,8 @@ static int pose_flip_quats_exec (bContext *C, wmOperator *UNUSED(op))
                /* only if bone is using quaternion rotation */
                if (pchan->rotmode == ROT_MODE_QUAT) {
                        /* quaternions have 720 degree range */
-                       pchan->quat[0]= -pchan->quat[0];
-                       pchan->quat[1]= -pchan->quat[1];
-                       pchan->quat[2]= -pchan->quat[2];
-                       pchan->quat[3]= -pchan->quat[3];
-                       
+                       negate_v4(pchan->quat);
+
                        /* tagging */
                        if (autokeyframe_cfra_can_key(scene, &ob->id)) {
                                ListBase dsources = {NULL, NULL};
index 94955e3c8150bb136d27cacfe46c961377cdb4c6..0acdc8b61fee731304b1b3283aae1f1ac22f04de 100644 (file)
@@ -1241,9 +1241,9 @@ void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
                                else if(event==2) {  /* rot */
                                        VECCOPY(base->object->rot, ob->rot);
                                        VECCOPY(base->object->drot, ob->drot);
-                                       /* Quats arnt used yet */
-                                       /*VECCOPY(base->object->quat, ob->quat);
-                                       VECCOPY(base->object->dquat, ob->dquat);*/
+
+                                       QUATCOPY(base->object->quat, ob->quat);
+                                       QUATCOPY(base->object->dquat, ob->dquat);
                                }
                                else if(event==3) {  /* size */
                                        VECCOPY(base->object->size, ob->size);
index 1af022c3c6ed04b51f03a1b366a3d3c9dad29844..024e3e8a020a735783019c6e56ad2c9daa21a18f 100644 (file)
@@ -165,24 +165,16 @@ static void object_clear_rot(Object *ob)
        }                                                // Duplicated in source/blender/editors/armature/editarmature.c
        else { 
                if (ob->rotmode == ROT_MODE_QUAT) {
-                       ob->quat[1]=ob->quat[2]=ob->quat[3]= 0.0f; 
-                       ob->quat[0]= 1.0f;
-                       
-                       ob->dquat[1]=ob->dquat[2]=ob->dquat[3]= 0.0f;
-                       ob->dquat[0]= 1.0f;
+                       unit_qt(ob->quat);
+                       unit_qt(ob->dquat);
                }
                else if (ob->rotmode == ROT_MODE_AXISANGLE) {
-                       /* by default, make rotation of 0 radians around y-axis (roll) */
-                       ob->rotAxis[0]=ob->rotAxis[2]=ob->rotAngle= 0.0f;
-                       ob->rotAxis[1]= 1.0f;
-                       
-                       ob->drotAxis[0]=ob->drotAxis[2]=ob->drotAngle= 0.0f;
-                       ob->drotAxis[1]= 1.0f;
+                       unit_axis_angle(ob->rotAxis, &ob->rotAngle);
+                       unit_axis_angle(ob->drotAxis, &ob->drotAngle);
                }
                else {
-                       ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0f;
-                       
-                       ob->drot[0]= ob->drot[1]= ob->drot[2]= 0.0f;
+                       zero_v3(ob->rot);
+                       zero_v3(ob->drot);
                }
        }
 }
@@ -532,16 +524,13 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
                        continue;
 
                if(apply_loc)
-                       ob->loc[0]= ob->loc[1]= ob->loc[2]= 0.0f;
+                       zero_v3(ob->loc);
                if(apply_scale)
                        ob->size[0]= ob->size[1]= ob->size[2]= 1.0f;
                if(apply_rot) {
-                       ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0f;
-                       ob->quat[1]= ob->quat[2]= ob->quat[3]= 0.0f;
-                       ob->rotAxis[0]= ob->rotAxis[2]= 0.0f;
-                       ob->rotAngle= 0.0f;
-                       
-                       ob->quat[0]= ob->rotAxis[1]= 1.0f;
+                       zero_v3(ob->rot);
+                       unit_qt(ob->quat);
+                       unit_axis_angle(ob->rotAxis, &ob->rotAngle);
                }
 
                where_is_object(scene, ob);