polyadvent

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

commit 468f0ad09807f8d29cdb448e8d59a680c7635690
parent 43af373d7d35df01900649f6a7d354c4be88827d
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 29 Jul 2019 22:50:03 -0700

terrain_collision: try more vertices

before it only tried the closest vertex. this sometimes wouldn't work.

Diffstat:
Msrc/terrain_collision.c | 21+++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/terrain_collision.c b/src/terrain_collision.c @@ -172,20 +172,21 @@ struct tri *collide_terrain(struct terrain *terrain, float *pos, struct model *m } query_terrain_grid(terrain, pos[0], pos[1], cells); - get_closest_verts(terrain, pos, queries, cells); - int closest_vind = queries[0].cell->verts_index[queries[0].cell_vert_index]; - struct vert_tris *vtris = &terrain->vtris[closest_vind / 3]; + for (int j = 0; j < ARRAY_SIZE(queries); j++) { + int vind = queries[j].cell->verts_index[queries[j].cell_vert_index]; + struct vert_tris *vtris = &terrain->vtris[vind / 3]; - for (int i = 0; i < vtris->tri_count; i++) {; - /* terrain_cell_debug(terrain, queries[i].cell, queries[i].cell_vert_index, pos); */ + for (int i = 0; i < vtris->tri_count; i++) {; + /* terrain_cell_debug(terrain, queries[i].cell, queries[i].cell_vert_index, pos); */ - struct tri *tri; - if ((tri = point_in_vert_tris(terrain->verts, vtris, pos))) { - terrain_tri_debug(terrain->verts, tri); - get_terrain_penetration(terrain->verts, tri, pos, move); - return tri; + struct tri *tri; + if ((tri = point_in_vert_tris(terrain->verts, vtris, pos))) { + terrain_tri_debug(terrain->verts, tri); + get_terrain_penetration(terrain->verts, tri, pos, move); + return tri; + } } }