Выбрать главу

 case 2: // Drawing Object 3

  gluDisk(quadratic,0.5f,1.5f,32,32); // Draw A Disc (CD Shape)

  break; // Done

Our fourth object is an object that I know many of you have been dying to figure out. The Sphere! This one is quite simple. The first parameter is the radius of the sphere. In case you're not familiar with radius/diameter, etc, the radius is the distance from the center of the object to the outside of the object. In this case our radius is 1.3f. Next we have our subdivision "around" the Z axis (32), and our subdivision "along" the Z axis (32). The more subdivisions you have the smoother the sphere will look. Spheres usually require quite a few subdivisions to make them look smooth.

 case 3: // Drawing Object 4

  gluSphere(quadratic,1.3f,32,32); // Draw A Sphere

  break; // Done

Our fifth object is created using the same command that we used to create a Cylinder. If you remember, when we were creating the Cylinder the first two parameters controlled the radius of the cylinder at the bottom and the top. To make a cone it makes sense that all we'd have to do is make the radius at one end Zero. This will create a point at one end. So in the code below, we make the radius at the top of the cylinder equal zero. This creates our point, which also creates our cone.

 case 4: // Drawing Object 5

  glTranslatef(0.0f,0.0f,-1.5f); // Center The Cone

  gluCylinder(quadratic, 1.0f, 0.0f, 3.0f, 32, 32); // A Cone With A Bottom Radius Of .5 And A Height Of 2

  break; // Done

Our sixth object is created with gluPartialDisc. The object we create using this command will look exactly like the disc we created above, but with the command gluPartialDisk there are two new parameters. The fifth parameter (part1) is the start angle we want to start drawing the disc at. The sixth parameter is the sweep angle. The sweep angle is the distance we travel from the current angle. We'll increase the sweep angle, which causes the disc to be slowly drawn to the screen in a clockwise direction. Once our sweep hits 360 degrees we start to increase the start angle. the makes it appear as if the disc is being erased, then we start all over again!

 case 5: // Drawing Object 6

  part1+=p1; // Increase Start Angle

  part2+=p2; // Increase Sweep Angle

  if (part1>359) // 360 Degrees

  {

   p1=0; // Stop Increasing Start Angle

   part1=0; // Set Start Angle To Zero

   p2=1; // Start Increasing Sweep Angle

   part2=0; // Start Sweep Angle At Zero

  }

  if (part2>359) // 360 Degrees

  {

   p1=1; // Start Increasing Start Angle

   p2=0; // Stop Increasing Sweep Angle

  }

  gluPartialDisk(quadratic, 0.5f, 1.5f, 32, 32, part1, part2-part1); // A Disk Like The One Before

  break; // Done

 };

 xrot+=xspeed; // Increase Rotation On X Axis

 yrot+=yspeed; // Increase Rotation On Y Axis

 return TRUE; // Keep Going

}

In the KillGLWindow() section of code, we need to delete the quadratic to free up system resources. We do this with the command gluDeleteQuadratic.

GLvoid KillGLWindow(GLvoid) // Properly Kill The Window

{

 gluDeleteQuadric(quadratic); // Delete Quadratic – Free Resources

Now for the final part, they key input. Just add this where we check the rest of key input.

 if (keys[' '] && !sp) // Is Spacebar Being Pressed?

 {

  sp=TRUE; // If So, Set sp To TRUE

  object++; // Cycle Through The Objects

  if (object>5) // Is object Greater Than 5?

   object=0; // If So, Set To Zero

 }

 if (!keys[' ']) // Has The Spacebar Been Released?

 {

  sp=FALSE; // If So, Set sp To FALSE

 }

Thats all! Now you can draw quadrics in OpenGL. Some really impressive things can be done with morphing and quadrics. The animated disc is an example of simple morphing.

Everyone if you have time go check out my website, TipTup.Com 2000.

GB Schmick (TipTup)
Jeff Molofee (NeHe)

* DOWNLOAD Visual C++ Code For This Lesson.

* DOWNLOAD Borland C++ Code For This Lesson. (Conversion by Patrick Salmons)

* DOWNLOAD Cygwin Code For This Lesson. (Conversion by Stephan Ferraro)

* DOWNLOAD Delphi Code For This Lesson. (Conversion by Marc Aarts)

* DOWNLOAD Game GLUT Code For This Lesson. (Conversion by Milikas Anastasios)

* DOWNLOAD Irix / GLUT Code For This Lesson. (Conversion by Rob Fletcher)

* DOWNLOAD Java Code For This Lesson. (Conversion by Jeff Kirby)

* DOWNLOAD Linux Code For This Lesson. (Conversion by Simon Werner)

* DOWNLOAD Linux/GLX Code For This Lesson. (Conversion by Mihael Vrbanec)

* DOWNLOAD Linux/SDL Code For This Lesson. (Conversion by Ti Leggett)

* DOWNLOAD Mac OS Code For This Lesson. (Conversion by Anthony Parker)

* DOWNLOAD Mac OS X/Cocoa Code For This Lesson. (Conversion by Bryan Blackburn)