Three Help Notes to assist in using SDL: (for ece660, 11/18/99)

1). The code for makeLightsOpenGL(), which scans the light list formed by SDL, and tells OpenGL about them;

2). Code for the TaperedCylinder shape.

3). A suggestion to simplify how SDL deals with dodecahedron, icosahedron, octahedron, and

tetrahedron, so it needn't read in a 3vn data file.


1). When an SDL file is read in, a list of light sources is made. The makeLightsOpenGL() method is called once thereafter to inform OpenGL about these lights.

//<<<<<<<<<<<<<<<<< makeLightsOpenGL >>>>>>>>>>>>>>>
void Scene:: makeLightsOpenGL()
{// build lights from scene's light list
  /* in GL.h: GL_LIGHT0..GL_LIGHT7 are defined as consecutive ints from 0x4000 to 0x4007 */

int num, lightNum = GL_LIGHT0;
Light *p;
float colr[4], posn[4]; // arrays to hold openGL color and position
for(p = light, num = 0; p && num < 8; p = p-> next, lightNum++, num++)
{ // set up to 8 OpenGL lights glEnable(lightNum);
(p->color).build4tuple(colr);
(p->pos).build4tuple(posn);
glLightfv(lightNum,GL_DIFFUSE,colr);
glLightfv(lightNum,GL_SPECULAR,colr);
glLightfv(lightNum,GL_POSITION,posn);
}
} // end of makeLightsOpenGL

2). And here is an improvement (11/30/99) to the TaperedCylinder class. You can replace the extant class in SDL.h with this. A tapered cylinder now has fields for pointers to the relevant quadrics of which it is composed, and the constructor creates quadric objects for each. The whole thing goes onto the SDL object list like any other object. Now each time the cylinder is drawn a new object is not created: it's just drawn.

class TaperedCylinder : public Shape{
private:
  GLUquadricObj * pwall; // OpenGL needs pointers to quadric objects
  GLUquadricObj * pbase;
  GLUquadricObj * pcap;
public:
  float smallRadius;
  TaperedCylinder() // constructor
  { //make the quadrics once only.
   pwall = gluNewQuadric(); //make a cylinder
   pbase = gluNewQuadric(); //make a cylinder
   pcap  = gluNewQuadric(); //make a cylinder
         gluQuadricDrawStyle(pwall,GLU_FILL);
         gluQuadricDrawStyle(pbase,GLU_FILL);
         gluQuadricDrawStyle(pcap, GLU_FILL);
  }
 void drawOpenGL()
 {
          tellMaterialsGL();
          glPushMatrix();
            glMultMatrixf(transf.m);
            glEnable(GL_NORMALIZE);
      gluCylinder(pwall,1.0,smallRadius,1.0, 30,4); // draw the cylinder wall
            glPushMatrix();
        glScalef(1, 1, -1); //flip base so normals point outside
        gluDisk(pbase, 0, 1, 30, 8); // draw base at z = 0
            glPopMatrix();
      glTranslatef(0,0,1);
            gluDisk(pcap, 0, smallRadius, 30, 8); //draw cap at z = 1
          glPopMatrix();
 }
};


3). As SDL is currently configured, it builds a Mesh object for the four Platonic solids: the dodecahedron, icosahedron, octahedron, and tetrahedron. This is useful if you need to wrap textures about them. But it means that you need to have the various 3vn files such as tetra.3vn, icosa.3vn, etc. in your current directory. (These can be found on the course FTP site in \3VNModels.) But say you wish to simplify SDL so that no mesh is created for the dodecahedron but instead the drawing tool glutSolidDodecahedron() is called to draw it. Here are the changes required. Similar changes would be used for the icosahedron, octahedron, and tetrahedron.

in SDL.CPP change:
case DODECAHEDRON: newShape = new Mesh("dodeca.3vn"); break;
to:
case DODECAHEDRON: newShape = new Dodecahedron; break;
and in SDL.h add a new class:
//<<<<<<<<<<<<<<< Dodecahedron class >>>>>>>>>>>>>>>>>>
class Dodecahedron : public Shape{
public:
void drawOpenGL() //tell how to draw it
{

tellMaterialsGL(); glPushMatrix();
glMultMatrixf(transf.m);
glutSolidDodecahedron();
glPopMatrix();
}
Dodecahedron() { }// constructor need not do anything
};

 I hope this helps,

Sandy