Esempio n. 1
0
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/");
}
Esempio n. 2
0
        bool Button::init(const std::string& normalImage, const std::string& selectedImage, const std::string& pressedImage, const std::string& disabledImage,
                          const std::string& label, const graphics::Color& labelColor, const std::string& font)
        {
            eventHandler = std::make_shared<EventHandler>(EventHandler::PRIORITY_MAX + 1);

            eventHandler->gamepadHandler = std::bind(&Button::handleGamepad, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
            eventHandler->uiHandler = std::bind(&Button::handleUI, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);

            sharedEngine->getEventDispatcher()->addEventHandler(eventHandler);

            if (!normalImage.empty())
            {
                normalSprite = std::make_shared<scene::Sprite>();
                if (normalSprite->initFromFile(normalImage, false))
                {
                    addDrawable(normalSprite);
                }
            }

            if (!selectedImage.empty())
            {
                selectedSprite = std::make_shared<scene::Sprite>();
                if (selectedSprite->initFromFile(selectedImage, false))
                {
                    addDrawable(selectedSprite);
                }
            }

            if (!pressedImage.empty())
            {
                pressedSprite = std::make_shared<scene::Sprite>();
                if (pressedSprite->initFromFile(pressedImage, false))
                {
                    addDrawable(pressedSprite);
                }
            }

            if (!disabledImage.empty())
            {
                disabledSprite = std::make_shared<scene::Sprite>();
                if (disabledSprite->initFromFile(disabledImage, false))
                {
                    addDrawable(disabledSprite);
                }
            }

            if (!label.empty())
            {
                labelDrawable = scene::TextDrawable::create(font, label);
                if (labelDrawable)
                {
                    labelDrawable->setColor(labelColor);
                    addDrawable(labelDrawable);
                }
            }

            updateSprite();

            return true;
        }
Esempio n. 3
0
// 初期化処理
bool AdventureScene::init(SceneManager* smgr) {
    // リソースファイルのロード
	ImageResourceManager& ircmgr = smgr->getResources().images();
	ircmgr.loadFromCSV("data/adventure_imgs.csv");
	SoundResourceManager& srcmgr = smgr->getResources().sounds();
	srcmgr.loadFromCSV("data/adventure_sounds.csv");
    // シナリオデータの読み込み
	mp_script->init(m_scriptPath);
    // タスクの登録処理
	std::vector<std::string>::iterator it;
	InstructionExpression iExp;
	std::string line;
	while ((line = mp_script->getLine()) != "") {
		Context context(line);
		iExp.interpret(context, smgr, this);
	}
    // 画面レイアウトの構築
    // メッセージウィンドウの登録
	DrawableImage* msgwindow = new DrawableImage();
	msgwindow->setHandle(ircmgr.get("message_window"));
	msgwindow->setPosition(0, 360);
	addDrawable("message_window", msgwindow, 7);
    // 名前表示ウィンドウの登録
	DrawableImage* namewindowRight = new DrawableImage();
	namewindowRight->setHandle(ircmgr.get("name_window"));
	namewindowRight->setPosition(0, 310);
	addDrawable("name_window_R", namewindowRight, 7);
    DrawableImage* namewindowLeft = new DrawableImage();
	namewindowLeft->setHandle(ircmgr.get("name_window"));
	namewindowLeft->setPosition(570, 310);
	addDrawable("name_window_L", namewindowLeft, 7);
	return true;
}
Esempio n. 4
0
        bool CheckBox::init(const std::string& normalImage, const std::string& selectedImage, const std::string& pressedImage, const std::string& disabledImage, const std::string& tickImage)
        {
            eventHandler = std::make_shared<EventHandler>(EventHandler::PRIORITY_MAX + 1);

            eventHandler->gamepadHandler = std::bind(&CheckBox::handleGamepad, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
            eventHandler->uiHandler = std::bind(&CheckBox::handleUI, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);

            sharedEngine->getEventDispatcher()->addEventHandler(eventHandler);

            if (!normalImage.empty())
            {
                normalSprite = std::make_shared<scene::Sprite>();
                if (normalSprite->initFromFile(normalImage, false))
                {
                    addDrawable(normalSprite);
                }
            }

            if (!selectedImage.empty())
            {
                selectedSprite = std::make_shared<scene::Sprite>();
                if (selectedSprite->initFromFile(selectedImage, false))
                {
                    addDrawable(selectedSprite);
                }
            }

            if (!pressedImage.empty())
            {
                pressedSprite = std::make_shared<scene::Sprite>();
                if (pressedSprite->initFromFile(pressedImage, false))
                {
                    addDrawable(pressedSprite);
                }
            }

            if (!disabledImage.empty())
            {
                disabledSprite = std::make_shared<scene::Sprite>();
                if (disabledSprite->initFromFile(disabledImage, false))
                {
                    addDrawable(disabledSprite);
                }
            }

            if (!tickImage.empty())
            {
                tickSprite = std::make_shared<scene::Sprite>();
                if (tickSprite->initFromFile(tickImage, false))
                {
                    addDrawable(tickSprite);
                }
            }

            updateSprite();

            return true;
        }
Esempio n. 5
0
    void rebuild_client_area(const osgfxbrowser::Rect &client_rect)
    {
                float zPos = -0.1; // note from Robert, was 0.1f, but now must be -0.1f to keep text visible??#!? due
                                   // to some other change in the OSG not tracked down yet...

        osg::ref_ptr<osgText::Font> arial = osgText::readRefFontFile("fonts/arial.ttf");

        osg::ref_ptr<osgText::Text> hints = new osgText::Text;
        hints->setFont(arial);
        hints->setColor(_hints_color);
        hints->setAlignment(osgText::Text::CENTER_BOTTOM);
        hints->setCharacterSize(13);
        hints->setPosition(osg::Vec3((client_rect.x0+client_rect.x1)/2, client_rect.y0 + 4, zPos));
        hints->setText("<RETURN> show/hide this panel      <LEFT> previous effect      <RIGHT> next effect      <DEL> enable/disable effects      'x' save to file      'r' rotate/stop");
        addDrawable(hints.get());

        std::string effect_name = "No Effect Selected";
        std::string effect_description = "";

        if (_selected_fx >= 0 && _selected_fx < static_cast<int>(_effects.size())) {
            effect_name = _effects[_selected_fx]->effectName();
            std::string author_name = _effects[_selected_fx]->effectAuthor();
            if (!author_name.empty()) {
                effect_description = author_name = "AUTHOR: " + std::string(_effects[_selected_fx]->effectAuthor()) + std::string("\n\n");
            }
            effect_description += "DESCRIPTION:\n" + std::string(_effects[_selected_fx]->effectDescription());

            if (_scene.valid() && _root.valid()) {
                _root->removeChildren(0, _root->getNumChildren());
                osg::ref_ptr<osgFX::Effect> effect = _effects[_selected_fx].get();
                effect->setEnabled(_fxen);
                effect->removeChildren(0, effect->getNumChildren());
                effect->addChild(_scene.get());
                effect->setUpDemo();
                _root->addChild(effect.get());
            }
        }

        osg::ref_ptr<osgText::Text> ename = new osgText::Text;
        ename->setFont(arial.get());
        ename->setColor(_name_color);
        ename->setAlignment(osgText::Text::CENTER_TOP);
        ename->setCharacterSize(32);
        ename->setPosition(osg::Vec3((client_rect.x0 + client_rect.x1) / 2, client_rect.y1 - 22, zPos));
        ename->setText(effect_name);
        addDrawable(ename.get());

        osg::ref_ptr<osgText::Text> edesc = new osgText::Text;
        edesc->setMaximumWidth(client_rect.width() - 16);
        edesc->setFont(arial.get());
        edesc->setColor(_desc_color);
        edesc->setAlignment(osgText::Text::LEFT_TOP);
        edesc->setCharacterSize(16);
        edesc->setPosition(osg::Vec3(client_rect.x0 + 8, client_rect.y1 - 60, zPos));
        edesc->setText(effect_description);
        addDrawable(edesc.get());
    }
Esempio n. 6
0
void CSulGeomArrow3D::createDrawable()
{
	// note: osg uses the center value for "center of mass" that is is why the cone has a 0.25 offset!
	osg::ref_ptr<osg::ShapeDrawable> rShapeHead = new osg::ShapeDrawable( new osg::Cone(osg::Vec3(0.0f,0.0f,m_bodyLen+m_headLen*0.25f), m_headRadius, m_headLen) );
	rShapeHead->setColor( m_colorHead );

	osg::ref_ptr<osg::ShapeDrawable> rShapeBody = new osg::ShapeDrawable( new osg::Cylinder(osg::Vec3(0.0f,0.0f,m_bodyLen/2.0f),m_bodyRadius,m_bodyLen) );
	rShapeBody->setColor( m_colorBody );

	addDrawable( rShapeHead );
	addDrawable( rShapeBody );
}
Esempio n. 7
0
OrbitalBodyImposter::OrbitalBodyImposter(osg::Image *core, double image_fraction, osg::Image *flare, double flare_scale) {
	assert(core);

	if (flare) {
		m_FlareImposter = makeImposter(flare, flare_scale / image_fraction, 0, true);
		addDrawable(m_FlareImposter.get());
	}

	// TODO need to take image_fraction into account
	m_PhaseShader = new PhaseShader;
	m_PhaseShader->setImage(core);
	m_CoreImposter = makeImposter(m_PhaseShader->getShadedImage(), 1.0 / image_fraction, &m_CoreTexture);
	addDrawable(m_CoreImposter.get());
}
Esempio n. 8
0
void EyeMap::createDrawables() {
  // Remove any existing Drawables
  _drawables.erase(_drawables.begin(), _drawables.end());

  // 1. First the faces
  faces = new osg::Geometry();
  faces->setSupportsDisplayList(false);

  faces->setVertexArray(_verts.get());
  faces->setColorArray(_colors.get());
  faces->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);

  // Normal
  osg::ref_ptr<osg::Vec3Array> ns(new osg::Vec3Array);
  ns->push_back(osg::Vec3(0.0f,0.0f,1.0f));
  faces->setNormalArray(ns.get());
  faces->setNormalBinding(osg::Geometry::BIND_OVERALL);

  int cur_size = 0;
  GLbyte this_len = 0;
  for (int i=0; i<_fan_lengths->getNumElements(); i++) {
    this_len = _fan_lengths->index(i);
    // The triangle fan that represents the face
    faces->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_FAN,cur_size,this_len));
    cur_size += this_len;
  }
  
  addDrawable(faces.get());
}
Esempio n. 9
0
void StarsGeode::createAndAddDrawable(const char* brightStarsFilePath)
{
    BrightStars bs(brightStarsFilePath);
    const BrightStars::s_BrightStar *stars = bs.stars();

    osg::ref_ptr<osg::Vec4Array> cAry = new osg::Vec4Array(bs.numStars());
    osg::ref_ptr<osg::Vec4Array> vAry = new osg::Vec4Array(bs.numStars());

    for(unsigned int i = 0; i < bs.numStars(); ++i)
    {
        t_equf equ;
        equ.right_ascension = _rightascd(stars[i].RA, 0, 0);
        equ.declination = stars[i].DE;

        osg::Vec3f vec = equ.toEuclidean();
        (*vAry)[i] = osg::Vec4f(vec.x(), vec.y(), vec.z(), i);

        (*cAry)[i] = osg::Vec4f(stars[i].sRGB_R, stars[i].sRGB_G, stars[i].sRGB_B, stars[i].Vmag + 0.4);
        // the 0.4 accounts for magnitude decrease due to the earth's atmosphere
    }
      
    osg::ref_ptr<osg::Geometry> g = new osg::Geometry;
    addDrawable(g);

    g->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
    g->setColorArray(cAry);
    g->setVertexArray(vAry);

    g->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, vAry->size()));

    // If things go wrong, fall back to big point rendering without geometry shader.
    g->getOrCreateStateSet()->setAttribute(new osg::Point(TWO_TIMES_SQRT2));
}
Esempio n. 10
0
void World::randomize(uint32_t width, uint32_t height, uint32_t nbObstacles, uint32_t seed)
{
    if(seed == 0)
    {
        seed = static_cast<uint32_t>(std::time(0));
    }

    std::mt19937 rng(seed);

    std::uniform_int_distribution<uint32_t> heightDistribution(0, height);
    std::uniform_int_distribution<uint32_t> widthDistribution(0, width);
    std::uniform_int_distribution<uint32_t> angleDistribution(0, 359);
    std::normal_distribution<float32> sizeDistribution(10.0, 5.0);

    for(uint32_t i = 0; i < nbObstacles; ++i)
    {
        std::shared_ptr<StaticBox> box = std::make_shared<StaticBox>(
            b2Vec2(widthDistribution(rng), heightDistribution(rng)),
            angleDistribution(rng),
            std::abs(sizeDistribution(rng)),
            std::abs(sizeDistribution(rng))
        );
        addDrawable(box);
    }
}
Esempio n. 11
0
osgToy::Normals::Normals( Node *node, float scale, Mode mode )
{
    MakeNormalsVisitor mnv(scale);
    mnv.setMode( mode );
    node->accept( mnv );

    osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;

    osg::ref_ptr<osg::Vec3Array> coords = mnv.getCoords();
    geom->setVertexArray( coords.get() );

    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    geom->setColorArray( colors.get() );
    geom->setColorBinding( osg::Geometry::BIND_OVERALL );
    if( mode == SurfaceNormals )
        colors->push_back( osg::Vec4( 1, 0, 0, 1 ));
    else if( mode == VertexNormals )
        colors->push_back( osg::Vec4( 0, 1, 0, 1 ));

    geom->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, 0, coords->size()));

    osg::StateSet* sset = geom->getOrCreateStateSet();
    sset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );

    addDrawable( geom.get() );
}
Esempio n. 12
0
	void Bar::createGeometry()
	{
		removeDrawables(0, getNumDrawables());
		
		// Create border
		_bordergeometry = new osg::Geometry;
		_bordergeometry->setName("border");
		_bordervecs = new osg::Vec3Array;
		_bordervecs->resize(4);
		_bordergeometry->setVertexArray(_bordervecs);
		_bordergeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,4));
		_bordercolors = new osg::Vec4Array;
		_bordercolors->push_back(_bordercolor);
		_bordergeometry->setColorArray(_bordercolors);
		_bordergeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
		addDrawable(_bordergeometry);
		
		// Create bar
		_bargeometry = new osg::Geometry;
		_bargeometry->setName("bar");
		_barvecs = new osg::Vec3Array;
		_barvecs->resize(4);
		_bargeometry->setVertexArray(_barvecs);
		_bargeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));
		_barcolors = new osg::Vec4Array;
		_barcolors->push_back(_barcolor);
		_bargeometry->setColorArray(_barcolors);
		_bargeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
		addDrawable(_bargeometry);
		
		// Create mark
		_markgeometry = new osg::Geometry;
		_markgeometry->setName("mark");
		_markvecs = new osg::Vec3Array;
		_markvecs->resize(4);
		_markgeometry->setVertexArray(_markvecs);
		_markgeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));
		_markcolors = new osg::Vec4Array;
		_markcolors->push_back(_markcolor);
		_markgeometry->setColorArray(_markcolors);
		_markgeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
		addDrawable(_markgeometry);
		
		setSize(_length,_width);
	}
void GameState_Game1::OnAwake(const SFMLStateInfo* lStateInfo)
{
	std::unique_ptr<sf::CircleShape> circle(new sf::CircleShape(150.0f));
	circle->setPosition(sf::Vector2f(400,300));
	circle->setFillColor(sf::Color::Yellow);
	circle->setOutlineThickness(2.0f);
	circle->setOutlineColor(sf::Color::White);
	addDrawable(std::move(circle));
}
Esempio n. 14
0
void World::addBorders(uint32_t width, uint32_t height)
{
    float32 w = static_cast<float32>(width);
    float32 h = static_cast<float32>(height);
    float32 w2 = w / 2.0f;
    float32 h2 = h / 2.0f;

    std::shared_ptr<StaticBox> boxL = std::make_shared<StaticBox> (b2Vec2(0.0f, h2), 0.0f, 1.0f, h);
    addDrawable(boxL);

    std::shared_ptr<StaticBox> boxU = std::make_shared<StaticBox>(b2Vec2(w2, 0.0f), 0.0f, w, 1.0f);
    addDrawable(boxU);

    std::shared_ptr<StaticBox> boxR = std::make_shared<StaticBox>(b2Vec2(w, h2), 0.0f, 1.0f, h);
    addDrawable(boxR);

    std::shared_ptr<StaticBox> boxD = std::make_shared<StaticBox>(b2Vec2(w2, h), 0.0f, w, 1.0f);
    addDrawable(boxD);
}
Esempio n. 15
0
        bool redraw(bool bClear = true)
            {
                double minX,maxX,minY,maxY;
                double zeroX,zeroY;
                double lineWidth;
                if (!computeMinMax(minX,maxX,minY,maxY))
                {
                    cerr << "Could not compute the minmax" << endl;
                    return false;
                }
//            lineWidth = 2.0*Utils::min(double(maxX-minX)/width(),double(maxY-minY)/height());
                lineWidth = 1.0;

                zeroX = (-double(minX)*(width()-1.0)/(maxX-minX));
                zeroY = (-double(minY)*(height()-1.0)/(maxY-minY));

                int basis;
                basis=createBasis(zeroX,zeroY,(width()-1.0)/double(maxX-minX),(height()-1.0)/double(maxY-minY));
                for (int i=0;i<mFunctions.size();i++)
                {
                    Functions *f = &mFunctions[i];
                    Surface *surface = new Surface(*f->pFunction,f->minX,f->minY,f->maxX-f->minX,f->maxY-f->minY);
                    addDrawable(basis,surface,false);
                }
                for (int i=0;i<mLines.size();i++)
                {
                    for (int j=1;j<mLines[i].xs.size();j++)
                    {
                        Line *line = new Line(mLines[i].xs[j-1],mLines[i].ys[j-1],mLines[i].xs[j],mLines[i].ys[j],lineWidth);
                        addDrawable(basis,line,false);
                    }
                }
                for (int i=0;i<mRectangles.size();i++)
                {
//                 Rectangle *rect = new Rectangle(mRectangles[i].x,mRectangles[i].y,mRectangles[i].w,mRectangles[i].h,lineWidth,mRectangles[i].color);
//                 addDrawable(basis,rect,false);
                }
                if (bClear)
                    clear();
                flip();
                return true;
            }
Esempio n. 16
0
//==============================================================================
void BoxShapeGeode::extractData()
{
  if(nullptr == mDrawable)
  {
    mDrawable = new BoxShapeDrawable(mBoxShape);
    addDrawable(mDrawable);
    return;
  }

  mDrawable->refresh(false);
}
Esempio n. 17
0
//==============================================================================
void EllipsoidShapeGeode::extractData()
{
  if(nullptr == mDrawable)
  {
    mDrawable = new EllipsoidShapeDrawable(mEllipsoidShape, mVisualAspect, this);
    addDrawable(mDrawable);
    return;
  }

  mDrawable->refresh(false);
}
Esempio n. 18
0
//==============================================================================
void CylinderShapeGeode::extractData()
{
  if(nullptr == mDrawable)
  {
    mDrawable = new CylinderShapeDrawable(mCylinderShape, this);
    addDrawable(mDrawable);
    return;
  }

  mDrawable->refresh(false);
}
Esempio n. 19
0
void Frame::rebuild()
{
    float zPos = -0.1f;

    removeDrawables(0, getNumDrawables());
    addDrawable(build_quad(rect_, bgcolor_));
    addDrawable(build_quad(Rect(rect_.x0 + 4, rect_.y1 - 24, rect_.x1 - 4, rect_.y1 - 4), osg::Vec4(0, 0, 0, bgcolor_.w()), false, zPos));

    osg::ref_ptr<osgText::Text> caption_text = new osgText::Text;
    caption_text->setText(caption_);
    caption_text->setColor(osg::Vec4(1, 1, 1, 1));
    caption_text->setAlignment(osgText::Text::CENTER_CENTER);
    caption_text->setFont("fonts/arial.ttf");
    caption_text->setCharacterSize(16);
    caption_text->setFontResolution(16, 16);
    caption_text->setPosition(osg::Vec3((rect_.x0 + rect_.x1) / 2, rect_.y1 - 15, zPos*2.0f));
    addDrawable(caption_text.get());

    rebuild_client_area(Rect(rect_.x0 + 4, rect_.y0 + 4, rect_.x1 - 4, rect_.y1 - 28));
}
Esempio n. 20
0
void HeightmapShapeGeode<S>::extractData()
{
  if (nullptr == mDrawable)
  {
    mDrawable
        = new HeightmapShapeDrawable<S>(mHeightmapShape, mVisualAspect, this);
    addDrawable(mDrawable);
    return;
  }

  mDrawable->refresh(false);
}
void LevelPortal::update(SubLevel* subLevel_p){
	
	auto& ps = PortalSpecs::get();

	if (mIsWaiting){
		++mWaitingFrames; 
	}
	if (mWaitingFrames == PortalSpecs::get().mWaitingFrames){

		auto& player = *mSubLevel_p->getLevel()->getPlayer();
		auto& camera = *mSubLevel_p->getLevel()->getCamera();

		auto nextSubLevel_p = std::shared_ptr<SubLevel>();
		sf::Vector2f newPos;
		{
			nextSubLevel_p = mSubLevel_p->getLevel()->getSubLevel(mTargetLevel);
			auto temp_sp = nextSubLevel_p->getEntity( mTargetPortal ).lock();
			auto nextPortal_p = dynamic_cast<LevelPortal*>(temp_sp.get() );
				//////////////////////////////////////////////////////////////
				// /Get the position of the targetPortal
				// /
				// /Adjust the position so that the player does not spawn
				// /directly into a new portal and is teleported back
				//////////////////////////////////////////////////////////////
			auto& rect = nextPortal_p->getHitBox();
			auto tilesWide = static_cast<int>(rect.width / X_STEP) -1;

			nextPortal_p->setEnabled(false);

			newPos = sf::Vector2f( rect.left + X_STEP * tilesWide, rect.top);
		}

		//////////////////////////////////////////////////////////////
		// /Switch sublevel to the target level.
		// /Move the player to the position previously calculated
		// /Snap the camera to the players position
		// /Lock the camera again (since snapToPosition unlocks it automaticly)
		//////////////////////////////////////////////////////////////
		mSubLevel_p->getLevel()->switchSubLevel( mTargetLevel );
		player.setPosition( newPos );
		player.setFacingDirection(mDirection);
		camera.snapToPosition( GAME_TO_SCREEN * newPos );
		camera.lockCamera();

		auto fade_sp = std::shared_ptr<SubLevelFade>(new SubLevelFade(PortalSpecs::get().mWaitingFrames, SubLevelFade::FADE_IN));
		nextSubLevel_p->addEntity(fade_sp);
		nextSubLevel_p->addDrawable(fade_sp, SubLevel::DRAW_SCREEN);
		mIsWaiting = false;
		mWaitingFrames = 0;
	}	

	mCurrentAnimation_p->updateAnimation();		
}
Esempio n. 22
0
CaremeInterface::CaremeInterface(Careme* instrument,const sf::Vector2f& size):
Interface(sf::Vector2u(1120,691),size),
_texture(),
_back(),
_instrument(instrument),
_envAttackKnob(0),
_envDecayKnob(0),
_envSustainKnob(0),
  _envReleaseKnob(0)
{
  if (_instrument && _texture.loadFromFile("img/careme.png"))
  {
    _back.setTexture(_texture);
    _back.setTextureRect(sf::IntRect(0,0,1120,691));

    _envAttackKnob =  new NELead6Knob(_instrument->getParameter(PARAM_CAREME_ENVATTACK),
                                      _texture,
                                      sf::IntRect(1120,0,128,128),
                                      sf::IntRect(1120,128,128,128));                                   
    _envDecayKnob =  new NELead6Knob( _instrument->getParameter(PARAM_CAREME_ENVDECAY),
                                      _texture,
                                      sf::IntRect(1120,0,128,128),
                                      sf::IntRect(1120,128,128,128));                                   
    _envSustainKnob =  new NELead6Knob( _instrument->getParameter(PARAM_CAREME_ENVSUSTAIN),
                                        _texture,
                                        sf::IntRect(1120,0,128,128),
                                        sf::IntRect(1120,128,128,128));                                   
    _envReleaseKnob =  new NELead6Knob( _instrument->getParameter(PARAM_CAREME_ENVRELEASE),
                                        _texture,
                                        sf::IntRect(1120,0,128,128),
                                        sf::IntRect(1120,128,128,128)); 


    sf::Vector2f scale(0.6f,0.6f);
    _envAttackKnob->setScale(scale);
    _envDecayKnob->setScale(scale);
    _envSustainKnob->setScale(scale);
    _envReleaseKnob->setScale(scale);

    _envAttackKnob->setPosition(744,24);
    _envDecayKnob->setPosition(832,24);
    _envSustainKnob->setPosition(925,24);
    _envReleaseKnob->setPosition(1020,24);

    addMouseCatcher(_envAttackKnob);
    addMouseCatcher(_envDecayKnob);
    addMouseCatcher(_envSustainKnob);
    addMouseCatcher(_envReleaseKnob);
    
    addDrawable(&_back);
  }
}
Esempio n. 23
0
void CSulGeomGrid::createDrawable()
{
	m_rGeo = new osg::Geometry;
	addDrawable( m_rGeo );

	m_rGeo->setVertexArray( new osg::Vec3Array );
    m_rGeo->setColorArray( new osg::Vec4Array );
    m_rGeo->setColorIndices( new osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType, 4, 4> );
	m_rGeo->setColorBinding( osg::Geometry::BIND_PER_VERTEX );

    m_rPrimitiveSet = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
    m_rGeo->addPrimitiveSet( m_rPrimitiveSet.get() );
}
Esempio n. 24
0
// create fake layer geometry
void CloudsLayer::_createGeometry()
{
    // dummy bounding box callback
    osg::Drawable::ComputeBoundingBoxCallback * pDummyBBCompute = new osg::Drawable::ComputeBoundingBoxCallback();

    // create OSG geode with 1 drawable node
    setCullingActive(false);
    setDataVariance(osg::Object::STATIC);

    // create tetrahedron around viewer (just to fill the whole volume)
    osg::Geometry * box_geometry = new osg::Geometry;
    box_geometry->setUseDisplayList(true);
    box_geometry->setDataVariance(osg::Object::STATIC);
    box_geometry->setComputeBoundingBoxCallback(pDummyBBCompute);

    const float fSqrt3 = sqrtf(3.0f);

    // create its' vertex
    osg::Vec3Array * paBoxPointsPos = new osg::Vec3Array;
    paBoxPointsPos->resize(4);
    paBoxPointsPos->at(0).set(0.f, 0.f, +2.f);
    paBoxPointsPos->at(1).set(-2.0f * fSqrt3, 0.f, -1.0f);
    paBoxPointsPos->at(2).set(fSqrt3, -3.0f, -1.0f);
    paBoxPointsPos->at(3).set(fSqrt3, +3.0f, -1.0f);
    // set vertex array
    paBoxPointsPos->setDataVariance(osg::Object::STATIC);
    box_geometry->setVertexArray(paBoxPointsPos);

    // draw elements command, that would be executed
    // volume is made looking inside
    osg::DrawElementsUShort * paBoxDrawElem = new osg::DrawElementsUShort(GL_TRIANGLES, 12);
    paBoxDrawElem->at(0)  = 0;
    paBoxDrawElem->at(1)  = 2;
    paBoxDrawElem->at(2)  = 1;
    paBoxDrawElem->at(3)  = 0;
    paBoxDrawElem->at(4)  = 3;
    paBoxDrawElem->at(5)  = 2;
    paBoxDrawElem->at(6)  = 0;
    paBoxDrawElem->at(7)  = 1;
    paBoxDrawElem->at(8)  = 3;
    paBoxDrawElem->at(9)  = 1;
    paBoxDrawElem->at(10) = 2;
    paBoxDrawElem->at(11) = 3;

    // add DIP
    paBoxDrawElem->setDataVariance(osg::Object::STATIC);
    box_geometry->addPrimitiveSet(paBoxDrawElem);

    // all is done, so add box to this geode
    addDrawable(box_geometry);
}
Esempio n. 25
0
bool World::willCollide(std::shared_ptr<Drawable> d)
{
    assert(d && "Drawable is null");
    assert(m_world && "World is null");
    addDrawable(d);
    m_world->Step(m_simulationRate/1000.0, m_velocityIterations, m_positionIterations);

    bool result = d->isColliding();

    d->die(this);
    this->removeDrawables();
    d->setMarkedForDeath(false);

    return result;
}
Esempio n. 26
0
        bool Label::init(const std::string& fontFile, const std::string& newText, const Vector2& newTextAnchor)
        {
            text = newText;
            textDrawable = scene::TextDrawable::create(fontFile, text, newTextAnchor);

            if (!textDrawable)
            {
                return false;
            }

            addDrawable(textDrawable);

            textDrawable->setText(text);

            return true;
        }
Esempio n. 27
0
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/");
}
Esempio n. 28
0
//==============================================================================
void LineSegmentShapeGeode::extractData(bool firstTime)
{
  if(mLineSegmentShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_PRIMITIVE)
     || firstTime)
  {
    mLineWidth->setWidth(mLineSegmentShape->getThickness());
    getOrCreateStateSet()->setAttributeAndModes(mLineWidth);
  }

  if(nullptr == mDrawable)
  {
    mDrawable = new LineSegmentShapeDrawable(mLineSegmentShape.get());
    addDrawable(mDrawable);
    return;
  }

  mDrawable->refresh(false);
}
Esempio n. 29
0
TexturedCuboid::TexturedCuboid(const osg::Vec3 &from, const osg::Vec3 &size) :
    Cuboid(from, size)
{
    _textureDrawable = new osg::Geometry();

    osg::Vec3Array *pyramidVertices = new osg::Vec3Array();
    {
        pyramidVertices->push_back( from + osg::Vec3(0, 0, size.z()));
        pyramidVertices->push_back( from + osg::Vec3(size.x(), 0, size.z()));
        pyramidVertices->push_back( from + osg::Vec3(size.x(), size.y(), size.z()));
        pyramidVertices->push_back( from + osg::Vec3(0, size.y(), size.z()));
    }

    _textureDrawable->setVertexArray( pyramidVertices );

    osg::DrawElementsUInt *face = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
    face->push_back(0);
    face->push_back(1);
    face->push_back(2);
    face->push_back(3);
    
    _textureDrawable->addPrimitiveSet(face);
        
    osg::Vec2Array* texcoords = new osg::Vec2Array(4);
    {
        (*texcoords)[0].set(size.x(), 0.0f);
        (*texcoords)[1].set(0.0f, 0.0f);
        (*texcoords)[3].set(size.x(), size.y() / 3.0f);
        (*texcoords)[2].set(0.0f,  size.y() / 3.0f); 

        _textureDrawable->setTexCoordArray(0, texcoords);
    }
             
    _texture = new osg::Texture2D;
    _texture->setDataVariance(osg::Object::DYNAMIC); 
    _texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); 
    _texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);

    osg::StateSet* stateSet = _textureDrawable->getOrCreateStateSet();
    stateSet->setTextureAttributeAndModes(0, _texture, osg::StateAttribute::ON);
    
    _textureDrawable->setStateSet(stateSet);
    addDrawable(_textureDrawable);
}
Esempio n. 30
0
void CSulGeomTriangleList::createDrawable()
{
	m_rGeo = new osg::Geometry;
	addDrawable( m_rGeo );

	osg::Vec3Array *verts = new osg::Vec3Array;
    osg::ref_ptr<osg::UIntArray> indices = new osg::UIntArray;
	m_rColors = new osg::Vec4Array;

	float c = 1.0f;
	sigma::uint32 count = 0;
	sigma::VEC_TRI::iterator i;	// FIXME: bet there is a good cpy stl thingy that can do this
	i = m_vecTri.begin();
	while ( i!=m_vecTri.end() )
	{
		verts->push_back( i->m_p0 );
		verts->push_back( i->m_p1 );
		verts->push_back( i->m_p2 );

		indices->push_back( count++ );
		indices->push_back( count++ );
		indices->push_back( count++ );

		m_rColors->push_back( osg::Vec4(c,c,c,1.0f) );
		m_rColors->push_back( osg::Vec4(c,c,c,1.0f) );
		m_rColors->push_back( osg::Vec4(c,c,c,1.0f) );

		++i;
	}
	m_rGeo->setVertexArray( verts );

    m_rGeo->setColorArray( m_rColors.get() );
	m_rGeo->setColorBinding( osg::Geometry::BIND_PER_VERTEX );

    m_rGeo->addPrimitiveSet(
        new osg::DrawElementsUInt( 
			GL_TRIANGLES,
            indices->size(), 
			&(indices->front())
		)
	);
}