/*
 * lib.h - vector library definitions
 *
 * Version:  2.2 (11/17/87)
 * Author:  Eric Haines, 3D/Eye, Inc.
 *
 * Modified: 1 October 1992
 *           Alexander R. Enzmann
 */
#ifndef _LIB_PROTO
#define _LIB_PROTO

#include "def.h"
#include "libvec.h"

/* Change this to "PARAMS(x) ()" if your compiler can't handle function 
   prototyping */
#ifndef PARAMS
#define PARAMS(x) x
#endif

/* Raytracers supported by this package (default OUTPUT_POVRAY): */

#define OUTPUT_VIDEO      0 /* Output direct to the screen (sys dependent) */
#define OUTPUT_NFF        1 /* MTV                                         */
#define OUTPUT_POVRAY     2 /* POV-Ray 1.0                                 */
#define OUTPUT_POLYRAY    3 /* Polyray v1.4, v1.5                          */
#define OUTPUT_VIVID      4 /* Vivid 2.0                                   */
#define OUTPUT_QRT        5 /* QRT 1.5                                     */
#define OUTPUT_RAYSHADE   6 /* Rayshade                                    */
#define OUTPUT_POVRAY_15  7 /* POV-Ray 1.5 (format is subject to change)   */
#define OUTPUT_RTRACE     8 /* RTrace 8.0.0                                */
#define OUTPUT_PLG        9 /* PLG format for use with "rend386"           */
#define OUTPUT_DELAYED   10 /* When this is used, all definitions will be
                               stored rather than immediately dumped.  When
                               all definitions are complete, use the call
                               "lib_flush_definitions" to spit them all out.
                               (Needed for RTRACE/PLG output.) */

/* Note: any new renderers should be added between OUTPUT_VIDEO and
   OUTPUT_DELAYED.  These two values are used as a range check that a known
   renderer has been selected in "lib_set_raytracer" */

/* Output library definitions */
#define OUTPUT_CURVES           0       /* true curve output */
#define OUTPUT_PATCHES          1       /* polygonal patches output */

#define OUTPUT_RESOLUTION       4       /* default amount of polygonalization */

/* The following type definitions aren't used just yet, the intent is to
   build & store the database internally, using the data types defined below. */

/* Type definition for holding a light */
typedef struct light_struct *light_ptr;
struct light_struct {
   COORD4 center_pt;
   light_ptr next;
   };

/* Type definition for holding a surface declaration */
typedef struct surface_struct *surface_ptr;
struct surface_struct {
   char *surf_name;
   unsigned surf_index;
   COORD4 color;
   double ka, kd, ks, shine, ang, kt, ior;
   surface_ptr next;
   };

struct box_struct {
   COORD4 point1, point2;
   };

struct cone_struct {
   COORD4 apex_pt, base_pt;
   };

struct disc_struct {
   COORD4 center, normal;
   double iradius, oradius;
   };

struct height_struct {
   char *filename;
   float **data;
   unsigned width, height;
   float x0, x1, y0, y1, z0, z1;
   };

struct polygon_struct {
   unsigned tot_vert;
   COORD4 *vert;
   };

struct polypatch_struct {
   unsigned tot_vert;
   COORD4 *vert, *norm;
   };

struct sphere_struct {
   COORD4 center_pt;
   };

struct superq_struct {
   COORD4 center_pt;
   double a1, a2, a3, n, e;
   };

struct torus_struct {
   COORD4 center, normal;
   double iradius, oradius;
   };

typedef struct {
   COORD4 from, at, up;
   double angle, aspect, hither, dist;
   int resx, resy;
   MATRIX tx;
   } viewpoint;

#define BOX_OBJ       1
#define CONE_OBJ      2
#define DISC_OBJ      3
#define HEIGHT_OBJ    4
#define POLYGON_OBJ   5
#define POLYPATCH_OBJ 6
#define SPHERE_OBJ    7
#define SUPERQ_OBJ    8
#define TORUS_OBJ     9

typedef struct object_struct *object_ptr;
struct object_struct {
   unsigned object_type;  /* Identify what kind of object */
   unsigned curve_format; /* Output as surface or as polygons? */
   unsigned surf_index;   /* Which surface was associated with this object? */
   union {
      struct box_struct       box;
      struct cone_struct      cone;
      struct disc_struct      disc;
      struct height_struct    height;
      struct polygon_struct   polygon;
      struct polypatch_struct polypatch;
      struct sphere_struct    sphere;
      struct superq_struct    superq;
      struct torus_struct     torus;
      } object_data;
   object_ptr next_object;
   };

/* Global variables - manipulate these at your own risk... */
extern viewpoint view;
extern surface_ptr lib_surfaces;
extern object_ptr lib_objects;
extern light_ptr lib_lights;

/* Library setup for IO functions */
void lib_set_output_file PARAMS((FILE *new_outfile));
void lib_set_default_texture PARAMS((char *default_texture));
void lib_set_raytracer PARAMS((int default_tracer));
void lib_set_polygonalization PARAMS((int u_steps, int v_steps));

/* Scene/object generation functions */
void lib_output_viewpoint PARAMS((COORD4 *from, COORD4 *at, COORD4 *up,
                                  double fov_angle, double aspect_ratio,
                                  double hither, int resx, int resy));
void lib_output_light PARAMS((COORD4 *center_pt));
void lib_output_background_color PARAMS((COORD4 *color));
char *lib_output_color PARAMS((char *name, COORD4 *color, double ka,
			       double kd, double ks, double shine,
			       double ang, double kt, double i_of_r));
void lib_output_cylcone PARAMS((COORD4 *base_pt, COORD4 *apex_pt,
                                int curve_format));
void lib_output_disc PARAMS((COORD4 *center, COORD4 *normal,
                             double iradius, double oradius,
                             int curve_format));
void lib_output_height PARAMS((char *, float **, unsigned, unsigned,
			       float, float, float, float, float, float));
void lib_output_sphere PARAMS((COORD4 *center_pt, int curve_format));
void lib_output_torus PARAMS((COORD4 *center, COORD4 *normal,
                              double iradius, double oradius,
                              int curve_format));
void lib_output_box PARAMS((COORD4 *point1, COORD4 *point2));
void lib_output_polygon PARAMS((int tot_vert, COORD4 *vert));
void lib_output_polypatch PARAMS((int tot_vert, COORD4 *vert, COORD4 *norm));
void lib_output_sq_sphere PARAMS((COORD4 *center_pt, double a1, double a2,
                                  double a3, double n, double e));
void lib_flush_definitions PARAMS((void));
#endif
