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