- 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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user