- // BASEMENT
- // This exteds 10m below the main section
- // Front face
- v->push_back( osg::Vec3( 0, -cw, -10) * transformMat ); // bottom right
- v->push_back( osg::Vec3( 0, cw, -10) * transformMat ); // bottom left
- v->push_back( osg::Vec3( 0, cw, 0) * transformMat ); // top left
- v->push_back( osg::Vec3( 0, -cw, 0) * transformMat ); // top right
-
- for (int i=0; i<4; ++i)
- n->push_back( osg::Vec3(1, 0, 0) * rotationMat ); // normal
-
- // Left face
- v->push_back( osg::Vec3( -cd, -cw, -10) * transformMat ); // bottom right
- v->push_back( osg::Vec3( 0, -cw, -10) * transformMat ); // bottom left
- v->push_back( osg::Vec3( 0, -cw, 0) * transformMat ); // top left
- v->push_back( osg::Vec3( -cd, -cw, 0) * transformMat ); // top right
-
- for (int i=0; i<4; ++i)
- n->push_back( osg::Vec3(0, -1, 0) * rotationMat ); // normal
-
- // Back face
- v->push_back( osg::Vec3( -cd, cw, -10) * transformMat ); // bottom right
- v->push_back( osg::Vec3( -cd, -cw, -10) * transformMat ); // bottom left
- v->push_back( osg::Vec3( -cd, -cw, 0) * transformMat ); // top left
- v->push_back( osg::Vec3( -cd, cw, 0) * transformMat ); // top right
-
- for (int i=0; i<4; ++i)
- n->push_back( osg::Vec3(-1, 0, 0) * rotationMat ); // normal
-
- // Right face
- v->push_back( osg::Vec3( 0, cw, -10) * transformMat ); // bottom right
- v->push_back( osg::Vec3( -cd, cw, -10) * transformMat ); // bottom left
- v->push_back( osg::Vec3( -cd, cw, 0) * transformMat ); // top left
- v->push_back( osg::Vec3( 0, cw, 0) * transformMat ); // top right
-
- for (int i=0; i<4; ++i)
- n->push_back( osg::Vec3(0, 1, 0) * rotationMat ); // normal
-
- // MAIN BODY
- // Front face
- v->push_back( osg::Vec3( 0, -cw, 0) * transformMat ); // bottom right
- v->push_back( osg::Vec3( 0, cw, 0) * transformMat ); // bottom left
- v->push_back( osg::Vec3( 0, cw, ch) * transformMat ); // top left
- v->push_back( osg::Vec3( 0, -cw, ch) * transformMat ); // top right
-
- for (int i=0; i<4; ++i)
- n->push_back( osg::Vec3(1, 0, 0) * rotationMat ); // normal
-
- // Left face
- v->push_back( osg::Vec3( -cd, -cw, 0) * transformMat ); // bottom right
- v->push_back( osg::Vec3( 0, -cw, 0) * transformMat ); // bottom left
- v->push_back( osg::Vec3( 0, -cw, ch) * transformMat ); // top left
- v->push_back( osg::Vec3( -cd, -cw, ch) * transformMat ); // top right
-
- for (int i=0; i<4; ++i)
- n->push_back( osg::Vec3(0, -1, 0) * rotationMat ); // normal
-
- // Back face
- v->push_back( osg::Vec3( -cd, cw, 0) * transformMat ); // bottom right
- v->push_back( osg::Vec3( -cd, -cw, 0) * transformMat ); // bottom left
- v->push_back( osg::Vec3( -cd, -cw, ch) * transformMat ); // top left
- v->push_back( osg::Vec3( -cd, cw, ch) * transformMat ); // top right
-
- for (int i=0; i<4; ++i)
- n->push_back( osg::Vec3(-1, 0, 0) * rotationMat ); // normal
-
- // Right face
- v->push_back( osg::Vec3( 0, cw, 0) * transformMat ); // bottom right
- v->push_back( osg::Vec3( -cd, cw, 0) * transformMat ); // bottom left
- v->push_back( osg::Vec3( -cd, cw, ch) * transformMat ); // top left
- v->push_back( osg::Vec3( 0, cw, ch) * transformMat ); // top right
-
- for (int i=0; i<4; ++i)
- n->push_back( osg::Vec3(0, 1, 0) * rotationMat ); // normal
-
- // ROOF
- if (building.pitched) {
+ for (unsigned int j = 0; j < BUILDING_SET_SIZE; j++) {
+ float width;
+ float depth;
+ int floors;
+ float height;
+ bool pitched;
+
+ if (buildingtype == SGBuildingBin::SMALL) {
+ // Small building
+ width = mat->get_building_small_min_width() + mt_rand(&seed) * mt_rand(&seed) * (mat->get_building_small_max_width() - mat->get_building_small_min_width());
+ depth = mat->get_building_small_min_depth() + mt_rand(&seed) * mt_rand(&seed) * (mat->get_building_small_max_depth() - mat->get_building_small_min_depth());
+ floors = SGMisc<double>::round(mat->get_building_small_min_floors() + mt_rand(&seed) * (mat->get_building_small_max_floors() - mat->get_building_small_min_floors()));
+ height = floors * (2.8 + mt_rand(&seed));
+
+ // Small buildings are never deeper than they are wide.
+ if (depth > width) { depth = width; }
+
+ pitched = (mt_rand(&seed) < mat->get_building_small_pitch());
+ } else if (buildingtype == SGBuildingBin::MEDIUM) {
+ width = mat->get_building_medium_min_width() + mt_rand(&seed) * mt_rand(&seed) * (mat->get_building_medium_max_width() - mat->get_building_medium_min_width());
+ depth = mat->get_building_medium_min_depth() + mt_rand(&seed) * mt_rand(&seed) * (mat->get_building_medium_max_depth() - mat->get_building_medium_min_depth());
+ floors = SGMisc<double>::round(mat->get_building_medium_min_floors() + mt_rand(&seed) * (mat->get_building_medium_max_floors() - mat->get_building_medium_min_floors()));
+ height = floors * (2.8 + mt_rand(&seed));
+
+ while ((height > width) && (floors > mat->get_building_medium_min_floors())) {
+ // Ensure that medium buildings aren't taller than they are wide
+ floors--;
+ height = floors * (2.8 + mt_rand(&seed));
+ }
+
+ pitched = (mt_rand(&seed) < mat->get_building_medium_pitch());
+ } else {
+ width = mat->get_building_large_min_width() + mt_rand(&seed) * (mat->get_building_large_max_width() - mat->get_building_large_min_width());
+ depth = mat->get_building_large_min_depth() + mt_rand(&seed) * (mat->get_building_large_max_depth() - mat->get_building_large_min_depth());
+ floors = SGMisc<double>::round(mat->get_building_large_min_floors() + mt_rand(&seed) * (mat->get_building_large_max_floors() - mat->get_building_large_min_floors()));
+ height = floors * (2.8 + mt_rand(&seed));
+ pitched = (mt_rand(&seed) < mat->get_building_large_pitch());
+ }