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;
publicclass WallCube
{
publicint 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; }
publicfloat 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);
}
publicvoid 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);
}
publicvoid 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 CreateCubeVertexBuffer to hodllám nahradit cyklem, ale problém mám s
tím - Jak do toho započítat pozici? (vlastnost Location) Děkuji.
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.