using System; namespace SAMP.API { public struct Vector3 { #region Class Variables private float _x, _y, _z; #endregion #region Constructor /// /// Creates a new Vector3 object. /// /// X position. /// Y position. /// Z position. public Vector3(float x, float y, float z) { this._x = x; this._y = y; this._z = z; } /// /// Creates a new Vector3 object. /// /// Uniform position. public Vector3(float v) { this._x = v; this._y = v; this._z = v; } /// /// Creates a new Vector3 object. /// /// Vector2 to copy. public Vector3(Vector2 v) { this._x = v.X; this._y = v.Y; this._z = 0f; } /// /// Creates a new Vector3 object. /// /// Vector3 to copy. public Vector3(Vector3 v) { this._x = v.X; this._y = v.Y; this._z = v.Z; } #endregion #region Accessors & Mutators /// /// Gets a zero-pointed Vector3. /// public static Vector3 Zero { get { return new Vector3(0f, 0f, 0f); } } /// /// Gets or sets the X position of this Vector3. /// public float X { get { return this._x; } set { this._x = value; } } /// /// Gets or sets the Y position of this Vector3. /// public float Y { get { return this._y; } set { this._y = value; } } /// /// Gets or sets the Z position of this Vector3. /// public float Z { get { return this._z; } set { this._z = value; } } #endregion #region Operator Overloads /// /// Add two Vector3 objects. /// /// The base term Vector3. /// The factor term Vector3 /// Returns the sum of v1 and v2. public static Vector3 operator +(Vector3 v1, Vector3 v2) { return new Vector3(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z); } /// /// Subtract two Vector3 objects. /// /// The base term Vector3. /// The factor term Vector3 /// Returns the value of v2 subratcted from v1. public static Vector3 operator -(Vector3 v1, Vector3 v2) { return new Vector3(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z); } /// /// Add two Vector3 objects. /// /// The base term Vector3. /// The factor term Vector3 /// Returns the sum of v1 and v2. public static Vector3 operator *(Vector3 v1, Vector3 v2) { return new Vector3(v1.X * v2.X, v1.Y * v2.Y, v1.Z * v2.Z); } /// /// Subtract two Vector3 objects. /// /// The base term Vector3. /// The factor term Vector3 /// Returns the value of v2 subratcted from v1. public static Vector3 operator /(Vector3 v1, Vector3 v2) { return new Vector3(v1.X / v2.X, v1.Y / v2.Y, v1.Z / v2.Z); } #endregion #region Method Overrides /// /// Returns a System.String that represents the Vector3. /// /// A System.String that represents the current Vector3. public override string ToString() { return string.Format("({0}, {1}, {2})", this.X, this.Y, this.Z); } #endregion #region Static Methods /// /// Determines the distance between two Vector3 objects. /// /// The base Vector3 term. /// The factor Vector3 term. /// Returns a double precision decimal representing the distance between v1 and v2. public static double Distance(Vector3 v1, Vector3 v2) { return Math.Sqrt(Math.Pow((double)v1.X - (double)v2.X, 2) + Math.Pow((double)v1.Y - (double)v2.Y, 2) + Math.Pow((double)v1.Z - (double)v2.Z, 2)); } #endregion #region Public Methods /// /// Determines the distance between this Vector3 and another Vector3. /// /// The Vector3 term. /// Returns a double precision decimal representing the distance between v and this Vector3. public double Distance(Vector3 v) { return Vector3.Distance(this, v); } /// /// Calculates the dot product of two vectors. /// /// The base Vector3 term. /// The factor Vector3 term. /// Returns the dot product of v1 and v2. public Vector3 Dot(Vector3 v1, Vector3 v2) { return new Vector3( x: v1.X * v2.X, y: v1.Y * v2.Y, z: v1.Z * v2.Z); } #endregion }; };