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 */
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
{
I hope this helps,
Sandy