Revision: 23135
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23135
Author:   aligorith
Date:     2009-09-12 07:06:28 +0200 (Sat, 12 Sep 2009)

Log Message:
-----------
2.5 - More work on Axis-Angle Rotations

* Added a few new methods for axis-angle conversions, and used these instead of 
manually performing those steps elsewhere
* Axis-angles to other representations now get their axes normalised to make 
sure that odd scaling doesn't occur.
* Made a few more tools work with axis-angles properly

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c
    branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h
    branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c
    branches/blender2.5/blender/source/blender/editors/animation/keyingsets.c
    branches/blender2.5/blender/source/blender/editors/armature/editarmature.c
    branches/blender2.5/blender/source/blender/editors/armature/poseobject.c
    branches/blender2.5/blender/source/blender/editors/transform/transform.c
    
branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_pose.c

Modified: 
branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c     
2009-09-12 04:03:26 UTC (rev 23134)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c     
2009-09-12 05:06:28 UTC (rev 23135)
@@ -1993,7 +1993,7 @@
        }
        else if (chan->rotmode == PCHAN_ROT_AXISANGLE) {
                /* axis-angle - stored in quaternion data, but not really that 
great for 3D-changing orientations */
-               VecRotToMat3(&chan->quat[1], chan->quat[0], rmat);
+               AxisAngleToMat3(&chan->quat[1], chan->quat[0], rmat);
        }
        else {
                /* quats are normalised before use to eliminate scaling issues 
*/

Modified: branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h     
2009-09-12 04:03:26 UTC (rev 23134)
+++ branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h     
2009-09-12 05:06:28 UTC (rev 23135)
@@ -342,8 +342,6 @@
 
 void VecUpMat3old(float *vec, float mat[][3], short axis);
 void VecUpMat3(float *vec, float mat[][3], short axis);
-void VecRotToMat3(float *vec, float phi, float mat[][3]);
-void VecRotToMat4(float *vec, float phi, float mat[][4]);
 
 void VecCopyf(float *v1, float *v2);
 int VecLen(int *v1, int *v2);
@@ -376,10 +374,23 @@
 void Vec2Copyf(float *v1, float *v2);
 void Vec2Lerpf(float *target, float *a, float *b, float t);
 
-void AxisAngleToQuat(float *q, float *axis, float angle);
-void QuatToAxisAngle(float *q, float *axis, float *angle);
+void AxisAngleToQuat(float q[4], float axis[3], float angle);
+void QuatToAxisAngle(float q[4], float axis[3], float *angle);
+void AxisAngleToEulO(float axis[3], float angle, float eul[3], short order);
+void EulOToAxisAngle(float eul[3], short order, float axis[3], float *angle);
+void AxisAngleToMat3(float axis[3], float angle, float mat[3][3]);
+void AxisAngleToMat4(float axis[3], float angle, float mat[4][4]);
+void Mat3ToAxisAngle(float mat[3][3], float axis[3], float *angle);
+void Mat4ToAxisAngle(float mat[4][4], float axis[3], float *angle);
+
+void Mat3ToVecRot(float mat[3][3], float axis[3], float *angle);
+void Mat4ToVecRot(float mat[4][4], float axis[3], float *angle);
+void VecRotToMat3(float *vec, float phi, float mat[][3]);
+void VecRotToMat4(float *vec, float phi, float mat[][4]);
+
 void RotationBetweenVectorsToQuat(float *q, float v1[3], float v2[3]);
 void vectoquat(float *vec, short axis, short upflag, float *q);
+void Mat3ToQuat_is_ok(float wmat[][3], float *q);
 
 void VecReflect(float *out, float *v1, float *v2);
 void VecBisect3(float *v, float *v1, float *v2, float *v3);
@@ -460,8 +471,6 @@
 
 short EenheidsMat(float mat[][3]);
 
-void Mat3ToQuat_is_ok(float wmat[][3], float *q);
-
 void i_ortho(float left, float right, float bottom, float top, float nearClip, 
float farClip, float matrix[][4]);
 void i_polarview(float dist, float azimuth, float incidence, float twist, 
float Vm[][4]);
 void i_translate(float Tx, float Ty, float Tz, float mat[][4]);

Modified: branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c  
2009-09-12 04:03:26 UTC (rev 23134)
+++ branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c  
2009-09-12 05:06:28 UTC (rev 23135)
@@ -3278,7 +3278,7 @@
 /* ************ AXIS ANGLE *************** */
 
 /* Axis angle to Quaternions */
-void AxisAngleToQuat(float *q, float *axis, float angle)
+void AxisAngleToQuat(float q[4], float axis[3], float angle)
 {
        float nor[3];
        float si;
@@ -3315,6 +3315,90 @@
        axis[2]= q[3] / si;
 }
 
+/* Axis Angle to Euler Rotation */
+void AxisAngleToEulO(float axis[3], float angle, float eul[3], short order)
+{
+       float q[4];
+       
+       /* use quaternions as intermediate representation for now... */
+       AxisAngleToQuat(q, axis, angle);
+       QuatToEulO(q, eul, order);
+}
+
+/* Euler Rotation to Axis Angle */
+void EulOToAxisAngle(float eul[3], short order, float axis[3], float *angle)
+{
+       float q[4];
+       
+       /* use quaternions as intermediate representation for now... */
+       EulOToQuat(eul, order, q);
+       QuatToAxisAngle(q, axis, angle);
+}
+
+/* axis angle to 3x3 matrix - safer version (normalisation of axis performed) 
*/
+void AxisAngleToMat3(float axis[3], float angle, float mat[3][3])
+{
+       float nor[3];
+       
+       /* normalise the axis first (to remove unwanted scaling) */
+       VecCopyf(nor, axis);
+       Normalize(nor);
+       
+       /* now convert this to a 3x3 matrix */
+       VecRotToMat3(nor, angle, mat);
+}
+
+/* axis angle to 4x4 matrix - safer version (normalisation of axis performed) 
*/
+void AxisAngleToMat4(float axis[3], float angle, float mat[4][4])
+{
+       float nor[3];
+       
+       /* normalise the axis first (to remove unwanted scaling) */
+       VecCopyf(nor, axis);
+       Normalize(nor);
+       
+       /* now convert this to a 4x4 matrix */
+       VecRotToMat4(nor, angle, mat);
+}
+
+/* 3x3 matrix to axis angle (alias around the other call) */
+void Mat3ToAxisAngle(float mat[3][3], float axis[3], float *angle)
+{
+       /* note different order of calling args... */
+       Mat3ToVecRot(axis, angle, mat);
+}
+
+/* 4x4 matrix to axis angle (alias around the other call) */
+void Mat4ToAxisAngle(float mat[4][4], float axis[3], float *angle)
+{
+       /* note different order of calling args... */
+       Mat4ToVecRot(axis, angle, mat);
+}
+
+/* ************ AXIS ANGLE (unchecked) *************** */
+
+/* 3x3 matrix to axis angle */
+void Mat3ToVecRot(float mat[3][3], float axis[3], float *angle)
+{
+       float q[4];
+       
+       /* use quaternions as intermediate representation */
+       // TODO: it would be nicer to go straight there...
+       Mat3ToQuat(mat, q);
+       QuatToAxisAngle(q, axis, angle);
+}
+
+/* 4x4 matrix to axis angle */
+void Mat4ToVecRot(float mat[4][4], float axis[3], float *angle)
+{
+       float q[4];
+       
+       /* use quaternions as intermediate representation */
+       // TODO: it would be nicer to go straight there...
+       Mat4ToQuat(mat, q);
+       QuatToAxisAngle(q, axis, angle);
+}
+
 /* axis angle to 3x3 matrix */
 void VecRotToMat3(float *vec, float phi, float mat[][3])
 {
@@ -3339,7 +3423,6 @@
        mat[2][0]= vz*vx*(1.0f-co)+vy*si;
        mat[2][1]= vy*vz*(1.0f-co)-vx*si;
        mat[2][2]= vz2+co*(1.0f-vz2);
-       
 }
 
 /* axis angle to 4x4 matrix */
@@ -3374,6 +3457,8 @@
        }
 }
 
+/* ************ VECTORS *************** */
+
 /* Returns a vector bisecting the angle at v2 formed by v1, v2 and v3 */
 void VecBisect3(float *out, float *v1, float *v2, float *v3)
 {

Modified: 
branches/blender2.5/blender/source/blender/editors/animation/keyingsets.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/keyingsets.c   
2009-09-12 04:03:26 UTC (rev 23134)
+++ branches/blender2.5/blender/source/blender/editors/animation/keyingsets.c   
2009-09-12 05:06:28 UTC (rev 23135)
@@ -1177,7 +1177,7 @@
                                                /* if this path is exactly 
"rotation", and the rotation mode is set to eulers,
                                                 * use "euler_rotation" instead 
so that rotations will be keyed correctly
                                                 */
-                                               if (strcmp(ksp->rna_path, 
"rotation")==0 && (cks->pchan->rotmode))
+                                               if (strcmp(ksp->rna_path, 
"rotation")==0 && (cks->pchan->rotmode > 0))
                                                        
BLI_dynstr_append(pathds, "euler_rotation");
                                                else
                                                        
BLI_dynstr_append(pathds, ksp->rna_path);

Modified: 
branches/blender2.5/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/editarmature.c  
2009-09-12 04:03:26 UTC (rev 23134)
+++ branches/blender2.5/blender/source/blender/editors/armature/editarmature.c  
2009-09-12 05:06:28 UTC (rev 23135)
@@ -4865,6 +4865,7 @@
                        
                        eul[0]= eul[1]= eul[2]= 0.0f;
                        
+                       // TODO: for 4 channel rotations, we need special flags 
for those too...
                        if (pchan->protectflag & OB_LOCK_ROTX)
                                eul[0]= oldeul[0];
                        if (pchan->protectflag & OB_LOCK_ROTY)

Modified: 
branches/blender2.5/blender/source/blender/editors/armature/poseobject.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/poseobject.c    
2009-09-12 04:03:26 UTC (rev 23134)
+++ branches/blender2.5/blender/source/blender/editors/armature/poseobject.c    
2009-09-12 05:06:28 UTC (rev 23135)
@@ -1009,12 +1009,25 @@
                                        }
                                }
                                else if (pchan->rotmode > 0) {
-                                       /* quat to euler */
-                                       QuatToEulO(chan->quat, pchan->eul, 
pchan->rotmode);
+                                       /* quat/axis-angle to euler */
+                                       if (chan->rotmode == 
PCHAN_ROT_AXISANGLE)
+                                               AxisAngleToEulO(&chan->quat[1], 
chan->quat[0], pchan->eul, pchan->rotmode);
+                                       else
+                                               QuatToEulO(chan->quat, 
pchan->eul, pchan->rotmode);
                                }
+                               else if (pchan->rotmode == PCHAN_ROT_AXISANGLE) 
{
+                                       /* quat/euler to axis angle */
+                                       if (chan->rotmode > 0)
+                                               EulOToAxisAngle(chan->eul, 
chan->rotmode, &pchan->quat[1], &pchan->quat[0]);
+                                       else    
+                                               QuatToAxisAngle(chan->quat, 
&pchan->quat[1], &pchan->quat[0]);
+                               }
                                else {
-                                       /* euler to quat */
-                                       EulOToQuat(chan->eul, chan->rotmode, 
pchan->quat);
+                                       /* euler/axis-angle to quat */
+                                       if (chan->rotmode > 0)
+                                               EulOToQuat(chan->eul, 
chan->rotmode, pchan->quat);
+                                       else
+                                               AxisAngleToQuat(pchan->quat, 
&chan->quat[1], chan->quat[0]);
                                }
                                
                                /* paste flipped pose? */
@@ -1026,6 +1039,14 @@
                                                pchan->eul[1] *= -1;
                                                pchan->eul[2] *= -1;
                                        }
+                                       else if (pchan->rotmode == 
PCHAN_ROT_AXISANGLE) {
+                                               float eul[3];
+                                               
+                                               
AxisAngleToEulO(&pchan->quat[1], pchan->quat[0], eul, EULER_ORDER_DEFAULT);
+                                               eul[1]*= -1;
+                                               eul[2]*= -1;
+                                               EulOToAxisAngle(eul, 
EULER_ORDER_DEFAULT, &pchan->quat[1], &pchan->quat[0]);
+                                       }
                                        else {
                                                float eul[3];
                                                

Modified: 
branches/blender2.5/blender/source/blender/editors/transform/transform.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/transform/transform.c    
2009-09-12 04:03:26 UTC (rev 23134)
+++ branches/blender2.5/blender/source/blender/editors/transform/transform.c    
2009-09-12 05:06:28 UTC (rev 23135)
@@ -1614,7 +1614,8 @@
 {
        /* quaternions get limited with euler... */
        /* this function only does the delta rotation */
-
+       

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to