diff options
Diffstat (limited to 'sdl/pyramid.c')
-rw-r--r-- | sdl/pyramid.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/sdl/pyramid.c b/sdl/pyramid.c index ab98494..1d36870 100644 --- a/sdl/pyramid.c +++ b/sdl/pyramid.c @@ -1,8 +1,14 @@ /* pyramid.c * + * @2010 Kamil Kaminski + * * notes: since lighting is enabled, we need to specify normals for * each polygon face so the OpenGL can calculate e.g. how light reflects * + * drawing a shadow for the pyramid would require drawing things twice, so on 2nd + * pass we would draw with black color and multiply by squished matrix, we should + * get to this later with better approach + * */ #include <SDL/SDL.h> @@ -10,11 +16,13 @@ /* for some reason order of the headers matters */ #include "math3d.h" #include "gltools.h" +#include "glframe.h" #include <sys/time.h> -#define FRAMES_PER_SECOND 300 +#define FRAMES_PER_SECOND 60 /* global */ int program_running = 1; +GLFrame camera; static GLfloat xRot = 0.0f; static GLfloat yRot = 0.0f; @@ -95,6 +103,9 @@ static void SetupRC() glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); + + /* set the camera to <0,0,0> */ + reset_glframe(&camera); } static void keys(SDL_keysym *keysym, unsigned int *keys_held, int flag) @@ -104,23 +115,36 @@ static void keys(SDL_keysym *keysym, unsigned int *keys_held, int flag) switch (keysym->sym) { case SDLK_ESCAPE: program_running = 0; break; - case SDLK_w: xRot -= 1.0f; break; - case SDLK_s: xRot += 1.0f; break; - case SDLK_a: yRot -= 1.0f; break; - case SDLK_d: yRot += 1.0f; break; + case SDLK_w: xRot -= 5.0f; break; + case SDLK_s: xRot += 5.0f; break; + case SDLK_a: yRot -= 5.0f; break; + case SDLK_d: yRot += 5.0f; break; + case SDLK_UP: move_forward(&camera, 0.1f); break; + case SDLK_DOWN: move_forward(&camera, -0.1f); break; + case SDLK_LEFT: rotate_local_y(&camera, 0.1f); break; + case SDLK_RIGHT: rotate_local_y(&camera, -0.1f); break; default: break; } } else { if (keys_held[SDLK_w]) - xRot -= 1.0f; + xRot -= 5.0f; if (keys_held[SDLK_s]) - xRot += 1.0f; + xRot += 5.0f; if (keys_held[SDLK_a]) - yRot -= 1.0f; + yRot -= 5.0f; if (keys_held[SDLK_d]) - yRot += 1.0f; + yRot += 5.0f; + + if (keys_held[SDLK_UP]) + move_forward(&camera, 0.01f); + if (keys_held[SDLK_DOWN]) + move_forward(&camera, -0.01f); + if (keys_held[SDLK_LEFT]) + rotate_local_y(&camera, 0.01f); + if (keys_held[SDLK_RIGHT]) + rotate_local_y(&camera, -0.01f); } xRot = (GLfloat) ((const int) xRot % 360); @@ -206,6 +230,9 @@ static void render(void) /* save the matrix state and do the rotations */ glPushMatrix(); + + apply_camera_transform(&camera); + /* move object back and do in place rotation */ glTranslatef(0.0f, 0.2f, -3.5f); glRotatef(xRot, 1.0f, 0.0f, 0.0f); |