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:
authorCampbell Barton <ideasman42@gmail.com>2011-02-02 03:40:55 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-02-02 03:40:55 +0300
commit95df65f1b55d311be4171f71bb106f9c7d193a79 (patch)
tree9ceafdf50ae1afbb903722ae4979d85ad7dd300f
parent19efa4301a5f2545eddfd4e5e56943d9a1d9f5cf (diff)
- 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.
-rw-r--r--source/blender/blenkernel/intern/action.c20
-rw-r--r--source/blender/blenkernel/intern/object.c11
-rw-r--r--source/blender/blenlib/BLI_math_rotation.h1
-rw-r--r--source/blender/blenlib/BLI_math_vector.h1
-rw-r--r--source/blender/blenlib/intern/math_rotation.c12
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c8
-rw-r--r--source/blender/editors/armature/editarmature.c14
-rw-r--r--source/blender/editors/armature/poseobject.c7
-rw-r--r--source/blender/editors/object/object_edit.c6
-rw-r--r--source/blender/editors/object/object_transform.c31
10 files changed, 58 insertions, 53 deletions
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 08b57ba18a3..3bfdbdc4fc9 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -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);
}
}
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 625410324a3..5704814e97b 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -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;
diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h
index c3efc64b9d6..7d0b8dfeaf3 100644
--- a/source/blender/blenlib/BLI_math_rotation.h
+++ b/source/blender/blenlib/BLI_math_rotation.h
@@ -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]);
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 5a5d518940d..4d8a4f2bbaf 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -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]);
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 28a37d9675a..2038121e3f2 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -34,7 +34,17 @@
/* 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;
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 8f00e7b6d0c..a01455c8df0 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -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];
diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c
index 3a7e10698cf..5e54cbf6345 100644
--- a/source/blender/editors/armature/editarmature.c
+++ b/source/blender/editors/armature/editarmature.c
@@ -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);
}
}
}
diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c
index 6c1adcb2ccb..2913f001d48 100644
--- a/source/blender/editors/armature/poseobject.c
+++ b/source/blender/editors/armature/poseobject.c
@@ -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};
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 94955e3c815..0acdc8b61fe 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -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);
diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c
index 1af022c3c6e..024e3e8a020 100644
--- a/source/blender/editors/object/object_transform.c
+++ b/source/blender/editors/object/object_transform.c
@@ -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);