【问题标题】:How can i show all edges in monogame?如何在单人游戏中显示所有边缘?
【发布时间】:2016-06-01 14:16:30
【问题描述】:

我正在使用Monogame 3.5,并且我有简单的立方体模型。我使用BasicEffect 来绘制它。我希望它透明,所以我使用effect.Alpha = 0.5f。是否可以在图片上显示所有边缘?

【问题讨论】:

    标签: c# 3d xna-4.0 monogame edge-detection


    【解决方案1】:

    有两种方法可以做到这一点,具体取决于您要查找的内容。您可以将渲染光栅化器状态设置为显示线框,也可以获取边缘列表并使用GraphicsDevice.DrawIndexedPrimitives 绘制一组VertexPositionColor。

    光栅尺状态

    您可以将立方体绘制成透明的,然后,假设您使用的是BasicEffect,您可以关闭所有阴影并将颜色设置为白色。

    然后您可以重新绘制立方体,并将新的光栅化器状态设置为FillMode.Wireframe。这是一些伪代码。

    //Draw the Cube Transparent
    DrawCubeTransparent();
    
    //Now save the Rastersizer state for later
    RasterizerState originalRasterizerState = GraphicsDevice.RasterizerState; 
    
    
    //Now set the RasterizerState too WireFrame
    RasterizerState newRasterizerState = new RasterizerState();  
    newRasterizerState.FillMode = FillMode.WireFrame;  
    GraphicsDevice.RasterizerState = newRasterizerState; 
    
    //Now redraw the cube as wireframe with the shading off and colour set to white
    DrawCubeWireFrame();
    
    //Now reset the Rastersizer fill state
    raphicsDevice.RasterizerState = originalRasterizerState;
    

    DrawIndexedPrimitives

    以前的方法可能不太理想,因为它会绘制所有三角形面,所以会有一条对角线穿过你的立方体面。

    另一种方法是找出要绘制的边,然后使用 DrawIndexedPrimitives 绘制包含所有边的顶点数组。

    一个简单的谷歌搜索将为您提供大量使用此功能的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      • 2021-11-18
      • 1970-01-01
      • 2022-09-28
      • 2019-08-05
      • 1970-01-01
      相关资源
      最近更新 更多