Add new "World Coordinate" types.

These types provide fixed-point representations of distances, angles,
positions, vectors, and rotations in 3d space.

WAngle (and WRot) represents 360 degrees in 1024 units.
WRange (and WPos, WVec) represents 1 cell in 1024 units.

Distance types in yaml can be written as <cell>c<subcell>, e.g. "4c512" for 4.5 cells.
This commit is contained in:
Paul Chote
2013-03-11 04:29:01 +13:00
parent 61959aa45b
commit 724ea88c3b
7 changed files with 478 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Drawing;
namespace OpenRA
{
/// <summary>
/// 3d World position - 1024 units = 1 cell.
/// </summary>
public struct WPos
{
public readonly int X, Y, Z;
public WPos(int x, int y, int z) { X = x; Y = y; Z = z; }
public WPos(WRange x, WRange y, WRange z) { X = x.Range; Y = y.Range; Z = z.Range; }
public static readonly WPos Zero = new WPos(0, 0, 0);
public static explicit operator WVec(WPos a) { return new WVec(a.X, a.Y, a.Z); }
public static WPos operator +(WPos a, WVec b) { return new WPos(a.X + b.X, a.Y + b.Y, a.Z + b.Z); }
public static WPos operator -(WPos a, WVec b) { return new WPos(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
public static WVec operator -(WPos a, WPos b) { return new WVec(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
public static bool operator ==(WPos me, WPos other) { return (me.X == other.X && me.Y == other.Y && me.Z == other.Z); }
public static bool operator !=(WPos me, WPos other) { return !(me == other); }
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); }
public override bool Equals(object obj)
{
if (obj == null)
return false;
WPos o = (WPos)obj;
return o == this;
}
public override string ToString() { return "{0},{1},{2}".F(X, Y, Z); }
}
}