资源简介

利用键盘控制汽进、后退、转弯、加速和减速;车前 制作一个弹出菜单,上面的菜单项用来控制车身和车轮的颜色以及退出程序。 定义对应于ReShape事件的回调函数,使得当用户改变窗口的大小时,显示的汽车不会变形。

资源截图

代码片段和文件信息

#include
#include
#include 
#include 
#include 
#include
float delta_v=0.0;
float r=1.0g=1.0b=0.0;
float r1=0.0g1=0.0b1=0.0;
float P[16];
float M[16];


//************ 光线及材质的定义**************

GLfloat light_ambient[]={0.0 0.0 0.0 1.0};
GLfloat light_diffuse[]={1.0 1.0 1.0 1.0};
GLfloat light_specular[]={1.0 1.0 1.0 1.0};
GLfloat light_position[]={20.0 20.0 20.0 0.0};
GLfloat mat_specular1[]={1.0 1.0 1.0 1.0};
GLfloat mat_diffuse1[]={1.0 1.0 1.0 1.0};
GLfloat mat_ambient1[]={1.0 1.0 1.0 1.0};
GLfloat mat_shininess1={10.0};
GLfloat global_ambient[]={0.10.10.10.1};
GLfloat vertices[ ] [3] ={{-0.701}{0.701}{0.70-1}{-0.70-1}{-0.510.8}{0.510.8}{0.51-0.8} {-0.51-0.8}};



void menu(int id){
switch(id)
 {
 case (1):
 exit(0);
 break;
}
     glutPostRedisplay();
}

//***********车身颜色变化菜单************

void color_car_body_menu(int id)
{
     
switch(id){

case(1):
         r=1.0;g=0.0;b=0.0;
break;

    case(2):
    r=0.0;g=1.0;b=0.0; 
    break;

    case(3): 
r=0.0;g=0.0;b=1.0; 
break;

    case(4):
r=0.9;g=0.1;b=0.6; 
    break;

    case(5):
    r=0.7;g=0.5;b=0.1;    
    break;

case(6):
r=1.0;g=0.0;b=0.0; 
break;
}
 glutPostRedisplay();

}

//************车轮颜色变化菜单***************

void color_car_wheel_menu(int id)
{
     
switch(id){

    case(1):
         r1=0.0;g1=0.5;b1=1.0;
break;

    case(2):
     r1=0.7;g1=0.8;b1=0.4; 
    break;

    case(3):
 r1=0.7;g1=0.0;b1=0.0; 
break;

    case(4):
         r1=0.9;g1=0.1;b1=0.6; 
    break;

case(5):
     r1=0.7;g1=0.5;b1=0.1;    
break;

case(6):
 r1=0.7;g1=1.0;b1=0.6; 
    break;
}
 glutPostRedisplay();

}

//******************定义跑道*********************
void runway()
{  glBegin(GL_QUADS);   
glColor3f(0.0f0.8f0.0f); 
   glVertex3f(-3.0f -0.3f 100.0f);  
glColor3f(0.0f0.8f0.0f); 
   glVertex3f( -0.8f -0.3f 100.0f);
glColor3f(0.0f0.8f0.0f); 
   glVertex3f( -0.8f-0.3f -100.0f);
glColor3f(0.0f0.8f0.0f); 
   glVertex3f(-3.0f-0.3f -100.0f);     
   glEnd();    


   glBegin(GL_QUADS);   
glColor3f(0.0f0.8f0.0f);  
   glVertex3f(0.8f -0.3f 100.0f);  
 glColor3f(0.0f0.8f0.0f); 
   glVertex3f( 3.0f -0.3f 100.0f);
 glColor3f(0.0f0.8f0.0f);  
   glVertex3f( 3.0f-0.3f -100.0f);
 glColor3f(0.0f0.8f0.0f);  
   glVertex3f(0.8f-0.3f -100.0f);     
   glEnd(); 



   glBegin(GL_QUADS);   
 glColor3f(0.9f1.0f0.9f);  
   glVertex3f(-0.8f-0.3f 100.0f);  
 glColor3f(0.9f1.0f0.9f);  
   glVertex3f( 0.8f -0.3f 100.0f);
 glColor3f(0.9f1.0f0.9f);  
   glVertex3f( 0.8f-0.3f -100.0f);
 glColor3f(0.9f1.0f0.9f);   
   glVertex3f(-0.8f-0.3f -100.0f);     
glEnd();  
}


//*************画车身**************

void quad(int aint b int c int d)
{
glBegin(GL_QUADS);
    
    glVertex3fv(vertices[a]);
 

评论

共有 条评论