creating bounding box list
Posted
by
Christian Frantz
on Game Development
See other posts from Game Development
or by Christian Frantz
Published on 2013-06-23T20:53:45Z
Indexed on
2013/06/24
16:39 UTC
Read the original article
Hit count: 405
I'm trying to create a list of bounding boxes for each cube drawn, so I can use the boxes to intersect with a ray that my mouse position is casting, but I have no idea how. I've created a list that stores the boxes, but how am I getting the values from each box?
for (int x = 0; x < mapHeight; x++)
{
for (int z = 0; z < mapWidth; z++)
{
cubes.Add(new Vector3(x, map[x, z], z), Matrix.Identity, grass);
boxList.Add(something here);
}
}
public Cube(GraphicsDevice graphicsDevice)
{
device = graphicsDevice;
var vertices = new List<VertexPositionTexture>();
BuildFace(vertices, new Vector3(0, 0, 0), new Vector3(0, 1, 1));
BuildFace(vertices, new Vector3(0, 0, 1), new Vector3(1, 1, 1));
BuildFace(vertices, new Vector3(1, 0, 1), new Vector3(1, 1, 0));
BuildFace(vertices, new Vector3(1, 0, 0), new Vector3(0, 1, 0));
BuildFaceHorizontal(vertices, new Vector3(0, 1, 0), new Vector3(1, 1, 1));
BuildFaceHorizontal(vertices, new Vector3(0, 0, 1), new Vector3(1, 0, 0));
cubeVertexBuffer = new VertexBuffer(device, VertexPositionTexture.VertexDeclaration, vertices.Count, BufferUsage.WriteOnly);
cubeVertexBuffer.SetData<VertexPositionTexture>(vertices.ToArray());
}
There aren't any clearly defined variables for the bounds of each cube created, so where do I create the bounding box from?
© Game Development or respective owner