diff options
author | Matt Turner <mattst88@gmail.com> | 2010-01-22 22:59:35 -0500 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2011-04-04 17:14:36 -0400 |
commit | c265e527e34736c49c2c6f017d84aa0723fb2fc9 (patch) | |
tree | 670ffd27f66a2a37bbf636cd3b20efe22e60fdf9 /glpong3d.c | |
parent | 54124c855dd096825b4487417ce1e085228dde9e (diff) |
Move paddle code into paddle.c.
Signed-off-by: Matt Turner <mattst88@gmail.com>
Diffstat (limited to 'glpong3d.c')
-rw-r--r-- | glpong3d.c | 68 |
1 files changed, 18 insertions, 50 deletions
@@ -18,7 +18,7 @@ static int GLPong_HandleEvents(void); static void GLPong_Draw(void); static void GLPong_CleanUp(void); static void GLPong_Move(void); -static void SDL_GL_GetMouseState(Paddle_t * paddle); +static void SDL_GL_GetMouseState(GLfloat * x, GLfloat * y); static GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface); int main(int argc, char * argv[]) { @@ -45,7 +45,6 @@ int main(int argc, char * argv[]) { break; } - SDL_GL_GetMouseState(&GLPong.Front); GLPong_Move(); /* begin drawing */ @@ -76,24 +75,6 @@ GLPong_Init(GLPong_t * GLPong) { SDL_Surface * temp = NULL; GLuint texture; - GLPong->Front.w = 0.66f; - GLPong->Front.h = 0.5f; - GLPong->Front.coord.x = -1.0f; - GLPong->Front.coord.y = -1.0f; - GLPong->Front.coord.z = GLPONG_FRONT_Z; - GLPong->Front.r = 1.0f; - GLPong->Front.g = 1.0f; - GLPong->Front.b = 1.0f; - - GLPong->Back.w = 0.66f; - 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 = GLPONG_BACK_Z; - GLPong->Back.r = 1.0f; - GLPong->Back.g = 1.0f; - GLPong->Back.b = 1.0f; - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); return -1; @@ -135,7 +116,7 @@ GLPong_Init(GLPong_t * GLPong) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(45.0f, GLPONG_WIDTH / GLPONG_HEIGHT, 3.0f, 9.0f); + gluPerspective(45.0f, GLPONG_WIDTH / GLPONG_HEIGHT, -GLPONG_FRONT_Z, -GLPONG_BACK_Z); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -158,10 +139,9 @@ GLPong_Init(GLPong_t * GLPong) { SDL_FreeSurface(temp); temp = IMG_Load("paddle-skyos.png"); - paddle_texture = SDL_GL_SurfaceToTexture(temp); - SDL_FreeSurface(temp); - temp = IMG_Load("paddle-skyos.png"); - paddle_texture_hit = SDL_GL_SurfaceToTexture(temp); + texture = SDL_GL_SurfaceToTexture(temp); + GLPong_PaddleInit(&GLPong->front_paddle, GLPONG_FRONT_Z, texture); + GLPong_PaddleInit(&GLPong->back_paddle, GLPONG_BACK_Z, texture); SDL_FreeSurface(temp); box = glGenLists(1); @@ -213,6 +193,11 @@ GLPong_HandleEvents(void) { static void GLPong_Move(void) { + GLfloat x, y; + + SDL_GL_GetMouseState(&x, &y); + GLPong_PaddleMove(&GLPong.front_paddle, x, y); + GLPong_BallMove(); } @@ -248,11 +233,11 @@ void GLPong_Draw(void) { glVertex3f(-1.5f, 1.0f, GLPONG_BACK_Z); glEnd(); - GLPong_PaddleDrawBack(&GLPong.Back); + GLPong_PaddleDraw(&GLPong.back_paddle); GLPong_BallDraw(); - GLPong_PaddleDrawFront(&GLPong.Front); + GLPong_PaddleDraw(&GLPong.front_paddle); } #if 0 @@ -332,33 +317,16 @@ SDL_GL_SurfaceToTexture(SDL_Surface * surface) { } static void -SDL_GL_GetMouseState(Paddle_t * paddle) { - int x, y; - float temp_x, temp_y; +SDL_GL_GetMouseState(GLfloat * x, GLfloat * y) { + int SDL_x, SDL_y; SDL_PumpEvents(); - SDL_GetMouseState(&x, &y); - - temp_x = ((float) x / GLPONG_WIDTH) * 3.3f - 1.65f; - - if (temp_x <= -1.5 + (paddle->w / 2)) { - temp_x = -1.5 + (paddle->w / 2); - } else if (temp_x >= 1.5 - (paddle->w / 2)) { - temp_x = 1.5 - (paddle->w / 2); - } - - temp_y = ((float) y / GLPONG_HEIGHT) * 2.5f - 1.25f; - - if (temp_y <= -1.0 + (paddle->h / 2)) { - temp_y = -1.0 + (paddle->h / 2); - } else if (temp_y >= 1.0 - (paddle->h / 2)) { - temp_y = 1.0 - (paddle->h / 2); - } + SDL_GetMouseState(&SDL_x, &SDL_y); - paddle->coord.x = temp_x - paddle->w / 2; - paddle->coord.y = -(temp_y + paddle->h / 2); + *x = ((float)SDL_x / GLPONG_WIDTH) * 3.3f - 1.65f; + *y = ((float)SDL_y / GLPONG_HEIGHT) * 2.25f - 1.25f; #ifdef DEBUG - printf("SDL (x, y): (%d, %d)\tGL (x, y, z): (%.3f, %.3f)\n", x, y, paddle->coord.x, paddle->coord.y); + printf("SDL (x, y): (%d, %d)\tGL (x, y): (%.3f, %.3f)\n", SDL_x, SDL_y, *x, *y); #endif } |