Searc

Monday 2 January 2012

BoundingBox's A pain in the but

I have spent a long time trying to ificiantly calculate bounding boxes for my terrain patches, i have resorted to bruteforce once the patch is created, the code is just a modifyed version of the standard xna method for calculting mesh bounding boxes. Here is a little update pic and the code used. I dont think this really needs an explanation, it just checks all vertices and then calculates the max and min bounds.



  public BoundingBox CalculateBoundingBox()
  
  {
  
    Vector3 Max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
  
    Vector3 Min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
  
     for (int i = 0; i < VertexData.Length; i ++)
  
     {
  
       Vector3 vectCurrentVertex = VertexData[i].Position;
  
       if (VertexData[i].Position.X < Min.X) Min.X = VertexData[i].Position.X;
  
       if (VertexData[i].Position.X > Max.X) Max.X = VertexData[i].Position.X;
  
       if (VertexData[i].Position.Y < Min.Y) Min.Y = VertexData[i].Position.Y;

  
       if (VertexData[i].Position.Y > Max.Y) Max.Y = VertexData[i].Position.Y;
  
       if (VertexData[i].Position.Z < Min.Z) Min.Z = VertexData[i].Position.Z;
  
       if (VertexData[i].Position.Z > Max.Z) Max.Z = VertexData[i].Position.Z;
  
     }
  
     return new BoundingBox(Min, Max); 
  
  }  

2 comments:

  1. Hello Prof. Budinga, Fabio here, excellent work! I am just getting started with graphics programming, although I've dabbed in XNA before. This time I'm interested in OpenGL. My goal is a simulation of our solar system, so I'm glad I found your page!

    There are many things I need help with, direction-wise, meaning where to go for resources. But in general, speaking about drawing a planet, its atmosphere, and its host star, can you point me in the right heading?

    Thanks, and once again, great job, it's looking fantastic!

    ReplyDelete
  2. Thanx alot for your praise :).

    Well first of all if you are new to graphics programming, try to develop some flat terrains first as they are much easier. Also maybe start with a simple solar system simulator, with just spheres and textures, that what i did. Then you can look in to LOD, vterrain.org has a wealth of knowledge on the subject, and also gamedev.net. You can also download the atmospheric scattering code from sponeal.net which is great also has a quadtree planet renderer, i myself use a similar technique, map 6 quadtree's on to a unit cube then map them to a sphere , there are many ways to do this. Also some great ref's and articles on outerra.com and also a great dev journal at http://www.infinity-universe.com/Infinity/. I think thats about all the info you should need for now. Feel free to email me i can try and hel you as best as i can, but i am no expert on this subject.

    ReplyDelete