summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2006-08-04 02:53:49 +0000
committerMatt Turner <mattst88@gmail.com>2006-08-04 02:53:49 +0000
commit6a2ef03d88a1757ce778f6aa943bd928f4a7b27c (patch)
treec7272959c01679e1009fa0cef60c6e29c6a49332
parentaf5e07345548d223b50c3a297743fc55f02e60e3 (diff)
Basic bouncing ball, rectangle outline of bounds
git-svn-id: svn://mattst88.com/svn/glpong3d/trunk@4 4dd1920e-271a-0410-bca0-81b404a81564
-rw-r--r--glpong3d.c85
1 files changed, 73 insertions, 12 deletions
diff --git a/glpong3d.c b/glpong3d.c
index bb0729a..b9a5d29 100644
--- a/glpong3d.c
+++ b/glpong3d.c
@@ -17,7 +17,7 @@ int main(int argc, char * argv[]) {
while ( !GLPong.done ) {
GLPong_HandleEvents();
- /* GLPong_Move();*/
+ GLPong_Move();
GLPong_Draw();
SDL_Delay(10);
}
@@ -32,15 +32,15 @@ void GLPong_Init() {
GLPong.done = 0;
GLPong.w = 800;
- GLPong.h = 600;
+ GLPong.h = 800;
- GLPong.Ball.w = 1.0f;
- GLPong.Ball.h = 1.0f;
- GLPong.Ball.x = -0.5f;
- GLPong.Ball.y = -0.5f;
+ GLPong.Ball.w = 0.2f;
+ GLPong.Ball.h = 0.2f;
+ GLPong.Ball.x = -0.1f;
+ GLPong.Ball.y = -0.1f;
GLPong.Ball.z = -3.0f;
- GLPong.Ball.xv = 0.0f;
- GLPong.Ball.yv = 0.0f;
+ GLPong.Ball.xv = 0.02f;
+ GLPong.Ball.yv = 0.01f;
GLPong.Ball.zv = -0.05f;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
@@ -122,10 +122,58 @@ void GLPong_HandleEvents() {
void GLPong_Draw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glLoadIdentity();
+ glColor3f(0.0f, 1.0f, 0.0f);
+ glTranslatef(0.0f, 0.0f, 0.0f);
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(-1.0f, -1.0f, -3.0f); /* Lower Left */
+ glVertex3f( 1.0f, -1.0f, -3.0f); /* Lower Right */
+ glVertex3f( 1.0f, 1.0f, -3.0f); /* Upper Right */
+ glVertex3f(-1.0f, 1.0f, -3.0f); /* Upper Left */
+ glEnd();
+
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, 0.0f);
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(-1.0f, -1.0f, -9.0f); /* Lower Left */
+ glVertex3f( 1.0f, -1.0f, -9.0f); /* Lower Right */
+ glVertex3f( 1.0f, 1.0f, -9.0f); /* Upper Right */
+ glVertex3f(-1.0f, 1.0f, -9.0f); /* Upper Left */
+ glEnd();
+
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, 0.0f);
+ glBegin(GL_LINES);
+ glVertex3f(-1.0f, -1.0f, -3.0f); /* Lower Left */
+ glVertex3f(-1.0f, -1.0f, -9.0f);
+ glEnd();
+
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, 0.0f);
+ glBegin(GL_LINES);
+ glVertex3f( 1.0f, -1.0f, -3.0f); /* Lower Right */
+ glVertex3f( 1.0f, -1.0f, -9.0f);
+ glEnd();
+
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, 0.0f);
+ glBegin(GL_LINES);
+ glVertex3f( 1.0f, 1.0f, -3.0f); /* Upper Right */
+ glVertex3f( 1.0f, 1.0f, -9.0f);
+ glEnd();
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, 0.0f);
+ glBegin(GL_LINES);
+ glVertex3f(-1.0f, 1.0f, -3.0f); /* Upper Left */
+ glVertex3f(-1.0f, 1.0f, -9.0f);
+ glEnd();
+
+ glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, ball_texture);
glEnable(GL_TEXTURE_2D);
- glLoadIdentity();
+ glColor3f(1.0f, 1.0f, 1.0f);
glTranslatef(GLPong.Ball.x, GLPong.Ball.y, GLPong.Ball.z);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex2f(GLPong.Ball.w, GLPong.Ball.h); /* Lower Left */
@@ -135,6 +183,15 @@ void GLPong_Draw() {
glEnd();
glDisable(GL_TEXTURE_2D);
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, GLPong.Ball.z);
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(-1.0f, -1.0f, 0.0f); /* Lower Left */
+ glVertex3f( 1.0f, -1.0f, 0.0f); /* Lower Right */
+ glVertex3f( 1.0f, 1.0f, 0.0f); /* Upper Right */
+ glVertex3f(-1.0f, 1.0f, 0.0f); /* Upper Left */
+ glEnd();
+
SDL_GL_SwapBuffers();
}
@@ -146,9 +203,13 @@ void GLPong_Move() {
GLPong.Ball.x += GLPong.Ball.xv;
GLPong.Ball.y += GLPong.Ball.yv;
GLPong.Ball.z += GLPong.Ball.zv;
- if (GLPong.Ball.z < -12.0f) {
- GLPong.Ball.zv = -GLPong.Ball.zv;
- } else if (GLPong.Ball.z > -3.0f) {
+ if ((GLPong.Ball.x > 1.0f) || (GLPong.Ball.x < -1.0f)) {
+ GLPong.Ball.xv = -GLPong.Ball.xv;
+ }
+ if ((GLPong.Ball.y > 1.0f) || (GLPong.Ball.y < -1.0f)) {
+ GLPong.Ball.yv = -GLPong.Ball.yv;
+ }
+ if ((GLPong.Ball.z < -9.0f) || (GLPong.Ball.z > -3.0f)) {
GLPong.Ball.zv = -GLPong.Ball.zv;
}
}