using System;
namespace SAMP.API {
public struct Vector3 {
#region Struct Variables
private float
m_fpX,
m_fpY,
m_fpZ;
#endregion
#region Constructor
///
/// Initializes a new instance of the struct.
///
/// X position.
/// Y position.
/// Z position.
public Vector3(float x, float y, float z) {
this.m_fpX = x;
this.m_fpY = y;
this.m_fpZ = z;
}
///
/// Initializes a new instance of the struct.
///
/// Uniform position.
public Vector3(float v) {
this.m_fpX = v;
this.m_fpY = v;
this.m_fpZ = v;
}
///
/// Initializes a new instance of the struct.
///
/// The to copy.
public Vector3(Vector2 v) {
this.m_fpX = v.X;
this.m_fpY = v.Y;
this.m_fpZ = 0f;
}
///
/// Initializes a new instance of the struct.
///
/// The to copy.
public Vector3(Vector3 v) {
this.m_fpX = v.X;
this.m_fpY = v.Y;
this.m_fpZ = v.Z;
}
#endregion
#region Accessors & Mutators
///
/// Gets the zero-pointed .
///
public static Vector3 Zero {
get {
return new Vector3(0.0f, 0.0f, 0.0f);
}
}
///
/// Gets or sets the X position of this .
///
public float X {
get {
return this.m_fpX;
} set {
this.m_fpX = value;
}
}
///
/// Gets or sets the Y position of this .
///
public float Y {
get {
return this.m_fpY;
} set {
this.m_fpY = value;
}
}
///
/// Gets or sets the Z position of this .
///
public float Z {
get {
return this.m_fpZ;
} set {
this.m_fpZ = value;
}
}
#endregion
#region Operator Overloads
///
/// Adds a to a , yielding a new .
///
/// The first to add.
/// The second to add.
/// The that is the sum of the values 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);
}
///
/// Subtracts a from a , yielding a new .
///
/// The to subtract from (the minuend).
/// The to subtract (the subtrahend).
/// The that is the v1 minus v2.
public static Vector3 operator -(Vector3 v1, Vector3 v2) {
return new Vector3(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
}
///
/// Computes the product of v1 and v2, yielding a new .
///
/// The to multiply.
/// The to multiply.
/// The that is the v1 * v2.
public static Vector3 operator *(Vector3 v1, Vector3 v2) {
return new Vector3(v1.X * v2.X, v1.Y * v2.Y, v1.Z * v2.Z);
}
///
/// Computes the division of v1 and v2, yielding a new .
///
/// The to divide (the divident).
/// The to divide (the divisor).
/// The that is the v1 / v2.
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 that represents the current .
///
/// A that represents the current .
public override string ToString() {
return string.Format("({0}, {1}, {2})", this.X, this.Y, this.Z);
}
#endregion
#region Static Methods
///
/// Calculates the distance between two objects.
///
/// The base term.
/// The factor term.
/// Returns a 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));
}
///
/// Calculates the dot product of two objects.
///
/// The base term.
/// he factor term./param>
/// Returns the dot product of v1 and v2.
public static 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
#region Public Methods
///
/// Calculates the distance between the current and another.
///
/// The term.
/// Returns a representing the distance between v and the current .
public double Distance(Vector3 v) {
return Vector3.Distance(this, v);
}
#endregion
};
};