Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 某些面孔没有出现_C#_Xna_Draw_Region_Zbuffer - Fatal编程技术网

C# 某些面孔没有出现

C# 某些面孔没有出现,c#,xna,draw,region,zbuffer,C#,Xna,Draw,Region,Zbuffer,好吧,我正在创造一个类似雷击机的地形,类似雷击机的地形被划分成不同的区域。我的问题只是一些面没有显示,而6x6区域的顶部和右侧部分没有显示 我想知道是否有人可以检查我的代码,看看我做错了什么,下面是函数: public void BuildFaceVertices(Vector3 pos, BlockFaceDirection blockFaceDirection) { Vector3 topLeftFront = new Vector3(0f, 1f, 0f)

好吧,我正在创造一个类似雷击机的地形,类似雷击机的地形被划分成不同的区域。我的问题只是一些面没有显示,而6x6区域的顶部和右侧部分没有显示

我想知道是否有人可以检查我的代码,看看我做错了什么,下面是函数:

    public void BuildFaceVertices(Vector3 pos, BlockFaceDirection blockFaceDirection)
    {
        Vector3 topLeftFront = new Vector3(0f, 1f, 0f) + pos;
        Vector3 bottomLeftFront = new Vector3(0f, 0f, 0f) + pos;
        Vector3 topRightFront = new Vector3(1f, 1f, 0f) + pos;
        Vector3 bottomRightFront = new Vector3(1f, 0f, 0f) + pos;
        Vector3 topLeftBack = new Vector3(0f, 1f, -1f) + pos;
        Vector3 topRightBack = new Vector3(1f, 1f, -1f) + pos;
        Vector3 bottomLeftBack = new Vector3(0f, 0f, -1f) + pos;
        Vector3 bottomRightBack = new Vector3(1f, 0f, -1f) + pos;

        Vector2 topLeft = new Vector2(0.0f, 0.0f);
        Vector2 topRight = new Vector2(1.0f, 0.0f);
        Vector2 bottomLeft = new Vector2(0.0f, 1.0f);
        Vector2 bottomRight = new Vector2(1.0f, 1.0f);

        switch (blockFaceDirection)
        {
            case BlockFaceDirection.ZIncreasing:
                SolidVertices.Add(new VertexPositionTexture(topRightFront, topRight));
                SolidVertices.Add(new VertexPositionTexture(bottomRightFront, bottomRight));
                SolidVertices.Add(new VertexPositionTexture(bottomLeftFront, bottomLeft));
                SolidVertices.Add(new VertexPositionTexture(topRightFront, topRight));
                SolidVertices.Add(new VertexPositionTexture(bottomLeftFront, bottomLeft));
                SolidVertices.Add(new VertexPositionTexture(topLeftFront, topLeft));
                break;
            case BlockFaceDirection.ZDecreasing:
                SolidVertices.Add(new VertexPositionTexture(topRightBack, topLeft));
                SolidVertices.Add(new VertexPositionTexture(topLeftBack, topRight));
                SolidVertices.Add(new VertexPositionTexture(bottomRightBack, bottomLeft));

                SolidVertices.Add(new VertexPositionTexture(topLeftBack, topRight));
                SolidVertices.Add(new VertexPositionTexture(bottomLeftBack, bottomRight));
                SolidVertices.Add(new VertexPositionTexture(bottomRightBack, bottomLeft));              
                break;
            case BlockFaceDirection.YIncreasing:
                SolidVertices.Add(new VertexPositionTexture(topRightBack, topRight));
                SolidVertices.Add(new VertexPositionTexture(topRightFront, bottomRight));
                SolidVertices.Add(new VertexPositionTexture(topLeftFront, bottomLeft));

                SolidVertices.Add(new VertexPositionTexture(topRightBack, topRight));
                SolidVertices.Add(new VertexPositionTexture(topLeftFront, bottomLeft));
                SolidVertices.Add(new VertexPositionTexture(topLeftBack, topLeft));                 
                break;
            case BlockFaceDirection.YDecreasing:
                SolidVertices.Add(new VertexPositionTexture(bottomLeftFront, topLeft));
                SolidVertices.Add(new VertexPositionTexture(bottomRightFront, topRight));
                SolidVertices.Add(new VertexPositionTexture(bottomLeftBack, bottomLeft));

                SolidVertices.Add(new VertexPositionTexture(bottomRightFront, topRight));
                SolidVertices.Add(new VertexPositionTexture(bottomRightBack, bottomRight));
                SolidVertices.Add(new VertexPositionTexture(bottomLeftBack, bottomLeft));
                break;
            case BlockFaceDirection.XIncreasing:
                SolidVertices.Add(new VertexPositionTexture(topRightBack, topRight));
                SolidVertices.Add(new VertexPositionTexture(bottomRightFront, bottomLeft));
                SolidVertices.Add(new VertexPositionTexture(topRightFront, topLeft));
                SolidVertices.Add(new VertexPositionTexture(topRightBack, topRight));
                SolidVertices.Add(new VertexPositionTexture(bottomRightBack, bottomRight));
                SolidVertices.Add(new VertexPositionTexture(bottomRightFront, bottomLeft));
                break;
            case BlockFaceDirection.XDecreasing:
                SolidVertices.Add(new VertexPositionTexture(topLeftBack, topLeft));
                SolidVertices.Add(new VertexPositionTexture(topLeftFront, topRight));
                SolidVertices.Add(new VertexPositionTexture(bottomLeftFront, bottomRight));
                SolidVertices.Add(new VertexPositionTexture(topLeftBack, topLeft));
                SolidVertices.Add(new VertexPositionTexture(bottomLeftFront, bottomRight));
                SolidVertices.Add(new VertexPositionTexture(bottomLeftBack, bottomLeft));
                break;

        }
    }'
此代码显示:第一个图像是未绘制的面,后者是未绘制区域的边


提前感谢Darestium,您的问题与所谓的背面剔除有关。我最近创造了一些类似于你正在做的事情,并遇到了同样的问题。解决方案很简单,但可能会很棘手,具体取决于构建顶点的方式。解决方案:必须按顺时针顺序构建索引。这意味着,如果您从要查看面的一侧查看面,则该面的索引必须在数组中按顺时针顺序排列。您似乎没有包含构建索引的代码,仅包含顶点,但我建议您按顺时针顺序构建顶点,然后简单地将索引列为0、1、2(以此类推)。粗略地看一下switch语句,似乎“ZIncreasing”方向的顶点是顺时针顺序的,但“zdecresing”是从右上到左上到右下的。如果你像我想象的那样从后面看“ZDecreating”面,那么我认为这是逆时针顺序,不会出现(或者,更确切地说,立方体的那部分的内面将被绘制,这对你来说是不可见的)

如果你很难在脑子里想出来,那就做一个小纸立方体,在角落贴上标签。创建顶点时,画出角点并确保它们按顺时针顺序排列