fixed topo's soft tabs; added zoom to cam_point_dir

This commit is contained in:
Ben Russell (300178622) 2012-11-04 15:19:44 +13:00
parent 27114c2c16
commit 13b3640db7
4 changed files with 33 additions and 28 deletions

4
.gitignore vendored
View File

@ -8,3 +8,7 @@ bts.exe
# backups, just in case you can't configure your editor properly # backups, just in case you can't configure your editor properly
*.bak *.bak
*~ *~
# gprof
gmon.out

View File

@ -117,4 +117,4 @@ int render_init(int width, int height);
void render_deinit(void); void render_deinit(void);
// vecmath.c // 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);

41
main.c
View File

@ -106,22 +106,23 @@ void run_game(void)
int quitflag = 0; int quitflag = 0;
int frame_prev = 0; int frame_prev = 0;
int frame_now = 0; int frame_now = 0;
int fps = 0; int fps = 0;
while(!quitflag) while(!quitflag)
{ {
float zoom = 1.0f;
// update angles // update angles
if(key_left) if(key_left)
angy += 0.02f; angy += 0.02f/zoom;
if(key_right) if(key_right)
angy -= 0.02f; angy -= 0.02f/zoom;
if(key_up) if(key_up)
angx -= 0.02f; angx -= 0.02f/zoom;
if(key_down) if(key_down)
angx += 0.02f; angx += 0.02f/zoom;
// clamp angle, YOU MUST NOT LOOK DIRECTLY UP OR DOWN! // clamp angle, YOU MUST NOT LOOK DIRECTLY UP OR DOWN!
if(angx > M_PI*0.499f) if(angx > M_PI*0.499f)
@ -134,7 +135,7 @@ void run_game(void)
float cya = cosf(angy); float cya = cosf(angy);
float sxa = sinf(angx); float sxa = sinf(angx);
float cxa = cosf(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 // move along
float mvx = 0.0f; float mvx = 0.0f;
@ -154,7 +155,7 @@ void run_game(void)
if(key_space) if(key_space)
mvy -= 1.0f; mvy -= 1.0f;
float mvspd = 0.2f; float mvspd = 0.2f/zoom;
mvx *= mvspd; mvx *= mvspd;
mvy *= mvspd; mvy *= mvspd;
mvz *= mvspd; mvz *= mvspd;
@ -166,17 +167,17 @@ void run_game(void)
if(mvx != 0.0f || mvy != 0.0f || mvz != 0.0f) if(mvx != 0.0f || mvy != 0.0f || mvz != 0.0f)
render_vxl_redraw(&tcam, map); render_vxl_redraw(&tcam, map);
frame_now = SDL_GetTicks(); frame_now = SDL_GetTicks();
fps++; fps++;
if(frame_now - frame_prev > 1000) if(frame_now - frame_prev > 1000)
{ {
char buf[16]; char buf[16];
sprintf(buf, "buld then snip | FPS: %d", fps); sprintf(buf, "buld then snip | FPS: %d", fps);
SDL_WM_SetCaption(buf, 0); SDL_WM_SetCaption(buf, 0);
fps = 0; fps = 0;
frame_prev = SDL_GetTicks(); frame_prev = SDL_GetTicks();
} }
//printf("%.2f",); //printf("%.2f",);
SDL_LockSurface(screen); SDL_LockSurface(screen);

View File

@ -1,6 +1,6 @@
#include "common.h" #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. // Another case where I'd copy-paste code from my aimbot.
// Except the last time I did it, I redid it from scratch, // 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! // Now build that matrix!
// Front vector (Z): Well, duh. // Front vector (Z): Well, duh.
model->mzx = nx; model->mzx = nx*zoom;
model->mzy = ny; model->mzy = ny*zoom;
model->mzz = nz; model->mzz = nz*zoom;
// Left (TODO: confirm) vector (X): Simple 2D 90deg rotation. // Left (TODO: confirm) vector (X): Simple 2D 90deg rotation.
// Can be derived from a bit of trial and error. // Can be derived from a bit of trial and error.