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
*.bak
*~
# gprof
gmon.out

View File

@ -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);

47
main.c
View File

@ -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);

View File

@ -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.