From 13b3640db77ab4a9bde2690b6e02cc4bf10cff5f Mon Sep 17 00:00:00 2001 From: "Ben Russell (300178622)" Date: Sun, 4 Nov 2012 15:19:44 +1300 Subject: [PATCH] fixed topo's soft tabs; added zoom to cam_point_dir --- .gitignore | 4 ++++ common.h | 2 +- main.c | 47 ++++++++++++++++++++++++----------------------- vecmath.c | 8 ++++---- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 1f34a96..51438a7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ bts.exe # backups, just in case you can't configure your editor properly *.bak *~ + +# gprof +gmon.out + diff --git a/common.h b/common.h index 8cc5ba5..431c3f2 100644 --- a/common.h +++ b/common.h @@ -117,4 +117,4 @@ int render_init(int width, int height); void render_deinit(void); // vecmath.c -void cam_point_dir(camera_t *model, float dx, float dy, float dz); +void cam_point_dir(camera_t *model, float dx, float dy, float dz, float zoom, float roll); diff --git a/main.c b/main.c index 84e5740..08fa8ef 100644 --- a/main.c +++ b/main.c @@ -105,23 +105,24 @@ void run_game(void) render_vxl_redraw(&tcam, map); int quitflag = 0; - - int frame_prev = 0; - int frame_now = 0; - int fps = 0; - while(!quitflag) + int frame_prev = 0; + int frame_now = 0; + int fps = 0; + + while(!quitflag) { + float zoom = 1.0f; // update angles if(key_left) - angy += 0.02f; + angy += 0.02f/zoom; if(key_right) - angy -= 0.02f; + angy -= 0.02f/zoom; if(key_up) - angx -= 0.02f; + angx -= 0.02f/zoom; if(key_down) - angx += 0.02f; + angx += 0.02f/zoom; // clamp angle, YOU MUST NOT LOOK DIRECTLY UP OR DOWN! if(angx > M_PI*0.499f) @@ -134,7 +135,7 @@ void run_game(void) float cya = cosf(angy); float sxa = sinf(angx); float cxa = cosf(angx); - cam_point_dir(&tcam, sya*cxa, sxa, cya*cxa); + cam_point_dir(&tcam, sya*cxa, sxa, cya*cxa, zoom, 0.0f); // move along float mvx = 0.0f; @@ -154,7 +155,7 @@ void run_game(void) if(key_space) mvy -= 1.0f; - float mvspd = 0.2f; + float mvspd = 0.2f/zoom; mvx *= mvspd; mvy *= mvspd; mvz *= mvspd; @@ -165,18 +166,18 @@ void run_game(void) if(mvx != 0.0f || mvy != 0.0f || mvz != 0.0f) render_vxl_redraw(&tcam, map); - - frame_now = SDL_GetTicks(); - fps++; - - if(frame_now - frame_prev > 1000) - { - char buf[16]; - sprintf(buf, "buld then snip | FPS: %d", fps); - SDL_WM_SetCaption(buf, 0); - fps = 0; - frame_prev = SDL_GetTicks(); - } + + frame_now = SDL_GetTicks(); + fps++; + + if(frame_now - frame_prev > 1000) + { + char buf[16]; + sprintf(buf, "buld then snip | FPS: %d", fps); + SDL_WM_SetCaption(buf, 0); + fps = 0; + frame_prev = SDL_GetTicks(); + } //printf("%.2f",); SDL_LockSurface(screen); diff --git a/vecmath.c b/vecmath.c index a55a194..d903084 100644 --- a/vecmath.c +++ b/vecmath.c @@ -1,6 +1,6 @@ #include "common.h" -void cam_point_dir(camera_t *model, float dx, float dy, float dz) +void cam_point_dir(camera_t *model, float dx, float dy, float dz, float zoom, float roll) { // Another case where I'd copy-paste code from my aimbot. // Except the last time I did it, I redid it from scratch, @@ -28,9 +28,9 @@ void cam_point_dir(camera_t *model, float dx, float dy, float dz) // Now build that matrix! // Front vector (Z): Well, duh. - model->mzx = nx; - model->mzy = ny; - model->mzz = nz; + model->mzx = nx*zoom; + model->mzy = ny*zoom; + model->mzz = nz*zoom; // Left (TODO: confirm) vector (X): Simple 2D 90deg rotation. // Can be derived from a bit of trial and error.