NOVINKA - Online rekvalifikační kurz Python programátor. Oblíbená a studenty ověřená rekvalifikace - nyní i online.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.
Avatar
matesax
Tvůrce
Avatar
matesax:28.10.2012 10:07

Dobrý den,
chtěl bych vytvořit 3D bludiště - mám sznam pozic tvořící trasu - všude jinde potřebuji stěny. Prvně jsem chtěl trasu protlačit o Y úroveň, ale to jsem nikde nenašel. Alespoň jsem přišel na to, jak udělat jednoduše kostku:

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

public class WallCube
{
    public int numberOfVertices = 8, numberOfIndices = 36;
    GraphicsDevice graphicsDevice;
    public VertexBuffer vertices;
    public IndexBuffer indices;

    public Matrix World { get; set; }
    public Matrix View { get; set; }
    public Matrix Projection { get; set; }
    public float Size { get; set; }
    public Vector3 Location { get; set; }

    public WallCube(GraphicsDevice graphicsDevice)
    {
        World = Matrix.Identity;
        this.graphicsDevice = graphicsDevice;
        View = Matrix.CreateLookAt(new Vector3(0, 0, 2), Vector3.Zero, Vector3.Up);
        Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, graphicsDevice.Viewport.AspectRatio, 1, 10);
    }

    public void CreateCubeVertexBuffer()
    {
        VertexPositionColor[] cubeVertices = new VertexPositionColor[numberOfVertices];

        cubeVertices[0].Position = new Vector3(-Size, -Size, -Size);
        cubeVertices[1].Position = new Vector3(-Size, -Size, Size);
        cubeVertices[2].Position = new Vector3(Size, -Size, Size);
        cubeVertices[3].Position = new Vector3(Size, -Size, -Size);
        cubeVertices[4].Position = new Vector3(-Size, Size, -Size);
        cubeVertices[5].Position = new Vector3(-Size, Size, Size);
        cubeVertices[6].Position = new Vector3(Size, Size, Size);
        cubeVertices[7].Position = new Vector3(Size, Size, -Size);

        cubeVertices[0].Color = Color.Black;
        cubeVertices[1].Color = Color.Red;
        cubeVertices[2].Color = Color.Yellow;
        cubeVertices[3].Color = Color.Green;
        cubeVertices[4].Color = Color.Blue;
        cubeVertices[5].Color = Color.Magenta;
        cubeVertices[6].Color = Color.White;
        cubeVertices[7].Color = Color.Cyan;

        vertices = new VertexBuffer(graphicsDevice, VertexPositionColor.VertexDeclaration, numberOfVertices, BufferUsage.WriteOnly);
        vertices.SetData<VertexPositionColor>(cubeVertices);
    }

    public void CreateCubeIndexBuffer()
    {
        indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, numberOfIndices, BufferUsage.WriteOnly);
        indices.SetData<UInt16>(
            new UInt16[]
            {

                0, 2, 3, 0, 1, 2,

                4, 6, 5, 4, 7, 6,

                5, 2, 1, 5, 6, 2,

                0, 7, 4, 0, 3, 7,

                0, 4, 1, 1, 4, 5,

                2, 6, 3, 3, 6, 7

            });

    }

}

V CreateCubeVer­texBuffer to hodllám nahradit cyklem, ale problém mám s tím - Jak do toho započítat pozici? (vlastnost Location) Děkuji.

Editováno 28.10.2012 10:08
 
Odpovědět
28.10.2012 10:07
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 1 zpráv z 1.