1
\$\begingroup\$

What I want to implement next in my game is frustum culling. The issue that I'm having is creating a draw method that I can check which cubes in my vertex buffer I draw or not. What I want to do is loop through my list "cubes" and check for each bounding box that the cube has. I've done this before when I had each cube have a separate vertex buffer, but now when I try it with a chunk of cubes, it crashes my computer. I know why this happened so I won't bother explaining it.

      cubes.Add(new Cube.Grass(device, new Vector3(x, map[x, z] - y, z), grass));
      cubeBoundingBox(some Vector3s here);

So with these two lines I add the cube to the list and create a bounding box based on the position and size of the box. I'm sure there's a better way to do this.

    public void DrawMap(GameTime gameTime)
    {
        ContainmentType CurrentContainmentType = ContainmentType.Disjoint;

        foreach (Cube block in cube.cubes)
        {
            CurrentContainmentType = cam.frustum.Contains(cube.cubeBoundingBox);

            //some more stuff here

            if (CurrentContainmentType != ContainmentType.Disjoint)
            {
               cube.Draw(effect);
            }

This is my old method that almost worked. But now that I have all cubes stored in a single vertex buffer, this won't work. I'm kinda lost here. How can I loop through all the cubes in my list "cubes" in order to check if they need to be culled or not? Or would it make more sense to make a list of bounding boxes and loop through that list?

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

Just iterate through the vertices with offset to the next first vertex of the next cube. Like this:

point[] linevertices = new point[6]; // line is made of 2 points

// Iterate through all lines
for(int i=0; i<6; i=i+2){
    // code
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .