我想知道在XNA中是否有Unity的Vector3Int
等效物。我不想使用Vector3在一个结构中存储三个整数,但我不想创建自己的类。 Vector3是否有结构(如Point < - > Vector2或Rectangle < - > Vector4)?
答案是不。 Point
是System.Drawing
的遗留物,Rectangle
帮助AABB碰撞。
将整数存储在浮点数中的唯一警告(它们消耗相同的内存量)可能会导致精度损失,因为浮点数无法精确存储某些值。在大多数情况下,这不是问题。浮点运算可能比整数运算运算慢。
我建议创建一个Vector3Int
结构:
public struct Vector3Int
{
public int X;
public int Y;
public int Z;
public Vector3Int()
{
X = 0;
Y = 0;
Z = 0;
}
public Vector3Int(int val)
{
X = val;
Y = val;
Z = val;
}
public Vector3Int(int x, int y, int z)
{
X = x;
Y = y;
Z = z;
}
}
这具有结构的优点,因为它存储在堆栈中。