在原始问题中将纹理映射到立方体上

时间:2013-09-02 19:41:23

标签: c# xna

我最近重新编写代码来绘制立方体,每个面上都有纹理,但是我无法将纹理映射到每个面上。 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);
        }
    }

0 个答案:

没有答案