#ifndef SAMPLE_H /* avoid multiple inclusion */ #define SAMPLE_H /***********************************************************************/ /* Miscellenaous Definitions */ /***********************************************************************/ #define BEGIN_COMMENT "/*" #define END_COMMENT "*/" #define EVER ;; #define BELL() putc(7) #define PAI 3.14159265358974 #define DEG_TO_RAD(a) (a) * 1.74532925199E-2 #define RAD_TO_DEG(a) (a) * 57.2957795131 #define DIM3 4 /* matrix for 3D is 4x4 size */ #define DIM2 3 /* matrix for 2D is 3x3 size */ #define IDENTITY_MATRIX_3D {{1., 0., 0., 0.},\ {0., 1., 0., 0.},\ {0., 0., 1., 0.},\ {0., 0., 0., 1.}}; #define IDENTITY_MATRIX_2D {{1., 0., 0.},\ {0., 1., 0.},\ {0., 0., 1.}}; #define NONE -1 #define TOLERANCE 0.5 #define EPS 1.0E-3 #define fabs(a) (((a) > 0.) ? (a) : (-a)) #define dabs(a) (((a) > 0.) ? (a) : (-a)) #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) #define OPAQUE 0 #define MIRROR 1 #define TRANSPARENT 2 /***********************************************************************/ /* 2D types */ /***********************************************************************/ typedef float Matrix2D[3][3]; typedef struct{ float x, y; } Point2D; typedef struct{ int magic; int width; int height; int depth; int length; int type; int maptype; int maplength; } Header; typedef struct{ unsigned char r, g, b; } Pixel; typedef struct{ Header hd; /* image header */ Pixel *pix; /* pixel */ } Image; /***********************************************************************/ /* 3D types */ /***********************************************************************/ typedef float Matrix3D[4][4]; typedef struct{ float x, y, z; } Point3D; typedef struct{ float r, g, b; } Color; typedef struct{ int type; /* OPAQUE / TRANSPARENT */ Color co; /* diffuse reflection */ float ks, kt; /* specular reflection, transparent coefficient */ float ir; /* index of refraction */ int np; /* Phong's power */ } Material; typedef struct{ Point3D p; /* center of sphere */ float r; /* radius of sphere */ Material m; /* material of sphere */ } Object; typedef struct{ Point3D ld; /* direction of light */ Color cl; /* color of light */ float ke; /* coefficient of ambient light */ } Light; typedef struct{ float xv, yv, zv; /* viewpoint */ float xf, yf, zf; /* view-reference point */ float ax, ay; /* view angles */ float rr; /* distance from vp and vrp */ Matrix3D vft; /* perspective transformation */ } Camera; typedef struct{ Point3D nl; /* plane normal */ Point3D ip; /* intersection */ } Plane; typedef struct{ Point3D dv; /* direction vector */ Point3D sp; /* start point */ Object *co; /* current object */ } Ray; /***********************************************************************/ /* Globally Accessible Functions */ /***********************************************************************/ #ifdef MAIN # define GLOB_FNC #else # define GLOB_FNC extern #endif /* * main.c */ GLOB_FNC void raytrace(); GLOB_FNC void set_pers_mat(); GLOB_FNC void set_screen(); GLOB_FNC void set_image_header(); GLOB_FNC void ray_trace(); GLOB_FNC Object *intersect(); GLOB_FNC void imgout(); GLOB_FNC void normalize(); GLOB_FNC float iproduct(); GLOB_FNC float powern(); GLOB_FNC void set_pers_mat(); GLOB_FNC void mult_mat3D(); GLOB_FNC void mult_vec_mat3D(); GLOB_FNC void copy_mat3D(); GLOB_FNC void mult_mat2D(); GLOB_FNC void mult_vec_mat2D(); GLOB_FNC void copy_mat2D(); #endif /* SAMPLE_H */ /*** EOF ***/