Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

object.hpp

00001 //==========================================================================
00002 // object.hpp : just a container class for all types of objects.
00003 //   All objects have to implement these basic routines and should
00004 //   be subclasses of "Object". The following must be provided for each object:
00005 //   (1) the min and max extents in object-space only (local modeling coords)
00006 //   (2) an update routine for the min/max extents
00007 //   (3) a general display routine (all materials, textures, lighting, etc.
00008 //       handled in object drawing routine)
00009 //   (4) a generalized display routine is required that will support all possible
00010 //       display attributes for vertices. An unsigned integer bitmask is sent
00011 //       to the routine that contains the ORing of all desired options in the
00012 //       display. By default, all attribs are displayed (OBJ_ALL). The user
00013 //       must provide implementations for all combinations:
00014 //       switch (Attribs)
00015 //       {
00016 //        case OBJ_NONE : // ONLY MAKE glVertex CALLS
00017 //         break;
00018 //        case OBJ_ALL : // DISPLAY WITH ALL VERTEX ATTRIBUTES
00019 //         break;
00020 //        case OBJ_COLORS : // VERTEX COLORS ONLY
00021 //         break;
00022 //        case OBJ_NORMALS : // VERTEX NORMALS ONLY
00023 //         break;
00024 //        case OBJ_TEXCOORDS : // VERTEX TEX-COORDS ONLY
00025 //         break;
00026 //        case (OBJ_COLORS | OBJ_NORMALS) : // VERTEX COLORS AND NORMALS ONLY
00027 //         break;
00028 //        case (OBJ_COLORS | OBJ_TEXCOORDS) : // VERTEX COLORS AND TEX-COORDS ONLY
00029 //         break;
00030 //        case (OBJ_NORMALS | OBJ_TEXCOORDS) : // VERTEX NORMALS AND TEX-COORDS ONLY
00031 //         break;
00032 //       };
00033 // These attributes need not be applied to each vertex in the display routine;
00034 // we need only worry about not making any associated state changes to Attribs
00035 // that are not called for. For example, if the user does not ask for OBJ_TEX_COORDS,
00036 // then all associated state must also not be changed in the display routine:
00037 // texture bindings, texture enabling, etc. Also, some attribs may not apply to
00038 // certain objects (obj may not have a texture), so we must make unset the bits
00039 // in the bitmask corresponding to those options (Attribs &= (~OBJ_*)) before
00040 // going into the switch statement.
00041 //==========================================================================
00042 
00043 #ifndef _OBJECT_
00044 #define _OBJECT_
00045 
00046 #include <vec3f.hpp>
00047 
00048 // OBJECT DISPLAY ATTRIBUTES; OR TOGETHER DESIRED COMBINATIONS
00049 #define OBJ_NONE 0
00050 #define OBJ_COLORS 1
00051 #define OBJ_NORMALS 2
00052 #define OBJ_TEXCOORDS 4
00053 #define OBJ_ALL (OBJ_COLORS | OBJ_NORMALS | OBJ_TEXCOORDS)
00054 
00055 class Object
00056 {
00057   public:
00058     Vec3f Min, Max;  // OBJECT EXTENTS IN OBJECT COORDS (AABB)
00059 
00060     void DrawAABB(float r=0, float g=0, float b=1);
00061 
00062     // UPDATE MIN/MAX IN OBJECT COORDS
00063     virtual void UpdateMinMax() = 0;        
00064 
00065     // FULL DISPLAY ROUTINE
00066     virtual void Display(unsigned int Attribs=OBJ_ALL) = 0;
00067 
00068     // RETURNS AN ARRAY OF TRIS (FLAT ARRAY OF FLOATS,
00069     // 3 VERTICES/TRI, 3 FLOATS/VERTEX, VERTICES IN COUNTER-CLOCKWISE ORDER
00070     // IF Tris==NULL AFTER CALLING, THEN UNABLE TO GET TRIS. ALLOCATION OF Tris IS DONE
00071     // WITHIN GetTris (just declare "float *Tris" and pass in "Tris") PROVIDED
00072     // TRIS==NULL WHEN PASSED IN; OTHERWISE, ALLOCATION IS NOT PERFORMED (MAY BE
00073     // PRE-ALLOCED BY THE USER FOR PACKING LARGER TRI ARRAYS).
00074     // ALSO RETURNS NumTris, WHICH WILL BE ZERO IF UNABLE TO GET TRIS.
00075     // A SEPARATE ROUTINE IS PROVIDED TO JUST GET THE # OF TRIS
00076     virtual void GetTris(float* &tris, int &numTris) { tris=NULL; numTris=0; }
00077     virtual void GetTris(double* &tris, int &numTris) { tris=NULL; numTris=0; }  
00078 
00079     // RETURNS AN ARRAY OF PER-FACE DATA.  USES SAME ATTRIBS (defined above) AS
00080     // Display().  ALLOCATES MEMORY AS DOES GetTris(), ABOVE.
00081     virtual void GetTriData(float* &data, int &numTris, int &numValuesPerTri,
00082                             unsigned int Attribs = OBJ_NORMALS) 
00083                             { data = NULL; numTris = 0; numValuesPerTri = 0; }
00084     virtual int GetNumTris() { return(0); }
00085 
00086     virtual ~Object() {}
00087 };
00088 
00089 #endif

Generated at Fri Oct 12 15:12:21 2001 for GLVU by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001