Game Development Reference
In-Depth Information
The following C++ code demonstrates one method of creating a stackable
deformer. This base case could be directly extended through inheritance to create
any type of deformer we could dream of (see Listing 13.1).
class PolyMesh; //our engine's mesh class
//A pure
virtual base class template for making deformers.
class BaseDeformer
public:
BaseDeformer();
//Calls Destroy()
virtual ˜BaseDeformer() { Destroy(); }
//Pure virtual, must be implemented in subclass
virtual void Deform()=0;
//Called on root of deformer stack,
//recursively evaluates entire chain
void Update()
{ Deform();
if (nextDeformer) nextDeformer −> Update();
}
//Called on root of deformer stack,
//recursively destroys entire chain
void Destroy()
{
if (nextDeformer) nextDeformer −> Release();
Release();
void Release()
{
delete this;
}
protected:
//Pointer to next deformer
BaseDeformer
nextDeformer;
//The mesh we are operating on prior to rendering
PolyMesh mesh;
} ;
//Example subclass of BaseDeformer for doing cloth simulation.
class ClothDeformer: public BaseDeformer
public:
//Pass it a mesh pointer
ClothDeformer(PolyMesh inMesh);
//Base class destructor will be called implicitly.
˜ClothDeformer() {} ;
//Override virtual function
void Deform()
{
Search Nedrilad ::




Custom Search