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

  1. #if !defined(_RFVIEW_H)
  2. #define _RFVIEW_H
  3.  
  4. /*
  5.  * The application instance handle (from rfview.c).
  6.  */ 
  7. extern HINSTANCE AppInstance;
  8.  
  9. /**********************************************************************
  10.  *
  11.  * Macro functions.
  12.  *
  13.  **********************************************************************/
  14.  
  15. /*
  16.  * Macros to convert real numbers in the range CREAL(0.0) to CREAL(1.0)
  17.  * (which RenderWare uses to represent the value of a color channel) to
  18.  * integers in the range 0 to 255 (which Windows uses to represent the
  19.  * value of the a color channel). We use the Windows style in the user
  20.  * interface because users are more used to 0 to 255.
  21.  */
  22. #define BYTETOREAL(v) (RDiv(INT2REAL((RwInt32)(v)), CREAL(255.0)))
  23. #define REALTOBYTE(r) ((int)(REAL2INT(RMul((r), CREAL(255.0)))))
  24.  
  25. /*
  26.  * A macro to convert a RenderWare RwRGBColor to a Windows COLORREF.
  27.  */
  28. #define RWTOCOLORREF(rgb) \
  29.     (PALETTERGB(REALTOBYTE((rgb)->r), REALTOBYTE((rgb)->g), REALTOBYTE((rgb)->b)))
  30.  
  31. /**********************************************************************
  32.  *
  33.  * Functions.
  34.  *
  35.  **********************************************************************/
  36.  
  37. /*
  38.  * Convert a RenderWare RwRGBColor to a Windows COLORREF.
  39.  */
  40. extern COLORREF    RGBToColorRef(RwRGBColor *rgb);
  41.  
  42. /*
  43.  * Convert a Windows COLORREF to a RenderWare RwRGBColor.
  44.  */
  45. extern RwRGBColor *ColorRefToRGB(COLORREF color, RwRGBColor *rgb); 
  46.  
  47. /**********************************************************************/
  48.  
  49. #include "object.h"
  50. #include "rtramp.h"
  51.  
  52. #ifndef   M_PI
  53. #define   M_PI  3.141592654
  54. #endif /* M_PI */
  55. #define M_2PI 6.283185308
  56.  
  57. /**********************************************************************
  58.  *
  59.  * Type definitions.
  60.  *
  61.  **********************************************************************/
  62.  
  63. /*
  64.  * This enumerated type tells us what kind of action should be taken
  65.  * on mouse events.
  66.  */
  67. typedef enum
  68. {
  69.     mmNoAction,
  70.     mmScrollBackdrop,
  71.     mmMoveAndTurnCamera,
  72.     mmTiltCamera,
  73.     mmSpinClump,
  74.     mmDragClump,
  75.     mmDragClumpInZ
  76. } MMMode;
  77.  
  78. /**********************************************************************
  79.  *
  80.  * Application global variables.
  81.  *
  82.  **********************************************************************/
  83.  
  84. /* defines */
  85. #define TwoPI  6.2831852
  86. #define rfSideA 1111          // tags for side used when changing materials
  87. #define rfSideB 1112          // tags for side used when changing materials
  88. #define rfSideC 1113          // tags for side used when changing materials
  89. #define rfSideD 1114          // tags for side used when changing materials
  90. #define rfSideAll 1115        // tags for all sides used when changing materials
  91. #define MAX_RSCROLL 100       // rotation maximum value (-0.5 to +0.5)
  92. #define MAX_SCROLL 500        // translate  maximum value (-2.5 to +2.5)
  93. #define MAX_SCROLLS 1000      // scale  maximum value (-5 to +5)
  94. #define MAX_CP_SCROLL 2400    // camera maximum position and point at (-12 to +12)
  95. #define MAX_CSCROLL 18000     // camera angle maximum (-90 to +90)   
  96. #define MAX_REPEAT 500        // maximum repeat count (0 to 500)
  97. #define WINDOWTAG 1234          // special window in a wall tag to animate material directly
  98. #define MODTEXTURE 1235          // tag for a polygon that is used for modifying texture
  99. #define MODCOLOR 0031          // modify the raster with this color
  100.  
  101. //  ************************************* start of Ferraro ****************************** 
  102. /* structure to hold info on animating materials */
  103. typedef struct {
  104.   RwBool Ambient;
  105.   RwBool Diffuse;
  106.   RwBool Specular;
  107.   RwBool MatAnimate;
  108.   float vAmbient,AmbientInc;
  109.   float vDiffuse,DiffuseInc;
  110.   float vSpecular,SpecularInc;
  111.   } rfSurfMom;
  112.  
  113. /* structure used for manipulating the cameras */
  114. typedef struct {
  115.   RwV3d pos;
  116.   RwReal vw_width,vw_height;
  117.   double angle;
  118.   float aspect;
  119.   RwV3d point;
  120.   RwReal val;    // angle of rotation, amount o
  121.   int repeat; // repeat count
  122.   } rfCamera;
  123.  
  124. // transform structure
  125. typedef struct {
  126.   RwReal x,y,z;  // axis of rotation or translation or origin of scale
  127.   int val;    // angle of rotation
  128.   int repeat; // repeat count
  129.   RwCombineOperation combine;  // combine operator
  130.   } rfTransform;  
  131.  
  132. // debugging structure
  133. typedef struct {
  134.   RwDebugSeverity Severity;
  135.   RwDebugState Message,Assertion,Script;
  136.   RwDebugState Output,Trace;
  137.   } rfDebugging;
  138.  
  139. // relative coordinate transformation working structure
  140. typedef struct {
  141.   RwV3d pos,up,at,right,vc;
  142.   } rfRelative;
  143.  
  144.  
  145. /*
  146.  * Class name for the MS Window's window class.
  147.  */
  148. #define RWVIEWCLASSNAME           "RwViewClass"
  149.  
  150. /*
  151.  * Window title.
  152.  */
  153. #define WINDOWTITLE               "RenderWare 3D Object Viewer"
  154.  
  155. /*
  156.  * Default size of the viewer's window.
  157.  */
  158. #define DEFAULTWINDOWWIDTH        1280 // 440
  159. #define DEFAULTWINDOWHEIGHT       1024 // 450
  160. #define DEFAULTNUMSPLINESAMPLES                100
  161.  
  162.  
  163. #if defined(CONSTRAIN_SIZE)
  164.  
  165. /*
  166.  * Maximum size of the viewer's window.
  167.  */
  168. #define MAXIMUMWINDOWWIDTH        1280 // 512
  169. #define MAXIMUMWINDOWHEIGHT       1024 // 522
  170.  
  171. #endif
  172.  
  173. /*
  174.  * The default size of the viewwindow.
  175.  */
  176. #define DEFAULTVIEWWINDOWSIZE     CREAL(0.4)
  177.  
  178. /*
  179.  * Default distance of the camera from the origin.
  180.  */
  181. #define DEFAULTCAMERADISTANCE     CREAL(7.0)
  182.  
  183.  
  184.  
  185. /* Default minimum height of a spline control point. */
  186. #define DEFAULTMINCONTROLPOINTHEIGHT           CREAL(0.1)
  187.  
  188. /* Default maximum height of a spline control point.*/
  189. #define DEFAULTMAXCONTROLPOINTHEIGHT           CREAL(2.0)
  190.  
  191. /* Spline tracking parameters. */
  192. #define MINSPLINEDELTA                         CREAL(0.002)
  193. #define DEFAULTSPLINEDELTA                     CREAL(0.004)
  194. #define MAXSPLINEDELTA                         CREAL(0.010)
  195.  
  196. #define DEFAULTNUMCONTROLPOINTS   20      
  197.  
  198. /* structure used for spline definition mostly taken from rwRoller  */
  199. typedef struct
  200. {
  201.     RwSpline *spline;
  202.     RwClump  *controlPointClumps[DEFAULTNUMCONTROLPOINTS];
  203.     RwClump  *coasterClump;
  204.     RwReal    t;
  205.     RwReal    tDelta;
  206.     RwV3d     tAt;
  207.     RwV3d     tUp;
  208.     RwV3d     tRight;
  209.     RwV3d     tPosition;
  210.     char      description[20];
  211.     char      filename[80];
  212. } RollerCoasterType;
  213.  
  214. // main definition occurs only in rfView.c
  215. #ifdef MAIN
  216.  RollerCoasterType *coaster;     // spline
  217.  rfRelative rfRel;               // relative (local) coordinate working structure
  218.       
  219.  HWND CurrentWindow;            // current window
  220.  rfDebugging rfDebug;           // debugging window
  221.  rfSurfMom rfSurf;              // surface momentum
  222.  RwBool rfReadSprite;        // should we read sprites
  223.  RwBool rfBirdsEye,rfPaletteView;  // is birds eye view and/or palette sprite displayed
  224. /*
  225.  * The bird's eye sprite and the texture the sprite uses. We could
  226.  * just keep a handle on the sprite and find the texture from it
  227.  * each time it is needed but for simplicitly we will keep a handle on
  228.  * both.
  229.  */
  230.  RwCamera   *BirdsEyeCamera = NULL;
  231.  RwTexture  *BirdsEyeTexture = NULL,*PaletteTexture = NULL;
  232.  RwClump    *BirdsEyeSprite = NULL,*PaletteSprite = NULL;
  233.  RwCamera   *CurrentCamera = NULL;
  234.  
  235.  rfCamera rfCam; // camera working structure
  236.  
  237.  rfTransform rfTran,rfRot,rfScale,rfLoc;  // transform structure for translatino, rotation, scaling and location
  238.  
  239.  RwBool rfRepeatMode = FALSE;  // if we are in repeat mode then do not show bounding box
  240.  
  241.  float textureRate=(float)1.0,accumulatedRate=(float)0.0;   // texture animation variables
  242. /*
  243.  * Global RenderWare object pointers. In this simple application we
  244.  * make use of only a single scene, camera and light.
  245.  */
  246. RwScene    *Scene  = NULL;
  247. RwCamera   *Camera = NULL;
  248. int DisplayDepth;
  249. /*
  250.  * This variable is used to remember which clump was last picked
  251.  * when spinning or dragging a clump on mouse move events.
  252.  */
  253.  RwClump    *SelectedClump = NULL;
  254.  
  255. /*
  256.  * This is the clump used to highlight the currently picked clump.
  257.  */
  258.  RwClump    *HighlightClump = NULL;
  259.  
  260. /*
  261.  * This matrix is used when spinning a clump, it is stored globally
  262.  * so that it is not necessary to re-build the matrix for each frame of
  263.  * animation.
  264.  */
  265.  RwMatrix4d *SpinMatrix = NULL;
  266.  
  267. /*
  268.  * This variable tells us whether the clump should be spun with
  269.  * momentum. Why do we need this as well as the Momentum setting?
  270.  * Well Momentum is TRUE if an object can have momentum (even if it
  271.  * does not currently have moment where SpinClump is TRUE only if we
  272.  * are actually spinning a clump with momentum currently.
  273.  */
  274.  BOOL        SpinClump = FALSE;
  275.  
  276. /*
  277.  * This variable tells us what kind of action to take on a mouse move.
  278.  * The action depends on the object that was picked when the mouse button
  279.  * went down, and on the selection of virtual keys that were depressed at
  280.  * that time. By default no action is taken on mouse move.
  281.  */
  282.  MMMode      MouseMoveMode = mmNoAction;
  283.  
  284. /*
  285.  * Global variables used to remember the last mouse X and Y coordinates
  286.  * when involved in a pan, zoom, drag or spin.
  287.  */
  288.  int         LastX;
  289.  int         LastY;
  290.  
  291. /*
  292.  * This stores the offset from the initial pick position to the origin
  293.  * of the picked clump. It used so that we drag objects by their picked
  294.  * position rather than by their origin.
  295.  */
  296.  RwV3d       PickOffset;
  297.  
  298. /*
  299.  * Current animation frame number. This is incremented each time a
  300.  * frame is drawn on timer expiry. The purpose of this variable is
  301.  * to enable us to periodically (based on the number of frames) call
  302.  * RwOrthoNormalizeMatrix() to correct any errors which have crept
  303.  * into the clump's joint matrix because of the inevitable
  304.  * restrictions on the accuracy of fixed-point numbers. See
  305.  * HandleTimer for more details.
  306.  */
  307.  int         FrameNumber = 0;
  308.  
  309. /*
  310.  * This flag indicates whether the 3D components of the application
  311.  * have been successfully initialized as yet. It is used to guard
  312.  * the message loop handler functions from being invoked before the
  313.  * 3D components of the application are successfully initialized.
  314.  */
  315.  BOOL        RwIsOpen = FALSE;
  316.  
  317. /*
  318.  * This is the last filename opened by the viewer. This is stored
  319.  * so that we can initialize the file open dialog with the last file
  320.  * loaded each time.
  321.  */
  322.  char        LastFileName[_MAX_PATH];
  323.  
  324. /*
  325.  * are we showing spline track
  326.  */
  327. BOOL HideSpline; 
  328.  
  329. /*
  330.  * are we showing control points on the spline
  331.  */
  332. BOOL HideControlPoints;
  333.  
  334. /*
  335.  * are we using acceleration and deceleration on the spline
  336.  */
  337. BOOL UseSmoothEnd;
  338. /*
  339.  * should object travel along spline
  340.  */
  341. BOOL TravelSpline;
  342.  
  343.  
  344.  
  345. #else   // external definitions: See above for description.
  346.  
  347. extern  RollerCoasterType *coaster;
  348. extern  rfRelative rfRel;    
  349. extern  HWND CurrentWindow;
  350. extern  rfDebugging rfDebug;
  351. extern  rfSurfMom rfSurf;
  352. extern  RwBool rfReadSprite;
  353. extern  RwBool rfBirdsEye,rfPaletteView;
  354. extern  RwCamera   *BirdsEyeCamera;
  355. extern  RwTexture  *BirdsEyeTexture,*PaletteTexture;
  356. extern  RwClump    *BirdsEyeSprite,*PaletteSprite;
  357. extern  RwCamera   *CurrentCamera;
  358. extern  rfCamera rfCam;
  359. extern  rfTransform rfTran,rfRot,rfScale,rfLoc;
  360. extern  RwBool rfRepeatMode;
  361. extern  float textureRate,accumulatedRate;
  362. extern  RwScene    *Scene ;
  363. extern  RwCamera   *Camera;
  364. extern  int DisplayDepth;
  365. extern  RwClump    *SelectedClump;
  366. extern  RwClump    *HighlightClump;
  367. extern  RwMatrix4d *SpinMatrix;
  368. extern  BOOL        SpinClump;
  369. extern  MMMode      MouseMoveMode;
  370. extern  int         LastX;
  371. extern  int         LastY;
  372. extern  RwV3d       PickOffset;
  373. extern  int         FrameNumber;
  374. extern  BOOL        RwIsOpen;
  375. extern  char        LastFileName[_MAX_PATH];
  376. extern  BOOL        HideSpline; 
  377. extern  BOOL        HideControlPoints; 
  378. extern  BOOL        UseSmoothEnd;
  379. extern  BOOL        TravelSpline; 
  380. #endif
  381.  
  382.  
  383. /*
  384.  * Spline tracking parameters.
  385.  */
  386. #define MINSPLINEDELTA                         CREAL(0.002)
  387. #define DEFAULTSPLINEDELTA                     CREAL(0.004)
  388. #define MAXSPLINEDELTA                         CREAL(0.010)
  389. #define SPLINEDELTAACCELERATION                CREAL(0.0005)
  390. #define SPLINEDELTADECCELERATION               CREAL(0.0006)       
  391.  
  392.  
  393. #endif /* !defined(_RFVIEW_H) */
  394.