XNA中是否有Vector3Int等效?

问题描述 投票:0回答:1

我想知道在XNA中是否有Unity的Vector3Int等效物。我不想使用Vector3在一个结构中存储三个整数,但我不想创建自己的类。 Vector3是否有结构(如Point < - > Vector2或Rectangle < - > Vector4)?

xna
1个回答
1
投票

答案是不。 PointSystem.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;
   }
}

这具有结构的优点,因为它存储在堆栈中。

© www.soinside.com 2019 - 2024. All rights reserved.