/* tilegrid.c - Don Yang (uguu.org) 05/31/03 */ #include"global.h" #include"core.h" #include"tilegrid.h" static GLuint ObjTile = 0; static void DrawTileGrid(void); /*********************************************************** DrawTileGridD */ void DrawTileGridD(void) { static const GLfloat tileambient[4] = {0.2f, 0.2f, 0.5f, 1.0f}; static const GLfloat tilediffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f}; static const GLfloat tilespecular[4] = {0.2f, 0.2f, 0.22f, 1.0f}; static const GLfloat tileemission[4] = {0.1f, 0.1f, 0.1f, 1.0f}; glMaterialfv(GL_FRONT, GL_AMBIENT, tileambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, tilediffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, tilespecular); glMaterialfv(GL_FRONT, GL_EMISSION, tileemission); DrawTileGrid(); } /* DrawTileGridD() */ /*********************************************************** DrawTileGridN */ void DrawTileGridN(void) { static const GLfloat tileambient[4] = {0.0f, 0.0f, 0.0f, 1.0f}; static const GLfloat tilediffuse[4] = {0.1f, 0.1f, 0.1f, 1.0f}; static const GLfloat tilespecular[4] = {0.0f, 0.0f, 0.0f, 1.0f}; static const GLfloat tileemission[4] = {0.0f, 0.0f, 0.0f, 1.0f}; glMaterialfv(GL_FRONT, GL_AMBIENT, tileambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, tilediffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, tilespecular); glMaterialfv(GL_FRONT, GL_EMISSION, tileemission); DrawTileGrid(); } /* DrawTileGridN() */ /************************************************************ InitTileGrid */ void InitTileGrid(void) { static const double tx[4][2] = { {1.0, 0.0}, { 0.0, 1.0}, {-1.0, 0.0}, {0.0,-1.0} }; static const double tz[4][2] = { {0.0, 1.0}, {-1.0, 0.0}, { 0.0,-1.0}, {1.0, 0.0} }; static const double edge = 1.78; static const double bevel = 0.2; double u, v, a; int i, c; glNewList(ObjTile = glGenLists(1), GL_COMPILE); for(c = 0; c < 4; c++) { glBegin(GL_QUAD_STRIP); for(i = 0; i <= TILE_CORNER_RESOLUTION; i++) { a = (double)i * PI / (TILE_CORNER_RESOLUTION * 2.0); u = cos(a); v = sin(a); glNormal3d(u * tx[4][0], v, u * tx[4][1]); glVertex3d((edge + bevel * u) * (tx[c][0] + tx[c][1]), v * bevel - bevel, (edge + bevel * u) * (tz[c][0] + tz[c][1])); glVertex3d((edge + bevel * u) * (tx[c][0] - tx[c][1]), v * bevel - bevel, (edge + bevel * u) * (tz[c][0] - tz[c][1])); } glEnd(); } glBegin(GL_QUADS); glNormal3d(0.0, 1.0, 0.0); glVertex3d(-edge, 0.0, edge); glVertex3d( edge, 0.0, edge); glVertex3d( edge, 0.0, -edge); glVertex3d(-edge, 0.0, -edge); glEnd(); glEndList(); } /* InitTileGrid() */ /********************************************************** UninitTileGrid */ void UninitTileGrid(void) { glDeleteLists(ObjTile, 1); } /* UninitTileGrid() */ /************************************************************ DrawTileGrid */ static void DrawTileGrid(void) { double d; int i, j; d = fmod(CurrentTime * DRIFT_DISTANCE, 4.0); for(i = -30; i <= 30; i += 4) { for(j = -32; j <= 32; j += 4) { glPushMatrix(); glTranslated((double)i - d, 0.0, (double)j); glCallList(ObjTile); glPopMatrix(); } } } /* DrawTileGrid() */