Beispiel #1
0
void RttManager::CDepthReflectionListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
{
  Hydrax *mHydrax = mRttManager->mHydrax;

  Ogre::SceneManager::MovableObjectIterator EntityIterator = mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
  Ogre::Entity* CurrentEntity;
  unsigned int k;

  while (EntityIterator.hasMoreElements()) {
    CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());

    for (k = 0; k < CurrentEntity->getNumSubEntities(); k++) {
      CurrentEntity->getSubEntity(k)->setMaterialName(mMaterials.front());

      mMaterials.pop();
    }

    EntityIterator.moveNext();
  }

  mHydrax->getMesh()->getEntity()->setVisible(true);

  if (mCameraPlaneDiff != 0) {
    mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->translate(0, mCameraPlaneDiff, 0);
  }

  mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->translate(0, mHydrax->getPlanesError(), 0);

  mHydrax->getCamera()->disableReflection();
  mHydrax->getCamera()->disableCustomNearClipPlane();
}
Beispiel #2
0
/**
 * @brief render a frame
 * @author Kito Berg-Taylor
 */
void THIS::paintGL()
{
    if (!initialised)
        initializeOgre();

    for (Ogre::SceneManager::MovableObjectIterator mit = mSceneMgr->getMovableObjectIterator("Entity");mit.hasMoreElements(); mit.moveNext() )
    {
        Ogre::Entity *entity = static_cast<Ogre::Entity*>(mit.peekNextValue());
        if (entity->hasSkeleton() )
        {
            for (Ogre::AnimationStateIterator animIt = entity->getAllAnimationStates()->getAnimationStateIterator(); animIt.hasMoreElements(); animIt.moveNext() )
            {
                Ogre::AnimationState *animState = animIt.peekNextValue();
                if ( animState->getEnabled() )
                {
                    animState->addTime(mWindow->getBestFPS()/10000);
                }
            }
        }
    }

    //Ogre::WindowEventUtilities::messagePump();
    mRoot->renderOneFrame();


}
Beispiel #3
0
void RttManager::CDepthListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
{
  Hydrax *mHydrax = mRttManager->mHydrax;

  Ogre::SceneManager::MovableObjectIterator EntityIterator = mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
  Ogre::Entity* CurrentEntity;
  unsigned int k;

  while (EntityIterator.hasMoreElements()) {
    CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());

    for (k = 0; k < CurrentEntity->getNumSubEntities(); k++) {
      CurrentEntity->getSubEntity(k)->setMaterialName(mMaterials.front());

      mMaterials.pop();
    }

    EntityIterator.moveNext();
  }

  mHydrax->getMesh()->getEntity()->setVisible(true);
  mHydrax->getGodRaysManager()->setVisible(false);
  mHydrax->getMesh()->getEntity()->setRenderQueueGroup(Ogre::RENDER_QUEUE_1);

  if (Ogre::Math::Abs(mHydrax->getPosition().y - mHydrax->getCamera()->getPosition().y) > mHydrax->getPlanesError()) {
    if (mHydrax->_isCurrentFrameUnderwater()) {
      mRttManager->mPlanes[RTT_DEPTH]->normal = -mRttManager->mPlanes[RTT_DEPTH]->normal;
      mRttManager->mPlanes[RTT_DEPTH]->getParentNode()->translate(0, +mHydrax->getPlanesError(), 0);
    } else {
      mRttManager->mPlanes[RTT_DEPTH]->getParentNode()->translate(0, -mHydrax->getPlanesError(), 0);
    }

    mHydrax->getCamera()->disableCustomNearClipPlane();
  }
}
Beispiel #4
0
	void DemoGameLogic::update(void)
	{
		mLastFrameTime = mCurrentTime;
		mCurrentTime = mTime->elapsed();

		float timeElapsedInSeconds = (mCurrentTime - mLastFrameTime) / 1000.0f;

		for (Ogre::SceneManager::MovableObjectIterator moi = mSceneManager->getMovableObjectIterator("Entity"); moi.hasMoreElements(); moi.moveNext())
		{
			Ogre::Entity *entity = static_cast<Ogre::Entity*>(moi.peekNextValue());

			Ogre::AnimationStateSet* animationStateSet = entity->getAllAnimationStates();		
			if(animationStateSet && animationStateSet->hasAnimationState("Walk"))
			{
				Ogre::AnimationState* walkAnimationState = animationStateSet->getAnimationState("Walk");
				walkAnimationState->addTime(timeElapsedInSeconds);
			}
		}

		float distance = mCameraSpeed * timeElapsedInSeconds;

		if(mKeyStates[Qt::Key_W] == KS_PRESSED)
		{
			mCamera->setPosition(mCamera->getPosition() + mCamera->getDirection() * distance);
		}
		if(mKeyStates[Qt::Key_S] == KS_PRESSED)
		{
			mCamera->setPosition(mCamera->getPosition() - mCamera->getDirection() * distance);
		}
		if(mKeyStates[Qt::Key_A] == KS_PRESSED)
		{
			mCamera->setPosition(mCamera->getPosition() - mCamera->getRight() * distance);
		}
		if(mKeyStates[Qt::Key_D] == KS_PRESSED)
		{
			mCamera->setPosition(mCamera->getPosition() + mCamera->getRight() * distance);
		}

		if(!mIsFirstFrame)
		{
			QPoint mouseDelta = mCurrentMousePos - mLastFrameMousePos;
			mCamera->yaw(Ogre::Radian(-mouseDelta.x() * timeElapsedInSeconds));
			mCamera->pitch(Ogre::Radian(-mouseDelta.y() * timeElapsedInSeconds));

			int wheelDelta = mCurrentWheelPos - mLastFrameWheelPos;
			Ogre::Radian fov = mCamera->getFOVy();
			fov += Ogre::Radian(-wheelDelta * 0.001);
			fov = (std::min)(fov, Ogre::Radian(2.0f));
			fov = (std::max)(fov, Ogre::Radian(0.5f));
			mCamera->setFOVy(fov);
		}
		mLastFrameMousePos = mCurrentMousePos;
		mLastFrameWheelPos = mCurrentWheelPos;

		mIsFirstFrame = false;
	}
void MainWindow::updateOGRE()
{
	QMutexLocker locker(&mutex);
	static bool updateGUI=true;


	Ogre::Root* mRoot = Ogre::Root::getSingletonPtr();
	mRoot->_fireFrameStarted();

	// loop through ogre widgets and update animation
	QList<OgreWidget*> rendlist = this->findChildren<OgreWidget*>();
	foreach (OgreWidget* w, rendlist)
	{

		// update animation for OgreWidget's sceneManager
		if (w->mRenderWindow && w->updatesEnabled())
		{
			// update OgreWidget
			w->update();
			//emit w->paintEvent(new QPaintEvent(w->rect()));
			for (Ogre::SceneManager::MovableObjectIterator mit = w->getSceneManager()->getMovableObjectIterator("Entity");
				mit.hasMoreElements(); mit.moveNext() )
			{
				Ogre::Entity *entity = static_cast<Ogre::Entity*>(mit.peekNextValue());
				if (updateGUI) {
					updateGUI = false;

				}
				// check has skeleton to avoid crash for non animable entities
				if (entity->hasSkeleton())
				{
					for (Ogre::AnimationStateIterator animIt = entity->getAllAnimationStates()->getAnimationStateIterator();
						animIt.hasMoreElements(); animIt.moveNext() )
					{
						Ogre::AnimationState *animState = animIt.peekNextValue();
						if ( animState->getEnabled() )
						{
							//std::cout << entity->getName() << " ZZZZZZZZZZZ " << animState->getAnimationName();
							animState->addTime(w->getRenderWindow()->getBestFPS()/10000);
						}
					}
				}
			}
		}
	}
	mRoot->_fireFrameRenderingQueued();
	mRoot->_fireFrameEnded();
}
	void RttManager::CDepthReflectionListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
    {
		Hydrax *mHydrax = mRttManager->mHydrax;

		mHydrax->getMesh()->getEntity()->setVisible(false);

        Ogre::SceneManager::MovableObjectIterator EntityIterator = 
			mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
        Ogre::Entity* CurrentEntity;
		unsigned int k;

        mMaterials.empty();

        while (EntityIterator.hasMoreElements())
        {
            CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());

			for(k = 0; k < CurrentEntity->getNumSubEntities(); k++)
			{
				mMaterials.push(CurrentEntity->getSubEntity(k)->getMaterialName());

			    CurrentEntity->getSubEntity(k)->setMaterialName(mHydrax->getMaterialManager()->getMaterial(MaterialManager::MAT_DEPTH)->getName());
			}

            EntityIterator.moveNext();
        }

        mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
		
        bool IsInUnderwaterError = false;

		if (mHydrax->getCamera()->getDerivedPosition().y > mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->getPosition().y)
		{
			mCameraPlaneDiff = 0;
			IsInUnderwaterError = true;
		}
		else
		{
			mCameraPlaneDiff = 0;
		}

        mHydrax->getCamera()->enableReflection(mRttManager->mPlanes[RTT_DEPTH_REFLECTION]);

		if (!IsInUnderwaterError)
		{
            mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_DEPTH_REFLECTION]);
		}
    }
Beispiel #7
0
  void GodRaysManager::DepthMapListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
  {
    Ogre::SceneManager::MovableObjectIterator EntityIterator = mGodRaysManager->mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
    Ogre::Entity * CurrentEntity = NULL;
    unsigned int k = 0;
    mGodRaysManager->mHydrax->getMesh()->getEntity()->setVisible(true);

    while(EntityIterator.hasMoreElements())
    {
      CurrentEntity = static_cast<Ogre::Entity *>(EntityIterator.peekNextValue());

      for(k = 0; k < CurrentEntity->getNumSubEntities(); k++)
      {
        CurrentEntity->getSubEntity(k)->setMaterialName(mMaterials.front());
        mMaterials.pop();
      }

      EntityIterator.moveNext();
    }
  }
Beispiel #8
0
	void DemoGameLogic::initialise(void)
	{
		//qApp->setStyleSheet(qApp->settings()->value("UI/StyleFile").toString());
		
		mDemoLog = mApplication->createLog("Demo");

		mApplication->showLogManager();

		mDemoLog->logMessage("A demonstration debug message", LL_DEBUG);
		mDemoLog->logMessage("A demonstration info message", LL_INFO);
		mDemoLog->logMessage("A demonstration warning message", LL_WARNING);
		mDemoLog->logMessage("A demonstration error message", LL_ERROR);

		//Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

		// Create the generic scene manager
		mSceneManager = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "GenericSceneManager");

		//Set up scene
		loadScene("media/scenes/test.scene");

		//mApplication->ogreRenderWindow()->addViewport(mCamera)->setBackgroundColour(Ogre::ColourValue::Black);

		mSceneManager->setAmbientLight( Ogre::ColourValue( 1, 1, 1 ) );

		//Create the MainMenu
		mMainMenu = new MainMenu(qApp, qApp->mainWidget());

		//Create widget to choose between models
		//mChooseMeshWidget = new ChooseMeshWidget(mJaiquaEntity, mRobotEntity, qApp->mainWidget());
		//mChooseMeshWidget->setWindowOpacity(qApp->settings()->value("System/DefaultWindowOpacity", 1.0).toDouble());
		//mChooseMeshWidget->move(qApp->mainWidget()->geometry().left() + qApp->mainWidget()->geometry().width() - mChooseMeshWidget->frameGeometry().width() - 10, qApp->mainWidget()->geometry().top() + 10);
		//mChooseMeshWidget->show();

		mTime = new QTime;
		mTime->start();

		mIsFirstFrame = true;

		mCameraSpeed = 10.0;

		

		for (Ogre::SceneManager::MovableObjectIterator moi = mSceneManager->getMovableObjectIterator("Entity"); moi.hasMoreElements(); moi.moveNext())
		{
			Ogre::Entity *entity = static_cast<Ogre::Entity*>(moi.peekNextValue());

			Ogre::AnimationStateSet* animationStateSet = entity->getAllAnimationStates();		
			if(animationStateSet && animationStateSet->hasAnimationState("Walk"))
			{
				Ogre::AnimationState* walkAnimationState = animationStateSet->getAnimationState("Walk");
				walkAnimationState->setLoop(true);
				walkAnimationState->setEnabled(true);
			}
		}

		mApplication->showFPSCounter();
		
		mStyleSettingsWidget = new StyleSettingsWidget;
		mApplication->addSettingsWidget("Style", mStyleSettingsWidget);
	}