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; }
Ogre::AnimationState* EC_OgreAnimationController::GetAnimationState(Ogre::Entity* entity, const std::string& name) { if (!entity) return 0; Ogre::AnimationStateSet* anims = entity->getAllAnimationStates(); if (!anims) return 0; if (anims->hasAnimationState(name)) return anims->getAnimationState(name); else return 0; }
//------------------------------------------------------------------------------------- void EntitySimple::setupAnimations() { if(modelName_ == "ogrehead.mesh") return; Ogre::AnimationStateSet* aniStetes = mBodyEnt->getAllAnimationStates(); if(aniStetes != NULL) { // populate our animation list for (int i = 0; i < SIMPLE_NUM_ANIMS; i++) { if(aniStetes->hasAnimationState(animNames[i])) { mAnims[i] = mBodyEnt->getAnimationState(animNames[i]); mAnims[i]->setLoop(true); } else { char c = animNames[i].c_str()[animNames[i].size() - 1]; if(c > '1' && c <= '9') { Ogre::String name = animNames[i]; name.erase(name.size() - 1, 1); name += "1"; mAnims[i] = mBodyEnt->getAnimationState(name); mAnims[i]->setLoop(true); } else mAnims[i] = NULL; } } } else { for (int i = 0; i < SIMPLE_NUM_ANIMS; i++) { mAnims[i] = NULL; } } if(mState != 1) playAnimation("Idle"); else playAnimation("Die"); }
void Actor::setAnimationEnabled(const QString& name, bool enabled) { assert(mNode); if(mNode->numAttachedObjects() == 0) { qWarning() << "Can't enable animation [" << name << "] on actor [" << getName() << "]" << " because it doesn't have any attached objects."; return; } Ogre::Entity* entity = dynamic_cast<Ogre::Entity*>(mNode->getAttachedObject(0)); if(!entity) { qWarning() << "Can't enable animation [" << name << "] on actor [" << getName() << "]" << " because its attachment isn't an entity."; return; } Ogre::AnimationStateSet* set = entity->getAllAnimationStates(); if(!set->hasAnimationState(name.toStdString())) { qWarning() << "Tried to set the state of an animation named " << name << " on actor " << QString::fromStdString(mNode->getName()) << " that doesn't exist. The animation states remain unchanged."; return; } Ogre::AnimationState* state = set->getAnimationState(name.toStdString()); state->setEnabled(enabled); state->setLoop(true); }
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); }