Sign in to follow this  
FirstDouchaEver

Mesh Cloning

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
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

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

Sign in to follow this