OutdoorEnv::OutdoorEnv(World* world) : Entity(kOutdoorEnv) { m_world = world; m_haveSky = false; m_nishitaSky = false; m_haveOcean = false; m_haveGlobalLight = true; m_dateTimeInited = false; createSkyBox(); createSkyDome(); setSkyBoxTexture("textures/skys/day/box"); createOceanMesh(); m_globalLight = new Light(Light::kGlobal, Vector3(1,-1,1), Rgb::White); m_globalLight->setWorld(m_world); // global fog m_globalFog = new Fog(); m_globalFog->setFogDensity(0.0004f); m_globalFog->setFogColor(Rgba(119,171,201).toVector()); m_globalFog->setWorld(m_world); // ocean fog m_oceanFog = new Fog(); m_oceanFog->setFogDensity(0.04f); m_oceanFog->setFogColor(Rgba(119,201,171).toVector() * 0.25f); m_oceanFog->setWorld(m_world); TypeZero(&m_lastNishitaParams); }
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; osg::Group* rootnode = new osg::Group; rootnode->addChild(createSkyBox()); // load the nodes from the commandline arguments. osg::Node* model = osgDB::readNodeFiles(arguments); if (!model) { const float radius = 1.0f; osg::Geode* geode = new osg::Geode; geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),radius))); model = geode; } // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(model); // create normals. osgUtil::SmoothingVisitor smoother; model->accept(smoother); rootnode->addChild( addRefractStateSet(model) ); // add a viewport to the viewer and attach the scene graph. viewer.setSceneData(rootnode); // create the windows and run the threads. viewer.realize(); // now check to see if vertex program is supported. osgViewer::Viewer::Windows windows; viewer.getWindows(windows); for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); itr != windows.end(); ++itr) { unsigned int contextID = (*itr)->getState()->getContextID(); osg::VertexProgram::Extensions* vpExt = osg::VertexProgram::getExtensions(contextID,false); if (vpExt) { if (!vpExt->isVertexProgramSupported()) { std::cout<<"Warning: ARB_vertex_program not supported by OpenGL drivers, unable to run application."<<std::endl; return 1; } } } return viewer.run(); }
int main( int argc, char** argv ) { osg::ArgumentParser arguments( &argc, argv ); int displayMode = 1; if ( arguments.read("--simple-mode") ) displayMode = 0; else if ( arguments.read("--analysis-mode") ) displayMode = 1; else if ( arguments.read("--compare-mode") ) displayMode = 2; std::string effectFile("test.xml"); arguments.read( "--effect", effectFile ); bool shadowed = false; if ( arguments.read("--shadowed") ) shadowed = true; float lodscale = 1.0f; arguments.read( "--lod-scale", lodscale ); std::string normalSceneFile; arguments.read( "--normal-scene", normalSceneFile ); // Create the scene osg::Node* model = osgDB::readNodeFiles( arguments ); if ( !model ) model = osgDB::readNodeFile( "lz.osg" ); osg::ref_ptr<osg::Group> scene = new osg::Group; scene->addChild( createSkyBox() ); scene->addChild( shadowed ? createShadowedScene(model) : model ); // Create the effect compositor from XML file #ifdef HAVE_SILVERLINING osg::ref_ptr<osgDB::XmlNode> xmlRoot = osgDB::readXmlFile( effectFile ); if ( !xmlRoot ) { OSG_WARN << "Effect file " << effectFile << " can't be loaded!" << std::endl; return 1; } // FIXME: SilverLining seems to be uncomfortable with default FBO settings? // I'm not sure if this is a SilverLining bug or mine osgFX::EffectCompositor::XmlTemplateMap templateMap; osgFX::EffectCompositor* compositor = new osgFX::EffectCompositor; //compositor->setRenderTargetImplementation( osg::Camera::PIXEL_BUFFER ); // FIXME: PIXEL_BUFFER can't work with NVIDIA 310.70 driver? compositor->loadFromXML( xmlRoot.get(), templateMap, NULL ); #else osgFX::EffectCompositor* compositor = osgFX::readEffectFile( effectFile ); if ( !compositor ) { OSG_WARN << "Effect file " << effectFile << " can't be loaded!" << std::endl; return 1; } #endif // For the fastest and simplest effect use, this is enough! compositor->addChild( scene.get() ); // Add all to the root node of the viewer osg::ref_ptr<osg::Group> root = new osg::Group; root->addChild( compositor ); if ( !normalSceneFile.empty() ) { // root->addChild( osgDB::readNodeFile(normalSceneFile) ); } osgViewer::Viewer viewer; viewer.getCamera()->setLODScale( lodscale ); viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler( new osgViewer::StatsHandler ); viewer.addEventHandler( new osgViewer::WindowSizeHandler ); viewer.setSceneData( root.get() ); if ( displayMode>0 ) configureViewerForMode( viewer, compositor, scene.get(), displayMode ); viewer.setUpViewOnSingleScreen( 0 ); return viewer.run(); }
void EngineMap::create() { //carrega atributos do xml String fileName = "media/maps/"; fileName += _name.c_str(); fileName += ".xml"; TiXmlDocument doc(fileName.c_str()); if (!doc.LoadFile()) return; TiXmlHandle handleDoc(&doc); //obtém elemento com as configurações do mapa TiXmlElement* elMap = handleDoc.FirstChild("map").Element(); if (!elMap) return; String stPlayerStart = elMap->Attribute("player_start"); String stPlayerStartOrientation = elMap->Attribute("player_start_orientation"); String stSkyBox = elMap->Attribute("skybox"); String stMinWorldSize = elMap->Attribute("min_world_size"); String stMaxWorldSize = elMap->Attribute("max_world_size"); String stAmbientLight = elMap->Attribute("ambient_light"); if (stPlayerStart != "") { _playerStart = StringConverter::parseVector3(stPlayerStart); } else { _playerStart = Vector3::ZERO; } if (stPlayerStartOrientation != "") { _playerStartOrientation = StringConverter::parseQuaternion(stPlayerStartOrientation); } else { _playerStartOrientation = Quaternion(1,0,0,0); } _skybox = stSkyBox; _minWorldSize = StringConverter::parseVector3(stMinWorldSize); _maxWorldSize = StringConverter::parseVector3(stMaxWorldSize); //cria a iluminação geral do mapa Vector3 ambientLight = StringConverter::parseVector3(stAmbientLight); EngineGlobalObjects::getInstance().getSceneManager()->setAmbientLight(ColourValue(ambientLight.x, ambientLight.y, ambientLight.z)); //obtém elementos e cria TiXmlElement* elObject = elMap->FirstChildElement("object"); while(elObject) { //obtém o tipo do objeto String stType = elObject->Attribute("type"); //verifica o tipo if (stType == "static_mesh") { String stMass = elObject->Attribute("mass"); String stInertia = elObject->Attribute("inertia"); String stCollision = elObject->Attribute("collision"); String stCastShadows = elObject->Attribute("castshadows"); String stMeshFile = elObject->Attribute("meshfile"); String stMaterial = elObject->Attribute("material"); String stName = elObject->Attribute("name"); String stPosition = elObject->Attribute("position"); String stOrientation = elObject->Attribute("orientation"); String stScale = elObject->Attribute("scale"); String stCenterOfMass = elObject->Attribute("center_of_mass"); //prepara os atributos bool castShadow = StringConverter::parseBool(stCastShadows); String nodeName = "map_object_" + stName; String entityName = "map_object_entity_" + stName; Real mass = StringConverter::parseReal(stMass); Vector3 inertia = StringConverter::parseVector3(stInertia); Vector3 position = StringConverter::parseVector3(stPosition); Quaternion orientation = StringConverter::parseQuaternion(stOrientation); Vector3 scale = StringConverter::parseVector3(stScale); Vector3 centerOfMass = StringConverter::parseVector3(stCenterOfMass); //cria o node e entity Entity *entity; entity = EngineGlobalObjects::getInstance().getSceneManager()->createEntity(entityName, stMeshFile); if (stMaterial != "") { entity->setMaterialName(stMaterial); } entity->setCastShadows(castShadow); SceneNode *node = EngineGlobalObjects::getInstance().getSceneManager()->getRootSceneNode()->createChildSceneNode(nodeName); node->attachObject(entity); //define tamanho node->setScale(scale); //cria colisão if (stCollision == "fixed") { OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( EngineGlobalObjects::getInstance().getWorld(), entity, true, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( EngineGlobalObjects::getInstance().getWorld(), col ); bod->attachNode( node ); bod->setPositionOrientation( position, orientation ); //define callback customizado bod->setCustomForceAndTorqueCallback<EngineMap>(&EngineMap::forceCallback, this); } else if (stCollision == "normal") { OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::ConvexHull(EngineGlobalObjects::getInstance().getWorld(), entity, 0)); OgreNewt::Body* bod = new OgreNewt::Body( EngineGlobalObjects::getInstance().getWorld(), col ); bod->attachNode( node ); bod->setMassMatrix( mass, inertia ); bod->setCenterOfMass(centerOfMass); bod->setStandardForceCallback(); bod->setPositionOrientation( position, orientation ); //define callback customizado bod->setCustomForceAndTorqueCallback<EngineMap>(&EngineMap::forceCallback, this); } } else if (stType == "light") { String stName = elObject->Attribute("name"); String stPosition = elObject->Attribute("position"); String stDirection = elObject->Attribute("direction"); String stAttenuation = elObject->Attribute("attenuation"); String stCastShadows = elObject->Attribute("castshadows"); String stDiffuse = elObject->Attribute("diffuse"); String stLightrange = elObject->Attribute("lightrange"); String stLighttype = elObject->Attribute("lighttype"); String stPower = elObject->Attribute("power"); String stSpecular = elObject->Attribute("specular"); Light *light; light = EngineGlobalObjects::getInstance().getSceneManager()->createLight(stName); if(stLighttype=="LT_POINT") light->setType(Light::LT_POINT); if(stLighttype=="LT_SPOTLIGHT") light->setType(Light::LT_SPOTLIGHT); if(stLighttype=="LT_DIRECTIONAL") light->setType(Light::LT_DIRECTIONAL); light->setPosition(StringConverter::parseVector3(stPosition)); light->setDiffuseColour(StringConverter::parseColourValue(stDiffuse)); light->setSpecularColour(StringConverter::parseColourValue(stSpecular)); Vector4 att = StringConverter::parseVector4(stAttenuation); light->setAttenuation(att.x, att.y, att.z, att.w); light->setDirection(StringConverter::parseVector3(stDirection)); light->setPowerScale(StringConverter::parseReal(stPower)); light->setSpotlightFalloff(1); light->setCastShadows(StringConverter::parseBool(stCastShadows)); } elObject = elObject->NextSiblingElement("object"); } //obtém elementos da fog e cria TiXmlElement* elFog = elMap->FirstChildElement("fog"); while(elFog) { String stFogMode = elFog->Attribute("mode"); String stFogColour = elFog->Attribute("colour"); String stFogStart = elFog->Attribute("start"); String stFogEnd = elFog->Attribute("end"); String stFogDensity = elFog->Attribute("density"); _fogMode = stFogMode; _fogColour = StringConverter::parseColourValue(stFogColour); _fogStart = StringConverter::parseReal(stFogStart); _fogEnd = StringConverter::parseReal(stFogEnd); _fogDensity = StringConverter::parseReal(stFogDensity); //configura a fog no cenário se o modo da fog foi informado if (stFogMode != "") { FogMode fogMode; if (_fogMode == "none") fogMode = FogMode::FOG_NONE; if (_fogMode == "exp") fogMode = FogMode::FOG_EXP; if (_fogMode == "exp2") fogMode = FogMode::FOG_EXP2; if (_fogMode == "linear") fogMode = FogMode::FOG_LINEAR; EngineGlobalObjects::getInstance().getSceneManager()->setFog(fogMode, _fogColour, _fogDensity, _fogStart, _fogEnd); } elFog = elFog->NextSiblingElement("fog"); } //cria o céu createSkyBox(); doc.Clear(); }