public void Quat4() { FQuat fq = FQuat.Euler(( Fix64 )45, ( Fix64 )(-23), ( Fix64 )(-48.88)); FQuat fq2 = FQuat.Euler(( Fix64 )23, ( Fix64 )(-78), ( Fix64 )(-132.43f)); Quat q = Quat.Euler(45, -23, -48.88f); Quat q2 = Quat.Euler(23, -78, -132.43f); FVec3 fv = new FVec3(12.5f, 9, 8); FVec3 fv2 = new FVec3(1, 0, 0); Vec3 v = new Vec3(12.5f, 9, 8); Vec3 v2 = new Vec3(1, 0, 0); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); this._output.WriteLine(fq2.ToString()); this._output.WriteLine(q2.ToString()); Fix64 fa = FQuat.Angle(fq, fq2); float a = Quat.Angle(q, q2); this._output.WriteLine(fa.ToString()); this._output.WriteLine(a.ToString()); fq = FQuat.AngleAxis(( Fix64 )(-123.324), fv); q = Quat.AngleAxis(-123.324f, v); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fa = FQuat.Dot(fq, fq2); a = Quat.Dot(q, q2); this._output.WriteLine(fa.ToString()); this._output.WriteLine(a.ToString()); fq = FQuat.FromToRotation(FVec3.Normalize(fv), fv2); q = Quat.FromToRotation(Vec3.Normalize(v), v2); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq = FQuat.Lerp(fq, fq2, ( Fix64 )0.66); q = Quat.Lerp(q, q2, 0.66f); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq = FQuat.Normalize(fq); q.Normalize(); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq.Inverse(); q = Quat.Inverse(q); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fv = FQuat.Orthogonal(fv); v = Quat.Orthogonal(v); this._output.WriteLine(fv.ToString()); this._output.WriteLine(v.ToString()); fq = FQuat.Slerp(fq, fq2, ( Fix64 )0.66); q = Quat.Slerp(q, q2, 0.66f); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq = FQuat.LookRotation(FVec3.Normalize(fv), fv2); q = Quat.LookRotation(Vec3.Normalize(v), v2); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq.ToAngleAxis(out fa, out fv); q.ToAngleAxis(out a, out v); this._output.WriteLine(fa.ToString()); this._output.WriteLine(a.ToString()); this._output.WriteLine(fv.ToString()); this._output.WriteLine(v.ToString()); fq = fq.Conjugate(); q = q.Conjugate(); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq.SetLookRotation(FVec3.Normalize(fv), fv2); q.SetLookRotation(Vec3.Normalize(v), v2); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); }
// DstPos and/or DstQuat will not be changed when KeyPos and/or KeyQuat are empty. public void GetBonePosition(float frame, float numFrames, bool loop, ref FVector dstPos, ref FQuat dstQuat) { // fast case: 1 frame only if (KeyTime.Length == 1 || numFrames == 1 || frame == 0) { if (KeyPos.Length > 0) { dstPos = KeyPos[0]; } if (KeyQuat.Length > 0) { dstQuat = KeyQuat[0]; } return; } // data for lerping int posX, rotX; // index of previous frame int posY, rotY; // index of next frame float posF, rotF; // fraction between X and Y for lerping var numTimeKeys = KeyTime.Length; var numPosKeys = KeyPos.Length; var numRotKeys = KeyQuat.Length; if (numTimeKeys > 0) { // here: KeyPos and KeyQuat sizes either equals to 1 or equals to KeyTime size Trace.Assert(numPosKeys <= 1 || numPosKeys == numTimeKeys); Trace.Assert(numRotKeys == 1 || numRotKeys == numTimeKeys); GetKeyParams(KeyTime, frame, numFrames, loop, out posX, out posY, out posF); rotX = posX; rotY = posY; rotF = posF; if (numPosKeys <= 1) { posX = posY = 0; posF = 0; } if (numRotKeys == 1) { rotX = rotY = 0; rotF = 0; } } else { // empty KeyTime array - keys are evenly spaced on a time line // note: KeyPos and KeyQuat sizes can be different if (KeyPosTime.Length > 0) { GetKeyParams(KeyPosTime, frame, numFrames, loop, out posX, out posY, out posF); } else if (numPosKeys > 1) { var position = frame / numFrames * numPosKeys; posX = position.FloorToInt(); posF = position - posX; posY = posX + 1; if (posY >= numPosKeys) { if (!loop) { posY = numPosKeys - 1; posF = 0; } else { posY = 0; } } } else { posX = posY = 0; posF = 0; } if (KeyQuatTime.Length > 0) { GetKeyParams(KeyQuatTime, frame, numFrames, loop, out rotX, out rotY, out rotF); } else if (numRotKeys > 1) { var Position = frame / numFrames * numRotKeys; rotX = Position.FloorToInt(); rotF = Position - rotX; rotY = rotX + 1; if (rotY >= numRotKeys) { if (!loop) { rotY = numRotKeys - 1; rotF = 0; } else { rotY = 0; } } } else { rotX = rotY = 0; rotF = 0; } } // get position if (posF > 0) { dstPos = MathUtils.Lerp(KeyPos[posX], KeyPos[posY], posF); } else if (numPosKeys > 0) // do not change DstPos when no keys { dstPos = KeyPos[posX]; } // get orientation if (rotF > 0) { dstQuat = FQuat.Slerp(KeyQuat[rotX], KeyQuat[rotY], rotF); } else if (numRotKeys > 0) // do not change DstQuat when no keys { dstQuat = KeyQuat[rotX]; } }