【发布时间】:2010-06-22 13:14:14
【问题描述】:
我对 XNA 中的 3D 东西还很陌生,不幸的是我遇到了一个我找不到解决方案的问题。 (甚至不知道问题是什么)。
简而言之:我在游戏中使用以下方法绘制四边形:
effect.World = Matrix.Identity *
Matrix.CreateRotationX(Rotation.X) *
Matrix.CreateRotationY(Rotation.Y) *
Matrix.CreateRotationZ(Rotation.Z) *
Matrix.CreateTranslation(Position);
// Apply camera-matrixes
effect.View = viewMatrix;
effect.Projection = projectionMatrix;
graphics.VertexDeclaration = vertDec;
// Begin effect drawing
effect.Begin();
foreach (EffectPass pass in
effect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.DrawUserIndexedPrimitives
<VertexPositionNormalTexture>(
PrimitiveType.TriangleList,
quad.Vertices, 0, 4,
quad.Indexes, 0, 2);
pass.End();
}
effect.End();
我的效果也有这些属性:
this.effect.TextureEnabled = true;
this.effect.Texture = texture;
而且它有效。我的四边形画得很好,我很高兴。但是有一个小问题。如果一个四边形在另一个四边形或常规模型之后,则确定在顶部绘制哪个四边形的方式是我绘制它们的顺序。
假设我在四边形 B 之前绘制四边形 A,然后 B 将显示在四边形 A 的顶部,即使它在 Z 轴上少 40 个单位。我必须说看起来很混乱! ;)
现在我的常规网格没有遇到过这样的问题,但当涉及到基元时,事情就会变得如此混乱。绘制规则线也有同样的问题:
graphics.DrawUserIndexedPrimitives<VertexPositionColor>(
PrimitiveType.LineStrip,
pointList,
0, // vertex buffer offset to add to each element of the index buffer
6, // number of vertices in pointList
new short[] { 0, 1 }, // the index buffer
0, // first index element to read
1 // number of primitives to draw
所以我真正要问的是:
A) 这正常吗?我是否应该构建一个特殊的引擎来决定何时绘制什么? 我可以通过在正确的时间绘制东西来轻松地在我的项目中解决这个问题,但我可以想象一个我无法想象的游戏。例如,一个 fps 无法在各处绘制广告牌! ;)
B) 如果这不正常,可能是什么原因以及什么是调试错误的解决方案/好方法。
如果能帮我解决这个问题,我将不胜感激! :)
【问题讨论】:
-
顺便说一下,您不必在对 DrawUserIndexedPrimitives 的调用中指定泛型类型
或 。编译器可以从您传递给函数的参数中判断您想要哪种类型。