Jump to content
  • Advertisement
Sign in to follow this  
FirstDouchaEver

Mesh Cloning

This topic is 4525 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

Hopefully this is a simple one.. :) I have a cTree Class containing an IP3DXMESH pointer to a tree mesh (a .x file). I want to be able to 'clone' this mesh to render many trees. What I want to do is create another cTree instance and render that in a different place - but not have to load the same mesh in - how is this possible? Ideally I'd like to have a copy constructor from my initially created cTree (which has the Mesh pointer and textures as well as scale matrices etc). I'm new to classes and never dealt with meshes before Cheers for any help

Share this post


Link to post
Share on other sites
Advertisement
Hi
You do not need to duplicate your mesh object. You would consume a lot of memory for nothing. A better approach is to create a game object with a pointer to a representation classholding your mesh (see pseudo-cpde below).


class GameObject;

class Representation {
public:
void Draw(GameObject* pGO);
private:
//your mesh details and structures
};

class GameObject {
public:
int xmap, ymap;
Representation* myRep;
void DrawRepresentation(void) {myRep->Draw(this);};
};



Now you have one mesh that is shared my as many game objects as you want. When you draw each game object, you are calling the Draw method of the linked representation class with a pointer to the calling game object: this takes care of passing the coordinates of the game object to its representation so that the representation is draw at the right place.

Hope that helps.
Ghostly yours,
Red.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!