X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Ftgdb%2Fobj.cxx;h=ebcb3167cc8a78acb643cbc9280c83e7f8b0c710;hb=7e7ce2f38e87d6244e05730fa4382da088bb25f1;hp=63ce70ea388a7501ebdb75ee4c3fb5fdcb0bbbe3;hpb=09778a8eabf592a02b271dc2f59b691cbdd1364e;p=simgear.git diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index 63ce70ea..ebcb3167 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -50,8 +50,6 @@ #include #include #include -#include -#include #include "SGTexturedTriangleBin.hxx" #include "SGLightBin.hxx" @@ -370,32 +368,11 @@ struct SGTileGeometryBin { osg::Geode* geode = new osg::Geode; SGMaterialTriangleMap::const_iterator i; for (i = materialTriangleMap.begin(); i != materialTriangleMap.end(); ++i) { - // CHUNCKED (sic) here splits up unconnected triangles parts of - // the mesh into different Geometry sets, presumably for better - // culling. I (timoore) believe it is more performant to build - // the biggest indexed sets possible at the expense of tight - // culling. -//#define CHUNCKED -#ifdef CHUNCKED - SGMaterial *mat = matlib->find(i->first); - - std::list connectSets; - i->second.getConnectedSets(connectSets); - - std::list::iterator j; - for (j = connectSets.begin(); j != connectSets.end(); ++j) { - osg::Geometry* geometry = i->second.buildGeometry(*j); - if (mat) - geometry->setStateSet(mat->get_state()); - geode->addDrawable(geometry); - } -#else osg::Geometry* geometry = i->second.buildGeometry(); SGMaterial *mat = matlib->find(i->first); if (mat) geometry->setStateSet(mat->get_state()); geode->addDrawable(geometry); -#endif } return geode; } @@ -553,14 +530,13 @@ struct AddModelLOD { } }; struct GetModelLODCoord { - GetModelLODCoord(const osg::Matrix& transform) : _transform(transform) {} - GetModelLODCoord(const GetModelLODCoord& rhs) : _transform(rhs._transform) + GetModelLODCoord() {} + GetModelLODCoord(const GetModelLODCoord& rhs) {} osg::Vec3 operator() (const ModelLOD& mlod) const { - return mlod.first->getBound().center() * _transform; + return mlod.first->getBound().center(); } - osg::Matrix _transform; }; typedef QuadTreeBuilder nodes = tile.get_wgs84_nodes(); + for (unsigned i = 0; i < nodes.size(); ++i) + nodes[i] = hlOr.transform(nodes[i]); + tile.set_wgs84_nodes(nodes); + + SGQuatf hlOrf(hlOr[0], hlOr[1], hlOr[2], hlOr[3]); + std::vector normals = tile.get_normals(); + for (unsigned i = 0; i < normals.size(); ++i) + normals[i] = hlOrf.transform(normals[i]); + tile.set_normals(normals); + SGTileGeometryBin tileGeometryBin; if (!tileGeometryBin.insertBinObj(tile, matlib)) return false; - SGVec3d center = tile.get_gbs_center2(); - SGGeod geodPos = SGGeod::fromCart(center); - SGQuatd hlOr = SGQuatd::fromLonLat(geodPos); - SGVec3f up = toVec3f(hlOr.backTransform(SGVec3d(0, 0, -1))); + SGVec3f up(0, 0, 1); GroundLightManager* lightManager = GroundLightManager::instance(); osg::ref_ptr lightGroup = new SGOffsetTransform(0.94); @@ -593,22 +583,6 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool terrainGroup->addChild(node); if (use_random_objects || use_random_vegetation) { - - // Simple matrix for used for flipping models that have been oriented - // with the center of the tile but upside down. - static const osg::Matrix flip(1, 0, 0, 0, - 0, -1, 0, 0, - 0, 0, -1, 0, - 0, 0, 0, 1); - // Determine an rotation matrix for the models to place them - // perpendicular to the earth's surface. We use the same matrix, - // based on the centre of the tile, as the small angular differences - // between different points on the tile aren't worth worrying about - // for random objects. We also need to flip the orientation 180 degrees - osg::Matrix mAtt = flip * osg::Matrix::rotate(hlOr.osg()); - // The inverse goes from world coordinates to Z up tile coordinates. - osg::Matrix world2Tile(osg::Matrix(hlOr.osg().conj()) * flip); - if (use_random_objects) { tileGeometryBin.computeRandomObjects(matlib); @@ -627,8 +601,8 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool // Create a matrix to place the object in the correct // location, and then apply the rotation matrix created // above, with an additional random heading rotation if appropriate. - osg::Matrix transformMat(mAtt); - transformMat.postMult(osg::Matrix::translate(obj.position.osg())); + osg::Matrix transformMat; + transformMat = osg::Matrix::translate(obj.position.osg()); if (obj.model->get_heading_type() == SGMatModel::HEADING_RANDOM) { // Rotate the object around the z axis. double hdg = mt_rand(&seed) * M_PI * 2; @@ -640,8 +614,7 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool position->addChild(node); models.push_back(ModelLOD(position, obj.lod)); } - RandomObjectsQuadtree quadtree((GetModelLODCoord(world2Tile)), - (AddModelLOD())); + RandomObjectsQuadtree quadtree((GetModelLODCoord()), (AddModelLOD())); quadtree.buildQuadTree(models.begin(), models.end()); randomObjects = quadtree.getRoot(); randomObjects->setName("random objects"); @@ -653,7 +626,8 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool tileGeometryBin.computeRandomForest(matlib); if (tileGeometryBin.randomForest.getNumTrees() > 0) { - randomForest = createForest(tileGeometryBin.randomForest, mAtt); + randomForest = createForest(tileGeometryBin.randomForest, + osg::Matrix::identity()); randomForest->setName("random trees"); } } @@ -691,8 +665,9 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool lightGroup->addChild(groundLights2); } } - + if (!tileGeometryBin.vasiLights.empty()) { + osg::Geode* vasiGeode = new osg::Geode; SGVec4f red(1, 0, 0, 1); SGMaterial* mat = matlib->find("RWY_RED_LIGHTS"); if (mat) @@ -702,17 +677,14 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool if (mat) white = mat->get_light_color(); - osg::Geode* geode = new osg::Geode; SGDirectionalLightListBin::const_iterator i; for (i = tileGeometryBin.vasiLights.begin(); i != tileGeometryBin.vasiLights.end(); ++i) { - geode->addDrawable(SGLightFactory::getVasi(up, *i, red, white)); + vasiGeode->addDrawable(SGLightFactory::getVasi(up, *i, red, white)); } - osg::Group* vasiLights = new osg::Group; - vasiLights->setCullCallback(new SGPointSpriteLightCullCallback(osg::Vec3(1, 0.0001, 0.000001), 6)); - vasiLights->setStateSet(lightManager->getRunwayLightStateSet()); - vasiLights->addChild(geode); - lightGroup->addChild(vasiLights); + vasiGeode->setCullCallback(new SGPointSpriteLightCullCallback(osg::Vec3(1, 0.0001, 0.000001), 6)); + vasiGeode->setStateSet(lightManager->getRunwayLightStateSet()); + lightGroup->addChild(vasiGeode); } if (tileGeometryBin.runwayLights.getNumLights() > 0 @@ -760,17 +732,14 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool // The toplevel transform for that tile. osg::MatrixTransform* transform = new osg::MatrixTransform; transform->setName(path); - transform->setMatrix(osg::Matrix::translate(center.osg())); + transform->setMatrix(osg::Matrix::rotate(hlOr.osg())* + osg::Matrix::translate(center.osg())); transform->addChild(terrainGroup); if (lightGroup->getNumChildren() > 0) { osg::LOD* lightLOD = new osg::LOD; lightLOD->addChild(lightGroup.get(), 0, 30000); - unsigned nodeMask = ~0u; - nodeMask &= ~SG_NODEMASK_CASTSHADOW_BIT; - nodeMask &= ~SG_NODEMASK_RECIEVESHADOW_BIT; - nodeMask &= ~SG_NODEMASK_PICK_BIT; - nodeMask &= ~SG_NODEMASK_TERRAIN_BIT; - lightLOD->setNodeMask(nodeMask); + // VASI is always on, so doesn't use light bits. + lightLOD->setNodeMask(LIGHTS_BITS | MODEL_BIT); transform->addChild(lightLOD); } @@ -783,7 +752,7 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool if (randomObjects.valid()) objectLOD->addChild(randomObjects.get(), 0, 20000); if (randomForest.valid()) objectLOD->addChild(randomForest.get(), 0, 20000); - unsigned nodeMask = SG_NODEMASK_CASTSHADOW_BIT | SG_NODEMASK_RECIEVESHADOW_BIT; + unsigned nodeMask = SG_NODEMASK_CASTSHADOW_BIT | SG_NODEMASK_RECIEVESHADOW_BIT | SG_NODEMASK_TERRAIN_BIT; objectLOD->setNodeMask(nodeMask); transform->addChild(objectLOD); }