summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--glpong3d.c67
-rw-r--r--glpong3d.h3
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