From 3aa0e202c360cbf69bfa26fe23daf43f5ef695a1 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Thu, 21 Jan 2010 21:30:36 -0500 Subject: Define GLPONG_FRONT_Z and GLPONG_BACK_Z. Signed-off-by: Matt Turner --- glpong3d.c | 67 +++++++++++++++++++++----------------------------------------- glpong3d.h | 3 +++ 2 files changed, 26 insertions(+), 44 deletions(-) diff --git a/glpong3d.c b/glpong3d.c index d6b2ed1..477988d 100644 --- a/glpong3d.c +++ b/glpong3d.c @@ -77,7 +77,7 @@ GLPong_Init(GLPong_t * GLPong) { GLPong->Ball.h = 0.5f; GLPong->Ball.coord.x = -(GLPong->Ball.w / 2); GLPong->Ball.coord.y = -(GLPong->Ball.h / 2); - GLPong->Ball.coord.z = -3.0f; + GLPong->Ball.coord.z = GLPONG_FRONT_Z; GLPong->Ball.r = 1.0f; GLPong->Ball.g = 0.0f; GLPong->Ball.b = 0.0f; @@ -89,7 +89,7 @@ GLPong_Init(GLPong_t * GLPong) { GLPong->Front.h = 0.5f; GLPong->Front.coord.x = -1.0f; GLPong->Front.coord.y = -1.0f; - GLPong->Front.coord.z = -3.0f; + GLPong->Front.coord.z = GLPONG_FRONT_Z; GLPong->Front.r = 1.0f; GLPong->Front.g = 1.0f; GLPong->Front.b = 1.0f; @@ -98,7 +98,7 @@ GLPong_Init(GLPong_t * GLPong) { GLPong->Back.h = 0.5f; GLPong->Back.coord.x = -(GLPong->Front.w / 2); GLPong->Back.coord.y = -(GLPong->Front.h / 2); - GLPong->Back.coord.z = -9.0f; + GLPong->Back.coord.z = GLPONG_BACK_Z; GLPong->Back.r = 1.0f; GLPong->Back.g = 1.0f; GLPong->Back.b = 1.0f; @@ -238,11 +238,11 @@ void GLPong_Move(void) { } GLPong.Ball.coord.z += GLPong.Ball.zv; - if (GLPong.Ball.coord.z < -9.0f) { - GLPong.Ball.coord.z = -9.0f; + if (GLPong.Ball.coord.z < GLPONG_BACK_Z) { + GLPong.Ball.coord.z = GLPONG_BACK_Z; GLPong.Ball.zv = -GLPong.Ball.zv; - } else if (GLPong.Ball.coord.z > -3.0f) { - GLPong.Ball.coord.z = -3.0f; + } else if (GLPong.Ball.coord.z > GLPONG_FRONT_Z) { + GLPong.Ball.coord.z = GLPONG_FRONT_Z; GLPong.Ball.zv = -GLPong.Ball.zv; } GLPong.Back.coord.x = GLPong.Ball.coord.x; @@ -251,9 +251,11 @@ void GLPong_Move(void) { } void GLPong_Draw(void) { + float count; + glLoadIdentity(); glColor3f(0.0f, 0.0f, 0.0f); - glTranslatef(0.0f, 0.0f, -9.0f); + glTranslatef(0.0f, 0.0f, GLPONG_BACK_Z); glBegin(GL_QUADS); glTexCoord2f(0.875f, 0.0f); glVertex2f( 1.5f, 1.0f); /* Upper Right */ glTexCoord2f(0.125f, 0.0f); glVertex2f(-1.5f, 1.0f); /* Upper Left */ @@ -262,56 +264,33 @@ void GLPong_Draw(void) { glEnd(); glDisable(GL_TEXTURE_2D); - glLoadIdentity(); glColor3f(0.0f, 1.0f, 0.0f); - - glTranslatef(0.0f, 0.0f, -3.0f); - glCallList(box); - - glLoadIdentity(); - glTranslatef(0.0f, 0.0f, -4.0f); - glCallList(box); - - glLoadIdentity(); - glTranslatef(0.0f, 0.0f, -5.0f); - glCallList(box); - - glLoadIdentity(); - glTranslatef(0.0f, 0.0f, -6.0f); - glCallList(box); - - glLoadIdentity(); - glTranslatef(0.0f, 0.0f, -7.0f); - glCallList(box); - - glLoadIdentity(); - glTranslatef(0.0f, 0.0f, -8.0f); - glCallList(box); - - glLoadIdentity(); - glTranslatef(0.0f, 0.0f, -9.0f); - glCallList(box); + for (count = GLPONG_FRONT_Z; count >= GLPONG_BACK_Z; count -= 1.0f) { + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, count); + glCallList(box); + } glLoadIdentity(); glTranslatef(0.0f, 0.0f, 0.0f); glBegin(GL_LINES); - glVertex3f(-1.5f, -1.0f, -3.0f); /* Lower Left */ - glVertex3f(-1.5f, -1.0f, -9.0f); + glVertex3f(-1.5f, -1.0f, GLPONG_FRONT_Z); /* Lower Left */ + glVertex3f(-1.5f, -1.0f, GLPONG_BACK_Z); glEnd(); glBegin(GL_LINES); - glVertex3f( 1.5f, -1.0f, -3.0f); /* Lower Right */ - glVertex3f( 1.5f, -1.0f, -9.0f); + glVertex3f( 1.5f, -1.0f, GLPONG_FRONT_Z); /* Lower Right */ + glVertex3f( 1.5f, -1.0f, GLPONG_BACK_Z); glEnd(); glBegin(GL_LINES); - glVertex3f( 1.5f, 1.0f, -3.0f); /* Upper Right */ - glVertex3f( 1.5f, 1.0f, -9.0f); + glVertex3f( 1.5f, 1.0f, GLPONG_FRONT_Z); /* Upper Right */ + glVertex3f( 1.5f, 1.0f, GLPONG_BACK_Z); glEnd(); glBegin(GL_LINES); - glVertex3f(-1.5f, 1.0f, -3.0f); /* Upper Left */ - glVertex3f(-1.5f, 1.0f, -9.0f); + glVertex3f(-1.5f, 1.0f, GLPONG_FRONT_Z); /* Upper Left */ + glVertex3f(-1.5f, 1.0f, GLPONG_BACK_Z); glEnd(); glLoadIdentity(); diff --git a/glpong3d.h b/glpong3d.h index 7dd0adf..844b629 100644 --- a/glpong3d.h +++ b/glpong3d.h @@ -7,6 +7,9 @@ #define GLPONG_WIDTH 800.0f #define GLPONG_HEIGHT 600.0f +#define GLPONG_FRONT_Z -3.0f +#define GLPONG_BACK_Z -9.0f + #define GLPONG_NOACTION 0 #define GLPONG_EXIT 1 -- cgit v1.2.3