質問
まあ、私はMinecraftのようなMinecraftのようなものを作成しています - Minecraftが地域に分離されています。私の問題は、単にいくつかの顔が表示されておらず、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;
}
}'
このコードが表示されています: s1100.photobucket.com/albums/g420/darestium/ 最初の画像は、描かれていない顔のものであり、後者は描かれていない領域の側面です。
よろしくお願いします、ダレシウム
解決
あなたの問題は、バックフェイスカリングと呼ばれるものに関係しています。私は最近、あなたがやっていることに似た何かを作成し、同じ問題に遭遇しました。ソリューションはシンプルですが、頂点を構築する方法に応じて注意が必要です。解決策:時計回りにインデックスを構築する必要があります。これが意味することは、あなたがそれを見たい側から顔を見ている場合、その顔のインデックスはあなたの配列で時計回りに順序でなければなりません。構築インデックスのコードを含めていないようですが、頂点だけですが、私はあなたがあなたの構築をするという提案をします 頂点 時計回りに順序で、インデックスを0、1、2(など)としてリストするだけです。スイッチステートメントの大まかな外観から、「zincreasing」方向の頂点は時計回りにあるように見えますが、「zdecreasing」はトップから左へと底に移動します。あなたが想像するように、後ろから「zdecreasing」顔を見ている場合、これは反時計回りであり、現れないと思います(または、キューブのその部分の内面が描画されます。あなたには見えません)。
頭の中で考えるのが難しい場合は、ちょっとした紙の立方体を作り、コーナーにラベルを付けてください。頂点を作成するとき、コーナーを追跡し、それらが時計回りに順番であることを確認します。