[Bf-python] quat multiplication

models at paposo.com models at paposo.com
Thu Nov 27 16:33:54 CET 2003


This is from arthrib.c:

void QuatMul(float *q, float *q1, float *q2)
{
 float t0,t1,t2;

 t0=   q1[0]*q2[0]-q1[1]*q2[1]-q1[2]*q2[2]-q1[3]*q2[3];
 t1=   q1[0]*q2[1]+q1[1]*q2[0]+q1[2]*q2[3]-q1[3]*q2[2];
 t2=   q1[0]*q2[2]+q1[2]*q2[0]+q1[3]*q2[1]-q1[1]*q2[3];
 q[3]= q1[0]*q2[3]+q1[3]*q2[0]+q1[1]*q2[2]-q1[2]*q2[1];
 q[0]=t0; 
 q[1]=t1; 
 q[2]=t2;
}

this is from a graphics library called cal3d:

void CalQuaternion::operator*=(const CalQuaternion& q)
{
  float qx, qy, qz, qw;
  qx = x;
  qy = y;
  qz = z;
  qw = w;

  x = qw * q.x + qx * q.w + qy * q.z - qz * q.y;
  y = qw * q.y - qx * q.z + qy * q.w + qz * q.x;
  z = qw * q.z + qx * q.y - qy * q.x + qz * q.w;
  w = qw * q.w - qx * q.x - qy * q.y - qz * q.z;
}

They output the quats in reverse from each other.
So if you have:
q1 = [1,1,1,1]
q2 = [2,2,2,2]

when you multiply the quats, blender gives:
q3 = [-4,4,4,4] (w,z,y,x)
and cal3d gives:
q3 = [4,4,4,-4] (x,y,z,w)

Any ideas as to this?



More information about the Bf-python mailing list