home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vr386 / demotask.c < prev    next >
C/C++ Source or Header  |  1996-03-19  |  4KB  |  153 lines

  1. /* Old animation routines for sample virtual world */
  2.  
  3. /* Written by Bernie Roehl, July 1992 */
  4. // PORTED TO vr-386 api BY dAVE sTAMPE, 9/1/94
  5.  
  6. // This code is old now: animation support will be much better
  7. // usingg STATMACH.C and new functions in the pipeline
  8.  
  9.  
  10. // OLD OLD CODE: NOT REALLY UPDATED FOR API.
  11. // USE AT OWN RISK!  TASKS WILL CHANGE IN FUTURE API RELEASES!
  12.  
  13.  
  14. /*
  15.  This code is part of the VR-386 project, created by Dave Stampe.
  16.  VR-386 is a desendent of REND386, created by Dave Stampe and
  17.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  18.  Stampre for VR-386.
  19.  
  20.  Copyright (c) 1994 by Dave Stampe:
  21.  May be freely used to write software for release into the public domain
  22.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  23.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  24.  this software or source code into their products!  Usually there is no
  25.  charge for under 50-100 items for low-cost or shareware products, and terms
  26.  are reasonable.  Any royalties are used for development, so equipment is
  27.  often acceptable payment.
  28.  
  29.  ATTRIBUTION:  If you use any part of this source code or the libraries
  30.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  31.  and any other authors in your documentation, source code, and at startup
  32.  of your program.  Let's keep the freeware ball rolling!
  33.  
  34.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  35.  REND386, improving programmer access by rewriting the code and supplying
  36.  a standard API.  If you write improvements, add new functions rather
  37.  than rewriting current functions.  This will make it possible to
  38.  include you improved code in the next API release.  YOU can help advance
  39.  VR-386.  Comments on the API are welcome.
  40.  
  41.  CONTACT: dstampe@psych.toronto.edu
  42. */
  43.  
  44.  
  45. #include <stdio.h>
  46. #include <string.h>
  47. #include <stdlib.h>
  48.  
  49. #include "vr_api.h"
  50. #include "intmath.h"
  51. #include "oldtasks.h"
  52.  
  53. #define MAXSPINCOLORS 100
  54.  
  55. typedef struct {
  56.     OBJECT *obj;
  57.     int np; /* number of polys in obj */
  58.     int ncolors;
  59.     unsigned colors[MAXSPINCOLORS];
  60. } SPINDATA;
  61.  
  62. extern void *objectlist;
  63. extern void *find_name();
  64.  
  65. void spinner(int cmd, char *init, long now, long period)
  66. {
  67.   char *colorlist, *q;
  68.   SPINDATA *data, **dataptr;
  69.   int i, color;
  70.   switch (cmd)
  71.     {
  72.       case 0:
  73.     if ((data = malloc(sizeof(SPINDATA))) == NULL) return;
  74.     dataptr = find_task_data(get_current_task());
  75.     *dataptr = data;
  76.     data->ncolors = 0;
  77.     if ((colorlist = strchr(init, ';')) != NULL)
  78.       {
  79.         *colorlist++ = '\0';
  80.         for (colorlist = strtok(colorlist, ","); colorlist; colorlist = strtok(NULL, ","))
  81.             if (data->ncolors >= MAXSPINCOLORS)
  82.                     break;
  83.             else
  84.                     data->colors[data->ncolors++] = strtoul(colorlist, NULL, 0);
  85.       }
  86.     data->obj = find_name(objectlist, init);
  87.     if (data->obj) get_obj_info(data->obj, NULL, &data->np);
  88.             break;
  89.      case 1:
  90.     dataptr = find_task_data(get_current_task());
  91.     data = *dataptr;
  92.     if (data == NULL) return;
  93.     if (data->obj == NULL) return;
  94.     color = (now/period) % data->ncolors;
  95.     for (i = 0; i < data->np; ++i)
  96.         set_poly_color(data->obj, i, data->colors[(color+i) % data->ncolors]);
  97.     world_changed++;
  98.     break;
  99.      default:
  100.     break;
  101.    }
  102. }
  103.  
  104.  
  105. typedef struct {
  106.     SEGMENT *seg;
  107.     long rx,ry,rz;
  108. } SCULDATA;
  109.  
  110. extern SEGMENT *find_seg(char *name);
  111.  
  112. void sculspin(int cmd, char *init, long now, long period)
  113. {
  114.   SCULDATA *data, **dataptr;
  115.   OBJECT *obj;
  116.   char *parms;
  117.   float rx, ry, rz;
  118.  
  119.   switch (cmd)
  120.     {
  121.       case 0:
  122.     if ((data = malloc(sizeof(SCULDATA))) == NULL) return;
  123.     dataptr = find_task_data(get_current_task());
  124.     *dataptr = data;
  125.     data->rx = data->ry = data->rz = 0;
  126.     if ((parms = strchr(init, ';')) != NULL)
  127.       {
  128.         *parms++ = '\0';
  129.         sscanf(parms, "%f,%f,%f", &rx, &ry, &rz);
  130.         data->rx = rx * 65536L;
  131.         data->ry = ry * 65536L;
  132.         data->rz = rz * 65536L;
  133.       }
  134.     data->seg = object2segment(find_seg(init));
  135.  
  136. /*            obj = find_name(objectlist, init);
  137.             if (obj)
  138.                 data->seg = get_object_owner(obj); */
  139.             break;
  140.      case 1:
  141.     dataptr = find_task_data(get_current_task());
  142.     data = *dataptr;
  143.     if (data == NULL) return;
  144.     if (data->seg == NULL) return;
  145.     rel_rot_segment(data->seg, data->rx, data->ry, data->rz, RYXZ);
  146.     update_segment(data->seg);
  147.     world_changed++;
  148.     break;
  149.      default:
  150.     break;
  151.    }
  152. }
  153.