void Stage01::InitBackgroundObjects() { auto engine = STGEngine::GetInstance(); Ptr<Mesh> roadMesh = Ptr<Mesh>::New(); auto& vertices = roadMesh->GetVertices(); vertices.push_back(Vector3f(-10000, 0, -10000)); vertices.push_back(Vector3f(10000, 0, -10000)); vertices.push_back(Vector3f(-10000, 0, 10000)); vertices.push_back(Vector3f(10000, 0, 10000)); auto& normals = roadMesh->GetNormals(); normals.push_back(Vector3f(0, 1, 0)); normals.push_back(Vector3f(0, 1, 0)); normals.push_back(Vector3f(0, 1, 0)); normals.push_back(Vector3f(0, 1, 0)); auto& uv = roadMesh->GetUV(); uv.push_back(Vector2f(-100, -100)); uv.push_back(Vector2f(100, -100)); uv.push_back(Vector2f(-100, 100)); uv.push_back(Vector2f(100, 100)); auto& indices = roadMesh->GetTriangles(); indices.push_back(0); indices.push_back(1); indices.push_back(2); indices.push_back(1); indices.push_back(2); indices.push_back(3); Material roadMaterial; roadMaterial.texture = texRoad; roadMesh->SetMaterial(roadMaterial); Ptr<MeshObject> road = Ptr<MeshObject>::New(); road->SetMesh(roadMesh); engine->AddBackgroundObject(road.Get()); CreateHouses(); }
int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); // construct the viewer. osgViewer::Viewer viewer; // add local test manipulator more suitable for testing impostors. viewer.setCameraManipulator(new TestManipulator); // load the nodes from the commandline arguments. osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFiles(arguments); if (model) { // the osgSim::InsertImpostorsVisitor used lower down to insert impostors // only operators on subclass of Group's, if the model top node is not // a group then it won't be able to insert an impostor. We therefore // manually insert an impostor above the model. if (dynamic_cast<osg::Group*>(model.get())==0) { const osg::BoundingSphere& bs = model->getBound(); if (bs.valid()) { osgSim::Impostor* impostor = new osgSim::Impostor; // standard LOD settings impostor->addChild(model.get()); impostor->setRange(0,0.0f,1e7f); impostor->setCenter(bs.center()); // impostor specific settings. impostor->setImpostorThresholdToBound(5.0f); model = impostor; } } // we insert an impostor node above the model, so we keep a handle // on the rootnode of the model, the is required since the // InsertImpostorsVisitor can add a new root in automatically and // we would know about it, other than by following the parent path // up from model. This is really what should be done, but I'll pass // on it right now as it requires a getRoots() method to be added to // osg::Node, and we're about to make a release so no new features! osg::ref_ptr<osg::Group> rootnode = new osg::Group; rootnode->addChild(model); // now insert impostors in the model using the InsertImpostorsVisitor. osgSim::InsertImpostorsVisitor ov; // traverse the model and collect all osg::Group's and osg::LOD's. // however, don't traverse the rootnode since we want to keep it as // the start of traversal, otherwise the insertImpostor could insert // and Impostor above the current root, making it nolonger a root! model->accept(ov); // insert the Impostors above groups and LOD's ov.insertImpostors(); } else { // no user model so we'll create our own world. model = Root = new osg::Group(); CreateHouses(); LayoutAsGrid(); } // add model to viewer. viewer.setSceneData(model); return viewer.run(); }