/* Copyright (c) James C. Bowman, 1997. * * With user interface code from Mark J. Kilgard. * 'drawCube' and 'drawTorus' by David Yu. */ /* This program is freely distributable without licensing fees and is provided without guarantee or warrantee expressed or implied. This program is -not- in the public domain. */ #include #include #include #include /* for cos(), sin(), and sqrt() */ #include #include #include "trackball.h" #ifndef M_PI #define M_PI 3.1415926f #endif /************************************************************************/ static GLboolean lighting = GL_TRUE; /* Enable lighting passes */ static GLboolean specular = GL_TRUE; /* Enable specular lighting */ static GLboolean drifting = GL_FALSE; /* Enable texture movement */ static GLboolean linear = GL_FALSE; /* Enable linear filtering */ static GLboolean useDepth = GL_FALSE; /* Enable depth buffering */ static GLuint object = 0; /* Which object to draw */ static int texWidth = 16, texHeight = 16; /* Small texture */ static int texChannels = 1; /* tex color channels 1-4 */ static GLuint octaves = 3; /* How many octaves of noise */ #define NUM_OBJECTS 2 void drawCube(void) { glBegin(GL_QUADS); glNormal3f(-1.0F, 0.0F, 0.0F); glTexCoord2f( 0.0F, 1.0F); glVertex3f(-0.5F,-0.5F,-0.5F); glTexCoord2f( 0.0F, 0.0F); glVertex3f(-0.5F,-0.5F, 0.5F); glTexCoord2f( 1.0F, 0.0F); glVertex3f(-0.5F, 0.5F, 0.5F); glTexCoord2f( 1.0F, 1.0F); glVertex3f(-0.5F, 0.5F,-0.5F); glNormal3f( 1.0F, 0.0F, 0.0F); glTexCoord2f( 1.0F, 1.0F); glVertex3f( 0.5F, 0.5F, 0.5F); glTexCoord2f( 0.0F, 1.0F); glVertex3f( 0.5F,-0.5F, 0.5F); glTexCoord2f( 0.0F, 0.0F); glVertex3f( 0.5F,-0.5F,-0.5F); glTexCoord2f( 1.0F, 0.0F); glVertex3f( 0.5F, 0.5F,-0.5F); glNormal3f( 0.0F,-1.0F, 0.0F); glTexCoord2f( 0.0F, 1.0F); glVertex3f(-0.5F,-0.5F,-0.5F); glTexCoord2f( 0.0F, 0.0F); glVertex3f( 0.5F,-0.5F,-0.5F); glTexCoord2f( 1.0F, 0.0F); glVertex3f( 0.5F,-0.5F, 0.5F); glTexCoord2f( 1.0F, 1.0F); glVertex3f(-0.5F,-0.5F, 0.5F); glNormal3f( 0.0F, 1.0F, 0.0F); glTexCoord2f( 1.0F, 1.0F); glVertex3f( 0.5F, 0.5F, 0.5F); glTexCoord2f( 0.0F, 1.0F); glVertex3f( 0.5F, 0.5F,-0.5F); glTexCoord2f( 0.0F, 0.0F); glVertex3f(-0.5F, 0.5F,-0.5F); glTexCoord2f( 1.0F, 0.0F); glVertex3f(-0.5F, 0.5F, 0.5F); glNormal3f( 0.0F, 0.0F,-1.0F); glTexCoord2f( 0.0F, 1.0F); glVertex3f(-0.5F,-0.5F,-0.5F); glTexCoord2f( 0.0F, 0.0F); glVertex3f(-0.5F, 0.5F,-0.5F); glTexCoord2f( 1.0F, 0.0F); glVertex3f( 0.5F, 0.5F,-0.5F); glTexCoord2f( 1.0F, 1.0F); glVertex3f( 0.5F,-0.5F,-0.5F); glNormal3f( 0.0F, 0.0F, 1.0F); glTexCoord2f( 1.0F, 1.0F); glVertex3f( 0.5F, 0.5F, 0.5F); glTexCoord2f( 0.0F, 1.0F); glVertex3f(-0.5F, 0.5F, 0.5F); glTexCoord2f( 0.0F, 0.0F); glVertex3f(-0.5F,-0.5F, 0.5F); glTexCoord2f( 1.0F, 0.0F); glVertex3f( 0.5F,-0.5F, 0.5F); glEnd(); } void drawTorus(void) { int numMajor = 20; int numMinor = 20; float majorRadius = 0.6F; float minorRadius = 0.2F; double majorStep = 2.0F*M_PI / numMajor; double minorStep = 2.0F*M_PI / numMinor; int i, j; for (i=0; i