PlanarReflection::PlanarReflection( osg::Camera * sceneCamera )
{
    int w = 1024, h = 1024;
    _sceneCamera = sceneCamera;

    _texture = new osg::Texture2D;
    _texture->setInternalFormat( GL_RGBA );
    _texture->setSourceFormat( GL_RGBA );
    _texture->setSourceType( GL_UNSIGNED_BYTE );
    _texture->setTextureWidth( w );
    _texture->setTextureHeight( h );
    _texture->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST );
    _texture->setFilter( osg::Texture::MAG_FILTER, osg::Texture::NEAREST );
    _textureProjectionMatrix = new osg::RefMatrix();

    // set up the background color and clear mask.
    setClearColor(osg::Vec4(1.0f, 1.0f, 1.0f, 0.0f));
    setClearMask( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );

    setViewport( 0,0,w,h );
    setReferenceFrame( osg::Transform::ABSOLUTE_RF );

    // set the camera to render before the main camera.
    setRenderOrder(osg::Camera::PRE_RENDER);
    attach( osg::Camera::COLOR_BUFFER, _texture );

    setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
}
Esempio n. 2
0
SkyBox::SkyBox()
{
    setReferenceFrame( osg::Transform::ABSOLUTE_RF );
    setCullingActive( false );

    osg::StateSet* ss = getOrCreateStateSet();
    ss->setAttributeAndModes( new osg::Depth(osg::Depth::LEQUAL, 1.0f, 1.0f) );
    ss->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
    ss->setMode( GL_CULL_FACE, osg::StateAttribute::OFF );
    ss->setRenderBinDetails( 5, "RenderBin" );
}
Esempio n. 3
0
DisplayTexture::DisplayTexture()
{
    setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    setRenderOrder(osg::Camera::POST_RENDER);
    setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    setViewMatrix(osg::Matrix());
    setProjectionMatrix(osg::Matrix::ortho2D(0, 1, 0, 1));
    getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF);
    addChild(createFullscreenQuad());

    setName("Display");

}
Esempio n. 4
0
    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);
    }
Esempio n. 5
0
	void WeaponHUD::createWeaponHUD() {
	
		ref_ptr<Node> crow = osgDB::readNodeFile("../BlenderFiles/exports/Brecheisen.ive");
	/*
	 * here a transformation is applied to the crowbar to show 
	 * it at the lower right of the screen as if it is held in
	 * the right hand
	 */
		ref_ptr<MatrixTransform> crowTransform = new MatrixTransform;
        crowTransform->setMatrix(
         Matrix::rotate(osg::DegreesToRadians(3.0f), Y_AXIS)
       * Matrix::rotate(DegreesToRadians(190.0f), Z_AXIS)
       * Matrix::translate(osg::Vec3(1.0f, 1.5f, -1.5f))
                                );
		crowTransform->addChild(crow);
	/*
	 * adjusting the shininess to give the crowbar a good appearance 
	 */
        brtr::ModifyMaterialVisitor mmv;
        mmv.setShininess(42).setSpecular(Vec4(0.4, 0.4, 0.4, 1));
        crow->accept(mmv);
	/*
	 * Adding a weapon switch to enable multiple weapon use
	 */
        ref_ptr<Switch> switcher = new Switch;
        switcher->addChild(crowTransform, true);
        _switcher = switcher;
        _handler = new WeaponSwitchHandler(switcher);

        ref_ptr<brtr::CelShading> celshade = new brtr::CelShading;
        celshade->addChild(switcher);
        celshade->setNodeMask(~brtr::interactionAndCollisionMask);

		setClearMask(GL_DEPTH_BUFFER_BIT);
		setRenderOrder(Camera::POST_RENDER);
        setReferenceFrame(Camera::ABSOLUTE_RF);
        setProjectionMatrixAsPerspective(100, 1, 0.001, 5);
		
        setViewMatrixAsLookAt(Vec3(), Vec3(0,1,0), Z_AXIS);
        getOrCreateStateSet()->setMode(GL_LIGHTING, StateAttribute::OFF | StateAttribute::PROTECTED | StateAttribute::OVERRIDE);
        addChild(celshade);
	}
Esempio n. 6
0
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);
};
Esempio n. 7
0
    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);
    }
void addFullInstrumentToWorkspace(MatrixWorkspace &workspace,
                                  bool includeMonitors, bool startYNegative,
                                  const std::string &instrumentName) {
  auto instrument = boost::make_shared<Instrument>(instrumentName);
  instrument->setReferenceFrame(
      boost::make_shared<ReferenceFrame>(Y, Z, Right, ""));
  workspace.setInstrument(instrument);

  const double pixelRadius(0.05);
  Object_sptr pixelShape = ComponentCreationHelper::createCappedCylinder(
      pixelRadius, 0.02, V3D(0.0, 0.0, 0.0), V3D(0., 1.0, 0.), "tube");

  const double detZPos(5.0);
  // Careful! Do not use size_t or auto, the unisgned will break the -=2 below.
  int ndets = static_cast<int>(workspace.getNumberHistograms());
  if (includeMonitors)
    ndets -= 2;
  for (int i = 0; i < ndets; ++i) {
    std::ostringstream lexer;
    lexer << "pixel-" << i << ")";
    Detector *physicalPixel =
        new Detector(lexer.str(), workspace.getAxis(1)->spectraNo(i),
                     pixelShape, instrument.get());
    int ycount(i);
    if (startYNegative)
      ycount -= 1;
    const double ypos = ycount * 2.0 * pixelRadius;
    physicalPixel->setPos(0.0, ypos, detZPos);
    instrument->add(physicalPixel);
    instrument->markAsDetector(physicalPixel);
    workspace.getSpectrum(i).setDetectorID(physicalPixel->getID());
  }

  // Monitors last
  if (includeMonitors) // These occupy the last 2 spectra
  {
    Detector *monitor1 =
        new Detector("mon1", workspace.getAxis(1)->spectraNo(ndets),
                     Object_sptr(), instrument.get());
    monitor1->setPos(0.0, 0.0, -9.0);
    instrument->add(monitor1);
    instrument->markAsMonitor(monitor1);
    workspace.getSpectrum(ndets).setDetectorID(ndets + 1);

    Detector *monitor2 =
        new Detector("mon2", workspace.getAxis(1)->spectraNo(ndets) + 1,
                     Object_sptr(), instrument.get());
    monitor2->setPos(0.0, 0.0, -2.0);
    instrument->add(monitor2);
    instrument->markAsMonitor(monitor2);
    workspace.getSpectrum(ndets + 1).setDetectorID(ndets + 2);
  }

  // Define a source and sample position
  // Define a source component
  ObjComponent *source = new ObjComponent(
      "moderator",
      ComponentCreationHelper::createSphere(0.1, V3D(0, 0, 0), "1"),
      instrument.get());
  source->setPos(V3D(0.0, 0.0, -20.0));
  instrument->add(source);
  instrument->markAsSource(source);

  // Define a sample as a simple sphere
  ObjComponent *sample = new ObjComponent(
      "samplePos",
      ComponentCreationHelper::createSphere(0.1, V3D(0, 0, 0), "1"),
      instrument.get());
  instrument->setPos(0.0, 0.0, 0.0);
  instrument->add(sample);
  instrument->markAsSamplePos(sample);
  // chopper position
  Component *chop_pos = new Component("chopper-position",
                                      Kernel::V3D(0, 0, -10), instrument.get());
  instrument->add(chop_pos);
}
Esempio n. 9
0
int main(int argc, char** argv)
{
    osg::ArgumentParser arguments( &argc, argv );

    std::string dbPath;
    arguments.read("--db_path", dbPath);

    std::srand ( unsigned ( std::time(0) ) );

    auto board = Board(boardDefinition, boardSizeX, boardSizeY, dbPath);
    auto ghostFactory = GhostFactory();

    auto main_obj = make_ref<osg::Group>();
    main_obj->addChild(board.draw().get());

    auto ghostModel = osgDB::readNodeFile(dbPath + "/cow.osg");
    auto ghostCount = 16;
    while(ghostCount--)
    {
        main_obj->addChild(ghostFactory.drawGhost(board, ghostModel).get());
    }

    // init rotate
    auto init_rotate = make_ref<osg::MatrixTransform>();
    init_rotate->setMatrix( osg::Matrix::rotate(osg::PI * 2, osg::Vec3(1.0f, 0.0f, 0.0f)) );

    // chain rotates
    init_rotate->addChild(main_obj);

    // Root group
    auto root = make_ref<osg::Group>();
    root->addChild(init_rotate);

    // Setup fog
    if(FogEnabled) {
        osg::ref_ptr<osg::Fog> fog = new osg::Fog;
        fog->setMode( osg::Fog::EXP2 );
        fog->setStart( 0.0f );
        fog->setEnd(board.getFieldSizeX() * 20);
        fog->setDensity(0.0135);
        fog->setColor( osg::Vec4(0., 0., 0., 1.0) );

        root->getOrCreateStateSet()->setAttributeAndModes(fog.get());
    }

    // Start viewer
    osgViewer::Viewer viewer;

    // Set up flashlight
    auto lightSource = make_ref<osg::LightSource>();
    lightSource->setReferenceFrame(osg::LightSource::ABSOLUTE_RF);
    auto light = lightSource->getLight();
    const osg::Vec3 lightPosition{1.5, -1, -1}; // right, down, front
    light->setPosition(osg::Vec4{lightPosition, 1});
    light->setDirection(osg::Vec3{0, 0, -1} * 30 - lightPosition);
    light->setSpotExponent(60);
    light->setSpotCutoff(90);
    light->setDiffuse(osg::Vec4(1, 1, 1, 1));
    light->setAmbient(osg::Vec4(0.6, 0.6, 0.6, 1));
    light->setSpecular(osg::Vec4(1, 1, 1, 1));
    light->setLinearAttenuation(0.001);
    light->setConstantAttenuation(0.5);
    root->addChild(lightSource);

    double height = std::min(board.getFieldSizeX(), board.getFieldSizeY()) / 1.5;

    auto fpsManipulator = make_ref<FPSManipulator>(board, viewer, *light);
    fpsManipulator->setHomePosition(
        osg::Vec3d(board.getFieldCenterX(1), board.getFieldCenterY(10), height),
        osg::Vec3d(0.0f, 0.0f, height),
        osg::Vec3d(0.0f, 0.0f, 1.0f)
    );


    auto keySwitch = make_ref<osgGA::KeySwitchMatrixManipulator>();
    keySwitch->addNumberedMatrixManipulator(make_ref<osgGA::OrbitManipulator>());
    keySwitch->addNumberedMatrixManipulator(fpsManipulator);
    viewer.setCameraManipulator(keySwitch);

    viewer.home();
    viewer.setSceneData( root );

    osgViewer::Viewer::Windows windows;
    viewer.getWindows(windows);
    viewer.getCamera()->setClearColor(osg::Vec4{0, 0, 0, 0});

    viewer.getCamera()->getView()->setLightingMode(osg::View::HEADLIGHT);
    auto defaultLight = viewer.getCamera()->getView()->getLight();
    defaultLight->setDiffuse(osg::Vec4(0, 0, 0, 1));
    defaultLight->setAmbient(osg::Vec4(0, 0, 0, 1));
    defaultLight->setSpecular(osg::Vec4(0, 0, 0, 1));

    // Shaders
    auto program = make_ref<osg::Program>();
    auto fragmentObject = make_ref<osg::Shader>(osg::Shader::FRAGMENT);
    loadShaderSource(fragmentObject, dbPath + "/shader.frag");
    auto vertexObject = make_ref<osg::Shader>(osg::Shader::VERTEX);
    loadShaderSource(vertexObject, dbPath + "/shader.vert");
    program->addShader(vertexObject);
    program->addShader(fragmentObject);
    root->getOrCreateStateSet()->setAttributeAndModes(program, osg::StateAttribute::ON);

    root->getOrCreateStateSet()->addUniform(new osg::Uniform("samplerName", TEXTURE_UNIT));
    root->getOrCreateStateSet()->addUniform(new osg::Uniform("Shininess", BoardObjectsShininess));
    root->getOrCreateStateSet()->addUniform(new osg::Uniform("FogEnabled", FogEnabled));

    // Optimize
    osgUtil::Optimizer optimzer;
    optimzer.optimize(root);

    viewer.setUpViewOnSingleScreen(0);

    return viewer.run();
}
Esempio n. 10
0
void osaOSGHUD::Initialize( osg::GraphicsContext* gc ){

  // Set the intrinsic paramters
  setProjectionMatrixAsOrtho2D( 0, gc->getTraits()->width, 
				0, gc->getTraits()->height );
  setViewMatrix( osg::Matrix::identity() );
  setReferenceFrame( osg::Camera::ABSOLUTE_RF );
  setRenderOrder( osg::Camera::NESTED_RENDER );
  setClearMask( GL_DEPTH_BUFFER_BIT );
  
  getOrCreateStateSet()->setMode( GL_LIGHTING, GL_FALSE );
  getOrCreateStateSet()->setMode( GL_DEPTH_TEST, GL_FALSE );

  // don't capture events
  setAllowEventFocus(false);

  setGraphicsContext( gc );
  setViewport( gc->getTraits()->x,
	       gc->getTraits()->y,
	       gc->getTraits()->width, 
	       gc->getTraits()->height );

  // search for the HUD branch
  bool found = false;
  for( unsigned int i=0; i<root->getNumParents(); i++ ){
    
    osg::ref_ptr<osg::Node> parent = root->getParent( i );
    osg::ref_ptr<osg::Group> group = parent->asGroup();
    if( group != 0 ){
      for( unsigned int j=0; j<group->getNumChildren(); j++ ){
        osg::ref_ptr<osg::Node> child = group->getChild( j );
        if( child->getName() == "HUD" ){
          found = true;
          osg::ref_ptr<osg::Group> hud = child->asGroup();
          hud->addChild( this );
        }
      }
    }
  }
  
  if( !found ){
    
    // create/configure the hud branch
    osg::ref_ptr<osg::Group> hud = new osg::Group;
    hud->setName( "HUD" );
    hud->getOrCreateStateSet()->setRenderBinDetails( 1, "RenderBin" );
    hud->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
    
    // add this camera to the hud branch
    hud->addChild( this );
    
    // configure the world branch
    root->getOrCreateStateSet()->setRenderBinDetails( 2, "RenderBin" );
    root->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON);
    
    
    osg::ref_ptr<osg::Group> group = new osg::Group;
    group->addChild( hud );
    group->addChild( root );
    
    viewer->setSceneData( group.get() );
    
  }
  
}
AbsoluteModelTransform::AbsoluteModelTransform( const AbsoluteModelTransform& rhs, const osg::CopyOp& copyop )
  : osg::Transform( rhs, copyop ),
    _matrix( rhs._matrix )
{
    setReferenceFrame( osg::Transform::ABSOLUTE_RF );
}
AbsoluteModelTransform::AbsoluteModelTransform( const osg::Matrix& m )
  : _matrix( m )
{
    setReferenceFrame( osg::Transform::ABSOLUTE_RF );
}
AbsoluteModelTransform::AbsoluteModelTransform()
{
    setReferenceFrame( osg::Transform::ABSOLUTE_RF );
}