home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / macraysh.sit / Code / Headers / geom.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-08  |  3.7 KB  |  139 lines

  1. /*
  2.  * geom.h
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: geom.h,v 4.0 91/07/17 14:37:52 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    geom.h,v $
  19.  * Revision 4.0  91/07/17  14:37:52  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #ifndef OBJECT_H
  24. #define OBJECT_H
  25.  
  26. #include "common.h"
  27. #include "transform.h"
  28. #include "bounds.h"
  29.  
  30. /*
  31.  * Constants for enter flag in HitNode.
  32.  */
  33. #define EXITING        1
  34. #define ENTERING    2
  35.  
  36. #define MAXMODELDEPTH    32        /* Maximum height of DAG. */
  37.  
  38. typedef char * GeomRef;
  39. typedef GeomRef GeomCreateFunc();
  40.  
  41. /*
  42.  * If the object has a normal method, it's a primitive
  43.  * otherwise it's an aggregate (or an instance)
  44.  */
  45. #define IsAggregate(o)        ((o)->methods->normal == NULL)
  46.  
  47. /*
  48.  * Geom methods.
  49.  * (p) means applies only to primitive objects
  50.  * (a) means applies only to aggregate objects
  51.  */
  52. typedef struct Methods {
  53.     char        *(*name)();        /* Geom name */
  54.     GeomRef        (*create)();        /* Create and return ref */
  55.     int        (*intersect)(),        /* Ray/obj intersection */
  56.             (*normal)(),        /* Geom normal (p) */
  57.             (*enter)(),        /* Ray enter or exit? (p) */
  58.             (*convert)();        /* Convert from list (a) */
  59.     void        (*uv)(),        /* 2D mapping (p) */
  60.             (*stats)(),        /* Statistics */
  61.             (*bounds)(),        /* Bounding volume */
  62.             (*user)();        /* User-defined method */
  63.     struct Methods    *(*methods)();        /* object methods func. */
  64.     char        checkbounds,        /* check bbox before int.? */
  65.             closed;            /* properly closed? */
  66. } Methods;
  67.  
  68. typedef void (*UserMethodType)();
  69.  
  70. /*
  71.  * Geom definition
  72.  */
  73. typedef struct Geom {
  74.     char *name;            /* Geom name, if any. */
  75.     GeomRef obj;            /* Pointer to object info. */
  76.     Methods *methods;
  77.     unsigned long prims;        /* sum of # primitive objects */
  78.     Float bounds[2][3];        /* Bounding box */
  79.     Float timenow;            /* Geom's idea of what time it is */
  80.     short int animtrans;        /* transformation is animated */
  81.     short int frame;        /* frame for which obj is inited */
  82.     struct Surface *surf;        /* surface, if any */
  83.     struct Trans *trans;        /* Transformation information */
  84.     struct Trans *transtail;    /* Double linked list end */
  85.     struct Texture *texture;    /* Texture mapping info. */
  86.     unsigned long counter;        /* "mailbox" for grid intersection */
  87.     struct Geom *next;        /* Next object. */
  88. } Geom;
  89.  
  90. /*
  91.  * Linked list of pointers to objects.
  92.  */
  93. typedef struct GeomList {
  94.     Geom *obj;
  95.     struct GeomList *next;
  96. } GeomList;
  97.  
  98. /*
  99.  * Array of hit information.  Stores a path through an object DAG,
  100.  * as well as the ray in 'model' (object) space and the distance from
  101.  * the ray origin to the point of intersection.
  102.  */
  103. typedef struct HitNode {
  104.     Geom *obj;            /* Geom hit */
  105.     Ray    ray;            /* Ray */
  106.     Float    mindist;        /* Amount of ray to ignore */
  107.     Float    dist;            /* Distance from ray origin to hit */
  108.     short    enter,            /* Enter (TRUE) or Leave (FALSE) obj */
  109.         dotrans;        /* transformations non-identity? */
  110.     Trans    trans;            /* parent-->obj and inverse trans */
  111. } HitNode;
  112.  
  113. /*
  114.  * Structure holding a list of HitNodes.  A maximum of MAXMODELDEPTH
  115.  * nodes can be referenced.
  116.  */
  117. typedef struct HitList {
  118.     int nodes;
  119.     HitNode data[MAXMODELDEPTH];
  120. } HitList;
  121.  
  122. extern char    *GeomName();
  123.  
  124. extern Geom    *GeomCreate(), *GeomCopy(), *GeomCopyNamed(),
  125.         *GeomComputeAggregateBounds();
  126.  
  127.  
  128. extern GeomList    *GeomStackPush(), *GeomStackPop();
  129.  
  130. extern void     PrimUV(), AggregatePrintInfo(),
  131.         IntersectStats();
  132.  
  133. extern int    AggregateConvert(), PrimNormal(),
  134.         TraceRay();    /* application-provided */
  135.  
  136. extern Methods    *MethodsCreate();
  137.  
  138. #endif /* OBJECT_H */
  139.