mirror of
https://github.com/celisej567/LibBSP.git
synced 2026-01-06 14:10:55 +03:00
Moderate refactor.
Removes "Source" from in front of source engine structures. Spells out full names of structures in class names. Adds punctuation to all documentation comments and fixes some mistakes. Adds some missing documentation comments.
This commit is contained in:
@@ -56,17 +56,17 @@
|
||||
<Compile Include="Source\Structs\BSP\Face.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Leaf.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Lumps\GameLump.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Lumps\SourceStaticProps.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Lumps\StaticProps.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Lumps\Textures.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Model.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Node.cs" />
|
||||
<Compile Include="Source\Structs\BSP\SourceCubemap.cs" />
|
||||
<Compile Include="Source\Structs\BSP\SourceDispInfo.cs" />
|
||||
<Compile Include="Source\Structs\BSP\SourceDispVertex.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Lumps\SourceDispVertices.cs" />
|
||||
<Compile Include="Source\Structs\BSP\SourceStaticProp.cs" />
|
||||
<Compile Include="Source\Structs\BSP\SourceTexData.cs" />
|
||||
<Compile Include="Source\Structs\BSP\TexInfo.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Cubemap.cs" />
|
||||
<Compile Include="Source\Structs\BSP\DisplacementInfo.cs" />
|
||||
<Compile Include="Source\Structs\BSP\DisplacementVertex.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Lumps\DisplacementVertices.cs" />
|
||||
<Compile Include="Source\Structs\BSP\StaticProp.cs" />
|
||||
<Compile Include="Source\Structs\BSP\TextureData.cs" />
|
||||
<Compile Include="Source\Structs\BSP\TextureInfo.cs" />
|
||||
<Compile Include="Source\Structs\BSP\Texture.cs" />
|
||||
<Compile Include="Source\Structs\Common\Entity.cs" />
|
||||
<Compile Include="Source\Structs\Common\Lumps\Entities.cs" />
|
||||
|
||||
@@ -4,19 +4,20 @@ using System.Collections.Generic;
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Custom Attribute class to mark a member of a struct as an count for another lump. The
|
||||
/// member this Attribute is applied to should always be paired with a member with an Index
|
||||
/// Attribute applied to it. The two attributes can the be used to grab a range of objects
|
||||
/// from the specified lump through the <c>BSP.GetReferencedObjects<T></c> method.
|
||||
/// member this Attribute is applied to should always be paired with a member with an
|
||||
/// <see cref="IndexAttribute"/> applied to it. The two attributes can the be used to grab a
|
||||
/// range of objects from the specified lump through the
|
||||
/// <see cref="BSP.GetReferencedObjects<T>(System.Object, System.String)"/> method.
|
||||
/// </summary>
|
||||
public class CountAttribute : Attribute {
|
||||
|
||||
public string lumpName;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance of an <see cref="LibBSP.CountAttribute"/> object. The member this Attribute
|
||||
/// Constructs a new instance of a <see cref="CountAttribute"/> object. The member this Attribute
|
||||
/// is applied to will be used as a count of objects in the lump referenced by <paramref name="lumpName"/>.
|
||||
/// </summary>
|
||||
/// <param name="lumpName">The lump the member is an count for. Corresponds to the public properties in the <c>BSP</c> class.</param>
|
||||
/// <param name="lumpName">The lump the member is an count for. Corresponds to the public properties in the <see cref="BSP"/> class.</param>
|
||||
public CountAttribute(string lumpName) {
|
||||
this.lumpName = lumpName;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ using System.Collections.Generic;
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Custom Attribute class to mark a member of a struct as an index into another lump. The
|
||||
/// member this Attribute is applied to should always be paired with a member with a Count
|
||||
/// Attribute applied to it. The two attributes can the be used to grab a range of objects
|
||||
/// from the specified lump through the <c>BSP.GetReferencedObjects<T></c> method.
|
||||
/// member this Attribute is applied to should always be paired with a member with a
|
||||
/// <see cref="CountAttribute"/> applied to it. The two attributes can the be used to grab a range of objects
|
||||
/// from the specified lump through the
|
||||
/// <see cref="BSP.GetReferencedObjects<T>(System.Object, System.String)"/> method.
|
||||
/// </summary>
|
||||
public class IndexAttribute : Attribute {
|
||||
|
||||
@@ -16,7 +17,7 @@ namespace LibBSP {
|
||||
/// Constructs a new instance of an <see cref="IndexAttribute"/> object. The member this Attribute
|
||||
/// is applied to will be used as an index into the lump referenced by <paramref name="lumpName"/>.
|
||||
/// </summary>
|
||||
/// <param name="lumpName">The lump the member is an index into. Corresponds to the public properties in the <c>BSP</c> class.</param>
|
||||
/// <param name="lumpName">The lump the member is an index into. Corresponds to the public properties in the <see cref="BSP"/> class.</param>
|
||||
public IndexAttribute(string lumpName) {
|
||||
this.lumpName = lumpName;
|
||||
}
|
||||
|
||||
@@ -13,18 +13,18 @@ namespace LibBSP {
|
||||
using Color32 = Color;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Static class containing helper methods for <see cref="UnityEngine.Color32"/> objects.
|
||||
/// Static class containing helper methods for <c>Color</c> objects.
|
||||
/// </summary>
|
||||
public static class Color32Extensions {
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <see cref="UnityEngine.Color32"/> from the passed values.
|
||||
/// Constructs a new <c>Color</c> from the passed values.
|
||||
/// </summary>
|
||||
/// <param name="a">A component.</param>
|
||||
/// <param name="r">R component.</param>
|
||||
/// <param name="g">G component.</param>
|
||||
/// <param name="b">B component.</param>
|
||||
/// <returns>The resulting <see cref="UnityEngine.Color32"/> object.</returns>
|
||||
/// <param name="a">Alpha component of the color.</param>
|
||||
/// <param name="r">Red component of the color.</param>
|
||||
/// <param name="g">Green component of the color.</param>
|
||||
/// <param name="b">Blue component of the color.</param>
|
||||
/// <returns>The resulting <c>Color</c> object.</returns>
|
||||
public static Color32 FromArgb(int a, int r, int g, int b) {
|
||||
#if UNITY
|
||||
return new Color32((byte)r, (byte)g, (byte)b, (byte)a);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//#if (UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
@@ -13,7 +11,7 @@ namespace LibBSP {
|
||||
/// Retrieves a custom attribute of a specified type that is applied to a specified member.
|
||||
/// </summary>
|
||||
/// <param name="element">The member to inspect.</param>
|
||||
/// <returns>A custom attribute that matches T, or null if no such attribute is found.</returns>
|
||||
/// <returns>A custom attribute that matches <typeparamref name="T"/>, or <c>null</c> if no such attribute is found.</returns>
|
||||
/// <typeparam name="T">The type of attribute to search for.</typeparam>
|
||||
public static T GetCustomAttribute<T>(this MemberInfo element) where T : Attribute {
|
||||
return Attribute.GetCustomAttribute(element, typeof(T)) as T;
|
||||
@@ -21,5 +19,3 @@ namespace LibBSP {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//#endif
|
||||
|
||||
@@ -52,19 +52,19 @@ namespace LibBSP {
|
||||
/// Intersects this <see cref="Plane"/> with two other <see cref="Plane"/>s at a <see cref="Vector3"/>. Returns NaN for all components if two or more <see cref="Plane"/>s are parallel.
|
||||
/// </summary>
|
||||
/// <param name="p1">This <see cref="Plane"/>.</param>
|
||||
/// <param name="p2"><see cref="Plane"/> to intersect</param>
|
||||
/// <param name="p3"><see cref="Plane"/> to intersect</param>
|
||||
/// <returns>Point of intersection if all three <see cref="Plane"/>s meet at a point, (NaN, NaN, NaN) otherwise</returns>
|
||||
/// <param name="p2"><see cref="Plane"/> to intersect.</param>
|
||||
/// <param name="p3"><see cref="Plane"/> to intersect.</param>
|
||||
/// <returns>Point of intersection if all three <see cref="Plane"/>s meet at a point, (NaN, NaN, NaN) otherwise.</returns>
|
||||
public static Vector3 Intersect(this Plane p1, Plane p2, Plane p3) {
|
||||
return Intersection(p1, p2, p3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intersects a <see cref="Plane"/> "<paramref name="p" />" with a <see cref="Ray"/> "<paramref name="r" />" at a <see cref="Vector3"/>. Returns NaN for all components if they do not intersect.
|
||||
/// Intersects a <see cref="Plane"/> "<paramref name="p"/>" with a <see cref="Ray"/> "<paramref name="r"/>" at a <see cref="Vector3"/>. Returns NaN for all components if they do not intersect.
|
||||
/// </summary>
|
||||
/// <param name="p"><see cref="Plane"/> to intersect with.</param>
|
||||
/// <param name="r"><see cref="Ray"/> to intersect.</param>
|
||||
/// <returns>Point of intersection if "<paramref name="r" />" intersects "<paramref name="p" />", (NaN, NaN, NaN) otherwise.</returns>
|
||||
/// <returns>Point of intersection if "<paramref name="r"/>" intersects "<paramref name="p"/>", (NaN, NaN, NaN) otherwise.</returns>
|
||||
public static Vector3 Intersection(Plane p, Ray r) {
|
||||
#if UNITY
|
||||
float enter;
|
||||
@@ -80,21 +80,21 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intersects this <see cref="Plane"/> with a <see cref="Ray"/> "<paramref name="r" />" at a <see cref="Vector3"/>. Returns NaN for all components if they do not intersect.
|
||||
/// Intersects this <see cref="Plane"/> with a <see cref="Ray"/> "<paramref name="r"/>" at a <see cref="Vector3"/>. Returns NaN for all components if they do not intersect.
|
||||
/// </summary>
|
||||
/// <param name="p">This <see cref="Plane"/>.</param>
|
||||
/// <param name="r"><see cref="Ray"/> to intersect.</param>
|
||||
/// <returns>Point of intersection if "<paramref name="r" />" intersects this <see cref="Plane"/>, (NaN, NaN, NaN) otherwise.</returns>
|
||||
/// <returns>Point of intersection if "<paramref name="r"/>" intersects this <see cref="Plane"/>, (NaN, NaN, NaN) otherwise.</returns>
|
||||
public static Vector3 Intersect(this Plane p, Ray r) {
|
||||
return Intersection(p, r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intersects a <see cref="Plane"/> "<paramref name="p" />" with this <see cref="Ray"/> at a <see cref="Vector3"/>. Returns NaN for all components if they do not intersect.
|
||||
/// Intersects a <see cref="Plane"/> "<paramref name="p"/>" with this <see cref="Ray"/> at a <see cref="Vector3"/>. Returns NaN for all components if they do not intersect.
|
||||
/// </summary>
|
||||
/// <param name="r">This <see cref="Ray"/>.</param>
|
||||
/// <param name="p"><see cref="Plane"/> to intersect with.</param>
|
||||
/// <returns>Point of intersection if this <see cref="Ray"/> intersects "<paramref name="p" />", (NaN, NaN, NaN) otherwise.</returns>
|
||||
/// <returns>Point of intersection if this <see cref="Ray"/> intersects "<paramref name="p"/>", (NaN, NaN, NaN) otherwise.</returns>
|
||||
public static Vector3 Intersect(this Ray r, Plane p) {
|
||||
return Intersection(p, r);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ namespace LibBSP {
|
||||
/// </summary>
|
||||
/// <param name="p1"><see cref="Plane"/> to intersect.</param>
|
||||
/// <param name="p2"><see cref="Plane"/> to intersect.</param>
|
||||
/// <returns>Line of intersection where "<paramref name="p1" />" intersects "<paramref name="p2" />", ((NaN, NaN, NaN) + p(NaN, NaN, NaN)) otherwise.</returns>
|
||||
/// <returns>Line of intersection where "<paramref name="p1"/>" intersects "<paramref name="p2"/>", ((NaN, NaN, NaN) + p(NaN, NaN, NaN)) otherwise.</returns>
|
||||
public static Ray Intersection(Plane p1, Plane p2) {
|
||||
Vector3 direction = Vector3.Cross(p1.normal, p2.normal);
|
||||
if (direction == Vector3.zero) {
|
||||
@@ -152,7 +152,7 @@ namespace LibBSP {
|
||||
/// </summary>
|
||||
/// <param name="p1">This <see cref="Plane"/>.</param>
|
||||
/// <param name="p2"><see cref="Plane"/> to intersect.</param>
|
||||
/// <returns>Line of intersection where this <see cref="Plane"/> intersects "<paramref name="p2" />", ((NaN, NaN, NaN) + p(NaN, NaN, NaN)) otherwise.</returns>
|
||||
/// <returns>Line of intersection where this <see cref="Plane"/> intersects "<paramref name="p2"/>", ((NaN, NaN, NaN) + p(NaN, NaN, NaN)) otherwise.</returns>
|
||||
public static Ray Intersect(this Plane p1, Plane p2) {
|
||||
return Intersection(p1, p2);
|
||||
}
|
||||
@@ -228,11 +228,11 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <see cref="List"/> of <see cref="Plane"/> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="Plane"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <see cref="List"/> of <see cref="Plane"/> objects.</returns>
|
||||
/// <returns>A <c>List</c> of <see cref="Plane"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
/// <remarks>This function goes here since it can't go into Unity's Plane class, and so can't depend
|
||||
|
||||
@@ -11,20 +11,21 @@ namespace LibBSP {
|
||||
using Vector2 = Vector2d;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Static class containing helper methods for <c>Rect</c> objects.
|
||||
/// Static class containing helper methods for <see cref="Rect"/> objects.
|
||||
/// </summary>
|
||||
public static class RectExtensions {
|
||||
|
||||
// Determines if this node's partition vector (as a line segment) intersects the passed box.
|
||||
// Seems rather esoteric, no? But it's needed. Algorithm adapted from top answer at
|
||||
// http://stackoverflow.com/questions/99353/how-to-test-if-a-line-segment-intersects-an-axis-aligned-rectange-in-2d
|
||||
/// <summary>
|
||||
/// Determines if this <c>Rect</c> is intersected by the line segment defined by <paramref name="head"/> and <paramref name="tail"/>.
|
||||
/// Determines if this <see cref="Rect"/> is intersected by the line segment defined by <paramref name="head"/> and <paramref name="tail"/>.
|
||||
/// </summary>
|
||||
/// <param name="rect">This <c>Rect</c></param>
|
||||
/// <param name="head">First point defining the line segment</param>
|
||||
/// <param name="tail">The change and x and y for the coordinates of the tail</param>
|
||||
/// <returns><c>true</c> if the line segment intersects this <c>Rect</c> at any point</returns>
|
||||
/// <remarks>
|
||||
/// Adapted from top answer at
|
||||
/// http://stackoverflow.com/questions/99353/how-to-test-if-a-line-segment-intersects-an-axis-aligned-rectange-in-2d
|
||||
/// </remarks>
|
||||
/// <param name="rect">This <see cref="Rect"/>.</param>
|
||||
/// <param name="head">First point defining the line segment.</param>
|
||||
/// <param name="tail">The change and x and y for the coordinates of the tail.</param>
|
||||
/// <returns><c>true</c> if the line segment intersects this <see cref="Rect"/> at any point.</returns>
|
||||
public static bool IntersectsSegment(Rect rect, Vector2 head, Vector2 tail) {
|
||||
// Compute the signed distance from the line to each corner of the box
|
||||
double[] dist = new double[4];
|
||||
|
||||
@@ -5,16 +5,16 @@ using System.Text;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Static class containing helper methods for <c>string</c> objects
|
||||
/// Static class containing helper methods for <c>string</c> objects.
|
||||
/// </summary>
|
||||
public static class StringExtensions {
|
||||
/// <summary>
|
||||
/// Splits a <c>string</c> using a Unicode character, unless that character is between two instances of a container.
|
||||
/// </summary>
|
||||
/// <param name="st">The <c>string</c> to split</param>
|
||||
/// <param name="separator">Unicode character that delimits the substrings in this instance</param>
|
||||
/// <param name="container">Container character. Any <paramref name="separator"/> characters that occur between two instances of this character will be ignored</param>
|
||||
/// <returns>Array of <c>string</c> objects that are the resulting substrings</returns>
|
||||
/// <param name="st">The <c>string</c> to split.</param>
|
||||
/// <param name="separator">Unicode <c>char</c> that delimits the substrings in this instance.</param>
|
||||
/// <param name="container">Container <c>char</c>. Any <paramref name="separator"/> characters that occur between two instances of this character will be ignored.</param>
|
||||
/// <returns>Array of <c>string</c> objects that are the resulting substrings.</returns>
|
||||
public static string[] SplitUnlessInContainer(this string st, char separator, char container, StringSplitOptions options = StringSplitOptions.None) {
|
||||
List<string> results = new List<string>();
|
||||
bool inContainer = false;
|
||||
@@ -57,13 +57,13 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Splits a <c>string</c> using a Unicode character, unless that character is contained between matching <paramref name="start" /> and <paramref name="end" /> Unicode characters.
|
||||
/// Splits a <c>string</c> using a Unicode character, unless that character is contained between matching <paramref name="start"/> and <paramref name="end"/> Unicode characters.
|
||||
/// </summary>
|
||||
/// <param name="st">The <c>string</c> to split</param>
|
||||
/// <param name="separator">Unicode character that delimits the substrings in this instance</param>
|
||||
/// <param name="start">The starting (left) container character. EX: '('</param>
|
||||
/// <param name="end">The ending (right) container character. EX: ')'</param>
|
||||
/// <returns>Array of <c>string</c> objects that are the resulting substrings</returns>
|
||||
/// <param name="st">The <c>string</c> to split.</param>
|
||||
/// <param name="separator">Unicode <c>char</c> that delimits the substrings in this instance.</param>
|
||||
/// <param name="start">The starting (left) container character. EX: '('.</param>
|
||||
/// <param name="end">The ending (right) container character. EX: ')'.</param>
|
||||
/// <returns>Array of <c>string</c> objects that are the resulting substrings.</returns>
|
||||
public static string[] SplitUnlessBetweenDelimiters(this string st, char separator, char start, char end, StringSplitOptions options = StringSplitOptions.None) {
|
||||
List<string> results = new List<string>();
|
||||
int containerLevel = 0;
|
||||
@@ -115,12 +115,12 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the <c>bytes</c> in a <c>byte</c> array into an ASCII <c>string</c> up until the first null byte (0x00).
|
||||
/// Parses the <c>byte</c>s in a <c>byte</c> array into an ASCII <c>string</c> up until the first null byte (0x00).
|
||||
/// </summary>
|
||||
/// <param name="bytes"><c>Byte</c>s to parse</param>
|
||||
/// <param name="offset">Position in the array to start copying from</param>
|
||||
/// <param name="bytes"><c>byte</c>s to parse.</param>
|
||||
/// <param name="offset">Position in the array to start copying from.</param>
|
||||
/// <param name="length">Number of bytes to read before stopping. Negative values will read to the end of the array.</param>
|
||||
/// <returns>The resulting <c>string</c></returns>
|
||||
/// <returns>The resulting <c>string</c>.</returns>
|
||||
public static string ToNullTerminatedString(this byte[] bytes, int offset = 0, int length = -1) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < bytes.Length; ++i) {
|
||||
@@ -138,8 +138,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Parses the <c>bytes</c> in a <c>byte</c> array into an ASCII <c>string</c>.
|
||||
/// </summary>
|
||||
/// <param name="bytes"><c>Byte</c>s to parse</param>
|
||||
/// <returns>The resulting <c>string</c></returns>
|
||||
/// <param name="bytes"><c>byte</c>s to parse.</param>
|
||||
/// <returns>The resulting <c>string</c>.</returns>
|
||||
public static string ToRawString(this byte[] bytes) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < bytes.Length; ++i) {
|
||||
|
||||
@@ -17,27 +17,27 @@ namespace LibBSP {
|
||||
using Vector3 = Vector3d;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Static class containing helper methods for <c>UIVertex</c> objects.
|
||||
/// Static class containing helper methods for <see cref="UIVertex"/> objects.
|
||||
/// </summary>
|
||||
public static class UIVertexExtensions {
|
||||
|
||||
/// <summary>
|
||||
/// Scales the position of this <c>UIVertex</c> by a number
|
||||
/// Scales the position of this <see cref="UIVertex"/> by a number.
|
||||
/// </summary>
|
||||
/// <param name="v1">This <c>UIVertex</c></param>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <returns>The scaled <c>UIVertex</c></returns>
|
||||
/// <param name="v1">This <see cref="UIVertex"/>.</param>
|
||||
/// <param name="scalar">Scalar value.</param>
|
||||
/// <returns>The scaled <see cref="UIVertex"/>.</returns>
|
||||
public static UIVertex Scale(this UIVertex v1, float scalar) {
|
||||
v1.position *= scalar;
|
||||
return v1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the position of this <c>UIVertex</c> to another <c>UIVertex</c>.
|
||||
/// Adds the position of this <see cref="UIVertex"/> to another <see cref="UIVertex"/>.
|
||||
/// </summary>
|
||||
/// <param name="v1">This <c>UIVertex</c></param>
|
||||
/// <param name="v2">The other <c>UIVertex</c></param>
|
||||
/// <returns>The resulting <c>UIVertex</c></returns>
|
||||
/// <param name="v1">This <see cref="UIVertex"/>.</param>
|
||||
/// <param name="v2">The other <see cref="UIVertex"/>.</param>
|
||||
/// <returns>The resulting <see cref="UIVertex"/>.</returns>
|
||||
public static UIVertex Add(this UIVertex v1, UIVertex v2) {
|
||||
return new UIVertex {
|
||||
color = v1.color,
|
||||
@@ -50,11 +50,11 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the position of a <c>Vector3</c> to this <c>UIVertex</c>.
|
||||
/// Adds the position of a <c>Vector3</c> to this <see cref="UIVertex"/>.
|
||||
/// </summary>
|
||||
/// <param name="v1">This <c>UIVertex</c></param>
|
||||
/// <param name="v2">The <c>Vector3</c></param>
|
||||
/// <returns>The resulting <c>UIVertex</c></returns>
|
||||
/// <param name="v1">This <see cref="UIVertex"/>.</param>
|
||||
/// <param name="v2">The <see cref="Vector3"/>.</param>
|
||||
/// <returns>The resulting <see cref="UIVertex"/>.</returns>
|
||||
public static UIVertex Translate(this UIVertex v1, Vector3 v2) {
|
||||
return new UIVertex {
|
||||
color = v1.color,
|
||||
@@ -67,14 +67,14 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>UIVertex</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="UIVertex"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>The resulting <c>UIVertex</c> object</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <remarks><c>UIVertex</c> has no constructor, so the object must be initialized field-by-field. Even if it
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>The resulting <see cref="UIVertex"/> object.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was null.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
/// <remarks><see cref="UIVertex"/> has no constructor, so the object must be initialized field-by-field. Even if it
|
||||
/// did have a constructor, the way data needs to be read wouldn't allow use of it.</remarks>
|
||||
public static UIVertex CreateVertex(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
@@ -131,13 +131,13 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>UIVertex</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="UIVertex"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>UIVertex</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="UIVertex"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
/// <remarks>This function goes here since I can't put it into Unity's <c>UIVertex</c> class, and so I can't
|
||||
/// depend on having a constructor taking a byte array.</remarks>
|
||||
public static List<UIVertex> LumpFactory(byte[] data, MapType type) {
|
||||
@@ -195,8 +195,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Quake2:
|
||||
|
||||
@@ -14,22 +14,25 @@ namespace LibBSP {
|
||||
#if !UNITY
|
||||
using Vector3 = Vector3d;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Enum of the known different map formats.
|
||||
/// </summary>
|
||||
public enum MapType : int {
|
||||
Undefined = 0,
|
||||
Quake = 29,
|
||||
// TYPE_GOLDSRC = 30, // Uses same algorithm and structures as Quake
|
||||
// TYPE_GOLDSRC = 30, // Uses mostly the same structures as Quake
|
||||
Nightfire = 42,
|
||||
Vindictus = 346131372,
|
||||
STEF2 = 556942937,
|
||||
MOHAA = 892416069,
|
||||
// TYPE_MOHBT = 1095516506, // Similar enough to MOHAA to use the same structures and algorithm
|
||||
// TYPE_MOHBT = 1095516506, // Similar enough to MOHAA to use the same structures
|
||||
STEF2Demo = 1263223129,
|
||||
FAKK = 1263223152,
|
||||
TacticalInterventionEncrypted = 1268885814,
|
||||
CoD2 = 1347633741, // Uses same algorithm and structures as COD1. Read differently.
|
||||
CoD2 = 1347633741,
|
||||
SiN = 1347633747, // The headers for SiN and Jedi Outcast are exactly the same
|
||||
Raven = 1347633748,
|
||||
CoD4 = 1347633759, // Uses same algorithm and structures as COD1. Read differently.
|
||||
CoD4 = 1347633759,
|
||||
Source17 = 1347633767,
|
||||
Source18 = 1347633768,
|
||||
Source19 = 1347633769,
|
||||
@@ -43,11 +46,22 @@ namespace LibBSP {
|
||||
Daikatana = 1347633778,
|
||||
SoF = 1347633782, // Uses the same header as Q3.
|
||||
Quake3 = 1347633783,
|
||||
// TYPE_RTCW = 1347633784, // Uses same algorithm and structures as Quake 3
|
||||
// TYPE_RTCW = 1347633784, // Uses same structures as Quake 3
|
||||
CoD = 1347633796,
|
||||
DMoMaM = 1347895914,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Struct containing basic information for a lump in a BSP file.
|
||||
/// </summary>
|
||||
public struct LumpInfo {
|
||||
public int ident;
|
||||
public int flags;
|
||||
public int version;
|
||||
public int offset;
|
||||
public int length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Holds data for any and all BSP formats. Any unused lumps in a given format
|
||||
/// will be left as null.
|
||||
@@ -65,7 +79,7 @@ namespace LibBSP {
|
||||
private Textures _textures;
|
||||
private List<UIVertex> _vertices;
|
||||
private List<Node> _nodes;
|
||||
private List<TexInfo> _texInfo;
|
||||
private List<TextureInfo> _texInfo;
|
||||
private List<Face> _faces;
|
||||
private List<Leaf> _leaves;
|
||||
private NumList _markSurfaces;
|
||||
@@ -83,17 +97,17 @@ namespace LibBSP {
|
||||
// Source
|
||||
private List<Face> _originalFaces;
|
||||
private NumList _texTable;
|
||||
private List<SourceTexData> _texDatas;
|
||||
private List<SourceDispInfo> _dispInfos;
|
||||
private SourceDispVertices _dispVerts;
|
||||
private List<TextureData> _texDatas;
|
||||
private List<DisplacementInfo> _dispInfos;
|
||||
private DisplacementVertices _dispVerts;
|
||||
private NumList _displacementTriangles;
|
||||
// public SourceOverlays overlays;
|
||||
private List<SourceCubemap> _cubemaps;
|
||||
private List<Cubemap> _cubemaps;
|
||||
private GameLump _gameLump;
|
||||
private SourceStaticProps _staticProps;
|
||||
private StaticProps _staticProps;
|
||||
|
||||
/// <summary>
|
||||
/// The version of this BSP. DO NOT CHANGE THIS unless you want to force reading a BSP as a certain format.
|
||||
/// The version of this BSP. Do not change this unless you want to force reading a BSP as a certain format.
|
||||
/// </summary>
|
||||
public MapType version {
|
||||
get {
|
||||
@@ -107,8 +121,14 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the BSP file in big endian format?
|
||||
/// </summary>
|
||||
public bool bigEndian { get { return _reader.bigEndian; } }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Entities"/> object in the BSP file, if available.
|
||||
/// </summary>
|
||||
public Entities entities {
|
||||
get {
|
||||
if (_entities == null) {
|
||||
@@ -121,6 +141,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="Plane"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<Plane> planes {
|
||||
get {
|
||||
if (_planes == null) {
|
||||
@@ -133,6 +156,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Textures"/> object in the BSP file, if available.
|
||||
/// </summary>
|
||||
public Textures textures {
|
||||
get {
|
||||
if (_textures == null) {
|
||||
@@ -145,6 +171,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="UIVertex"/> objects in the BSP file representing the vertices of the BSP, if available.
|
||||
/// </summary>
|
||||
public List<UIVertex> vertices {
|
||||
get {
|
||||
if (_vertices == null) {
|
||||
@@ -157,6 +186,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="Node"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<Node> nodes {
|
||||
get {
|
||||
if (_nodes == null) {
|
||||
@@ -169,18 +201,24 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
public List<TexInfo> texInfo {
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="TextureInfo"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<TextureInfo> texInfo {
|
||||
get {
|
||||
if (_texInfo == null) {
|
||||
int index = TexInfo.GetIndexForLump(version);
|
||||
int index = TextureInfo.GetIndexForLump(version);
|
||||
if (index >= 0) {
|
||||
_texInfo = TexInfo.LumpFactory(_reader.ReadLumpNum(index, version), version);
|
||||
_texInfo = TextureInfo.LumpFactory(_reader.ReadLumpNum(index, version), version);
|
||||
}
|
||||
}
|
||||
return _texInfo;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="Face"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<Face> faces {
|
||||
get {
|
||||
if (_faces == null) {
|
||||
@@ -193,6 +231,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="Leaf"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<Leaf> leaves {
|
||||
get {
|
||||
if (_leaves == null) {
|
||||
@@ -205,6 +246,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="Edge"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<Edge> edges {
|
||||
get {
|
||||
if (_edges == null) {
|
||||
@@ -217,6 +261,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="Model"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<Model> models {
|
||||
get {
|
||||
if (_models == null) {
|
||||
@@ -229,6 +276,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="Brush"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<Brush> brushes {
|
||||
get {
|
||||
if (_brushes == null) {
|
||||
@@ -241,6 +291,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="BrushSide"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<BrushSide> brushSides {
|
||||
get {
|
||||
if (_brushSides == null) {
|
||||
@@ -253,6 +306,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="Texture"/> objects in the BSP file representing Materials (shaders), if available.
|
||||
/// </summary>
|
||||
public Textures materials {
|
||||
get {
|
||||
if (_materials == null) {
|
||||
@@ -265,6 +321,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="Face"/> objects in the BSP file representing the Original Faces, if available.
|
||||
/// </summary>
|
||||
public List<Face> originalFaces {
|
||||
get {
|
||||
if (_originalFaces == null) {
|
||||
@@ -277,54 +336,69 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
public List<SourceTexData> texDatas {
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="TextureData"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<TextureData> texDatas {
|
||||
get {
|
||||
if (_texDatas == null) {
|
||||
int index = SourceTexData.GetIndexForLump(version);
|
||||
int index = TextureData.GetIndexForLump(version);
|
||||
if (index >= 0) {
|
||||
_texDatas = SourceTexData.LumpFactory(_reader.ReadLumpNum(index, version), version);
|
||||
_texDatas = TextureData.LumpFactory(_reader.ReadLumpNum(index, version), version);
|
||||
}
|
||||
}
|
||||
return _texDatas;
|
||||
}
|
||||
}
|
||||
|
||||
public List<SourceDispInfo> dispInfos {
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="DisplacementInfo"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<DisplacementInfo> dispInfos {
|
||||
get {
|
||||
if (_dispInfos == null) {
|
||||
int index = SourceDispInfo.GetIndexForLump(version);
|
||||
int index = DisplacementInfo.GetIndexForLump(version);
|
||||
if (index >= 0) {
|
||||
_dispInfos = SourceDispInfo.LumpFactory(_reader.ReadLumpNum(index, version), version);
|
||||
_dispInfos = DisplacementInfo.LumpFactory(_reader.ReadLumpNum(index, version), version);
|
||||
}
|
||||
}
|
||||
return _dispInfos;
|
||||
}
|
||||
}
|
||||
|
||||
public SourceDispVertices dispVerts {
|
||||
/// <summary>
|
||||
/// The <see cref="DisplacementVertices"/> object in the BSP file, if available.
|
||||
/// </summary>
|
||||
public DisplacementVertices dispVerts {
|
||||
get {
|
||||
if (_dispVerts == null) {
|
||||
int index = SourceDispVertex.GetIndexForLump(version);
|
||||
int index = DisplacementVertex.GetIndexForLump(version);
|
||||
if (index >= 0) {
|
||||
_dispVerts = SourceDispVertex.LumpFactory(_reader.ReadLumpNum(index, version), version);
|
||||
_dispVerts = DisplacementVertex.LumpFactory(_reader.ReadLumpNum(index, version), version);
|
||||
}
|
||||
}
|
||||
return _dispVerts;
|
||||
}
|
||||
}
|
||||
|
||||
public List<SourceCubemap> cubemaps {
|
||||
/// <summary>
|
||||
/// A <c>List</c> of <see cref="Cubemap"/> objects in the BSP file, if available.
|
||||
/// </summary>
|
||||
public List<Cubemap> cubemaps {
|
||||
get {
|
||||
if (_cubemaps == null) {
|
||||
int index = SourceCubemap.GetIndexForLump(version);
|
||||
int index = Cubemap.GetIndexForLump(version);
|
||||
if (index >= 0) {
|
||||
_cubemaps = SourceCubemap.LumpFactory(_reader.ReadLumpNum(index, version), version);
|
||||
_cubemaps = Cubemap.LumpFactory(_reader.ReadLumpNum(index, version), version);
|
||||
}
|
||||
}
|
||||
return _cubemaps;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="NumList"/> object containing the Mark Surfaces (Leaf Surfaces) lump, if available.
|
||||
/// </summary>
|
||||
public NumList markSurfaces {
|
||||
get {
|
||||
if (_markSurfaces == null) {
|
||||
@@ -338,6 +412,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="NumList"/> object containing the Surface Edges lump, if available.
|
||||
/// </summary>
|
||||
public NumList surfEdges {
|
||||
get {
|
||||
if (_surfEdges == null) {
|
||||
@@ -351,6 +428,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="NumList"/> object containing the Mark Brushes (Leaf Brushes) lump, if available.
|
||||
/// </summary>
|
||||
public NumList markBrushes {
|
||||
get {
|
||||
if (_markBrushes == null) {
|
||||
@@ -364,6 +444,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="NumList"/> object containing the Face Vertex Indices lump, if available.
|
||||
/// </summary>
|
||||
public NumList indices {
|
||||
get {
|
||||
if (_indices == null) {
|
||||
@@ -377,6 +460,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="NumList"/> object containing the Texture offsets table lump, if available.
|
||||
/// </summary>
|
||||
public NumList texTable {
|
||||
get {
|
||||
if (_texTable == null) {
|
||||
@@ -390,6 +476,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="NumList"/> object containing the Displacement Triangles lump, if available.
|
||||
/// </summary>
|
||||
public NumList displacementTriangles {
|
||||
get {
|
||||
if (_displacementTriangles == null) {
|
||||
@@ -403,6 +492,9 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="GameLump"/> object in the BSP file containing internal lumps, if available.
|
||||
/// </summary>
|
||||
public GameLump gameLump {
|
||||
get {
|
||||
if (_gameLump == null) {
|
||||
@@ -415,14 +507,17 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
|
||||
public SourceStaticProps staticProps {
|
||||
/// <summary>
|
||||
/// The <see cref="StaticProps"/> object in the BSP file extracted from the <see cref="BSP.gameLump"/>, if available.
|
||||
/// </summary>
|
||||
public StaticProps staticProps {
|
||||
get {
|
||||
if (_staticProps == null) {
|
||||
if (gameLump != null && gameLump.ContainsKey(GameLumpType.sprp)) {
|
||||
GameLump.GameLumpInfo info = gameLump[GameLumpType.sprp];
|
||||
LumpInfo info = gameLump[GameLumpType.sprp];
|
||||
byte[] thisLump = new byte[info.length];
|
||||
Array.Copy(gameLump.rawData, info.offset - gameLump.gameLumpOffset, thisLump, 0, info.length);
|
||||
_staticProps = SourceStaticProp.LumpFactory(thisLump, version, info.version);
|
||||
_staticProps = StaticProp.LumpFactory(thisLump, version, info.version);
|
||||
}
|
||||
}
|
||||
return _staticProps;
|
||||
@@ -487,7 +582,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>BSP</c> instance pointing to the file at <paramref name="filePath"/>. The
|
||||
/// Creates a new <see cref="BSP"/> instance pointing to the file at <paramref name="filePath"/>. The
|
||||
/// <c>List</c>s in this class will be read and populated when accessed through their properties.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The path to the .BSP file.</param>
|
||||
@@ -497,7 +592,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>BSP</c> instance using the file referenced by <paramref name="file"/>. The
|
||||
/// Creates a new <see cref="BSP"/> instance using the file referenced by <paramref name="file"/>. The
|
||||
/// <c>List</c>s in this class will be read and populated when accessed through their properties.
|
||||
/// </summary>
|
||||
/// <param name="file">A reference to the .BSP file.</param>
|
||||
@@ -515,23 +610,30 @@ namespace LibBSP {
|
||||
|
||||
/// <summary>
|
||||
/// Gets all objects of type <typeparamref name="T"/> referenced through passed object <paramref name="o"/>
|
||||
/// contained in the lump <paramref name="lumpName"/> stored in this <c>BSP</c> class. This is done by
|
||||
/// contained in the lump <paramref name="lumpName"/> stored in this <see cref="BSP"/> class. This is done by
|
||||
/// reflecting the <c>Type</c> of <paramref name="o"/> and looping through its public properties to find
|
||||
/// a member with an <c>IndexAttribute</c> attribute and a member with <c>CountAttribute</c> attribute
|
||||
/// a member with an <see cref="IndexAttribute"/> attribute and a member with a <see cref="CountAttribute"/> attribute
|
||||
/// both corresponding to <paramref name="lumpName"/>. The index and count are obtained and used to construct
|
||||
/// a new <c>List<<typeparamref name="T"/>></c> object containing the corresponding objects.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of <c>object</c> stored in the lump <paramref name="lumpName"/>.</typeparam>
|
||||
/// <param name="o">The <c>object</c> which contains and index and count corresponding to <paramref name="lumpName"/>.</param>
|
||||
/// <param name="lumpName">The name of the property in this <c>BSP</c> object to get a <c>List</c> of objects from.</param>
|
||||
/// <param name="lumpName">The name of the property in this <see cref="BSP"/> object to get a <c>List</c> of objects from.</param>
|
||||
/// <returns>The <c>List<<typeparamref name="T"/>></c> of objects in the lump from the index and length specified in <paramref name="o"/>.</returns>
|
||||
/// <exception cref="ArgumentException">The <c>BSP</c> class contains no property corresponding to <paramref name="lumpName"/>.</exception>
|
||||
/// <exception cref="ArgumentException">The <see cref="BSP"/> class contains no property corresponding to <paramref name="lumpName"/>.</exception>
|
||||
/// <exception cref="ArgumentException">The <c>object</c> referenced by <paramref name="o"/> is missing one or both members with <c>IndexAttribute</c> or <c>CountAttribute</c> attributes corresponding to <paramref name="lumpName"/>.</exception>
|
||||
/// <exception cref="ArgumentNullException">One or both of <paramref name="o"/> or <paramref name="lumpName"/> is null.</exception>
|
||||
public List<T> GetReferencedObjects<T>(object o, string lumpName) {
|
||||
if (o == null) {
|
||||
throw new ArgumentNullException("Object cannot be null.");
|
||||
}
|
||||
if (lumpName == null) {
|
||||
throw new ArgumentNullException("Lump name cannot be null.");
|
||||
}
|
||||
// First, find the property in this class corresponding to lumpName, and grab its "get" method
|
||||
PropertyInfo targetLump = typeof(BSP).GetProperty(lumpName, BindingFlags.Public | BindingFlags.Instance);
|
||||
if (targetLump == null) {
|
||||
throw new ArgumentException("The lump " + lumpName + " does not exist in the BSP class");
|
||||
throw new ArgumentException("The lump " + lumpName + " does not exist in the BSP class.");
|
||||
}
|
||||
|
||||
// Next, find the properties in the passed object corresponding to lumpName, through the Index and Length custom attributes
|
||||
@@ -560,7 +662,7 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
if (indexProperty == null || countProperty == null) {
|
||||
throw new ArgumentException("An object of type " + objectType.Name + " does not implement both an Index and Count for lump " + lumpName);
|
||||
throw new ArgumentException("An object of type " + objectType.Name + " does not implement both an Index and Count for lump " + lumpName + ".");
|
||||
}
|
||||
|
||||
// Get the index and length from the object
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Holds the data used by the brush structures of all formats of BSP
|
||||
/// Holds the data used by the brush structures of all formats of BSP.
|
||||
/// </summary>
|
||||
public struct Brush {
|
||||
|
||||
@@ -13,12 +13,12 @@ namespace LibBSP {
|
||||
public int contents { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Brush</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="Brush"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public Brush(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -84,13 +84,13 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>Brush</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="Brush"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>Brush</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="Brush"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public static List<Brush> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -144,8 +144,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.CoD: {
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Holds the data used by the brush side structures of all formats of BSP
|
||||
/// Holds the data used by the brush side structures of all formats of BSP.
|
||||
/// </summary>
|
||||
public struct BrushSide {
|
||||
|
||||
@@ -15,12 +15,12 @@ namespace LibBSP {
|
||||
public bool bevel { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>BrushSide</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="BrushSide"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public BrushSide(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -103,13 +103,13 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>BrushSide</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="BrushSide"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>BrushSide</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="BrushSide"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public static List<BrushSide> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -169,8 +169,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.CoD: {
|
||||
|
||||
@@ -15,19 +15,19 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Holds all data for a Cubemap from Source engine.
|
||||
/// </summary>
|
||||
public struct SourceCubemap {
|
||||
public struct Cubemap {
|
||||
|
||||
public Vector3 origin { get; private set; }
|
||||
public int size { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>SourceCubemap</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="Cubemap"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
public SourceCubemap(byte[] data, MapType type) : this() {
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public Cubemap(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
@@ -54,14 +54,14 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>SourceCubemap</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="Cubemap"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>SourceCubemap</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
public static List<SourceCubemap> LumpFactory(byte[] data, MapType type) {
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="Cubemap"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public static List<Cubemap> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
@@ -86,11 +86,11 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
int offset = 0;
|
||||
List<SourceCubemap> lump = new List<SourceCubemap>(data.Length / structLength);
|
||||
List<Cubemap> lump = new List<Cubemap>(data.Length / structLength);
|
||||
byte[] bytes = new byte[structLength];
|
||||
for (int i = 0; i < data.Length / structLength; ++i) {
|
||||
Array.Copy(data, (i * structLength), bytes, 0, structLength);
|
||||
lump.Add(new SourceCubemap(bytes, type));
|
||||
lump.Add(new Cubemap(bytes, type));
|
||||
offset += structLength;
|
||||
}
|
||||
return lump;
|
||||
@@ -99,8 +99,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Vindictus:
|
||||
@@ -15,7 +15,7 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Holds all data for a Displacement from Source engine.
|
||||
/// </summary>
|
||||
public struct SourceDispInfo {
|
||||
public struct DisplacementInfo {
|
||||
|
||||
public Vector3 startPosition { get; private set; }
|
||||
public int dispVertStart { get; private set; }
|
||||
@@ -24,13 +24,13 @@ namespace LibBSP {
|
||||
public uint[] allowedVerts { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>SourceDispInfo</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="DisplacementInfo"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
public SourceDispInfo(byte[] data, MapType type) : this() {
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public DisplacementInfo(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
@@ -74,14 +74,14 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>SourceDispInfo</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="DisplacementInfo"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>SourceDispInfo</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
public static List<SourceDispInfo> LumpFactory(byte[] data, MapType type) {
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="DisplacementInfo"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public static List<DisplacementInfo> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
@@ -115,11 +115,11 @@ namespace LibBSP {
|
||||
}
|
||||
}
|
||||
int offset = 0;
|
||||
List<SourceDispInfo> lump = new List<SourceDispInfo>(data.Length / structLength);
|
||||
List<DisplacementInfo> lump = new List<DisplacementInfo>(data.Length / structLength);
|
||||
byte[] bytes = new byte[structLength];
|
||||
for (int i = 0; i < data.Length / structLength; ++i) {
|
||||
Array.Copy(data, (i * structLength), bytes, 0, structLength);
|
||||
lump.Add(new SourceDispInfo(bytes, type));
|
||||
lump.Add(new DisplacementInfo(bytes, type));
|
||||
offset += structLength;
|
||||
}
|
||||
return lump;
|
||||
@@ -128,8 +128,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Vindictus:
|
||||
@@ -15,19 +15,19 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Holds all the data for a displacement in a Source map.
|
||||
/// </summary>
|
||||
public struct SourceDispVertex {
|
||||
public struct DisplacementVertex {
|
||||
|
||||
public Vector3 normal { get; private set; } // The normalized vector direction this vertex points from "flat"
|
||||
public float dist { get; private set; } // Magnitude of normal, before normalization
|
||||
public float alpha { get; private set; } // Alpha value of texture at this vertex
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>SourceDispVertex</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="DisplacementVertex"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
public SourceDispVertex(byte[] data, MapType type) : this() {
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
public DisplacementVertex(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
@@ -37,24 +37,24 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>SourceDispVertices</c> object.
|
||||
/// Factory method to parse a <c>byte</c> array into a <see cref="DisplacementVertices"/> object.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>SourceDispVertices</c> object</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
public static SourceDispVertices LumpFactory(byte[] data, MapType type) {
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <see cref="DisplacementVertices"/> object.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
public static DisplacementVertices LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
return new SourceDispVertices(data, type);
|
||||
return new DisplacementVertices(data, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Vindictus:
|
||||
@@ -11,12 +11,12 @@ namespace LibBSP {
|
||||
public int secondVertex { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Edge</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="Edge"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public Edge(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -53,13 +53,13 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>Edge</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="Edge"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>Edge</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="Edge"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was null.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public static List<Edge> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -104,8 +104,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Quake2:
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace LibBSP {
|
||||
/// <remarks>
|
||||
/// Faces is one of the more different lumps between versions. Some of these fields
|
||||
/// are only used by one format. However, there are some commonalities which make
|
||||
/// it worthwhile to unify these. All formats use a plane, a texture, and vertices
|
||||
/// in some way. Also (unused for the decompiler) they all use lightmaps.
|
||||
/// it worthwhile to unify these. All formats use a plane, a texture, vertices,
|
||||
/// and lightmaps in some way.
|
||||
/// </remarks>
|
||||
public struct Face {
|
||||
|
||||
@@ -44,12 +44,12 @@ namespace LibBSP {
|
||||
public Vector2 patchSize { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Face</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="Face"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public Face(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -160,13 +160,13 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>Face</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="Face"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>Face</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="Face"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public static List<Face> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -244,8 +244,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.FAKK:
|
||||
@@ -292,8 +292,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for the original faces lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForOriginalFacesLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Vindictus:
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Holds data for a leaf structure in a BSP map
|
||||
/// Holds data for a leaf structure in a BSP map.
|
||||
/// </summary>
|
||||
public struct Leaf {
|
||||
|
||||
@@ -15,12 +15,12 @@ namespace LibBSP {
|
||||
public int pvs { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Leaf</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="Leaf"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public Leaf(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -95,13 +95,13 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>Leaf</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="Leaf"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>Leaf</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="Leaf"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public static List<Leaf> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -169,8 +169,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Raven:
|
||||
|
||||
58
LibBSP/Source/Structs/BSP/Lumps/DisplacementVertices.cs
Normal file
58
LibBSP/Source/Structs/BSP/Lumps/DisplacementVertices.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Class representing a group of <see cref="DisplacementVertex"/> objects. Contains helpful methods to handle Displacement Vertices in the <c>List</c>.
|
||||
/// </summary>
|
||||
public class DisplacementVertices : List<DisplacementVertex> {
|
||||
|
||||
/// <summary>
|
||||
/// Parses the passed <c>byte</c> array into a <c>List</c> of <see cref="DisplacementVertex"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">Array of <c>byte</c>s to parse.</param>
|
||||
/// <param name="type">Format identifier.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
public DisplacementVertices(byte[] data, MapType type) : base(data.Length / 20) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
int structLength = 20;
|
||||
byte[] bytes = new byte[structLength];
|
||||
for (int i = 0; i < data.Length / structLength; ++i) {
|
||||
Array.Copy(data, (i * structLength), bytes, 0, structLength);
|
||||
Add(new DisplacementVertex(bytes, type));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets enough vertices from the list for a displacement of power <paramref name="power"/>, starting at <paramref name="first"/>.
|
||||
/// </summary>
|
||||
/// <param name="first">The first vertex to get.</param>
|
||||
/// <param name="power">The power of the displacement.</param>
|
||||
/// <returns>Array of <see cref="DisplacementVertex"/> objects containing all the vertices in this displacement</returns>
|
||||
public virtual DisplacementVertex[] GetVerticesInDisplacement(int first, int power) {
|
||||
int numVerts = 0;
|
||||
switch (power) {
|
||||
case 2: {
|
||||
numVerts = 25;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
numVerts = 81;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
numVerts = 289;
|
||||
break;
|
||||
}
|
||||
}
|
||||
DisplacementVertex[] ret = new DisplacementVertex[numVerts];
|
||||
for (int i = 0; i < numVerts; ++i) {
|
||||
ret[i] = this[first + i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,28 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Enum containing known game lumps.
|
||||
/// </summary>
|
||||
public enum GameLumpType : int {
|
||||
hlpd = 1685089384,
|
||||
tlpd = 1685089396,
|
||||
prpd = 1685090928,
|
||||
sprp = 1936749168,
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class containing the identification and information for the various Game Lumps in Source
|
||||
/// engine BSPs. The only one we're really concerned with is the Static Props.
|
||||
/// </summary>
|
||||
public class GameLump : Dictionary<GameLumpType, GameLump.GameLumpInfo> {
|
||||
|
||||
public struct GameLumpInfo {
|
||||
public ushort flags;
|
||||
public ushort version;
|
||||
public int offset;
|
||||
public int length;
|
||||
}
|
||||
public class GameLump : Dictionary<GameLumpType, LumpInfo> {
|
||||
|
||||
private byte[] _rawData;
|
||||
private int _gameLumpOffset;
|
||||
|
||||
/// <summary>
|
||||
/// Byte array representing the raw data read from the BSP for the game lump
|
||||
/// Byte array representing the raw data read from the BSP for the game lump.
|
||||
/// </summary>
|
||||
public byte[] rawData {
|
||||
get {
|
||||
@@ -32,7 +32,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The amount to subtract from all the <c>GameLumpInfo.offset</c> values to find the offset relative to the start of the Game Lump data. May be 0.
|
||||
/// The amount to subtract from all the <see cref="LumpInfo.offset"/> values to find the offset relative to the start of the Game Lump data. May be 0.
|
||||
/// </summary>
|
||||
public int gameLumpOffset {
|
||||
get {
|
||||
@@ -41,13 +41,13 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>GameLump</c> object by parsing a <c>byte</c> array into a <c>Dictionary</c> of <c>GameLumpInfo</c> objects.
|
||||
/// Creates a new <see cref="GameLump"/> object by parsing a <c>byte</c> array into a <c>Dictionary</c> of <see cref="LumpInfo"/> objects.
|
||||
/// These objects contain offsets, lengths and versions of the GameLump lumps.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public GameLump(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -84,13 +84,14 @@ namespace LibBSP {
|
||||
int lowestLumpOffset = Int32.MaxValue;
|
||||
|
||||
for (int i = 0; i < numGameLumps; ++i) {
|
||||
GameLumpInfo info = new GameLumpInfo {
|
||||
LumpInfo info = new LumpInfo {
|
||||
ident = BitConverter.ToInt32(data, (i * structLength) + 4),
|
||||
flags = BitConverter.ToUInt16(data, (i * structLength) + 8),
|
||||
version = BitConverter.ToUInt16(data, (i * structLength) + 10),
|
||||
offset = BitConverter.ToInt32(data, (i * structLength) + 12),
|
||||
length = BitConverter.ToInt32(data, (i * structLength) + 16),
|
||||
};
|
||||
this[(GameLumpType)BitConverter.ToInt32(data, (i * structLength) + 4)] = info;
|
||||
this[(GameLumpType)info.ident] = info;
|
||||
|
||||
if (info.offset < lowestLumpOffset) {
|
||||
lowestLumpOffset = info.offset;
|
||||
@@ -103,11 +104,11 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Passes a <c>byte</c> array into the constructor for <c>GameLump</c>.
|
||||
/// Passes a <c>byte</c> array into the constructor for <see cref="GameLump"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A new <c>GameLump</c> object</returns>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A new <see cref="GameLump"/> object.</returns>
|
||||
/// <remarks>This is only here for consistency with the other lump structures.</remarks>
|
||||
public static GameLump LumpFactory(byte[] data, MapType type) {
|
||||
return new GameLump(data, type);
|
||||
@@ -116,8 +117,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Vindictus:
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Class representing a group of <c>SourceDispVertex</c> objects. Contains helpful methods to handle Displacement Vertices in the <c>List</c>
|
||||
/// </summary>
|
||||
public class SourceDispVertices : List<SourceDispVertex> {
|
||||
|
||||
/// <summary>
|
||||
/// Parses the passed <c>byte</c> array into a <c>List</c> of <c>SourceDispVertices</c>
|
||||
/// </summary>
|
||||
/// <param name="data">Array of <c>byte</c>s to parse</param>
|
||||
/// <param name="type">Format identifier</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
public SourceDispVertices(byte[] data, MapType type) : base(data.Length / 20) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
int structLength = 20;
|
||||
byte[] bytes = new byte[structLength];
|
||||
for (int i = 0; i < data.Length / structLength; ++i) {
|
||||
Array.Copy(data, (i * structLength), bytes, 0, structLength);
|
||||
Add(new SourceDispVertex(bytes, type));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets enough vertices from the list for a displacement of power <paramref name="power" />, starting at <paramref name="first" />.
|
||||
/// </summary>
|
||||
/// <param name="first">The first vertex to get</param>
|
||||
/// <param name="power">The power of the displacement</param>
|
||||
/// <returns>Array of <c>SourceDispVertex</c> objects containing all the vertices in this displacement</returns>
|
||||
public virtual SourceDispVertex[] GetVerticesInDisplacement(int first, int power) {
|
||||
int numVerts = 0;
|
||||
switch (power) {
|
||||
case 2: {
|
||||
numVerts = 25;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
numVerts = 81;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
numVerts = 289;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SourceDispVertex[] ret = new SourceDispVertex[numVerts];
|
||||
for (int i = 0; i < numVerts; ++i) {
|
||||
ret[i] = this[first + i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,20 @@ using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// List of <c>SourceStaticProp</c> objects containing data relevant to Static Props, like the dictionary of actual model paths.
|
||||
/// List of <see cref="StaticProp"/> objects containing data relevant to Static Props, like the dictionary of actual model paths.
|
||||
/// </summary>
|
||||
public class SourceStaticProps : List<SourceStaticProp> {
|
||||
public class StaticProps : List<StaticProp> {
|
||||
|
||||
public string[] dictionary { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Parses the passed <c>byte</c> array into a <c>List</c> of <c>SourceStaticProp</c> objects
|
||||
/// Parses the passed <c>byte</c> array into a <c>List</c> of <see cref="StaticProp"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">Array of <c>byte</c>s to parse</param>
|
||||
/// <param name="type">Format identifier</param>
|
||||
/// <param name="version">Version of static prop lump this is</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
public SourceStaticProps(byte[] data, MapType type, int version) {
|
||||
/// <param name="data">Array of <c>byte</c>s to parse.</param>
|
||||
/// <param name="type">Format identifier.</param>
|
||||
/// <param name="version">Version of static prop lump this is.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
public StaticProps(byte[] data, MapType type, int version) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace LibBSP {
|
||||
byte[] bytes = new byte[structLength];
|
||||
for (int i = 0; i < numProps; ++i) {
|
||||
Array.Copy(data, (dictionary.Length * 128) + (numLeafDefinitions * 2) + 12 + (i * structLength), bytes, 0, structLength);
|
||||
Add(new SourceStaticProp(bytes, type, version));
|
||||
Add(new StaticProp(bytes, type, version));
|
||||
offset += structLength;
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,18 @@ using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// <c>List</c><<c>Texture</c>> with some useful methods for manipulating <c>Texture</c> objects,
|
||||
/// <c>List</c><<see cref="Texture"/>> with some useful methods for manipulating <see cref="Texture"/> objects,
|
||||
/// especially when handling them as a group.
|
||||
/// </summary>
|
||||
public class Textures : List<Texture> {
|
||||
|
||||
/// <summary>
|
||||
/// Parses a <c>byte</c> array into this <c>List</c> of <c>Texture</c> objects
|
||||
/// Parses a <c>byte</c> array into this <c>List</c> of <see cref="Texture"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public Textures(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -101,8 +101,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the name of the texture at the specified offset.
|
||||
/// </summary>
|
||||
/// <param name="offset">Lump offset of the texture name to find</param>
|
||||
/// <returns>The name of the texture at offset <paramref name="offset" />, or null if it doesn't exist</returns>
|
||||
/// <param name="offset">Lump offset of the texture name to find.</param>
|
||||
/// <returns>The name of the texture at offset <paramref name="offset" />, or null if it doesn't exist.</returns>
|
||||
public string GetTextureAtOffset(uint offset) {
|
||||
int current = 0;
|
||||
for (int i = 0; i < Count; ++i) {
|
||||
@@ -120,12 +120,12 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Finds the offset of the specified texture name.
|
||||
/// </summary>
|
||||
/// <param name="inTexture">The texture name to find in the lump</param>
|
||||
/// <returns>The offset of the specified texture, or -1 if it wasn't found</returns>
|
||||
public int GetOffsetOf(string inTexture) {
|
||||
/// <param name="name">The texture name to find in the lump.</param>
|
||||
/// <returns>The offset of the specified texture, or -1 if it wasn't found.</returns>
|
||||
public int GetOffsetOf(string name) {
|
||||
int offset = 0;
|
||||
for (int i = 0; i < Count; ++i) {
|
||||
if (this[i].name.Equals(inTexture, StringComparison.CurrentCultureIgnoreCase)) {
|
||||
if (this[i].name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) {
|
||||
return offset;
|
||||
} else {
|
||||
offset += this[i].name.Length + 1;
|
||||
|
||||
@@ -3,8 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// An attempt at an all-encompassing model class containing all data needed for any
|
||||
/// given models lump in any given BSP.
|
||||
/// A class containing all data needed for the models lump in any given BSP.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// In general, we need to use models to find one or more leaves containing the
|
||||
@@ -25,12 +24,12 @@ namespace LibBSP {
|
||||
[Count("faces")] public int numFaces { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Model</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="Model"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public Model(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -107,13 +106,13 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>Model</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="Model"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>Model</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="Model"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public static List<Model> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -179,8 +178,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Raven:
|
||||
|
||||
@@ -10,14 +10,15 @@ namespace LibBSP {
|
||||
public int plane { get; private set; }
|
||||
public int child1 { get; private set; } // Negative values are valid here. However, the child can never be zero,
|
||||
public int child2 { get; private set; } // since that would reference the head node causing an infinite loop.
|
||||
// TODO: Other things in Node structure
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Node</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="Node"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public Node(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -64,13 +65,13 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>Node</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="Node"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>Node</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="Node"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public static List<Node> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -134,8 +135,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Raven:
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace LibBSP {
|
||||
using Vector3 = Vector3d;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Handles the data needed for one static prop.
|
||||
/// Handles the data needed for a static prop object.
|
||||
/// </summary>
|
||||
public struct SourceStaticProp {
|
||||
public struct StaticProp {
|
||||
|
||||
public Vector3 origin { get; private set; }
|
||||
public Vector3 angles { get; private set; }
|
||||
@@ -29,13 +29,14 @@ namespace LibBSP {
|
||||
public string targetname { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>SourceStaticProp</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="StaticProp"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
public SourceStaticProp(byte[] data, MapType type, int version) : this() {
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <param name="version">The version of static prop lump this object is a member of.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public StaticProp(byte[] data, MapType type, int version) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
@@ -103,14 +104,14 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to create a <c>SourceStaticProps</c> object.
|
||||
/// Factory method to create a <see cref="StaticProps"/> object.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <param name="version">The version of the Static Prop lump</param>
|
||||
/// <returns>A <c>SourceStaticProps</c> object</returns>
|
||||
public static SourceStaticProps LumpFactory(byte[] data, MapType type, int version) {
|
||||
return new SourceStaticProps(data, type, version);
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <param name="version">The version of the Static Prop lump.</param>
|
||||
/// <returns>A <see cref="StaticProps"/> object.</returns>
|
||||
public static StaticProps LumpFactory(byte[] data, MapType type, int version) {
|
||||
return new StaticProps(data, type, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,15 +29,15 @@ namespace LibBSP {
|
||||
public string mask { get; private set; } // Only used by MoHAA, "ignore" means it's unused
|
||||
public int flags { get; private set; }
|
||||
public int contents { get; private set; }
|
||||
public TexInfo texAxes { get; private set; }
|
||||
public TextureInfo texAxes { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Texture</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="Texture"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public Texture(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -46,7 +46,7 @@ namespace LibBSP {
|
||||
mask = "ignore";
|
||||
flags = 0;
|
||||
contents = 0;
|
||||
texAxes = null;
|
||||
texAxes = new TextureInfo();
|
||||
switch (type) {
|
||||
case MapType.Quake:
|
||||
case MapType.Nightfire: {
|
||||
@@ -56,7 +56,7 @@ namespace LibBSP {
|
||||
case MapType.Quake2:
|
||||
case MapType.SoF:
|
||||
case MapType.Daikatana: {
|
||||
texAxes = new TexInfo(new Vector3(BitConverter.ToSingle(data, 0), BitConverter.ToSingle(data, 4), BitConverter.ToSingle(data, 8)), BitConverter.ToSingle(data, 12), new Vector3(BitConverter.ToSingle(data, 16), BitConverter.ToSingle(data, 20), BitConverter.ToSingle(data, 24)), BitConverter.ToSingle(data, 28), -1, -1);
|
||||
texAxes = new TextureInfo(new Vector3(BitConverter.ToSingle(data, 0), BitConverter.ToSingle(data, 4), BitConverter.ToSingle(data, 8)), BitConverter.ToSingle(data, 12), new Vector3(BitConverter.ToSingle(data, 16), BitConverter.ToSingle(data, 20), BitConverter.ToSingle(data, 24)), BitConverter.ToSingle(data, 28), -1, -1);
|
||||
flags = BitConverter.ToInt32(data, 32);
|
||||
name = data.ToNullTerminatedString(40, 32);
|
||||
break;
|
||||
@@ -93,7 +93,7 @@ namespace LibBSP {
|
||||
break;
|
||||
}
|
||||
case MapType.SiN: {
|
||||
texAxes = new TexInfo(new Vector3(BitConverter.ToSingle(data, 0), BitConverter.ToSingle(data, 4), BitConverter.ToSingle(data, 8)), BitConverter.ToSingle(data, 12), new Vector3(BitConverter.ToSingle(data, 16), BitConverter.ToSingle(data, 20), BitConverter.ToSingle(data, 24)), BitConverter.ToSingle(data, 28), -1, -1);
|
||||
texAxes = new TextureInfo(new Vector3(BitConverter.ToSingle(data, 0), BitConverter.ToSingle(data, 4), BitConverter.ToSingle(data, 8)), BitConverter.ToSingle(data, 12), new Vector3(BitConverter.ToSingle(data, 16), BitConverter.ToSingle(data, 20), BitConverter.ToSingle(data, 24)), BitConverter.ToSingle(data, 28), -1, -1);
|
||||
flags = BitConverter.ToInt32(data, 32);
|
||||
name = data.ToNullTerminatedString(36, 64);
|
||||
break;
|
||||
@@ -105,11 +105,11 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>Textures</c> object.
|
||||
/// Factory method to parse a <c>byte</c> array into a <see cref="Textures"/> object.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>Textures</c> object</returns>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <see cref="Textures"/> object.</returns>
|
||||
public static Textures LumpFactory(byte[] data, MapType type) {
|
||||
return new Textures(data, type);
|
||||
}
|
||||
@@ -117,8 +117,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.CoD:
|
||||
@@ -166,8 +166,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for the materials lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForMaterialLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Nightfire: {
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace LibBSP {
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Contains all the information for a single SourceTexData object
|
||||
/// Contains all the information for a single Texture Data object.
|
||||
/// </summary>
|
||||
public struct SourceTexData {
|
||||
public struct TextureData {
|
||||
|
||||
public Vector3 reflectivity { get; private set; }
|
||||
public int stringTableIndex { get; private set; }
|
||||
@@ -26,12 +26,12 @@ namespace LibBSP {
|
||||
public int view_height { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>SourceTexData</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="TextureData"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
public SourceTexData(byte[] data, MapType type) : this() {
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
public TextureData(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
@@ -44,22 +44,22 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>SourceTexData</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="TextureData"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>SourceTexData</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
public static List<SourceTexData> LumpFactory(byte[] data, MapType type) {
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="TextureData"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
public static List<TextureData> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
int structLength = 32;
|
||||
List<SourceTexData> lump = new List<SourceTexData>(data.Length / structLength);
|
||||
List<TextureData> lump = new List<TextureData>(data.Length / structLength);
|
||||
byte[] bytes = new byte[structLength];
|
||||
for (int i = 0; i < data.Length / structLength; i++) {
|
||||
Array.Copy(data, (i * structLength), bytes, 0, structLength);
|
||||
lump.Add(new SourceTexData(bytes, type));
|
||||
lump.Add(new TextureData(bytes, type));
|
||||
}
|
||||
return lump;
|
||||
}
|
||||
@@ -67,8 +67,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Vindictus:
|
||||
@@ -15,19 +15,24 @@ namespace LibBSP {
|
||||
|
||||
/// <summary>
|
||||
/// This class contains the texture scaling information for certain formats.
|
||||
/// Some BSP formats lack this lump (or it is contained in a different one)
|
||||
/// so their cases will be left out.
|
||||
/// Some BSP formats lack this lump (or the information is contained in a
|
||||
/// different lump) so their cases will be left out.
|
||||
/// </summary>
|
||||
public class TexInfo {
|
||||
public struct TextureInfo {
|
||||
|
||||
public const int S = 0;
|
||||
public const int T = 1;
|
||||
public static readonly Vector3[] baseAxes = new Vector3[] { new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, -1, 0),
|
||||
new Vector3(0, 0, -1), new Vector3(1, 0, 0), new Vector3(0, -1, 0),
|
||||
new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, -1),
|
||||
new Vector3(-1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, -1),
|
||||
new Vector3(0, 1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, -1),
|
||||
new Vector3(0, -1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, -1) };
|
||||
/// <summary>
|
||||
/// Array of base texture axes. When referenced properly, provides a good default texture axis for any given plane.
|
||||
/// </summary>
|
||||
public static readonly Vector3[] baseAxes = new Vector3[] {
|
||||
new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, -1, 0),
|
||||
new Vector3(0, 0, -1), new Vector3(1, 0, 0), new Vector3(0, -1, 0),
|
||||
new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, -1),
|
||||
new Vector3(-1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, -1),
|
||||
new Vector3(0, 1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, -1),
|
||||
new Vector3(0, -1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, -1)
|
||||
};
|
||||
|
||||
public Vector3[] axes { get; private set; }
|
||||
public float[] shifts { get; private set; }
|
||||
@@ -35,16 +40,18 @@ namespace LibBSP {
|
||||
public int texture { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>TexInfo</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="TextureInfo"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
public TexInfo(byte[] data, MapType type) {
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public TextureInfo(byte[] data, MapType type) : this() {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
texture = -1;
|
||||
flags = -1;
|
||||
axes = new Vector3[2];
|
||||
shifts = new float[2];
|
||||
axes[S] = new Vector3(BitConverter.ToSingle(data, 0), BitConverter.ToSingle(data, 4), BitConverter.ToSingle(data, 8));
|
||||
@@ -87,15 +94,15 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>TexInfo</c> object using the passed data.
|
||||
/// Creates a new <see cref="TextureInfo"/> object using the passed data.
|
||||
/// </summary>
|
||||
/// <param name="s">The S texture axis</param>
|
||||
/// <param name="SShift">The texture shift on the S axis</param>
|
||||
/// <param name="t">The T texture axis</param>
|
||||
/// <param name="TShift">The texture shift on the T axis</param>
|
||||
/// <param name="flags">The flags for this <c>TexInfo</c></param>
|
||||
/// <param name="texture">Index into the texture list for the texture this <c>TexInfo</c> uses</param>
|
||||
public TexInfo(Vector3 s, float SShift, Vector3 t, float TShift, int flags, int texture) {
|
||||
/// <param name="s">The S texture axis.</param>
|
||||
/// <param name="SShift">The texture shift on the S axis.</param>
|
||||
/// <param name="t">The T texture axis.</param>
|
||||
/// <param name="TShift">The texture shift on the T axis.</param>
|
||||
/// <param name="flags">The flags for this <see cref="TextureInfo"/>.</param>
|
||||
/// <param name="texture">Index into the texture list for the texture this <see cref="TextureInfo"/> uses.</param>
|
||||
public TextureInfo(Vector3 s, float SShift, Vector3 t, float TShift, int flags, int texture) : this() {
|
||||
axes = new Vector3[2];
|
||||
axes[S] = s;
|
||||
axes[T] = t;
|
||||
@@ -111,15 +118,14 @@ namespace LibBSP {
|
||||
/// permission because it falls under the terms of the GPL v2 license, because I'm not making
|
||||
/// any money, just awesome tools.
|
||||
/// </summary>
|
||||
/// <param name="p"><c>Plane</c> of the surface</param>
|
||||
/// <returns>The best matching texture axes for the given <c>Plane</c></returns>
|
||||
/// <param name="p"><see cref="Plane"/> of the surface.</param>
|
||||
/// <returns>The best matching texture axes for the given <see cref="Plane"/>.</returns>
|
||||
public static Vector3[] TextureAxisFromPlane(Plane p) {
|
||||
int bestaxis = 0;
|
||||
double dot; // Current dot product
|
||||
double best = 0; // "Best" dot product so far
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
// For all possible axes, positive and negative
|
||||
dot = Vector3.Dot(p.normal, new Vector3(baseAxes[i * 3][0], baseAxes[i * 3][1], baseAxes[i * 3][2]));
|
||||
double dot = Vector3.Dot(p.normal, new Vector3(baseAxes[i * 3][0], baseAxes[i * 3][1], baseAxes[i * 3][2]));
|
||||
if (dot > best) {
|
||||
best = dot;
|
||||
bestaxis = i;
|
||||
@@ -132,14 +138,14 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <c>TexInfo</c> objects.
|
||||
/// Factory method to parse a <c>byte</c> array into a <c>List</c> of <see cref="TextureInfo"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse</param>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>A <c>List</c> of <c>TexInfo</c> objects</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
|
||||
public static List<TexInfo> LumpFactory(byte[] data, MapType type) {
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>A <c>List</c> of <see cref="TextureInfo"/> objects.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was null.</exception>
|
||||
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
|
||||
public static List<TextureInfo> LumpFactory(byte[] data, MapType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
@@ -174,11 +180,11 @@ namespace LibBSP {
|
||||
throw new ArgumentException("Map type " + type + " isn't supported by the Leaf lump factory.");
|
||||
}
|
||||
}
|
||||
List<TexInfo> lump = new List<TexInfo>(data.Length / structLength);
|
||||
List<TextureInfo> lump = new List<TextureInfo>(data.Length / structLength);
|
||||
byte[] bytes = new byte[structLength];
|
||||
for (int i = 0; i < data.Length / structLength; ++i) {
|
||||
Array.Copy(data, (i * structLength), bytes, 0, structLength);
|
||||
lump.Add(new TexInfo(bytes, type));
|
||||
lump.Add(new TextureInfo(bytes, type));
|
||||
}
|
||||
return lump;
|
||||
}
|
||||
@@ -186,8 +192,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for this lump in the BSP file for a specific map format.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
|
||||
public static int GetIndexForLump(MapType type) {
|
||||
switch (type) {
|
||||
case MapType.Quake:
|
||||
@@ -16,16 +16,17 @@ namespace LibBSP {
|
||||
using Vector4 = Vector4d;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Class containing all data for a single <c>Entity</c>, including attributes, Source Entity I/O connections and solids.
|
||||
/// Class containing all data for a single <see cref="Entity"/>, including attributes, Source Entity I/O connections and solids.
|
||||
/// </summary>
|
||||
[Serializable] public class Entity : Dictionary<string, string>, IComparable, IComparable<Entity> {
|
||||
|
||||
public const char ConnectionMemberSeparater = (char)0x1B;
|
||||
|
||||
public List<EntityConnection> connections = new List<EntityConnection>();
|
||||
public List<MAPBrush> brushes = new List<MAPBrush>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this <c>Entity</c> is brush-based or not.
|
||||
/// Gets whether this <see cref="Entity"/> is brush-based or not.
|
||||
/// </summary>
|
||||
public bool brushBased { get { return brushes.Count > 0 || modelNumber >= 0; } }
|
||||
|
||||
@@ -128,14 +129,14 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows an attribute to be accessed easily using <c>Entity</c>["<paramref name="key" />"] notation.
|
||||
/// If an attribute doesn't exist, it returns the empty <c>string</c>. This emulates the behavior of the engines.
|
||||
/// Allows an attribute to be accessed easily using <see cref="Entity"/>["<paramref name="key"/>"] notation.
|
||||
/// If an attribute doesn't exist, it returns an empty <c>string</c>. This emulates the behavior of game engines.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It's up to the developer to ensure the empty string doesn't cause problems, rather than returning null!
|
||||
/// It's up to the developer to ensure the empty string doesn't cause problems, because this won't return <c>null</c>.
|
||||
/// </remarks>
|
||||
/// <param name="key">The attribute to retrieve</param>
|
||||
/// <returns>The value of the attribute if it exists, empty <c>string</c> otherwise</returns>
|
||||
/// <param name="key">The attribute to retrieve.</param>
|
||||
/// <returns>The value of the attribute if it exists, empty <c>string</c> otherwise.</returns>
|
||||
public new string this[string key] {
|
||||
get {
|
||||
if (ContainsKey(key)) {
|
||||
@@ -148,37 +149,37 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of an <c>Entity</c>, parsing the given <c>byte</c> array into an <c>Entity</c> structure.
|
||||
/// Initializes a new instance of an <see cref="Entity"/>, parsing the given <c>byte</c> array into an <see cref="Entity"/> structure.
|
||||
/// </summary>
|
||||
/// <param name="data">Array to parse</param>
|
||||
/// <param name="data">Array to parse.</param>
|
||||
public Entity(byte[] data, MapType type) : this(Encoding.ASCII.GetString(data).Split('\n')) { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of an <c>Entity</c> with the given classname.
|
||||
/// Initializes a new instance of an <see cref="Entity"/> with the given classname.
|
||||
/// </summary>
|
||||
/// <param name="className">Classname of the new <C>Entity</C></param>
|
||||
/// <param name="className">Classname of the new <see cref="Entity"/>.</param>
|
||||
public Entity(string className) : base(StringComparer.InvariantCultureIgnoreCase) {
|
||||
Add("classname", className);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of an <c>Entity</c> object with no initial properties.
|
||||
/// Initializes a new instance of an <see cref="Entity"/> object with no initial properties.
|
||||
/// </summary>
|
||||
public Entity() : base(StringComparer.InvariantCultureIgnoreCase) { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of an <c>Entity</c> object, copying the attributes, connections and brushes of the passed <c>Entity</c>.
|
||||
/// Initializes a new instance of an <see cref="Entity"/> object, copying the attributes, connections and brushes of the passed <see cref="Entity"/>.
|
||||
/// </summary>
|
||||
/// <param name="copy">The <c>Entity</c> to copy</param>
|
||||
/// <param name="copy">The <see cref="Entity"/> to copy.</param>
|
||||
public Entity(Entity copy) : base(copy, StringComparer.InvariantCultureIgnoreCase) {
|
||||
connections = new List<EntityConnection>(copy.connections);
|
||||
brushes = new List<MAPBrush>(copy.brushes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of an <c>Entity</c>, parsing the given <c>string</c> array into an <c>Entity</c> structure.
|
||||
/// Initializes a new instance of an <see cref="Entity"/>, parsing the given <c>string</c> array into an <see cref="Entity"/> structure.
|
||||
/// </summary>
|
||||
/// <param name="lines">Array of attributes, patches, brushes, displacements etc. to parse</param>
|
||||
/// <param name="lines">Array of <c>string</c>s representing attributes, patches, brushes, displacements etc. to parse.</param>
|
||||
public Entity(string[] lines) : base(StringComparer.InvariantCultureIgnoreCase) {
|
||||
int braceCount = 0;
|
||||
|
||||
@@ -248,23 +249,23 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method to create an <c>Entity</c> from a <c>string</c> "<paramref name="st" />" where
|
||||
/// "<paramref name="st" />" contains all lines for the entity, including attributes, brushes, etc.
|
||||
/// Factory method to create an <see cref="Entity"/> from a <c>string</c> "<paramref name="st"/>" where
|
||||
/// "<paramref name="st"/>" contains all lines for the entity, including attributes, brushes, etc.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This was necessary since the <c>Entity</c>(<c>string</c>) constructor was already used in a different way
|
||||
/// This was necessary since the <see cref="Entity(System.String)"/> constructor was already used in a different way.
|
||||
/// </remarks>
|
||||
/// <param name="st">The data to parse</param>
|
||||
/// <returns>The resulting <c>Entity</c> object</returns>
|
||||
/// <param name="st">The data to parse.</param>
|
||||
/// <returns>The resulting <see cref="Entity"/> object.</returns>
|
||||
public static Entity FromString(string st) {
|
||||
return new Entity(st.Split('\n'));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renames the attribute named "<paramref name="oldName" />" to "<paramref name="newName" />". Replaces the old entry if it already exists.
|
||||
/// Renames the attribute named "<paramref name="oldName"/>" to "<paramref name="newName"/>". Replaces the old entry if it already exists.
|
||||
/// </summary>
|
||||
/// <param name="oldName">Attribute to be renamed</param>
|
||||
/// <param name="newName">New name for this attribute</param>
|
||||
/// <param name="oldName">Attribute to be renamed.</param>
|
||||
/// <param name="newName">New name for this attribute.</param>
|
||||
public void RenameKey(string oldName, string newName) {
|
||||
if (ContainsKey(oldName)) {
|
||||
string val = this[oldName];
|
||||
@@ -277,10 +278,10 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the input <c>string</c> "<paramref name="st" />" into a key/value pair and adds
|
||||
/// it as an attribute to this <c>Entity</c>
|
||||
/// Parses the input <c>string</c> "<paramref name="st"/>" into a key/value pair and adds
|
||||
/// it as an attribute to this <see cref="Entity"/>.
|
||||
/// </summary>
|
||||
/// <param name="st">The <c>string</c> to be parsed</param>
|
||||
/// <param name="st">The <c>string</c> to be parsed.</param>
|
||||
public void Add(string st) {
|
||||
string key = "";
|
||||
string val = "";
|
||||
@@ -337,9 +338,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <c>string</c> representation of this <c>Entity</c>.
|
||||
/// Gets a <c>string</c> representation of this <see cref="Entity"/>.
|
||||
/// </summary>
|
||||
/// <returns><c>string</c> representation of this <c>Entity</c>.</returns>
|
||||
/// <returns><c>string</c> representation of this <see cref="Entity"/>.</returns>
|
||||
public override string ToString() {
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.Append("{\n");
|
||||
@@ -357,7 +358,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the attribute named "<paramref name="key" />" has the value "<paramref name="value" />".
|
||||
/// Checks if the attribute named "<paramref name="key"/>" has the value "<paramref name="value"/>".
|
||||
/// </summary>
|
||||
/// <param name="key">The attribute to check.</param>
|
||||
/// <param name="value">The value to compare.</param>
|
||||
@@ -367,16 +368,16 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the bits in "spawnflags" corresponding to the set bits set in <paramref name="bits" /> are set.
|
||||
/// Checks if the bits in "spawnflags" corresponding to the set bits set in <paramref name="bits"/> are set.
|
||||
/// </summary>
|
||||
/// <param name="bits">The bits to compare spawnflags to.</param>
|
||||
/// <returns><c>true</c> if all bits that were set in <paramref name="bits" /> were set in spawnflags.</returns>
|
||||
/// <returns><c>true</c> if all bits that were set in <paramref name="bits"/> were set in spawnflags.</returns>
|
||||
public bool SpawnflagsSet(uint bits) {
|
||||
return ((spawnflags & bits) == bits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggles the bits in "spawnflags" which are set in <paramref name="bits" />.
|
||||
/// Toggles the bits in "spawnflags" which are set in <paramref name="bits"/>.
|
||||
/// </summary>
|
||||
/// <param name="bits">Bitmask of bits to toggle.</param>
|
||||
public void ToggleSpawnflags(uint bits) {
|
||||
@@ -384,8 +385,8 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the bits in "spawnflags" which are set in <paramref name="bits" />.
|
||||
/// Equivalent to spawnflags = (<paramref name="bits" /> ^ 0xFFFFFFFF) & spawnflags.
|
||||
/// Clears the bits in "spawnflags" which are set in <paramref name="bits"/>.
|
||||
/// Equivalent to spawnflags = (<paramref name="bits"/> ^ 0xFFFFFFFF) & spawnflags.
|
||||
/// </summary>
|
||||
/// <param name="bits">Bitmask of bits to clear.</param>
|
||||
public void ClearSpawnflags(uint bits) {
|
||||
@@ -393,7 +394,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the bits in "spawnflags" which are set in <paramref name="bits" />.
|
||||
/// Sets the bits in "spawnflags" which are set in <paramref name="bits"/>.
|
||||
/// </summary>
|
||||
/// <param name="bits">Bitmask of bits to set.</param>
|
||||
public void SetSpawnflags(uint bits) {
|
||||
@@ -405,8 +406,8 @@ namespace LibBSP {
|
||||
/// and no <paramref name="failDefault"/> was provided.
|
||||
/// </summary>
|
||||
/// <param name="key">Name of the attribute to retrieve.</param>
|
||||
/// <param name="failDefault">Value to return if <paramref name="key" /> doesn't exist, or couldn't be converted.</param>
|
||||
/// <returns>The numeric value of the value corresponding to <paramref name="key" />.</returns>
|
||||
/// <param name="failDefault">Value to return if <paramref name="key"/> doesn't exist, or couldn't be converted.</param>
|
||||
/// <returns>The numeric value of the value corresponding to <paramref name="key"/>.</returns>
|
||||
public float GetFloat(string key, float? failDefault = null) {
|
||||
try {
|
||||
return Single.Parse(this[key]);
|
||||
@@ -423,8 +424,8 @@ namespace LibBSP {
|
||||
/// and no <paramref name="failDefault"/> was provided.
|
||||
/// </summary>
|
||||
/// <param name="key">Name of the attribute to retrieve.</param>
|
||||
/// <param name="failDefault">Value to return if <paramref name="key" /> doesn't exist, or couldn't be converted.</param>
|
||||
/// <returns>The numeric value of the value corresponding to <paramref name="key" />.</returns>
|
||||
/// <param name="failDefault">Value to return if <paramref name="key"/> doesn't exist, or couldn't be converted.</param>
|
||||
/// <returns>The numeric value of the value corresponding to <paramref name="key"/>.</returns>
|
||||
public int GetInt(string key, int? failDefault = null) {
|
||||
try {
|
||||
return Int32.Parse(this[key]);
|
||||
@@ -437,8 +438,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Vector attribute as a <c>Vector4</c>. This will only read as many values as are in the attribute, and can be
|
||||
/// implicitly converted to <c>Vector3</c>, <c>Vector2</c>, or <c>Color</c>.
|
||||
/// Gets a Vector attribute as a <see cref="Vector4"/>. This will only read as many values as are in the attribute.
|
||||
/// </summary>
|
||||
/// <param name="key">Name of the attribute to retrieve.</param>
|
||||
/// <returns>Vector representation of the components of the attribute.</returns>
|
||||
@@ -458,12 +458,12 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this <c>Entity</c> to another object. First "classname" attributes are compared, then "targetname".
|
||||
/// Compares this <see cref="Entity"/> to another object. First "classname" attributes are compared, then "targetname".
|
||||
/// Attributes are compared alphabetically. Targetnames are only compared if classnames match.
|
||||
/// </summary>
|
||||
/// <param name="obj"><c>Object</c> to compare to.</param>
|
||||
/// <returns>Less than zero if this entity is first, 0 if they occur at the same time, greater than zero otherwise.</returns>
|
||||
/// <exception cref="ArgumentException"><paramref name="obj"/> was not of type <c>Entity</c>.</exception>
|
||||
/// <exception cref="ArgumentException"><paramref name="obj"/> was not of type <see cref="Entity"/>.</exception>
|
||||
public int CompareTo(object obj) {
|
||||
if (obj == null) { return 1; }
|
||||
Entity other = obj as Entity;
|
||||
@@ -474,10 +474,10 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this <c>Entity</c> to another <c>Entity</c>. First "classname" attributes are compared, then "targetname".
|
||||
/// Compares this <see cref="Entity"/> to another <see cref="Entity"/>. First "classname" attributes are compared, then "targetname".
|
||||
/// Attributes are compared alphabetically. Targetnames are only compared if classnames match.
|
||||
/// </summary>
|
||||
/// <param name="other"><c>Entity</c> to compare to.</param>
|
||||
/// <param name="other"><see cref="Entity"/> to compare to.</param>
|
||||
/// <returns>Less than zero if this entity is first, 0 if they occur at the same time, greater than zero otherwise.</returns>
|
||||
public int CompareTo(Entity other) {
|
||||
if (other == null) { return 1; }
|
||||
@@ -486,11 +486,11 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory method for an <c>Entities</c> object from a <c>byte</c> array.
|
||||
/// Factory method for an <see cref="Entities"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to parse.</param>
|
||||
/// <param name="type">The map type.</param>
|
||||
/// <returns>An <c>Entities</c> object, which is a <c>List</c> of <c>Entity</c>s.</returns>
|
||||
/// <returns>An <see cref="Entities"/> object, which is a <c>List</c> of <see cref="Entity"/>s.</returns>
|
||||
public static Entities LumpFactory(byte[] data, MapType type) {
|
||||
return new Entities(data, type);
|
||||
}
|
||||
|
||||
@@ -3,29 +3,29 @@ using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Class representing a group of <c>Entity</c> objects. Contains helpful methods to handle Entities in the <c>List</c>.
|
||||
/// Class representing a group of <see cref="Entity"/> objects. Contains helpful methods to handle Entities in the <c>List</c>.
|
||||
/// </summary>
|
||||
public class Entities : List<Entity> {
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of an <c>Entities</c> object copying a passed <c>IEnumerable</c> of <c>Entity</c> objects.
|
||||
/// Initializes a new instance of an <see cref="Entities"/> object copying a passed <c>IEnumerable</c> of <see cref="Entity"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="data">Collection of <c>Entity</c> objects to copy.</param>
|
||||
/// <param name="data">Collection of <see cref="Entity"/> objects to copy.</param>
|
||||
public Entities(IEnumerable<Entity> data) : base(data) { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of an <c>Entities</c> object with a specified initial capacity.
|
||||
/// Initializes a new instance of an <see cref="Entities"/> object with a specified initial capacity.
|
||||
/// </summary>
|
||||
/// <param name="initialCapacity">Initial capacity of the <c>List</c> of <c>Entity</c> objects.</param>
|
||||
/// <param name="initialCapacity">Initial capacity of the <c>List</c> of <see cref="Entity"/> objects.</param>
|
||||
public Entities(int initialCapacity) : base(initialCapacity) { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new empty <c>Entities</c> object.
|
||||
/// Initializes a new empty <see cref="Entities"/> object.
|
||||
/// </summary>
|
||||
public Entities() : base() { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <c>Entities</c> object, and parses the passed <c>byte</c> array into the <c>List</c>.
|
||||
/// Initializes a new <see cref="Entities"/> object, and parses the passed <c>byte</c> array into the <c>List</c>.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>Byte</c>s read from a file.</param>
|
||||
public Entities(byte[] data, MapType type) : base() {
|
||||
@@ -84,7 +84,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all <c>Entity</c> with "<paramref name="key" />" set to "<paramref name="value" />".
|
||||
/// Deletes all <see cref="Entity"/> objects with "<paramref name="key"/>" set to "<paramref name="value"/>".
|
||||
/// </summary>
|
||||
/// <param name="key">Attribute to match.</param>
|
||||
/// <param name="value">Desired value of attribute.</param>
|
||||
@@ -93,36 +93,36 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <c>List</c> of all <c>Entity</c>s with "<paramref name="key" />" set to "<paramref name="value" />".
|
||||
/// Gets a <c>List</c> of all <see cref="Entity"/> objects with "<paramref name="key"/>" set to "<paramref name="value"/>".
|
||||
/// </summary>
|
||||
/// <param name="key">Name of the attribute to search for.</param>
|
||||
/// <param name="value">Value of the attribute to search for.</param>
|
||||
/// <returns><c>List</c>(<c>Entity</c>) that have the specified key/value pair.</returns>
|
||||
/// <returns><c>List</c><<see cref="Entity"/>> that have the specified key/value pair.</returns>
|
||||
public List<Entity> GetAllWithAttribute(string key, string value) {
|
||||
return FindAll(entity => { return entity[key].Equals(value, StringComparison.InvariantCultureIgnoreCase); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <c>List</c> of <c>Entity</c>s objects with the specified targetname.
|
||||
/// Gets a <c>List</c> of <see cref="Entity"/>s objects with the specified targetname.
|
||||
/// </summary>
|
||||
/// <param name="targetname">Targetname attribute to find.</param>
|
||||
/// <returns><c>List</c>(<c>Entity</c>) with the specified targetname.</returns>
|
||||
/// <returns><c>List</c><<see cref="Entity"/>> with the specified targetname.</returns>
|
||||
public List<Entity> GetAllWithName(string targetname) {
|
||||
return FindAll(entity => { return entity.name.Equals(targetname, StringComparison.InvariantCultureIgnoreCase); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first <c>Entity</c> with "<paramref name="key" />" set to "<paramref name="value" />".
|
||||
/// Gets the first <see cref="Entity"/> with "<paramref name="key"/>" set to "<paramref name="value"/>".
|
||||
/// </summary>
|
||||
/// <param name="key">Name of the attribute to search for.</param>
|
||||
/// <param name="value">Value of the attribute to search for.</param>
|
||||
/// <returns><c>Entity</c> with the specified key/value pair, or null if none exists.</returns>
|
||||
/// <returns><see cref="Entity"/> with the specified key/value pair, or null if none exists.</returns>
|
||||
public Entity GetWithAttribute(string key, string value) {
|
||||
return Find(entity => { return entity[key].Equals(value, StringComparison.InvariantCultureIgnoreCase); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first <c>Entity</c> with the specified targetname.
|
||||
/// Gets the first <see cref="Entity"/> with the specified targetname.
|
||||
/// </summary>
|
||||
/// <param name="targetname">Targetname attribute to find.</param>
|
||||
/// <returns>Entity object with the specified targetname.</returns>
|
||||
|
||||
@@ -21,12 +21,12 @@ namespace LibBSP {
|
||||
public DataType type { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>NumList</c> object from a <c>byte</c> array.
|
||||
/// Creates a new <see cref="NumList"/> object from a <c>byte</c> array.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The type of number to store</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
|
||||
/// <exception cref="ArgumentException"><paramref name="type" /> was not a member of the DataType enum</exception>
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The type of number to store.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException"><paramref name="type"/> was not a member of the DataType enum.</exception>
|
||||
public NumList(byte[] data, DataType type) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -84,11 +84,11 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>NumList</c> object from a <c>byte</c> array and returns it.
|
||||
/// Creates a new <see cref="NumList"/> object from a <c>byte</c> array and returns it.
|
||||
/// </summary>
|
||||
/// <param name="data"><c>byte</c> array to parse</param>
|
||||
/// <param name="type">The type of number to store</param>
|
||||
/// <returns>The resulting <c>NumList</c></returns>
|
||||
/// <param name="data"><c>byte</c> array to parse.</param>
|
||||
/// <param name="type">The type of number to store.</param>
|
||||
/// <returns>The resulting <see cref="NumList"/>.</returns>
|
||||
public static NumList LumpFactory(byte[] data, DataType type) {
|
||||
return new NumList(data, type);
|
||||
}
|
||||
@@ -97,9 +97,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for the Mark Surfaces lump in the BSP file for a specific map format, and the type of data the format uses.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <param name="dataType"><c>out</c> parameter for the data type this version uses</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented</returns>
|
||||
/// <param name="version">The map type.</param>
|
||||
/// <param name="dataType"><c>out</c> parameter that will contain the data type this version uses.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented.</returns>
|
||||
public static int GetIndexForMarkSurfacesLump(MapType version, out DataType dataType) {
|
||||
switch (version) {
|
||||
case MapType.Raven:
|
||||
@@ -157,9 +157,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for the Surface Edges lump in the BSP file for a specific map format, and the type of data the format uses.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <param name="dataType"><c>out</c> parameter for the data type this version uses</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented</returns>
|
||||
/// <param name="version">The map type.</param>
|
||||
/// <param name="dataType"><c>out</c> parameter that will contain data type this version uses.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented.</returns>
|
||||
public static int GetIndexForSurfEdgesLump(MapType version, out DataType dataType) {
|
||||
switch (version) {
|
||||
case MapType.Quake2:
|
||||
@@ -192,9 +192,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for the Mark Brushes lump in the BSP file for a specific map format, and the type of data the format uses.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <param name="dataType"><c>out</c> parameter for the data type this version uses</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented</returns>
|
||||
/// <param name="version">The map type.</param>
|
||||
/// <param name="dataType"><c>out</c> parameter that will contain the data type this version uses.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented.</returns>
|
||||
public static int GetIndexForMarkBrushesLump(MapType version, out DataType dataType) {
|
||||
switch (version) {
|
||||
case MapType.Quake3:
|
||||
@@ -244,9 +244,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for the indices lump in the BSP file for a specific map format, and the type of data the format uses.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <param name="dataType"><c>out</c> parameter for the data type this version uses</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented</returns>
|
||||
/// <param name="version">The map type.</param>
|
||||
/// <param name="dataType"><c>out</c> parameter that will contain the data type this version uses.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented.</returns>
|
||||
public static int GetIndexForIndicesLump(MapType version, out DataType dataType) {
|
||||
switch (version) {
|
||||
case MapType.FAKK:
|
||||
@@ -276,9 +276,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for the texture table lump in the BSP file for a specific map format, and the type of data the format uses.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <param name="dataType"><c>out</c> parameter for the data type this version uses</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented</returns>
|
||||
/// <param name="version">The map type.</param>
|
||||
/// <param name="dataType"><c>out</c> parameter that will contain the data type this version uses.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented.</returns>
|
||||
public static int GetIndexForTexTableLump(MapType version, out DataType dataType) {
|
||||
switch (version) {
|
||||
case MapType.Vindictus:
|
||||
@@ -303,9 +303,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the index for the displacement triangles lump in the BSP file for a specific map format, and the type of data the format uses.
|
||||
/// </summary>
|
||||
/// <param name="type">The map type</param>
|
||||
/// <param name="dataType"><c>out</c> parameter for the data type this version uses</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented</returns>
|
||||
/// <param name="version">The map type.</param>
|
||||
/// <param name="dataType"><c>out</c> parameter that will contain the data type this version uses.</param>
|
||||
/// <returns>Index for this lump, or -1 if the format doesn't have this lump or it's not implemented.</returns>
|
||||
public static int GetIndexForDisplacementTrianglesLump(MapType version, out DataType dataType) {
|
||||
switch (version) {
|
||||
case MapType.Vindictus:
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <c>a</c> component of this <c>Plane</c>
|
||||
/// The <c>a</c> component of this <see cref="Plane"/>.
|
||||
/// </summary>
|
||||
public double a {
|
||||
get {
|
||||
@@ -28,7 +28,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <c>b</c> component of this <c>Plane</c>
|
||||
/// The <c>b</c> component of this <see cref="Plane"/>.
|
||||
/// </summary>
|
||||
public double b {
|
||||
get {
|
||||
@@ -37,7 +37,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <c>c</c> component of this <c>Plane</c>
|
||||
/// The <c>c</c> component of this <see cref="Plane"/>.
|
||||
/// </summary>
|
||||
public double c {
|
||||
get {
|
||||
@@ -46,7 +46,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This <c>Plane</c>, flipped over so the negative side is now the positive side, and vice versa.
|
||||
/// This <see cref="Plane"/>, flipped over so the negative side is now the positive side, and vice versa.
|
||||
/// </summary>
|
||||
public Plane flipped {
|
||||
get {
|
||||
@@ -55,11 +55,11 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Plane</c> object using <c>float</c>s. The first three <c>float</c>s are the normal, and the last one is the distance.
|
||||
/// Creates a new <see cref="Plane"/> object using <c>float</c>s. The first three <c>float</c>s are the normal, and the last one is the distance.
|
||||
/// </summary>
|
||||
/// <param name="nums">Components of this <c>Plane</c></param>
|
||||
/// <exception cref="ArgumentException">4 <c>float</c>s were not passed</exception>
|
||||
/// <exception cref="ArgumentNullException">The passed array was null</exception>
|
||||
/// <param name="nums">Components of this <see cref="Plane"/>.</param>
|
||||
/// <exception cref="ArgumentException">4 <c>float</c>s were not passed.</exception>
|
||||
/// <exception cref="ArgumentNullException">The passed array was <c>null</c>.</exception>
|
||||
public Plane(params float[] nums) {
|
||||
if (nums == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -73,11 +73,11 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Plane</c> object using <c>double</c>s. The first three <c>double</c>s are the normal, and the last one is the distance.
|
||||
/// Creates a new <see cref="Plane"/> object using <c>double</c>s. The first three <c>double</c>s are the normal, and the last one is the distance.
|
||||
/// </summary>
|
||||
/// <param name="nums">Components of this <c>Plane</c></param>
|
||||
/// <exception cref="ArgumentException">4 <c>double</c>s were not passed</exception>
|
||||
/// <exception cref="ArgumentNullException">The passed array was null</exception>
|
||||
/// <param name="nums">Components of this <see cref="Plane"/>.</param>
|
||||
/// <exception cref="ArgumentException">4 <c>double</c>s were not passed.</exception>
|
||||
/// <exception cref="ArgumentNullException">The passed array was <c>null</c>.</exception>
|
||||
public Plane(params double[] nums) {
|
||||
if (nums == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -91,10 +91,10 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Plane</c> object using a normal and distance.
|
||||
/// Creates a new <see cref="Plane"/> object using a normal and distance.
|
||||
/// </summary>
|
||||
/// <param name="normal">Normal of this <c>Plane</c></param>
|
||||
/// <param name="dist">Distance from the origin to this <c>Plane</c></param>
|
||||
/// <param name="normal">Normal of this <see cref="Plane"/>.</param>
|
||||
/// <param name="dist">Distance from the origin to this <see cref="Plane"/>.</param>
|
||||
public Plane(Vector3d normal, double dist) {
|
||||
this._normal = new Vector3d(normal);
|
||||
_normal.Normalize();
|
||||
@@ -102,26 +102,26 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Plane</c> object using a normal and distance.
|
||||
/// Creates a new <see cref="Plane"/> object using a normal and distance.
|
||||
/// </summary>
|
||||
/// <param name="normal">Normal of this <c>Plane</c></param>
|
||||
/// <param name="dist">Distance from the origin to this <c>Plane</c></param>
|
||||
/// <param name="normal">Normal of this <see cref="Plane"/>.</param>
|
||||
/// <param name="dist">Distance from the origin to this <see cref="Plane"/>.</param>
|
||||
public Plane(Vector3d normal, float dist) : this(normal, Convert.ToDouble(dist)) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Plane</c> object by copying another <c>Plane</c>.
|
||||
/// Creates a new <see cref="Plane"/> object by copying another <see cref="Plane"/>.
|
||||
/// </summary>
|
||||
/// <param name="copy"><c>Plane</c> to copy.</param>
|
||||
/// <param name="copy"><see cref="Plane"/> to copy.</param>
|
||||
public Plane(Plane copy) {
|
||||
_normal = new Vector3d(copy.normal);
|
||||
distance = copy.distance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Plane</c> object using a normal and a point on the <c>Plane</c>.
|
||||
/// Creates a new <see cref="Plane"/> object using a normal and a point on the <see cref="Plane"/>.
|
||||
/// </summary>
|
||||
/// <param name="normal">Normal of this <c>Plane</c></param>
|
||||
/// <param name="point">A point on this <c>Plane</c></param>
|
||||
/// <param name="normal">Normal of this <see cref="Plane"/>.</param>
|
||||
/// <param name="point">A point on this <see cref="Plane"/>.</param>
|
||||
public Plane(Vector3d normal, Vector3d point) {
|
||||
this._normal = normal;
|
||||
_normal.Normalize();
|
||||
@@ -129,35 +129,39 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Plane</c> object using three points on the <c>Plane</c>.
|
||||
/// Creates a new <see cref="Plane"/> object using three points on the <see cref="Plane"/>.
|
||||
/// </summary>
|
||||
/// <param name="point0">A point on the <c>Plane</c></param>
|
||||
/// <param name="point1">A point on the <c>Plane</c></param>
|
||||
/// <param name="point2">A point on the <c>Plane</c></param>
|
||||
/// <param name="point0">A point on the <see cref="Plane"/>.</param>
|
||||
/// <exception cref="ArgumentNullException"><param name="points"/> is <c>null</c>.</exception>
|
||||
/// <exception cref="ArgumentException">3 <see cref="Vector3d"/>s were not passed.</exception>
|
||||
public Plane(params Vector3d[] points) {
|
||||
if (points == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
if (points.Length < 3) {
|
||||
throw new ArgumentException("Plane constructor was not given enough points to define a plane");
|
||||
throw new ArgumentException("Plane constructor was not given enough points to define a plane.");
|
||||
}
|
||||
_normal = ((points[0] - points[2]) ^ (points[0] - points[1]));
|
||||
_normal.Normalize();
|
||||
distance = points[0] * _normal;
|
||||
}
|
||||
|
||||
#region IEquatable
|
||||
/// <summary>
|
||||
/// Determines whether this <c>Plane</c> is equal to another <c>object</c>.
|
||||
/// Determines whether this <see cref="Plane"/> is equal to another <c>object</c>.
|
||||
/// </summary>
|
||||
/// <param name="obj"><c>object</c> to compare to</param>
|
||||
/// <returns>Whether <paramref name="obj" /> is a <c>Plane</c> and is equal to this <c>Plane</c></returns>
|
||||
/// <param name="obj"><c>object</c> to compare to.</param>
|
||||
/// <returns>Whether <paramref name="obj"/> is a <see cref="Plane"/> and is equal to this <see cref="Plane"/>.</returns>
|
||||
public override bool Equals(object obj) {
|
||||
if (object.ReferenceEquals(obj, null) || !GetType().IsAssignableFrom(obj.GetType())) { return false; }
|
||||
return Equals((Plane)obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares whether two <c>Plane</c>s are equal, or approximately equal.
|
||||
/// Compares whether two <see cref="Plane"/>s are equal, or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="other">The <c>Plane</c> to compare to</param>
|
||||
/// <returns><c>true</c> if this <c>Plane</c> is parallel to, faces the same direction, and has the same distance as, the given <c>Plane</c>.</returns>
|
||||
/// <param name="other">The <see cref="Plane"/> to compare to.</param>
|
||||
/// <returns><c>true</c> if this <see cref="Plane"/> is parallel to, faces the same direction, and has the same distance as, the given <see cref="Plane"/>.</returns>
|
||||
public bool Equals(Plane other) {
|
||||
return (normal == other.normal && distance + 0.001 >= other.distance && distance - 0.001 <= other.distance);
|
||||
}
|
||||
@@ -165,44 +169,45 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Generates a hash code for this instance based on instance data.
|
||||
/// </summary>
|
||||
/// <returns>The hash code for this instance</returns>
|
||||
/// <returns>The hash code for this instance.</returns>
|
||||
public override int GetHashCode() {
|
||||
return _normal.GetHashCode() ^ distance.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares whether two <c>Plane</c>s are equal, or approximately equal.
|
||||
/// Compares whether two <see cref="Plane"/>s are equal, or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="other">The <c>Plane</c> to compare to</param>
|
||||
/// <returns><c>true</c> if this <c>Plane</c> is parallel to, faces the same direction, and has the same distance as, the given <c>Plane</c>.</returns>
|
||||
/// <param name="other">The <see cref="Plane"/> to compare to.</param>
|
||||
/// <returns><c>true</c> if this <see cref="Plane"/> is parallel to, faces the same direction, and has the same distance as, the given <see cref="Plane"/>.</returns>
|
||||
public static bool operator ==(Plane p1, Plane p2) {
|
||||
return p1.Equals(p2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares whether two <c>Plane</c>s are not equal, or approximately equal.
|
||||
/// Compares whether two <see cref="Plane"/>s are not equal, or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="other">The <c>Plane</c> to compare to</param>
|
||||
/// <returns><c>false</c> if this <c>Plane</c> is parallel to, faces the same direction, and has the same distance as, the given <c>Plane</c>.</returns>
|
||||
/// <param name="other">The <see cref="Plane"/> to compare to.</param>
|
||||
/// <returns><c>false</c> if this <see cref="Plane"/> is parallel to, faces the same direction, and has the same distance as, the given <see cref="Plane"/>.</returns>
|
||||
public static bool operator !=(Plane p1, Plane p2) {
|
||||
return !p1.Equals(p2);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the given <c>Vector3d</c> is contained in this <c>Plane</c>.
|
||||
/// Determines whether the given <see cref="Vector3d"/> is contained in this <see cref="Plane"/>.
|
||||
/// </summary>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <returns><c>true</c> if the <c>Vector3d</c> is contained in this <c>Plane</c>.</returns>
|
||||
/// <param name="v">Point.</param>
|
||||
/// <returns><c>true</c> if the <see cref="Vector3d"/> is contained in this <see cref="Plane"/>.</returns>
|
||||
public bool Contains(Vector3d v) {
|
||||
double distanceTo = GetDistanceToPoint(v);
|
||||
return distanceTo < 0.001 && distanceTo > -0.001;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the signed distance from this <c>Plane</c> to a given point.
|
||||
/// Gets the signed distance from this <see cref="Plane"/> to a given point.
|
||||
/// </summary>
|
||||
/// <param name="to">Point to get the distance to</param>
|
||||
/// <returns>Signed distance from this <c>Plane</c> to the given point.</returns>
|
||||
/// <param name="to">Point to get the distance to.</param>
|
||||
/// <returns>Signed distance from this <see cref="Plane"/> to the given point.</returns>
|
||||
public double GetDistanceToPoint(Vector3d to) {
|
||||
// Ax + By + Cz - d = DISTANCE = normDOTpoint - d
|
||||
double normLength = System.Math.Pow(normal.x, 2) + System.Math.Pow(normal.y, 2) + System.Math.Pow(normal.z, 2);
|
||||
@@ -213,16 +218,16 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is <paramref name="v" /> on the positive side of this <c>Plane</c>?
|
||||
/// Is <paramref name="v"/> on the positive side of this <see cref="Plane"/>?
|
||||
/// </summary>
|
||||
/// <param name="v">Point to get the side for</param>
|
||||
/// <returns><c>true</c> if <paramref name="v" /> is on the positive side of this <c>Plane</c></returns>
|
||||
/// <param name="v">Point to get the side for.</param>
|
||||
/// <returns><c>true</c> if <paramref name="v"/> is on the positive side of this <see cref="Plane"/>.</returns>
|
||||
public bool GetSide(Vector3d v) {
|
||||
return GetDistanceToPoint(v) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flips this <c>Plane</c> to face the opposite direction.
|
||||
/// Flips this <see cref="Plane"/> to face the opposite direction.
|
||||
/// </summary>
|
||||
public void Flip() {
|
||||
normal = -normal;
|
||||
@@ -230,29 +235,29 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flips this <c>Plane</c> to face the opposite direction.
|
||||
/// Flips this <see cref="Plane"/> to face the opposite direction.
|
||||
/// </summary>
|
||||
public static Plane operator -(Plane flipMe) {
|
||||
return new Plane(-flipMe.normal, -flipMe.distance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a nicely formatted string representation of this <c>Plane</c>.
|
||||
/// Gets a nicely formatted string representation of this <see cref="Plane"/>.
|
||||
/// </summary>
|
||||
/// <returns>A nicely formatted string representation of this <c>Plane</c></returns>
|
||||
/// <returns>A nicely formatted <c>string</c> representation of this <see cref="Plane"/>.</returns>
|
||||
public override string ToString() {
|
||||
return "(" + normal.ToString() + ") " + distance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raycasts a <c>Ray</c> against this <c>Plane</c>.
|
||||
/// Raycasts a <see cref="Ray"/> against this <see cref="Plane"/>.
|
||||
/// </summary>
|
||||
/// <param name="ray"><c>Ray</c> to raycast against</param>
|
||||
/// <param name="enter">Out parameter. The distance along <paramref name="ray" /> where the collision happened</param>
|
||||
/// <param name="ray"><see cref="Ray"/> to raycast against.</param>
|
||||
/// <param name="enter"><c>out</c> parameter that will contain the distance along <paramref name="ray"/> where the collision happened.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> and <paramref name="enter" /> is positive if <c>Ray</c> intersects this <c>Plane</c> in front of the way,
|
||||
/// <c>false</c> and <paramref name="enter" /> is negative if <c>Ray</c> intersects this <c>Plane</c> behind the ray,
|
||||
/// <c>false</c> and <paramref name="enter" /> is 0 if the <c>Ray</c> is parallel to this <c>Plane</c>
|
||||
/// <c>true</c> and <paramref name="enter"/> is positive if <see cref="Ray"/> intersects this <see cref="Plane"/> in front of the ray,
|
||||
/// <c>false</c> and <paramref name="enter"/> is negative if <see cref="Ray"/> intersects this <see cref="Plane"/> behind the ray,
|
||||
/// <c>false</c> and <paramref name="enter"/> is 0 if the <see cref="Ray"/> is parallel to this <see cref="Plane"/>.
|
||||
/// </returns>
|
||||
public bool Raycast(Ray ray, out double enter) {
|
||||
double denom = (Vector3d.Dot(ray.direction, normal));
|
||||
|
||||
@@ -3,7 +3,7 @@ using System;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// A struct for a <c>Ray</c> defined by a starting point and a direction vector.
|
||||
/// A struct for a <see cref="Ray"/> defined by a starting point and a direction vector.
|
||||
/// </summary>
|
||||
public struct Ray : IEquatable<Ray> {
|
||||
|
||||
@@ -18,10 +18,10 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Ray</c> object using the specified origin and direction.
|
||||
/// Creates a new <see cref="Ray"/> object using the specified origin and direction.
|
||||
/// </summary>
|
||||
/// <param name="origin">Origin point of this <C>Ray</C></param>
|
||||
/// <param name="direction">Direction vector of this <c>Ray</c></param>
|
||||
/// <param name="origin">Origin point of this <see cref="Ray"/>.</param>
|
||||
/// <param name="direction">Direction vector of this <see cref="Ray"/>.</param>
|
||||
public Ray(Vector3d origin, Vector3d direction) {
|
||||
this.origin = origin;
|
||||
this._direction = direction;
|
||||
@@ -29,54 +29,57 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the point at <paramref name="distance" /> units along this <c>Ray</c>.
|
||||
/// Gets the point at <paramref name="distance"/> units along this <see cref="Ray"/>.
|
||||
/// </summary>
|
||||
/// <param name="distance">Distance of the point to get</param>
|
||||
/// <returns>The point at <paramref name="distance" /> units along this <c>Ray</c></returns>
|
||||
/// <param name="distance">Distance of the point to get.</param>
|
||||
/// <returns>The point at <paramref name="distance"/> units along this <see cref="Ray"/>.</returns>
|
||||
public Vector3d GetPoint(double distance) {
|
||||
return origin + (distance * direction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a nicely formatted string representation of this <c>Ray</c>.
|
||||
/// Gets a nicely formatted <c>string</c> representation of this <see cref="Ray"/>.
|
||||
/// </summary>
|
||||
/// <returns>A nicely formatted string representation of this <c>Ray</c></returns>
|
||||
/// <returns>A nicely formatted <c>string</c> representation of this <see cref="Ray"/>.</returns>
|
||||
public override string ToString() {
|
||||
return string.Format("( {0}, {1} )", origin, direction);
|
||||
}
|
||||
|
||||
#region IEquatable
|
||||
/// <summary>
|
||||
/// Determines whether this <c>Ray</c> is equivalent to another.
|
||||
/// Determines whether this <see cref="Ray"/> is equivalent to another.
|
||||
/// </summary>
|
||||
/// <param name="r1">The <c>Ray</c> to compare to</param>
|
||||
/// <returns><c>true</c> if this <c>Ray</c> and <paramref name="r1" /> have the same origin and direction</returns>
|
||||
/// <param name="r1">A <see cref="Ray"/> to compare.</param>
|
||||
/// <param name="r2">A <see cref="Ray"/> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="r1"/> and <paramref name="r2"/> have the same <see cref="Ray.origin"/> and <see cref="Ray.direction"/>.</returns>
|
||||
public static bool operator ==(Ray r1, Ray r2) {
|
||||
return r1.Equals(r2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this <c>Ray</c> is not equivalent to another.
|
||||
/// Determines whether this <see cref="Ray"/> is not equivalent to another.
|
||||
/// </summary>
|
||||
/// <param name="r1">The <c>Ray</c> to compare to</param>
|
||||
/// <returns><c>true</c> if this <c>Ray</c> and <paramref name="r1" /> don't have the same origin and direction</returns>
|
||||
/// <param name="r1">A <see cref="Ray"/> to compare.</param>
|
||||
/// <param name="r2">A <see cref="Ray"/> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="r1"/> and <paramref name="r2"/> don't have the same <see cref="Ray.origin"/> and <see cref="Ray.direction"/>.</returns>
|
||||
public static bool operator !=(Ray r1, Ray r2) {
|
||||
return !r1.Equals(r2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this <c>Ray</c> is equivalent to another.
|
||||
/// Determines whether this <see cref="Ray"/> is equivalent to another.
|
||||
/// </summary>
|
||||
/// <param name="other">The <c>Ray</c> to compare to</param>
|
||||
/// <returns><c>true</c> if this <c>Ray</c> and <paramref name="other" /> have the same origin and direction</returns>
|
||||
/// <param name="other">The <see cref="Ray"/> to compare to.</param>
|
||||
/// <returns><c>true</c> if this <see cref="Ray"/> and <paramref name="other"/> have the same <see cref="Ray.origin"/> and <see cref="Ray.direction"/>.</returns>
|
||||
public bool Equals(Ray other) {
|
||||
return origin.Equals(other.origin) && direction.Equals(other.direction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this <c>Ray</c> is equivalent to another <c>object</c>.
|
||||
/// Determines whether this <see cref="Ray"/> is equivalent to another <c>object</c>.
|
||||
/// </summary>
|
||||
/// <param name="obj">The <c>object</c> to compare to</param>
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <c>Ray</c> and this <c>Ray</c> and <paramref name="obj" /> have the same origin and direction</returns>
|
||||
/// <param name="obj">The <c>object</c> to compare to.</param>
|
||||
/// <returns><c>true</c> if <paramref name="obj"/> is a <see cref="Ray"/> and this <see cref="Ray"/> and <paramref name="obj"/> have the same <see cref="Ray.origin"/> and <see cref="Ray.direction"/>.</returns>
|
||||
public override bool Equals(object obj) {
|
||||
if (object.ReferenceEquals(obj, null) || !GetType().IsAssignableFrom(obj.GetType())) { return false; }
|
||||
return Equals((Ray)obj);
|
||||
@@ -85,10 +88,11 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Generates a hash code for this instance based on instance data.
|
||||
/// </summary>
|
||||
/// <returns>The hash code for this instance</returns>
|
||||
/// <returns>The hash code for this instance.</returns>
|
||||
public override int GetHashCode() {
|
||||
return origin.GetHashCode() ^ direction.GetHashCode();
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,16 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Struct defining a rectangle in 2D space.
|
||||
/// </summary>
|
||||
public struct Rect : IEquatable<Rect> {
|
||||
|
||||
public Vector2d position;
|
||||
public Vector2d size;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the center point of this <c>Rect</c>
|
||||
/// Gets the center point of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public Vector2d center {
|
||||
get {
|
||||
@@ -18,7 +21,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of this <c>Rect</c>
|
||||
/// Gets the width of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public double width {
|
||||
get {
|
||||
@@ -30,7 +33,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of this <c>Rect</c>
|
||||
/// Gets the height of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public double height {
|
||||
get {
|
||||
@@ -42,7 +45,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bottom-left coordinate of this <c>Rect</c>
|
||||
/// Gets the bottom-left coordinate of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public Vector2d min {
|
||||
get {
|
||||
@@ -55,7 +58,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the top-right coordinate of this <c>Rect</c>
|
||||
/// Gets the top-right coordinate of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public Vector2d max {
|
||||
get {
|
||||
@@ -68,7 +71,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the left bound of this <c>Rect</c>
|
||||
/// Gets the left bound of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public double x {
|
||||
get {
|
||||
@@ -80,7 +83,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the left bound of this <c>Rect</c>
|
||||
/// Gets the left bound of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public double xMin {
|
||||
get {
|
||||
@@ -92,7 +95,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the right bound of this <c>Rect</c>
|
||||
/// Gets the right bound of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public double xMax {
|
||||
get {
|
||||
@@ -104,7 +107,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the upper bound of this <c>Rect</c>
|
||||
/// Gets the upper bound of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public double y {
|
||||
get {
|
||||
@@ -116,7 +119,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the upper bound of this <c>Rect</c>
|
||||
/// Gets the upper bound of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public double yMin {
|
||||
get {
|
||||
@@ -128,7 +131,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lower bound of this <c>Rect</c>
|
||||
/// Gets the lower bound of this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
public double yMax {
|
||||
get {
|
||||
@@ -140,35 +143,35 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Rect</c> object.
|
||||
/// Creates a new <see cref="Rect"/> object.
|
||||
/// </summary>
|
||||
/// <param name="left">Left bound</param>
|
||||
/// <param name="top">Upper bound</param>
|
||||
/// <param name="width">Width</param>
|
||||
/// <param name="height">Height</param>
|
||||
/// <param name="left">Left bound.</param>
|
||||
/// <param name="top">Upper bound.</param>
|
||||
/// <param name="width">Width.</param>
|
||||
/// <param name="height">Height.</param>
|
||||
public Rect(double left, double top, double width, double height) : this() {
|
||||
position = new Vector2d(left, top);
|
||||
size = new Vector2d(width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Rect</c> object from the specified bounds
|
||||
/// Creates a new <see cref="Rect"/> object from the specified bounds.
|
||||
/// </summary>
|
||||
/// <param name="left">Left bound</param>
|
||||
/// <param name="top">Upper bound</param>
|
||||
/// <param name="right">Right bound</param>
|
||||
/// <param name="bottom">Lower bound</param>
|
||||
/// <returns>The resulting <c>Rect</c></returns>
|
||||
/// <param name="left">Left bound.</param>
|
||||
/// <param name="top">Upper bound.</param>
|
||||
/// <param name="right">Right bound.</param>
|
||||
/// <param name="bottom">Lower bound.</param>
|
||||
/// <returns>The resulting <see cref="Rect"/></returns>
|
||||
public static Rect MinMaxRect(double left, double top, double right, double bottom) {
|
||||
return new Rect(left, top, right - left, bottom - top);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this <c>Rect</c> contains the specified point.
|
||||
/// Gets whether this <see cref="Rect"/> contains the specified point.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check</param>
|
||||
/// <param name="allowInverse">If the <c>Rect</c>'s size is negative, should the check allow this?</param>
|
||||
/// <returns><c>true</c> if the point is contained in the <C>Rect</C></returns>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="allowInverse">If the <see cref="Rect"/>'s size is negative, should the check allow this?</param>
|
||||
/// <returns><c>true</c> if the point is contained in the <see cref="Rect"/>.</returns>
|
||||
public bool Contains(Vector2d point, bool allowInverse = false) {
|
||||
if (allowInverse) {
|
||||
return point.x > position.x && point.x < position.x + size.x && point.y > position.y && point.y < position.y + size.y;
|
||||
@@ -181,11 +184,11 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this <c>Rect</c> overlaps the specified <c>Rect</c>.
|
||||
/// Gets whether this <see cref="Rect"/> overlaps the specified <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
/// <param name="other">The <c>Rect</c> to check</param>
|
||||
/// <param name="allowInverse">If either <c>Rect</c>'s size is negative, should the check allow this?</param>
|
||||
/// <returns><c>true</c> if the other <c>Rect</c> overlaps this <C>Rect</C></returns>
|
||||
/// <param name="other">The <see cref="Rect"/> to check.</param>
|
||||
/// <param name="allowInverse">If either <see cref="Rect"/>'s size is negative, should the check allow this?</param>
|
||||
/// <returns><c>true</c> if the other <see cref="Rect"/> overlaps this <see cref="Rect"/>.</returns>
|
||||
public bool Overlaps(Rect other, bool allowInverse = false) {
|
||||
if (allowInverse) {
|
||||
return Contains(other.position, true) || Contains(other.position + other.size, true) || Contains(other.min, true) || Contains(other.max, true) ||
|
||||
@@ -201,12 +204,12 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets this <c>Rect</c>'s components
|
||||
/// Sets this <see cref="Rect"/>'s components.
|
||||
/// </summary>
|
||||
/// <param name="left">The left bound to set</param>
|
||||
/// <param name="top">The upper bound to set</param>
|
||||
/// <param name="width">The width to set</param>
|
||||
/// <param name="height">The height to set</param>
|
||||
/// <param name="left">The left bound to set.</param>
|
||||
/// <param name="top">The upper bound to set.</param>
|
||||
/// <param name="width">The width to set.</param>
|
||||
/// <param name="height">The height to set.</param>
|
||||
public void Set(double left, double top, double width, double height) {
|
||||
position.x = left;
|
||||
position.y = top;
|
||||
@@ -215,21 +218,21 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given a normalized point, returns a coordinate point inside the <c>Rect</c>.
|
||||
/// Given a normalized point, returns a coordinate point inside the <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
/// <param name="rect">The <c>Rect</c></param>
|
||||
/// <param name="normalizedCoordinates">The normalized coordinates</param>
|
||||
/// <returns>The denormalized coordinates</returns>
|
||||
/// <param name="rect">The <see cref="Rect"/>.</param>
|
||||
/// <param name="normalizedCoordinates">The normalized coordinates.</param>
|
||||
/// <returns>The denormalized coordinates.</returns>
|
||||
public static Vector2d NormalizedToPoint(Rect rect, Vector2d normalizedCoordinates) {
|
||||
return new Vector2d(rect.x + (rect.width * normalizedCoordinates.x), rect.y + (rect.height * normalizedCoordinates.y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given a point, returns a normalized point relative to the <c>Rect</c>.
|
||||
/// Given a point, returns a normalized point relative to the <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
/// <param name="rect">The <c>Rect</c></param>
|
||||
/// <param name="point">The coordinates</param>
|
||||
/// <returns>The normalized coordinates</returns>
|
||||
/// <param name="rect">The <see cref="Rect"/>.</param>
|
||||
/// <param name="point">The coordinates.</param>
|
||||
/// <returns>The normalized coordinates.</returns>
|
||||
public static Vector2d PointToNormalized(Rect rect, Vector2d point) {
|
||||
if (rect.width != 0 && rect.height != 0) {
|
||||
return new Vector2d((point.x - rect.x) / rect.width, (point.y - rect.y) / rect.height);
|
||||
@@ -239,27 +242,28 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives a nicely formatted <c>string</c> for this <c>Rect</c>.
|
||||
/// Gives a nicely formatted <c>string</c> for this <see cref="Rect"/>.
|
||||
/// </summary>
|
||||
/// <returns>Nicely formatted <c>string</c> for this <c>Rect</c></returns>
|
||||
/// <returns>Nicely formatted <c>string</c> for this <see cref="Rect"/>.</returns>
|
||||
public override string ToString() {
|
||||
return string.Format("(x:{1}, y:{2}, width:{3}, height:{4})", x, y, width, height);
|
||||
}
|
||||
|
||||
#region IEquatable
|
||||
/// <summary>
|
||||
/// Determines whether this <c>Rect</c> equals another
|
||||
/// Determines whether this <see cref="Rect"/> equals another.
|
||||
/// </summary>
|
||||
/// <param name="other">The <c>Rect</c> to compare to</param>
|
||||
/// <returns><c>true</c> if the <c>Rect</c>s are equal</returns>
|
||||
/// <param name="other">The <see cref="Rect"/> to compare to.</param>
|
||||
/// <returns><c>true</c> if the <see cref="Rect"/>s are equal.</returns>
|
||||
public bool Equals(Rect other) {
|
||||
return position == other.position && size == other.size;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this <c>Rect</c> equals another <c>object</c>
|
||||
/// Determines whether this <see cref="Rect"/> equals another <c>object</c>.
|
||||
/// </summary>
|
||||
/// <param name="other">The <c>object</c> to compare to</param>
|
||||
/// <returns><c>true</c> if the other <c>object</c> is not null and a <c>Rect</c>, and the <c>Rect</c>s are equal</returns>
|
||||
/// <param name="other">The <c>object</c> to compare to.</param>
|
||||
/// <returns><c>true</c> if the other <c>object</c> is not null and a <see cref="Rect"/>, and the <see cref="Rect"/>s are equal.</returns>
|
||||
public override bool Equals(object obj) {
|
||||
if (object.ReferenceEquals(obj, null)) { return false; }
|
||||
if (!(obj is Rect)) { return false; }
|
||||
@@ -267,19 +271,19 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this <c>Rect</c> equals another
|
||||
/// Determines whether this <see cref="Rect"/> equals another.
|
||||
/// </summary>
|
||||
/// <param name="other">The <c>Rect</c> to compare to</param>
|
||||
/// <returns><c>true</c> if the <c>Rect</c>s are equal</returns>
|
||||
/// <param name="other">The <see cref="Rect"/> to compare to.</param>
|
||||
/// <returns><c>true</c> if the <see cref="Rect"/>s are equal.</returns>
|
||||
public static bool operator ==(Rect r1, Rect r2) {
|
||||
return r1.Equals(r2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this <c>Rect</c> does not equal another
|
||||
/// Determines whether this <see cref="Rect"/> does not equal another.
|
||||
/// </summary>
|
||||
/// <param name="other">The <c>Rect</c> to compare to</param>
|
||||
/// <returns><c>true</c> if the <c>Rect</c>s are not equal</returns>
|
||||
/// <param name="other">The <see cref="Rect"/> to compare to.</param>
|
||||
/// <returns><c>true</c> if the <see cref="Rect"/>s are not equal.</returns>
|
||||
public static bool operator !=(Rect r1, Rect r2) {
|
||||
return !r1.Equals(r2);
|
||||
}
|
||||
@@ -287,10 +291,11 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Generates a hash code for this instance based on instance data.
|
||||
/// </summary>
|
||||
/// <returns>The hash code for this instance</returns>
|
||||
/// <returns>The hash code for this instance.</returns>
|
||||
public override int GetHashCode() {
|
||||
return position.GetHashCode() ^ size.GetHashCode();
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,30 +9,30 @@ namespace LibBSP {
|
||||
/// </summary>
|
||||
[Serializable] public struct Vector2d : IEquatable<Vector2d>, IEnumerable, IEnumerable<double> {
|
||||
|
||||
/// <summary>Returns <c>Vector2d</c>(NaN, NaN, NaN)</summary>
|
||||
/// <summary>Returns <see cref="Vector2d"/>(NaN, NaN).</summary>
|
||||
public static Vector2d undefined { get { return new Vector2d(System.Double.NaN, System.Double.NaN); } }
|
||||
/// <summary>Returns <c>Vector2d</c>(1, 0)</summary>
|
||||
/// <summary>Returns <see cref="Vector2d"/>(1, 0).</summary>
|
||||
public static Vector2d right { get { return new Vector2d(1, 0); } }
|
||||
/// <summary>Returns <c>Vector2d</c>(0, 1)</summary>
|
||||
/// <summary>Returns <see cref="Vector2d"/>(0, 1).</summary>
|
||||
public static Vector2d up { get { return new Vector2d(0, 1); } }
|
||||
/// <summary>Returns <c>Vector2d</c>(-1, 0)</summary>
|
||||
/// <summary>Returns <see cref="Vector2d"/>(-1, 0).</summary>
|
||||
public static Vector2d left { get { return new Vector2d(-1, 0); } }
|
||||
/// <summary>Returns <c>Vector2d</c>(0, -1)</summary>
|
||||
/// <summary>Returns <see cref="Vector2d"/>(0, -1).</summary>
|
||||
public static Vector2d down { get { return new Vector2d(0, -1); } }
|
||||
/// <summary>Returns <c>Vector2d</c>(0, 0)</summary>
|
||||
/// <summary>Returns <see cref="Vector2d"/>(0, 0).</summary>
|
||||
public static Vector2d zero { get { return new Vector2d(0, 0); } }
|
||||
/// <summary>Returns <c>Vector2d</c>(1, 1)</summary>
|
||||
/// <summary>Returns <see cref="Vector2d"/>(1, 1).</summary>
|
||||
public static Vector2d one { get { return new Vector2d(1, 1); } }
|
||||
|
||||
public double x;
|
||||
public double y;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a component using an indexer, x=0, y=1
|
||||
/// Gets or sets a component using an indexer, x=0, y=1.
|
||||
/// </summary>
|
||||
/// <param name="index">Component to get or set</param>
|
||||
/// <returns>Component</returns>
|
||||
/// <exception cref="IndexOutOfRangeException"><paramref name="index" /> was negative or greater than 1</exception>
|
||||
/// <param name="index">Component to get or set.</param>
|
||||
/// <returns>Component.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException"><paramref name="index"/> was negative or greater than 1.</exception>
|
||||
public double this[int index] {
|
||||
get {
|
||||
switch (index) {
|
||||
@@ -65,18 +65,18 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the magnitude of this <c>Vector2d</c>, or its distance from (0, 0).
|
||||
/// Gets the magnitude of this <see cref="Vector2d"/>, or its distance from (0, 0).
|
||||
/// </summary>
|
||||
public double magnitude { get { return Math.Sqrt(sqrMagnitude); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the magnitude of this <c>Vector2d</c> squared. This is useful for when you are comparing the lengths of two vectors
|
||||
/// but don't need to know the exact length, and avoids a square root.
|
||||
/// Gets the magnitude of this <see cref="Vector2d"/> squared. This is useful for when you are comparing the lengths of two vectors
|
||||
/// but don't need to know the exact length, and avoids calculating a square root.
|
||||
/// </summary>
|
||||
public double sqrMagnitude { get { return System.Math.Pow(x, 2) + System.Math.Pow(y, 2); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the normalized version of this <c>Vector2d</c> (unit vector with the same direction).
|
||||
/// Gets the normalized version of this <see cref="Vector2d"/> (unit vector with the same direction).
|
||||
/// </summary>
|
||||
public Vector2d normalized {
|
||||
get {
|
||||
@@ -87,9 +87,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Vector2d</c> object using elements in the passed array as components
|
||||
/// Creates a new <see cref="Vector2d"/> object using elements in the passed array as components.
|
||||
/// </summary>
|
||||
/// <param name="point">Components of the vector</param>
|
||||
/// <param name="point">Components of the vector.</param>
|
||||
public Vector2d(params float[] point) {
|
||||
if (point == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -105,9 +105,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Vector2d</c> object using elements in the passed array as components
|
||||
/// Creates a new <see cref="Vector2d"/> object using elements in the passed array as components.
|
||||
/// </summary>
|
||||
/// <param name="point">Components of the vector</param>
|
||||
/// <param name="point">Components of the vector.</param>
|
||||
public Vector2d(params double[] point) {
|
||||
if (point == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -123,9 +123,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Vector2d</c> object using elements in the passed array as components
|
||||
/// Creates a new <see cref="Vector2d"/> object using elements in the passed array as components.
|
||||
/// </summary>
|
||||
/// <param name="point">Components of the vector</param>
|
||||
/// <param name="point">Components of the vector.</param>
|
||||
public Vector2d(params int[] point) {
|
||||
if (point == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -141,9 +141,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Crates a new <c>Vector2d</c> instance using the components from the supplied <c>Vector2d</c>
|
||||
/// Crates a new <see cref="Vector2d"/> instance using the components from the supplied <see cref="Vector2d"/>.
|
||||
/// </summary>
|
||||
/// <param name="vector">Vector to copy components from</param>
|
||||
/// <param name="vector">Vector to copy components from.</param>
|
||||
public Vector2d(Vector2d vector) {
|
||||
x = vector.x;
|
||||
y = vector.y;
|
||||
@@ -152,9 +152,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Adds two vectors together componentwise. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector to add</param>
|
||||
/// <param name="v2">Second vector to add</param>
|
||||
/// <returns>The resulting vector</returns>
|
||||
/// <param name="v1">First vector to add.</param>
|
||||
/// <param name="v2">Second vector to add.</param>
|
||||
/// <returns>The resulting vector.</returns>
|
||||
public static Vector2d operator +(Vector2d v1, Vector2d v2) {
|
||||
return Add(v1, v2);
|
||||
}
|
||||
@@ -162,87 +162,87 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Adds two vectors together componentwise. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector to add</param>
|
||||
/// <param name="v2">Second vector to add</param>
|
||||
/// <returns>The resulting vector</returns>
|
||||
/// <param name="v1">First vector to add.</param>
|
||||
/// <param name="v2">Second vector to add.</param>
|
||||
/// <returns>The resulting vector.</returns>
|
||||
public static Vector2d Add(Vector2d v1, Vector2d v2) {
|
||||
return new Vector2d(v1.x + v2.x, v1.y + v2.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts one vector from another. This operation is NOT commutative
|
||||
/// Subtracts one vector from another. This operation is NOT commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to subtract from</param>
|
||||
/// <param name="v2">Vector to subtract</param>
|
||||
/// <returns>Difference from <paramref name="v1" /> to <paramref name="v2" /></returns>
|
||||
/// <param name="v1">Vector to subtract from.</param>
|
||||
/// <param name="v2">Vector to subtract.</param>
|
||||
/// <returns>Difference from <paramref name="v1"/> to <paramref name="v2"/>.</returns>
|
||||
public static Vector2d operator -(Vector2d v1, Vector2d v2) {
|
||||
return Subtract(v1, v2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts one vector from another. This operation is NOT commutative
|
||||
/// Subtracts one vector from another. This operation is NOT commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to subtract from</param>
|
||||
/// <param name="v2">Vector to subtract</param>
|
||||
/// <returns>Difference from <paramref name="v1" /> to <paramref name="v2" /></returns>
|
||||
/// <param name="v1">Vector to subtract from.</param>
|
||||
/// <param name="v2">Vector to subtract.</param>
|
||||
/// <returns>Difference from <paramref name="v1"/> to <paramref name="v2"/>.</returns>
|
||||
public static Vector2d Subtract(Vector2d v1, Vector2d v2) {
|
||||
return new Vector2d(v1.x - v2.x, v1.y - v2.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0) - <paramref name="v1" />.
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0) - <paramref name="v1"/>.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to negate</param>
|
||||
/// <returns><paramref name="v1" /> with all components negated</returns>
|
||||
/// <param name="v1">Vector to negate.</param>
|
||||
/// <returns><paramref name="v1"/> with all components negated.</returns>
|
||||
public static Vector2d operator -(Vector2d v1) {
|
||||
return Negate(v1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0) - <paramref name="v1" />.
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0) - <paramref name="v1"/>.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to negate</param>
|
||||
/// <returns><paramref name="v1" /> with all components negated</returns>
|
||||
/// <param name="v1">Vector to negate.</param>
|
||||
/// <returns><paramref name="v1"/> with all components negated.</returns>
|
||||
public static Vector2d Negate(Vector2d v1) {
|
||||
return new Vector2d(-v1.x, -v1.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector2d operator *(Vector2d v1, double scalar) {
|
||||
return Scale(v1, scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector2d operator *(double scalar, Vector2d v1) {
|
||||
return Scale(v1, scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector2d Scale(Vector2d v1, double scalar) {
|
||||
return new Vector2d(v1.x * scalar, v1.y * scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector2d Scale(double scalar, Vector2d v1) {
|
||||
return Scale(v1, scalar);
|
||||
}
|
||||
@@ -250,9 +250,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Multiplies two vectors together componentwise. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>Resulting vector when the passed vectors' components are multiplied</returns>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Resulting vector when the passed vectors' components are multiplied.</returns>
|
||||
public static Vector2d Scale(Vector2d v1, Vector2d v2) {
|
||||
return new Vector2d(v1.x * v2.x, v1.y * v2.y);
|
||||
}
|
||||
@@ -260,9 +260,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Vector dot product. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>Dot product of these two vectors</returns>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Dot product of these two vectors.</returns>
|
||||
public static double operator *(Vector2d v1, Vector2d v2) {
|
||||
return Dot(v1, v2);
|
||||
}
|
||||
@@ -270,28 +270,29 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Vector dot product. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>Dot product of these two vectors</returns>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Dot product of these two vectors.</returns>
|
||||
public static double Dot(Vector2d v1, Vector2d v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar division. Divides all components of <paramref name="v1" /> by <paramref name="divisor" /> and returns the result.
|
||||
/// Scalar division. Divides all components of <paramref name="v1"/> by <paramref name="divisor"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to divide</param>
|
||||
/// <param name="divisor">Divisor</param>
|
||||
/// <returns>Resulting vector when all components of <paramref name="v1" /> are divided by <paramref name="divisor" />.</returns>
|
||||
/// <param name="v1">Vector to divide.</param>
|
||||
/// <param name="divisor">Divisor.</param>
|
||||
/// <returns>Resulting vector when all components of <paramref name="v1"/> are divided by <paramref name="divisor"/>.</returns>
|
||||
public static Vector2d operator /(Vector2d v1, double divisor) {
|
||||
return Scale(v1, 1.0 / divisor);
|
||||
}
|
||||
|
||||
#region IEquatable
|
||||
/// <summary>
|
||||
/// Equivalency. Returns <c>true</c> if the components of two vectors are equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the components of two vectors are equal or approximately equal.</returns>
|
||||
public static bool operator ==(Vector2d v1, Vector2d v2) {
|
||||
return v1.Equals(v2);
|
||||
@@ -300,8 +301,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Non-Equivalency. Returns <c>true</c> if the components of two vectors are not equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the components of two vectors are not equal or approximately equal.</returns>
|
||||
public static bool operator !=(Vector2d v1, Vector2d v2) {
|
||||
return !v1.Equals(v2);
|
||||
@@ -310,8 +311,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Equivalency. Returns <c>true</c> if the components of two vectors are equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the components of two vectors are equal or approximately equal.</returns>
|
||||
public bool Equals(Vector2d other) {
|
||||
return (Math.Abs(x - other.x) < 0.001 && Math.Abs(y - other.y) < 0.001);
|
||||
@@ -320,8 +321,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Equivalency. Returns <c>true</c> if the other object is a vector, and the components of two vectors are equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the other object is a vector, and the components of two vectors are equal or approximately equal.</returns>
|
||||
public override bool Equals(object obj) {
|
||||
if (object.ReferenceEquals(obj, null) || !GetType().IsAssignableFrom(obj.GetType())) { return false; }
|
||||
@@ -331,24 +332,25 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Generates a hash code for this instance based on instance data.
|
||||
/// </summary>
|
||||
/// <returns>The hash code for this instance</returns>
|
||||
/// <returns>The hash code for this instance.</returns>
|
||||
public override int GetHashCode() {
|
||||
return x.GetHashCode() ^ y.GetHashCode();
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the distance from this vector to another.
|
||||
/// </summary>
|
||||
/// <param name="to">Vector to calculate distance to</param>
|
||||
/// <returns>Distance from this vector to the passed vector</returns>
|
||||
/// <param name="to">Vector to calculate distance to.</param>
|
||||
/// <returns>Distance from this vector to the passed vector.</returns>
|
||||
public double Distance(Vector2d to) {
|
||||
return (this - to).magnitude;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a human-readable string representation of this vector.
|
||||
/// Gets a human-readable <c>string</c> representation of this vector.
|
||||
/// </summary>
|
||||
/// <returns>Human-readable string representation of this vector</returns>
|
||||
/// <returns>Human-readable <c>string</c> representation of this vector.</returns>
|
||||
public override string ToString() {
|
||||
return string.Format("( {0} , {1} )", x.ToString(), y.ToString());
|
||||
}
|
||||
@@ -366,10 +368,10 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the area of the triangle defined by three points using Heron's formula.
|
||||
/// </summary>
|
||||
/// <param name="p1">First vertex of triangle</param>
|
||||
/// <param name="p2">Second vertex of triangle</param>
|
||||
/// <param name="p3">Third vertex of triangle</param>
|
||||
/// <returns>Area of the triangle defined by these three vertices</returns>
|
||||
/// <param name="p1">First vertex of triangle.</param>
|
||||
/// <param name="p2">Second vertex of triangle.</param>
|
||||
/// <param name="p3">Third vertex of triangle.</param>
|
||||
/// <returns>Area of the triangle defined by these three vertices.</returns>
|
||||
public static double TriangleArea(Vector3d p1, Vector3d p2, Vector3d p3) {
|
||||
return Math.Sqrt(SqrTriangleArea(p1, p2, p3)) / 4.0;
|
||||
}
|
||||
@@ -377,10 +379,10 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the square of the area of the triangle defined by three points. This is useful when simply comparing two areas when you don't need to know exactly what the area is.
|
||||
/// </summary>
|
||||
/// <param name="p1">First vertex of triangle</param>
|
||||
/// <param name="p2">Second vertex of triangle</param>
|
||||
/// <param name="p3">Third vertex of triangle</param>
|
||||
/// <returns>Square of the area of the triangle defined by these three vertices</returns>
|
||||
/// <param name="p1">First vertex of triangle.</param>
|
||||
/// <param name="p2">Second vertex of triangle.</param>
|
||||
/// <param name="p3">Third vertex of triangle.</param>
|
||||
/// <returns>Square of the area of the triangle defined by these three vertices.</returns>
|
||||
public static double SqrTriangleArea(Vector3d p1, Vector3d p2, Vector3d p3) {
|
||||
double a = p1.Distance(p2);
|
||||
double b = p1.Distance(p3);
|
||||
@@ -388,8 +390,9 @@ namespace LibBSP {
|
||||
return 4.0 * a * a * b * b - Math.Pow((a * a) + (b * b) - (c * c), 2);
|
||||
}
|
||||
|
||||
#region IEnumerable
|
||||
/// <summary>
|
||||
/// Allows enumeration through the components of a <c>Vector2d</c> using a foreach loop.
|
||||
/// Allows enumeration through the components of a <see cref="Vector2d"/> using a foreach loop.
|
||||
/// </summary>
|
||||
public IEnumerator<double> GetEnumerator() {
|
||||
yield return x;
|
||||
@@ -397,7 +400,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows enumeration through the components of a <c>Vector2d</c> using a foreach loop, auto-boxed version.
|
||||
/// Allows enumeration through the components of a <see cref="Vector2d"/> using a foreach loop, auto-boxed version.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This foreach loop will look like foreach(object o in Vector2d). This will auto-box the doubles in System.Double
|
||||
@@ -408,21 +411,22 @@ namespace LibBSP {
|
||||
yield return x;
|
||||
yield return y;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts this <c>Vector2d</c> into a <c>Vector3d</c>. This will be called when Vector3d v3 = v2 is used.
|
||||
/// Implicitly converts this <see cref="Vector2d"/> into a <see cref="Vector3d"/>. This will be called when <c>Vector3d v3 = v2</c> is used.
|
||||
/// </summary>
|
||||
/// <param name="v"><c>Vector2d</c> to convert</param>
|
||||
/// <returns>The input vector as a <c>Vector3d</c>, Z component set to 0</returns>
|
||||
/// <param name="v"><see cref="Vector2d"/> to convert.</param>
|
||||
/// <returns>The input vector as a <see cref="Vector3d"/>, Z component set to 0.</returns>
|
||||
public static implicit operator Vector3d(Vector2d v) {
|
||||
return new Vector3d(v.x, v.y, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts this <c>Vector2d</c> into a <c>Vector4d</c>. This will be called when Vector4d v4 = v2 is used.
|
||||
/// Implicitly converts this <see cref="Vector2d"/> into a <see cref="Vector4d"/>. This will be called when <c>Vector4d v4 = v2</c> is used.
|
||||
/// </summary>
|
||||
/// <param name="v"><c>Vector2d</c> to convert</param>
|
||||
/// <returns>The input vector as a <c>Vector4d</c>, Z and W components set to 0</returns>
|
||||
/// <param name="v"><see cref="Vector2d"/> to convert.</param>
|
||||
/// <returns>The input vector as a <see cref="Vector4d"/>, Z and W components set to 0.</returns>
|
||||
public static implicit operator Vector4d(Vector2d v) {
|
||||
return new Vector4d(v.x, v.y, 0, 0);
|
||||
}
|
||||
|
||||
@@ -11,23 +11,23 @@ namespace LibBSP {
|
||||
/// </summary>
|
||||
[Serializable] public struct Vector3d : IEquatable<Vector3d>, IEnumerable, IEnumerable<double> {
|
||||
|
||||
/// <summary>Returns <c>Vector3d</c>(NaN, NaN, NaN)</summary>
|
||||
/// <summary>Returns <see cref="Vector3d"/>(NaN, NaN, NaN).</summary>
|
||||
public static Vector3d undefined { get { return new Vector3d(System.Double.NaN, System.Double.NaN, System.Double.NaN); } }
|
||||
/// <summary>Returns <c>Vector3d</c>(1, 0, 0)</summary>
|
||||
/// <summary>Returns <see cref="Vector3d"/>(1, 0, 0).</summary>
|
||||
public static Vector3d right { get { return new Vector3d(1, 0, 0); } }
|
||||
/// <summary>Returns <c>Vector3d</c>(0, 1, 0)</summary>
|
||||
/// <summary>Returns <see cref="Vector3d"/>(0, 1, 0).</summary>
|
||||
public static Vector3d forward { get { return new Vector3d(0, 1, 0); } }
|
||||
/// <summary>Returns <c>Vector3d</c>(0, 0, 1)</summary>
|
||||
/// <summary>Returns <see cref="Vector3d"/>(0, 0, 1).</summary>
|
||||
public static Vector3d up { get { return new Vector3d(0, 0, 1); } }
|
||||
/// <summary>Returns <c>Vector3d</c>(-1, 0, 0)</summary>
|
||||
/// <summary>Returns <see cref="Vector3d"/>(-1, 0, 0).</summary>
|
||||
public static Vector3d left { get { return new Vector3d(-1, 0, 0); } }
|
||||
/// <summary>Returns <c>Vector3d</c>(0, -1, 0)</summary>
|
||||
/// <summary>Returns <see cref="Vector3d"/>(0, -1, 0).</summary>
|
||||
public static Vector3d back { get { return new Vector3d(0, -1, 0); } }
|
||||
/// <summary>Returns <c>Vector3d</c>(0, 0, -1)</summary>
|
||||
/// <summary>Returns <see cref="Vector3d"/>(0, 0, -1).</summary>
|
||||
public static Vector3d down { get { return new Vector3d(0, 0, -1); } }
|
||||
/// <summary>Returns <c>Vector3d</c>(0, 0, 0)</summary>
|
||||
/// <summary>Returns <see cref="Vector3d"/>(0, 0, 0).</summary>
|
||||
public static Vector3d zero { get { return new Vector3d(0, 0, 0); } }
|
||||
/// <summary>Returns <c>Vector3d</c>(1, 1, 1)</summary>
|
||||
/// <summary>Returns <see cref="Vector3d"/>(1, 1, 1).</summary>
|
||||
public static Vector3d one { get { return new Vector3d(1, 1, 1); } }
|
||||
|
||||
public double x;
|
||||
@@ -35,11 +35,11 @@ namespace LibBSP {
|
||||
public double z;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a component using an indexer, x=0, y=1, z=2
|
||||
/// Gets or sets a component using an indexer, x=0, y=1, z=2.
|
||||
/// </summary>
|
||||
/// <param name="index">Component to get or set</param>
|
||||
/// <returns>Component</returns>
|
||||
/// <exception cref="IndexOutOfRangeException"><paramref name="index" /> was negative or greater than 2</exception>
|
||||
/// <param name="index">Component to get or set.</param>
|
||||
/// <returns>Component.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException"><paramref name="index"/> was negative or greater than 2.</exception>
|
||||
public double this[int index] {
|
||||
get {
|
||||
switch (index) {
|
||||
@@ -79,18 +79,18 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the magnitude of this <c>Vector3d</c>, or its distance from (0, 0, 0).
|
||||
/// Gets the magnitude of this <see cref="Vector3d"/>, or its distance from (0, 0, 0).
|
||||
/// </summary>
|
||||
public double magnitude { get { return Math.Sqrt(sqrMagnitude); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the magnitude of this <c>Vector3d</c> squared. This is useful for when you are comparing the lengths of two vectors
|
||||
/// but don't need to know the exact length, and avoids a square root.
|
||||
/// Gets the magnitude of this <see cref="Vector3d"/> squared. This is useful for when you are comparing the lengths of two vectors
|
||||
/// but don't need to know the exact length, and avoids calculating a square root.
|
||||
/// </summary>
|
||||
public double sqrMagnitude { get { return System.Math.Pow(x, 2) + System.Math.Pow(y, 2) + System.Math.Pow(z, 2); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the normalized version of this <c>Vector3d</c> (unit vector with the same direction).
|
||||
/// Gets the normalized version of this <see cref="Vector3d"/> (unit vector with the same direction).
|
||||
/// </summary>
|
||||
public Vector3d normalized {
|
||||
get {
|
||||
@@ -101,9 +101,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Vector3d</c> object using elements in the passed array as components
|
||||
/// Creates a new <see cref="Vector3d"/> object using elements in the passed array as components.
|
||||
/// </summary>
|
||||
/// <param name="point">Components of the vector</param>
|
||||
/// <param name="point">Components of the vector.</param>
|
||||
public Vector3d(params float[] point) {
|
||||
if (point == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -124,9 +124,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Vector3d</c> object using elements in the passed array as components
|
||||
/// Creates a new <see cref="Vector3d"/> object using elements in the passed array as components.
|
||||
/// </summary>
|
||||
/// <param name="point">Components of the vector</param>
|
||||
/// <param name="point">Components of the vector.</param>
|
||||
public Vector3d(params double[] point) {
|
||||
if (point == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -147,9 +147,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Vector3d</c> object using elements in the passed array as components
|
||||
/// Creates a new <see cref="Vector3d"/> object using elements in the passed array as components.
|
||||
/// </summary>
|
||||
/// <param name="point">Components of the vector</param>
|
||||
/// <param name="point">Components of the vector.</param>
|
||||
public Vector3d(params int[] point) {
|
||||
if (point == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -170,9 +170,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Crates a new <c>Vector3d</c> instance using the components from the supplied <c>Vector3d</c>
|
||||
/// Crates a new <see cref="Vector3d"/> instance using the components from the supplied <see cref="Vector3d"/>.
|
||||
/// </summary>
|
||||
/// <param name="vector">Vector to copy components from</param>
|
||||
/// <param name="vector">Vector to copy components from.</param>
|
||||
public Vector3d(Vector3d vector) {
|
||||
x = vector.x;
|
||||
y = vector.y;
|
||||
@@ -182,9 +182,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Adds two vectors together componentwise. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector to add</param>
|
||||
/// <param name="v2">Second vector to add</param>
|
||||
/// <returns>The resulting vector</returns>
|
||||
/// <param name="v1">First vector to add.</param>
|
||||
/// <param name="v2">Second vector to add.</param>
|
||||
/// <returns>The resulting vector.</returns>
|
||||
public static Vector3d operator +(Vector3d v1, Vector3d v2) {
|
||||
return Add(v1, v2);
|
||||
}
|
||||
@@ -192,87 +192,87 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Adds two vectors together componentwise. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector to add</param>
|
||||
/// <param name="v2">Second vector to add</param>
|
||||
/// <returns>The resulting vector</returns>
|
||||
/// <param name="v1">First vector to add.</param>
|
||||
/// <param name="v2">Second vector to add.</param>
|
||||
/// <returns>The resulting vector.</returns>
|
||||
public static Vector3d Add(Vector3d v1, Vector3d v2) {
|
||||
return new Vector3d(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts one vector from another. This operation is NOT commutative
|
||||
/// Subtracts one vector from another. This operation is NOT commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to subtract from</param>
|
||||
/// <param name="v2">Vector to subtract</param>
|
||||
/// <returns>Difference from <paramref name="v1" /> to <paramref name="v2" /></returns>
|
||||
/// <param name="v1">Vector to subtract from.</param>
|
||||
/// <param name="v2">Vector to subtract.</param>
|
||||
/// <returns>Difference from <paramref name="v1"/> to <paramref name="v2"/>.</returns>
|
||||
public static Vector3d operator -(Vector3d v1, Vector3d v2) {
|
||||
return Subtract(v1, v2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts one vector from another. This operation is NOT commutative
|
||||
/// Subtracts one vector from another. This operation is NOT commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to subtract from</param>
|
||||
/// <param name="v2">Vector to subtract</param>
|
||||
/// <returns>Difference from <paramref name="v1" /> to <paramref name="v2" /></returns>
|
||||
/// <param name="v1">Vector to subtract from.</param>
|
||||
/// <param name="v2">Vector to subtract.</param>
|
||||
/// <returns>Difference from <paramref name="v1"/> to <paramref name="v2"/>.</returns>
|
||||
public static Vector3d Subtract(Vector3d v1, Vector3d v2) {
|
||||
return new Vector3d(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0, 0) - <paramref name="v1" />.
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0, 0) - <paramref name="v1"/>.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to negate</param>
|
||||
/// <returns><paramref name="v1" /> with all components negated</returns>
|
||||
/// <param name="v1">Vector to negate.</param>
|
||||
/// <returns><paramref name="v1"/> with all components negated.</returns>
|
||||
public static Vector3d operator -(Vector3d v1) {
|
||||
return Negate(v1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0, 0) - <paramref name="v1" />.
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0, 0) - <paramref name="v1"/>.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to negate</param>
|
||||
/// <returns><paramref name="v1" /> with all components negated</returns>
|
||||
/// <param name="v1">Vector to negate.</param>
|
||||
/// <returns><paramref name="v1"/> with all components negated.</returns>
|
||||
public static Vector3d Negate(Vector3d v1) {
|
||||
return new Vector3d(-v1.x, -v1.y, -v1.z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector3d operator *(Vector3d v1, double scalar) {
|
||||
return Scale(v1, scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector3d operator *(double scalar, Vector3d v1) {
|
||||
return Scale(v1, scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector3d Scale(Vector3d v1, double scalar) {
|
||||
return new Vector3d(v1.x * scalar, v1.y * scalar, v1.z * scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector3d Scale(double scalar, Vector3d v1) {
|
||||
return Scale(v1, scalar);
|
||||
}
|
||||
@@ -280,9 +280,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Multiplies two vectors together componentwise. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>Resulting vector when the passed vectors' components are multiplied</returns>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Resulting vector when the passed vectors' components are multiplied.</returns>
|
||||
public static Vector3d Scale(Vector3d v1, Vector3d v2) {
|
||||
return new Vector3d(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
|
||||
}
|
||||
@@ -290,9 +290,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Vector dot product. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>Dot product of these two vectors</returns>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Dot product of these two vectors.</returns>
|
||||
public static double operator *(Vector3d v1, Vector3d v2) {
|
||||
return Dot(v1, v2);
|
||||
}
|
||||
@@ -300,9 +300,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Vector dot product. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>Dot product of these two vectors</returns>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Dot product of these two vectors.</returns>
|
||||
public static double Dot(Vector3d v1, Vector3d v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
}
|
||||
@@ -310,8 +310,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Vector cross product. This operation is NOT commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Cross product of these two vectors. Can be thought of as the normal to the plane defined by these two vectors.</returns>
|
||||
public static Vector3d operator ^(Vector3d v1, Vector3d v2) {
|
||||
return Cross(v1, v2);
|
||||
@@ -320,28 +320,29 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Vector cross product. This operation is NOT commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Cross product of these two vectors. Can be thought of as the normal to the plane defined by these two vectors.</returns>
|
||||
public static Vector3d Cross(Vector3d v1, Vector3d v2) {
|
||||
return new Vector3d(v1.y * v2.z - v2.y * v1.z, v2.x * v1.z - v1.x * v2.z, v1.x * v2.y - v2.x * v1.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar division. Divides all components of <paramref name="v1" /> by <paramref name="divisor" /> and returns the result.
|
||||
/// Scalar division. Divides all components of <paramref name="v1"/> by <paramref name="divisor"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to divide</param>
|
||||
/// <param name="divisor">Divisor</param>
|
||||
/// <returns>Resulting vector when all components of <paramref name="v1" /> are divided by <paramref name="divisor" />.</returns>
|
||||
/// <param name="v1">Vector to divide.</param>
|
||||
/// <param name="divisor">Divisor.</param>
|
||||
/// <returns>Resulting vector when all components of <paramref name="v1"/> are divided by <paramref name="divisor"/>.</returns>
|
||||
public static Vector3d operator /(Vector3d v1, double divisor) {
|
||||
return Scale(v1, 1.0 / divisor);
|
||||
}
|
||||
|
||||
#region IEquatable
|
||||
/// <summary>
|
||||
/// Equivalency. Returns <c>true</c> if the components of two vectors are equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the components of two vectors are equal or approximately equal.</returns>
|
||||
public static bool operator ==(Vector3d v1, Vector3d v2) {
|
||||
return v1.Equals(v2);
|
||||
@@ -350,8 +351,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Non-Equivalency. Returns <c>true</c> if the components of two vectors are not equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the components of two vectors are not equal or approximately equal.</returns>
|
||||
public static bool operator !=(Vector3d v1, Vector3d v2) {
|
||||
return !v1.Equals(v2);
|
||||
@@ -360,8 +361,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Equivalency. Returns <c>true</c> if the components of two vectors are equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the components of two vectors are equal or approximately equal.</returns>
|
||||
public bool Equals(Vector3d other) {
|
||||
return (Math.Abs(x - other.x) < 0.001 && Math.Abs(y - other.y) < 0.001 && Math.Abs(z - other.z) < 0.001);
|
||||
@@ -370,8 +371,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Equivalency. Returns <c>true</c> if the other object is a vector, and the components of two vectors are equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the other object is a vector, and the components of two vectors are equal or approximately equal.</returns>
|
||||
public override bool Equals(object obj) {
|
||||
if (object.ReferenceEquals(obj, null) || !GetType().IsAssignableFrom(obj.GetType())) { return false; }
|
||||
@@ -381,24 +382,25 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Generates a hash code for this instance based on instance data.
|
||||
/// </summary>
|
||||
/// <returns>The hash code for this instance</returns>
|
||||
/// <returns>The hash code for this instance.</returns>
|
||||
public override int GetHashCode() {
|
||||
return x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode();
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the distance from this vector to another.
|
||||
/// </summary>
|
||||
/// <param name="to">Vector to calculate distance to</param>
|
||||
/// <returns>Distance from this vector to the passed vector</returns>
|
||||
/// <param name="to">Vector to calculate distance to.</param>
|
||||
/// <returns>Distance from this vector to the passed vector.</returns>
|
||||
public double Distance(Vector3d to) {
|
||||
return (this - to).magnitude;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a human-readable string representation of this vector.
|
||||
/// Gets a human-readable <c>string</c> representation of this vector.
|
||||
/// </summary>
|
||||
/// <returns>Human-readable string representation of this vector</returns>
|
||||
/// <returns>Human-readable <c>string</c> representation of this vector.</returns>
|
||||
public override string ToString() {
|
||||
return string.Format("( {0} , {1} , {2} )", x.ToString(), y.ToString(), z.ToString());
|
||||
}
|
||||
@@ -417,10 +419,10 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the area of the triangle defined by three points using Heron's formula.
|
||||
/// </summary>
|
||||
/// <param name="p1">First vertex of triangle</param>
|
||||
/// <param name="p2">Second vertex of triangle</param>
|
||||
/// <param name="p3">Third vertex of triangle</param>
|
||||
/// <returns>Area of the triangle defined by these three vertices</returns>
|
||||
/// <param name="p1">First vertex of triangle.</param>
|
||||
/// <param name="p2">Second vertex of triangle.</param>
|
||||
/// <param name="p3">Third vertex of triangle.</param>
|
||||
/// <returns>Area of the triangle defined by these three vertices.</returns>
|
||||
public static double TriangleArea(Vector3d p1, Vector3d p2, Vector3d p3) {
|
||||
return Math.Sqrt(SqrTriangleArea(p1, p2, p3)) / 4.0;
|
||||
}
|
||||
@@ -428,10 +430,10 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the square of the area of the triangle defined by three points. This is useful when simply comparing two areas when you don't need to know exactly what the area is.
|
||||
/// </summary>
|
||||
/// <param name="p1">First vertex of triangle</param>
|
||||
/// <param name="p2">Second vertex of triangle</param>
|
||||
/// <param name="p3">Third vertex of triangle</param>
|
||||
/// <returns>Square of the area of the triangle defined by these three vertices</returns>
|
||||
/// <param name="p1">First vertex of triangle.</param>
|
||||
/// <param name="p2">Second vertex of triangle.</param>
|
||||
/// <param name="p3">Third vertex of triangle.</param>
|
||||
/// <returns>Square of the area of the triangle defined by these three vertices.</returns>
|
||||
public static double SqrTriangleArea(Vector3d p1, Vector3d p2, Vector3d p3) {
|
||||
double a = p1.Distance(p2);
|
||||
double b = p1.Distance(p3);
|
||||
@@ -439,8 +441,9 @@ namespace LibBSP {
|
||||
return 4.0 * a * a * b * b - Math.Pow((a * a) + (b * b) - (c * c), 2);
|
||||
}
|
||||
|
||||
#region IEnumerable
|
||||
/// <summary>
|
||||
/// Allows enumeration through the components of a <c>Vector3d</c> using a foreach loop.
|
||||
/// Allows enumeration through the components of a <see cref="Vector3d"/> using a foreach loop.
|
||||
/// </summary>
|
||||
public IEnumerator<double> GetEnumerator() {
|
||||
yield return x;
|
||||
@@ -449,7 +452,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows enumeration through the components of a <c>Vector3d</c> using a foreach loop, auto-boxed version.
|
||||
/// Allows enumeration through the components of a <see cref="Vector3d"/> using a foreach loop, auto-boxed version.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This foreach loop will look like foreach(object o in Vector3d). This will auto-box the doubles in System.Double
|
||||
@@ -461,30 +464,31 @@ namespace LibBSP {
|
||||
yield return y;
|
||||
yield return z;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts this <c>Vector3d</c> into a <c>Vector2d</c>. This will be called when Vector2d v2 = v3 is used.
|
||||
/// Implicitly converts this <see cref="Vector3d"/> into a <see cref="Vector2d"/>. This will be called when <c>Vector2d v2 = v3</c> is used.
|
||||
/// </summary>
|
||||
/// <param name="v"><c>Vector3d</c> to convert</param>
|
||||
/// <returns>The input vector as a <c>Vector2d</c>, Z component discarded</returns>
|
||||
/// <param name="v"><see cref="Vector3d"/> to convert.</param>
|
||||
/// <returns>The input vector as a <see cref="Vector2d"/>, Z component discarded.</returns>
|
||||
public static implicit operator Vector2d(Vector3d v) {
|
||||
return new Vector2d(v.x, v.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts this <c>Vector3d</c> into a <c>Vector4d</c>. This will be called when Vector4d v4 = v3 is used.
|
||||
/// Implicitly converts this <see cref="Vector3d"/> into a <see cref="Vector4d"/>. This will be called when <c>Vector4d v4 = v3</c> is used.
|
||||
/// </summary>
|
||||
/// <param name="v"><c>Vector3d</c> to convert</param>
|
||||
/// <returns>The input vector as a <c>Vector4d</c>, W component set to 0</returns>
|
||||
/// <param name="v"><see cref="Vector3d"/> to convert.</param>
|
||||
/// <returns>The input vector as a <see cref="Vector4d"/>, W component set to 0.</returns>
|
||||
public static implicit operator Vector4d(Vector3d v) {
|
||||
return new Vector4d(v.x, v.y, v.z, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts this <c>Vector3d</c> into a <c>Color</c> by interpreting (x, y, z) as (r, g, b) respectively.
|
||||
/// Implicitly converts this <see cref="Vector3d"/> into a <c>Color</c> by interpreting (x, y, z) as (r, g, b) respectively, and alpha set to 100%.
|
||||
/// </summary>
|
||||
/// <param name="v"><c>Vector3d</c> to convert</param>
|
||||
/// <returns>This <c>Vector3d</c> in a <c>Color</c> object interpreted as RGB.</returns>
|
||||
/// <param name="v"><see cref="Vector3d"/> to convert.</param>
|
||||
/// <returns>This <see cref="Vector3d"/> in a <c>Color</c> object interpreted as RGB.</returns>
|
||||
public static implicit operator Color32(Vector3d v) {
|
||||
return Color32Extensions.FromArgb(255, (int)Math.Max(v.x, 255), (int)Math.Max(v.y, 255), (int)Math.Max(v.z, 255));
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace LibBSP {
|
||||
/// </summary>
|
||||
[Serializable] public struct Vector4d : IEquatable<Vector4d>, IEnumerable, IEnumerable<double> {
|
||||
|
||||
/// <summary>Returns <c>Vector4d</c>(NaN, NaN, NaN)</summary>
|
||||
/// <summary>Returns <see cref="Vector4d"/>(NaN, NaN, NaN, NaN).</summary>
|
||||
public static Vector4d undefined { get { return new Vector4d(System.Double.NaN, System.Double.NaN, System.Double.NaN, System.Double.NaN); } }
|
||||
/// <summary>Returns <c>Vector4d</c>(0, 0, 0, 0)</summary>
|
||||
/// <summary>Returns <see cref="Vector4d"/>(0, 0, 0, 0).</summary>
|
||||
public static Vector4d zero { get { return new Vector4d(0, 0, 0, 0); } }
|
||||
/// <summary>Returns <c>Vector4d</c>(1, 1, 1, 1)</summary>
|
||||
/// <summary>Returns <see cref="Vector4d"/>(1, 1, 1, 1).</summary>
|
||||
public static Vector4d one { get { return new Vector4d(1, 1, 1, 1); } }
|
||||
|
||||
public double x;
|
||||
@@ -24,11 +24,11 @@ namespace LibBSP {
|
||||
public double w;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a component using an indexer, x=0, y=1, z=2, w=3
|
||||
/// Gets or sets a component using an indexer, x=0, y=1, z=2, w=3.
|
||||
/// </summary>
|
||||
/// <param name="index">Component to get or set</param>
|
||||
/// <returns>Component</returns>
|
||||
/// <exception cref="IndexOutOfRangeException"><paramref name="index" /> was negative or greater than 3</exception>
|
||||
/// <param name="index">Component to get or set.</param>
|
||||
/// <returns>Component.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException"><paramref name="index"/> was negative or greater than 3.</exception>
|
||||
public double this[int index] {
|
||||
get {
|
||||
switch (index) {
|
||||
@@ -75,18 +75,18 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the magnitude of this <c>Vector4d</c>, or its distance from (0, 0, 0, 0).
|
||||
/// Gets the magnitude of this <see cref="Vector4d"/>, or its distance from (0, 0, 0, 0).
|
||||
/// </summary>
|
||||
public double magnitude { get { return Math.Sqrt(sqrMagnitude); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the magnitude of this <c>Vector4d</c> squared. This is useful for when you are comparing the lengths of two vectors
|
||||
/// but don't need to know the exact length, and avoids a square root.
|
||||
/// Gets the magnitude of this <see cref="Vector4d"/> squared. This is useful for when you are comparing the lengths of two vectors
|
||||
/// but don't need to know the exact length, and avoids calculating a square root.
|
||||
/// </summary>
|
||||
public double sqrMagnitude { get { return System.Math.Pow(x, 2) + System.Math.Pow(y, 2) + System.Math.Pow(z, 2) + System.Math.Pow(w, 2); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the normalized version of this <c>Vector4d</c> (unit vector with the same direction).
|
||||
/// Gets the normalized version of this <see cref="Vector4d"/> (unit vector with the same direction).
|
||||
/// </summary>
|
||||
public Vector4d normalized {
|
||||
get {
|
||||
@@ -97,9 +97,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Vector4d</c> object using elements in the passed array as components
|
||||
/// Creates a new <see cref="Vector4d"/> object using elements in the passed array as components.
|
||||
/// </summary>
|
||||
/// <param name="point">Components of the vector</param>
|
||||
/// <param name="point">Components of the vector.</param>
|
||||
public Vector4d(params float[] point) {
|
||||
if (point == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -126,9 +126,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Vector4d</c> object using elements in the passed array as components
|
||||
/// Creates a new <see cref="Vector4d"/> object using elements in the passed array as components.
|
||||
/// </summary>
|
||||
/// <param name="point">Components of the vector</param>
|
||||
/// <param name="point">Components of the vector.</param>
|
||||
public Vector4d(params double[] point) {
|
||||
if (point == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -155,9 +155,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>Vector4d</c> object using elements in the passed array as components
|
||||
/// Creates a new <see cref="Vector4d"/> object using elements in the passed array as components.
|
||||
/// </summary>
|
||||
/// <param name="point">Components of the vector</param>
|
||||
/// <param name="point">Components of the vector.</param>
|
||||
public Vector4d(params int[] point) {
|
||||
if (point == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -184,9 +184,9 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Crates a new <c>Vector4d</c> instance using the components from the supplied <c>Vector4d</c>
|
||||
/// Crates a new <see cref="Vector4d"/> instance using the components from the supplied <see cref="Vector4d"/>.
|
||||
/// </summary>
|
||||
/// <param name="vector">Vector to copy components from</param>
|
||||
/// <param name="vector">Vector to copy components from.</param>
|
||||
public Vector4d(Vector4d vector) {
|
||||
x = vector.x;
|
||||
y = vector.y;
|
||||
@@ -197,9 +197,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Adds two vectors together componentwise. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector to add</param>
|
||||
/// <param name="v2">Second vector to add</param>
|
||||
/// <returns>The resulting vector</returns>
|
||||
/// <param name="v1">First vector to add.</param>
|
||||
/// <param name="v2">Second vector to add.</param>
|
||||
/// <returns>The resulting vector.</returns>
|
||||
public static Vector4d operator +(Vector4d v1, Vector4d v2) {
|
||||
return Add(v1, v2);
|
||||
}
|
||||
@@ -207,87 +207,87 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Adds two vectors together componentwise. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector to add</param>
|
||||
/// <param name="v2">Second vector to add</param>
|
||||
/// <returns>The resulting vector</returns>
|
||||
/// <param name="v1">First vector to add.</param>
|
||||
/// <param name="v2">Second vector to add.</param>
|
||||
/// <returns>The resulting vector.</returns>
|
||||
public static Vector4d Add(Vector4d v1, Vector4d v2) {
|
||||
return new Vector4d(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts one vector from another. This operation is NOT commutative
|
||||
/// Subtracts one vector from another. This operation is NOT commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to subtract from</param>
|
||||
/// <param name="v2">Vector to subtract</param>
|
||||
/// <returns>Difference from <paramref name="v1" /> to <paramref name="v2" /></returns>
|
||||
/// <param name="v1">Vector to subtract from.</param>
|
||||
/// <param name="v2">Vector to subtract.</param>
|
||||
/// <returns>Difference from <paramref name="v1"/> to <paramref name="v2"/>.</returns>
|
||||
public static Vector4d operator -(Vector4d v1, Vector4d v2) {
|
||||
return Subtract(v1, v2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts one vector from another. This operation is NOT commutative
|
||||
/// Subtracts one vector from another. This operation is NOT commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to subtract from</param>
|
||||
/// <param name="v2">Vector to subtract</param>
|
||||
/// <returns>Difference from <paramref name="v1" /> to <paramref name="v2" /></returns>
|
||||
/// <param name="v1">Vector to subtract from.</param>
|
||||
/// <param name="v2">Vector to subtract.</param>
|
||||
/// <returns>Difference from <paramref name="v1"/> to <paramref name="v2"/>.</returns>
|
||||
public static Vector4d Subtract(Vector4d v1, Vector4d v2) {
|
||||
return new Vector4d(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0, 0, 0) - <paramref name="v1" />.
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0, 0, 0) - <paramref name="v1"/>.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to negate</param>
|
||||
/// <returns><paramref name="v1" /> with all components negated</returns>
|
||||
/// <param name="v1">Vector to negate.</param>
|
||||
/// <returns><paramref name="v1"/> with all components negated.</returns>
|
||||
public static Vector4d operator -(Vector4d v1) {
|
||||
return Negate(v1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0, 0, 0) - <paramref name="v1" />.
|
||||
/// Returns the negative of this vector. Equivalent to (0, 0, 0, 0) - <paramref name="v1"/>.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to negate</param>
|
||||
/// <returns><paramref name="v1" /> with all components negated</returns>
|
||||
/// <param name="v1">Vector to negate.</param>
|
||||
/// <returns><paramref name="v1"/> with all components negated.</returns>
|
||||
public static Vector4d Negate(Vector4d v1) {
|
||||
return new Vector4d(-v1.x, -v1.y, -v1.z, -v1.w);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector4d operator *(Vector4d v1, double scalar) {
|
||||
return Scale(v1, scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector4d operator *(double scalar, Vector4d v1) {
|
||||
return Scale(v1, scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector4d Scale(Vector4d v1, double scalar) {
|
||||
return new Vector4d(v1.x * scalar, v1.y * scalar, v1.z * scalar, v1.w * scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1" /> by <paramref name="scalar" /> and returns the result.
|
||||
/// Scalar multiplication. Multiplies all components of <paramref name="v1"/> by <paramref name="scalar"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="scalar">Scalar</param>
|
||||
/// <param name="v1">Vector to scale</param>
|
||||
/// <returns>Resulting Vector</returns>
|
||||
/// <param name="scalar">Scalar.</param>
|
||||
/// <param name="v1">Vector to scale.</param>
|
||||
/// <returns>Resulting Vector.</returns>
|
||||
public static Vector4d Scale(double scalar, Vector4d v1) {
|
||||
return Scale(v1, scalar);
|
||||
}
|
||||
@@ -295,9 +295,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Multiplies two vectors together componentwise. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>Resulting vector when the passed vectors' components are multiplied</returns>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Resulting vector when the passed vectors' components are multiplied.</returns>
|
||||
public static Vector4d Scale(Vector4d v1, Vector4d v2) {
|
||||
return new Vector4d(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w);
|
||||
}
|
||||
@@ -305,9 +305,9 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Vector dot product. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>Dot product of these two vectors</returns>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Dot product of these two vectors.</returns>
|
||||
public static double operator *(Vector4d v1, Vector4d v2) {
|
||||
return Dot(v1, v2);
|
||||
}
|
||||
@@ -315,28 +315,29 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Vector dot product. This operation is commutative.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>Dot product of these two vectors</returns>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns>Dot product of these two vectors.</returns>
|
||||
public static double Dot(Vector4d v1, Vector4d v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scalar division. Divides all components of <paramref name="v1" /> by <paramref name="divisor" /> and returns the result.
|
||||
/// Scalar division. Divides all components of <paramref name="v1"/> by <paramref name="divisor"/> and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="v1">Vector to divide</param>
|
||||
/// <param name="divisor">Divisor</param>
|
||||
/// <returns>Resulting vector when all components of <paramref name="v1" /> are divided by <paramref name="divisor" />.</returns>
|
||||
/// <param name="v1">Vector to divide.</param>
|
||||
/// <param name="divisor">Divisor.</param>
|
||||
/// <returns>Resulting vector when all components of <paramref name="v1"/> are divided by <paramref name="divisor"/>.</returns>
|
||||
public static Vector4d operator /(Vector4d v1, double divisor) {
|
||||
return Scale(v1, 1.0 / divisor);
|
||||
}
|
||||
|
||||
#region IEquatable
|
||||
/// <summary>
|
||||
/// Equivalency. Returns <c>true</c> if the components of two vectors are equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the components of two vectors are equal or approximately equal.</returns>
|
||||
public static bool operator ==(Vector4d v1, Vector4d v2) {
|
||||
return v1.Equals(v2);
|
||||
@@ -345,8 +346,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Non-Equivalency. Returns <c>true</c> if the components of two vectors are not equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the components of two vectors are not equal or approximately equal.</returns>
|
||||
public static bool operator !=(Vector4d v1, Vector4d v2) {
|
||||
return !v1.Equals(v2);
|
||||
@@ -355,8 +356,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Equivalency. Returns <c>true</c> if the components of two vectors are equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the components of two vectors are equal or approximately equal.</returns>
|
||||
public bool Equals(Vector4d other) {
|
||||
return (Math.Abs(x - other.x) < 0.001 && Math.Abs(y - other.y) < 0.001 && Math.Abs(z - other.z) < 0.001 && Math.Abs(w - other.w) < 0.001);
|
||||
@@ -365,8 +366,8 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Equivalency. Returns <c>true</c> if the other object is a vector, and the components of two vectors are equal or approximately equal.
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <param name="v1">First vector.</param>
|
||||
/// <param name="v2">Second vector.</param>
|
||||
/// <returns><c>true</c> if the other object is a vector, and the components of two vectors are equal or approximately equal.</returns>
|
||||
public override bool Equals(object obj) {
|
||||
if (object.ReferenceEquals(obj, null) || !GetType().IsAssignableFrom(obj.GetType())) { return false; }
|
||||
@@ -376,24 +377,25 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Generates a hash code for this instance based on instance data.
|
||||
/// </summary>
|
||||
/// <returns>The hash code for this instance</returns>
|
||||
/// <returns>The hash code for this instance.</returns>
|
||||
public override int GetHashCode() {
|
||||
return x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode() ^ w.GetHashCode();
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the distance from this vector to another.
|
||||
/// </summary>
|
||||
/// <param name="to">Vector to calculate distance to</param>
|
||||
/// <returns>Distance from this vector to the passed vector</returns>
|
||||
/// <param name="to">Vector to calculate distance to.</param>
|
||||
/// <returns>Distance from this vector to the passed vector.</returns>
|
||||
public double Distance(Vector4d to) {
|
||||
return (this - to).magnitude;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a human-readable string representation of this vector.
|
||||
/// Gets a human-readable <c>string</c> representation of this vector.
|
||||
/// </summary>
|
||||
/// <returns>Human-readable string representation of this vector</returns>
|
||||
/// <returns>Human-readable <c>string</c> representation of this vector.</returns>
|
||||
public override string ToString() {
|
||||
return string.Format("( {0} , {1} , {2} , {3} )", x.ToString(), y.ToString(), z.ToString(), w.ToString());
|
||||
}
|
||||
@@ -413,10 +415,10 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the area of the triangle defined by three points using Heron's formula.
|
||||
/// </summary>
|
||||
/// <param name="p1">First vertex of triangle</param>
|
||||
/// <param name="p2">Second vertex of triangle</param>
|
||||
/// <param name="p3">Third vertex of triangle</param>
|
||||
/// <returns>Area of the triangle defined by these three vertices</returns>
|
||||
/// <param name="p1">First vertex of triangle.</param>
|
||||
/// <param name="p2">Second vertex of triangle.</param>
|
||||
/// <param name="p3">Third vertex of triangle.</param>
|
||||
/// <returns>Area of the triangle defined by these three vertices.</returns>
|
||||
public static double TriangleArea(Vector4d p1, Vector4d p2, Vector4d p3) {
|
||||
return Math.Sqrt(SqrTriangleArea(p1, p2, p3)) / 4.0;
|
||||
}
|
||||
@@ -424,10 +426,10 @@ namespace LibBSP {
|
||||
/// <summary>
|
||||
/// Gets the square of the area of the triangle defined by three points. This is useful when simply comparing two areas when you don't need to know exactly what the area is.
|
||||
/// </summary>
|
||||
/// <param name="p1">First vertex of triangle</param>
|
||||
/// <param name="p2">Second vertex of triangle</param>
|
||||
/// <param name="p3">Third vertex of triangle</param>
|
||||
/// <returns>Square of the area of the triangle defined by these three vertices</returns>
|
||||
/// <param name="p1">First vertex of triangle.</param>
|
||||
/// <param name="p2">Second vertex of triangl.</param>
|
||||
/// <param name="p3">Third vertex of triangle.</param>
|
||||
/// <returns>Square of the area of the triangle defined by these three vertices.</returns>
|
||||
public static double SqrTriangleArea(Vector4d p1, Vector4d p2, Vector4d p3) {
|
||||
double a = p1.Distance(p2);
|
||||
double b = p1.Distance(p3);
|
||||
@@ -435,8 +437,9 @@ namespace LibBSP {
|
||||
return 4.0 * a * a * b * b - Math.Pow((a * a) + (b * b) - (c * c), 2);
|
||||
}
|
||||
|
||||
#region IEnumerable
|
||||
/// <summary>
|
||||
/// Allows enumeration through the components of a <c>Vector4d</c> using a foreach loop.
|
||||
/// Allows enumeration through the components of a <see cref="Vector4d"/> using a foreach loop.
|
||||
/// </summary>
|
||||
public IEnumerator<double> GetEnumerator() {
|
||||
yield return x;
|
||||
@@ -446,7 +449,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows enumeration through the components of a <c>Vector4d</c> using a foreach loop, auto-boxed version.
|
||||
/// Allows enumeration through the components of a <see cref="Vector4d"/> using a foreach loop, auto-boxed version.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This foreach loop will look like foreach(object o in Vector4d). This will auto-box the doubles in System.Double
|
||||
@@ -459,31 +462,32 @@ namespace LibBSP {
|
||||
yield return z;
|
||||
yield return w;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts this <c>Vector4d</c> into a <c>Vector2d</c>. This will be called when Vector2d v2 = v4 is used.
|
||||
/// Implicitly converts this <see cref="Vector4d"/> into a <see cref="Vector2d"/>. This will be called when Vector2d v2 = v4 is used.
|
||||
/// </summary>
|
||||
/// <param name="v"><c>Vector4d</c> to convert</param>
|
||||
/// <returns>The input vector as a <c>Vector2d</c>, Z and W components discarded</returns>
|
||||
/// <param name="v"><see cref="Vector4d"/> to convert.</param>
|
||||
/// <returns>The input vector as a <see cref="Vector2d"/>, Z and W components discarded.</returns>
|
||||
public static implicit operator Vector2d(Vector4d v) {
|
||||
return new Vector2d(v.x, v.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts this <c>Vector4d</c> into a <c>Vector3d</c>. This will be called when Vector3d v3 = v4 is used.
|
||||
/// Implicitly converts this <see cref="Vector4d"/> into a <see cref="Vector3d"/>. This will be called when Vector3d v3 = v4 is used.
|
||||
/// </summary>
|
||||
/// <param name="v"><c>Vector4d</c> to convert</param>
|
||||
/// <returns>The input vector as a <c>Vector3d</c>, W component discarded</returns>
|
||||
/// <param name="v"><see cref="Vector4d"/> to convert.</param>
|
||||
/// <returns>The input vector as a <see cref="Vector3d"/>, W component discarded.</returns>
|
||||
public static implicit operator Vector3d(Vector4d v) {
|
||||
return new Vector3d(v.x, v.y, v.z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts this <c>Vector4d</c> into a <c>Color</c> by interpreting (x, y, z) as (r, g, b) respectively, and w as alpha.
|
||||
/// Implicitly converts this <see cref="Vector4d"/> into a <c>Color</c> by interpreting (x, y, z) as (r, g, b) respectively, and w as alpha.
|
||||
/// Assumes colors range from 0 to 255.
|
||||
/// </summary>
|
||||
/// <param name="v"><c>Vector4d</c> to convert</param>
|
||||
/// <returns>This <c>Vector4d</c> in a <c>Color</c> object interpreted as RGBA.</returns>
|
||||
/// <param name="v"><see cref="Vector4d"/> to convert.</param>
|
||||
/// <returns>This <see cref="Vector4d"/> in a <c>Color</c> object interpreted as RGBA.</returns>
|
||||
public static implicit operator Color32(Vector4d v) {
|
||||
return Color32Extensions.FromArgb((int)Math.Max(v.w, 255), (int)Math.Max(v.x, 255), (int)Math.Max(v.y, 255), (int)Math.Max(v.z, 255));
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ namespace LibBSP {
|
||||
public bool isWater = false;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new empty <c>MAPBrush</c> object. Internal data will have to be set manually.
|
||||
/// Creates a new empty <see cref="MAPBrush"/> object. Internal data will have to be set manually.
|
||||
/// </summary>
|
||||
public MAPBrush() { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>MAPBrush</c> object using the supplied <c>string</c> array as data.
|
||||
/// Creates a new <see cref="MAPBrush"/> object using the supplied <c>string</c> array as data.
|
||||
/// </summary>
|
||||
/// <param name="lines">Data to parse.</param>
|
||||
public MAPBrush(string[] lines) {
|
||||
|
||||
@@ -34,12 +34,12 @@ namespace LibBSP {
|
||||
public MAPDisplacement displacement;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new empty <c>MAPBrushSide</c> object. Internal data will have to be set manually.
|
||||
/// Creates a new empty <see cref="MAPBrushSide"/> object. Internal data will have to be set manually.
|
||||
/// </summary>
|
||||
public MAPBrushSide() { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a <c>MAPBrushSide</c> object using the provided <c>string</c> array as the data.
|
||||
/// Constructs a <see cref="MAPBrushSide"/> object using the provided <c>string</c> array as the data.
|
||||
/// </summary>
|
||||
/// <param name="lines">Data to parse.</param>
|
||||
public MAPBrushSide(string[] lines) {
|
||||
|
||||
@@ -25,12 +25,12 @@ namespace LibBSP {
|
||||
public float[][] alphas;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new empty <c>MAPDisplacement</c> object. Internal data will have to be set manually.
|
||||
/// Creates a new empty <see cref="MAPDisplacement"/> object. Internal data will have to be set manually.
|
||||
/// </summary>
|
||||
public MAPDisplacement() { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a <c>MAPDisplacement</c> object using the provided <c>string</c> array as the data.
|
||||
/// Constructs a <see cref="MAPDisplacement"/> object using the provided <c>string</c> array as the data.
|
||||
/// </summary>
|
||||
/// <param name="lines">Data to parse.</param>
|
||||
public MAPDisplacement(string[] lines) {
|
||||
|
||||
@@ -25,12 +25,12 @@ namespace LibBSP {
|
||||
public string texture;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new empty <c>MAPPatch</c> object. Internal data will have to be set manually.
|
||||
/// Creates a new empty <see cref="MAPPatch"/> object. Internal data will have to be set manually.
|
||||
/// </summary>
|
||||
public MAPPatch() { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <c>MAPPatch</c> object using the supplied string array as data.
|
||||
/// Constructs a new <see cref="MAPPatch"/> object using the supplied string array as data.
|
||||
/// </summary>
|
||||
/// <param name="lines">Data to parse.</param>
|
||||
public MAPPatch(string[] lines) {
|
||||
|
||||
@@ -23,9 +23,9 @@ namespace LibBSP {
|
||||
public bool bigEndian { get { return _bigEndian; } set { _bigEndian = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of a <c>BSPReader</c> class to read the specified file.
|
||||
/// Creates a new instance of a <see cref="BSPReader"/> class to read the specified file.
|
||||
/// </summary>
|
||||
/// <param name="file">The <c>FileInfo</c> representing the file this <c>BSPReader</c> should read.</param>
|
||||
/// <param name="file">The <c>FileInfo</c> representing the file this <see cref="BSPReader"/> should read.</param>
|
||||
public BSPReader(FileInfo file) {
|
||||
if (!File.Exists(file.FullName)) {
|
||||
throw new FileNotFoundException("Unable to open BSP file; file " + file.FullName + " not found.");
|
||||
@@ -96,12 +96,6 @@ namespace LibBSP {
|
||||
case MapType.DMoMaM: {
|
||||
return ReadLumpFromOffsetLengthPairAtOffset(8 + (16 * index), version);
|
||||
}
|
||||
/*
|
||||
case MapType.Doom:
|
||||
case MapType.Hexen: {
|
||||
int[] ol = getLumpInfo(index);
|
||||
return readLump(ol[0], ol[1]);
|
||||
}*/
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
@@ -161,7 +155,7 @@ namespace LibBSP {
|
||||
/// <param name="data">The byte array to Xor.</param>
|
||||
/// <param name="index">The index in the key byte array to start reading from.</param>
|
||||
/// <returns>The input <c>byte</c> array Xored with the key <c>byte</c> array.</returns>
|
||||
/// <exception cref="ArgumentNullException">The passed <paramref name="data"/> parameter was null.</exception>
|
||||
/// <exception cref="ArgumentNullException">The passed <paramref name="data"/> parameter was <c>null</c>.</exception>
|
||||
private byte[] XorWithKeyStartingAtIndex(byte[] data, int index = 0) {
|
||||
if (data == null) {
|
||||
throw new ArgumentNullException();
|
||||
@@ -177,10 +171,10 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the <c>MapType</c> member most closely represented by the referenced file. If the file is
|
||||
/// found to be big-endian, this will set <c>bigEndian</c> to <c>true</c>.
|
||||
/// Tries to get the <see cref="MapType"/> member most closely represented by the referenced file. If the file is
|
||||
/// found to be big-endian, this will set <see cref="BSPReader.bigEndian"/> to <c>true</c>.
|
||||
/// </summary>
|
||||
/// <returns>The <c>MapType</c> of this BSP, <c>MapType.Undefined</c> if it could not be determined.</returns>
|
||||
/// <returns>The <see cref="MapType"/> of this BSP, <see cref="MapType.Undefined"/> if it could not be determined.</returns>
|
||||
public MapType GetVersion() {
|
||||
MapType ret = GetVersion(false);
|
||||
if (ret == MapType.Undefined) {
|
||||
@@ -193,10 +187,10 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the <c>MapType</c> member most closely represented by the referenced file.
|
||||
/// Tries to get the <see cref="MapType"/> member most closely represented by the referenced file.
|
||||
/// </summary>
|
||||
/// <param name="bigEndian">Set to <c>true</c> to attempt reading the data in big-endian byte order.</param>
|
||||
/// <returns>The <c>MapType</c> of this BSP, <c>MapType.Undefined</c> if it could not be determined.</returns>
|
||||
/// <returns>The <see cref="MapType"/> of this BSP, <see cref="MapType.Undefined"/> if it could not be determined.</returns>
|
||||
private MapType GetVersion(bool bigEndian) {
|
||||
MapType current = MapType.Undefined;
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
@@ -419,7 +413,7 @@ namespace LibBSP {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes of the <see cref="FileStream"/> and releases the handle to the File.
|
||||
/// Disposes of the <c>FileStream</c> and releases the handle to the File.
|
||||
/// </summary>
|
||||
public void Close() {
|
||||
stream.Dispose();
|
||||
|
||||
Reference in New Issue
Block a user