CSIT 540 Assignment 2 -- Hierarchical Modeling

In this assignment you define a 3D model and display it. Use OpenGL to create and display a character of your own design. Then you will become familiar with 3D rendering pipeline, 3D hierarchical modeling and transformations.
  1. Setup a 3D model by hierarchical modeling in OpenGL. Such model should be composed of primitive shapes (box, generalized cylinder, sphere, and triangle). It should use at least 10 primitives and at least 4 levels of hierarchy. You must also use at least one each of the glTranslate(), glRotate() and glScale() calls to position these primitives in space (and you will probably use many of all of them!) You must also use glPushMatrix() and glPopMatrix() to nest your matrix transformations.
     
  2. Display the model you design using OpenGL. You may need to set up the camera matrix, some lighting and material attributes of the model in order to display it correctly.
  1. Save and load the model that you design. (4 pts)
     
  2. Use more than 2 lights. (4 pts)
     
  3. Make the camera of the application adjustable. E.g. translation, rotation or scaling. (4 pts)
     
  4. Add some UI, such as dialog box or slider, keyboard control or mouse interaction to control the translation, the rotation and the scale of the primitive. (4 pts)
     
  5. Use dynamic data structure to store the primitive which support adding or deleting primitive in run time. (4 pts)
     
  6. Select the primitive by mouse. You need to highlight the selected primitive or just output a sentence on the command line to indicate a primitive is selected. (4 pts) If you can do something more, such as transformation, deletion or assigning material, after the primitive are picked, you can get more bonus depending on how good you can do (+2 pts, e.g. If you combine optional requirement 4 and 6 together, at most you can get 4+4+2=10 pts as bonus). You can also do hierarchy picking. What I mean is that the user can pick a vertex, an edge, a face or a primitive. Some bonus can also be given if you can do this (+2 pts).
     
  7. Implement a simple "L-system" with some parameter to control the output of the "L-system".(4 pts) There are 2 links for the information about "L-system". The first one is a java applet http://www.javaview.de/vgp/tutor/lsystem/PaLSystem.html. It shows you what "L-system" is and how "L-system" works. You can play with the parameters on "Num Iterations" and "Angle". The other one is a general introduction to "L-system" http://en.wikipedia.org/wiki/L-system.
     
  8. If you have implemented something interesting and you think it can be regarded as bonus, please email me to determine whether it is regarded as a bonus.
RequirementPercentages
Project Requirement 150%
Project Requirement 230%
Optional Requirement20%
  • The source code should be able to be compiled with visual C++ 6, visual studio 2003/2005 or visual C++ express. If you are using other development environment. Please let me know before you hand in the assignment and remind me of whether there is any special required library used in the assignment.
  • The executable file should be able to run on Windows 2000/XP. If you write the program on Linux or other OS, please let me know.
  • The brief description can be in any popular text file format, such as doc, pdf and txt. The brief description should cover the following content:
    1. Your name and student ID.
    2. How to compile your program? If your program is written with the tools and library I mention, just write which tools you use.
    3. How to run your program?
    4. Where do you put your code to complete the requirement 1 (Which function and which file)? How many levels of hierarchy and how many primitive do you use?
    5. For the bonuses, please list which features are implemented and describe how these features are implemented briefly. (ATTENTION: I won't search your code for hidden features to give bonus, so you should list the bonus you try to get clearly.)
Q&A: I will post the answers to some important questions that you ask me.
  1. Q: I use Visual C++ Express. When I compile the sample. The compiler reported that it can't find "GL/gl.h".

    A: Visual C++ Express doesn't contain any library that is used to build windows-based application. In order to use the features provided by Windows, e.g. Windows GUI and OpenGL, please follow this webpage to install Platform SDK for Windows, http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/.
    If you don't know how to do the step 3, please follow these steps:
    • Run visual C++
    • Go to "Tools" -> "Options..."
    • Expand the "Projects and Solutions" item on the tree panel on the left of the "options" dialog.
    • Select "VC++ directories" under "Projects and Solutions" item which you just expanded.
    • Now you can select appropriate filter for the directories on the top-right drop-down list control which is labeled with "Show directories for:"
    • Add the corresponding path using the "New Line" button below the drop-down list control.
    • Repeat step E and F until you add up all these three paths:
      Executable files: C:/Program Files/Microsoft Platform SDK for Windows Server 2003 R2/Bin
      Include files: C:/Program Files/Microsoft Platform SDK for Windows Server 2003 R2/Include
      Library files: C:/Program Files/Microsoft Platform SDK for Windows Server 2003 R2/Lib
     
  2. Q: I downloaded the example code from the course webpage but I cannot even execute the exe files. It says cannot find the glut.dll.

    A: This is the website for the GLUT (The OpenGL Utility Toolkit).
    http://www.xmission.com/~nate/glut.html
    You can download the lib there. There is also some useful documentation about GLUT on this website. Please take a look at them.
     
     
  3. Q: How to install GLUT?

    A: This guideline works for Visual Studio.NET 2003/2005 and Visual C++ Express.
    I assume that your windows is installed in %WINDOWS%. The platform SDK is installed in %PLATFORMSDK%. If you don't know where your platform SDK is, please find it in the installation folder of your visual studio 2003/2005 C++.
    I. Download the lib from that webpage.
    II. Unpackage the zip file, and you will see 5 files. They are: glut32.dll, glut32.lib, glut.def, glut.h and readme-win32.txt.
    III. Put glut32.dll into %WINDOWS%/System.
          Put glut.h into %PLATFORMSDK%/Include/GL.
          Put glut32.lib into %PLATFORMSDK%/Lib.
     
  4. Q: There is an error about redefinition of exit(), when I was compiling sample.

    A: You can solve this conflict as below:
    I. Open the glut.h file.
    II. find the line with "extern _CRTIMP void __cdecl exit(int);"
    III. Replace it as "extern _CRTIMP __declspec(noreturn) void __cdecl exit(int);".
    Done!
     
  5. Q: Are we meant to be able to start with the assignment at this stage? So far we have not seen the code to pop up a window to implement OpenGL? It is better if we can know how to create a window to do OpenGL.

    A: Sure. Here is a website containing lots of useful sample which will help you finish this assignment.
    http://www.opengl.org/resources/code/samples/redbook/
    I highly recommend you to start from sample "aargb" and sample "light". Please make sure that you can compile the "aargb" sample with GLUT. Then you can play with "light" sample. At the beginning, you'd better not modify the parameters for lighting and material. You focus on how to change the sphere in the "light" sample to your model. After you setup your model, you can modify the parameters for lighting and material and see what you will get. Have fun. :)
     
  6. Q: I am completely new to visual studio 2003/2005/visual C++ Express, how can I start to compile a source code?

    A: Here is a walkthrough to get started with visual studio/visual C++. It is only for new users of these tools; and it's not the only way that can compile the sample with these tools. I take the "aargb" sample in Q&A 5 for example.
    • You should create a project in order to compile the source code. Create a new "Wn32 console Application" project by menu "File"->"New"->"Project". Then select "Console Application" and "Empty project" in the application setting of the "Win32 Application Wizard".
    • After the project is created, add the aargb.c to the project by menu "Project"->"Add existing item". You can also add a new file by menu "Project"->"Add new item".
    • If you install all the things correctly as I mention in Q&A 1~4, you can now build the executable file with menu "Build"->"build solution".
    • Under the debug menu, use the "Start debugging" to run the program with debug function, such as break point or step by step debug, or use the "Start without debugging" to run the program without debug function.
    • The executable exe file can be found in the debug/release folder of the solution folder.

  7. Q: How can I get started with OpenGL?

    A: The red book (OpenGL Programming Guide) is a tutorial-style book, which is excellent for learning OpenGL. The first several chapters (at least chapter 1~3. the more, the better) and the samples I mention above will help you to do the assignment.
     
  8. Q: What do the glXXX APIs mean in the sample code given in Question 2?

    A: In addition to the tutorial-style the red book http://fly.cc.fer.hr/~unreal/theredbook/, you can find out what the APIs exactly mean in the reference-style document http://alien.dowling.edu/~vassil/thebluebook/ 

 

我的代码

看了5天的OPENGL资料终于用一天时间搞定。还有些要求没做到,比如存储读取模型,动态模型添加删除,还有个L-system。

/*
Assignment2, produce by Stone-Chen Yi
Version 2.0

3 light sources, they can be controlled
dependent by keyboard(1,2,3 and space) or mouse(right button then display a menu)

lamp can be controlled by keyboard(x,y,z,X,Y,Z)

wire sphere and cone can be controlled by mouse(middle button)

the whole scene can be controlled by keyboard(a,d,w,s)

can add or delete the balls which floats in the air by mouse(right button)
*/

#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>


static int spin = 0, spin1=0;
static float light_x = 0.0,light_y=0.0, light_z = 0.4;
static float plane_go = 0.0, plane_move = 0.0;
static float ball_z=0.4;
static int wire_angle=0, ball_count=5;

static float m=1.0;
static int light0 =1, light1=1, light2=1;


   GLuint listName;

   GLfloat normal_mat_ambient[]= { 0.8, 0.2, 0.2, 1.0 };
   GLfloat normal_mat_diffuse[]= { 0.8, 0.8, 0.8, 1.0 };
   GLfloat normal_mat_specular[] = { 0.1, 0.1, 0.1, 1.0 };
   GLfloat normal_mat_shininess[] = { 5.0 };

   GLfloat desk_mat_ambient[]= { 0.2, 0.4, 0.0, 1.0 };
   GLfloat desk_mat_diffuse[]= { 0.0, 0.3, 0.8, 1.0 };
   GLfloat desk_mat_specular[] = { 0.0, 0.0, 0.0, 0.0 };
   GLfloat desk_mat_shininess[] = { 10.0 };

   GLfloat cy_mat_ambient[]= { 0.2, 0.4, 0.0, 1.0 };
   GLfloat cy_mat_diffuse[]= { 1.0, 1.0, 0.0, 1.0 };
   GLfloat cy_mat_specular[] = { 0.0, 0.0, 0.0, 0.0 };
   GLfloat cy_mat_shininess[] = { 0.0 };

   GLUquadricObj *pobj;

void desk(void){
 glMaterialfv(GL_FRONT, GL_AMBIENT, desk_mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, desk_mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, desk_mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, desk_mat_shininess);
    glutSolidCube(1.0);
}

void lampholder(void){
 glColor3f (0.2, 0.6, 0.8);
    pobj=gluNewQuadric();
    gluQuadricDrawStyle(pobj,GLU_FILL);//indicate draw model(GL_POINT,GL_LINE or GL_FILL)
    gluCylinder( pobj,0.5,0.06,0.1,36,16); //Cylinder
}

void downlampstander(void){
 glColor3f (0.2, 0.2, 0.2);
    pobj=gluNewQuadric();
    gluQuadricDrawStyle(pobj,GLU_FILL);//indicate draw model(GL_POINT,GL_LINE or GL_FILL)
    gluCylinder( pobj,0.06,0.06, light_z,36,16); //Cylinder
}

void connectionball(void){
 glColor3f (0.2, 0.2, 0.6); 
    glutSolidSphere(0.1,36,36);
}

void uplampstander(void){
    glColor3f (0.2, 0.2, 0.2); 
    pobj=gluNewQuadric();
    gluQuadricDrawStyle(pobj,GLU_FILL);//indicate draw model(GL_POINT,GL_LINE or GL_FILL)
    gluCylinder( pobj,0.06,0.06, 0.6,36,16);
}

void lampshade(void){
 glColor3f (0.6, 0.6, 0.8);
    pobj=gluNewQuadric();
    gluQuadricDrawStyle(pobj,GLU_FILL);//indicate draw model(GL_POINT,GL_LINE or GL_FILL)
    gluCylinder( pobj,0.6,0.2,0.2,36,16); //Cylinder
}

void lampshadecover(void){
    glColor3f (0.6, 0.6, 0.6);
    glutSolidSphere (0.16,16,16);
    glColor3f (0.6, 0.6, 0.8);
    pobj=gluNewQuadric();
    gluQuadricDrawStyle(pobj,GLU_FILL);//indicate draw model(GL_POINT,GL_LINE or GL_FILL)
    gluDisk( pobj,0.0,0.2,36,16);  //Circle disk
}

void solidsphere(void){
 glTranslatef(0.0, 0.0, ball_z);
    glutSolidSphere(0.2,36,36);
}

void torus(void){
    glMaterialfv(GL_FRONT, GL_AMBIENT, normal_mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, normal_mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, normal_mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, normal_mat_shininess);
    glutSolidTorus (0.125, 0.45, 8, 35);
}

void cylinder(void){
 glTranslatef(1.0, 0.0, 2.8);
    glMaterialfv(GL_FRONT, GL_AMBIENT, cy_mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, cy_mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, cy_mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, cy_mat_shininess);
    pobj=gluNewQuadric();
    gluQuadricDrawStyle(pobj,GLU_FILL);//indicate draw model(GL_POINT,GL_LINE or GL_FILL)
    gluCylinder( pobj,0.6,0.6,0.2,36,36); //Cylinder
}

void wirecone(void){
     glRotatef(-90,1.0,0.0,0.0);
     glMaterialfv(GL_FRONT, GL_AMBIENT, normal_mat_ambient);
     glMaterialfv(GL_FRONT, GL_DIFFUSE, normal_mat_diffuse);
     glMaterialfv(GL_FRONT, GL_SPECULAR, normal_mat_specular);
     glMaterialfv(GL_FRONT, GL_SHININESS, normal_mat_shininess);
     glutWireCone(0.3,0.5,16,36);
}

void wiresphere(void){
 glTranslatef(0.0, 0.9, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, normal_mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, normal_mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, normal_mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, normal_mat_shininess);
    pobj=gluNewQuadric();
    gluQuadricDrawStyle(pobj,GLU_LINE);//indicate draw model(GLU_LINE)
    gluSphere(pobj,0.4,40,40);
}

void teapot(void){
 glTranslatef(0.0, -0.5, 1.0);
    glutSolidTeapot(0.3);
}

void init(void)
{
   //put the wire sphere into the list
   listName = glGenLists (1);
   glNewList (listName, GL_COMPILE);
      glColor3f (1.0, 0.0, 0.0);  /*  current color red  */
      glutWireSphere(0.1,36,36);
      glTranslatef (0.5, 0.0, 0.0); /*  move position  */
   glEndList ();

   //light1
   GLfloat light1_ambient[]= { 0.2, 0.2, 0.2, 1.0 };
   GLfloat light1_diffuse[]= { 1.0, 0.0, 0.0, 1.0 };
   GLfloat light1_specular[] = { 1.0, 0.6, 0.6, 1.0 };
   GLfloat light1_position[] = { 15.0, 9.0, -16.0, 1.0 };

   glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
   glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
   glLightfv(GL_LIGHT1, GL_SPECULAR,light1_specular);
   glLightfv(GL_LIGHT1, GL_POSITION,light1_position);

   //light2
   GLfloat light2_ambient[]= { 0.2, 0.2, 0.2, 1.0 };
   GLfloat light2_diffuse[]= { 0.0, 0.0, 1.0, 1.0};
   GLfloat light2_specular[] = { 1.0, 0.6, 0.6, 1.0 };
   GLfloat light2_position[] = {-4.0, 0.0, 15.0, 1.0};

   glLightfv(GL_LIGHT2, GL_AMBIENT, light2_ambient);
   glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_diffuse);
   glLightfv(GL_LIGHT2, GL_SPECULAR,light2_specular);
   glLightfv(GL_LIGHT2, GL_POSITION, light2_position);


   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel (GL_SMOOTH);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_LIGHT1);
   glEnable(GL_LIGHT2);
   glEnable(GL_DEPTH_TEST);
}

 

void display(void)
{
   GLfloat light0_diffuse[]= { 0.0, 1.0, 0.0, 1.0 };
   GLfloat position[] = { 2.0, 1.0, 1.0, 1.0 };

   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);

   glPushMatrix ();

       //lighting source turnning
       glPushMatrix ();
           glRotated ((GLdouble) spin, 0.0, 1.0, 0.0);
           glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
           glLightfv (GL_LIGHT0, GL_POSITION, position);
 
           glTranslated (1.0, 1.0, 2.0);

           glDisable (GL_LIGHTING);
           glColor3f (0.1, 0.1, 0.1);
           glutSolidSphere (0.03,16,16);
           glEnable (GL_LIGHTING);
       glPopMatrix ();

       //X,Y,Z coordinate lines may help me move, rotate.
       glEnable (GL_LINE_STIPPLE);
       glLineStipple (1, 0x1111);  /*  dotted  */
       glColor3f (0.0, 0.0, 1.0);
       glBegin(GL_LINES); 
       glVertex3f (0.0, 0.0, 0.0);
       glVertex3f (0.0, 0.0, 5.0);
       glEnd();
       glLineStipple (1, 0xA1A1);
       glColor3f (0.0, 1.0, 0.0);
       glBegin(GL_LINES); 
       glVertex3f (0.0, 0.0, 0.0);
       glVertex3f (0.0, 5.0, 0.0);
       glEnd();
       glLineStipple (1, 0xAAAA);
       glColor3f (1.0, 0.0, 0.0);
       glBegin(GL_LINES); 
       glVertex3f (0.0, 0.0, 0.0);
       glVertex3f (5.0, 0.0, 0.0);
       glEnd();
  
    //
       gluLookAt (4.0, 1.0, 4.0, 0.0, 0.0, 0.0, -1.0, 1.0, -1.0);
  
       //move front, back, left, right
       glTranslatef((plane_move/sqrt(2.0))+(plane_go/sqrt(2.0)),0.0,(plane_go/sqrt(2.0))-(plane_move/sqrt(2.0)));
       glPushMatrix ();
           glPushMatrix ();
               glTranslatef(-1.0, -1.0, -1.0); //move the model down
               glRotatef (-90.0, 1.0, 0.0, 0.0 ); //turn the model
 
               //desk
               glPushMatrix ();
                   glScalef(4.0, 4.0,0.02);
                   desk();
               glPopMatrix ();

               glTranslatef(light_x, light_y, 0.0);
      glDisable (GL_LIGHTING);
               glPushMatrix ();
                   //lamp holder                  
                   lampholder();
               glPopMatrix ();

               glPushMatrix ();
                   //down lampstander
                   downlampstander();
               glPopMatrix ();

               glTranslatef(0.0, 0.0, light_z-0.2);
               //connection ball
               connectionball();

               //up lampstander
               glPushMatrix ();
                   uplampstander();
               glPopMatrix ();
      glEnable (GL_LIGHTING);

               glTranslatef(0.0, 0.0, 0.4);
               //lampshade
               glPushMatrix ();
                   lampshade();
               glPopMatrix ();

               glTranslatef(0.0, 0.0, 0.2);
               //cover of lampshade and ball
               glPushMatrix ();
       lampshadecover();
               glPopMatrix ();

               //solidsphere
      glPushMatrix ();
                   solidsphere();
               glPopMatrix ();

               //SolidTorus
               glTranslatef(-1.0, 0.0, -0.8);
               glPushMatrix ();
                   torus();
               glPopMatrix ();

         //Cylinder
               glPushMatrix ();
                   cylinder();
               glPopMatrix ();
              
           glPopMatrix ();

     glPushMatrix ();
         glTranslatef(1.2, -0.5, 0.2);
      glRotatef(wire_angle,0.0,1.0,0.0);
         //wire Cone
               glPushMatrix ();
             wirecone();
               glPopMatrix ();

               //wire sphere
               glPushMatrix ();
                   wiresphere();
               glPopMatrix ();
     glPopMatrix ();
 
           //teapot
           glPushMatrix ();
               teapot();
           glPopMatrix ();

           //get 5 wire sphere from the list
           glPushMatrix ();
               glTranslatef(-2.5, 1.5, -2.5);
               glRotatef(45+spin1,0.0,1.0,0.0);
               GLuint i;
               for (i = 0; i < ball_count; i++)   
                    glCallList (listName);
           glPopMatrix ();
       glPopMatrix ();
   glPopMatrix ();
  
   glFlush ();
   glutSwapBuffers();
}

void reshape (int w, int h)
{
   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity();
   gluPerspective(40.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}

//still some problems when it moves. the screen always twinkle
void balljump(){
 while(ball_z<2.0){
    ball_z= ball_z+0.01;
    display();
 }
   
}

void mouse(int button, int state, int x, int y)
{
   switch (button) {
      case GLUT_LEFT_BUTTON:
         if (state == GLUT_DOWN) {
            spin1 = (spin1 + 30) % 360;
            glutPostRedisplay();
         }
         break;
    case GLUT_MIDDLE_BUTTON:
         if (state == GLUT_DOWN) {
            wire_angle = (wire_angle + 30) % 360;
            glutPostRedisplay();
         }
         break;
      default:
         break;
   }
}

void keyboard(unsigned char key, int x, int y)
{
   switch (key) {
      case 'w':
         plane_go = plane_go-0.2;
         display();
         break;
      case 's':
         plane_go = plane_go+0.2;
         display();
         break;
      case 'd':
         plane_move = plane_move+0.2;
         display();
         break;
      case 'a':
         plane_move = plane_move-0.2;
         display();
         break;
      case 'x':
         light_x = light_x+0.2;
         display();
         break;
      case 'X':
         light_x = light_x-0.2;
         display();
         break;
      case 'y':
         light_y = light_y+0.2;
         display();
         break;
      case 'Y':
         light_y = light_y-0.2;
         display();
         break;
      case 'z':
         light_z= light_z +0.1;
         display();
         break;
      case 'Z':
         light_z = light_z-0.1;
         display();
         break;
   case '1':
    if(light0==1){
              glDisable(GL_LIGHT0);
     light0=0;
    }
    else if(light0==0){
                 glEnable(GL_LIGHT0);
        light0=1;
    }
    display();
          break;
   case '2':
          if(light1==1){
    
              glDisable(GL_LIGHT1);
     light1=0;
    }
    else if(light1==0){
                 glEnable(GL_LIGHT1);
        light1=1;
    }
    display();
          break;
   case '3':
          if(light2==1){
              glDisable(GL_LIGHT2);
     light2=0;
    }
    else if(light2==0){
                 glEnable(GL_LIGHT2);
        light2=1;
    }
    display();
          break;
      case 32:
    spin = (spin + 30) % 360;
          glutPostRedisplay();
       display();
          break;
      case 27:
         exit(0);
         break;
   }
}

void menu(int id)
{
 if (id==0)  {
  glEnable(GL_LIGHT1);
  light1=1;
  display();
 }
 else if (id==1)  {
  glDisable(GL_LIGHT1);
  light1=0;
  display();
 }
 else if (id==2)  {
  glEnable(GL_LIGHT2);
  light2=1;
  display();
 }
 else if (id==3)  {
  glDisable(GL_LIGHT2);
  light2=0;
  display();
 }
    else if (id==4)  {
  glEnable(GL_LIGHT0);
  light0=1;
  display();
 }
 else if (id==5)  {
  glDisable(GL_LIGHT0);
  light0=0;
  display();
 }
 else if (id==6)  {
  ball_count=ball_count+1;
  display();
 }
 else if (id==7)  {
  ball_count=ball_count-1;
  display();
 }
 else if (id==8)  {
  balljump();}

    else if (id==10)  {
  exit(0);
 }
   
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
   glutInitWindowSize (700, 700);
   glutInitWindowPosition (300, 300);
   glutCreateWindow("Created by Chen Yi, 06769098");
   //glutCreateWindow (argv[0]);
   init ();
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutMouseFunc(mouse);
   glutKeyboardFunc(keyboard);

   glutCreateMenu(menu);
   glutAddMenuEntry("light0 on", 4);
   glutAddMenuEntry("light0 off", 5);
   glutAddMenuEntry("light1 on", 0);
   glutAddMenuEntry("light1 off", 1);
   glutAddMenuEntry("light2 on", 2);
   glutAddMenuEntry("light2 off", 3);
   glutAddMenuEntry("add ball", 6);
   glutAddMenuEntry("delete ball", 7);
   glutAddMenuEntry("ball jump", 8);
   glutAddMenuEntry("quit", 10);
   glutAttachMenu(GLUT_RIGHT_BUTTON);

   glutMainLoop();
   return 0;
}
 

运行结果:

整个平台可以前后左右移动,其他的部分分别可以绕某个轴转动或者上下左右前后移动

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值