home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / rayce27s / proto.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-02  |  9.4 KB  |  239 lines

  1. /*
  2.  * proto.h -- function prototypes
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <math.h>
  8. #include <assert.h>
  9.  
  10. /* miscellaneous routines */
  11. PUBLIC void     transform_ray(struct ray *r, object *o);
  12. PUBLIC void     close_input(void);
  13. PUBLIC void     raytrace(char *fname);
  14. PUBLIC void     readfile(char *fname);
  15. PUBLIC void     set_input(char *fname);
  16. PUBLIC void     abort_trace(int);
  17.  
  18. /* device dep. code */
  19. PUBLIC void     check_abort(void);
  20. PUBLIC void     init_machine(void);
  21. PUBLIC void     initialize(void);
  22. PUBLIC void     timer_start(void);
  23. PUBLIC long     timer_stop(void);
  24.  
  25. /* errors */
  26. PUBLIC void     internal_error(char *module, int line);
  27. PUBLIC void     warning(char *format,...);
  28. PUBLIC void     errormsg(char *format,...);
  29. PUBLIC void     alloc_err(char *s);
  30.  
  31. /* stats */
  32. PUBLIC void     start_stats(void);
  33. PUBLIC void     set_defaults(void);
  34. PUBLIC void     print_all_shape_stats(char *format, object *p);
  35. PUBLIC void     print_image_map(struct image_map *p);
  36.  
  37. /* debug */
  38. PUBLIC unsigned long memory_left(void);
  39. PUBLIC void     print_v(char *s, vector v);
  40. PUBLIC void     print_matrix(matrix c);
  41. PUBLIC void     print_poly(spoly *p);
  42. PUBLIC void     print_queue(dqueue * root);
  43. PUBLIC void     print_c(char *s, color c);
  44.  
  45.  
  46. /* colors. */
  47. PUBLIC void     scale_color(color *c, double fact);
  48. PUBLIC color    color_add(color a, color b);
  49. PUBLIC color    color_mul(color a, color b);
  50. PUBLIC color    scolorproduct(double fact, color c);
  51. PUBLIC color    color_scaled(color *c, double fact);
  52. PUBLIC void     copy_color(color *dst, color *src);
  53. PUBLIC color    normcol(color col);
  54. PUBLIC double   color_length(color c);
  55. PUBLIC color   *get_new_color(void);
  56. PUBLIC void     free_color(color *c);
  57.  
  58. /*
  59.  * inline vector operations and other macros
  60.  */
  61. #include "macro.h"
  62. #include "vector.h"
  63.  
  64. /* math routines */
  65. PUBLIC int      sturm_solve_rt_poly(spoly *thepoly, double *roots, bool chkall);
  66. PUBLIC int      solve_rt_poly(spoly *thepoly, double *roots, bool chkall);
  67. PUBLIC double   poly_eval(register double x, int ord, double *coef);
  68. PUBLIC double   degtorad(double deg);
  69. PUBLIC double   radtodeg(double rad);
  70. PUBLIC double   frand(void);
  71. PUBLIC double   rand1(void);
  72. PUBLIC double   Gauss_rand(void);
  73. PUBLIC void     torotv(vector *v);
  74. PUBLIC bool     isvnull(vector a);
  75. PUBLIC void     copy_vector(vector *dst, vector *src);
  76. PUBLIC void     update_min_and_max(vector *min, vector *max, vector point);
  77. PUBLIC void     do_box_bound(vector *bmin, vector *bmax, matrix inv_trans, vector p1, vector p2);
  78. PUBLIC double   safe_arctangent(double a, double b);
  79.  
  80. /* matrices */
  81. PUBLIC vector   transform_normal(matrix A, vector n);
  82. PUBLIC void     split_inv_trans(matrix A, vector *trans, vector *scal, matrix rot);
  83. PUBLIC void     copy_matrix(matrix dst, matrix src);
  84. PUBLIC void     rotate_matrix(matrix m, vector v);
  85. PUBLIC void     mmproduct(matrix product, matrix left, matrix right);
  86. PUBLIC void     transpose_matrix(matrix tr, matrix org);
  87. PUBLIC vector   mvproduct(matrix A, vector x);
  88. PUBLIC vector   transform_direction(matrix A, vector x);
  89. PUBLIC void     invert_trans(matrix out, matrix in);
  90. PUBLIC void     make_rotation_matrix(matrix m, vector v);
  91.  
  92. PUBLIC void     null_matrix(matrix m);
  93. PUBLIC void     unit_matrix(matrix m);
  94. PUBLIC void     inv_rotate_matrix(matrix m, vector r);
  95. PUBLIC void     scale_matrix(matrix m, vector s);
  96. PUBLIC void     inv_scale_matrix(matrix m, vector s);
  97. PUBLIC void     translate_matrix(matrix m, vector t);
  98. PUBLIC void     inv_translate_matrix(matrix m, vector t);
  99.  
  100.  
  101. /* the real tracing stuff */
  102. PUBLIC color    shade(struct intersect i, struct ray r, int n, double imp);
  103. PUBLIC color    bgcolor(struct ray *r);
  104. PUBLIC color    trace(struct ray r, int n, double imp);
  105. PUBLIC color    trace_a_ray(struct ray r, int n);
  106. PUBLIC struct intersect intersect(struct ray r);
  107. PUBLIC struct ray sample_ray(struct ray r, double theta);
  108. PUBLIC bool     shadow_test(struct ray r, double ldistance, object *light, int recursion);
  109.  
  110. /* depth queue routines */
  111. PUBLIC void     add_to_queue(dqueue * root, dqueue q_ent);
  112. PUBLIC dqueue  *get_new_queue(void);
  113. PUBLIC void     free_queue(dqueue * root);
  114. PUBLIC void     print_queue(dqueue * root);
  115.  
  116. /*
  117.  * intersection routines; global so they can be used for special bounding
  118.  * shapes
  119.  */
  120.  
  121. PUBLIC int      intersect_rawbox(vector p1, vector p2, struct ray *r, double *params);
  122. PUBLIC bool     intersect_object(dqueue * globalq, object *o, struct ray *r, int flags);
  123. PUBLIC int      intersect_sphere(vector center, double rsq, struct ray *r, double *hits);
  124.  
  125. /* precompute_xxx. They compute constants in the xxx_data structure */
  126. PUBLIC void     precompute_object_list(object *o);
  127. PUBLIC void     precompute_object(object *o);
  128.  
  129. /* polygons */
  130. PUBLIC void     add_vertex_to_polygon(object *o, vector vert);
  131.  
  132. /* the get_new_xxx routines. They alloc xxx, and initialize it */
  133. PUBLIC double  *get_new_float(void);
  134. PUBLIC matrix  *get_new_matrix(void);
  135.  
  136. /* get_new_xxx_object */
  137. PUBLIC object  *get_new_disc_object(void);
  138. PUBLIC object  *get_new_smooth_triangle_object(void);
  139. PUBLIC object  *get_new_triangle_object(void);
  140. PUBLIC object  *get_new_extrusion_object(void);
  141. PUBLIC object  *make_cylinder_object(vector p1, vector p2, double rad);
  142. PUBLIC object  *get_new_torus_object(void);
  143. PUBLIC object  *get_new_object(void);
  144. PUBLIC object  *get_new_superq_object(void);
  145. PUBLIC object  *get_new_sphere_object(void);
  146. PUBLIC object  *get_new_quadric_object(void);
  147. PUBLIC object  *get_new_plane_object(void);
  148. PUBLIC object  *get_new_light_object(void);
  149. PUBLIC object  *get_new_box_object(void);
  150. PUBLIC object  *get_new_CSGinter_object(void);
  151. PUBLIC object  *get_new_CSGunion_object(void);
  152. PUBLIC object  *get_new_algebraic_object(void);
  153. PUBLIC object  *get_new_polygon_object(void);
  154.  
  155. /* free_xxx routines. They free xxx, and xxx's sub-data */
  156. PUBLIC void     free_float(double *f);
  157.  
  158. /* vectors */
  159. PUBLIC void     rotate_vector(vector *v, matrix rotmat);
  160. PUBLIC void     free_vector(vector *v);
  161. PUBLIC vector  *get_new_vector(void);
  162.  
  163. /* polynomials */
  164. PUBLIC void     poly_neg(spoly *dst, spoly *src);
  165. PUBLIC void     poly_multiply(spoly *dest, spoly *p1, spoly *p2);
  166. PUBLIC void     poly_power(spoly *dst, int exponent, spoly *src);
  167. PUBLIC void     poly_copy(spoly *dst, spoly *src);
  168. PUBLIC void     poly_clean(spoly *p);
  169. PUBLIC void     poly_add(spoly *dst, spoly *p1, spoly *p2);
  170. PUBLIC void     poly_scalmult(spoly *d, double fact);
  171. PUBLIC void     poly_sub(spoly *dst, spoly *p1, spoly *p2);
  172.  
  173. /* cameras */
  174. PUBLIC double   to_fov_coeff(struct camera *c, double angle);
  175. PUBLIC void     point_camera(struct camera *c, vector lookat);
  176. PUBLIC struct camera *get_new_camera(void);
  177. PUBLIC void     free_camera(struct camera *c);
  178. PUBLIC void     translate_camera(struct camera *c, vector t);
  179. PUBLIC void     rotate_camera(struct camera *c, matrix rotmat);
  180. PUBLIC void     scale_camera(struct camera *c, vector s);
  181. PUBLIC void     copy_camera(struct camera *dst, struct camera *src);
  182. PUBLIC void     print_camera(struct camera *c);
  183.  
  184. /* objects */
  185. PUBLIC void     print_object_list(object *o);
  186. PUBLIC void     print_object(object *obj);
  187. PUBLIC void     free_object(object *op);
  188. PUBLIC void     free_object_list(object *p);
  189. PUBLIC void     rotate_object(object *op, matrix rotmat);
  190. PUBLIC void     translate_object(object *op, vector t);
  191. PUBLIC void     scale_object(object *op, vector s);
  192. PUBLIC void     rotate_object_list(object *p, matrix rotmat);
  193. PUBLIC void     scale_object_list(object *p, vector r);
  194. PUBLIC void     translate_object_list(object *p, vector r);
  195. PUBLIC void     speed_object_list(object *start, vector s);
  196. PUBLIC void     copy_object(object *dst, object *src);
  197.  
  198. PUBLIC void     generic_scale_object(object *o, vector s);
  199. PUBLIC void     generic_translate_object(object *o, vector t);
  200. PUBLIC void     generic_rotate_object(object *o, matrix m);
  201.  
  202. PUBLIC void     append_to_object_list(object *o, object *toadd);
  203. PUBLIC void     add_bounds_to_clip(object *o);
  204.  
  205.  
  206. /* textures! */
  207. PUBLIC void     fill_texture(struct texture_data *tp, struct texture_data *orgtext, struct intersect i);
  208. PUBLIC struct texture_data *get_new_texture(void);
  209. PUBLIC void     free_texture(struct texture_data *t);
  210. PUBLIC struct texture_data *copy_texture(struct texture_data *dst, struct texture_data *src);
  211. PUBLIC void     translate_texture(struct texture_data *t, vector v);
  212. PUBLIC void     scale_texture(struct texture_data *t, vector s);
  213. PUBLIC void     rotate_texture(struct texture_data *t, matrix rotmat);
  214. PUBLIC void     print_texture(struct texture_data *tx);
  215.  
  216. /* imagemaps */
  217. PUBLIC struct pixel_data *get_TGA_pixels(char *fn);
  218. PUBLIC struct pixel_data *get_GIF_pixels(char *fn);
  219. PUBLIC color    get_image_map_color(struct image_map *p, struct intersect i);
  220. PUBLIC struct image_map *get_new_image_map(void);
  221. PUBLIC void     copy_image_map(struct image_map *dst, struct image_map *src);
  222. PUBLIC void     inverse_spheremap(double *u, double *v, vector x);
  223. PUBLIC void     inverse_planemap(double *u, double *v, vector x);
  224. PUBLIC void     inverse_torusmap(double *u, double *v, vector x);
  225. PUBLIC void     inverse_cylindermap(double *u, double *v, vector x);
  226. PUBLIC void     load_gif(struct pixel_data *image, FILE * f);
  227. PUBLIC void     free_image_map(struct image_map *p);
  228.  
  229. /* composites */
  230. PUBLIC object  *get_new_composite_object(void);
  231. PUBLIC void     speed_composite(object *o, vector spd);
  232. PUBLIC void     add_to_composite(object *c, object *o);
  233. PUBLIC void     add_to_CSG(object *c, object *o);
  234.  
  235. /* lights */
  236. PUBLIC color    light_color(struct light_data *l, vector a);
  237. PUBLIC void     make_light_list(object *o);
  238. PUBLIC void     print_light_list(void);
  239.