-
Notifications
You must be signed in to change notification settings - Fork 0
/
carnival.c
executable file
·141 lines (117 loc) · 3.18 KB
/
carnival.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* Greg Bolsinga */
/* carnival rides animation project */
/* April 28, 1992 */
/* cs319 */
/* Prof Hearn */
/* SGI: compile using cc carnival.c -lgl_s -lm -o carnival */
/* Mac OS X: compile using cc -Wall *.c -framework OpenGL -framework GLUT -lobjc -o carnival */
/* ride the roller coaster by typing 'carnival -c' */
/* ride the ferris wheel by typing 'carnival -w' */
/* look around with 'carnival -l xl yl zl xa ya za' */
/* where (xl,yl,zl) is where you are, and */
/* (xa,ya,za) is where you are looking at. */
#include "carnival.h"
#include "tent.h"
#include "ferris.h"
#include "coaster.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Coord rollerin[350][3]; /* Coords for the inner rail */
Coord rollerout[350][3]; /* Coords for the outer rail */
/* The following is a function that assigns one 3D coordinate to another. */
void assignCoord(Coord a[3], Coord b[3])
{
int i;
for(i = 0; i < 3; i++)
{
a[i] = b[i];
}
}
/* The following calculates the average of two sets of 3D points. */
void avgPts(Coord a[3], Coord b[3], Coord result[3])
{
int i;
for(i = 0; i < 3; i++)
{
result[i] = (a[i] + b[i]) / 2.0;
}
}
/* This draws some mountains, which are very simple, so the animation */
/* isn't slowed down. */
void mountains(void)
{
Coord mnt1p[3] = {80, 50, 0 };
Coord mnt1b1[3] = {80, -1.0, -50 };
Coord mnt1b2[3] = {80, -1.0, 50 };
Coord mnt2p[3] = {75, 40, -20 };
Coord mnt2b1[3] = {75, -1.0, -40 };
Coord mnt2b2[3] = {75, -1.0, 0.0 };
Coord mnt3p[3] = {85, 45, -45 };
Coord mnt3b1[3] = {85, -1, -70 };
Coord mnt3b2[3] = {85, -1, -5 };
GLubyte brown[3] = {116, 87, 11 };
GLubyte snow[3] = {196, 196, 196 };
glBegin(GL_POLYGON);
glColor3ubv(brown);
glVertex3fv(mnt1b1);
glVertex3fv(mnt1b2);
glColor3ubv(snow);
glVertex3fv(mnt1p);
glEnd();
glBegin(GL_POLYGON);
glColor3ubv(brown);
glVertex3fv(mnt2b1);
glVertex3fv(mnt2b2);
glColor3ubv(snow);
glVertex3fv(mnt2p);
glEnd();
glBegin(GL_POLYGON);
glColor3ubv(brown);
glVertex3fv(mnt3b1);
glVertex3fv(mnt3b2);
glColor3ubv(snow);
glVertex3fv(mnt3p);
glEnd();
}
/* The folowing draws the entire scene. It takes the current rotation */
/* of the ferris wheel and the number of points in the roller coaster */
/* arrays. It returns the position of the ferris wheel rider. */
void drawScene(Coord rotation, int rollPts, Coord fwv[3])
{
Coord gr1[3] = {100, -1.0, 100 };
Coord gr2[3] = {100, -1.0, -100 };
Coord gr3[3] = {-100, -1.0, -100 };
Coord gr4[3] = {-100, -1.0, 100 };
GLubyte grass[3] = {123, 193, 87 };
/* Draw the ground */
glColor3ubv(grass);
glBegin(GL_POLYGON);
glVertex3fv(gr1);
glVertex3fv(gr2);
glVertex3fv(gr3);
glVertex3fv(gr4);
glEnd();
/* Draw some mountains */
mountains();
coaster(rollPts);
glPushMatrix();
glTranslatef(-25.0, 6.5, 0.0);
ferris(rotation, fwv);
fwv[0] += -25.0;
fwv[1] += 6.5;
glPopMatrix();
glPushMatrix();
glTranslatef(17, -1.0, -8);
glRotatef(0.1 * (-900), 0, 1, 0);
tent();
glPopMatrix();
glPushMatrix();
glTranslatef(-22, -1, -11);
tent();
glPopMatrix();
/*
for(i=0; i<100000; i++);
*/
/* return the position of the ferris wheel rider */
}