home *** CD-ROM | disk | FTP | other *** search
- /*
- * XXXX.c -- handle XXXX type objects This is what an object-file should
- * look like.
- *
- * (c) 1993, 1994 by Han-Wen Nienhuys <hanwen@stack.urc.tue.nl>
- *
- * 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.
- */
-
- #include "ray.h"
- #include "proto.h"
- #include "extern.h
-
-
- extern struct methods my_methods;
-
- /* zap memory used by o->data.XXXX, and its substructures */
- PRIVATE void
- free_XXXX(object *o)
- {
- free((void *) o->data.XXXX);
- o->type = NOSHAPE;
- }
-
- /* initialize a XXXX_data struct */
- PRIVATE void
- init_XXXX(struct XXXX_data *t)
- {
-
- }
-
-
- /* don't change this one. It allocates a struct XXXX_data */
- PRIVATE struct XXXX_data *
- get_new_XXXX(void)
- {
- struct XXXX_data *p;
- p = ALLOC(struct XXXX_data);
-
- CHECK_MEM(p, my_methods.name);
- init_XXXX(p);
- return p;
- }
-
- /* is vector loc inside a XXXX ? */
- PRIVATE bool
- inside_XXXX(object *o, vector loc)
- {
- struct XXXX_data *p = o->data.XXXX;
-
- /*
- * NOTE: delete this if you don't want to use transformation
- * matrices.
- */
-
- if (o->inv_trans)
- loc = mvproduct(*o->inv_trans, loc);
-
- /* insert code */
-
- }
-
-
-
- /*
- * NOTE: if you don't want to use transformation matrices, then you
- * should:
- *
- * - delete the references to generic_xx_object routines, in my_methods,
- *
- * - code these routines
- *
- * - remove the #define below
- */
- #ifdef UNDEFINED
-
- /* scale it. */
- PRIVATE void
- scale_XXXX(object *o, vector s)
- {
- struct XXXX_data *p = o->data.XXXX;
-
- }
-
- /* rotation */
- PRIVATE void
- rotate_XXXX(object *o, matrix rotmat)
- {
- struct XXXX_data *p = o->data.XXXX;
-
- }
-
- /* and translation */
- PRIVATE void
- translate_XXXX(object *o, vector t)
- {
- struct XXXX_data *p = o->data.XXXX;
-
- }
-
- #endif
-
-
- PUBLIC void
- print_XXXX(object *o)
- {
- #ifdef DEBUG
- struct XXXX_data *p = o->data.XXXX;
-
- #endif
- }
-
- /*
- * the real intersection calculation.
- */
- PRIVATE int
- intersect_XXXX(struct XXXX_data *tor, struct ray *r, double *rhits, bool chkall)
- {
- my_methods.test++;
- my_methods.hit++;
- }
-
- /*
- * intersect with the o->data.XXXX part, return TRUE if intersection
- * found.
- */
- PRIVATE bool
- all_XXXX_intersections(dqueue * q, object *o, struct ray *r, int flags, bool *isinside)
- {
- int n,
- j;
- double inter[4];
- dqueue q_ent;
- bool loc_ins;
-
- struct ray localray;
-
- localray = *r;
- transform_ray(&localray, o);
- n = intersect_XXXX(o->data.XXXX, localray, inter, flags & CHKALL);
- loc_ins = *isinside = (n % 2) ^ o->inverted;
-
- if (!n)
- return FALSE;
-
-
- if (flags & CHKINSIDE && n > 1) /* check everything? */
- for (j = 0; j < n; j++) {
- q_ent.t = inter[j];
- q_ent.obj = o;
- q_ent.entering = (loc_ins = !loc_ins);
- add_to_queue(q, q_ent);
- } else {
- /* record only one hit. */
-
- q_ent.t = inter[0];
- q_ent.obj = o;
- q_ent.entering = (loc_ins = !loc_ins);
- add_to_queue(q, q_ent);
- }
-
- return TRUE;
- }
-
-
-
- /*
- * returns the normal to the XXXX
- */
- PRIVATE vector
- XXXX_normal(struct intersect i, vector loc)
- {
- struct XXXX_data *p = i.q_ent.obj->data.XXXX;
- vector n;
-
- /*
- * NOTE: delete this if you don't want to use transformation
- * matrices.
- */
- if (o->inv_trans)
- loc = mvproduct(*o->inv_trans, loc);
-
-
- if (o->inv_trans)
- n = transform_normal(*o->inv_trans, n);
- norm(n, n);
- return n;
- }
-
- /* copy the shape data */
- PRIVATE void
- copy_XXXX(object *dst, object *src)
- {
- assert(dst != NULL && src != NULL);
-
- if (dst->type != XXXX)
- dst->data.XXXX = get_new_XXXX();
- *dst->data.XXXX = *src->data.XXXX;
- dst->type = src->type;
- }
-
- PRIVATE void
- precompute_XXXX(object *o)
- {
- struct XXXX_data *b = o->data.XXXX;
-
- /* do precomputation */
-
- /* do autobounding */
-
- /* stats */
- my_methods.howmuch++;
- global_stats.prims++;
- }
-
- /* below, nothings has to be changed. */
- PRIVATE struct methods my_methods =
- {
- all_XXXX_intersections,
- XXXX_normal,
- copy_XXXX,
- inside_XXXX,
- generic_rotate_object,
- generic_translate_object,
- generic_scale_object,
-
- /* remove this, if you use customised transform routines */
- #ifdef UNDEFINE
- rotate_XXXX,
- translate_XXXX,
- scale_XXXX,
- #endif
-
- free_XXXX,
- print_XXXX,
- precompute_XXXX,
- "XXXX",
- };
-
- /* alloc/init */
- PUBLIC object *
- get_new_XXXX_object(void)
- {
- object *o;
-
- o = get_new_object();
-
- o->data.XXXX = get_new_XXXX();
-
- o->methods = &my_methods;
- o->type = XXXX;
-
- return o;
- }
-
- /* eof */
-