📄 rc.c
字号:
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double floor(double o);
#define ACC 48
/* Some <math.h> files do not define M_PI... */
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define FOG
#define FOG_D 0.1
#define DIST 30
#define MESA_BUGGED
int rr=0;
int frame = 0;
GLfloat difmat1[4] = { 1.0, 0.4, 0.4, 1.0 };
GLfloat difamb1[4] = { 1.0, 0.4, 0.4, 1.0 };
GLfloat difmat2[4] = { 0.6, 0.6, 0.6, 1.0 };
GLfloat difamb2[4] = { 0.6, 0.6, 0.6, 1.0 };
GLfloat difmat3[4] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat difamb3[4] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat difmat4[4] = { 0.5, 0.5, 1.0, 1.0 };
GLfloat difamb4[4] = { 0.5, 0.5, 1.0, 1.0 };
GLfloat difmat5[4] = { 1.0, 1.0, 0.5, 1.0 };
GLfloat difamb5[4] = { 1.0, 1.0, 0.5, 1.0 };
GLfloat matspec1[4] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat matspec2[4] = { 0.774, 0.774, 0.774, 1.0 };
GLfloat matspec4[4] = { 0.5, 0.5, 1.0, 1.0 };
GLfloat dif_zwart[4] = { 0.3, 0.3, 0.3, 1.0 };
GLfloat amb_zwart[4] = { 0.4, 0.4, 0.4, 1.0 };
GLfloat spc_zwart[4] = { 0.4, 0.4, 0.4, 1.0 };
GLfloat dif_copper[4] = { 0.5, 0.3, 0.1, 1.0 };
GLfloat amb_copper[4] = { 0.2, 0.1, 0.0, 1.0 };
GLfloat spc_copper[4] = { 0.3, 0.1, 0.1, 1.0 };
GLfloat fogcol[4] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat hishin[1] = { 100.0 };
GLfloat loshin[1] = { 5.0 };
GLfloat lightpos[4] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat lightamb[4] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat lightdif[4] = { 0.8, 0.8, 0.8, 1.0 };
GLubyte texture[32][32][3];
GLubyte sky[32][32][3];
#if defined(_WIN32)
#define drand48() (((float) rand())/((float) RAND_MAX))
#endif
int rnd(int i)
{
return (int) ((double) drand48()*i);
}
void make_texture(void)
{
int i,j;
GLubyte r, g, b;
for (i=0;i<32;i++)
{
for (j=0;j<32;j++)
{
r = 100 + rnd(156);
g = 100 + rnd(156);
b = (b+g)/2 - rnd(100);
texture[i][j][0] = r/2;
texture[i][j][1] = g/2;
texture[i][j][2] = b/2;
r = rnd(100);
b = rnd(100)+156;
sky[i][j][1] = sky[i][j][0] = r;
sky[i][j][2] = b;
}
}
}
#define MAX 10000
extern int tot;
float plaatje = 0.0;
float speed = 0;
int angle = 0;
float angle2 = 0;
float angle3 = 0;
GLfloat x[MAX], y[MAX], z[MAX];
GLfloat dx[MAX], dy[MAX], dz[MAX];
GLfloat al[MAX], rl[MAX], hd[MAX], pt[MAX];
GLfloat strips[27][MAX][3], normal[27][MAX][3], bnormal[2][MAX][3];
GLdouble cum_al = 0.0, view_al = 0.0;
int opt[MAX];
GLfloat r1[MAX], r2[MAX], r3[MAX];
void copper_texture(void)
{
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, dif_copper);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, amb_copper);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spc_copper);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 13);
}
void groen_texture(void)
{
glMaterialfv(GL_FRONT, GL_DIFFUSE, difmat4);
glMaterialfv(GL_FRONT, GL_AMBIENT, difamb4);
glMaterialfv(GL_FRONT, GL_SPECULAR, matspec4);
glMaterialf(GL_FRONT, GL_SHININESS, 5.0);
}
void rood_texture(void)
{
glMaterialfv(GL_FRONT, GL_DIFFUSE, difmat1);
glMaterialfv(GL_FRONT, GL_AMBIENT, difamb1);
glMaterialfv(GL_FRONT, GL_SPECULAR, matspec1);
glMaterialf(GL_FRONT, GL_SHININESS, 0.1*128);
}
void metaal_texture(void)
{
glMaterialfv(GL_FRONT, GL_DIFFUSE, difmat2);
glMaterialfv(GL_FRONT, GL_AMBIENT, difamb2);
glMaterialfv(GL_FRONT, GL_SPECULAR, matspec2);
glMaterialf(GL_FRONT, GL_SHININESS, 0.6*128.0);
}
void wit_texture(void)
{
glMaterialfv(GL_FRONT, GL_DIFFUSE, difmat3);
glMaterialfv(GL_FRONT, GL_AMBIENT, difamb3);
glMaterialfv(GL_FRONT, GL_SPECULAR, matspec1);
glMaterialf(GL_FRONT, GL_SHININESS, 0.8*128.0);
}
void geel_texture(void)
{
glMaterialfv(GL_FRONT, GL_DIFFUSE, difmat5);
glMaterialfv(GL_FRONT, GL_AMBIENT, difamb5);
glMaterialfv(GL_FRONT, GL_SPECULAR, matspec1);
glMaterialf(GL_FRONT, GL_SHININESS, 0.8*128.0);
}
void zwart_texture(void)
{
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, dif_zwart);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, amb_zwart);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spc_zwart);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 90);
}
#define VERTEX(I,J) glNormal3fv(normal[I][J]); glVertex3fv(strips[I][J]);
void do_display (void)
{
int i,j,s,t, tmp;
cum_al = 0.0;
metaal_texture();
for (s=0;s<24;s += 2)
{
t = s+2;
if (!(t&7))
t=t-8;
if (s == 16)
rood_texture();
glBegin(GL_QUADS);
for (i=0;i<tot;i=j)
{
tmp = 0;
for (j=i+1;j<tot;j++)
if ((tmp=tmp+tmp+opt[j]) > 4000 || (!(j%(3*DIST))))
break;
if (j>=tot)
j = 0;
rr++;
VERTEX(s, j);
VERTEX(s, i);
VERTEX(t, i);
VERTEX(t, j);
if (!j)
break;
}
glEnd();
}
printf("Split up to %d parts.\n", rr);
rood_texture();
for (i=0;i<tot-2;i+=DIST)
{
if (!(i%(DIST*5)))
continue;
glBegin(GL_QUADS);
glNormal3fv(bnormal[0][i]);
glVertex3fv(strips[24][i]);
glVertex3fv(strips[24][i+5]);
glVertex3fv(strips[26][i+5]);
glVertex3fv(strips[26][i]);
glNormal3fv(bnormal[1][i]);
glVertex3fv(strips[25][i]);
glVertex3fv(strips[25][i+5]);
glVertex3fv(strips[26][i+5]);
glVertex3fv(strips[26][i]);
glEnd();
}
wit_texture();
for (i=0;i<tot-2;i+=DIST)
{
if (i%(DIST*5))
continue;
glBegin(GL_QUADS);
glNormal3fv(bnormal[0][i]);
glVertex3fv(strips[24][i]);
glVertex3fv(strips[24][i+5]);
glVertex3fv(strips[26][i+5]);
glVertex3fv(strips[26][i]);
glNormal3fv(bnormal[1][i]);
glVertex3fv(strips[25][i]);
glVertex3fv(strips[25][i+5]);
glVertex3fv(strips[26][i+5]);
glVertex3fv(strips[26][i]);
glEnd();
}
groen_texture();
glBegin(GL_QUADS);
for (i=0;i<tot;i+=90)
{
if (dy[i]<0.2)
continue;
glNormal3f(-1.0, 0.0, 0.0);
glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]-0.7);
glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]-0.2);
glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]+0.2);
glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]+0.7);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]+0.7);
glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]+0.2);
glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]+0.2);
glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]+0.7);
glNormal3f(0.0, 0.0, -1.0);
glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]-0.7);
glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]-0.2);
glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]-0.2);
glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]-0.7);
glNormal3f(1.0, 0.0, 0.0);
glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]-0.7);
glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]-0.2);
glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]+0.2);
glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]+0.7);
}
glEnd();
}
void do_one_wheel(void)
{
float a,p,q;
int i;
copper_texture();
glBegin(GL_QUAD_STRIP);
for (i=0;i<=ACC;i++)
{
a = i*M_PI*2/ACC;
p = cos(a);
q = sin(a);
glNormal3f(p, q, 0.4);
glVertex3f(0.7*p, 0.7*q, 0.8);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(0.8*p, 0.8*q, 0.7);
}
glEnd();
glBegin(GL_QUAD_STRIP);
for (i=0;i<=ACC;i++)
{
a = i*M_PI*2/ACC;
p = cos(a);
q = sin(a);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(0.7*p, 0.7*q, 0.8);
glVertex3f(0.6*p, 0.6*q, 0.8);
}
glEnd();
glBegin(GL_QUAD_STRIP);
for (i=0;i<=ACC;i++)
{
a = i*M_PI*2/ACC;
p = cos(a);
q = sin(a);
glNormal3f(-p, -q, 0.0);
glVertex3f(0.6*p, 0.6*q, 0.8);
glVertex3f(0.6*p, 0.6*q, 0.7);
}
glEnd();
glBegin(GL_QUADS);
for (i=0;i<=12;i++)
{
a = i*M_PI/6;
p = cos(a);
q = sin(a);
glNormal3f(p, q, 0.0);
glVertex3f(0.65*p + 0.08*q, 0.65*q + 0.08*p, 0.75);
glVertex3f(0.65*p - 0.08*q, 0.65*q - 0.08*p, 0.75);
glVertex3f(-0.08*q, -0.08*p, 0.95);
glVertex3f(0.08*q, 0.08*p, 0.95);
if (!i)
rood_texture();
}
zwart_texture();
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(0.1, 0.0, 0.8);
glVertex3f(-0.1, 0.0, 0.8);
glVertex3f(-0.1, 0.0, -0.8);
glVertex3f(0.1, 0.0, -0.8);
glNormal3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 0.1, 0.8);
glVertex3f(0.0, -0.1, 0.8);
glVertex3f(0.0, -0.1, -0.8);
glVertex3f(0.0, 0.1, -0.8);
glEnd();
}
void init_wheel(void)
{
glNewList(2, GL_COMPILE);
do_one_wheel();
glRotatef(180.0, 0.0, 1.0, 0.0);
do_one_wheel();
glRotatef(180.0, 0.0, 1.0, 0.0);
glEndList();
}
void display_wheel(float w)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -