Skip to content

Instantly share code, notes, and snippets.

@alexguirre
Created September 9, 2016 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexguirre/8e8da8a3bdfd8afa54f520032ed07430 to your computer and use it in GitHub Desktop.
Save alexguirre/8e8da8a3bdfd8afa54f520032ed07430 to your computer and use it in GitHub Desktop.
// RPH
using Rage;
internal struct RotatedVector3
{
public readonly Vector3 Position;
public readonly Rotator Rotation;
public readonly float Heading;
public RotatedVector3(Vector3 position, float heading)
{
Position = position;
Heading = heading;
Rotation = new Rotator(0.0f, 0.0f, heading);
}
public RotatedVector3(Vector3 position, Rotator rotation)
{
Position = position;
Heading = rotation.Yaw;
Rotation = rotation;
}
public static RotatedVector3 Zero
{
get { return new RotatedVector3(Vector3.Zero, 0f); }
}
public static bool operator ==(RotatedVector3 left, RotatedVector3 right)
{
return left.Position == right.Position && left.Rotation == right.Rotation;
}
public static bool operator !=(RotatedVector3 left, RotatedVector3 right)
{
return left.Position != right.Position || left.Rotation != right.Rotation;
}
public static RotatedVector3 operator +(RotatedVector3 left, RotatedVector3 right)
{
return new RotatedVector3(left.Position + right.Position, left.Rotation + right.Rotation);
}
public static RotatedVector3 operator -(RotatedVector3 left, RotatedVector3 right)
{
return new RotatedVector3(left.Position - right.Position, left.Rotation - right.Rotation);
}
public override bool Equals(object obj)
{
if (obj.GetType() != typeof(RotatedVector3))
throw new System.InvalidCastException();
return Equals((RotatedVector3)obj);
}
public bool Equals(RotatedVector3 spawnPoint)
{
return this.Position == spawnPoint.Position && this.Rotation == spawnPoint.Rotation;
}
public override int GetHashCode()
{
int hash = 13;
hash = (hash * 7) + this.Position.GetHashCode();
hash = (hash * 7) + this.Rotation.GetHashCode();
return hash;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment