home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / avril / avril.h < prev    next >
C/C++ Source or Header  |  1996-03-19  |  66KB  |  1,374 lines

  1. /*
  2.  *                          The AVRIL System
  3.  *
  4.  *  AVRIL stands for A Virtual Reality Interface Library.  It's a library
  5.  *  of routines for doing fast, polygon-based rendering on a variety of
  6.  *  platforms.  It also provides support for device i/o, and will provide
  7.  *  simulation,  user interface, interaction detection and more.
  8.  *
  9.  *  It's designed to be easy to use, portable, and fast.
  10.  *
  11.  */
  12.  
  13. /* Copyright 1994 by Bernie Roehl */
  14.  
  15. /*
  16.    You may use this code for your own non-commercial projects without
  17.    paying any fees or royalties.  "Non-commercial", in this context,
  18.    means that the software you write is given away for free to anyone
  19.    who wants it.
  20.    
  21.    Commercial use, including shareware, requires a licensing
  22.    fee and a specific written agreement with the author.
  23.  
  24.    All programs created using this software (both commercial and
  25.    non-commercial) must acknowledge the use of the AVRIL library,
  26.    both in the documentation and in a banner screen at the start or
  27.    end of the program.
  28.  
  29.    For more information, contact Bernie Roehl (broehl@uwaterloo.ca).
  30.  
  31. */
  32.  
  33. /* This is version 2.0 -- January, 1995 */
  34.  
  35. /* Three special data types are used in AVRIL:
  36.  
  37.         vrl_Scalar  -- a measure of virtual distance
  38.         vrl_Factor  -- a multiplication factor, usually in the range -1 to +1
  39.         vrl_Angle   -- measured in 65536th's of a degree
  40.  
  41.    In the floating-point version of the code, they're all floats.  In
  42.    the fixed-point version, they're all stored in a 32-bit word; they
  43.    use differing numbers of bits for the integer and fractional parts of
  44.    their values.
  45.  */
  46.  
  47. #define VRL_VERSION 2
  48.  
  49. #define VRL_PC_COMPATABLE 1
  50. #define VRL_USE_FIXED_POINT 1
  51.  
  52. #include <stdio.h>      /* FILE */
  53. #ifdef __GNUC__
  54. #include <djgppstd.h>   /* memcpy() */
  55. #else
  56. #include <string.h>     /* memcpy() */
  57. #endif
  58.  
  59. typedef short int vrl_Boolean;    /* zero or non-zero */
  60. typedef short int vrl_16bit;      /* a 16 bit integer */
  61. typedef long int vrl_32bit;       /* a 32 bit integer */
  62. typedef unsigned short int vrl_unsigned16bit;   /* a 16-bit unsigned integer */
  63. typedef unsigned long int vrl_unsigned32bit;    /* a 32-bit unsigned integer */
  64.  
  65. #define abs32(v) labs(v)          /* long absolute value */
  66.  
  67. #ifdef VRL_USE_FIXED_POINT
  68. typedef vrl_32bit vrl_Scalar;  /* 32.0 */
  69. typedef vrl_32bit vrl_Factor;  /* 3.29 */
  70. #define VRL_UNITY 536870912L   /* 2**29 */
  71. typedef vrl_32bit vrl_Angle;   /* 16.16 */
  72. #define VRL_ANGLECONVERSION 65536  /* 2**16 */
  73. vrl_Factor vrl_ScalarDivide(vrl_Scalar a, vrl_Scalar b);
  74. vrl_Scalar vrl_ScalarMultDiv(vrl_Scalar a, vrl_Scalar b, vrl_Scalar c);
  75. vrl_Scalar vrl_FactorMultiply(vrl_Factor a, vrl_Scalar b);
  76. #define vrl_ScalarRound(a) (a)
  77. #define vrl_ScalarAbs(a) abs32(a)
  78.  
  79. #else  /* floating-point */
  80. typedef float vrl_Scalar;
  81. typedef float vrl_Factor;
  82. #define VRL_UNITY 1.0
  83. typedef float vrl_Angle;
  84. #define VRL_ANGLECONVERSION 1
  85. #define vrl_ScalarDivide(a, b) (((float) (a)) / ((float) (b)))
  86. #define vrl_ScalarMultDiv(a, b, c) ((((float) (a)) * ((float) (b))) / ((float) (c)))
  87. #define vrl_FactorMultiply(a, b) (((float) (a)) * ((float) (b)))
  88. vrl_Scalar vrl_ScalarRound(vrl_Scalar a);
  89. #define vrl_ScalarAbs(a) fabs((float) (a))
  90. #endif
  91.  
  92. /* Additional types */
  93.  
  94. typedef vrl_unsigned32bit vrl_Time;   /* a time in milliseconds */
  95. typedef vrl_unsigned32bit vrl_Color;  /* a four-byte value, red low-order */
  96.  
  97. typedef vrl_16bit vrl_ScreenPos;      /* a screen-space pixel location */
  98. typedef vrl_32bit vrl_ScreenCoord;    /* a screen-space coordinate */
  99. #define VRL_SCREEN_FRACT_BITS 8       /* screen coords are 24.8 */
  100.  
  101. /*
  102.    Conversion routines.  You should always use these, to ensure your code
  103.    will work in both the floating-point and fixed-point implementations.
  104.  */
  105.  
  106. #define float2scalar(f) ((vrl_Scalar) (f))
  107. #define scalar2float(s) ((float) (s))
  108. #define float2factor(f) ((vrl_Factor) ((f) * VRL_UNITY))
  109. #define factor2float(a) (((float) (a)) / VRL_UNITY)
  110. #define float2angle(f) ((vrl_Angle) ((f) * VRL_ANGLECONVERSION))
  111. #define angle2float(a) (((float) (a)) / VRL_ANGLECONVERSION)
  112.  
  113. /* Math functions */
  114.  
  115. void vrl_MathInit(void);     /* initializes math routines */
  116. vrl_Factor vrl_Sine(vrl_Angle angle);
  117. vrl_Factor vrl_Cosine(vrl_Angle angle);
  118.  
  119. /* Vector functions */
  120.  
  121. typedef vrl_Scalar vrl_Vector[3];
  122.  
  123. #define X 0
  124. #define Y 1
  125. #define Z 2
  126. #define XROT 3
  127. #define YROT 4
  128. #define ZROT 5
  129.  
  130. void vrl_VectorCreate(vrl_Vector result, vrl_Scalar x, vrl_Scalar y, vrl_Scalar z);
  131. void vrl_VectorAdd(vrl_Vector result, vrl_Vector v1, vrl_Vector v2);
  132. void vrl_VectorSub(vrl_Vector result, vrl_Vector v1, vrl_Vector v2);
  133. void vrl_VectorNegate(vrl_Vector v);
  134. vrl_Factor vrl_VectorDotproduct(vrl_Vector v1, vrl_Vector v2);
  135. vrl_Scalar vrl_VectorCrossproduct(vrl_Vector result, vrl_Vector v1, vrl_Vector v2);
  136. vrl_Scalar vrl_VectorMagnitude(vrl_Vector v);
  137. void vrl_VectorNormalize(vrl_Vector v);
  138. vrl_Scalar vrl_VectorDistance(vrl_Vector v1, vrl_Vector v2);
  139. void vrl_VectorScale(vrl_Vector v, vrl_Scalar newmag);
  140. void vrl_VectorRescale(vrl_Vector v, vrl_Scalar newmag);
  141.  
  142. #define vrl_VectorCopy(destination, source) memcpy((destination), (source), sizeof(vrl_Vector))
  143. #define vrl_VectorPrint(out, str, v) fprintf(out, "%s%f,%f,%f", (str), scalar2float((v)[X]), scalar2float((v)[Y]), scalar2float((v)[Z]))
  144. #define vrl_VectorEqual(v1, v2) ((v1)[X] == (v2)[X] && (v1)[Y] == (v2)[Y] && (v1)[Z] == (v2)[Z])
  145. #define vrl_VectorZero(v) ((v)[X] = (v)[Y] = (v)[Z] = 0)
  146.  
  147. extern vrl_Vector vrl_VectorNULL;  /* the [0,0,0] vector */
  148.  
  149. /* note that normalized vectors actually have vrl_Factors as elements */
  150.  
  151. /* Matrix functions */
  152.  
  153. typedef vrl_Scalar vrl_Matrix[4][3];
  154.  
  155. /* The rotational elements of a matrix are actually vrl_Factors, not
  156.    vrl_Scalars; only the translational elements are vrl_Scalars. */
  157.  
  158. void vrl_MatrixIdentity(vrl_Matrix m);
  159. void vrl_MatrixMultiply(vrl_Matrix result, vrl_Matrix m1, vrl_Matrix m2);
  160. void vrl_MatrixInverse(vrl_Matrix result, vrl_Matrix m);
  161. void vrl_MatrixRotX(vrl_Matrix m, vrl_Angle angle, vrl_Boolean leftside);
  162. void vrl_MatrixRotY(vrl_Matrix m, vrl_Angle angle, vrl_Boolean leftside);
  163. void vrl_MatrixRotZ(vrl_Matrix m, vrl_Angle angle, vrl_Boolean leftside);
  164. void vrl_MatrixRotVector(vrl_Matrix m, vrl_Angle angle, vrl_Vector vector, vrl_Boolean leftside);
  165. void vrl_MatrixResetRotations(vrl_Matrix m);
  166. void vrl_MatrixGetBasis(vrl_Vector v, vrl_Matrix m, int axis);
  167. void vrl_MatrixSetBasis(vrl_Matrix m, vrl_Vector v, int axis);
  168. void vrl_MatrixTranslate(vrl_Matrix result, vrl_Vector v, vrl_Boolean leftside);
  169. void vrl_MatrixGetRotations(vrl_Matrix m, vrl_Angle *rx, vrl_Angle *ry, vrl_Angle *rz);
  170.  
  171. #define vrl_MatrixCopy(result, m) memcpy((result), (m), sizeof(vrl_Matrix))
  172. #define vrl_MatrixGetTranslation(v, m) vrl_VectorCopy((v), (m)[3])
  173. #define vrl_MatrixSetTranslation(m, v) vrl_VectorCopy((m)[3], (v))
  174.  
  175. /* Transformation functions */
  176.  
  177. void vrl_Transform(vrl_Vector result, vrl_Matrix m, vrl_Vector v);
  178. vrl_Scalar vrl_TransformX(vrl_Matrix m, vrl_Vector v);
  179. vrl_Scalar vrl_TransformY(vrl_Matrix m, vrl_Vector v);
  180. vrl_Scalar vrl_TransformZ(vrl_Matrix m, vrl_Vector v);
  181.  
  182. /* Data types */
  183.  
  184. typedef struct _vrl_world vrl_World;
  185. typedef struct _vrl_object vrl_Object;
  186. typedef struct _vrl_shape vrl_Shape;
  187. typedef struct _vrl_rep vrl_Rep;
  188. typedef struct _vrl_facet vrl_Facet;
  189. typedef struct _vrl_surface vrl_Surface;
  190. typedef struct _vrl_light vrl_Light;
  191. typedef struct _vrl_camera vrl_Camera;
  192. typedef struct _vrl_device vrl_Device;
  193. typedef struct _vrl_device_channel vrl_DeviceChannel;
  194. typedef struct _vrl_serial_port vrl_SerialPort;
  195. typedef struct _vrl_surface_map vrl_Surfacemap;
  196. typedef struct _vrl_hue vrl_Hue;
  197. typedef struct _vrl_palette vrl_Palette;
  198. typedef struct _vrl_stereo_conf vrl_StereoConfiguration;
  199.  
  200. typedef enum
  201.         {
  202.         VRL_COORD_LOCAL = 0, VRL_COORD_PARENT,
  203.         VRL_COORD_WORLD, VRL_COORD_OBJREL
  204.         } vrl_CoordFrame;
  205.  
  206. struct _vrl_hue
  207.     {
  208.     unsigned char start;       /* starting index into palette */
  209.     unsigned char maxshade;    /* maximum number of shades */
  210.     };
  211.  
  212. struct _vrl_palette
  213.     {
  214.     unsigned char data[256][3];
  215.     vrl_Hue huemap[256];
  216.     int changed : 1;    
  217.     };
  218.  
  219. void vrl_PaletteInit(vrl_Palette *pal);
  220. int vrl_PaletteRead(FILE *in, vrl_Palette *pal);
  221. vrl_Color vrl_PaletteGetEntry(vrl_Palette *pal, int n);
  222. void vrl_PaletteSetEntry(vrl_Palette *pal, int n, vrl_Color color);
  223.  
  224. #define vrl_PaletteHasChanged(pal) ((pal)->changed)
  225. #define vrl_PaletteSetChanged(pal, flag) ((pal)->changed = (flag))
  226. #define vrl_PaletteGetHuemap(pal) ((pal)->huemap)
  227.     
  228. /* Worlds */
  229.  
  230. struct _vrl_world
  231.     {
  232.     vrl_Object *objects;      /* tree of objects */
  233.     vrl_Light *lights;        /* linked list of lights */
  234.     vrl_Camera *cameras;      /* linked list of cameras */
  235.     vrl_Camera *camera;       /* current camera */
  236.     vrl_Camera *left_camera;  /* left-eye camera */
  237.     vrl_Camera *right_camera; /* right-eye camera */
  238.     vrl_StereoConfiguration *stereo;  /* stereoscopic viewing information */
  239.     vrl_Factor ambient;       /* ambient light level */
  240.     vrl_Scalar scale;         /* millimeters per unit of virtual space */
  241.     vrl_Scalar movestep;      /* default movement step size */
  242.     vrl_Angle rotstep;        /* default rotation step size */
  243.     vrl_Boolean movement_mode : 1;    /* non-zero if we can fly by looking up */
  244.     vrl_Boolean use_stereo : 1;       /* non-zero if we want stereoscopic viewing */
  245.     vrl_Boolean screenclear : 1;      /* set if we should clear the screen */
  246.     vrl_Boolean horizon : 1;          /* set if we should draw a horizon   */
  247.     vrl_Color horizoncolors[10];      /* entry 0 is ground, entry n is sky */
  248.     int nhorizoncolors;       /* number of colors used in horizoncolors[] */
  249.     vrl_Palette palette;      /* the palette, if one is used */
  250.     };
  251.  
  252. vrl_World *vrl_WorldInit(vrl_World *world);
  253. void vrl_WorldAddLight(vrl_Light *light);
  254. void vrl_WorldRemoveLight(vrl_Light *light);
  255. vrl_Light *vrl_WorldFindLight(char *name);
  256. void vrl_WorldAddCamera(vrl_Camera *camera);
  257. void vrl_WorldRemoveCamera(vrl_Camera *camera);
  258. vrl_Camera *vrl_WorldFindCamera(char *name);
  259. void vrl_WorldAddObject(vrl_Object *obj);
  260. void vrl_WorldRemoveObject(vrl_Object *obj);
  261. vrl_Object *vrl_WorldFindObject(char *name);
  262. int vrl_WorldCountObjects(void);
  263. int vrl_WorldCountFacets(void);
  264. int vrl_WorldCountLights(void);
  265. int vrl_WorldCountCameras(void);
  266. void vrl_WorldGetBounds(vrl_Vector v1, vrl_Vector v2);
  267. void vrl_WorldGetCenter(vrl_Vector v);
  268. vrl_Scalar vrl_WorldGetSize(void);
  269.  
  270. #define vrl_WorldCreate() vrl_WorldInit(vrl_malloc(sizeof(vrl_World)))
  271. #define vrl_WorldSetScreenClear(n) (vrl_current_world->screenclear = (n) ? 1 : 0)
  272. #define vrl_WorldGetScreenClear() (vrl_current_world->screenclear)
  273. #define vrl_WorldToggleScreenClear() (vrl_current_world->screenclear = !vrl_current_world->screenclear)
  274. #define vrl_WorldSetStereo(n) (vrl_current_world->use_stereo = (n) ? 1 : 0)
  275. #define vrl_WorldGetStereo() (vrl_current_world->use_stereo)
  276. #define vrl_WorldToggleStereo() (vrl_current_world->use_stereo = !vrl_current_world->use_stereo)
  277. #define vrl_WorldSetStereoConfiguration(conf) (vrl_current_world->stereo = (conf))
  278. #define vrl_WorldGetStereoConfiguration() (vrl_current_world->stereo)
  279. #define vrl_WorldSetHorizon(n) (vrl_current_world->horizon = (n) ? 1 : 0)
  280. #define vrl_WorldGetHorizon() (vrl_current_world->horizon)
  281. #define vrl_WorldToggleHorizon() (vrl_current_world->horizon = !vrl_current_world->horizon)
  282. #define vrl_WorldSetMovementMode(n) (vrl_current_world->movement_mode = (n) ? 1 : 0)
  283. #define vrl_WorldGetMovementMode() (vrl_current_world->movement_mode)
  284. #define vrl_WorldToggleMovementMode() (vrl_current_world->movement_mode = !vrl_current_world->movement_mode)
  285. #define vrl_WorldSetMovestep(distance) (vrl_current_world->movestep = (distance))
  286. #define vrl_WorldGetMovestep() (vrl_current_world->movestep)
  287. #define vrl_WorldSetTurnstep(angle) (vrl_current_world->rotstep = (angle))
  288. #define vrl_WorldGetTurnstep() (vrl_current_world->rotstep)
  289. #define vrl_WorldSetScale(s) (vrl_current_world->scale = (s))
  290. #define vrl_WorldGetScale() (vrl_current_world->scale)
  291. #define vrl_WorldSetAmbient(amb) (vrl_current_world->ambient = (amb))
  292. #define vrl_WorldGetAmbient() (vrl_current_world->ambient)
  293. #define vrl_WorldSetGroundColor(color) (vrl_current_world->horizoncolors[0] = (color))
  294. #define vrl_WorldGetGroundColor() (vrl_current_world->horizoncolors[0])
  295. #define vrl_WorldSetSkyColor(color) (vrl_current_world->horizoncolors[vrl_current_world->nhorizoncolors-1] = (color))
  296. #define vrl_WorldGetSkyColor() (vrl_current_world->horizoncolors[vrl_current_world->nhorizoncolors-1])
  297. #define vrl_WorldGetPalette() (&vrl_current_world->palette)
  298. #define vrl_WorldGetLights() (vrl_current_world->lights)
  299. #define vrl_WorldGetCameras() (vrl_current_world->cameras)
  300. #define vrl_WorldGetObjectTree() (vrl_current_world->objects)
  301. #define vrl_WorldSetCamera(cam) (vrl_current_world->camera = (cam))
  302. #define vrl_WorldGetCamera() (vrl_current_world->camera)
  303. #define vrl_WorldSetLeftCamera(cam) (vrl_current_world->left_camera = (cam))
  304. #define vrl_WorldGetLeftCamera() (vrl_current_world->left_camera)
  305. #define vrl_WorldSetRightCamera(cam) (vrl_current_world->right_camera = (cam))
  306. #define vrl_WorldGetRightCamera() (vrl_current_world->right_camera)
  307. #define vrl_WorldUpdate() vrl_ObjectUpdate(vrl_WorldGetObjectTree())
  308.  
  309. extern vrl_World *vrl_current_world;   /* the currently active world */
  310.  
  311. #define vrl_WorldSetCurrent(world) (vrl_current_world = (world))
  312. #define vrl_WorldGetCurrent() (vrl_current_world)
  313.  
  314. /* Objects */
  315.  
  316. typedef int (*vrl_ObjectFunction)(vrl_Object *obj);
  317.  
  318. struct _vrl_object
  319.     {
  320.     vrl_Shape *shape;           /* geometry information */
  321.     vrl_Surfacemap *surfmap;    /* array of pointers to surface descriptors */
  322.     vrl_Matrix localmat;        /* transformation matrix relative to our parent */
  323.     vrl_Matrix globalmat;       /* transformation matrix relative to the world */
  324.     vrl_Object *parent;         /* pointer to our parent in the hierarchy */
  325.     vrl_Object *children;       /* pointer to our children */
  326.     vrl_Object *siblings;       /* pointers to our siblings */
  327.     vrl_Vector minbound, maxbound;  /* bounding box (world coords) */
  328.     vrl_Boolean fixed : 1;              /* set if object is immobile */
  329.     vrl_Boolean moved : 1;              /* set when our local matrix has changed */
  330.     vrl_Boolean rotate_box : 1;         /* set if bounding box should rotate */
  331.     vrl_Boolean highlight : 1;          /* set if object is highlighted */
  332.     vrl_Boolean invisible : 1;          /* set if object is invisible */
  333.     unsigned char layer;        /* the layer we're on (0 for all, 1-255) */
  334.     vrl_Object *contents;       /* points to objects contained by this one (not used) */
  335.     vrl_Rep *forced_rep;        /* if not NULL, forces a rep to be used */
  336.     char *name;                 /* name of the object (may be NULL) */
  337.     void *applic_data;          /* pointer to application-specific data */
  338.     vrl_ObjectFunction function;   /* object function */
  339.     vrl_Object *next;           /* points to next object on a list */
  340.     };
  341.  
  342. vrl_Object *vrl_ObjectInit(vrl_Object *obj);
  343. vrl_Object *vrl_ObjectCreate(vrl_Shape *shape);
  344. vrl_Object *vrl_ObjectCopy(vrl_Object *obj);
  345. void vrl_ObjectDestroy(vrl_Object *object);
  346. void vrl_ObjectMove(vrl_Object *obj, vrl_Scalar x, vrl_Scalar y, vrl_Scalar z);
  347. void vrl_ObjectRelMove(vrl_Object *obj, vrl_Scalar x, vrl_Scalar y, vrl_Scalar z);
  348. void vrl_ObjectRotVector(vrl_Object *obj, vrl_Angle angle, vrl_Vector vector);
  349. void vrl_ObjectRotReset(vrl_Object *obj);
  350. void vrl_ObjectRotate(vrl_Object *obj, vrl_Angle angle, int axis, vrl_CoordFrame frame, vrl_Object *relative_to);
  351. void vrl_ObjectTranslate(vrl_Object *obj, vrl_Vector v, vrl_CoordFrame frame, vrl_Object *relative_to);
  352. void vrl_ObjectLookAt(vrl_Object *obj, vrl_Vector forward, vrl_Vector up);
  353. vrl_Object *vrl_ObjectAttach(vrl_Object *obj, vrl_Object *newparent);
  354. vrl_Object *vrl_ObjectDetach(vrl_Object *obj);
  355. vrl_Object *vrl_ObjectUpdate(vrl_Object *object);
  356. void vrl_ObjectTraverse(vrl_Object *object, int (*function)(vrl_Object *obj));
  357. void vrl_ObjectMakeFixed(vrl_Object *object);
  358. void vrl_ObjectMakeMovable(vrl_Object *object);
  359. vrl_Object *vrl_ObjectFindRoot(vrl_Object *obj);
  360. vrl_Scalar vrl_ObjectComputeDistance(vrl_Object *obj1, vrl_Object *obj2);
  361.  
  362. #define vrl_ObjectRotX(obj, angle) vrl_ObjectRotate((obj), (angle), X, VRL_COORD_PARENT, NULL)
  363. #define vrl_ObjectRotY(obj, angle) vrl_ObjectRotate((obj), (angle), Y, VRL_COORD_PARENT, NULL)
  364. #define vrl_ObjectRotZ(obj, angle) vrl_ObjectRotate((obj), (angle), Z, VRL_COORD_PARENT, NULL)
  365. #define vrl_ObjectVectorMove(obj, v) vrl_ObjectMove((obj), (v)[X], (v)[Y], (v)[Z])
  366. #define vrl_ObjectVectorRelMove(obj, v) vrl_ObjectTranslate((obj), (v), VRL_COORD_PARENT, NULL)
  367. #define vrl_ObjectSetLayer(object, lay) ((obj)->layer = (lay))
  368. #define vrl_ObjectGetLayer(object) ((object)->layer)
  369. #define vrl_ObjectSetShape(object, shp) ((object)->shape = (shp))
  370. #define vrl_ObjectGetShape(object) ((object)->shape)
  371. #define vrl_ObjectSetSurfacemap(object, map) ((object)->surfmap = (map))
  372. #define vrl_ObjectGetSurfacemap(object) ((object)->surfmap)
  373. #define vrl_ObjectSetHighlight(object, high) ((object)->highlight = (high))
  374. #define vrl_ObjectGetHighlight(object) ((object)->highlight)
  375. #define vrl_ObjectToggleHighlight(object) ((object)->highlight = !(object)->highlight)
  376. #define vrl_ObjectSetVisibility(object, vis) ((object)->invisible = ((vis) ? 1 : 0))
  377. #define vrl_ObjectGetVisibility(object) ((object)->invisible)
  378. #define vrl_ObjectToggleVisibility(object) ((object)->invisible = !(object)->invisible)
  379. #define vrl_ObjectIsFixed(object) ((object)->fixed)
  380. #define vrl_ObjectGetMinbounds(object, v) vrl_VectorCopy((v), (object)->minbound)
  381. #define vrl_ObjectGetMaxbounds(object, v) vrl_VectorCopy((v), (object)->maxbound)
  382. #define vrl_ObjectSetRep(object, r) ((object)->forced_rep = (r))
  383. #define vrl_ObjectGetRep(object) ((object)->forced_rep)
  384. #define vrl_ObjectGetWorldX(object) ((object)->globalmat[3][X])
  385. #define vrl_ObjectGetWorldY(object) ((object)->globalmat[3][Y])
  386. #define vrl_ObjectGetWorldZ(object) ((object)->globalmat[3][Z])
  387. #define vrl_ObjectGetWorldLocation(object, v) vrl_VectorCopy((v), (object)->globalmat[3])
  388. #define vrl_ObjectGetRelativeX(object) ((object)->localmat[3][X])
  389. #define vrl_ObjectGetRelativeY(object) ((object)->localmat[3][Y])
  390. #define vrl_ObjectGetRelativeZ(object) ((object)->localmat[3][Z])
  391. #define vrl_ObjectGetRelativeLocation(object, v) vrl_VectorCopy((v), (object)->localmat[3])
  392. #define vrl_ObjectGetWorldRotations(object, rx, ry, rz) vrl_MatrixGetRotations((object)->globalmat, (rx), (ry), (rz))
  393. #define vrl_ObjectGetRelativeRotations(object, rx, ry, rz) vrl_MatrixGetRotations((object)->localmat, (rx), (ry), (rz))
  394. #define vrl_ObjectSetName(obj, str) ((obj)->name = (str))
  395. #define vrl_ObjectGetName(obj) ((obj)->name)
  396. #define vrl_ObjectSetApplicationData(obj, data) ((obj)->applic_data = (data))
  397. #define vrl_ObjectGetApplicationData(obj) ((obj)->applic_data)
  398. #define vrl_ObjectSetFunction(obj, fn) ((obj)->function = (fn))
  399. #define vrl_ObjectGetFunction(obj) ((obj)->function)
  400. #define vrl_ObjectGetForwardVector(object, v) vrl_MatrixGetBasis((v), (object)->globalmat, Z)
  401. #define vrl_ObjectGetRightVector(object, v) vrl_MatrixGetBasis((v), (object)->globalmat, X)
  402. #define vrl_ObjectGetUpVector(object, v) vrl_MatrixGetBasis((v), (object)->globalmat, Y)
  403. #define vrl_ObjectGetParent(object) ((object)->parent)
  404.  
  405. /* Shapes */
  406.  
  407. struct _vrl_shape
  408.     {
  409.     vrl_Vector center;  /* center of bounding sphere */
  410.     vrl_Scalar radius;  /* radius of bounding sphere */
  411.     vrl_Vector minbound, maxbound;  /* bounding box */
  412.     vrl_Surfacemap *default_surfacemap;  /* default surface map for this shape */
  413.     vrl_Rep *replist;  /* linked list of representations */
  414.     char *name;        /* name of this shape */
  415.     vrl_Shape *next;   /* shapes are kept in a linked list */
  416.     };
  417.  
  418. vrl_Shape *vrl_ShapeInit(vrl_Shape *shape);
  419. void vrl_ShapeComputeBounds(vrl_Shape *shape);
  420. void vrl_ShapeRescale(vrl_Shape *shape, float sx, float sy, float sz);
  421. void vrl_ShapeOffset(vrl_Shape *shape, vrl_Scalar tx, vrl_Scalar ty, vrl_Scalar tz);
  422. void vrl_ShapeUpdate(vrl_Shape *shape);
  423. void vrl_ShapeTransform(vrl_Matrix mat, vrl_Shape *shape);
  424. vrl_Rep *vrl_ShapeGetRep(vrl_Shape *shape, vrl_Scalar size);
  425. void vrl_ShapeAddRep(vrl_Shape *shape, vrl_Rep *rep, vrl_Scalar size);
  426. void vrl_ShapeTraverseReps(vrl_Shape *shape, int (*function)(vrl_Rep *rep));       /* NEEDED? */
  427. int vrl_ShapeCountReps(vrl_Shape *shape);
  428. vrl_Shape *vrl_ShapeGetList(void);
  429. vrl_Shape *vrl_ShapeFind(char *name);
  430. void vrl_ShapeComputeVertexNormals(vrl_Shape *shape);
  431.  
  432. #define vrl_ShapeCreate() vrl_ShapeInit(vrl_malloc(sizeof(vrl_Shape)))
  433. #define vrl_ShapeGetRadius(shape) ((shape)->radius)
  434. #define vrl_ShapeGetCenter(shape, v) vrl_VectorCopy((v), (shape)->center)
  435. #define vrl_ShapeGetMinbounds(shape, v) vrl_VectorCopy((v), (shape)->minbound)
  436. #define vrl_ShapeGetMaxbounds(shape, v) vrl_VectorCopy((v), (shape)->maxbound)
  437. #define vrl_ShapeGetSurfacemap(shape) ((shape)->default_surfacemap)
  438. #define vrl_ShapeSetSurfacemap(shape, map) ((shape)->default_surfacemap = (map))
  439. #define vrl_ShapeGetName(shape) ((shape)->name)
  440. #define vrl_ShapeSetName(shape, str) ((shape)->name = (str))
  441. #define vrl_ShapeGetNext(shape) ((shape)->next)
  442. #define vrl_ShapeGetFirstRep(shape) ((shape)->replist)
  443.  
  444. /* Representations */
  445.  
  446. typedef struct { int v1, v2; } vrl_Edge;
  447.  
  448. typedef enum
  449.         {
  450.         VRL_SORT_NONE = 0, VRL_SORT_FARTHEST, VRL_SORT_NEAREST,
  451.         VRL_SORT_AVERAGE, VRL_SORT_OTHER
  452.         } vrl_SortingType;
  453.  
  454. struct _vrl_rep
  455.     {
  456.     vrl_Scalar size;    /* size (in pixels) at which to use this rep */
  457.     vrl_Rep *next;      /* next less-detailed rep */
  458.     vrl_SortingType sorttype;  /* type of poly sorting to do on this rep */
  459.     int nvertices;      /* number of vertices (and normals if present) */
  460.     vrl_Vector *vertices;   /* array of vertices */
  461.     vrl_Vector *normals;    /* array of vertex normals; can be NULL */
  462.     vrl_Facet *facets;  /* facets are kept in a linked list */
  463.     vrl_Edge *edges;
  464.     };
  465.  
  466. vrl_Rep *vrl_RepInit(vrl_Rep *rep, int nvertices, vrl_Boolean has_normals);
  467. void vrl_RepAddFacet(vrl_Rep *rep, vrl_Facet *facet);
  468. void vrl_RepTraverseVertices(vrl_Rep *rep, int (*function)(vrl_Vector *vertex, vrl_Vector *normal));
  469. void vrl_RepTraverseFacets(vrl_Rep *rep, int (*function)(vrl_Facet *facet));
  470. vrl_Facet *vrl_RepGetFacet(vrl_Rep *rep, int n);
  471. vrl_Facet *vrl_RepFindFacet(vrl_Rep *rep, unsigned int id);
  472. int vrl_RepCountFacets(vrl_Rep *rep);
  473. void vrl_RepComputeVertexNormals(vrl_Rep *rep);
  474. void vrl_RepBuildEdges(vrl_Rep *rep);
  475.  
  476. #define vrl_RepCreate(nv, norm) vrl_RepInit(vrl_malloc(sizeof(vrl_Rep)), (nv), (norm))
  477. #define vrl_RepSetSorting(rep, type) ((rep)->sorttype = (type))
  478. #define vrl_RepGetSorting(rep) ((rep)->sorttype)
  479. #define vrl_RepGetSize(rep) ((rep)->size)
  480. #define vrl_RepCountVertices(rep) ((rep)->nvertices)
  481. #define vrl_RepGetVertex(rep, n, v) vrl_VectorCopy((v), (rep)->vertices[n])
  482. #define vrl_RepSetVertex(rep, n, v) vrl_VectorCopy((rep)->vertices[n], (v))
  483. #define vrl_RepHasNormals(rep) ((rep)->normals)
  484. #define vrl_RepGetNormal(rep, n, v) vrl_VectorCopy((v), (rep)->normals[n])
  485. #define vrl_RepGetNext(rep) ((rep)->next)
  486.  
  487. /* Facets */
  488.  
  489. struct _vrl_facet
  490.     {
  491.     int surface;            /* index into object's surface array */
  492.     vrl_Vector normal;      /* perpendicular to facet, left-hand rule */
  493.     unsigned int id;        /* identifier for this facet */
  494.     vrl_Boolean highlight : 1;      /* facet is highlighted */
  495.     vrl_Boolean interior  : 1;      /* facet is on the interior of an object (not used) */
  496.     vrl_Facet *details;     /* points to linked list of detail facets (not used) */
  497.     vrl_Facet *nearside, *farside;  /* only farside is used */
  498.     int npoints;  /* number of points in the facet */
  499.     int *points;  /* indices into array of vertices of the facet points */
  500.     int *edges;   /* indices into array edges */
  501.     };
  502.  
  503. vrl_Facet *vrl_FacetInit(vrl_Facet *facet, int npts);
  504. void vrl_FacetTraverse(vrl_Facet *facet, int (*function)(vrl_Facet *f));
  505. void vrl_FacetComputeNormal(vrl_Facet *facet, vrl_Vector *vertices);
  506.  
  507. #define vrl_FacetCreate(npts) vrl_FacetInit(vrl_malloc(sizeof(vrl_Facet)), (npts))
  508. #define vrl_FacetSetSurfnum(facet, n) ((facet)->surface = (n))
  509. #define vrl_FacetGetSurfnum(facet) ((facet)->surface)
  510. #define vrl_FacetCountPoints(facet) ((facet)->npoints)
  511. #define vrl_FacetGetPoint(facet, n) ((facet)->points[n])
  512. #define vrl_FacetGetVertex(rep, facet, n, v) vrl_VectorCopy((v), (rep)->vertices[(facet)->points[n]])
  513. #define vrl_FacetSetHighlight(facet, high) ((facet)->highlight = ((high) ? 1 : 0))
  514. #define vrl_FacetGetHighlight(facet) ((facet)->highlight)
  515. #define vrl_FacetToggleHighlight(facet) ((facet)->highlight = !(facet)->highlight)
  516. #define vrl_FacetSetInterior(facet, inter) ((facet)->interior = ((inter) ? 1 : 0))
  517. #define vrl_FacetGetInterior(facet) ((facet)->interior)
  518. #define vrl_FacetToggleInterior(facet) ((facet)->interior = !(facet)->interior)
  519. #define vrl_FacetSetId(facet, n) ((facet)->id = (n))
  520. #define vrl_FacetGetId(facet) ((facet)->id)
  521. #define vrl_FacetGetNormal(facet, v) vrl_VectorCopy((v), (facet)->normal)
  522. #define vrl_FacetSetPoint(facet, n, m) ((facet)->points[n] = (m))
  523. #define vrl_FacetGetPoint(facet, n) ((facet)->points[n])
  524.  
  525. /* Textures */
  526.  
  527. typedef void vrl_Texture;  /* for now... */
  528.  
  529. /* Surfaces */
  530.  
  531. typedef enum
  532.         {
  533.         VRL_SURF_SIMPLE = 0, VRL_SURF_FLAT, VRL_SURF_METAL,
  534.         VRL_SURF_GLASS, VRL_SURF_GOURAUD, VRL_SURF_SPECULAR
  535.         } vrl_SurfaceType;
  536.  
  537. typedef unsigned char vrl_Exponent;
  538.  
  539. struct _vrl_surface
  540.     {
  541.     vrl_SurfaceType type;
  542.     unsigned char hue;
  543.     unsigned char brightness;
  544.     vrl_Exponent exp;
  545.     vrl_Surface *next;
  546.     vrl_Texture *texture;
  547.     };
  548.  
  549. vrl_Surface *vrl_SurfaceFromDesc(vrl_unsigned16bit desc, vrl_Surface *surf);
  550. vrl_unsigned16bit vrl_SurfaceToDesc(vrl_Surface *surf);
  551. vrl_Surface *vrl_SurfaceInit(vrl_Surface *surf);
  552. vrl_Surface *vrl_SurfaceGetList(void);
  553. vrl_Surface *vrl_SurfaceCreate(unsigned char hue);
  554.  
  555. #define vrl_SurfaceSetType(surf, t) ((surf)->type = (t))
  556. #define vrl_SurfaceGetType(surf) ((surf)->type)
  557. #define vrl_SurfaceSetHue(surf, h) ((surf)->hue = (h))
  558. #define vrl_SurfaceGetHue(surf) ((surf)->hue)
  559. #define vrl_SurfaceSetBrightness(surf, b) ((surf)->brightness = (b))
  560. #define vrl_SurfaceGetBrightness(surf) ((surf)->brightness)
  561. #define vrl_SurfaceSetExponent(surf, e) ((surf)->exp = (e))
  562. #define vrl_SurfaceGetExponent(surf) ((surf)->exp)
  563. #define vrl_SurfaceSetTexture(surf, t) ((surf)->texture = (t))
  564. #define vrl_SurfaceGetTexture(surf) ((surf)->texture)
  565. #define vrl_SurfaceGetNext(surf) ((surf)->next)
  566.  
  567. struct _vrl_surface_map
  568.     {
  569.     int nentries;
  570.     vrl_Surface **entries;
  571.     vrl_Surfacemap *next;
  572.     };
  573.  
  574. vrl_Surfacemap *vrl_SurfacemapCreate(int n);
  575. vrl_Surfacemap *vrl_SurfacemapGetList(void);
  576.  
  577. #define vrl_SurfacemapCountEntries(map) ((map)->nentries)
  578. #define vrl_SurfacemapSetSurface(map, surfnum, surf) ((map)->entries[surfnum] = (surf))
  579. #define vrl_SurfacemapGetSurface(map, surfnum) ((map)->entries[surfnum])
  580. #define vrl_SurfacemapGetNext(map) ((map)->next)
  581.  
  582. /* Lights */
  583.  
  584. typedef enum
  585.     {
  586.     VRL_LIGHT_AMBIENT = 0, VRL_LIGHT_DIRECTIONAL, VRL_LIGHT_POINTSOURCE
  587.     } vrl_LightingType;
  588.  
  589. struct _vrl_light
  590.     {
  591.     vrl_LightingType type;  /* type of light source */
  592.     vrl_Boolean on : 1;     /* set if the light is on */
  593.     vrl_Factor intensity;   /* how bright the light is */
  594.     vrl_Object *object;     /* the object this light is associated with, if any */
  595.     vrl_Light *next;        /* lights are kept in a linked list */
  596.     char *name;             /* name of this light */
  597.     void *applic_data;      /* pointer to application-specific data */
  598.     int (*function)(vrl_Light *light);  /* light function */
  599.     };
  600.  
  601. vrl_Light *vrl_LightInit(vrl_Light *light);
  602. vrl_Light *vrl_LightCreate(void);
  603. void vrl_LightDestroy(vrl_Light *light);
  604.  
  605. #define vrl_LightSetType(light, ltype) ((light)->type = (ltype))
  606. #define vrl_LightGetType(light) ((light)->type)
  607. #define vrl_LightOn(light) ((light)->on = 1)
  608. #define vrl_LightOff(light) ((light)->on = 0)
  609. #define vrl_LightToggle(light) ((light)->on = !((light)->on))
  610. #define vrl_LightIsOn(light) ((light)->on)
  611. #define vrl_LightSetIntensity(light, inten) ((light)->intensity = (inten))
  612. #define vrl_LightGetIntensity(light) ((light)->intensity)
  613. #define vrl_LightAssociate(light, obj) ((light)->object = (obj))
  614. #define vrl_LightDisAssociate(light) ((light)->object = NULL)
  615. #define vrl_LightGetObject(light) ((light)->object)
  616. #define vrl_LightSetName(light, str) ((light)->name = (str))
  617. #define vrl_LightGetName(light) ((light)->name)
  618. #define vrl_LightGetNext(light) ((light)->next)
  619. #define vrl_LightSetApplicationData(light, data) ((light)->applic_data = (data))
  620. #define vrl_LightGetApplicationData(light) ((light)->applic_data)
  621.  
  622. #define vrl_LightMove(light, x, y, z) vrl_ObjectMove((light)->object, x, y, z)
  623. #define vrl_LightRelMove(light, x, y, z) vrl_ObjectRelMove((light)->object, (x), (y), (z))
  624. #define vrl_LightVectorMove(light, v) vrl_ObjectVectorMove((light)->object, (v))
  625. #define vrl_LightVectorRelMove(light, v) vrl_ObjectVectorRelMove((light)->object, (v))
  626. #define vrl_LightRotX(light, angle) vrl_ObjectRotX((light)->object, (angle))
  627. #define vrl_LightRotY(light, angle) vrl_ObjectRotY((light)->object, (angle))
  628. #define vrl_LightRotZ(light, angle) vrl_ObjectRotZ((light)->object, (angle))
  629. #define vrl_LightRotVector(light, angle, vector) vrl_ObjectRotVector((light)->object, (angle), (vector))
  630. #define vrl_LightRotReset(light) vrl_ObjectRotReset((light)->object)
  631. #define vrl_LightRotate(light, angle, axis, frame, relative_to) vrl_ObjectRotate((light)->obj, (angle), (axis), (frame), (relative_to))
  632. #define vrl_LightTranslate(light, v, axis, frame, relative_to) vrl_ObjectTranslate((light)->obj, (v), (frame), (relative_to))
  633. #define vrl_LightLookAt(light, forward, up) vrl_ObjectLookAt((light)->obj, (forward), (up))
  634. #define vrl_LightAttach(light, newparent) vrl_ObjectAttach((light)->object, (newparent))
  635. #define vrl_LightDetach(light) vrl_ObjectDetach((light)->object)
  636.  
  637. #define vrl_LightGetWorldLocation(light, v) vrl_ObjectGetWorldLocation((light)->object, (v))
  638. #define vrl_LightGetWorldRotations(light, rx, ry, rz) vrl_ObjectGetWorldRotations((light)->object, (rx), (ry), (rz))
  639. #define vrl_LightGetRelativeLocation(light, v) vrl_ObjectGetRelativeLocation((light)->object, (v))
  640. #define vrl_LightGetRelativeRotations(light, rx, ry, rz) vrl_ObjectGetRelativeRotations((light)->object, (rx), (ry), (rz))
  641.  
  642. #define vrl_LightGetWorldX(light) ((light)->object->globalmat[3][X])
  643. #define vrl_LightGetWorldY(light) ((light)->object->globalmat[3][Y])
  644. #define vrl_LightGetWorldZ(light) ((light)->object->globalmat[3][Z])
  645.  
  646. #define vrl_LightGetRelativeX(light) ((light)->object->localmat[3][X])
  647. #define vrl_LightGetRelativeY(light) ((light)->object->localmat[3][Y])
  648. #define vrl_LightGetRelativeZ(light) ((light)->object->localmat[3][Z])
  649.  
  650. /* Cameras */
  651.  
  652. struct _vrl_camera
  653.     {
  654.     vrl_Scalar hither;   /* distance to near clipping plane */
  655.     vrl_Scalar yon;      /* distance to far culling plane */
  656.     float zoom;          /* zoom factor (1/tan(FOV/2)) */
  657.     float aspect;        /* aspect ratio */
  658.     vrl_Boolean ortho : 1;    /* set if we want orthographic projection (not used) */
  659.     vrl_Scalar orthodist;     /* apparent "distance" for orthographic projection (not used) */
  660.     vrl_Object *object;       /* the object this camera is attached to */
  661.     unsigned char need_updating;  /* set when zoom or aspect is changed */
  662.     /* these next four are only used internally, for object culling */
  663.     vrl_Factor aright, cright, btop, ctop;
  664.     vrl_Camera *next;       /* cameras are kept in a linked list */
  665.     char *name;             /* name of this camera */
  666.     void *applic_data;      /* pointer to application-specific data */
  667.     };
  668.  
  669. vrl_Camera *vrl_CameraInit(vrl_Camera *camera);
  670. vrl_Camera *vrl_CameraCreate(void);
  671. void vrl_CameraDestroy(vrl_Camera *camera);
  672.  
  673. #define vrl_CameraSetZoom(camera, zf) (((camera)->zoom = (zf)), (camera)->need_updating = 1)
  674. #define vrl_CameraGetZoom(camera) ((camera)->zoom)
  675. #define vrl_CameraSetAspect(camera, asp) (((camera)->aspect = (asp)), (camera)->need_updating = 1)
  676. #define vrl_CameraGetAspect(camera) ((camera)->aspect)
  677. #define vrl_CameraSetHither(camera, h) ((camera)->hither = (h))
  678. #define vrl_CameraGetHither(camera) ((camera)->hither)
  679. #define vrl_CameraSetYon(camera, y) ((camera)->yon = (y))
  680. #define vrl_CameraGetYon(camera) ((camera)->yon)
  681. #define vrl_CameraAssociate(camera, obj) ((camera)->object = (obj))
  682. #define vrl_CameraGetObject(camera) ((camera)->object)
  683. #define vrl_CameraSetName(camera, str) ((camera)->name = (str))
  684. #define vrl_CameraGetName(camera) ((camera)->name)
  685. #define vrl_CameraGetNext(camera) ((camera)->next)
  686. #define vrl_CameraSetApplicationData(cam, data) ((cam)->applic_data = (data))
  687. #define vrl_CameraGetApplicationData(cam) ((cam)->applic_data)
  688.  
  689. #define vrl_CameraMove(camera, x, y, z) vrl_ObjectMove((camera)->object, x, y, z)
  690. #define vrl_CameraRelMove(camera, x, y, z) vrl_ObjectRelMove((camera)->object, (x), (y), (z))
  691. #define vrl_CameraVectorMove(camera, v) vrl_ObjectVectorMove((camera)->object, (v))
  692. #define vrl_CameraVectorRelMove(camera, v) vrl_ObjectVectorRelMove((camera)->object, (v))
  693. #define vrl_CameraRotX(camera, angle) vrl_ObjectRotX((camera)->object, (angle))
  694. #define vrl_CameraRotY(camera, angle) vrl_ObjectRotY((camera)->object, (angle))
  695. #define vrl_CameraRotZ(camera, angle) vrl_ObjectRotZ((camera)->object, (angle))
  696. #define vrl_CameraRotVector(camera, angle, vector) vrl_ObjectRotVector((camera)->object, (angle), (vector))
  697. #define vrl_CameraRotReset(camera) vrl_ObjectRotReset((camera)->object)
  698. #define vrl_CameraRotate(camera, angle, axis, frame, relative_to) vrl_ObjectRotate((camera)->object, (angle), (axis), (frame), (relative_to))
  699. #define vrl_CameraTranslate(camera, v, axis, frame, relative_to) vrl_ObjectTranslate((camera)->object, (v), (frame), (relative_to))
  700. #define vrl_CameraLookAt(camera, forward, up) vrl_ObjectLookAt((camera)->object, (forward), (up))
  701. #define vrl_CameraAttach(camera, newparent) vrl_ObjectAttach((camera)->object, (newparent))
  702. #define vrl_CameraDetach(camera) vrl_ObjectDetach((camera)->object)
  703.  
  704. #define vrl_CameraGetWorldX(camera) ((camera)->object->globalmat[3][X])
  705. #define vrl_CameraGetWorldY(camera) ((camera)->object->globalmat[3][Y])
  706. #define vrl_CameraGetWorldZ(camera) ((camera)->object->globalmat[3][Z])
  707.  
  708. #define vrl_CameraGetRelativeX(camera) ((camera)->object->localmat[3][X])
  709. #define vrl_CameraGetRelativeY(camera) ((camera)->object->localmat[3][Y])
  710. #define vrl_CameraGetRelativeZ(camera) ((camera)->object->localmat[3][Z])
  711.  
  712. #define vrl_CameraGetWorldLocation(camera, v) vrl_ObjectGetWorldLocation((camera)->object, (v))
  713. #define vrl_CameraGetWorldRotations(camera, rx, ry, rz) vrl_ObjectGetWorldRotations((camera)->object, (rx), (ry), (rz))
  714. #define vrl_CameraGetRelativeLocation(camera, v) vrl_ObjectGetRelativeLocation((camera)->object, (v))
  715. #define vrl_CameraGetRelativeRotations(camera, rx, ry, rz) vrl_ObjectGetRelativeRotations((camera)->object, (rx), (ry), (rz))
  716.  
  717. #define vrl_CameraGetForwardVector(camera, v) vrl_ObjectGetForwardVector((camera)->object, (v))
  718. #define vrl_CameraGetRightVector(camera, v) vrl_ObjectGetRightVector((camera)->object, (v))
  719. #define vrl_CameraGetUpVector(camera, v) vrl_ObjectGetUpVector((camera)->object, (v))
  720.  
  721. /* Memory allocation functions */
  722.  
  723. void *vrl_malloc(unsigned int nbytes);
  724. void *vrl_calloc(unsigned int nitems, unsigned int item_size);
  725. void vrl_free(void *ptr);
  726.  
  727. /* Rendering functions */
  728.  
  729. typedef struct
  730.     {
  731.     vrl_Boolean memory : 1;       /* set if the renderer ran out of memory */
  732.     vrl_Boolean objects : 1;      /* set if there were too many objects  */
  733.     vrl_Boolean facets : 1;       /* set if there were too many facets   */
  734.     } vrl_RenderStatus;
  735.  
  736. vrl_Boolean vrl_RenderInit(int maxvert, int maxf, int maxobjs, int maxlights, unsigned int mempoolsize);
  737. void vrl_RenderQuit(void);
  738. void vrl_RenderBegin(vrl_Camera *camera, vrl_Light *lights);
  739. void vrl_RenderSetAmbient(vrl_Factor amb);
  740. void vrl_RenderHorizon(void);
  741. vrl_RenderStatus *vrl_RenderObjlist(vrl_Object *objects);
  742. void vrl_RenderSetHorizontalShift(int n);
  743. void vrl_RenderSetDrawMode(int mode);
  744. int vrl_RenderGetDrawMode(void);
  745. void vrl_RenderSetWireframeColor(vrl_Color color);
  746. vrl_Color vrl_RenderGetWireframeColor(void);
  747. void vrl_RenderSetHighlightColor(vrl_Color color);
  748. vrl_Color vrl_RenderGetHighlightColor(void);
  749.  
  750. void vrl_RenderMonitorInit(int x, int y);  /* monitor the specified point */
  751. vrl_Boolean vrl_RenderMonitorRead(vrl_Object **obj, vrl_Facet **facet, int *vertnum);  /* returns zero if none */
  752.  
  753. void vrl_TransformVertexToScreen(vrl_ScreenCoord *x, vrl_ScreenCoord *y, vrl_Object *obj, vrl_Vector vertex);
  754.  
  755. /* Layer support */
  756.  
  757. void vrl_LayerOn(int n);
  758. void vrl_LayerOff(int n);
  759. void vrl_LayerToggle(int n);
  760. vrl_Boolean vrl_LayerIsOn(int n);
  761. void vrl_LayerAllOn(void);
  762. void vrl_LayerAllOff(void);
  763.  
  764. /* File i/o routines */
  765.  
  766. void vrl_FileSetLoadpath(char *path);
  767. char *vrl_FileFixupFilename(char *fname);
  768. vrl_Shape *vrl_ReadPLG(FILE *in);
  769. int vrl_WritePLG(vrl_Shape *shape, FILE *out);
  770. void vrl_SetReadPLGscale(float x, float y, float z);
  771. void vrl_SetReadPLGoffset(float x, float y, float z);
  772. int vrl_ReadWLD(FILE *in);
  773. void vrl_ReadWLDfeature(int argc, char *argv[], char *rawtext);
  774. vrl_Object *vrl_ReadFIG(FILE *in, vrl_Object *parent, char *rootname);
  775. void vrl_SetReadFIGpartArray(vrl_Object **ptr, int maxparts);
  776. void vrl_SetReadFIGscale(float x, float y, float z);
  777. vrl_Object *vrl_ReadObjectPLG(FILE *in);
  778.  
  779. vrl_Object *vrl_ObjectLoadPLGfile(char *filename);
  780. vrl_Object *vrl_ObjectLoadFIGfile(char *filename);
  781. int vrl_LoadWLDfile(char *filename);
  782. int vrl_ObjectSavePLGfile(vrl_Object *object, char *filename);
  783.  
  784. /* Raster support */
  785.  
  786. typedef struct
  787.     {
  788.     vrl_ScreenPos width, height, depth;
  789.     vrl_ScreenPos left, top, right, bottom;
  790.     vrl_ScreenPos rowbytes;
  791. #ifdef __BORLANDC__
  792.     unsigned char far *data;
  793. #else
  794.     unsigned char *data;
  795. #endif
  796.     } vrl_Raster;
  797.  
  798. vrl_Raster *vrl_RasterCreate(vrl_ScreenPos width, vrl_ScreenPos height, vrl_unsigned16bit depth);
  799. void vrl_RasterDestroy(vrl_Raster *raster);
  800. void vrl_RasterSetWindow(vrl_Raster *raster, vrl_ScreenPos left, vrl_ScreenPos top, vrl_ScreenPos right, vrl_ScreenPos bottom);
  801. void vrl_RasterGetWindow(vrl_Raster *raster, vrl_ScreenPos *left, vrl_ScreenPos *top, vrl_ScreenPos *right, vrl_ScreenPos *bottom);
  802.  
  803. #define vrl_RasterGetHeight(r) ((r)->height)
  804. #define vrl_RasterGetWidth(r) ((r)->width)
  805. #define vrl_RasterGetDepth(r) ((r)->depth)
  806. #define vrl_RasterGetRowbytes(r) ((r)->rowbytes)
  807. #define vrl_RasterSetRowbytes(r, n) ((r)->rowbytes = (n))
  808. #define vrl_RasterReadScanline(r, n, buff) memcpy((buff), &(r)->data[(n)*(r)->rowbytes], (r)->rowbytes)
  809. #define vrl_RasterWriteScanline(r, n, buff) memcpy(&(r)->data[(n)*(r)->rowbytes], (buff), (r)->rowbytes)
  810. #define vrl_RasterGetData(r) ((r)->data)
  811.  
  812. /* Display routines */
  813.  
  814. typedef struct _vrl_outvertex vrl_OutputVertex;
  815.  
  816. struct _vrl_outvertex
  817.     {
  818.     vrl_ScreenCoord x,y,z;            /* X, Y screen coordinates and Z-depth */
  819.     vrl_16bit red, green, blue;       /* components of the color */
  820.     vrl_OutputVertex *next, *prev;    /* doubly-linked circular list */
  821.     /* don't rely on anything below here staying the same */
  822.     vrl_unsigned16bit u, v;           /* texture map coordinates */
  823.     vrl_Factor intensity;             /* intensity of light at this vertex */
  824.     vrl_unsigned16bit outcode;        /* used for XY clipping */
  825.     /* future versions of AVRIL may have additional info per vertex */
  826.     };
  827.  
  828. typedef struct _vrl_outfacet vrl_OutputFacet;
  829.  
  830. struct _vrl_outfacet
  831.     {
  832.     vrl_OutputVertex *points;     /* linked list of vertices for this facet */
  833.     vrl_Surface *surface;         /* surface properties */
  834.     vrl_Color color;              /* color of this facet (flat shading only) */
  835.     /* don't rely on anything below here staying the same */
  836.     vrl_Factor intensity;         /* amount of light falling on this facet */
  837.     int xclip;                    /* this facet needs X clipping */
  838.     int yclip;                    /* this facet needs Y clipping */
  839.     int highlight : 1;            /* this facet is highlighted */
  840.     vrl_Facet *original;          /* points back at the facet we came from */
  841.     void *outobj;                 /* points back at the outobject we belong to */
  842.     vrl_ScreenCoord minbound[3], maxbound[3];  /* bounding box for smarter sorting */
  843.     vrl_OutputFacet *details;     /* linked list of detail facets */
  844.     vrl_OutputFacet *next;        /* only used to link detail facets */
  845.     /* future versions of AVRIL may have additional info per facet */
  846.     };
  847.  
  848. typedef enum
  849.         {
  850.         VRL_DISPLAY_GET_VERSION = 0, VRL_DISPLAY_GET_DESCRIPTION,
  851.         VRL_DISPLAY_INIT, VRL_DISPLAY_QUIT,
  852.         VRL_DISPLAY_CLEAR, VRL_DISPLAY_POINT, VRL_DISPLAY_LINE,
  853.         VRL_DISPLAY_CLOSED_LINE, VRL_DISPLAY_POLY, VRL_DISPLAY_BOX,
  854.         VRL_DISPLAY_TEXT, VRL_DISPLAY_TEXT_POSITION,
  855.         VRL_DISPLAY_GET_TEXTWIDTH, VRL_DISPLAY_GET_TEXTHEIGHT,
  856.         VRL_DISPLAY_GET_SORTORDER, VRL_DISPLAY_CAN_GOURAUD,
  857.         VRL_DISPLAY_UPDATE_PALETTE, VRL_DISPLAY_CAN_XY_CLIP,
  858.         VRL_DISPLAY_BEGIN_FRAME, VRL_DISPLAY_END_FRAME,
  859.         VRL_DISPLAY_SET_RASTER, VRL_DISPLAY_GET_RASTER,
  860.         VRL_DISPLAY_SET_Z_BUFFER, VRL_DISPLAY_GET_Z_BUFFER,
  861.         VRL_DISPLAY_USE_Z_BUFFER, VRL_DISPLAY_CLEAR_Z_BUFFER,
  862.         VRL_DISPLAY_SET_SHADING,
  863.         } vrl_DisplayCommand;
  864.  
  865. typedef vrl_32bit vrl_DisplayDriverFunction(vrl_DisplayCommand cmd, vrl_32bit lparm, void *pparm1);
  866. extern vrl_DisplayDriverFunction *vrl_current_display_driver;
  867. #define vrl_DisplaySetDriver(driver) (vrl_current_display_driver = (driver))
  868.  
  869. int vrl_DisplayInit(vrl_Raster *raster);
  870. void vrl_DisplayQuit(void);
  871. void vrl_DisplayClear(vrl_Color color);
  872. void vrl_DisplayPoint(vrl_ScreenPos x, vrl_ScreenPos y, vrl_Color color);
  873. void vrl_DisplayLine(vrl_ScreenPos x1, vrl_ScreenPos y1, vrl_ScreenPos x2, vrl_ScreenPos y2, vrl_Color color);
  874. void vrl_DisplayBox(vrl_ScreenPos x1, vrl_ScreenPos y1, vrl_ScreenPos x2, vrl_ScreenPos y2, vrl_Color color);
  875. void vrl_DisplayText(vrl_ScreenPos x, vrl_ScreenPos y, vrl_Color color, char *message);
  876.  
  877. #define vrl_DisplayGetTextWidth(string) (*vrl_current_display_driver)(VRL_DISPLAY_GET_TEXTWIDTH, 0, string)
  878. #define vrl_DisplayGetTextHeight(string) (*vrl_current_display_driver)(VRL_DISPLAY_GET_TEXTHEIGHT, 0, string)
  879. #define vrl_DisplayGetSortOrder() (*vrl_current_display_driver)(VRL_DISPLAY_GET_SORTORDER, 0, NULL)
  880. #define vrl_DisplayCanGouraud() (*vrl_current_display_driver)(VRL_DISPLAY_CAN_GOURAUD, 0, NULL)
  881. #define vrl_DisplayCanXYclip() (*vrl_current_display_driver)(VRL_DISPLAY_CAN_XY_CLIP, 0, NULL)
  882. #define vrl_DisplayGetVersion() (*vrl_current_display_driver)(VRL_DISPLAY_GET_VERSION, 0, NULL)
  883. char *vrl_DisplayGetDescription(void);
  884. #define vrl_DisplayBeginFrame() (*vrl_current_display_driver)(VRL_DISPLAY_BEGIN_FRAME, 0, NULL)
  885. #define vrl_DisplayEndFrame() (*vrl_current_display_driver)(VRL_DISPLAY_END_FRAME, 0, NULL)
  886. #define vrl_DisplaySetRaster(r) (*vrl_current_display_driver)(VRL_DISPLAY_SET_RASTER, 0, (r))
  887. vrl_Raster *vrl_DisplayGetRaster(void);
  888. #define vrl_DisplaySetZbuffer(r) (*vrl_current_display_driver)(VRL_DISPLAY_SET_Z_BUFFER, 0, (r))
  889. #define vrl_DisplayGetZbuffer() (*vrl_current_display_driver)(VRL_DISPLAY_GET_Z_BUFFER, 0, NULL)
  890. #define vrl_DisplayClearZbuffer(depth) (*vrl_current_display_driver)(VRL_DISPLAY_CLEAR_Z_BUFFER, depth, NULL)
  891. #define vrl_DisplayUseZbuffer(flag) (*vrl_current_display_driver)(VRL_DISPLAY_USE_Z_BUFFER, flag, NULL)
  892. #define vrl_DisplayUpdatePalette(palette) (*vrl_current_display_driver)(VRL_DISPLAY_UPDATE_PALETTE, 0, palette)
  893. #define vrl_DisplaySetShading(value) (*vrl_current_display_driver)(VRL_DISPLAY_SET_SHADING, (value), NULL)
  894.  
  895. vrl_Color vrl_DisplayComputeColor(vrl_Surface *surf, vrl_Factor intensity, vrl_Factor ambient, vrl_Scalar depth);
  896. void vrl_DisplayComputeVertexColor(vrl_OutputVertex *v, vrl_Surface *surf, vrl_Factor intensity, vrl_Factor ambient, vrl_Scalar depth);
  897.  
  898. void vrl_DisplaySetWindow(vrl_ScreenPos x1, vrl_ScreenPos y1, vrl_ScreenPos x2, vrl_ScreenPos y2);
  899. void vrl_DisplayGetWindow(vrl_ScreenPos *x1, vrl_ScreenPos *y1, vrl_ScreenPos *x2, vrl_ScreenPos *y2);
  900.  
  901. #define vrl_DisplayGetWidth() vrl_RasterGetWidth(vrl_DisplayGetRaster())
  902. #define vrl_DisplayGetHeight() vrl_RasterGetHeight(vrl_DisplayGetRaster())
  903. #define vrl_DisplayGetDepth() vrl_RasterGetDepth(vrl_DisplayGetRaster())
  904. #define vrl_DisplayUpdate() vrl_VideoBlit(vrl_DisplayGetRaster())
  905.  
  906. /* Video support */
  907.  
  908. typedef enum
  909.         {
  910.         VRL_VIDEO_GET_VERSION = 0, VRL_VIDEO_GET_DESCRIPTION,
  911.         VRL_VIDEO_SETUP, VRL_VIDEO_SHUTDOWN, VRL_VIDEO_GET_MODE,
  912.         VRL_VIDEO_SET_DRAW_PAGE, VRL_VIDEO_SET_VIEW_PAGE, VRL_VIDEO_GET_NPAGES,
  913.         VRL_VIDEO_HAS_PALETTE, VRL_VIDEO_SET_PALETTE,
  914.         VRL_VIDEO_SET_NTSC, VRL_VIDEO_CHECK_RETRACE,
  915.         VRL_VIDEO_GET_RASTER, VRL_VIDEO_BLIT,
  916.         VRL_VIDEO_CURSOR_HIDE, VRL_VIDEO_CURSOR_SHOW, VRL_VIDEO_CURSOR_RESET,
  917.         VRL_VIDEO_CURSOR_MOVE, VRL_VIDEO_CURSOR_SET_APPEARANCE
  918.         } vrl_VideoCommand;
  919.  
  920. typedef vrl_32bit vrl_VideoDriverFunction(vrl_VideoCommand cmd, vrl_32bit lparm, void *pparm1);
  921. extern vrl_VideoDriverFunction *vrl_current_video_driver;
  922. #define vrl_VideoSetDriver(driver) (vrl_current_video_driver = (driver))
  923.  
  924. #define vrl_VideoSetup(mode) (*vrl_current_video_driver)(VRL_VIDEO_SETUP, (mode), NULL)
  925. void vrl_VideoShutdown(void);
  926. #define vrl_VideoGetMode() (*vrl_current_video_driver)(VRL_VIDEO_GET_MODE, 0, NULL)
  927. void vrl_VideoSetDrawPage(int page);
  928. int vrl_VideoGetDrawPage(void);
  929. void vrl_VideoSetViewPage(int page);
  930. int vrl_VideoGetViewPage(void);
  931. int vrl_VideoGetNpages(void);
  932. #define vrl_VideoHasPalette() (*vrl_current_video_driver)(VRL_VIDEO_HAS_PALETTE, 0, NULL)
  933. void vrl_VideoSetPalette(int start, int end, vrl_Palette *palette);  /* updates the palette */
  934. void vrl_VideoGetPalette(int start, int end, vrl_Palette *palette);
  935. #define vrl_VideoSetNTSC(flag) (*vrl_current_video_driver)(VRL_VIDEO_SET_NTSC, flag, NULL)
  936. #define vrl_VideoCheckRetrace() (*vrl_current_video_driver)(VRL_VIDEO_CHECK_RETRACE, 0, NULL)
  937. vrl_Raster *vrl_VideoGetRaster(void);
  938. #define vrl_VideoBlit(buffer)  (*vrl_current_video_driver)(VRL_VIDEO_BLIT, 0, (buffer))
  939. #define vrl_VideoGetVersion() (*vrl_current_video_driver)(VRL_VIDEO_GET_VERSION, 0, NULL)
  940. char *vrl_VideoGetDescription(void);
  941. #define vrl_VideoCursorHide() (*vrl_current_video_driver)(VRL_VIDEO_CURSOR_HIDE, 0, NULL)
  942. #define vrl_VideoCursorShow() (*vrl_current_video_driver)(VRL_VIDEO_CURSOR_SHOW, 0, NULL)
  943. #define vrl_VideoCursorReset() (*vrl_current_video_driver)(VRL_VIDEO_CURSOR_RESET, 0, NULL)
  944. #define vrl_VideoCursorMove(x, y) (*vrl_current_video_driver)(VRL_VIDEO_CURSOR_MOVE, (((long) (x)) << 16) | (((long) (y)) & 0xFFFF), NULL)
  945. #define vrl_VideoCursorSetAppearance(app) (*vrl_current_video_driver)(VRL_VIDEO_CURSOR_SET_APPEARANCE, app)
  946.  
  947. /* Stereoscopic viewing support */
  948.  
  949. typedef enum
  950.     {
  951.     VRL_STEREOEYE_NEITHER = 0,
  952.     VRL_STEREOEYE_LEFT,
  953.     VRL_STEREOEYE_RIGHT,
  954.     VRL_STEREOEYE_BOTH
  955.     } VRL_STEREO_EYE;
  956.  
  957. typedef enum
  958.     {
  959.     VRL_STEREOTYPE_NONE = 0, VRL_STEREOTYPE_SEQUENTIAL,
  960.     VRL_STEREOTYPE_ANAGLYPH_SEQUENTIAL, VRL_STEREOTYPE_ANAGLYPH_WIRE_ALTERNATE,
  961.     VRL_STEREOTYPE_ENIGMA, VRL_STEREOTYPE_FRESNEL,
  962.     VRL_STEREOTYPE_CYBERSCOPE, VRL_STEREOTYPE_CRYSTALEYES,
  963.     VRL_STEREOTYPE_CHROMADEPTH, VRL_STEREOTYPE_SIRDS,
  964.     VRL_STEREOTYPE_TWOCARDS, VRL_STEREOTYPE_ANAGLYPH_SOLID_ALTERNATE
  965.     } VRL_STEREO_TYPE;
  966.  
  967. void vrl_DisplayStereoSetType(VRL_STEREO_TYPE stype);
  968. VRL_STEREO_TYPE vrl_DisplayStereoGetType(void);
  969.  
  970. void vrl_DisplayStereoSetDrawEye(VRL_STEREO_EYE eye);
  971. VRL_STEREO_EYE vrl_DisplayStereoGetDrawEye(void);
  972.  
  973. void vrl_DisplayStereoSetViewEye(VRL_STEREO_EYE eye);
  974. VRL_STEREO_EYE vrl_DisplayStereoGetViewEye(void);
  975.  
  976. void vrl_DisplayStereoSetLeftWindow(vrl_ScreenPos x1, vrl_ScreenPos y1, vrl_ScreenPos x2, vrl_ScreenPos y2);
  977. void vrl_DisplayStereoSetRightWindow(vrl_ScreenPos x1, vrl_ScreenPos y1, vrl_ScreenPos x2, vrl_ScreenPos y2);
  978.  
  979. void vrl_DisplayStereoSetCardFunction(void (*function)(VRL_STEREO_EYE));
  980.  
  981. struct _vrl_stereo_conf      /* stores details about the stereo configuration */
  982.     {
  983.     VRL_STEREO_TYPE type;                  /* type of stereo viewing system */ 
  984.     float eyespacing;                      /* eye spacing in millimeters */
  985.     float convergence;                     /* convergence distance in millimeters */
  986.     vrl_Angle leftrot, rightrot;           /* amount by which each eye is rotated around Y */
  987.     int left_eye_shift, right_eye_shift;   /* extra offset due to lateral screen displacement */
  988.     int center_offset;                     /* offset to center of image for each eye */
  989.     int two_eyes;                          /* two eyes used */
  990.     vrl_Scalar chromanear, chromafar;      /* bounds for Chromadepth */
  991.     };
  992.  
  993. int vrl_StereoSetup(void);   /* creates a pair of cameras */
  994. int vrl_StereoConfigure(vrl_StereoConfiguration *conf);
  995. vrl_StereoConfiguration *vrl_StereoInitConfiguration(vrl_StereoConfiguration *conf);
  996.  
  997. #define vrl_StereoCreateConfiguration() vrl_StereoInitConfiguration(vrl_malloc(sizeof(vrl_StereoConfiguration)))
  998.  
  999. #define vrl_StereoSetType(conf, st_type) ((conf)->type = (st_type))
  1000. #define vrl_StereoGetType(conf) ((conf)->type)
  1001.  
  1002. #define vrl_StereoGetNeyes(conf) ((conf)->two_eyes)
  1003.  
  1004. #define vrl_StereoSetLeftEyeShift(conf, shift) ((conf)->left_eye_shift = (shift))
  1005. #define vrl_StereoGetLeftEyeShift(conf) ((conf)->left_eye_shift)
  1006. #define vrl_StereoSetRightEyeShift(conf, shift) ((conf)->right_eye_shift = (shift))
  1007. #define vrl_StereoGetRightEyeShift(conf) ((conf)->right_eye_shift)
  1008.  
  1009. #define vrl_StereoSetLeftEyeRotation(conf, rot) ((conf)->leftrot = (rot))
  1010. #define vrl_StereoGetLeftEyeRotation(conf) ((conf)->leftrot)
  1011. #define vrl_StereoSetRightEyeRotation(conf, rot) ((conf)->rightrot = (rot))
  1012. #define vrl_StereoGetRightEyeRotation(conf) ((conf)->rightrot)
  1013.  
  1014. #define vrl_StereoSetEyespacing(conf, spacing) ((conf)->eyespacing = (spacing))
  1015. #define vrl_StereoGetEyespacing(conf) ((conf)->eyespacing)
  1016.  
  1017. #define vrl_StereoSetConvergence(conf, conv) ((conf)->convergence = (conv))
  1018. #define vrl_StereoGetConvergence(conf) ((conf)->convergence)
  1019.  
  1020. #define vrl_StereoGetTotalLeftShift(conf) (-((conf)->center_offset + (conf)->left_eye_shift))
  1021. #define vrl_StereoGetTotalRightShift(conf) ((conf)->center_offset + (conf)->right_eye_shift)
  1022.  
  1023. #define vrl_StereoSetChromaNear(conf, val) ((conf)->chromanear = (val))
  1024. #define vrl_StereoGetChromaNear(conf) ((conf)->chromanear)
  1025.  
  1026. #define vrl_StereoSetChromaFar(conf, val) ((conf)->chromafar = (val))
  1027. #define vrl_StereoGetChromaFar(conf) ((conf)->chromafar)
  1028.  
  1029. /* Retrace handling */
  1030.  
  1031. void vrl_SetRetraceHandler(void (*function)(void));
  1032.  
  1033. /* XY clipping */
  1034.  
  1035. void vrl_DisplaySetXYclip(vrl_ScreenPos left, vrl_ScreenPos right, vrl_ScreenPos top, vrl_ScreenPos bottom);
  1036.  
  1037. vrl_OutputVertex *vrl_DisplayXYclipPoint(vrl_OutputVertex *vertices, unsigned int flags);
  1038. vrl_OutputVertex *vrl_DisplayXYclipLine(vrl_OutputVertex *vertices, unsigned int flags);
  1039. vrl_OutputVertex *vrl_DisplayXYclipPoly(vrl_OutputVertex *vertices, unsigned int flags);
  1040.  
  1041. #define VRL_DISPLAY_XYCLIP_CLIP_X     0x01
  1042. #define VRL_DISPLAY_XYCLIP_CLIP_Y     0x02
  1043. #define VRL_DISPLAY_XYCLIP_Z          0x04
  1044. #define VRL_DISPLAY_XYCLIP_INTENSITY  0x08
  1045.  
  1046. /* Timer routines */
  1047.  
  1048. vrl_Boolean vrl_TimerInit(void);
  1049. void vrl_TimerQuit(void);
  1050. vrl_Time vrl_TimerRead(void);
  1051. void vrl_TimerDelay(vrl_Time time);
  1052. #define vrl_TimerGetTickRate() (1000)
  1053.  
  1054. /* Mouse routines */
  1055.  
  1056. vrl_Boolean vrl_MouseInit(void);
  1057. void vrl_MouseQuit(void);
  1058. vrl_Boolean vrl_MouseReset(void);
  1059. vrl_Boolean vrl_MouseRead(int *x, int *y, unsigned int *buttons);
  1060. void vrl_MouseSetUsage(int u);
  1061. int vrl_MouseGetUsage(void);
  1062. void vrl_MouseSetPointer(void *u);
  1063. void *vrl_MouseGetPointer(void);
  1064.  
  1065. /* Keyboard routines */
  1066.  
  1067. vrl_Boolean vrl_KeyboardCheck(void);
  1068. unsigned int vrl_KeyboardRead(void);
  1069.  
  1070. /* System routines */
  1071.  
  1072. vrl_Boolean vrl_SystemStartup(void);
  1073. void vrl_SystemRun(void);
  1074. vrl_RenderStatus *vrl_SystemRender(vrl_Object *list);
  1075. vrl_Time vrl_SystemGetRenderTime(void);
  1076. vrl_Time vrl_SystemGetFrameRate(void);
  1077. void vrl_SystemCommandLine(int argc, char *argv[]);
  1078.  
  1079. void vrl_SystemRequestRefresh(void);
  1080. vrl_Boolean vrl_SystemQueryRefresh(void);
  1081.  
  1082. void vrl_SystemStartRunning(void);
  1083. void vrl_SystemStopRunning(void);
  1084. vrl_Boolean vrl_SystemIsRunning(void);
  1085.  
  1086. /* Routines defined by application */
  1087.  
  1088. void vrl_ApplicationDrawUnder(void);
  1089. void vrl_ApplicationDrawOver(vrl_RenderStatus *stat);
  1090. void vrl_ApplicationInit(void);
  1091. void vrl_ApplicationKey(unsigned int c);
  1092. void vrl_ApplicationMouseUp(int x, int y, unsigned int buttons);
  1093.  
  1094. /* User interface routines */
  1095.  
  1096. void vrl_UserInterfaceBox(int w, int h, int *x, int *y);
  1097. void vrl_UserInterfacePopText(char *text[]);
  1098. void vrl_UserInterfacePopMsg(char *msg);
  1099. int vrl_UserInterfacePopMenu(char *text[]);
  1100. int vrl_UserInterfaceMenuDispatch(char *text[], int (**funcs)(void));
  1101. unsigned vrl_UserInterfacePopPrompt(char *prompt, char *buff, int n);
  1102. int vrl_UserInterfaceDismiss(void);
  1103.  
  1104. void vrl_UserInterfaceDrawCompass(vrl_Camera *camera, int compass_x, int compass_y, int compass_armlen);
  1105. void vrl_UserInterfaceDropText(int x, int y, vrl_Color color, char *text);
  1106.  
  1107. /* Pseudo-tasking routines */
  1108.  
  1109. vrl_Boolean vrl_TaskCreate(void (*function)(void), void *data, vrl_Time period);
  1110. void vrl_TaskRun(void);
  1111. void *vrl_TaskGetData(void);
  1112. vrl_Time vrl_TaskGetElapsed(void);
  1113. vrl_Time vrl_TaskGetTimeNow(void);
  1114.  
  1115. /* Routines for creating primitive shapes */
  1116.  
  1117. vrl_Shape *vrl_PrimitiveBox(vrl_Scalar width, vrl_Scalar height, vrl_Scalar depth, vrl_Surfacemap *map);
  1118. vrl_Shape *vrl_PrimitiveCone(vrl_Scalar radius, vrl_Scalar height, int nsides, vrl_Surfacemap *map);
  1119. vrl_Shape *vrl_PrimitiveCylinder(vrl_Scalar bottom_radius, vrl_Scalar top_radius, vrl_Scalar height, int nsides, vrl_Surfacemap *map);
  1120. vrl_Shape *vrl_PrimitivePrism(vrl_Scalar width, vrl_Scalar height, vrl_Scalar depth, vrl_Surfacemap *map);
  1121. vrl_Shape *vrl_PrimitiveSphere(vrl_Scalar radius, int vsides, int hsides, vrl_Surfacemap *map);
  1122.  
  1123. /* Device support */
  1124.  
  1125. typedef enum
  1126.         {
  1127.         VRL_DEVICE_INIT = 0, VRL_DEVICE_QUIT, VRL_DEVICE_POLL,
  1128.         VRL_DEVICE_RESET, VRL_DEVICE_SET_RANGE
  1129.         } vrl_DeviceCommand;
  1130.  
  1131. typedef int vrl_DeviceDriverFunction(vrl_DeviceCommand cmd, vrl_Device *device);
  1132. typedef int vrl_DeviceOutputFunction(vrl_Device *device, int parm1, vrl_Scalar parm2);
  1133.  
  1134. typedef enum
  1135.     {
  1136.     VRL_MOTION_NONE = 0, VRL_MOTION_RELATIVE, VRL_MOTION_ABSOLUTE
  1137.     } vrl_DeviceMotionMode;
  1138.  
  1139. typedef int vrl_Buttonmap[][2];
  1140.  
  1141. /* In the following struct, fields marked with a (^) can be set by the
  1142.    device function; not all of them need to be, since reasonable defaults
  1143.    are already set for each.  Fields marked with a (^^) must be set for
  1144.    every device. */
  1145.  
  1146. struct _vrl_device
  1147.     {
  1148.     char *nickname;             /* name used by application for this device */
  1149.     int version;                /* device struct version number (^) */
  1150.     char *desc;                 /* user-readable device description (^^) */
  1151.     vrl_DeviceDriverFunction *fn;   /* the driver function itself */
  1152.     vrl_SerialPort *port;       /* pointer to serial port */
  1153.     vrl_DeviceMotionMode rotation_mode;     /* rotation mode for this device (^) */
  1154.     vrl_DeviceMotionMode translation_mode;  /* translation mode for this device (^) */
  1155.     int mode;                   /* mode of operation (^) */
  1156.     vrl_Time period;            /* milliseconds between reads (^) */
  1157.     vrl_Time lastread;          /* timer value when we last read */
  1158.     int nbuttons;               /* number of buttons the device has (^) */
  1159.     vrl_unsigned32bit buttons;      /* current button status */
  1160.     vrl_unsigned32bit bchanged;     /* which buttons have changed state */
  1161.     vrl_Buttonmap *buttonmap;   /* button mapping table for 2D devices */
  1162.     int noutput_channels;       /* number of output channels (^) */
  1163.     vrl_DeviceOutputFunction *outfunc;  /* function to call to generate output (^) */
  1164.     int nchannels;              /* number of input channels the device has (^^) */
  1165.     vrl_DeviceChannel *channels;   /* pointer to array of channels (^^) */
  1166.     void *localdata;            /* data used only by the driver (^) */
  1167.     vrl_Device *next;           /* devices are kept in a linked list */
  1168.     };
  1169.  
  1170. vrl_Device *vrl_DeviceOpen(vrl_DeviceDriverFunction fn, vrl_SerialPort *port);
  1171. void vrl_DeviceClose(vrl_Device *device);
  1172. int vrl_DevicePoll(vrl_Device *device);
  1173. int vrl_DeviceReset(vrl_Device *device);
  1174. int vrl_DeviceSetRange(vrl_Device *device);
  1175. int vrl_DevicePollAll(void);
  1176. void vrl_DeviceCloseAll(void);
  1177. void vrl_DeviceOutput(vrl_Device *device, int channel, vrl_Scalar value);
  1178. vrl_Device *vrl_DeviceGetFirst(void);
  1179. vrl_Device *vrl_DeviceFind(char *nickname);
  1180.  
  1181. #define vrl_DeviceGetNickname(device) ((device)->nickname)
  1182. #define vrl_DeviceSetNickname(device, name) ((device)->nickname = (name))
  1183. #define vrl_DeviceGetNext(dev) ((dev)->next)
  1184. #define vrl_DeviceGetDesc(device) ((device)->desc)
  1185. #define vrl_DeviceSetPeriod(device, per) ((device)->period = (per))
  1186. #define vrl_DeviceGetPeriod(device) ((device)->period)
  1187. #define vrl_DeviceGetMode(device) ((device)->mode)
  1188. #define vrl_DeviceSetMode(device, m) ((device)->mode = (m))
  1189. #define vrl_DeviceGetPort(device) ((device)->port)
  1190. #define vrl_DeviceGetNchannels(device) ((device)->nchannels)
  1191. #define vrl_DeviceGetNButtons(device) ((device)->nbuttons)
  1192. #define vrl_DeviceGetButtons(device) ((device)->buttons)
  1193. #define vrl_DeviceGetChangedButtons(device) ((device)->bchanged)
  1194. #define vrl_DeviceGetNOutputChannels(device) ((device)->noutput_channels)
  1195. #define vrl_DeviceGetRotationMode(device) ((device)->rotation_mode)
  1196. #define vrl_DeviceGetTranslationMode(device) ((device)->translation_mode)
  1197.  
  1198. #define vrl_DeviceGetButtonmap(device) ((device)->buttonmap)
  1199. #define vrl_DeviceSetButtonmap(device, map) ((device)->buttonmap = (map))
  1200.  
  1201. struct _vrl_device_channel
  1202.     {
  1203.     vrl_32bit centerpoint;        /* value of center point in raw device coords */
  1204.     vrl_32bit deadzone;           /* minimum acceptable value in device coords */
  1205.     vrl_32bit range;              /* maximum absolute value relative to zero */
  1206.     vrl_Scalar scale;             /* maximum returned value */
  1207.     vrl_Boolean accumulate : 1;   /* if set, accumulate values */
  1208.     vrl_Boolean changed : 1;      /* set if rawvalue has changed */
  1209.     vrl_32bit rawvalue;           /* current value in raw device coordinates */
  1210.     vrl_32bit oldvalue;           /* previous value in raw device coordinates */
  1211.     vrl_Scalar value;             /* current value, clipped, centered and deadzoned and accumulated */
  1212.     };
  1213.  
  1214. #define vrl_DeviceGetCenter(device, channel) ((device)->channels[channel].centerpoint)
  1215. #define vrl_DeviceGetDeadzone(device, channel) ((device)->channels[channel].deadzone)
  1216. #define vrl_DeviceSetDeadzone(device, channel, value) ((device)->channels[channel].deadzone = (value))
  1217. #define vrl_DeviceGetScale(device, channel) ((device)->channels[channel].scale)
  1218. #define vrl_DeviceSetScale(device, channel, value) ((device)->channels[channel].scale = (value))
  1219. #define vrl_DeviceGetAccumulate(device, channel) ((device)->channels[channel].accumulate)
  1220. #define vrl_DeviceSetAccumulate(device, channel, value) ((device)->channels[channel].accumulate = (value))
  1221. #define vrl_DeviceGetChanged(device, channel) ((device)->channels[channel].changed)
  1222. #define vrl_DeviceGetRawValue(device, channel) ((device)->channels[channel].rawvalue)
  1223. #define vrl_DeviceGetValue(device, channel) ((device)->channels[channel].value)
  1224.  
  1225. /* Serial input/output support */
  1226.  
  1227. typedef enum
  1228.         {
  1229.         VRL_PARITY_EVEN = 0, VRL_PARITY_ODD, VRL_PARITY_NONE
  1230.         } vrl_ParityType;
  1231.  
  1232. struct _vrl_serial_port {
  1233.     unsigned int address;  /* hardware address */
  1234.     int irq;               /* IRQ level (*not* interrupt number!) */
  1235.     int buffsize;          /* size of the buffer */
  1236.     char *buffer;          /* pointer to the buffer */
  1237.     int in, out;           /* offsets into buffer */
  1238.     vrl_SerialPort *next;  /* serial ports are kept in a linked list */
  1239.     };
  1240.  
  1241. vrl_SerialPort *vrl_SerialOpen(unsigned int address, int irq, unsigned int buffsize);
  1242. void vrl_SerialClose(vrl_SerialPort *port);
  1243. void vrl_SerialCloseAll(void);
  1244. void vrl_SerialSetParameters(vrl_SerialPort *port, unsigned int baud, vrl_ParityType parity, int databits, int stopbits);
  1245. vrl_Boolean vrl_SerialCheck(vrl_SerialPort *port);
  1246. unsigned int vrl_SerialGetc(vrl_SerialPort *port);
  1247. void vrl_SerialPutc(unsigned int c, vrl_SerialPort *port);
  1248. void vrl_SerialPutString(unsigned char *s, vrl_SerialPort *p);
  1249. void vrl_SerialFlush(vrl_SerialPort *p);
  1250. void vrl_SerialSetDTR(vrl_SerialPort *port, vrl_Boolean value);
  1251. void vrl_SerialSetRTS(vrl_SerialPort *port, vrl_Boolean value);
  1252. void vrl_SerialFifo(vrl_SerialPort *p, int n);
  1253.  
  1254. typedef struct _device_packet_buffer
  1255.     {
  1256.     int buffsize;           /* size of a packet */
  1257.     int ind;                /* current index into buffer */
  1258.     unsigned char *buffer;  /* pointer to the buffer itself */
  1259.     } vrl_DevicePacketBuffer;
  1260.  
  1261. vrl_DevicePacketBuffer *vrl_DeviceCreatePacketBuffer(int buffsize);
  1262. void vrl_DeviceDestroyPacketBuffer(vrl_DevicePacketBuffer *buff);
  1263. vrl_Boolean vrl_DeviceGetPacket(vrl_SerialPort *port, vrl_DevicePacketBuffer *buff);
  1264. #define vrl_DevicePacketGetBuffer(buff) (((vrl_DevicePacketBuffer *)buff)->buffer)
  1265.  
  1266. /* Configuration file support */
  1267.  
  1268. void vrl_ConfigSetCompassDisplay(vrl_Boolean flag);
  1269. vrl_Boolean vrl_ConfigGetCompassDisplay(void);
  1270. void vrl_ConfigToggleCompassDisplay(void);
  1271. void vrl_ConfigSetPositionDisplay(vrl_Boolean flag);
  1272. vrl_Boolean vrl_ConfigGetPositionDisplay(void);
  1273. void vrl_ConfigTogglePositionDisplay(void);
  1274. void vrl_ConfigSetFramerateDisplay(vrl_Boolean flag);
  1275. vrl_Boolean vrl_ConfigGetFramerateDisplay(void);
  1276. void vrl_ConfigToggleFramerateDisplay(void);
  1277.  
  1278. int vrl_ReadCFG(FILE *in);
  1279. int vrl_ReadCFGfile(char *filename);
  1280. int vrl_ReadCFGProcessLine(char *buff);
  1281. void vrl_ConfigStartup(char *filename);
  1282.  
  1283. /* PCX file support */
  1284.  
  1285. vrl_Boolean vrl_ReadPCX(FILE *in);
  1286. vrl_Boolean vrl_WritePCX(FILE *out);
  1287.  
  1288. /*
  1289.    These #defines are provided for the sake of backward compatability to
  1290.    release 1.1 of AVRIL; they should no longer be used.
  1291.  */
  1292.  
  1293. /* Cursors are now part of the display module, not the mouse module */
  1294. #define vrl_MouseCursorHide() vrl_DisplayCursorHide()
  1295. #define vrl_MouseCursorShow() vrl_DisplayCursorShow()
  1296.  
  1297. /* Highlighting and wireframing are now part of the rendering module, not
  1298.    the display module */
  1299. #define vrl_DisplaySetDrawMode(mode) vrl_RenderSetDrawMode(mode)
  1300. #define vrl_DisplayGetDrawMode() vrl_RenderGetDrawMode()
  1301. #define vrl_DisplaySetWireframeColor(color) vrl_RenderSetWireframeColor(color)
  1302. #define vrl_DisplayGetWireframeColor() vrl_RenderGetWireframeColor()
  1303. #define vrl_DisplaySetHighlightColor(color) vrl_RenderSetHighlightColor(color)
  1304. #define vrl_DisplayGetHighlightColor() vrl_RenderGetHighlightColor()
  1305.  
  1306. /* The old vrl_ObjectGetRotations() function is now replaced by
  1307.    vrl_ObjectGetWorldRotations(), for the sake of consistency; same for
  1308.    the routines which get an object's location. */
  1309.  
  1310. #define vrl_ObjectGetRotations(object, rx, ry, rz) vrl_ObjectGetWorldRotations((object), (rx), (ry), (rz))
  1311. #define vrl_ObjectGetX(object) vrl_ObjectGetWorldX(object)
  1312. #define vrl_ObjectGetY(object) vrl_ObjectGetWorldY(object)
  1313. #define vrl_ObjectGetZ(object) vrl_ObjectGetWorldZ(object)
  1314. #define vrl_ObjectGetLocation(object, v) vrl_ObjectGetWorldLocation((object), (v))
  1315.  
  1316. /* Same for cameras */
  1317.  
  1318. #define vrl_CameraGetRotations(camera, rx, ry, rz) vrl_CameraGetWorldRotations((camera), (rx), (ry), (rz))
  1319. #define vrl_CameraGetX(camera) vrl_CameraGetWorldX(camera)
  1320. #define vrl_CameraGetY(camera) vrl_CameraGetWorldY(camera)
  1321. #define vrl_CameraGetZ(camera) vrl_CameraGetWorldZ(camera)
  1322. #define vrl_CameraGetLocation(camera, v) vrl_CameraGetWorldLocation((camera), (v))
  1323.  
  1324. /* Same for lights */
  1325.  
  1326. #define vrl_LightGetRotations(light, rx, ry, rz) vrl_LightGetWorldRotations((light), (rx), (ry), (rz))
  1327. #define vrl_LightGetX(light) vrl_LightGetWorldX(light)
  1328. #define vrl_LightGetY(light) vrl_LightGetWorldY(light)
  1329. #define vrl_LightGetZ(light) vrl_LightGetWorldZ(light)
  1330. #define vrl_LightGetLocation(light, v) vrl_LightGetWorldLocation((light), (v))
  1331.  
  1332. /* Not currently documented in the manual, mostly because they're in a state
  1333.    of flux:
  1334.  
  1335.     vrl_ShapeInit()   
  1336.     vrl_ShapeCreate()
  1337.     vrl_ShapeComputeBounds()
  1338.     vrl_ShapeGetRadius()
  1339.     vrl_ShapeGetCenter()
  1340.     vrl_ShapeGetMinbounds()
  1341.     vrl_ShapeGetMaxbounds()
  1342.     vrl_RepInit()
  1343.     vrl_RepCreate()
  1344.     vrl_RepAddFacet()
  1345.     vrl_RepGetFacet()
  1346.     vrl_RepHasNormals()
  1347.     vrl_RepGetNormal()
  1348.     vrl_FacetInit()
  1349.     vrl_FacetCerate()
  1350.     vrl_FacetTraverse())
  1351.     vrl_FacetComputeNormal()
  1352.     vrl_FacetSetInterior()
  1353.     vrl_FacetGetInterior()
  1354.     vrl_FacetToggleInterior()
  1355.     vrl_FacetGetNormal()
  1356.     vrl_FacetSetPoint()
  1357.     vrl_FacetGetPoint()
  1358.     vrl_WritePLG()
  1359.     vrl_ObjectSavePLGfile()
  1360.     vrl_SetRetraceHandler()
  1361.     vrl_DisplayGetSortOrder()
  1362.     vrl_DisplayComputeColor()
  1363.     vrl_DisplayComputeVertexColor()
  1364.     vrl_VideoSetNTSC()
  1365.     vrl_Texture typedef
  1366.     vrl_SurfaceSetTexture()
  1367.     vrl_SurfaceGetTexture()
  1368.     everything related to the XY clipping
  1369.     all the configuration file routines
  1370.  
  1371.  */
  1372.  
  1373. /* End of avril.h */
  1374.