polyadvent

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

commit 35865d59734ee3d1d36b12d20aef92da41497319
parent 22d643338dc8db1a5e1f85d91b34cbf2dc78f462
Author: William Casarin <jb55@jb55.com>
Date:   Sat,  3 Nov 2018 23:04:22 -0700

calculate bounding boxes for geometry

Diffstat:
Msrc/geometry.h | 2++
Msrc/ply.c | 11+++++++++++
2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/geometry.h b/src/geometry.h @@ -16,6 +16,8 @@ struct buffer_geometry { struct geometry { struct buffer_geometry vbos; + float min[3]; + float max[3]; int num_indices; int num_verts; float *vertices; diff --git a/src/ply.c b/src/ply.c @@ -6,6 +6,7 @@ #include "file.h" #include "common.h" #include "ply.h" +#include "vec3.h" /* void parse_vertex( */ @@ -159,6 +160,16 @@ int parse_ply(const char *filename, struct geometry *geom) { break; } + // compute bounding box as we go + if (cvert == 0) { + vec3_copy(vert, geom->min); + vec3_copy(vert, geom->max); + } + else { + vec3_min(vert, geom->min, geom->min); + vec3_max(vert, geom->max, geom->max); + } + geom->vertices[cvert * 3] = vert[0]; geom->vertices[cvert * 3 + 1] = vert[1]; geom->vertices[cvert * 3 + 2] = vert[2];