AxisAlignedBox3f TriMesh::calcBoundingBox( const Matrix44f &transform ) const { if( mVertices.empty() ) return AxisAlignedBox3f( Vec3f::zero(), Vec3f::zero() ); Vec3f min( transform.transformPointAffine( mVertices[0] ) ); Vec3f max( min ); for( size_t i = 0; i < mVertices.size(); ++i ) { Vec3f v = transform.transformPointAffine( mVertices[i] ); if( v.x < min.x ) min.x = v.x; else if( v.x > max.x ) max.x = v.x; if( v.y < min.y ) min.y = v.y; else if( v.y > max.y ) max.y = v.y; if( v.z < min.z ) min.z = v.z; else if( v.z > max.z ) max.z = v.z; } return AxisAlignedBox3f( min, max ); }
AxisAlignedBox3f AxisAlignedBox3f::transformed( const Matrix44f &transform ) const { Vec3f verts[8]; for(size_t i=0;i<8;i++) verts[i] = transform.transformPointAffine(mVerts[i]); Vec3f min = verts[0]; Vec3f max = verts[0]; for(size_t i=1;i<8;i++) { if(verts[i].x < min.x) min.x = verts[i].x; if(verts[i].y < min.y) min.y = verts[i].y; if(verts[i].z < min.z) min.z = verts[i].z; if(verts[i].x > max.x) max.x = verts[i].x; if(verts[i].y > max.y) max.y = verts[i].y; if(verts[i].z > max.z) max.z = verts[i].z; } return AxisAlignedBox3f(min, max); }