隐藏游戏/物理数学的包装器

时间:2013-09-18 02:31:21

标签: c# math xna directx wrapper

我想知道是否有任何包装器可以隐藏游戏编程的数学。例如,我不关心像normalise这样的术语 - 我宁愿只是获取游戏程序员需要的信息。

// too math-oriented
Vector2 dir = a.position - b.position;
dir.Normalise();

// much better
DirectionVector2 dir = DirectionVector2.AToB(a.position, b.position);

甚至

// true if ball has gone off-screen
// 'dot', 'normal', ugh...
if (Vector2.Dot(WallNormal, WallToBallDir) < 0)

// true if ball has gone off-screen
if (DirectionVector2.GetAngle(WallFacingDir, WallToBallDir) == Angles.Obtuse)

甚至是

// some stuff
Matrix world = translation * rotation * scale * 100 other things.
Vector2 rotation = new Vector2(world.m23, world.m33, world.m44);

// made easier
Transform objWorld = new Transform(translateVector, rotVector, scaleVector);
Vector2 rotation = objWorld.rotation;

这些只是我头脑中的一些。我觉得所有的数学函数('atan2','cos'等)都可以简化为getAngle或getLength等。其他人都同意吗?

我知道我可以自己编写这个包装器,但我想知道是否有其他人已经为DirectX / XNA创建了一个。

1 个答案:

答案 0 :(得分:1)

在标准化示例中,法向量和非法向量的点积非常不同。有时候你确实想要使用非法向量进行向量数学运算(例如,使用向量进行各种操作然后对其进行后标准化可能会更快)。

在你的轮换示例中,我真的不认为你甚至不了解旋转是什么。相对于标准正交基础定义旋转。它是一个3x3矩阵。您可以将许多3x3矩阵分解为欧拉角或四元数,但即使这样也不是全部。

总的来说,我真的不认为你可以抽象出这些东西。它们是非常重要的原始人。你真的必须学会理解一些基本的线性代数。如果没有它,你将很难调试任何问题。