Frage

Nun, ich schaffe ein Minecraft -ähnliches Terrain -Ding, das - wie Minecraft in Regionen unterteilt ist. Mein Problem ist einfach, dass einige Gesichter nicht angezeigt werden und der obere und rechte Teil von 6x6 -Regionen nicht angezeigt wird.

Ich habe mich gefragt, ob jemand meinen Code überprüfen könnte, um zu sehen, was ich falsch mache. Hier ist die Funktion:

    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;

        }
    }'

Dieser Code wird angezeigt: s1100.photobucket.com/albums/g420/darestium/ Das erste Bild ist von den Gesichtern, die nicht gezogen werden, und letzteres ist von den Seiten der Regionen, die nicht gezeichnet werden.

Vielen Dank im Voraus, Darestium

War es hilfreich?

Lösung

Ihr Problem hat mit dem, was als Backface Culling bezeichnet wird, zu tun. Ich habe kürzlich etwas Ähnliches geschaffen wie das, was Sie tun, und bin auf die gleichen Probleme gestoßen. Die Lösung ist einfach, kann aber schwierig sein, je nachdem, wie Sie Ihre Eckpunkte bauen. Die Lösung: Sie müssen Ihre Indizes im Uhrzeigersinn erstellen. Wenn Sie das Gesicht von der Seite sehen, von der Sie es sehen möchten, müssen die Indizes dieses Gesichts in Ihrem Array im Uhrzeigersinn sein. Sie scheinen Ihren Code nicht für das Erstellen von Indizes und nur Scheitelpunkte aufgenommen zu haben, aber ich werde den Vorschlag machen, dass Sie Ihre erstellen Eckpunkte Im Uhrzeigersinn und dann einfach Ihre Indizes als 0, 1, 2 (usw., in der Reihenfolge) auflisten. Aus einem flüchtigen Blick über Ihre Switch -Anweisung scheint es, dass die Eckpunkte der "Zincrease" -Richtung im Uhrzeigersinn in der Reihenfolge sind, aber das "Zdekreting" von oben nach Topleft nach unten geht. Wenn Sie das "Zdekrebäuer" von hinten von hinten sehen, wie ich es mir vorstellen kann, dann denke ich ist für Sie nicht sichtbar).

Wenn es schwer in Ihrem Kopf zu denken ist, machen Sie einfach einen kleinen Papierwürfel und beschriften Sie die Ecken. Verfolgen Sie die Ecken, während Sie die Eckpunkte erstellen, und stellen Sie sicher, dass sie im Uhrzeigersinn sind.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top