dungeon_crawler
diff prototype/src/mesh.cc @ 21:0588f8a1a351
converting LIGHT meshes to lights
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 21 Aug 2012 06:33:36 +0300 |
parents | e5567ddbf2ef |
children | cbf86e5198a9 |
line diff
1.1 --- a/prototype/src/mesh.cc Tue Aug 21 04:57:33 2012 +0300 1.2 +++ b/prototype/src/mesh.cc Tue Aug 21 06:33:36 2012 +0300 1.3 @@ -201,3 +201,39 @@ 1.4 1.5 glPopMatrix(); 1.6 } 1.7 + 1.8 + 1.9 +void Mesh::calc_bsph() 1.10 +{ 1.11 + glBindBuffer(GL_ARRAY_BUFFER, vbo[MESH_ATTR_VERTEX]); 1.12 + Vector3 *varr = (Vector3*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY); 1.13 + 1.14 + bsph_center = Vector3(0, 0, 0); 1.15 + 1.16 + for(unsigned int i=0; i<nverts; i++) { 1.17 + bsph_center += varr[i]; 1.18 + } 1.19 + bsph_center /= (float)nverts; 1.20 + 1.21 + // assume all vertices are equidistant from the center 1.22 + bsph_rad = (varr[0] - bsph_center).length(); 1.23 + 1.24 + glUnmapBuffer(GL_ARRAY_BUFFER); 1.25 + bsph_valid = true; 1.26 +} 1.27 + 1.28 +const Vector3 &Mesh::get_bsph_center() const 1.29 +{ 1.30 + if(!bsph_valid) { 1.31 + ((Mesh*)this)->calc_bsph(); 1.32 + } 1.33 + return bsph_center; 1.34 +} 1.35 + 1.36 +float Mesh::get_bsph_radius() const 1.37 +{ 1.38 + if(!bsph_valid) { 1.39 + ((Mesh*)this)->calc_bsph(); 1.40 + } 1.41 + return bsph_rad; 1.42 +}