goat3d

diff src/mesh.cc @ 76:9785847d52d4

bounding boxes calculation (untested) and automatic camera placement in goatview
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 May 2014 13:43:45 +0300
parents dad392c710df
children 4b653386a154
line diff
     1.1 --- a/src/mesh.cc	Thu May 08 00:50:16 2014 +0300
     1.2 +++ b/src/mesh.cc	Thu May 08 13:43:45 2014 +0300
     1.3 @@ -228,3 +228,22 @@
     1.4  {
     1.5  	return material;
     1.6  }
     1.7 +
     1.8 +AABox Mesh::get_bounds(const Matrix4x4 &xform) const
     1.9 +{
    1.10 +	AABox bbox;
    1.11 +
    1.12 +	for(size_t i=0; i<vertices.size(); i++) {
    1.13 +		Vector3 v = vertices[i].transformed(xform);
    1.14 +
    1.15 +		for(int j=0; j<3; j++) {
    1.16 +			if(v[j] < bbox.bmin[j]) {
    1.17 +				bbox.bmin[j] = v[j];
    1.18 +			}
    1.19 +			if(v[j] > bbox.bmax[j]) {
    1.20 +				bbox.bmax[j] = v[j];
    1.21 +			}
    1.22 +		}
    1.23 +	}
    1.24 +	return bbox;
    1.25 +}
    1.26 \ No newline at end of file