Mesh Cloning

Started by
0 comments, last by Red Ghost 17 years, 11 months ago
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
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.
Ghostly yours,Red.

This topic is closed to new replies.

Advertisement