【问题标题】:What is the best way to configure the position of a model / texture in xna project在 xna 项目中配置模型/纹理位置的最佳方法是什么
【发布时间】:2012-11-26 14:01:03
【问题描述】:

我想知道我下面使用的方法是否是在屏幕上绘制之前确定模型位置的正确方法。 因为当我想创建一个复制我的模型的地板时。我发现自己面临着“Z-fighting”问题^^。

非常感谢

在绘制之前将代码示例放在我的模型上的位置:

model_Position.X = (float) 1.0;
model_Position.Z = (float) 3.0;
model_Position.Y = (float) 5.0;

// Draw the model. A model can have multiple meshes, so loop.
foreach (ModelMesh mesh in model_ground_land1.Meshes)
{
    // This is where the mesh orientation is set, as well 
    // as our camera and projection.
    foreach (BasicEffect effect in mesh.Effects)
    {
        effect.EnableDefaultLighting();
        effect.World = transforms[mesh.ParentBone.Index]  *
    Matrix.CreateRotationY(model_Rotation) * Matrix.CreateTranslation(model_Position);
        effect.View = View;
        effect.Projection = Projection;
    }
    // Draw the mesh, using the effects set above.
    mesh.Draw();
}

【问题讨论】:

    标签: c# 3d xna mesh


    【解决方案1】:

    据我所知,您的方法对于定位模型是正确的。关于 Z 战斗问题,当两个 3D 面在同一平面上绘制时相互重叠时会发生。正如您所说的“复制模型”,这听起来像是问题所在,而不是模型定位本身。为了解决战斗,您可以在绘制模型的第二个副本之前将一些非零值设置为GraphicsDevice.RasterizerState.DepthBias。来自documentation:

    “具有高 z-bias 值的多边形出现在具有高 z-bias 值的多边形前面 低值,不需要对绘图顺序进行排序。例如, 值为 1 的多边形出现在值为 1 的多边形前面 0。”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-16
      • 2012-10-08
      • 2021-05-31
      • 2012-04-02
      • 1970-01-01
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多