Jump to content
  • Advertisement
Sign in to follow this  
brainydexter

OpenGL Class Model structure for 3d object

This topic is 3175 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am in the process of making a 3d FPS game in C++/openGL. I am at the stage where I can load 3d models. I have already written a very basic importer which processes the famous collada dae format and it returns a list of triangles and polygon lists. Till now, it renders the model fine. My problem is, as the model grows larger, moving around becomes very slow. And, this is just one model that I am loading at a time. My question is: 1. How should I model a class which can represent this .dae object file? As of now, I just take the triangles and the list of polygons and put them between a glBegin() / glEnd() construct! 2. Any suggestions on how I can speed up ? Please let me know if I need to provide more details. I'd appreciate any help. Thanks (check out some of the screenies @ my blog )

Share this post


Link to post
Share on other sites
Advertisement
Yes, I'm taking one step at a time. I am just worried about static models for now.

My classes looks something like this:

class Model {
public:

list<Triangle*> GetTriangles();
list<PrimPolygon*> GetPolygons();

protected:
list<Triangle*> m_Triangles;
list<PrimPolygon*> m_Polygons;
}

class Vertex
{
boost::unordered_map<Semantic, float*> m_Attributes;
}

enum Semantic
{
Position = 0,
Color = 1,
Normal = 2,
TexCoord = 3
};

class Triangle
{
protected:
Vertex *m_V1, *m_V2, *m_V3;
}

class PrimPolygon
{
protected:
std::vector<Vertex*> m_Vertices;
size_t m_N;
}



//I have ommitted get/set methods, but this is my overall structure

Share this post


Link to post
Share on other sites
Your Get functions return the lists by value, making an unnecessary copy. You should return a const reference instead:

const list<Triangle*> & GetTriangles();
const list<PrimPolygon*> & GetPolygons();


Also, using VBOs should improve performance.

Share this post


Link to post
Share on other sites
Thanks Gage64,

I actually did that for returning polygons, but I wasn't sure if that would be a wise thing to do, because if I have to move the model around, they would be const and be problematic. But then, I think multiplying by transformation matrices should take care of that ?

Also, what do you suggest about my model class ? Should I organise it in a different manner or is it okay or do you have any recommendations for me ?

Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!