home *** CD-ROM | disk | FTP | other *** search
/ Learn 3D Graphics Programming on the PC / Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso / rwwin / xbject.h_ / xbject.bin
Text File  |  1995-11-14  |  8KB  |  239 lines

  1. #if !defined(_OBJECT_H)
  2. #define _OBJECT_H
  3.  
  4. /**********************************************************************
  5.  *
  6.  * File :     object.h
  7.  *
  8.  * Abstract : The interface to a "sub-class" of RenderWare clumps
  9.  *            which provides enhanced functionality such as binding a
  10.  *            light to a clump which acts as the visual representation
  11.  *            of a light and also stores the filename of the file from
  12.  *            which the clump was loaded.
  13.  *
  14.  *            This application had been written to be compatible with
  15.  *            both the fixed and floating-point versions of the
  16.  *            RenderWare library, i.e., it uses the macros CREAL,
  17.  *            INT2REAL, RAdd, RDiv, RSub etc. If your application is
  18.  *            intended for the floating-point version of the library
  19.  *            only these macros are not necessary.
  20.  *
  21.  *            Please note that this application is intended for
  22.  *            demonstration purposes only. No support will be
  23.  *            provided for this code and it comes with no warranty.
  24.  *
  25.  **********************************************************************
  26.  *
  27.  * This file is a product of Criterion Software Ltd.
  28.  *
  29.  * This file is provided as is with no warranties of any kind and is
  30.  * provided without any obligation on Criterion Software Ltd. or
  31.  * Canon Inc. to assist in its use or modification.
  32.  *
  33.  * Criterion Software Ltd. will not, under any
  34.  * circumstances, be liable for any lost revenue or other damages arising
  35.  * from the use of this file.
  36.  *
  37.  * Copyright (c) 1994, 1995 Criterion Software Ltd.
  38.  * All Rights Reserved.
  39.  *
  40.  * RenderWare is a trademark of Canon Inc.
  41.  *
  42.  **********************************************************************/
  43.  
  44. /**********************************************************************
  45.  *
  46.  * Comment:
  47.  *
  48.  * This code demonstrates the use of the user data pointer which is
  49.  * supported by most RenderWare objects. The user data pointer allows
  50.  * additional information to be stored with an object by setting the
  51.  * user data pointer to an application defined structure.
  52.  *
  53.  * The viewer manipulates two main kinds of RenderWare objects, clumps
  54.  * and lights. RenderWare lights are normally invisible but to make
  55.  * manipulation uniform between the two object types we create a clump
  56.  * to represent each light. We therefore need some mechanism to tie
  57.  * a light and the clump which represents it together (and vice-versa).
  58.  * This is one of the uses to which we put the user data to.
  59.  *
  60.  * Also, in order to give object's identifiable names and to allow us
  61.  * to save them under their original filenames we need to be able to
  62.  * store the filename of the file storing the clump. We also use the
  63.  * user-data field for this purpose.
  64.  *
  65.  * We define a structure which holds a filename string and a light
  66.  * object handle (which may be NULL if the clump does not represent
  67.  * a light). An instance of this structure is stored in the user
  68.  * data field of each clump. For lights, however, we simply store
  69.  * the handle of the clump representing the light directly in the
  70.  * user data field.
  71.  *
  72.  **********************************************************************/
  73.  
  74. /**********************************************************************
  75.  *
  76.  * Type definitions.
  77.  *
  78.  **********************************************************************/
  79.  
  80. /*
  81.  * different types of objects present 
  82.  */
  83. typedef enum
  84. {
  85.     rfIsClump,
  86.     rfIsSprite,
  87.     rfIsSpline,
  88.     rfIsPaletteSprite,
  89.     rfIsLight,
  90.     rfNoMoveClump
  91. } rfDataType;
  92.  
  93. /*
  94.  * This is the user data structure stored with each clump. It consists
  95.  * of a filename string which will be empty for clumps not loaded from
  96.  * a file (such as those which represent lights) and a light pointer
  97.  * which will be NULL for those clumps which do not represent lights.
  98.  */
  99. typedef struct
  100. {
  101.     char     fileName[_MAX_PATH]; /* The file storing this clump      */
  102.     RwLight *light;               /* The light this clump represents  */ 
  103.     rfDataType datatype; /* type of object */
  104. } ClumpUserData;
  105.  
  106. /**********************************************************************
  107.  *
  108.  * Macro functions.
  109.  *
  110.  **********************************************************************/
  111.  
  112. /*
  113.  * Return the clump's user data pointer. If this clump is a child
  114.  * in a clump hiearchy it has no user data so the user data of the
  115.  * clump at the root of the hierarcy is returned.
  116.  */
  117. #define GETCLUMPUSERDATA(clump) ((ClumpUserData *)RwGetClumpData(RwGetClumpRoot(clump)))
  118.  
  119. /*
  120.  * Get the clump's file name (may be empty).
  121.  */
  122. #define GETCLUMPFILENAME(clump) (GETCLUMPUSERDATA(clump)->fileName)
  123.  
  124. /*
  125.  * Return the light associated with a clump (if it has one).
  126.  */
  127. #define GETCLUMPLIGHT(clump)    (GETCLUMPUSERDATA(clump)->light)
  128.  
  129. /*
  130.  * Return the datatype associated with a clump (if it has one).
  131.  */
  132. #define GETOBJECTTYPE(clump)    (GETCLUMPUSERDATA(clump)->datatype)
  133.  
  134. /*
  135.  * Test whether the clump is the visual representation of a light
  136.  * or an object in its own right.
  137.  */
  138. #define ISCLUMPLIGHT(clump)     (GETCLUMPLIGHT(clump) != NULL)
  139.  
  140. /*
  141.  * Return the clump which is the visual representation of a light.
  142.  */
  143. #define GETLIGHTCLUMP(light)    ((RwClump *)RwGetLightData(light))
  144.  
  145. /**********************************************************************
  146.  *
  147.  * Functions.
  148.  *
  149.  **********************************************************************/
  150.  
  151. /*
  152.  * Read a clump from the given file. This function creates and
  153.  * initializes the user data structure of the clump.
  154.  *
  155.  * RenderWare API Equivalent: RwReadShape()
  156.  */
  157. extern RwClump *ReadClumpObj(char *fileName);
  158.  
  159. /*
  160.  * Create a sprite from the bitmap contained in the given file.
  161.  *
  162.  * RenderWare API Equivalent: RwCreateSprite()
  163.  */
  164. extern RwClump *CreateSpriteObj(char *fileName);
  165.  
  166. /*
  167.  * Create a light of the given type. A clump is built which represents
  168.  * this light and is attached to the user data field of the light.
  169.  *
  170.  * NOTE: We return a pointer to the clump build rather than the light
  171.  * as clump's are the main object type of the viewer.
  172.  *
  173.  * RenderWare API Equivalent: RwCreateLight()
  174.  */
  175. extern RwLight *CreateLightObj(RwLightType kind);
  176.  
  177. /*
  178.  * Duplicate the given clump object and its associated light (if it has
  179.  * one).
  180.  *
  181.  * RenderWare API Equivalent: RwDuplicateClump(), RwDuplicateLight().
  182.  */
  183. extern RwClump *DuplicateClumpObj(RwClump *);
  184.  
  185. /*
  186.  * Add a clump object to the given scene. This function will also add the
  187.  * light object to the scene if the the clump represents a light.
  188.  *
  189.  * RenderWare API Equivalent: RwAddClumpToScene(), RwAddLightToScene().
  190.  */
  191. extern RwScene *AddClumpObjToScene(RwScene *scene, RwClump *clump);
  192.  
  193. /*
  194.  * Add a light object to the given scene. This function will also add the
  195.  * clump object representing a light to the scene.
  196.  *
  197.  * RenderWare API Equivalent: RwAddLightToScene(), RwAddClumpToScene().
  198.  */
  199. extern RwScene *AddLightObjToScene(RwScene *scene, RwLight *light);
  200.  
  201. /*
  202.  * Set the brightness of the given light object. This function also
  203.  * updates the visual appearance of the clump object representing the
  204.  * light to reflect the new brightness.
  205.  *
  206.  * RenderWare API Equivalent: RwSetLightBrightness().
  207.  */
  208. extern RwLight *SetLightObjBrightness(RwLight *light, RwReal bright);
  209.  
  210. /*
  211.  * Set the color of the given light object. This function also
  212.  * updates the visual appearance of the clump object representing the
  213.  * light to reflect the new color.
  214.  *
  215.  * RenderWare API Equivalent: RwSetLightColor().
  216.  */
  217. extern RwLight *SetLightObjColor(RwLight *light, RwReal r, RwReal g, RwReal b);
  218.  
  219. /*
  220.  * Turn the clump which is the visible representation of a light on or off.
  221.  * This function does not turn the light itself on or off, it only
  222.  * shows or hides the visible representation of that light.
  223.  *
  224.  * RenderWare API Equivalent: RwSetClumpState().
  225.  */
  226. extern RwLight *SetLightObjVisibleState(RwLight *light, RwState state);
  227.  
  228. /*
  229.  * Destory the given clump object (and its associated light if it has
  230.  * one). This function will also free the user data structure allocated
  231.  * for the clump.
  232.  *
  233.  * RenderWare API Equivalent: RwDestoryClump()
  234.  */
  235. extern void     DestroyClumpObj(RwClump *clump);
  236.  
  237. /**********************************************************************/
  238.  
  239. #endif /* !defined(_OBJECT_H) */