Jump to content

  • Log In with Google      Sign In   
  • Create Account

Best way to create bounding boxes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 burnt_casadilla   Members   -  Reputation: 442

Like
0Likes
Like

Posted 16 July 2013 - 09:38 AM

I have a CubeChunk class which creates indices and vertices for each "Cube" in my chunk. What I want to do is create a bounding box for each of these cubes, so what I'm wondering is what is the best way to do this? Should I create a separate list for each chunk and store the bounding boxes in that? Or should I call a CreateBoundingBox method each time the cube is created or drawn?

For Example 

for (int x = 0; x < 50; x++)
            {
                for (int z = 0; z < 50; z++)
                {
                    for (int y = 0; y <= map[x, z]; y++)
                    {

                        if (y >= 1)
                        {
                            SetUpIndicesAndVertices(x, map[x, z] - y, z, vertices, indices);
                            cubes.Add(new Cube.Stone(device, new Vector3(x, map[x, z] - y, z), stone));
                              CreateBoundingBox(some kind of vector3 values here);
                        }

                        else
                        {
                            SetUpIndicesAndVertices(x, map[x, z] - y, z, vertices, indices);
                            cubes.Add(new Cube.Grass(device, new Vector3(x, map[x, z] - y, z), grass));
                              CreateBoundingBox(some kind of vector3 values here);
                        }
                    }
                }

Or I could replace the line with cubeBB.Add(new BoundingBox(some vector3 crap here). Which one would make more sense to use? 


If you see a post from me, you can safely assume its C# and XNA :)


Sponsor:

#2 smr   Members   -  Reputation: 1652

Like
0Likes
Like

Posted 16 July 2013 - 10:05 AM

Just curious why you need a separate bounding box for each cube? Wouldn't each cube already be its own bounding box?



#3 burnt_casadilla   Members   -  Reputation: 442

Like
0Likes
Like

Posted 16 July 2013 - 10:12 AM

To test collision between mouse and cube, or player and cube. I didn't know I could just use the cube as its own bounding box though. How would I do that?


If you see a post from me, you can safely assume its C# and XNA :)


#4 Pink Horror   Members   -  Reputation: 1204

Like
0Likes
Like

Posted 16 July 2013 - 10:44 AM

If I understand correctly, you want to take your "Cube", which is your own custom box, and make an official XNA BoundingBox out of it. I think you should make a Cube Intersect method, and locally construct the BoundingBox inside of that method for the intersection test. It's better than having it hang around in memory. A local struct shouldn't cost much to create.



#5 burnt_casadilla   Members   -  Reputation: 442

Like
0Likes
Like

Posted 16 July 2013 - 12:21 PM

So what you're saying is to create the BoundingBox of the cube at the point of intersection with the mouse or player? I guess that could work. It would save a lot of unnecessary bounding boxes in the memory. Although I didn't think c# had an issue with things hanging around in memory but who knows :P


If you see a post from me, you can safely assume its C# and XNA :)


#6 smr   Members   -  Reputation: 1652

Like
0Likes
Like

Posted 16 July 2013 - 01:08 PM

So what you're saying is to create the BoundingBox of the cube at the point of intersection with the mouse or player? I guess that could work. It would save a lot of unnecessary bounding boxes in the memory. Although I didn't think c# had an issue with things hanging around in memory but who knows tongue.png

 

An optimization over this would be instead of creating a new cube to test collision, set aside a number of already created bounding boxes in a circular queue and reuse. Update the appropriate fields and properties of the BB to match the cube and send to the collision tester. This will save you many allocations per collision frame. If you plan to target a mobile device this will help to reduce garbage collections which could affect your framerate.



#7 burnt_casadilla   Members   -  Reputation: 442

Like
0Likes
Like

Posted 16 July 2013 - 01:26 PM

What I was thinking is that I could have something like this:

 

x, x, x, x, x,

x, x, x, x, x,

x, x, o, x, x,

x, x, x, x, x,

x, x, x, x, x,

 

Where the x's are equal to 2 cubes and 0 is the player. The 5x5 space would be like a bounding box for the player which moves with the player and allows the player to only mine or build within that 5x5 box. I would definitely decrease the amount of bounding boxes needed, but I wouldn't even know how to start coding it.


If you see a post from me, you can safely assume its C# and XNA :)





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS