ossimPlanetLatLonHud::ossimPlanetLatLonHud() { setUpdateCallback(new ossimPlanetLatLonHudUpdateCallback); theInitializedFlag = false; theAutoUpdateFlag = true; theFontName = "arial.ttf"; theFont = osgText::readFontFile(theFontName.c_str()); theFontChanged = true; theCharacterSize = 16; theCharacterSizeDirtyFlag = true; theLookLabel = "Look At: "; theEyeLabel = "Eye: "; theRangeLabel = "Range: "; theLatDisplayString = "dd.ddddddddddddC"; theLonDisplayString = "ddd.ddddddddddddC"; theCompass = new ossimPlanetCompass; theCompass->setRotateByViewMatrix(true); theCompass->buildCompass(); theCompass->getOrCreateStateSet()->setAttribute(new osg::PolygonMode(), osg::StateAttribute::PROTECTED); // don't allow to go to wireframe theViewportChangedFlag = false; }
SilverLiningNode::SilverLiningNode( const char* licenseUser, const char* licenseKey ) : _initialized(false) { _sky = new SkyDrawable(this); _sky->setUseVertexBufferObjects( false ); _sky->setUseDisplayList( false ); _sky->getOrCreateStateSet()->setRenderBinDetails( 98, "RenderBin" ); _sky->getOrCreateStateSet()->setAttributeAndModes( new osg::Depth(osg::Depth::LEQUAL, 0.0, 1.0, false) ); addDrawable( _sky.get() ); _cloud = new CloudDrawable(this); _cloud->setUseVertexBufferObjects( false ); _cloud->setUseDisplayList( false ); _cloud->getOrCreateStateSet()->setRenderBinDetails( 99, "RenderBin" ); _cloud->setCullCallback( new AlwaysKeepCallback ); // This seems to avoid cloud to twinkle sometimes addDrawable( _cloud.get() ); AtmosphereUpdater* updater = new AtmosphereUpdater; setUpdateCallback( updater ); setCullCallback( updater ); setCullingActive( false ); getOrCreateStateSet()->setRenderBinDetails( 100, "RenderBin" ); _atmosphere = new SilverLining::Atmosphere( licenseUser, licenseKey ); _atmosphere->DisableFarCulling( true ); _atmosphere->EnableLensFlare( true ); const char* slPath = getenv( "SILVERLINING_PATH" ); if ( slPath ) _resourcePath = osgDB::convertFileNameToNativeStyle(std::string(slPath) + "/resources/"); }
RigGeometry::RigGeometry() : mSkeleton(nullptr) , mLastFrameNumber(0) , mBoundsFirstFrame(true) { setUpdateCallback(new osg::Callback); // dummy to make sure getNumChildrenRequiringUpdateTraversal() is correct // update done in accept(NodeVisitor&) }
//============================================================================== WorldNode::WorldNode(std::shared_ptr<dart::simulation::World> _world) : mWorld(_world), mSimulating(false), mNumStepsPerCycle(1), mViewer(nullptr) { setUpdateCallback(new WorldNodeCallback); }
TextShape::TextShape(std::string command, std::string name) { // check for changed values createParameter("pos", new Vec3Type()); createParameter("color", new Vec4Type()); createParameter("bcolor", new Vec4Type()); createParameter("enableOutline", new BoolType()); createParameter("size", new FloatType()); createParameter("label", new StringType()); createParameter("font", new StringType()); _type = SimpleShape::TEXT; BasicShape::setName(name); // default color is white for font setColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); // set a default background color setBackdropColor(osg::Vec4(0.0, 0.0, 0.0, 1.0)); setCharacterSize(10.0f); setFontResolution(40,40); osgText::Font* font = NULL; // check if fontMap has been constucted if ( _fontMap == NULL ) _fontMap = new ThreadMap< std::string, osgText::Font* >(); // check if font exists in map else load it and add it if( ! _fontMap->get(std::string("/usr/share/fonts/liberation/LiberationSans-Regular.ttf"), font) ) { font = osgText::readFontFile("/usr/share/fonts/liberation/LiberationSans-Regular.ttf"); _fontMap->add(std::string("/usr/share/fonts/liberation/LiberationSans-Regular.ttf"), font); } setFont(font); if( Globals::G_ROTAXIS ) setAxisAlignment(osgText::TextBase::XY_PLANE); else setAxisAlignment(osgText::TextBase::XZ_PLANE); // off by default setBackdropType(osgText::Text::NONE); osg::StateSet* state = osgText::Text::getOrCreateStateSet(); state->setMode(GL_BLEND, osg::StateAttribute::ON); state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); //osg::Material* mat = new osg::Material(); //mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); //state->setAttributeAndModes(mat, osg::StateAttribute::ON); setUpdateCallback(new TextUpdateCallback()); update(command); }
Level::Level(const std::string &mapfile) : _numDeaths(0), _reachedFinish(false) { _shadowedScene = new osgShadow::ShadowedScene; _shadowedScene->setReceivesShadowTraversalMask(RECEIVE_SHADOW_MASK); _shadowedScene->setCastsShadowTraversalMask(CAST_SHADOW_MASK); _shadowedScene->setShadowTechnique(new osgShadow::ShadowMap); addChild(_shadowedScene); _headUpDisplay = new HeadUpDisplay(); addChild(_headUpDisplay->getCamera()); addChild((new Sky())->getCamera()); initializePhysicsWorld(); // load map from file loadMapFromFile(mapfile); // add player to level _shadowedScene->addChild(Player::getInstance()); addChild(Player::getInstance()->getParticleEffects()); // add player ghost object to world _physicsWorld->addCollisionObject(Player::getInstance()->getGhostObject(), btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter); // register player controller _physicsWorld->addAction(Player::getInstance()->getController()); // initialize members LazyCameraManipulator *cameraManipulator = new LazyCameraManipulator(); // setup manipulator to track the player cameraManipulator->setTrackNode(Player::getInstance()); cameraManipulator->setHomePosition(LEVEL_CAMERA_HOME_EYE, LEVEL_CAMERA_HOME_CENTER, LEVEL_CAMERA_HOME_UP); // player must be updated after physic is updated Player::getInstance()->setUpdateCallback(new PlayerUpdater()); // set _cameraManipulator as manipulator for the scene viewer.setCameraManipulator(cameraManipulator); LevelUpdater *stepCallback = new LevelUpdater(this); setUpdateCallback(stepCallback); // player keyboard control _keyboardHandler = new LevelKeyboardHandler(); viewer.addEventHandler(_keyboardHandler); initializeLighting(); Sound::getInstance()->stop(MENU_MUSIC_FILE); Sound::getInstance()->playInLoop(LEVEL_MUSIC_FILE); }
void QuadPrimitive::applyLineShader(osg::StateSet* stateSet) { const std::string vertexSource = "#version 330 \n" " \n" "uniform vec3 center; \n" "uniform mat4 osg_ModelViewProjectionMatrix; \n" "uniform vec4 mat_diffuse; \n" " \n" "layout (location = 0) in vec4 Position; \n" "layout (location = 1) in vec3 osg_Normal; \n" "layout (location = 2) in vec4 osg_Color; \n" "layout (location = 3) in vec2 osg_Texcoord; \n" "out vec4 color; \n" "out vec2 Texcoord; \n" " \n" "void main() \n" "{ \n" //" vec3 ecNormal = normalize( osg_NormalMatrix * osg_Normal ); \n" //" float diffuse = max( dot( ecLightDir, ecNormal ), 0. ); \n" //" color = vec4( diffuse * mat_diffuse.rgb, mat_diffuse.a ); \n"// " color = osg_Color; \n"// " Texcoord = osg_Texcoord;\n" " gl_Position = osg_ModelViewProjectionMatrix * (Position + vec4(center, 0)); \n" "} \n"; osg::Shader* vShader = new osg::Shader(osg::Shader::VERTEX, vertexSource); const std::string fragmentSource = "#version 330 \n" //"uniform sampler2D gDiffuseMap;\n" "in vec4 color; \n" "in vec2 Texcoord; \n" "out vec4 fragData; \n" " \n" "void main() \n" "{ \n" " fragData = color; \n" //" fragData = color*texture(gDiffuseMap, Texcoord); \n" "} \n"; osg::Shader* fShader = new osg::Shader(osg::Shader::FRAGMENT, fragmentSource); osg::Program* program = new osg::Program; program->addShader(vShader); program->addShader(fShader); stateSet->setAttribute(program); auto uni = new osg::Uniform("center", m_center); uni->setUpdateCallback(new UniformUpdater([this](osg::Uniform* uni, unsigned int /*frameNum*/){ uni->set(m_center); })); stateSet->addUniform(uni); }
Renderable::Renderable(void) :read_write_lock_(QReadWriteLock::NonRecursive), content_root_(new osg::MatrixTransform), expired_(true), hidden_(false) { addChild(content_root_); setUpdateCallback(new UpdateCallback); setDataVariance(Object::DYNAMIC); return; }
Refraction() { unsigned int rttSize = Settings::Manager::getInt("rtt size", "Water"); setRenderOrder(osg::Camera::PRE_RENDER); setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); setReferenceFrame(osg::Camera::RELATIVE_RF); setSmallFeatureCullingPixelSize(Settings::Manager::getInt("small feature culling pixel size", "Water")); setName("RefractionCamera"); setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_Actor|Mask_ParticleSystem|Mask_Sky|Mask_Sun|Mask_Player|Mask_Lighting); setNodeMask(Mask_RenderToTexture); setViewport(0, 0, rttSize, rttSize); // No need for Update traversal since the scene is already updated as part of the main scene graph // A double update would mess with the light collection (in addition to being plain redundant) setUpdateCallback(new NoTraverseCallback); // No need for fog here, we are already applying fog on the water surface itself as well as underwater fog // assign large value to effectively turn off fog // shaders don't respect glDisable(GL_FOG) osg::ref_ptr<osg::Fog> fog (new osg::Fog); fog->setStart(10000000); fog->setEnd(10000000); getOrCreateStateSet()->setAttributeAndModes(fog, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE); mClipCullNode = new ClipCullNode; addChild(mClipCullNode); mRefractionTexture = new osg::Texture2D; mRefractionTexture->setTextureSize(rttSize, rttSize); mRefractionTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); mRefractionTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); mRefractionTexture->setInternalFormat(GL_RGB); mRefractionTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); mRefractionTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); attach(osg::Camera::COLOR_BUFFER, mRefractionTexture); mRefractionDepthTexture = new osg::Texture2D; mRefractionDepthTexture->setSourceFormat(GL_DEPTH_COMPONENT); mRefractionDepthTexture->setInternalFormat(GL_DEPTH_COMPONENT24); mRefractionDepthTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); mRefractionDepthTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); mRefractionDepthTexture->setSourceType(GL_UNSIGNED_INT); mRefractionDepthTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); mRefractionDepthTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); attach(osg::Camera::DEPTH_BUFFER, mRefractionDepthTexture); }
TritonNode::TritonNode( const char* licenseUser, const char* licenseKey ) : _resourceLoader(0), _environment(0), _ocean(0), _atmosphere(0), _licenseName(licenseUser), _licenseKey(licenseKey), _initialized(false) { _oceanDrawable = new OceanDrawable(this); _oceanDrawable->setUseVertexBufferObjects( false ); _oceanDrawable->setUseDisplayList( false ); addDrawable( _oceanDrawable.get() ); OceanUpdater* updater = new OceanUpdater; setUpdateCallback( updater ); setCullCallback( updater ); getOrCreateStateSet()->setAttribute( new osg::Program ); const char* slPath = getenv( "TRITON_PATH" ); if ( slPath ) _resourcePath = osgDB::convertFileNameToNativeStyle(std::string(slPath) + "/resources/"); }
Tiled2DGraphics::Tiled2DGraphics(const osg::Vec2& size, const osg::Vec4& constraining_rect, double tile_width, double tile_height, const Options& options) : osg::MatrixTransform(), _size(size), _constrainingRect(constraining_rect), _minZoomLevel(computeMinZoomLevel()), _maxZoomLevel(_minZoomLevel), _currentZoomLevel(0.0f), _currentVisibleLevel(NULL), _scrollDelta(0,0), _visibleTiles(), _tilesToHide(), _tileWidth(tile_width), _tileHeight(tile_height), _origin(osg::Image::BOTTOM_LEFT), _zoomRegistrationPoint(), _clampingPolicy(ClampSoft), _useCache(true), _debug(options.debug), _debugTiles(options.debugTiles), _tilesComputed(false), _lastLevelId(0), _enabled(true) { _tilesToHideCache = new TilesToHideCache(options.tilesCacheLifeTime); _mergeController = new MergeController(this, options.numTilesToMergePerFrame); setUpdateCallback(new Tiled2DGraphicsUpdateCallback(this)); setZoomLevel(_minZoomLevel); updateOffset(ClampHard); setZoomRegistrationPoint(cefix::Rect::getCenter(constraining_rect)); if (_debug) { cefix::DebugGeometryFactory::enable("tiles_2d"); cefix::DebugGeometryFactory::enable("tiles_2d_overlay"); cefix::DebugGeometryFactory::get("tiles_2d")->setLocZ(1); addChild(cefix::DebugGeometryFactory::get("tiles_2d")->getOrCreateNode()); } }
AbstractHimmel::AbstractHimmel() : osg::MatrixTransform() , m_timef(NULL) , m_autoUpdateTime(false) , m_initialized(false) , m_dirty(false) , m_cameraHint(NULL) , m_widthHint(0u) , m_heightHint(0u) , m_lastElapsed(0.0) , m_referenceBoundingRadius(1.f) { setupNode(getOrCreateStateSet()); setUpdateCallback(new HimmelNodeCallback); setReferenceFrame(osg::Transform::ABSOLUTE_RF); };
Reflection() { setRenderOrder(osg::Camera::PRE_RENDER); setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); setReferenceFrame(osg::Camera::RELATIVE_RF); setSmallFeatureCullingPixelSize(Settings::Manager::getInt("small feature culling pixel size", "Water")); setName("ReflectionCamera"); bool reflectActors = Settings::Manager::getBool("reflect actors", "Water"); setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_ParticleSystem|Mask_Sky|Mask_Player|Mask_Lighting|(reflectActors ? Mask_Actor : 0)); setNodeMask(Mask_RenderToTexture); unsigned int rttSize = Settings::Manager::getInt("rtt size", "Water"); setViewport(0, 0, rttSize, rttSize); // No need for Update traversal since the mSceneRoot is already updated as part of the main scene graph // A double update would mess with the light collection (in addition to being plain redundant) setUpdateCallback(new NoTraverseCallback); mReflectionTexture = new osg::Texture2D; mReflectionTexture->setInternalFormat(GL_RGB); mReflectionTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); mReflectionTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); mReflectionTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); mReflectionTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); attach(osg::Camera::COLOR_BUFFER, mReflectionTexture); // XXX: should really flip the FrontFace on each renderable instead of forcing clockwise. osg::ref_ptr<osg::FrontFace> frontFace (new osg::FrontFace); frontFace->setMode(osg::FrontFace::CLOCKWISE); getOrCreateStateSet()->setAttributeAndModes(frontFace, osg::StateAttribute::ON); mClipCullNode = new ClipCullNode; addChild(mClipCullNode); }
TextShape::TextShape(std::string command, std::string name) { _type = SimpleShape::TEXT; BasicShape::setName(name); setColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); setCharacterSize(10.0f); setFontResolution(40,40); setFont ("/usr/share/fonts/liberation/LiberationSans-Regular.ttf"); setAxisAlignment(osgText::TextBase::XZ_PLANE); setBackdropType(osgText::Text::NONE); osg::StateSet* state = osgText::Text::getOrCreateStateSet(); state->setMode(GL_BLEND, osg::StateAttribute::ON); state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); //osg::Material* mat = new osg::Material(); //mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); //state->setAttributeAndModes(mat, osg::StateAttribute::ON); setUpdateCallback(new TextUpdateCallback()); update(command); }
LightManager::LightManager() { setDataVariance(DYNAMIC); setUpdateCallback(Utils::makeNodeCallback(this, &LightManager::update)); }
LaserScanLineNode::LaserScanLineNode(URGCPPWrapper &urg) : laser_scan_line(new LaserScanLine(urg)) { setUpdateCallback(new LaserScanLineCallback); addDrawable(laser_scan_line); }
void OrbitalBodyImposter::updatePhase(osg::Vec3 const &direction_to_sun, double ambient) { if (!getUpdateCallback()) { setUpdateCallback(m_PhaseShader->makeCallback(m_CoreTexture.get(), direction_to_sun, ambient)); } }