home *** CD-ROM | disk | FTP | other *** search
- /*
- * ray.h -- types, constants.
- *
- * (c) 1993, 1994 Han-Wen Nienhuys, <hanwen@stack.urc.tue.nl>
- *
- * Based on work by George Kyriazis, 1988
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #ifndef NULL
- #define NULL (void *) 0
- #endif
-
- #ifndef FALSE
- #define FALSE 0
- #endif
-
- #ifndef TRUE
- #define TRUE 1
- #endif
-
- #define EXTERN extern /* so space can easily be allocated, see
- * initalize.c */
-
- #define PRIVATE static /* local to a module */
- #define PUBLIC /* global function */
-
- #define EPSILON 1e-10 /* ridiculously small */
- #define INFTY 1e20 /* ridiculously big, unity of MIN() */
- #define BOUNDFUDGE 1e-3 /* make bounds this amount too big */
- #define DEFAULT_TOLERANCE 1e-3
-
- #define ALG_TOLERANCE DEFAULT_TOLERANCE / 2 /* max error for superqs,
- * and algebraics */
-
- /* constants and bounds for the program */
- #define DEFAULTMAXLEVEL 3 /* default maximum recursion level */
- #define MAX_ORDER 12 /* maximum polynomial order */
- #define MAXMAPS 20 /* maximum number of maps to keep track of */
- #define MAXCACHE DEFAULTMAXLEVEL /* level of shadow caches to keep. */
- #define BUFFERSIZE 10240 /* size of input file buffers */
-
- typedef signed char bool; /* a boolean variable */
- typedef double matrix[4][4]; /* a 4x4 matrix, 3x3 for rotation, an
- * extra column for translation */
-
- typedef unsigned char byte;
-
- /* guess what */
- typedef struct {
- double x,
- y,
- z;
- }
-
- vector;
-
- /* the color structure */
- typedef struct {
- double r,
- g,
- b;
- }
-
- color;
-
-
- /**************************************************************************/
- /* the intersection structure */
-
- typedef struct _obj object;
-
- /* Depth queue */
- typedef struct _dqstruct dqueue;
-
- struct _dqstruct {
- object *obj, /* the object which was hit. */
- *obj2; /* needed for extrusion */
- double t; /* where in the ray */
- bool entering; /* entering or exiting? (relative to
- * ray.pos status) */
- dqueue *next;
- };
-
- struct intersect {
- dqueue q_ent;
- vector n, /* the normal at that point */
- x, /* the intersection point in world
- * coordinates (with speed) */
- objectx, /* intersection in shape coordinates */
- objectn;
- };
-
- /* ray types */
- enum {
- R_SHADOW = 0x01,
- R_REFLECT = 0x02,
- R_REFRACT = 0x04,
- R_EYE = 0x08,
- };
-
- /* the ray structure */
- struct ray {
- vector pos; /* origin */
- vector dir; /* direction */
- char type; /* what kind, see above */
- long rayid; /* not used. (yet) */
- double maxt, /* biggest value to look for (if it is
- * more, than don't check intersection
- * details */
- mint; /* smallest t values to look for. (if it
- * is less, then exit) */
- };
-
-
- /* standard manipulators for objects */
- struct methods {
- bool (*all_intersections_method) (dqueue * q, object *op, struct ray * r, int flags, bool *b);
- vector (*normal_method) (struct intersect, vector);
- void (*copy_method) (object *, object *);
- bool (*inside_method) (object *, vector);
- void (*rotate_method) (object *, matrix rotmat);
- void (*translate_method) (object *, vector);
- void (*scale_method) (object *, vector);
- void (*free_method) (object *);
- void (*print_method) (object *);
- void (*precompute_method) (object *);
- char *name;
- long test,
- hit,
- howmuch;
- };
-
- enum {
- CHKALL = 0x01,
- CHKINSIDE = 0x02,
- };
-
- /* some statistics variables */
- struct global_stat_struc {
- long
- raytest, /* total number of ray/intersection tests */
- rayintersections, /* number of rays hitting
- * something */
- objtest, /* number of objects tested. */
- objhit, /* total no. objects hit */
- shadowtest, /* total number shadow ray tests */
- reflected, /* total number of reflected rays */
- refracted, /* total number of refracted rays */
- eyerays,
- boundtest,
- boundhit,
- cliptest,
- cliphit,
- cachetest,
- cachehit,
- cachemiss, /* how many do we have in one scene? */
- objects,
- bounds,
- clips,
- prims,
- nonprims;
- };
-
- /* statistics for a single line. */
- struct line_stat_struc {
- long
- raytest, /* rays */
- rayintersections, /* rays hitting something */
- shadowtest, /* shadow test */
- reflected, /* reflected rays */
- refracted, /* refracted rays */
- eyerays; /* eye rays */
- short maxdepth; /* maximum depth reached. */
- };
-
- enum { /* texturing. */
- T_EGAL, /* smooth */
- T_BLEND, /* texture blend (not yet) */
- T_IMAGEMAP, /* image mapping */
- T_COLORMAP, /* color mapped texture: perlin style (not
- * yet) */
- };
-
- enum {
- PHONG_SHADING
- };
-
-
- #include "objects.h"
-
- /* structure to hold texture info */
- struct texture_data {
- int type,
- shadingtype;
-
- union {
- struct image_map *image;
- } exttext; /* extended info */
- color *PoVcolor;
-
- color refl_color, /* reflective color */
- refr_color, /* refractive color */
- ambient, /* ambient color */
- diffuse, /* diffuse color */
- specular; /* specular color */
-
- double roughness, /* specular roughness: 0 < roughn <=1 */
- index, /* index of refraction */
- refl_diffuse, /* circle of diffusion in
- * reflection */
- refr_diffuse, /* circle of diffusion in
- * refraction */
- brilliance; /* tightness of diffuse illum. */
-
- matrix inv_trans; /* inverse transformation */
- };
-
- struct pixel_data {
- int imagex,
- imagey; /* resolution */
- byte *pal,
- *data; /* the data */
- int palsize; /* palette size, 0 for 24 bit color */
- };
-
- struct image_map {
- struct pixel_data *pic; /* the picture */
- void
- (*inv_map) /* inverse mapping */ (double *u, double *v, vector
- x);
- bool once; /* only one time? */
- bool interpolated; /* not used */
- bool usenormal,
- uvswap; /* swap output of inv_map? */
- double u_offs,
- v_offs; /* translate image over surface */
- double u_range,
- v_range; /* scale it. */
- };
-
- /* eye viewing stuff */
- struct camera {
- vector eye_dir,
- eye,
- sky;
- double fov,
- aspect;
- };
-
- /*
- * the object structure.
- */
- struct _obj {
- int type; /* type of object */
- union shape_data { /* the data. */
- struct plane_data *plane;
- struct sphere_data *sphere;
- struct quadric_data *quadric;
- struct light_data *light;
- struct box_data *box;
- struct torus_data *torus;
- struct algebraic_data *algebraic;
- struct superq_data *superq;
- struct polygon_data *polygon;
- struct extrusion_data *extrusion;
- struct triangle_data *triangle;
- struct disc_data *disc;
- object *CSG;
- struct composite_data *composite;
- }
- data;
- vector bmax,
- bmin; /* for bounding */
- object *daddy;
- object *next;
- struct texture_data *text; /* the texture of the object */
- vector speed; /* motion coefficients */
- object *bound; /* bounding shape to the object */
- object *clip; /* is the bounding shape a clip? */
- bool inverted; /* for CSG purposes. */
- struct methods *methods;
- matrix *inv_trans;
- };
-
- /* structure for a polynomial in one var. */
- typedef struct _sply {
- int ord;
- double coef[MAX_ORDER + 1];
- }
-
- spoly;
-