Skip to main content
gamedev.net
🔒 Locked

OO Design

Started by gamedream Mar 31, 2004 at 11:43 PM 1 replies 650+ views
Original Post
gamedream
gamedream
If a character that needs to draw itself, so, what is the draw method placed from? in the character or in the view object? also, if a character that has a draw method, than how can I call the view object to perform the draw function? pls give me the example to describe the design and tell me how is good. thank you very much
grbrg
grbrg
I guess this should belong to a programming forum, we''re talking about game design here.

Btw, your question needs to be described in a little bit more detail. If I understand correctly a "view" object is a certain view on the game world, right? Then the draw method belongs to the character and the view calls all draw methods of objects it wants to show. If that is not what you meant, you''ll have to clarify the question for the programming forum.

------------------------------
There are only 10 kinds of people: those that understand binary and those that don''t.
------------------------------ There are only 10 kinds of people: those that understand binary and those that don't.
hplus0603
hplus0603
This should be posted to programming, not design, no?

Anyway, you typically want objects implementing your Viewable interface to go into some scene graph (like an octree).

Then, you use a Visitor to visit all Viewables that intersect the viewing frustum.

The protocol for Viewable is typically to return a description of some sort (i e, group of geometry, material, and pose/matrix state) which the renderer uses to actually render the thing.

The reason you don''t want objects calling renderer->setTexture() and similar functions directly is that then, if you change your rendering to require multi-passing (for shadows, reflection, etc) then you have to update ALL the objects, if the objects do the rendering.

Having objects describe themselves with multiples of geometry-material-state is much more flexible, as you can easily throw that at mirroring, cube mapping, shadow maps, shadow volumes, cel shading, and whatever else you care about implementing.


class Mesh {
double time;
void const * vertexData;
unsigned int vertexFormat;
unsigned int numVertices;
unsigned short const * indexData;
unsigned int numIndices;
Texture * texture;
Matrix43 objectPosition;
Matrix43 * skeletonPose;
unsigned int numBones;
};

class AllViewables;

class Viewable {
public:
virtual void onAdded( AllViewables * av ) = 0;
virtual void location( Vector3 & outPos, float & outRadius ) = 0;
virtual void geometryAtTime( double time, Mesh const *& outMeshes, int & outCount ) = 0;
};

class ViewableVisitor;

class AllViewables {
public:
virtual void onMoved( Viewable * v ) = 0;
virtual void add( Viewable * v ) = 0;
virtual void remove( Viewable * v ) = 0;

virtual void visit( ViewableVisitor * vv, Frustum const & f ) = 0;
};

class ViewableVisitor {
public:
virtual void visit( Viewable * v ) = 0;
};


You would create one ViewableVisitor instance for rendering the scene from the point of view of a light into a light map; another for rendering the scene from the point of view of the camera into a glow buffer; a third for stencil volumes, etc.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.