0

我最近重新编写了绘制立方体的代码,每个面上都有一个纹理,但是我无法将纹理映射到每个面上。 http://imgur.com/a/0sHKq 上图是我想要的游戏外观。底部图像是它当前的样子。

我设置块的代码如下。

newVertices[0].Position = new Vector3(position.X, position.Y, position.Z);
        newVertices[0].TextureCoordinate = new Vector2(1, 1);
        newVertices[1].Position = new Vector3(position.X, position.Y + size.Y, position.Z);
        newVertices[1].TextureCoordinate = new Vector2(1, 0);
        newVertices[2].Position = new Vector3(position.X + size.X, position.Y + size.Y, position.Z);
        newVertices[2].TextureCoordinate = new Vector2(0, 0);
        newVertices[3].Position = new Vector3(position.X + size.X, position.Y, position.Z);
        newVertices[3].TextureCoordinate = new Vector2(0, 1);
        newVertices[4].Position = new Vector3(position.X, position.Y, position.Z + size.Z);
        newVertices[4].TextureCoordinate = new Vector2(0, 1);
        newVertices[5].Position = new Vector3(position.X, position.Y + size.Y, position.Z + size.Z);
        newVertices[5].TextureCoordinate = new Vector2(0, 0);
        newVertices[6].Position = new Vector3(position.X + size.X, position.Y + size.Y, position.Z + size.Z);
        newVertices[6].TextureCoordinate = new Vector2(1, 0);
        newVertices[7].Position = new Vector3(position.X + size.X, position.Y, position.Z + size.Z);
        newVertices[7].TextureCoordinate = new Vector2(1, 1);

这是我能想到的最好的方法,但是没有纹理,或者更有可能是纹理的一角,被应用于顶面和底面。

我的绘图代码,如果有任何用处

public void Draw(Camera camera)
    {
        effect.View = camera.View;
        effect.Projection = camera.Projection;
        effect.World = rotationMatrix;

        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
        {
            pass.Apply();
            graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, newVertices, 0, 8, indices, 0, 12);
        }
    }
4

0 回答 0