[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34616] trunk/blender/source/blender: - some parts of the code to remove rotation were not removing axis/ angle rotation (only functional change of this commit).
Campbell Barton
ideasman42 at gmail.com
Wed Feb 2 01:40:56 CET 2011
Revision: 34616
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34616
Author: campbellbarton
Date: 2011-02-02 00:40:55 +0000 (Wed, 02 Feb 2011)
Log Message:
-----------
- some parts of the code to remove rotation were not removing axis/angle rotation (only functional change of this commit).
- 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.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/action.c
trunk/blender/source/blender/blenkernel/intern/object.c
trunk/blender/source/blender/blenlib/BLI_math_rotation.h
trunk/blender/source/blender/blenlib/BLI_math_vector.h
trunk/blender/source/blender/blenlib/intern/math_rotation.c
trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
trunk/blender/source/blender/editors/armature/editarmature.c
trunk/blender/source/blender/editors/armature/poseobject.c
trunk/blender/source/blender/editors/object/object_edit.c
trunk/blender/source/blender/editors/object/object_transform.c
Modified: trunk/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/action.c 2011-02-01 23:53:54 UTC (rev 34615)
+++ trunk/blender/source/blender/blenkernel/intern/action.c 2011-02-02 00:40:55 UTC (rev 34616)
@@ -424,7 +424,8 @@
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 rest_pose(bPose *pose)
{
bPoseChannel *pchan;
- int i;
if (!pose)
return;
@@ -1050,16 +1050,12 @@
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);
}
}
Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c 2011-02-01 23:53:54 UTC (rev 34615)
+++ trunk/blender/source/blender/blenkernel/intern/object.c 2011-02-02 00:40:55 UTC (rev 34616)
@@ -1013,10 +1013,13 @@
* 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;
Modified: trunk/blender/source/blender/blenlib/BLI_math_rotation.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_rotation.h 2011-02-01 23:53:54 UTC (rev 34615)
+++ trunk/blender/source/blender/blenlib/BLI_math_rotation.h 2011-02-02 00:40:55 UTC (rev 34616)
@@ -39,6 +39,7 @@
/* 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]);
Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h 2011-02-01 23:53:54 UTC (rev 34615)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h 2011-02-02 00:40:55 UTC (rev 34616)
@@ -84,6 +84,7 @@
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]);
Modified: trunk/blender/source/blender/blenlib/intern/math_rotation.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_rotation.c 2011-02-01 23:53:54 UTC (rev 34615)
+++ trunk/blender/source/blender/blenlib/intern/math_rotation.c 2011-02-02 00:40:55 UTC (rev 34616)
@@ -34,8 +34,18 @@
/* 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;
}
Modified: trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector_inline.c 2011-02-01 23:53:54 UTC (rev 34615)
+++ trunk/blender/source/blender/blenlib/intern/math_vector_inline.c 2011-02-02 00:40:55 UTC (rev 34616)
@@ -282,6 +282,14 @@
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];
Modified: trunk/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- trunk/blender/source/blender/editors/armature/editarmature.c 2011-02-01 23:53:54 UTC (rev 34615)
+++ trunk/blender/source/blender/editors/armature/editarmature.c 2011-02-02 00:40:55 UTC (rev 34616)
@@ -688,10 +688,11 @@
}
/* 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 @@
}
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);
}
}
}
Modified: trunk/blender/source/blender/editors/armature/poseobject.c
===================================================================
--- trunk/blender/source/blender/editors/armature/poseobject.c 2011-02-01 23:53:54 UTC (rev 34615)
+++ trunk/blender/source/blender/editors/armature/poseobject.c 2011-02-02 00:40:55 UTC (rev 34616)
@@ -1892,11 +1892,8 @@
/* 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};
Modified: trunk/blender/source/blender/editors/object/object_edit.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_edit.c 2011-02-01 23:53:54 UTC (rev 34615)
+++ trunk/blender/source/blender/editors/object/object_edit.c 2011-02-02 00:40:55 UTC (rev 34616)
@@ -1241,9 +1241,9 @@
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);
Modified: trunk/blender/source/blender/editors/object/object_transform.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_transform.c 2011-02-01 23:53:54 UTC (rev 34615)
+++ trunk/blender/source/blender/editors/object/object_transform.c 2011-02-02 00:40:55 UTC (rev 34616)
@@ -165,24 +165,16 @@
} // 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 @@
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);
More information about the Bf-blender-cvs
mailing list