polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit 96d04833968b65c1e9c59b506a7ed6429dd09eaf
parent 52a94c11cd8a8c3a2b95b1f0cf636a45e6477a6a
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 21 Jul 2019 16:46:34 -0700

fix freecam

Diffstat:
Mmain.c | 2++
Msrc/model.c | 3+++
Msrc/update.c | 13++++++++-----
Msrc/window.c | 2+-
4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/main.c b/main.c @@ -86,6 +86,8 @@ int main(void) /* accumulator -= dt; */ /* } */ + default_config.camera = game.test_resources.camera_node_id; + last = new_time; struct fbo *fbo = &game.test_resources.shadow_buffer; diff --git a/src/model.c b/src/model.c @@ -101,6 +101,9 @@ static struct model *load_static_model(enum static_model m) snprintf(path, 128, "data/models/%s.mdl", static_model_defs[m].file); load_mdl(path, model, &lgeom); + vec3_copy(lgeom.min, geom->min); + vec3_copy(lgeom.max, geom->max); + make_buffer_geometry(&lgeom.mkgeom, geom); free_make_geometry(&lgeom.mkgeom); diff --git a/src/update.c b/src/update.c @@ -255,7 +255,8 @@ void orbit_update_from_mouse(struct orbit *camera, struct input *input, node_recalc(target_node); vec3_copy(node_world(target_node), target); - vec3_add(target, V3(0.0, 0.0, player_geom->max[2] * 2.0), target); + assert(player_geom->max[2] != 0); + vec3_add(target, V3(0.0, 0.0, player_geom->max[2]), target); /* vec3_add(target, V3(0.0, 0.0, 10.0), target); */ float mx = 0.0, my = 0.0; @@ -277,7 +278,7 @@ void orbit_update_from_mouse(struct orbit *camera, struct input *input, camera->coords.radius += input->wheel_y * dt * 100.0; } - camera->coords.radius = max(5.0, camera->coords.radius); + camera->coords.radius = max(1.0, camera->coords.radius); camera->coords.azimuth += mx; camera->coords.inclination += my; @@ -299,7 +300,7 @@ static void camera_keep_above_ground(struct terrain *terrain, float cam_terrain_z = terrain->fn(terrain, camera_world[0], camera_world[1]); - const float bias = 2.0; + const float bias = 1.0; if (camera_world[2] < cam_terrain_z + bias) camera_world[2] = cam_terrain_z + bias; @@ -357,11 +358,13 @@ void update (struct game *game) { /* spherical_dir(game->test_resources.camera.coords, camera_dir); */ /* vec3_scale(camera_dir, -1, camera_dir); */ - if (ideq(&res->camera_node_id, &res->free_camera_id)) { + if (game->input.modifiers & KMOD_ALT && + ideq(&res->camera_node_id, &res->free_camera_id)) + { struct node *freecam_node = get_node(&res->free_camera_id); assert(freecam_node); + assert(streq(freecam_node->label, "freecam")); movement(game, freecam_node, 1.0); - node_recalc(freecam_node); } else { player_movement(game, pnode); diff --git a/src/window.c b/src/window.c @@ -11,7 +11,7 @@ void handle_resize(struct game *game, int width, int height) { /* printf("resizing %d %d\n", width, height); */ glViewport( 0, 0, width, height ); - mat4_perspective(75 /* fov */, (float)width / height, 1.0, 10000.0, + mat4_perspective(75 /* fov */, (float)width / height, 0.1, 10000.0, game->test_resources.proj_persp); resize_fbos(get_entity(&game->test_resources.player_id),