views:

143

answers:

2

What is the best method to store 3d models in game ? I store in vectors: vector triangles (each triangle contain number of texcords, numer of vertex and number of normal), vector points; vector normals; vector texCords;

+2  A: 

I'm not sure what constitutes "the best method" in this case, as that's going to be situation dependent and in your question, it's somewhat open to interpretation.

If you're talking about how to rapidly render static objects, you can go a long way using Display Lists. They can be used to memoize all of the OpenGL calls once and then recall those instructions to render the object whenever used in your game. All of the overhead you incured to calculate vertex locations, normals, etc are only performed once when you build each display list. The drawback is that you won't see much of a performance gain if your models change too often.

EDIT: SurvivalMachine below mentions that display lists are deprecated. In particular, they are deprecated in OpenGL Version 3.0 and completely removed from the standard in Version 3.1. After a little research, it appears that the Vertex Buffer Object (VBO) extension is the prefered alternative, though a number of sources I found claimed that performance wasn't as good as display lists.

andand
Display Lists are deprecated.
SurvivalMachine
@SurvivalMachine: I didn't know that. It's been a while since I've done any grpahics programming. Thanks for the heads-up; I've updated my answer.
andand
Looks to me like performance of VBOs compared to display lists really depends on the video card. I also did some searching and several discussions were years old, and were indicating that "new" cards at that time were starting to see higher performance of VBOs than DLs. In any case, the deprecation of display lists is (IMO) plenty of reason to stay away from them, not to mention there's no equivalent of a display list in DirectX, so if you ever wanted to abstract your engine to allow for DirectX support you would have to move to vertex arrays or VBOs.
Ricket
A: 

I chose to import models from the .ms3d format, and while I may refactor later, I think it provided a decent foundation for the data structure of my 3D models.

The spec (in C header format) is a pretty straightforward read; I am writing my game in Java so I simply ported over each data structure: vertex, triangle, group, material, and optionally the skeletal animation elements.

But really, a model is just triplets of vertices (or triangles), each with a material, right? Start by creating those basic structures, write a draw function that takes a model for an argument and draws it, and then add on any other features you might need as you need them. Iterative design, if you will.

Ricket
Now I store my triangles on std::vector, but it works very slow :/I must store on std::vector, beacouse I checking collisions with them, is there better way then vector ?
subSeven
I would use a regular array. std::vector will have overhead because it is meant for holding a data structure that changes often; but since you are just loading the data once, and you should be able to know (or figure out) exactly how many triangles you need to store, you don't need the extra capabilities of a vector. If you really wanted, you could load into the vector and then copy it into an array after loading. Anyway, looping over an array will probably give you that extra speed that you need.
Ricket
Also make sure you are doing more efficient collision than just checking collision against all triangles every frame. You should be doing something more high-level, like bounding box checking or even a quadtree/octree in a large scene, and only if those test true then should you drill down into the triangles of only the colliding meshes.
Ricket