Ejemplo n.º 1
0
	//---------------------------------------------------------------------
	bool BillboardSetElement::_createBillboardSet(void)
	{
		Ogre::SceneNode* parent = mBasicNode;

		if (parent)
		{
			mBillboardSet = mSystem->getSceneManager()->createBillboardSet( parent->getName() );
			mBillboardSet->setMaterialName(mBillboardMaterial);

            if ( (mStacks > 1) || (mSlices > 1) )
                mBillboardSet->setTextureStacksAndSlices(mStacks, mSlices);

            mBillboardSet->setCastShadows(false);

            mBillboardSet->setVisible(mVisible);

			parent->attachObject(mBillboardSet);

			for ( int i=0; i<mBillboardCount; ++i )
			{
				Ogre::Billboard *billboard = mBillboardSet->createBillboard(0, i*mBillboardInterval, 0, mBillboardColour * mAlphaValue);
				assert (billboard);
				billboard->setDimensions(mBillboardWidth, mBillboardHeight);
			}

            _resetBillboardStartTexIndex();
            _resetBillboardStartScaleTime();

			return true;
		}

		return false;
	}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------------------
bool CBillboardSetEditor::load(bool async)
{
    if(mLoaded->get())
        return true;
    
    if(CNodeEditor::load())
    {
        mBillboardSetHandle = mOgitorsRoot->GetSceneManager()->createBillboardSet(mName->get());
        mHandle->attachObject(mBillboardSetHandle);
        
        mBillboardSetHandle->setBillboardType((Ogre::BillboardType)mBillboardType->get());
        mBillboardSetHandle->setSortingEnabled(mSorting->get());
        mBillboardSetHandle->setBillboardOrigin((Ogre::BillboardOrigin)mOrigin->get());
        mBillboardSetHandle->setBillboardRotationType((Ogre::BillboardRotationType)mRotation->get());
        mBillboardSetHandle->setDefaultWidth(mDefaultWidth->get());
        mBillboardSetHandle->setDefaultHeight(mDefaultHeight->get());
        mBillboardSetHandle->setVisibilityFlags(1 << mLayer->get());
        if(mMaterial->get() != "")
            mBillboardSetHandle->setMaterialName(mMaterial->get());
        
        mBillboardSetHandle->setPointRenderingEnabled(mPointRendering->get());
        mBillboardSetHandle->setRenderingDistance(mRenderDistance->get());

        Ogre::Vector2 v2val;
        Ogre::Vector3 v3val;
        Ogre::Vector4 v4val;
        Ogre::ColourValue cval;
        Ogre::Real rval;
        int ival;
        Ogre::String propname;

        int count = mBillboardCount->get();
        for(int ix = 0;ix < count;ix++)
        {
            propname = "billboard" + Ogre::StringConverter::toString(ix);

            Ogre::Billboard *pBillboard = mBillboardSetHandle->createBillboard(Ogre::Vector3::ZERO);
            mProperties.getValue(propname + "::position", v3val);
            pBillboard->setPosition(v3val);
            mProperties.getValue(propname + "::colour", cval);
            pBillboard->setColour(cval);
            mProperties.getValue(propname + "::dimensions", v2val);
             pBillboard->setDimensions(v2val.x, v2val.y);
            mProperties.getValue(propname + "::rotation", rval);
            pBillboard->setRotation(Ogre::Degree(rval));
            mProperties.getValue(propname + "::texcoordindex", ival);
            pBillboard->setTexcoordIndex(ival);
            mProperties.getValue(propname + "::texrect", v4val);
            pBillboard->setTexcoordRect(v4val.x, v4val.y, v4val.z, v4val.w);
        }

    }
    else
        return false;

    return true;
}
Ejemplo n.º 3
0
	void Billboard::build(){
			mBillboardSet = Level::getSingleton()->getSceneManager()->createBillboardSet(mFilename+ts(GameElement::getNextIdCounter()));
			mBillboardSet->setMaterialName(mFilename);
			mBillboardSet->setCullIndividually(true);
			
			//mBillboardSet->setPointRenderingEnabled(true);
			//mBillboardSet->setBillboardsInWorldSpace(true);
			//mBillboardSet->setBillboardType(Ogre::BillboardType::BBT_PERPENDICULAR_COMMON);
			if (mParentConnector.mGameObject == NULL){
				mSceneNode->attachObject(mBillboardSet);
			}else{
				//Ogre::Vector3 scale = mSceneNode->getScale();
				if (mParentConnector.mBone != ""){
					mParentConnector.mGameObject->getEntity()->attachObjectToBone(mParentConnector.mBone, mBillboardSet);
					getNode()->setPosition(mSceneNode->getPosition());
					getNode()->setOrientation(mSceneNode->getOrientation());
				}else{
					throw("Billboard object requires to be attached to a parent's bone.  No bone, no go");
				}


				//mEntity->getParentNode()->setScale(scale);
				//mBoneNodeMode =true;
			}


			
			//attachObject(mBillboardSet);
			
			Ogre::AxisAlignedBox box(Ogre::Vector3(0,0,0), Ogre::Vector3(0,0,0));
			for (list<BILLBOARD_ELEMENT>::iterator it = mBillboardElement.begin();it!=mBillboardElement.end();it++){
				Ogre::Billboard* bb = mBillboardSet->createBillboard((*it).mPos, (*it).mColour);
				bb->setDimensions((*it).mSize.x,(*it).mSize.y);

				Ogre::Vector3 np1 = (*it).mPos + Ogre::Vector3((*it).mSize.x, (*it).mSize.y, (*it).mSize.x);
				Ogre::Vector3 np2 = (*it).mPos - Ogre::Vector3((*it).mSize.x, (*it).mSize.y, (*it).mSize.x);
				Ogre::AxisAlignedBox box2(np2, np1);
				box.merge(box2);
			}
			mBillboardSet->setBounds(box, (*mBillboardElement.begin()).mSize.x);
		


		/*mHaloSet = mSceneMgr->createBillboardSet("halo");
	mHaloSet->setMaterialName("lensflare/halo");
	mHaloSet->setCullIndividually(true);
	mHaloSet->setQueryFlags(VOIDOBJECT);	// They should not be detected by rays.*/
		Parent::build();
		//attachObject(mCamera);
		mBillboardSet->setQueryFlags(SceneQueryFlag::IMMATERIAL);
		mBillboardSet->setRenderQueueGroup(mLevelSegment->getSceneManager()->getRenderQueue()->getDefaultQueueGroup()+getRenderQueueDelta());
		
	}
Ejemplo n.º 4
0
/**
 * @inheritDoc
 */
Error ImageGraphicObject::initialize(void) {
    ASSERT(!m_bInitialized);
    
    std::string image = IMAGE_BASE_PATH + m_image;
    /*m_sourceImage = IMG_Load(image.c_str());
    m_displayImage = SDL_ConvertSurface(m_sourceImage, m_sourceImage->format, m_sourceImage->flags);*/
    
    Ogre::SceneNode* rootNode = static_cast<GraphicScene*>(m_pSystemScene)->getRootNode();
    Ogre::SceneManager* sceneManager = static_cast<GraphicScene*>(m_pSystemScene)->getSceneManager();
    Ogre::SceneNode* myNode = static_cast<Ogre::SceneNode*>(rootNode->createChild());
    Ogre::BillboardSet* mySet = sceneManager->createBillboardSet("mySet");
    Ogre::Billboard* myBillboard = mySet->createBillboard(Ogre::Vector3(0, 0, 0));
    myBillboard->setDimensions(100, 100);
    myNode->attachObject(mySet);
    
    m_bInitialized = true;
    return Errors::Success;
}
Ejemplo n.º 5
0
	//---------------------------------------------------------------------
	void BillboardSetElement::setBillboardCount(int count)
	{
		mBillboardCount = count;

		if (mBillboardSet)
		{
			mBillboardSet->clear();

			for ( int i=0; i<mBillboardCount; ++i )
			{
				Ogre::Billboard *billboard = mBillboardSet->createBillboard(0, i*mBillboardInterval, 0, mBillboardColour * mAlphaValue);
				assert (billboard);
				billboard->setDimensions(mBillboardWidth, mBillboardHeight);
			}

            _resetBillboardStartTexIndex();
            _resetBillboardStartScaleTime();
		}
	}
int OgreBillboardInterface::createBillboard(const std::string& name, const vec2& size, const vec3& displacement, Transformable* link) {
	if(billboard_sets.count(name) == 0) {
		char buf[256];
		sprintf(buf, "Invalid billboard set '%s'", name.c_str());
		LOG(buf);
		return -1;
	}

	int id = icount;
	icount++;
	billboards[id].displacement = displacement;
	billboards[id].link = link;
	billboards[id].link_id = link->getId();
	billboards[id].size = size;
	Ogre::Billboard* b = billboard_sets[name]->createBillboard(Ogre::Vector3(0, 0, 0));
	billboards[id].billboard = b;
	billboards[id].set = billboard_sets[name];
	b->setDimensions(size[0], size[1]);
	billboards[id].set->notifyBillboardDataChanged();
	
	return id;
}
Ejemplo n.º 7
0
	void Lightning::create()
	{
		remove();

		Ogre::Vector3 end = mOrigin + mDirection*mLength;
		Ogre::Vector3 current, last = mOrigin;

		// Create ray segments
		for(Ogre::uint32 k = 1; k < mDivisions+1; k++)
		{
			Ogre::Vector3 current = mOrigin + mDirection*mLength*(static_cast<Ogre::Real>(k)/mDivisions);

			current += (mLength/(mDivisions*3))*Ogre::Vector3(
				Ogre::Math::RangeRandom(-1, 1), Ogre::Math::RangeRandom(-1, 1), Ogre::Math::RangeRandom(-1, 1));

			mSegments.push_back(Segment(last, current));

			mRealLength += (current-last).length();

			last = current;
		}

		// Create the associated billboard set
		mBillboardSet = mSceneManager->createBillboardSet();
		mBillboardSet->setMaterialName("SkyX_Lightning");
		mBillboardSet->setBillboardType(Ogre::BBT_ORIENTED_SELF);

		Ogre::Real width = mWidthMultiplier*3*(static_cast<Ogre::Real>(mRecursivity)/4+1)*Ogre::Math::RangeRandom(0.5f, 2.5f-mRecursivity/3);

		// Create the associated billboard for each segment
		Ogre::Real delta;
		Ogre::Vector2 bounds;
		Ogre::Billboard* bb;
		for(Ogre::uint32 k = 0; k < mSegments.size(); k++)
		{
			delta = 1.0f / mSegments.size();
			bounds = Ogre::Vector2(k*delta,(k+1)*delta);

			bounds = Ogre::Vector2(mBounds.x, mBounds.x) + bounds*(mBounds.y-mBounds.x);

			bb = mBillboardSet->createBillboard((mSegments.at(k).a+mSegments.at(k).b)/2);
			bb->setDimensions(width, (mSegments.at(k).a-mSegments.at(k).b).length());
			bb->setColour(Ogre::ColourValue(0,bounds.x,bounds.y));
			bb->mDirection = (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy();

			bb = mBillboardSet->createBillboard(mSegments.at(k).a + (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy()*width/2);
			bb->setDimensions(width, width);
			bb->setColour(Ogre::ColourValue(1,bounds.x,bounds.x));
			bb->mDirection = (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy();
			
			bb = mBillboardSet->createBillboard(mSegments.at(k).b - (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy()*width/2);
			bb->setDimensions(width, width);
			bb->setColour(Ogre::ColourValue(1,bounds.y,bounds.y));
			bb->mDirection = -(mSegments.at(k).a-mSegments.at(k).b).normalisedCopy();
		
			width *= 1-(1.0f/(mRecursivity*mRecursivity))*(1.0f/mSegments.size());
		}

		mBillboardSet->_updateBounds();

		mSceneNode->attachObject(mBillboardSet);

		mBillboardSet->setCustomParameter(0, Ogre::Vector4(1,0,0,0));

		// Ramifications
		if (mRecursivity > 0)
		{
			Ogre::Real angle;
			Ogre::Vector3 dir;
			Ogre::Real lengthMult;
			for (Ogre::uint32 k = 0; k < mDivisions-1; k++)
			{
				angle = (mSegments.at(k).b-mSegments.at(k).a).normalisedCopy().dotProduct(
					((mSegments.at(k+1).b-mSegments.at(k+1).a).normalisedCopy()));

				if (angle < Ogre::Math::RangeRandom(mAngleRange.x, mAngleRange.y))
				{
					dir = (mSegments.at(k).b-mSegments.at(k).a).normalisedCopy();
					dir.x *= Ogre::Math::RangeRandom(0.8f, 1.2f);
					dir.y *= Ogre::Math::RangeRandom(0.8f, 1.2f);
					dir.z *= Ogre::Math::RangeRandom(0.8f, 1.2f);
					dir.normalise();

					delta = 1.0f / mSegments.size();
					bounds = Ogre::Vector2(mBounds.x+(mBounds.y-mBounds.x)*(k+1)*delta,1);

					lengthMult = Ogre::Math::RangeRandom(0.1f, 0.7f);

					Lightning* lightning = new Lightning(mSceneManager, mSceneNode, mSegments.at(k).b, dir, lengthMult*mLength, 2+mDivisions*lengthMult, mRecursivity-1, mTimeMultiplier, mWidthMultiplier, bounds);
					lightning->create();
					
					mChildren.push_back(lightning);
				}
			}
		}

		mCreated = true;
	}
Ejemplo n.º 8
0
    //---------------------------------------------------------------------
    void BillboardSetElement::updateRenderInstance( Real time, TransformInfo &info )
    {
        if (mBillboardSet)
        {
            bool updateTexIndex = false;

            if (mSlices > 1 || mStacks > 1)
            {
                mCurrentTexIntervalTime += time;

                if (mCurrentTexIntervalTime >= mTexIntervalTime)
                {
                    updateTexIndex = true;
                    mCurrentTexIntervalTime = 0.0f;
                }            
            }

            for ( int i = 0; i < mBillboardSet->getNumBillboards(); ++i )
            {
                Ogre::Billboard* billboard = mBillboardSet->getBillboard(i);

                if (updateTexIndex)
                {
                    uint16 texIndex = billboard->getTexcoordIndex();
                    ++texIndex;

                    if (texIndex == mStacks * mSlices)
                        texIndex = 0;

                    billboard->setTexcoordIndex(texIndex);
                }
                
                if (mColourChanged)
                    billboard->setColour(mBillboardColour * mAlphaValue);

                if (mSizeChanged)
                {
                    _CurrentScaleInfo& info = mCurrentScaleInfos[i];
                    info.mCurrentScaleIntervalTime += time;

                    float colourPersent = fmod( info.mCurrentScaleIntervalTime, mScaleIntervalTime );

                    if (info.mCurrentScaleIntervalTime > mScaleIntervalTime)
                    {
                        info.mCurrentScaleIntervalTime  = colourPersent;

                        ++(info.mCurrentIndex);

                        if (info.mCurrentIndex == MAX_STAGES)
                            info.mCurrentIndex = 0;
                    }

                    Ogre::Vector3 resultColour;

                    Real rate = colourPersent / mScaleIntervalTime;

                    int incIndex = info.mCurrentIndex + 1;
                    if (incIndex == MAX_STAGES)
                        incIndex = 0;

                    resultColour = mBillboardScale[info.mCurrentIndex] * (1-rate) + mBillboardScale[incIndex] * rate;

                    billboard->setDimensions(mBillboardWidth * resultColour.x,
                        mBillboardHeight * resultColour.y);
                }
            }

            if (mColourChanged)
                mColourChanged = false;
        }
    }
Ejemplo n.º 9
0
int main(int argc, char* argv[])
{
	std::unique_ptr<ExecutionArgs> exArgs(new ExecutionArgs());
	if (!processCommandLineArgs(argc, argv, *exArgs)) {
		return -1;
	} else if (exArgs->helpPrompt) {
		std::cout << "Usage: sts [--help] || [--config]" << std::endl;
		std::cout << "Options:" << std::endl;
		std::cout << "\t --help - print this message;" << std::endl;
		std::cout << "\t --config - show config dialog." << std::endl;
		std::cout << std::endl;
		return 0;
	}

	try {
		Ogre::String lConfigFileName = "ogre.cfg";
		Ogre::String lPluginsFileName = "plugins.cfg";
		Ogre::String lLogFileName = "Ogre_STS.log";

		std::unique_ptr<Ogre::Root> lRoot(new Ogre::Root(lPluginsFileName, lConfigFileName, lLogFileName));

		if (exArgs->showConfigDialog) {
			if (!lRoot->showConfigDialog()) {
				return 0;
			}
		}

		Ogre::String lWindowTitle = "STS";
		Ogre::String lCustomCapacities = "";

		/* Check for the valid ogre.cfg */
		bool lCreateAWindowAutomatically = lRoot->restoreConfig();
		if (!lCreateAWindowAutomatically) {
			initSomeRenderSystem(lRoot);
		}
		Ogre::RenderWindow* lWindow = lRoot->initialise(lCreateAWindowAutomatically, lWindowTitle, lCustomCapacities);

		if (!lWindow) {
			/* ogre.cfg is not available - start with hardcoded parameters */
			unsigned int lSizeX = 800;
			unsigned int lSizeY = 600;
			bool lFullscreen = false;

			Ogre::NameValuePairList lParams;
			lParams["FSAA"] = "0";
			lParams["vsync"] = "true";
			lWindow = lRoot->createRenderWindow(lWindowTitle, lSizeX, lSizeY, lFullscreen, &lParams);
		}

		/* Create a scene manager */
		Ogre::SceneManager* lScene = lRoot->createSceneManager(Ogre::ST_GENERIC, "SceneManager");

		Ogre::SceneNode* lRootSceneNode = lScene->getRootSceneNode();

		/* Create camera */
		Ogre::Camera* lCamera = lScene->createCamera("MyCamera");

		/* Create viewport (camera <-> window) */
		Ogre::Viewport* vp = lWindow->addViewport(lCamera);

		vp->setAutoUpdated(true);
		vp->setBackgroundColour(Ogre::ColourValue(1, 0, 1));

		lCamera->setAspectRatio(float(vp->getActualWidth()) / vp->getActualHeight());
		lCamera->setPosition(Ogre::Vector3(0, 100, -1));
		lCamera->lookAt(Ogre::Vector3(0, 0, 0));

		/* Set clipping*/
		lCamera->setNearClipDistance(1.5f);
		lCamera->setFarClipDistance(3000.0f);

		/* Lighting */
		Ogre::Light* lLight = lScene->createLight("MainLight");
		lLight->setPosition(Ogre::Vector3(0, 100, 0));

		/* Resource manager */
		Ogre::String lRcGroupName = "Main group";
		initResourceMainGroup(lRcGroupName);

		/* Load model */
		Ogre::Entity* lShipEntity = lScene->createEntity("airship.mesh");
		lShipEntity->setCastShadows(false);

		Ogre::SceneNode* lShipNode = lRootSceneNode->createChildSceneNode();
		lShipNode->attachObject(lShipEntity);
		lShipNode->setScale(Ogre::Vector3(3.15f, 3.15f, 3.15f));

		/* Starship start point */
		Ogre::Vector3 razorSP(0, -200, -100);
		lShipNode->setPosition(razorSP);

		/* Sprite billboard */
		Ogre::SceneNode* lSpriteNode = lRootSceneNode->createChildSceneNode();
		Ogre::BillboardSet* lBillboardSet = lScene->createBillboardSet();
		lBillboardSet->setMaterialName("enemy_01", lRcGroupName);
		lBillboardSet->setTextureStacksAndSlices(1, 4);
		Ogre::Billboard* lSpriteBillboard = lBillboardSet->createBillboard(Ogre::Vector3(0, 0, 0));
		lSpriteBillboard->setDimensions(48.0f / 2.0f, 58.0f / 2.0f);
		lSpriteBillboard->setTexcoordIndex(1);
		lSpriteNode->attachObject(lBillboardSet);
		lSpriteNode->setPosition(Ogre::Vector3(0, -200, 100));

		/* Obtain the timer pointer */
		Ogre::Timer* lTimer = lRoot->getTimer();

		/* Skip all the messages */
		lWindow->setAutoUpdated(false);
		lRoot->clearEventTimes();

		while (!lWindow->isClosed()) {
			float angle = Ogre::Math::Sin(float(lTimer->getMilliseconds()) * Ogre::Math::PI / 2000.0f) * Ogre::Math::PI / 4.0f;
			float diplacement = Ogre::Math::Cos(float(lTimer->getMilliseconds()) * Ogre::Math::PI / 2000.0f) * 100.0f;
			lShipNode->setOrientation(Ogre::Quaternion(Ogre::Radian(angle), Ogre::Vector3(0, 0, 1)));
			lShipNode->setPosition(razorSP + Ogre::Vector3(diplacement, 0.0f, 0.0f));

			unsigned int spriteFrame = (lTimer->getMilliseconds() / 125) % 2;
			lSpriteBillboard->setTexcoordIndex(spriteFrame);

			lWindow->update(false);
			lWindow->swapBuffers();
			lRoot->renderOneFrame();

			Ogre::WindowEventUtilities::messagePump();
		}
		Ogre::LogManager::getSingleton().logMessage("Render window closed.");
	}
	catch (Ogre::Exception &e) {
		std::cerr << "Ogre::Exception: " << e.what() << std::endl;
	}
	catch (std::exception &e) {
		std::cerr << "std::exception: " << e.what() << std::endl;
	}

	return 0;
}