owl's Blog

Sign in to follow this  
  • entries
    26
  • comments
    30
  • views
    33720

Finding data structures that make sense

Sign in to follow this  
owl

282 views

Last time I was showing how I managed to load a big mesh for the level and to wrap the character model inside an ellipsoid and make both collide using Kasper Fauerby's Swept Sphere collision algorithms. Since then I've been working in the data structures necessary to organize the level components a little better.

I needed to be able to make little parts of the level with a 3D modeling program and then being able to select from a program of my own which one of them to include in a game level and where. For this I came up with the following classes:

  • Core Model: Loads all the elements of a model into an OpenGL VBO's.
    • Model: It's an instance that points to a specific Core Model. It processes the vertices and updates the VBO during animation.
      • Collision Mesh: Is used for meshes that have no animation. It holds the triangles in system memory, an AABB encompassing them and the location in World Space.
        • Tile: It's the structure that represents static objects in the level to collide with. It contains a Model and a Collision Mesh.
          • Contents: It holds lists of Core Models, Models, Tiles and the Tile references composing the Map.

            There is a XML file describing how a Level is composed. It defines which Textures and Models to use and which of those each Tile should use. Also the size of the map and where the Tiles must be located.

            There is only one Model per Tile type (hence just one VBO). All these unique tiles are hold in an array and when the Map is drawn they are referenced by their location in the array.

            The vertices in the Collision Mesh (which are in model space) are transformed into world-ellipsoid space at the time of collision according to the tile's position. It'd be better to convert the ellipsoid position to Mesh space but it was easier to do it this way right now.

            The only reason I created the Tile class was to keep the classes used for collision decoupled from the ones used for drawing.

            The next step is to implement an Octree and push all the tiles in it. Then collide the character's AABB with the Octree each frame and test for collision only with those Tiles that are near.

            [media]
            [/media]
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now