From 07586e84ce88d5a79e1c8623cfdcd50a160aed40 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sun, 6 Oct 2019 12:52:12 +0100 Subject: [PATCH] Rotate orientation of pitched roofs by 90 degrees Also add some additional checking of parameters. --- simgear/scene/tgdb/SGBuildingBin.cxx | 183 ++++++++++++++------------- 1 file changed, 92 insertions(+), 91 deletions(-) diff --git a/simgear/scene/tgdb/SGBuildingBin.cxx b/simgear/scene/tgdb/SGBuildingBin.cxx index a22be5c9..df01aa81 100644 --- a/simgear/scene/tgdb/SGBuildingBin.cxx +++ b/simgear/scene/tgdb/SGBuildingBin.cxx @@ -105,6 +105,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(1, 0, 0) ); // normal c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof + t->push_back( osg::Vec2( 0.0, 0.0) ); } // Left face @@ -116,6 +117,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0, -1, 0) ); // normal c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof + t->push_back( osg::Vec2( 0.0, 0.0) ); } // Back face @@ -127,6 +129,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(-1, 0, 0) ); // normal c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof + t->push_back( osg::Vec2( 0.0, 0.0) ); } // Right face @@ -138,6 +141,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0, 1, 0) ); // normal c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof + t->push_back( osg::Vec2( 0.0, 0.0) ); } // MAIN BODY @@ -147,6 +151,11 @@ struct MakeBuildingLeaf v->push_back( osg::Vec3( 0.0, 0.5, 1.0) ); // top left v->push_back( osg::Vec3( 0.0, -0.5, 1.0) ); // top right + t->push_back( osg::Vec2( 1.0, 0.0) ); // bottom right + t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom left + t->push_back( osg::Vec2( 0.0, 1.0) ); // top left + t->push_back( osg::Vec2( 1.0, 1.0) ); // top right + for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(1, 0, 0) ); // normal c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof @@ -158,6 +167,11 @@ struct MakeBuildingLeaf v->push_back( osg::Vec3( 0.0, -0.5, 1.0) ); // top left v->push_back( osg::Vec3( -1.0, -0.5, 1.0) ); // top right + t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom right + t->push_back( osg::Vec2( 1.0, 0.0) ); // bottom left + t->push_back( osg::Vec2( 1.0, 1.0) ); // top left + t->push_back( osg::Vec2( 0.0, 1.0) ); // top right + for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0, -1, 0) ); // normal c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof @@ -169,6 +183,11 @@ struct MakeBuildingLeaf v->push_back( osg::Vec3( -1.0, -0.5, 1.0) ); // top left v->push_back( osg::Vec3( -1.0, 0.5, 1.0) ); // top right + t->push_back( osg::Vec2( 1.0, 0.0) ); // bottom right + t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom left + t->push_back( osg::Vec2( 0.0, 1.0 ) ); // top left + t->push_back( osg::Vec2( 1.0, 1.0 ) ); // top right + for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(-1, 0, 0) ); // normal c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof @@ -180,6 +199,11 @@ struct MakeBuildingLeaf v->push_back( osg::Vec3( -1.0, 0.5, 1.0) ); // top left v->push_back( osg::Vec3( 0.0, 0.5, 1.0) ); // top right + t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom right + t->push_back( osg::Vec2( 1.0, 0.0) ); // bottom left + t->push_back( osg::Vec2( 1.0, 1.0 ) ); // top left + t->push_back( osg::Vec2( 0.0, 1.0 ) ); // top right + for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0, 1, 0) ); // normal c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof @@ -189,110 +213,67 @@ struct MakeBuildingLeaf // Front pitched roof v->push_back( osg::Vec3( 0.0, -0.5, 1.0) ); // bottom right v->push_back( osg::Vec3( 0.0, 0.5, 1.0) ); // bottom left - v->push_back( osg::Vec3( -0.5, 0.5, 1.5) ); // top left - v->push_back( osg::Vec3( -0.5, -0.5, 1.5) ); // top right + v->push_back( osg::Vec3( 0.0, 0.0, 1.5) ); // top left + v->push_back( osg::Vec3( 0.0, 0.0, 1.5) ); // top right + + t->push_back( osg::Vec2( 0.5, 1.0) ); // bottom right + t->push_back( osg::Vec2( 0.5, 1.0) ); // bottom right + t->push_back( osg::Vec2( 0.5, 1.0) ); // bottom right + t->push_back( osg::Vec2( 0.5, 1.0) ); // bottom right for (int i=0; i<4; ++i) { - n->push_back( osg::Vec3(0.707, 0, 0.707) ); // normal - c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to differentiate wall from roof + n->push_back( osg::Vec3( 1, 0, 0) ); // normal + c->push_back( osg::Vec4( 1, 0, 0, 0) ); // color - used to differentiate wall from roof. This is really an extension of the wall } // Left pitched roof - v->push_back( osg::Vec3(-1.0, -0.5, 1.0) ); // bottom right - v->push_back( osg::Vec3( 0.0, -0.5, 1.0) ); // bottom left - v->push_back( osg::Vec3(-0.5, -0.5, 1.5) ); // top left - v->push_back( osg::Vec3(-0.5, -0.5, 1.5) ); // top right + v->push_back( osg::Vec3( -1.0, -0.5, 1.0) ); // bottom left + v->push_back( osg::Vec3( 0.0, -0.5, 1.0) ); // bottom right + v->push_back( osg::Vec3( 0.0, 0.0, 1.5) ); // top right + v->push_back( osg::Vec3( -1.0, 0.0, 1.5) ); // top left + + t->push_back( osg::Vec2( -1.0, 0.0) ); // bottom right + t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom left + t->push_back( osg::Vec2( 0.0, 1.0 ) ); // top left + t->push_back( osg::Vec2( -1.0, 1.0 ) ); // top right for (int i=0; i<4; ++i) { - n->push_back( osg::Vec3(0, -1, 0) ); // normal + n->push_back( osg::Vec3(0, -0.707, 0.707) ); // normal c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to differentiate wall from roof } // Back pitched roof - v->push_back( osg::Vec3(-1.0, 0.5, 1.0) ); // bottom right - v->push_back( osg::Vec3(-1.0, -0.5, 1.0) ); // bottom left - v->push_back( osg::Vec3(-0.5, -0.5, 1.5) ); // top left - v->push_back( osg::Vec3(-0.5, 0.5, 1.5) ); // top right + v->push_back( osg::Vec3( -1.0, 0.5, 1.0) ); // bottom right + v->push_back( osg::Vec3( -1.0, -0.5, 1.0) ); // bottom left + v->push_back( osg::Vec3( -1.0, 0.0, 1.5) ); // top left + v->push_back( osg::Vec3( -1.0, 0.0, 1.5) ); // top right + + t->push_back( osg::Vec2( 0.5, 1.0) ); // bottom right + t->push_back( osg::Vec2( 0.5, 1.0) ); // bottom right + t->push_back( osg::Vec2( 0.5, 1.0) ); // bottom right + t->push_back( osg::Vec2( 0.5, 1.0) ); // bottom right for (int i=0; i<4; ++i) { - n->push_back( osg::Vec3(-0.707, 0, 0.707) ); // normal - c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to differentiate wall from roof + n->push_back( osg::Vec3(-1.0, 0, 0) ); // normal + c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof. This is really an extension of the wall below. } // Right pitched roof - v->push_back( osg::Vec3( 0.0, 0.5, 1.0) ); // bottom right - v->push_back( osg::Vec3(-1.0, 0.5, 1.0) ); // bottom left - v->push_back( osg::Vec3(-0.5, 0.5, 1.5) ); // top left - v->push_back( osg::Vec3(-0.5, 0.5, 1.5) ); // top right + v->push_back( osg::Vec3( 0.0, 0.5, 1.0) ); // bottom left + v->push_back( osg::Vec3( -1.0, 0.5, 1.0) ); // bottom right + v->push_back( osg::Vec3( -1.0, 0.0, 1.5) ); // top right + v->push_back( osg::Vec3( 0.0, 0.0, 1.5) ); // top left + + t->push_back( osg::Vec2( -1.0, 0.0) ); // bottom right + t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom left + t->push_back( osg::Vec2( 0.0, 1.0 ) ); // top left + t->push_back( osg::Vec2( -1.0, 1.0 ) ); // top right for (int i=0; i<4; ++i) { - n->push_back( osg::Vec3(0, 1, 0) ); // normal + n->push_back( osg::Vec3(0, 0.707, 0.707) ); // normal c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to differentiate wall from roof } - // The 1024x1024 texture is split into 32x16 blocks. - // For a small building, each block is 6m wide and 3m high. - // For a medium building, each block is 10m wide and 3m high. - // For a large building, each block is 20m wide and 3m high - - // Texture coordinates are adjusted in the shader. Here we just use - // the full [0,1] range. - - // BASEMENT - uses the baseline texture - for (unsigned int i = 0; i < 16; i++) { - t->push_back( osg::Vec2( 0.0, 0.0) ); - } - - // MAIN BODY - // Front - t->push_back( osg::Vec2( 1.0, 0.0) ); // bottom right - t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom left - t->push_back( osg::Vec2( 0.0, 1.0) ); // top left - t->push_back( osg::Vec2( 1.0, 1.0) ); // top right - - // Left - t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom right - t->push_back( osg::Vec2( 1.0, 0.0) ); // bottom left - t->push_back( osg::Vec2( 1.0, 1.0) ); // top left - t->push_back( osg::Vec2( 0.0, 1.0) ); // top right - - // Back (same as front for the moment) - t->push_back( osg::Vec2( 1.0, 0.0) ); // bottom right - t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom left - t->push_back( osg::Vec2( 0.0, 1.0 ) ); // top left - t->push_back( osg::Vec2( 1.0, 1.0 ) ); // top right - - // Right (same as left for the moment) - t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom right - t->push_back( osg::Vec2( 1.0, 0.0) ); // bottom left - t->push_back( osg::Vec2( 1.0, 1.0 ) ); // top left - t->push_back( osg::Vec2( 0.0, 1.0 ) ); // top right - - // ROOF - // ROOF - Front top surface. Negative x-coord will wrap texture - t->push_back( osg::Vec2( -1.0, 0.0) ); // bottom right - t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom left - t->push_back( osg::Vec2( 0.0, 1.0 ) ); // top left - t->push_back( osg::Vec2( -1.0, 1.0 ) ); // top right - - // ROOF - Left - t->push_back( osg::Vec2( 1.0, 1.0) ); // bottom right - t->push_back( osg::Vec2( 1.0, 0.0) ); // bottom left - t->push_back( osg::Vec2( 1.0, 0.0 ) ); // top left - t->push_back( osg::Vec2( 1.0, 1.0 ) ); // top right - - // ROOF - Back (same as front for the moment) - t->push_back( osg::Vec2( -1.0, 0.0) ); // bottom right - t->push_back( osg::Vec2( 0.0, 0.0) ); // bottom left - t->push_back( osg::Vec2( 0.0, 1.0 ) ); // top left - t->push_back( osg::Vec2( -1.0, 1.0 ) ); // top right - - // ROOF - Right (same as left for the moment) - t->push_back( osg::Vec2( 1.0, 1.0) ); // bottom right - t->push_back( osg::Vec2( 1.0, 0.0) ); // bottom left - t->push_back( osg::Vec2( 1.0, 0.0 ) ); // top left - t->push_back( osg::Vec2( 1.0, 1.0 ) ); // top right - Geometry* geom = new Geometry; static int buildingCounter = 0; geom->setName("BuildingGeometry_" + std::to_string(buildingCounter++)); @@ -350,10 +331,10 @@ struct AddBuildingLeafObject positions->push_back(building.position); // Depth is the x-axis, width is the y-axis - scale->push_back(osg::Vec3(building.depth, building.width, building.height)); - rot->push_back(osg::Vec3(building.rotation, building.pitch_height, building.walltex0.x())); - tex->push_back(osg::Vec3(building.walltex0.y(), building.tex1.x(), building.tex1.y())); - rtex->push_back(osg::Vec3(building.rooftex0.x(), building.rooftex0.y(), 0.0f)); + scale->push_back(osg::Vec3f(building.depth, building.width, building.height)); + rot->push_back(osg::Vec3f(building.rotation, building.pitch_height, building.walltex0.x())); + tex->push_back(osg::Vec3f(building.walltex0.y(), building.tex1.x(), building.tex1.y())); + rtex->push_back(osg::Vec3f(building.rooftex0.x(), building.rooftex0.y(), 0.0f)); DrawArrays* primSet = static_cast(geom->getPrimitiveSet(0)); primSet->setNumInstances(positions->size()); @@ -468,8 +449,8 @@ typedef QuadTreeBuilder 0.5f) || + (wall_offset_y + gain_y > (6.0f * 3.0f * BUILDING_TEXTURE_BLOCK_HEIGHT))) { + SG_LOG(SG_TERRAIN, SG_ALERT, "Small building texture coordinates out of bounds offset (" << wall_offset_x << ", " << wall_offset_y << ") gain (" << gain_x << ", " << gain_y << ")"); + } + + wall_tex0 = Vec2f(wall_offset_x, wall_offset_y); roof_tex0 = Vec2f(roof_offset_x, roof_offset_y); tex1 = Vec2f(gain_x, gain_y); @@ -507,9 +495,16 @@ typedef QuadTreeBuilder 0.5f) || + (wall_offset_y + gain_y < (6.0f * 3.0f * BUILDING_TEXTURE_BLOCK_HEIGHT)) || + (wall_offset_y + gain_y > ((6.0f * 3.0f + 3.0f * 8.0f) * BUILDING_TEXTURE_BLOCK_HEIGHT))) { + SG_LOG(SG_TERRAIN, SG_ALERT, "Medium building texture coordinates out of bounds offset (" << wall_offset_x << ", " << wall_offset_y << ") gain (" << gain_x << ", " << gain_y << ")"); + } + + wall_tex0 = Vec2f(wall_offset_x, wall_offset_y); roof_tex0 = Vec2f(roof_offset_x, roof_offset_y); tex1 = Vec2f(gain_x, gain_y); @@ -526,9 +521,15 @@ typedef QuadTreeBuilder 0.5f) || + (wall_offset_y + gain_y < ((6.0f * 3.0f + 3.0f * 8.0f) * BUILDING_TEXTURE_BLOCK_HEIGHT)) || + (wall_offset_y + gain_y > 1.0) ) { + SG_LOG(SG_TERRAIN, SG_ALERT, "Large building texture coordinates out of bounds offset (" << wall_offset_x << ", " << wall_offset_y << ") gain (" << gain_x << ", " << gain_y << ")"); + } + wall_tex0 = Vec2f(wall_offset_x, wall_offset_y); roof_tex0 = Vec2f(roof_offset_x, roof_offset_y); tex1 = Vec2f(gain_x, gain_y);