home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / OpenGL / stonehenge / Ring.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.8 KB  |  144 lines

  1. /*
  2.  * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  * Permission to use, copy, modify, and distribute this software for
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  *
  25.  * US Government Users Restricted Rights
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37. #include <GL/glu.h>
  38. #include <GL/glx.h>
  39.  
  40. #include <math.h>
  41. #include <stdio.h>
  42.  
  43. #include "Ring.h"
  44.  
  45. inline float radians(float a) {return a * M_PI / 180.0;};
  46.  
  47. Ring::Ring() 
  48. {
  49.   Point sar_dim, lin_dim;
  50.  
  51.   radius = 10;
  52.  
  53.   nstones = 30;
  54.  
  55.   sar_dim.set(.2, .5, 1);
  56.   sarcen.set_dimensions(sar_dim);
  57.   sarcen.translate(radius, 0, sar_dim.pt[2]);
  58.  
  59.   angle = 360.0 / (float)nstones;
  60.  
  61.   lin_dim.set(.2, .99 * tan(2.0 * M_PI / (float)nstones) * 
  62.           (radius - sar_dim.pt[0]) / 2.0, .2);
  63.   lintel.set_dimensions(lin_dim);
  64.   lintel.translate(radius, 0, 2.*sar_dim.pt[2] + lin_dim.pt[2]);
  65. }
  66.  
  67.  
  68.  Ring::~Ring()
  69. {
  70. }
  71.  
  72. void Ring::erode(float p)
  73. {
  74.   sarcen.erode(p);
  75.   lintel.erode(p);
  76. }
  77.  
  78. void Ring::draw()
  79. {
  80.   draw_sarcens();
  81.   draw_lintels();
  82. }
  83.  
  84. void Ring::draw_sarcens()
  85. {
  86.   int i;
  87.   for (i = 0; i < nstones; i++) {
  88.     glPushMatrix();
  89.     glRotatef(i * angle, 0, 0, 1);
  90.     sarcen.draw();
  91.     glPopMatrix();
  92.   }
  93. }
  94.  
  95. void Ring::draw_lintels()
  96. {
  97.   int i;
  98.   glPushMatrix();
  99.   glRotatef(angle / 2.0, 0, 0, 1);
  100.   for (i = 0; i < nstones; i++) {
  101.     glPushMatrix();
  102.     glRotatef(i * angle, 0, 0, 1);
  103.     lintel.draw();
  104.     glPopMatrix();
  105.   }
  106.   glPopMatrix();
  107. }
  108.  
  109. void Ring::draw_shadow(Point dlight, GLfloat blur,
  110.                Color color, Color diffuse)
  111. {
  112.   draw_sarcens_shadows(dlight, blur, color, diffuse);
  113.   draw_lintels_shadows(dlight, blur, color, diffuse);
  114. }
  115.  
  116. void Ring::draw_sarcens_shadows(Point dlight, GLfloat blur,
  117.                 Color color, Color diffuse)
  118. {
  119.   int i;
  120.   Stone proto;
  121.  
  122.   proto = sarcen;
  123.   for (i = 0; i < nstones; i++) {
  124.     proto.rotate_self_aboutz(angle);
  125.     proto.draw_shadow(dlight, blur, color, diffuse);
  126.   }
  127. }
  128.  
  129. void Ring::draw_lintels_shadows(Point dlight, GLfloat blur,
  130.                 Color color, Color diffuse)
  131. {  
  132.   int i;
  133.   Stone proto;
  134.  
  135.   proto = lintel;
  136.  
  137.   proto.rotate_self_aboutz(angle / 2.0);
  138.  
  139.   for (i = 0; i < nstones; i++) {
  140.     proto.rotate_self_aboutz(angle);
  141.     proto.draw_shadow(dlight, blur, color, diffuse);
  142.   }
  143. }
  144.