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

  1. /*
  2.  * XXXX.c -- handle XXXX type objects This is what an object-file should
  3.  * look like.
  4.  * 
  5.  * (c) 1993, 1994 by Han-Wen Nienhuys <hanwen@stack.urc.tue.nl>
  6.  * 
  7.  * This program is free software; you can redistribute it and/or modify it
  8.  * under the terms of the GNU General Public License as published by the
  9.  * Free Software Foundation;
  10.  * 
  11.  * This program is distributed in the hope that it will be useful, but
  12.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * General Public License for more details.
  15.  * 
  16.  * You should have received a copy of the GNU General Public License along
  17.  * with this program; if not, write to the Free Software Foundation, Inc.,
  18.  * 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include "ray.h"
  22. #include "proto.h"
  23. #include "extern.h
  24.  
  25.  
  26. extern struct methods my_methods;
  27.  
  28. /* zap memory used by o->data.XXXX, and its substructures */
  29. PRIVATE void
  30. free_XXXX(object *o)
  31. {
  32.     free((void *) o->data.XXXX);
  33.     o->type = NOSHAPE;
  34. }
  35.  
  36. /* initialize a XXXX_data struct */
  37. PRIVATE void
  38. init_XXXX(struct XXXX_data *t)
  39. {
  40.  
  41. }
  42.  
  43.  
  44. /* don't change this one. It allocates a struct XXXX_data */
  45. PRIVATE struct XXXX_data *
  46. get_new_XXXX(void)
  47. {
  48.     struct XXXX_data *p;
  49.     p = ALLOC(struct XXXX_data);
  50.  
  51.     CHECK_MEM(p, my_methods.name);
  52.     init_XXXX(p);
  53.     return p;
  54. }
  55.  
  56. /* is vector loc inside a XXXX ? */
  57. PRIVATE bool
  58. inside_XXXX(object *o, vector loc)
  59. {
  60.     struct XXXX_data *p = o->data.XXXX;
  61.  
  62.     /*
  63.      * NOTE:  delete this if you don't want to use transformation
  64.      * matrices.
  65.      */
  66.  
  67.     if (o->inv_trans)
  68.     loc = mvproduct(*o->inv_trans, loc);
  69.  
  70.     /* insert code */
  71.  
  72. }
  73.  
  74.  
  75.  
  76. /*
  77.  * NOTE: if you don't want to use transformation matrices, then you
  78.  * should:
  79.  * 
  80.  * - delete the references to generic_xx_object routines, in my_methods,
  81.  * 
  82.  * - code these routines
  83.  * 
  84.  * - remove the #define below
  85.  */
  86. #ifdef UNDEFINED
  87.  
  88. /* scale it. */
  89. PRIVATE void
  90. scale_XXXX(object *o, vector s)
  91. {
  92.     struct XXXX_data *p = o->data.XXXX;
  93.  
  94. }
  95.  
  96. /* rotation */
  97. PRIVATE void
  98. rotate_XXXX(object *o, matrix rotmat)
  99. {
  100.     struct XXXX_data *p = o->data.XXXX;
  101.  
  102. }
  103.  
  104. /* and translation */
  105. PRIVATE void
  106. translate_XXXX(object *o, vector t)
  107. {
  108.     struct XXXX_data *p = o->data.XXXX;
  109.  
  110. }
  111.  
  112. #endif
  113.  
  114.  
  115. PUBLIC void
  116. print_XXXX(object *o)
  117. {
  118. #ifdef DEBUG
  119.     struct XXXX_data *p = o->data.XXXX;
  120.  
  121. #endif
  122. }
  123.  
  124. /*
  125.  * the real intersection calculation.
  126.  */
  127. PRIVATE int
  128. intersect_XXXX(struct XXXX_data *tor, struct ray *r, double *rhits, bool chkall)
  129. {
  130.     my_methods.test++;
  131.     my_methods.hit++;
  132. }
  133.  
  134. /*
  135.  * intersect with the o->data.XXXX part, return TRUE if intersection
  136.  * found.
  137.  */
  138. PRIVATE bool
  139. all_XXXX_intersections(dqueue * q, object *o, struct ray *r, int flags, bool *isinside)
  140. {
  141.     int             n,
  142.                     j;
  143.     double          inter[4];
  144.     dqueue          q_ent;
  145.     bool            loc_ins;
  146.  
  147.     struct ray      localray;
  148.  
  149.     localray = *r;
  150.     transform_ray(&localray, o);
  151.     n = intersect_XXXX(o->data.XXXX, localray, inter, flags & CHKALL);
  152.     loc_ins = *isinside = (n % 2) ^ o->inverted;
  153.  
  154.     if (!n)
  155.     return FALSE;
  156.  
  157.  
  158.     if (flags & CHKINSIDE && n > 1)    /* check everything? */
  159.     for (j = 0; j < n; j++) {
  160.         q_ent.t = inter[j];
  161.         q_ent.obj = o;
  162.         q_ent.entering = (loc_ins = !loc_ins);
  163.         add_to_queue(q, q_ent);
  164.     } else {
  165.     /* record only one hit. */
  166.  
  167.     q_ent.t = inter[0];
  168.     q_ent.obj = o;
  169.     q_ent.entering = (loc_ins = !loc_ins);
  170.     add_to_queue(q, q_ent);
  171.     }
  172.  
  173.     return TRUE;
  174. }
  175.  
  176.  
  177.  
  178. /*
  179.  * returns the normal to the XXXX
  180.  */
  181. PRIVATE vector
  182. XXXX_normal(struct intersect i, vector loc)
  183. {
  184.     struct XXXX_data *p = i.q_ent.obj->data.XXXX;
  185.     vector          n;
  186.  
  187.     /*
  188.      * NOTE:  delete this if you don't want to use transformation
  189.      * matrices.
  190.      */
  191.     if (o->inv_trans)
  192.     loc = mvproduct(*o->inv_trans, loc);
  193.  
  194.  
  195.     if (o->inv_trans)
  196.     n = transform_normal(*o->inv_trans, n);
  197.     norm(n, n);
  198.     return n;
  199. }
  200.  
  201. /* copy the shape data */
  202. PRIVATE void
  203. copy_XXXX(object *dst, object *src)
  204. {
  205.     assert(dst != NULL && src != NULL);
  206.  
  207.     if (dst->type != XXXX)
  208.     dst->data.XXXX = get_new_XXXX();
  209.     *dst->data.XXXX = *src->data.XXXX;
  210.     dst->type = src->type;
  211. }
  212.  
  213. PRIVATE void
  214. precompute_XXXX(object *o)
  215. {
  216.     struct XXXX_data *b = o->data.XXXX;
  217.  
  218.     /* do precomputation */
  219.  
  220.     /* do autobounding */
  221.  
  222.     /* stats */
  223.     my_methods.howmuch++;
  224.     global_stats.prims++;
  225. }
  226.  
  227. /* below, nothings has to be changed. */
  228. PRIVATE struct methods my_methods =
  229. {
  230.     all_XXXX_intersections,
  231.     XXXX_normal,
  232.     copy_XXXX,
  233.     inside_XXXX,
  234.     generic_rotate_object,
  235.     generic_translate_object,
  236.     generic_scale_object,
  237.  
  238. /* remove this, if you use customised transform routines */
  239. #ifdef UNDEFINE
  240.     rotate_XXXX,
  241.     translate_XXXX,
  242.     scale_XXXX,
  243. #endif
  244.  
  245.     free_XXXX,
  246.     print_XXXX,
  247.     precompute_XXXX,
  248.     "XXXX",
  249. };
  250.  
  251. /* alloc/init */
  252. PUBLIC object  *
  253. get_new_XXXX_object(void)
  254. {
  255.     object         *o;
  256.  
  257.     o = get_new_object();
  258.  
  259.     o->data.XXXX = get_new_XXXX();
  260.  
  261.     o->methods = &my_methods;
  262.     o->type = XXXX;
  263.  
  264.     return o;
  265. }
  266.  
  267. /* eof */
  268.