using System;
namespace ServerEngine.GuildWars.Tools
{
///
/// This class can basically be used for the whole collision/pathing/movement stuff in GW.
///
public class GWVector
{
private float deltaX;
private float deltaY;
private int planeZ;
///
/// Initializes a new instance of the class.
///
public GWVector(float deltaX, float deltaY, int planeZ)
{
this.deltaX = deltaX;
this.deltaY = deltaY;
this.planeZ = planeZ;
}
///
/// This property contains the X component of a vector.
///
public float X
{
get { return deltaX; }
set { deltaX = value; }
}
///
/// This property contains the Y component of a vector.
///
public float Y
{
get { return deltaY; }
set { deltaY = value; }
}
///
/// This property contains the plane the vector is used for.
/// The plane is known as a single chunk of trapezoids within a pmap.
///
public int PlaneZ
{
get { return planeZ; }
set { planeZ = value; }
}
///
/// This property contains the absolute length of a vector.
/// Note that this will be calculated.
///
public float Length
{
get { return (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY); }
set
{
var tmp = UnitVector;
deltaX = tmp.X * value;
deltaY = tmp.Y * value;
planeZ = tmp.PlaneZ;
}
}
///
/// This property contains a sub vector of this with the length of 1.
///
public GWVector UnitVector
{
get { return new GWVector(deltaX / Length, deltaY / Length, planeZ); }
}
///
/// Returns the angle with a given vector
///
public float CosWith(GWVector v1)
{
return (((v1.X * X) + (v1.Y * Y)) / (v1.Length * Length));
}
///
/// Returns a clone of this.
///
public GWVector Clone()
{
var result = new GWVector(0, 0, 0) { X = deltaX, Y = deltaY, PlaneZ = planeZ };
return result;
}
///
/// Operator overload.
///
public static GWVector operator +(GWVector v1, GWVector v2)
{
return new GWVector(v1.X + v2.X, v1.Y + v2.Y, v2.PlaneZ);
}
///
/// Operator overload.
///
public static GWVector operator -(GWVector v1, GWVector v2)
{
return new GWVector(v1.X - v2.X, v1.Y - v2.Y, v2.PlaneZ);
}
///
/// Operator overload.
///
public static GWVector operator *(GWVector v1, float val)
{
return new GWVector(v1.X * val, v1.Y * val, v1.PlaneZ);
}
///
/// Note: NO SKALAR Product
///
public static float operator *(GWVector v1, GWVector v2)
{
return (v1.X * v2.Y) - (v1.Y * v2.X);
}
///
/// ToString overload.
///
public override string ToString()
{
return "[" + deltaX + ", " + deltaY + "]";
}
}
}