/// <summary> /// Reads a BXDQuaternion with the given XmlReader and returns the reading. /// </summary> /// <param name="reader"></param> /// <returns></returns> private static BXDQuaternion ReadBXDQuaternion_2_2(XmlReader reader) { BXDQuaternion quat = new BXDQuaternion(); foreach (string name in IOUtilities.AllElements(reader)) { switch (name) { case "X": // Assign the X value. quat.X = float.Parse(reader.ReadElementContentAsString()); break; case "Y": // Assign the Y value. quat.Y = float.Parse(reader.ReadElementContentAsString()); break; case "Z": // Assign the Z value. quat.Z = float.Parse(reader.ReadElementContentAsString()); break; case "W": // Assign the W value. quat.W = float.Parse(reader.ReadElementContentAsString()); break; } } return(quat); }
/// <summary> /// Constructs a new instance of the FieldNode class. /// </summary> /// <param name="nodeID"></param> /// <param name="physicsGroupID"></param> public FieldNode(string nodeID, string physicsGroupID = BXDFProperties.BXDF_DEFAULT_NAME) { NodeID = nodeID; Position = new BXDVector3(); Rotation = new BXDQuaternion(); SubMeshID = -1; CollisionMeshID = -1; PropertySetID = physicsGroupID; }
/// <summary> /// Writes the BXDQuaternion to an XML file with the given XmlWriter. /// </summary> /// <param name="writer"></param> /// <param name="quat"></param> /// <param name="id"></param> private static void WriteBXDQuaternion(XmlWriter writer, BXDQuaternion quat, string id) { writer.WriteStartElement("BXDQuaternion"); writer.WriteAttributeString("ID", id); writer.WriteElementString("X", quat.X.ToString("F4")); writer.WriteElementString("Y", quat.Y.ToString("F4")); writer.WriteElementString("Z", quat.Z.ToString("F4")); writer.WriteElementString("W", quat.W.ToString("F4")); writer.WriteEndElement(); }
/// <summary> /// Get a BXDQuaternion from the given Inventor.Matrix. /// </summary> /// <param name="m"></param> /// <returns></returns> public static BXDQuaternion QuaternionFromMatrix(Matrix m) { BXDQuaternion q = new BXDQuaternion(); double tr = m.Cell[1, 1] + m.Cell[2, 2] + m.Cell[3, 3]; double s; if (tr > 0) { s = Math.Sqrt(tr + 1.0) * 2; q.W = (float)(0.25 * s); q.X = (float)((m.Cell[3, 2] - m.Cell[2, 3]) / s); q.Y = (float)((m.Cell[1, 3] - m.Cell[3, 1]) / s); q.Z = (float)((m.Cell[2, 1] - m.Cell[1, 2]) / s); } else if ((m.Cell[1, 1] > m.Cell[2, 2]) && (m.Cell[1, 1] > m.Cell[3, 3])) { s = Math.Sqrt(1.0 + m.Cell[1, 1] - m.Cell[2, 2] - m.Cell[3, 3]) * 2; q.W = (float)((m.Cell[3, 2] - m.Cell[2, 3]) / s); q.X = (float)(0.25 * s); q.Y = (float)((m.Cell[1, 2] + m.Cell[2, 1]) / s); q.Z = (float)((m.Cell[1, 3] + m.Cell[3, 1]) / s); } else if (m.Cell[2, 2] > m.Cell[3, 3]) { s = Math.Sqrt(1.0 + m.Cell[2, 2] - m.Cell[1, 1] - m.Cell[3, 3]) * 2; q.W = (float)((m.Cell[1, 3] - m.Cell[3, 1]) / s); q.X = (float)((m.Cell[1, 2] + m.Cell[2, 1]) / s); q.Y = (float)(0.25 * s); q.Z = (float)((m.Cell[2, 3] + m.Cell[3, 2]) / s); } else { s = Math.Sqrt(1.0 + m.Cell[3, 3] - m.Cell[1, 1] - m.Cell[2, 2]) * 2; q.W = (float)((m.Cell[2, 1] - m.Cell[1, 2]) / s); q.X = (float)((m.Cell[1, 3] + m.Cell[3, 1]) / s); q.Y = (float)((m.Cell[2, 3] + m.Cell[3, 2]) / s); q.Z = (float)(0.25 * s); } return(q); }
/// <summary> /// BXD Quaternion -> OpenGL Quaternion /// </summary> /// <param name="val"></param> /// <returns></returns> public static Quaternion Convert(this BXDQuaternion val) { return(new Quaternion(val.X, val.Y, val.Z, val.W)); }