private Matrix4x4 ComputeRotation(RenderModel.Node node) { Matrix4x4 rot = new Matrix4x4(); rot.D4 = 1; var quat = node.DefaultRotation.Normalize(); float sqw = quat.W * quat.W; float sqx = quat.I * quat.I; float sqy = quat.J * quat.J; float sqz = quat.K * quat.K; rot.A1 = (sqx - sqy - sqz + sqw); rot.B2 = (-sqx + sqy - sqz + sqw); rot.C3 = (-sqx - sqy + sqz + sqw); float tmp1 = quat.I * quat.J; float tmp2 = quat.K * quat.W; rot.B1 = 2.0f * (tmp1 + tmp2); rot.A2 = 2.0f * (tmp1 - tmp2); tmp1 = quat.I * quat.K; tmp2 = quat.J * quat.W; rot.C1 = 2.0f * (tmp1 - tmp2); rot.A3 = 2.0f * (tmp1 + tmp2); tmp1 = quat.J * quat.K; tmp2 = quat.I * quat.W; rot.C2 = 2.0f * (tmp1 + tmp2); rot.B3 = 2.0f * (tmp1 - tmp2); return(rot); }
/// <summary> /// Adds a node to the model. /// </summary> /// <param name="node">The node to add.</param> /// <returns>The node index.</returns> public sbyte AddNode(RenderModel.Node node) { _model.Nodes.Add(node); // Generate runtime data _model.RuntimeNodeOrientations.Add(new RenderModel.RuntimeNodeOrientation { Translation = node.DefaultTranslation, Rotation = node.DefaultRotation, Scale = node.DefaultScale, }); return((sbyte)(_model.Nodes.Count - 1)); }
private Matrix4x4 ComputeTransform(RenderModel.Node node) { Matrix4x4 matrix_translation = new Matrix4x4(); matrix_translation.A4 = node.DefaultTranslation.X; matrix_translation.B4 = node.DefaultTranslation.Y; matrix_translation.C4 = node.DefaultTranslation.Z; matrix_translation.A1 = 1; matrix_translation.B2 = 1; matrix_translation.C3 = 1; matrix_translation.D4 = 1; Matrix4x4 matrix = ComputeRotation(node) * matrix_translation; return(matrix); }