home *** CD-ROM | disk | FTP | other *** search
/ Learn 3D Graphics Programming on the PC / Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso / rwwin / object.h1_ / object.bin
Text File  |  1995-11-14  |  8KB  |  213 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.  * This is the user data structure stored with each clump. It consists
  82.  * of a filename string which will be empty for clumps not loaded from
  83.  * a file (such as those which represent lights) and a light pointer
  84.  * which will be NULL for those clumps which do not represent lights.
  85.  */
  86. typedef struct
  87. {
  88.     char     fileName[_MAX_PATH]; /* The file storing this clump      */
  89.     RwLight *light;               /* The light this clump represents  */
  90. } ClumpUserData;
  91.  
  92. /**********************************************************************
  93.  *
  94.  * Macro functions.
  95.  *
  96.  **********************************************************************/
  97.  
  98. /*
  99.  * Return the clump's user data pointer. If this clump is a child
  100.  * in a clump hiearchy it has no user data so the user data of the
  101.  * clump at the root of the hierarcy is returned.
  102.  */
  103. #define GETCLUMPUSERDATA(clump) ((ClumpUserData *)RwGetClumpData(RwGetClumpRoot(clump)))
  104.  
  105. /*
  106.  * Get the clump's file name (may be empty).
  107.  */
  108. #define GETCLUMPFILENAME(clump) (GETCLUMPUSERDATA(clump)->fileName)
  109.  
  110. /*
  111.  * Return the light associated with a clump (if it has one).
  112.  */
  113. #define GETCLUMPLIGHT(clump)    (GETCLUMPUSERDATA(clump)->light)
  114.  
  115. /*
  116.  * Test whether the clump is the visual representation of a light
  117.  * or an object in its own right.
  118.  */
  119. #define ISCLUMPLIGHT(clump)     (GETCLUMPLIGHT(clump) != NULL)
  120.  
  121. /*
  122.  * Return the clump which is the visual representation of a light.
  123.  */
  124. #define GETLIGHTCLUMP(light)    ((RwClump *)RwGetLightData(light))
  125.  
  126. /**********************************************************************
  127.  *
  128.  * Functions.
  129.  *
  130.  **********************************************************************/
  131.  
  132. /*
  133.  * Read a clump from the given file. This function creates and
  134.  * initializes the user data structure of the clump.
  135.  *
  136.  * RenderWare API Equivalent: RwReadShape()
  137.  */
  138. extern RwClump *ReadClumpObj(char *fileName);
  139.  
  140. /*
  141.  * Create a light of the given type. A clump is built which represents
  142.  * this light and is attached to the user data field of the light.
  143.  *
  144.  * NOTE: We return a pointer to the clump build rather than the light
  145.  * as clump's are the main object type of the viewer.
  146.  *
  147.  * RenderWare API Equivalent: RwCreateLight()
  148.  */
  149. extern RwLight *CreateLightObj(RwLightType kind);
  150.  
  151. /*
  152.  * Duplicate the given clump object and its associated light (if it has
  153.  * one).
  154.  *
  155.  * RenderWare API Equivalent: RwDuplicateClump(), RwDuplicateLight().
  156.  */
  157. extern RwClump *DuplicateClumpObj(RwClump *);
  158.  
  159. /*
  160.  * Add a clump object to the given scene. This function will also add the
  161.  * light object to the scene if the the clump represents a light.
  162.  *
  163.  * RenderWare API Equivalent: RwAddClumpToScene(), RwAddLightToScene().
  164.  */
  165. extern RwScene *AddClumpObjToScene(RwScene *scene, RwClump *clump);
  166.  
  167. /*
  168.  * Add a light object to the given scene. This function will also add the
  169.  * clump object representing a light to the scene.
  170.  *
  171.  * RenderWare API Equivalent: RwAddLightToScene(), RwAddClumpToScene().
  172.  */
  173. extern RwScene *AddLightObjToScene(RwScene *scene, RwLight *light);
  174.  
  175. /*
  176.  * Set the brightness of the given light object. This function also
  177.  * updates the visual appearance of the clump object representing the
  178.  * light to reflect the new brightness.
  179.  *
  180.  * RenderWare API Equivalent: RwSetLightBrightness().
  181.  */
  182. extern RwLight *SetLightObjBrightness(RwLight *light, RwReal bright);
  183.  
  184. /*
  185.  * Set the color of the given light object. This function also
  186.  * updates the visual appearance of the clump object representing the
  187.  * light to reflect the new color.
  188.  *
  189.  * RenderWare API Equivalent: RwSetLightColor().
  190.  */
  191. extern RwLight *SetLightObjColor(RwLight *light, RwReal r, RwReal g, RwReal b);
  192.  
  193. /*
  194.  * Turn the clump which is the visible representation of a light on or off.
  195.  * This function does not turn the light itself on or off, it only
  196.  * shows or hides the visible representation of that light.
  197.  *
  198.  * RenderWare API Equivalent: RwSetClumpState().
  199.  */
  200. extern RwLight *SetLightObjVisibleState(RwLight *light, RwState state);
  201.  
  202. /*
  203.  * Destory the given clump object (and its associated light if it has
  204.  * one). This function will also free the user data structure allocated
  205.  * for the clump.
  206.  *
  207.  * RenderWare API Equivalent: RwDestoryClump()
  208.  */
  209. extern void     DestroyClumpObj(RwClump *clump);
  210.  
  211. /**********************************************************************/
  212.  
  213. #endif /* !defined(_OBJECT_H) */