home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include "Scenery.h"
- #include "Render.h"
- #include "MiscMath.h"
-
-
- typedef struct Mountain
- {
- float left[3], peak[3], right[3];
- float color[3];
- };
-
- static void init_mountains(Mountain m[], int num, float dist)
- {
- float angle = 0.0;
- srand48(0);
-
- for (int i = 0; i < num; i++)
- {
- angle += 2.0*M_PI/(float)num;
- float peak_angle = angle + drand48()/20.0;
- float left_angle = peak_angle - 4.0*M_PI/(float)num + drand48()/10.0;
- float right_angle = peak_angle + 4.0*M_PI/(float)num + drand48()/10.0;
-
- m[i].peak[0] = dist*fcos(peak_angle);
- m[i].peak[2] = dist*fsin(peak_angle);
-
- m[i].left[0] = dist*fcos(left_angle);
- m[i].left[2] = dist*fsin(left_angle);
-
- m[i].right[0] = dist*fcos(right_angle);
- m[i].right[2] = dist*fsin(right_angle);
-
- m[i].peak[1] = 400.0 + 100.0*drand48();
- m[i].left[1] = m[i].right[1] = -800.0;
-
- // random shades of dark green
- m[i].color[0] = drand48()/5.0;
- m[i].color[1] = .4 + drand48()/10.0;
- m[i].color[2] = drand48()/5.0;
- }
- }
-
- void draw_mountain(Mountain *mountain, int i)
- {
- c3f(mountain[i].color);
-
- bgnpolygon();
- v3f(mountain[i].right);
- v3f(mountain[i].peak);
- v3f(mountain[i].left);
- endpolygon();
- }
-
-
- void draw_mountains(float yaw, float dist, float fovx)
- {
- const int NUM_MOUNTAINS = 30;
- static Mountain *mountain = NULL;
-
- if (mountain == NULL)
- {
- mountain = new Mountain[NUM_MOUNTAINS];
- init_mountains(mountain, NUM_MOUNTAINS, dist);
- }
-
- long last_zbuffer = getzbuffer();
-
- if (yaw < 0)
- yaw += 2.0*M_PI;
-
- // turn yaw into mountain angle
- // mountains are 0 at +x, yaw is 0 at -z
- float angle = yaw - M_PI/2.0;
-
- float mountains_per_radian = (float)NUM_MOUNTAINS/(2.0*M_PI);
-
- int start = (int)((angle - fovx/2.0)*mountains_per_radian);
- int end = (int)((angle + fovx/2.0)*mountains_per_radian);
-
- // for safety's sake
- start -= 2;
- end += 2;
-
- if (start < 0)
- start += NUM_MOUNTAINS;
- if (end < 0)
- end += NUM_MOUNTAINS;
-
- int i;
-
- if (start < end)
- for (i = start; i <= end; i++)
- draw_mountain(mountain,i);
- else
- {
- for (i = start; i < NUM_MOUNTAINS; i++)
- draw_mountain(mountain,i);
- for (i = 0; i <= end; i++)
- draw_mountain(mountain,i);
- }
-
- zbuffer(last_zbuffer);
- }
-
-
- void draw_tree(int display_mode)
- {
- if (display_mode == RENDER_FILLED)
- lmbind(MATERIAL,WOOD);
- else
- cpack(0x4A75); // .46 .29 0.0 XXX
-
- pushmatrix();
- translate(0.0,12.0,0.0);
- scale(1.5,25.0,1.5);
- rotate(900,'x');
- if (display_mode == RENDER_FILLED)
- fcylinder();
- else
- wcylinder();
- popmatrix();
-
-
- if (display_mode == RENDER_FILLED)
- lmbind(MATERIAL,LEAVES);
- else
- cpack(0xFF10);
-
- pushmatrix();
- translate(0.0,32.0,0.0);
- scale(10.0,14.0,10.0);
- if (display_mode == RENDER_FILLED)
- fsphere();
- else
- wsphere();
- popmatrix();
- }
-
-
- void draw_pole(int display_mode)
- {
- if (display_mode == RENDER_FILLED)
- lmbind(MATERIAL,WOOD);
- else
- cpack(0x4A75); // .46 .29 0.0 XXX
-
- pushmatrix();
- translate(0.0,14.0,0.0);
- scale(0.5,30.0,0.5);
- rotate(900,'x');
- if (display_mode == RENDER_FILLED)
- fcylinder();
- else
- wcylinder();
- popmatrix();
-
- pushmatrix();
- translate(0.0,28.0,-1.0);
- scale(10.0,0.4,0.2);
- if (display_mode == RENDER_FILLED)
- fcube();
- else
- wcube();
- popmatrix();
-
- pushmatrix();
- translate(0.0,25.0,-1.0);
- scale(10.0,0.4,0.2);
- if (display_mode == RENDER_FILLED)
- fcube();
- else
- wcube();
- popmatrix();
-
- if (display_mode == RENDER_FILLED)
- lmbind(MATERIAL,0);
- }
-