public static OpenToolkit.Mathematics.Quaternion ToOtk(this Assimp.Quaternion q) { var ret = new OpenToolkit.Mathematics.Quaternion(); ret.X = q.X; ret.Y = q.Y; ret.Z = q.Z; ret.W = q.W; return(ret); }
private static Assimp.Quaternion Interpolate(Assimp.Quaternion pStart, Assimp.Quaternion pEnd, float pFactor) { Assimp.Quaternion pOut; // calc cosine theta float cosom = pStart.X * pEnd.X + pStart.Y * pEnd.Y + pStart.Z * pEnd.Z + pStart.W * pEnd.W; // adjust signs (if necessary) Assimp.Quaternion end = pEnd; if (cosom < 0.0f) { cosom = -cosom; end.X = -end.X; // Reverse all signs end.Y = -end.Y; end.Z = -end.Z; end.W = -end.W; } // Calculate coefficients float sclp, sclq; if (((1.0f) - cosom) > (0.0001f)) // 0.0001 -> some epsillon { // Standard case (slerp) float omega, sinom; omega = (float)Math.Acos(cosom); // extract theta from dot product's cos theta sinom = (float)Math.Sin(omega); sclp = (float)Math.Sin(((1.0f) - pFactor) * omega) / sinom; sclq = (float)Math.Sin(pFactor * omega) / sinom; } else { // Very close, do linear interp (because it's faster) sclp = (1.0f) - pFactor; sclq = pFactor; } pOut.X = sclp * pStart.X + sclq * end.X; pOut.Y = sclp * pStart.Y + sclq * end.Y; pOut.Z = sclp * pStart.Z + sclq * end.Z; pOut.W = sclp * pStart.W + sclq * end.W; return(pOut); }
public static Assimp.Quaternion CalcInterpolatedRotation(float animationTime, Assimp.NodeAnimationChannel nodeAnim) { if (nodeAnim.RotationKeyCount == 1) { return(nodeAnim.RotationKeys[0].Value); } Assimp.Quaternion result; int index = FindRotation(animationTime, nodeAnim); int nextIndex = (index + 1); float deltaTime = (float)(nodeAnim.RotationKeys[nextIndex].Time - nodeAnim.RotationKeys[index].Time); float factor = (animationTime - (float)nodeAnim.RotationKeys[index].Time) / deltaTime; Assimp.Quaternion start = nodeAnim.RotationKeys[index].Value; Assimp.Quaternion end = nodeAnim.RotationKeys[nextIndex].Value; result = Interpolate(start, end, factor); result.Normalize(); return(result); }
private static void ReadNodeHeirarchy(float animationTime, Assimp.Node node, Assimp.Animation animation, mat4 parentTransform, AllBoneInfos allBones) { string nodeName = node.Name; mat4 nodeTransform = node.Transform.ToMat4(); Assimp.NodeAnimationChannel nodeAnim = FineNodeAnim(animation, nodeName); if (nodeAnim != null) { mat4 mat = mat4.identity(); // Interpolate scaling and generate scaling transformation matrix Assimp.Vector3D Scaling = CalcInterpolatedScaling(animationTime, nodeAnim); mat4 ScalingM = glm.scale(mat, new vec3(Scaling.X, Scaling.Y, Scaling.Z)); // Interpolate rotation and generate rotation transformation matrix Assimp.Quaternion RotationQ = CalcInterpolatedRotation(animationTime, nodeAnim); mat4 RotationM = new Assimp.Matrix4x4(RotationQ.GetMatrix()).ToMat4(); // Interpolate translation and generate translation transformation matrix Assimp.Vector3D Translation = CalcInterpolatedPosition(animationTime, nodeAnim); mat4 TranslationM = glm.translate(mat4.identity(), new vec3(Translation.X, Translation.Y, Translation.Z)); // Combine the above transformations nodeTransform = TranslationM * RotationM * ScalingM; } mat4 transform = parentTransform * nodeTransform; if (allBones.nameIndexDict.ContainsKey(nodeName)) { uint BoneIndex = allBones.nameIndexDict[nodeName]; allBones.boneInfos[BoneIndex].finalTransformation = transform; } for (int i = 0; i < node.ChildCount; i++) { ReadNodeHeirarchy(animationTime, node.Children[i], animation, transform, allBones); } }
private static Assimp.Quaternion CalcInterpolatedRotation(float animationTime, Assimp.NodeAnimationChannel nodeAnim) { Assimp.Quaternion Out; // we need at least two values to interpolate... if (nodeAnim.RotationKeyCount == 1) { Out = nodeAnim.RotationKeys[0].Value; return(Out); } uint RotationIndex = FindRotation(animationTime, nodeAnim); uint NextRotationIndex = (RotationIndex + 1); //assert(NextRotationIndex < nodeAnim.RotationKeyCount); float DeltaTime = (float)(nodeAnim.RotationKeys[NextRotationIndex].Time - nodeAnim.RotationKeys[RotationIndex].Time); float Factor = (animationTime - (float)nodeAnim.RotationKeys[RotationIndex].Time) / DeltaTime; //assert(Factor >= 0.0f && Factor <= 1.0f); Assimp.Quaternion StartRotationQ = nodeAnim.RotationKeys[RotationIndex].Value; Assimp.Quaternion EndRotationQ = nodeAnim.RotationKeys[NextRotationIndex].Value; Out = Interpolate(StartRotationQ, EndRotationQ, Factor); Out.Normalize(); return(Out); }
private static Assimp.Quaternion CalcInterpolatedRotation(float animationTime, Assimp.NodeAnimationChannel nodeAnim) { Assimp.Quaternion result; // we need at least two values to interpolate... if (nodeAnim.RotationKeyCount == 1) { result = nodeAnim.RotationKeys[0].Value; return(result); } uint index = FindRotation(animationTime, nodeAnim); uint nextIndex = (index + 1); //assert(NextRotationIndex < nodeAnim.RotationKeyCount); float deltaTime = (float)(nodeAnim.RotationKeys[nextIndex].Time - nodeAnim.RotationKeys[index].Time); float factor = (animationTime - (float)nodeAnim.RotationKeys[index].Time) / deltaTime; //assert(Factor >= 0.0f && Factor <= 1.0f); Assimp.Quaternion start = nodeAnim.RotationKeys[index].Value; Assimp.Quaternion end = nodeAnim.RotationKeys[nextIndex].Value; result = Interpolate(start, end, factor); result.Normalize(); return(result); }
public static Assimp.Quaternion Interpolate(Assimp.Quaternion start, Assimp.Quaternion end, float factor) { Assimp.Quaternion result; float cosom = start.X * end.X + start.Y * end.Y + start.Z * end.Z + start.W * end.W; if (cosom < 0.0f) { cosom = -cosom; end.X = -end.X; // Reverse all signs end.Y = -end.Y; end.Z = -end.Z; end.W = -end.W; } float sclp, sclq; if (((1.0f) - cosom) > (0.0001f)) // 0.0001 -> some epsillon { float omega, sinom; omega = (float)Math.Acos(cosom); // extract theta from dot product's cos theta sinom = (float)Math.Sin(omega); sclp = (float)Math.Sin(((1.0f) - factor) * omega) / sinom; sclq = (float)Math.Sin(factor * omega) / sinom; } else { sclp = (1.0f) - factor; sclq = factor; } result.X = sclp * start.X + sclq * end.X; result.Y = sclp * start.Y + sclq * end.Y; result.Z = sclp * start.Z + sclq * end.Z; result.W = sclp * start.W + sclq * end.W; return(result); }
private static Quaternion ToQuaternion(Assimp.Quaternion quaternion) { return(Unsafe.As <Assimp.Quaternion, Quaternion>(ref quaternion)); }
private static Quaternion toDX(Assimp.Quaternion q) { return(new Quaternion(q.X, q.Y, q.Z, q.W)); }
public static Quaternion FromAssimp(Assimp.Quaternion value) { return(new Quaternion(value.X, value.Y, value.Z, value.W)); }
public static XNAQ ToXna(this Assimp.Quaternion q) { return(new XNAQ(q.X, q.Y, q.Z, q.W)); }
public static OpenTK.Quaternion ToGL(this Assimp.Quaternion quaternion) { return(OpenTK.Quaternion.FromMatrix(quaternion.GetMatrix().ToGL())); }
private Quaternion ConvertQuaternion(Assimp.Quaternion quat) { return(new Quaternion(quat.X, quat.Y, quat.Z, quat.W)); }
internal static SharpDX.Quaternion ToQuat(this Assimp.Quaternion q) { return(new SharpDX.Quaternion(q.X, q.Y, q.Z, q.W)); }
public static Quaternion ToSystemQuaternion(this Assimp.Quaternion quat) { return(new Quaternion(quat.X, quat.Y, quat.Z, quat.W)); }