⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rc.c

📁 学习c++必备
💻 C
📖 第 1 页 / 共 2 页
字号:
{    int ww = w;    glPopMatrix();    glPushMatrix();    glTranslatef(x[ww], y[ww], z[ww]);    glRotatef(r3[ww]*180/M_PI, 0.0, 0.0, 1.0);    glRotatef(-r2[ww]*180/M_PI, 0.0, 1.0, 0.0);    glRotatef(r1[ww]*180/M_PI, 1.0, 0.0, 0.0);    glTranslatef(-0.15*(w-ww), 0.8, 0.0);    glRotatef(-w, 0.0, 0.0, 1.0);    glCallList(2);    glRotatef(w, 0.0, 0.0, 1.0);    glTranslatef(0.0, -0.8, 0.0);    zwart_texture();    glBegin(GL_QUADS);    glNormal3f(0.0, 1.0, 0.0);    glVertex3f(-0.3, 1.1, 0.3);    glVertex3f(1.0, 1.1, 0.3);    glVertex3f(1.0, 1.1, -0.3);    glVertex3f(0.3, 1.1, -0.3);    glEnd();}void display_cart(float w){    display_wheel(w);    geel_texture();    glEnable(GL_AUTO_NORMAL);    glEnable(GL_NORMALIZE);    glBegin(GL_QUADS);    glNormal3f(0.0, 1.0, 0.0);    glVertex3f(0.5, 0.8, -0.70);    glVertex3f(0.5, 0.8, 0.70);    glVertex3f(-2.0, 0.8, 0.70);    glVertex3f(-2.0, 0.8, -0.70);    glNormal3f(1.0, 0.0, 0.0);    glVertex3f(-2.0, 0.8, -0.70);    glVertex3f(-2.0, 0.8, 0.70);    glVertex3f(-2.0, 2.3, 0.70);    glVertex3f(-2.0, 2.3, -0.70);    glNormal3f(0.71, 0.71, 0.0);    glVertex3f(-2.0, 2.3, -0.70);    glVertex3f(-2.0, 2.3, 0.70);    glVertex3f(-1.7, 2.0, 0.70);    glVertex3f(-1.7, 2.0, -0.70);    glNormal3f(0.12, 0.03, 0.0);    glVertex3f(-1.7, 2.0, -0.70);    glVertex3f(-1.7, 2.0, 0.70);    glVertex3f(-1.4, 0.8, 0.70);    glVertex3f(-1.4, 0.8, -0.70);    glNormal3f(0.0, 1.0, 0.0);    glVertex3f(-1.4, 0.8, -0.70);    glVertex3f(-1.4, 0.8, 0.70);    glVertex3f(0.0, 0.8, 0.70);    glVertex3f(0.0, 0.8, -0.70);    glNormal3f(1.0, 0.0, 0.0);    glVertex3f(0.0, 0.8, -0.70);    glVertex3f(0.0, 0.8, 0.70);    glVertex3f(0.0, 1.5, 0.70);    glVertex3f(0.0, 1.5, -0.70);    glNormal3f(0.5, 0.3, 0.0);    glVertex3f(0.0, 1.5, -0.70);    glVertex3f(0.0, 1.5, 0.70);    glVertex3f(-0.5, 1.8, 0.70);    glVertex3f(-0.5, 1.8, -0.70);    glNormal3f(1.0, 0.0, 0.0);    glVertex3f(-0.5, 1.8, -0.70);    glVertex3f(-0.5, 1.8, 0.70);    glVertex3f(-0.5, 0.8, 0.70);    glVertex3f(-0.5, 0.8, -0.70);    zwart_texture();    glNormal3f(0.0, 0.0, 1.0);    glVertex3f(-1.8, 0.8, 0.70);    glVertex3f(-1.8, 1.3, 0.70);    glVertex3f(0.0, 1.3, 0.70);    glVertex3f(0.0, 0.8, 0.70);    glVertex3f(-1.8, 0.8, -0.70);    glVertex3f(-1.8, 1.6, -0.70);    glVertex3f(0.0, 1.4, -0.70);    glVertex3f(0.0, 0.8, -0.70);    glVertex3f(-2.0, 0.8, 0.70);    glVertex3f(-2.0, 2.3, 0.70);    glVertex3f(-1.7, 2.0, 0.70);    glVertex3f(-1.4, 0.8, 0.70);    glVertex3f(-2.0, 0.8, -0.70);    glVertex3f(-2.0, 2.3, -0.70);    glVertex3f(-1.7, 2.0, -0.70);    glVertex3f(-1.4, 0.8, -0.70);    glVertex3f(0.0, 0.8, -0.70);    glVertex3f(0.0, 1.5, -0.70);    glVertex3f(-0.5, 1.8, -0.70);    glVertex3f(-0.5, 0.8, -0.70);    glVertex3f(0.0, 0.8, 0.70);    glVertex3f(0.0, 1.5, 0.70);    glVertex3f(-0.5, 1.8, 0.70);    glVertex3f(-0.5, 0.8, 0.70);    glEnd();}void display(void){    int plaatje2, l;    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glPushMatrix();    glCallList(1);    glPopMatrix();    glPushMatrix();    glEnable(GL_TEXTURE_2D);    glTexImage2D(GL_TEXTURE_2D, 0, 3, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE,	&texture[0][0][0]);    glBegin(GL_QUADS);    glNormal3f(0.0, 1.0, 0.0);    glTexCoord2f(0.0, 0.0); glVertex3f(-120, -4.1, -120);    glTexCoord2f(0.0, 1.0); glVertex3f(-120, -4.1, 120);    glTexCoord2f(1.0, 1.0); glVertex3f(120, -4.1, 120);    glTexCoord2f(1.0, 0.0); glVertex3f(120, -4.1, -120);    glEnd();    glDisable(GL_TEXTURE_2D);/* The sky moves with us to give a perception of being infinitely far away */    groen_texture();    l = plaatje;    glBegin(GL_QUADS);    glNormal3f(0.0, 1.0, 0.0);    glTexCoord2f(0.0, 0.0);    glVertex3f(-400+x[l], 21+y[l], -400+z[l]);    glTexCoord2f(0.0, 1.0);    glVertex3f(-400+x[l], 21+y[l], 400+z[l]);    glTexCoord2f(1.0, 1.0);    glVertex3f(400+x[l], 21+y[l], 400+z[l]);    glTexCoord2f(1.0, 0.0);    glVertex3f(400+x[l], 21+y[l], -400+z[l]);    glEnd();    display_cart(plaatje);    plaatje2 = plaatje + 40;    if (plaatje2 >= tot)	plaatje2 -= tot;    display_cart(plaatje2);    plaatje2 = plaatje + 20;    if (plaatje2 >= tot)	plaatje2 -= tot;    display_cart(plaatje2);    plaatje2 = plaatje - 20;    if (plaatje2 < 0)	plaatje2 += tot;    display_wheel(plaatje2);    glFlush();    glutSwapBuffers();    glPopMatrix();}void myinit (void) {    glShadeModel (GL_SMOOTH);    glFrontFace(GL_CCW);    glEnable(GL_DEPTH_TEST);    glClearColor(fogcol[0], fogcol[1], fogcol[2], fogcol[3]);    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);    glLightfv(GL_LIGHT0, GL_AMBIENT, lightamb);    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightdif);    glEnable(GL_LIGHTING);    glEnable(GL_LIGHT0);    glColor3f(1.0, 1.0, 1.0);    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);#ifdef FOG/* fog */    glEnable(GL_FOG);    glFogi(GL_FOG_MODE, GL_LINEAR);    glFogfv(GL_FOG_COLOR, fogcol);    glFogf(GL_FOG_DENSITY, 0.01);    glFogf(GL_FOG_START, 0.01);    glFogf(GL_FOG_END, 55.0);    glHint(GL_FOG_HINT, GL_NICEST);#endif    make_texture();    init_wheel();    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);/*    glTexImage2D(GL_TEXTURE_2D, 0, 3, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE,	&texture[0][0][0]);*/    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);}/* ARGSUSED1 */void parsekey(unsigned char key, int x, int y){    switch (key)    {	case 27: exit(0);	case 13: speed = 0; break;    }}/* ARGSUSED1 */void parsekey_special(int key, int x, int y){    switch (key)    {	case GLUT_KEY_UP:	speed ++; break;	case GLUT_KEY_DOWN:	speed --; break;	case GLUT_KEY_RIGHT:	angle ++; break;	case GLUT_KEY_LEFT:	angle --; break;    }}void SetCamera(void){    float plaatje2;    int l,l2;    l = plaatje;    plaatje2 = plaatje + 10;    if (plaatje2 >= tot)	plaatje2 -= tot;    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    glFrustum (-0.1, 0.1, -0.1, 0.1, 0.1, 550.0);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();#if 1    glTranslated(0.0, +0.4, 0.0);    glRotated(angle*5.0, 0.0, 1.0, 0.0);    glTranslatef(0.0, 0.0, -6.5-2*sin(angle2)-sin(angle3));    glRotatef(45 - 35*cos(angle3), 1.0, 0.0, 0.0);    glRotatef(-100*sin(angle3), 0.0, 1.0, 0.0);#else    glRotatef(100*sin(angle3), 0.0, 1.0, 0.0);    glRotatef(-45 + 35*cos(angle3), 1.0, 0.0, 0.0);    glTranslatef(0.0, 0.0, +6+2*sin(angle2)+sin(angle3));    glRotated(-angle*5.0, 0.0, 1.0, 0.0);    glTranslated(0.0, -0.4, 0.0);#endif    l2 = plaatje2;    glTranslatef(-0.15*(plaatje-l), 0.0, 0.0);    gluLookAt(x[l], y[l], z[l],	x[l2], y[l2], z[l2],	dx[l], dy[l], dz[l]);}void Animate(void){    int l1;    l1 = plaatje;    speed += (y[l1] - y[l1+4])*2-0.005;    speed -= (fabs(rl[l1]-al[l1]) + fabs(pt[l1]) + fabs(hd[l1])) * speed/200;    if (frame > 450)	speed -= 0.2208;    if (speed < 0)	speed = 0;    if (frame < 10)	speed = 0;    if (frame == 10)	speed = 4.5;    if (frame > 155 && frame < 195)	speed = 7.72;    plaatje += speed;    if (plaatje >= tot) {	plaatje = tot - 1;	glutIdleFunc(NULL);	return;    }    if (plaatje < 0)	plaatje += tot;    SetCamera();    angle2 = frame*4*M_PI/503;    angle3 = frame*6*M_PI/503;    glutPostRedisplay();    frame++;}void myReshape(int w, int h){    SetCamera();    glViewport (0, 0, w, h);}int main(int argc, char *argv[]){    int sz;    extern void calculate_rc(void);    calculate_rc();    printf("tot = %d\n", tot);    if (argc > 1)	sz = atoi(argv[1]);    else	sz = 200;    glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE | GLUT_MULTISAMPLE);    glutInitWindowPosition(200, 0);    glutInitWindowSize(sz, sz);    glutCreateWindow("Roller coaster");    glNewList(1, GL_COMPILE);    do_display();    glEndList();    glutDisplayFunc(display);    glutKeyboardFunc(parsekey);    glutSpecialFunc(parsekey_special);    glutReshapeFunc(myReshape);    glutIdleFunc(Animate);    myinit();    glutSwapBuffers();    glutMainLoop();    return 0;             /* ANSI C requires main to return int. */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -