-/* glschool_gl.c, Copyright (c) 2005-2006 David C. Lambert <dcl@panix.com>
+/* glschool_gl.c, Copyright (c) 2005-2012 David C. Lambert <dcl@panix.com>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
#include "sphere.h"
#include "glschool_gl.h"
+#include "sphere.h"
#include "tube.h"
-static GLUquadricObj *Quadratic;
-
void
drawGoal(double *goal, GLuint goalList)
{
glPopMatrix();
}
-void
+int
drawBoundingBox(BBox *bbox, Bool wire)
{
+ int polys = 0;
double xMin = BBOX_XMIN(bbox);
double yMin = BBOX_YMIN(bbox);
double zMin = BBOX_ZMIN(bbox);
glVertex3f(xMax, yMin, zMin);
glVertex3f(xMax, yMax, zMin);
glVertex3f(xMin, yMax, zMin);
+ polys++;
glEnd();
/* left */
glVertex3f(xMin, yMin, zMin);
glVertex3f(xMin, yMax, zMin);
glVertex3f(xMin, yMax, zMax);
+ polys++;
glEnd();
/* right */
glVertex3f(xMax, yMin, zMax);
glVertex3f(xMax, yMax, zMax);
glVertex3f(xMax, yMax, zMin);
+ polys++;
glEnd();
/* top */
glVertex3f(xMin, yMax, zMax);
glVertex3f(xMin, yMax, zMin);
glVertex3f(xMax, yMax, zMin);
+ polys++;
glEnd();
/* bottom */
glVertex3f(xMax, yMin, zMax);
glVertex3f(xMax, yMin, zMin);
glVertex3f(xMin, yMin, zMin);
+ polys++;
glEnd();
if (wire) glLineWidth(1.0);
+
+ return polys;
}
-void
+int
createBBoxList(BBox *bbox, GLuint *bboxList, int wire)
{
+ int polys = 0;
*bboxList = glGenLists(1);
glNewList(*bboxList, GL_COMPILE);
- drawBoundingBox(bbox, wire);
+ polys = drawBoundingBox(bbox, wire);
glEndList();
+ return polys;
}
-#if 1
void
-createDrawLists(BBox *bbox, GLuint *bboxList, GLuint *goalList, GLuint *fishList, int wire)
+createDrawLists(BBox *bbox, GLuint *bboxList, GLuint *goalList, GLuint *fishList, int *fish_polys, int *box_polys, int wire)
{
- if (Quadratic == (GLUquadricObj *)0) return;
-
- gluQuadricDrawStyle(Quadratic, (wire ? GLU_LINE : GLU_FILL));
- createBBoxList(bbox, bboxList, wire);
+ int faces = 16;
- *goalList = glGenLists(1);
- glNewList(*goalList, GL_COMPILE);
- gluSphere(Quadratic, 5.0, 10, 10);
- glEndList();
+ *box_polys = 0;
+ *fish_polys = 0;
- *fishList = glGenLists(1);
- glNewList(*fishList, GL_COMPILE);
-#if 0
- gluSphere(Quadratic, 2.0, 10, 5);
- gluCylinder(Quadratic, 2.0, 0.0, 10.0, 10, 5);
-#else
- gluSphere(Quadratic, 2.0, 3, 2);
- gluCylinder(Quadratic, 2.0, 0.0, 10.0, 3, 2);
-#endif
- glEndList();
-}
+ *box_polys += createBBoxList(bbox, bboxList, wire);
-#else
-void
-createDrawLists(BBox *bbox, GLuint *bboxList, GLuint *goalList, GLuint *fishList, Bool wire)
-{
- createBBoxList(bbox, bboxList, wire);
+ *box_polys = 0;
+ *fish_polys = 0;
*goalList = glGenLists(1);
glNewList(*goalList, GL_COMPILE);
- glScalef(10.0, 10.0, 10.0);
- unit_sphere(10, 10, wire);
+ glScalef (5, 5, 5);
+ *box_polys += unit_sphere (10, 10, wire);
glEndList();
*fishList = glGenLists(1);
glNewList(*fishList, GL_COMPILE);
- glScalef(2.0, 2.0, 2.0);
- unit_sphere(10, 10, wire);
- cone(0, 0, 0,
- 0, 0, 5,
- 1, 0, 10,
- True, False, wire);
+ *fish_polys += cone (0, 0, 0,
+ 0, 0, 10,
+ 2, 0,
+ faces, True, (faces <= 3), /* cap */
+ wire);
+ glTranslatef (0, 0, -0.3);
+ glScalef (2, 2, 2);
+ glRotatef (90, 1, 0, 0);
+ if (faces > 3)
+ *fish_polys += unit_sphere (faces, faces, wire);
glEndList();
}
-#endif
void
initLights(void)
initLights();
if (doFog) initFog();
-
- Quadratic = gluNewQuadric();
}
void
void
drawSchool(XColor *colors, School *s,
GLuint bboxList, GLuint goalList, GLuint fishList,
- int rotCounter, Bool drawGoal_p, Bool drawBBox_p)
+ int rotCounter, Bool drawGoal_p, Bool drawBBox_p,
+ int fish_polys, int box_polys, unsigned long *polys)
{
double xVect[3];
double colorVect[3];
glDisable(GL_LIGHTING);
glCallList(bboxList);
glEnable(GL_LIGHTING);
+ *polys += box_polys;
}
if (drawGoal_p) drawGoal(SCHOOL_GOAL(s), goalList);
glTranslatef(FISH_X(f), FISH_Y(f), FISH_Z(f));
glRotatef(180.0+rotTheta, xVect[0], xVect[1], xVect[2]);
glCallList(fishList);
+ *polys += fish_polys;
}
glPopMatrix();
}