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

  1. /* EXAMPLE7 -- Gouraud shading */
  2.  
  3. /* Written by Bernie Roehl, April 1995 */
  4.  
  5. #include "avril.h"
  6.  
  7. static void load_palette(char *filename)
  8.     {
  9.     FILE *infile = fopen(filename, "rb");
  10.     if (infile)
  11.         {
  12.         vrl_PaletteRead(infile, vrl_WorldGetPalette());
  13.         fclose(infile);
  14.         }
  15.     }
  16.  
  17. static vrl_Angle tumblerate;
  18.  
  19. void tumbler(void)
  20.     {
  21.     vrl_Object *obj = vrl_TaskGetData();
  22.     vrl_Angle amount = vrl_TaskGetElapsed() * tumblerate;
  23.     vrl_ObjectRotY(obj, amount);
  24.     vrl_ObjectRotX(obj, amount);
  25.     vrl_SystemRequestRefresh();
  26.     }
  27.  
  28. void main()
  29.     {
  30.     vrl_Shape *smooth_shape;
  31.     vrl_Object *thing;
  32.     vrl_Light *light;
  33.     vrl_Camera *camera;
  34.     vrl_Surface *surf;
  35.  
  36.     vrl_SystemStartup();
  37.     
  38.     load_palette("shade32.pal");
  39.  
  40.     smooth_shape = vrl_PrimitiveCylinder(100, 25, 200, 16, NULL);
  41.     vrl_ShapeComputeVertexNormals(smooth_shape);
  42.  
  43.     surf = vrl_SurfacemapGetSurface(vrl_ShapeGetSurfacemap(smooth_shape), 0);
  44.     vrl_SurfaceSetType(surf, VRL_SURF_GOURAUD);
  45.     vrl_SurfaceSetHue(surf, 4);
  46.     vrl_SurfaceSetBrightness(surf, 243);
  47.  
  48.     thing = vrl_ObjectCreate(smooth_shape);
  49.     vrl_ObjectRelMove(thing, 0, -100, 0);
  50.  
  51.     vrl_WorldSetAmbient(0);
  52.     light = vrl_LightCreate();
  53.     vrl_LightRotY(light, float2angle(45));
  54.  
  55.     camera = vrl_CameraCreate();
  56.     vrl_CameraMove(camera, 0, 0, -1400);
  57.  
  58.     tumblerate = float2angle(72.0 / vrl_TimerGetTickRate());
  59.     vrl_TaskCreate(tumbler, thing, 0);
  60.  
  61.     vrl_SystemRun();
  62.     }
  63.