16
16
#include "rotator.h"
18
#define DEF_DELAY "15000"
19
#define DEF_DISKS "0" /* < 2 means 3-12 */
20
#define DEF_WIRE "False"
21
18
#define DEF_LIGHT "True"
22
#define DEF_FPS "False"
23
19
#define DEF_FOG "False"
24
20
#define DEF_TEXTURE "True"
26
#define DEFAULTS "*delay: " DEF_DELAY "\n" \
27
"*count: " DEF_DISKS "\n" \
28
"*showFPS: " DEF_FPS "\n" \
29
"*wireframe: " DEF_WIRE "\n"
22
#define DEFAULTS "*delay: 15000\n" \
31
27
# define refresh_glhanoi 0
594
592
* people's hardware supports 3D textures, so I didn't bother (xorg
595
593
* ATI server doesn't :-( )
597
static void drawTube(GLdouble bottomRadius, GLdouble topRadius,
595
static int drawTube(GLdouble bottomRadius, GLdouble topRadius,
598
596
GLdouble bottomThickness, GLdouble topThickness,
599
597
GLdouble height, GLuint nSlice, GLuint nLoop)
602
601
GLfloat *cosCache = malloc(sizeof(GLfloat) * nSlice);
603
602
GLfloat *sinCache = malloc(sizeof(GLfloat) * nSlice);
684
684
upperRadius * cosCache[slice]);
685
685
glVertex3f(lowerRadius * sinCache[slice], lowerY,
686
686
lowerRadius * cosCache[slice]);
688
689
glNormal3f(0.0, 0.0, 1.0);
689
690
glVertex3f(0.0, upperY, upperRadius);
690
691
glVertex3f(0.0, lowerY, lowerRadius);
722
725
innerRadius * cosCache[slice]);
724
727
glVertex3f(radius * sinCache[slice], y, radius * cosCache[slice]);
726
730
glVertex3f(0.0, y, innerRadius);
727
731
glVertex3f(0.0, y, radius);
731
static void drawPole(GLfloat radius, GLfloat length)
733
drawTube(radius, radius, radius, radius, length, NSLICE, NLOOPS);
736
static void drawDisk3D(GLdouble inner_radius, GLdouble outer_radius,
739
drawTube(outer_radius, outer_radius, outer_radius - inner_radius,
740
outer_radius - inner_radius, height, NSLICE, NLOOPS);
743
static void drawCuboid(GLfloat length, GLfloat width, GLfloat height)
736
static int drawPole(GLfloat radius, GLfloat length)
738
return drawTube(radius, radius, radius, radius, length, NSLICE, NLOOPS);
741
static int drawDisk3D(GLdouble inner_radius, GLdouble outer_radius,
744
return drawTube(outer_radius, outer_radius, outer_radius - inner_radius,
745
outer_radius - inner_radius, height, NSLICE, NLOOPS);
748
static int drawCuboid(GLfloat length, GLfloat width, GLfloat height)
745
750
GLfloat xmin = -length / 2.0f;
746
751
GLfloat xmax = length / 2.0f;
756
762
glVertex3f(xmax, ymin, zmax); /* 1 */
757
763
glVertex3f(xmax, ymax, zmax); /* 2 */
758
764
glVertex3f(xmin, ymax, zmax); /* 3 */
760
767
glNormal3fv(right);
761
768
glVertex3f(xmax, ymin, zmax); /* 1 */
762
769
glVertex3f(xmax, ymin, zmin); /* 5 */
763
770
glVertex3f(xmax, ymax, zmin); /* 6 */
764
771
glVertex3f(xmax, ymax, zmax); /* 2 */
766
774
glNormal3fv(back);
767
775
glVertex3f(xmax, ymin, zmin); /* 5 */
768
776
glVertex3f(xmin, ymin, zmin); /* 4 */
769
777
glVertex3f(xmin, ymax, zmin); /* 7 */
770
778
glVertex3f(xmax, ymax, zmin); /* 6 */
772
781
glNormal3fv(left);
773
782
glVertex3f(xmin, ymin, zmin); /* 4 */
774
783
glVertex3f(xmin, ymin, zmax); /* 0 */
775
784
glVertex3f(xmin, ymax, zmax); /* 3 */
776
785
glVertex3f(xmin, ymax, zmin); /* 7 */
779
789
glVertex3f(xmin, ymax, zmax); /* 3 */
780
790
glVertex3f(xmax, ymax, zmax); /* 2 */
781
791
glVertex3f(xmax, ymax, zmin); /* 6 */
782
792
glVertex3f(xmin, ymax, zmin); /* 7 */
784
795
glNormal3fv(down);
785
796
glVertex3f(xmin, ymin, zmin); /* 4 */
786
797
glVertex3f(xmax, ymin, zmin); /* 5 */
787
798
glVertex3f(xmax, ymin, zmax); /* 1 */
788
799
glVertex3f(xmin, ymin, zmax); /* 0 */
792
static void drawDisks(glhcfg *glhanoi)
805
static int drawDisks(glhcfg *glhanoi)
797
811
glTranslatef(0.0f, glhanoi->baseHeight, 0.0f);
1152
1170
glNewList(glhanoi->baseList, GL_COMPILE);
1153
1171
setMaterial(baseColor, cWhite, 50);
1154
drawCuboid(glhanoi->baseLength, glhanoi->baseWidth,
1155
glhanoi->baseHeight);
1172
glhanoi->basepolys = drawCuboid(glhanoi->baseLength, glhanoi->baseWidth,
1173
glhanoi->baseHeight);
1164
1182
glPushMatrix();
1165
1183
glTranslatef(0.0f, glhanoi->baseHeight, 0.0f);
1166
1184
setMaterial(poleColor, cWhite, 50);
1167
drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
1185
glhanoi->polepolys = drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
1168
1186
glPushMatrix();
1169
1187
glTranslatef(-glhanoi->poleOffset, 0.0, 0.0);
1170
drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
1188
glhanoi->polepolys += drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
1172
1190
glTranslatef(glhanoi->poleOffset, 0.0, 0.0);
1173
drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
1191
glhanoi->polepolys += drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
1230
1249
glNewList(disk->displayList, GL_COMPILE);
1231
1250
setMaterial(color, cWhite, 100.0);
1232
drawDisk3D(glhanoi->poleRadius,
1233
getDiskRadius(glhanoi, i),
1234
glhanoi->diskHeight);
1251
disk->polys += drawDisk3D(glhanoi->poleRadius,
1252
getDiskRadius(glhanoi, i),
1253
glhanoi->diskHeight);
1237
1256
for(i = glhanoi->maxDiskIdx; i >= 0; --i) {
1266
static void drawFloor(glhcfg *glhanoi)
1285
static int drawFloor(glhcfg *glhanoi)
1268
1287
glCallList(glhanoi->floorList);
1288
return glhanoi->floorpolys;
1271
static void drawTowers(glhcfg *glhanoi)
1291
static int drawTowers(glhcfg *glhanoi)
1273
1293
glCallList(glhanoi->baseList);
1274
1294
glCallList(glhanoi->poleList);
1295
return glhanoi->basepolys + glhanoi->polepolys;
1277
1298
/* Window management, etc