/// <summary> /// Writes a 6-byte <see cref="Vector3s"/> value to the data stream in XYZ order. This function /// expects a Y-up vector. /// </summary> /// <param name="binaryWriter">The current <see cref="BinaryWriter"/> object.</param> /// <param name="vector">The Vector to write.</param> /// <param name="storeAs">Which axis configuration the read vector should be stored as.</param> public static void WriteVector3s(this BinaryWriter binaryWriter, Vector3s vector, AxisConfiguration storeAs = AxisConfiguration.ZUp) { switch (storeAs) { case AxisConfiguration.Native: { binaryWriter.Write(vector.X); binaryWriter.Write(vector.Y); binaryWriter.Write(vector.Z); break; } case AxisConfiguration.YUp: { binaryWriter.Write(vector.X); binaryWriter.Write(vector.Y); binaryWriter.Write(vector.Z); break; } case AxisConfiguration.ZUp: { binaryWriter.Write(vector.X); binaryWriter.Write(vector.Z); binaryWriter.Write((short)(vector.Y * -1)); break; } default: throw new ArgumentOutOfRangeException(nameof(storeAs), storeAs, null); } }
/// <summary> /// Computes the cross product of two vectors, producing a new vector which /// is orthogonal to the two original vectors. /// </summary> /// <param name="start">The start vector.</param> /// <param name="end">The end vector.</param> /// <returns>The cross product of the two vectors.</returns> public static Vector3s Cross(Vector3s start, Vector3s end) { short x = (short)(start.Y * end.Z - end.Y * start.Z); short y = (short)((start.X * end.Z - end.X * start.Z) * -1); short z = (short)(start.X * end.Y - end.X * start.Y); var rtnvector = new Vector3s(x, y, z); return(rtnvector); }
/// <summary> /// Computes the dot product of two vectors. /// </summary> /// <param name="start">The start vector.</param> /// <param name="end">The end vector.</param> /// <returns>The dot product of the two vectors.</returns> public static short Dot(Vector3s start, Vector3s end) { return((short)((start.X * end.X) + (start.Y * end.Y) + (start.Z * end.Z))); }
/// <summary> /// Creates a new <see cref="Box"/> object from a top and bottom corner. /// </summary> /// <param name="inBottomCorner">The bottom corner of the box.</param> /// <param name="inTopCorner">The top corner of the box.</param> /// <returns>A new <see cref="Box"/> object.</returns> public ShortBox(Vector3s inBottomCorner, Vector3s inTopCorner) { this.BottomCorner = inBottomCorner; this.TopCorner = inTopCorner; }