public Quaternion(Vec3 right, Vec3 forward, Vec3 up) { float s, p, tr = right.x + forward.y + up.z; _w = 1; _v = new Vector3(); if (tr > 0) { s = (float)Math.Sqrt(tr + 1.0f); p = 0.5f / s; _w = s * 0.5f; _v.x = (forward.z - up.y) * p; _v.y = (up.x - right.z) * p; _v.z = (right.y - forward.x) * p; } else if ((right.x >= forward.y) && (right.x >= up.z)) { s = (float)Math.Sqrt(right.x - forward.y - up.z + 1.0f); p = 0.5f / s; _w = (forward.z - up.y) * p; _v.x = s * 0.5f; _v.y = (right.y + forward.x) * p; _v.z = (right.z + up.x) * p; } else if ((forward.y >= right.x) && (forward.y >= up.z)) { s = (float)Math.Sqrt(forward.y - up.z - right.x + 1.0f); p = 0.5f / s; _w = (up.x - right.z) * p; _v.x = (forward.x + right.y) * p; _v.y = s * 0.5f; _v.z = (forward.z + up.y) * p; } else if ((up.z >= right.x) && (up.z >= forward.y)) { s = (float)Math.Sqrt(up.z - right.x - forward.y + 1.0f); p = 0.5f / s; _w = (right.y - forward.x) * p; _v.x = (up.x + right.z) * p; _v.y = (up.y + forward.z) * p; _v.z = s * 0.5f; } }
public Object_Type1(BinaryReader br, string[] filePathsCollection) { filesPaths = filePathsCollection; ///////////////////////// vector1.X = (float)br.ReadDouble(); vector1.Y = (float)br.ReadDouble(); vector1.Z = (float)br.ReadDouble(); vector2.X = (float)br.ReadDouble(); vector2.Y = (float)br.ReadDouble(); vector2.Z = (float)br.ReadDouble(); br.ReadUInt32(); br.ReadUInt32(); id = br.ReadInt16(); temp1 = br.ReadUInt16(); rotMatrix34.m00 = (float)br.ReadDouble(); rotMatrix34.m01 = (float)br.ReadDouble(); rotMatrix34.m02 = (float)br.ReadDouble(); rotMatrix34.m03 = (float)br.ReadDouble(); rotMatrix34.m10 = (float)br.ReadDouble(); rotMatrix34.m11 = (float)br.ReadDouble(); rotMatrix34.m12 = (float)br.ReadDouble(); rotMatrix34.m13 = (float)br.ReadDouble(); rotMatrix34.m20 = (float)br.ReadDouble(); rotMatrix34.m21 = (float)br.ReadDouble(); rotMatrix34.m22 = (float)br.ReadDouble(); rotMatrix34.m23 = (float)br.ReadDouble(); br.BaseStream.Position = br.BaseStream.Position + 16; ////////////////////////// pos = rotMatrix34.GetTranslation(); scale = rotMatrix34.GetScale(); rotMatrix34.DescaleRotation(); quaternion = new Quaternion(rotMatrix34); //quaternion = quaternion * new Quaternion(-0.7071f, 0, 0, 0.7071f); //quaternion = new Quaternion(quaternion.x, quaternion.z, (-1)*quaternion.y, quaternion.w); //quaternion = quaternion.Normalized; rotation.x = quaternion.x; rotation.y = quaternion.y; rotation.z = quaternion.z; rotation.w = quaternion.w; path = GetFilePath(id); }