本文整理汇总了C++中ogre::AnimationState类的典型用法代码示例。如果您正苦于以下问题:C++ AnimationState类的具体用法?C++ AnimationState怎么用?C++ AnimationState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AnimationState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void Actor::update(float deltaTime)
{
assert(mNode);
if(mNode->numAttachedObjects() == 0)
{
return;
}
Ogre::Entity* entity = dynamic_cast<Ogre::Entity*>(mNode->getAttachedObject(0));
if(!entity)
{
return;
}
Ogre::AnimationStateSet* set = entity->getAllAnimationStates();
if(!set)
{
return;
}
Ogre::AnimationStateIterator it = set->getAnimationStateIterator();
while(it.hasMoreElements())
{
Ogre::AnimationState* state = it.getNext();
if(state->getEnabled())
{
state->addTime(deltaTime);
}
}
}
示例2: insertBoundedPart
NifOgre::EntityList NpcAnimation::insertBoundedPart(const std::string &mesh, int group, const std::string &bonename)
{
NifOgre::EntityList entities = NifOgre::Loader::createEntities(mEntityList.mSkelBase, bonename,
mInsert, mesh);
std::vector<Ogre::Entity*> &parts = entities.mEntities;
for(size_t i = 0;i < parts.size();i++)
{
parts[i]->getUserObjectBindings().setUserAny(Ogre::Any(group));
if (mVisibilityFlags != 0)
parts[i]->setVisibilityFlags(mVisibilityFlags);
for(unsigned int j=0; j < parts[i]->getNumSubEntities(); ++j)
{
Ogre::SubEntity* subEnt = parts[i]->getSubEntity(j);
subEnt->setRenderQueueGroup(subEnt->getMaterial()->isTransparent() ? RQG_Alpha : RQG_Main);
}
}
if(entities.mSkelBase)
{
Ogre::AnimationStateSet *aset = entities.mSkelBase->getAllAnimationStates();
Ogre::AnimationStateIterator asiter = aset->getAnimationStateIterator();
while(asiter.hasMoreElements())
{
Ogre::AnimationState *state = asiter.getNext();
state->setEnabled(false);
state->setLoop(false);
}
Ogre::SkeletonInstance *skelinst = entities.mSkelBase->getSkeleton();
Ogre::Skeleton::BoneIterator boneiter = skelinst->getBoneIterator();
while(boneiter.hasMoreElements())
boneiter.getNext()->setManuallyControlled(true);
}
return entities;
}
示例3: getAnimationMask
float GfxBody::getAnimationMask (const std::string &name)
{
if (dead) THROW_DEAD(className);
Ogre::AnimationState *state = getAnimState(name);
if (!state->getEnabled()) return 0.0f;
return state->getWeight();
}
示例4: EnableAnimation
bool EC_OgreAnimationController::EnableAnimation(const std::string& name, bool looped, Real fadein, bool high_priority)
{
Ogre::Entity* entity = GetEntity();
Ogre::AnimationState* animstate = GetAnimationState(entity, name);
if (!animstate)
return false;
animstate->setLoop(looped);
// See if we already have this animation
AnimationMap::iterator i = animations_.find(name);
if (i != animations_.end())
{
i->second.phase_ = PHASE_FADEIN;
i->second.num_repeats_ = (looped ? 0: 1);
i->second.fade_period_ = fadein;
i->second.high_priority_ = high_priority;
return true;
}
// Start new animation from zero weight & speed factor 1, also reset time position
animstate->setTimePosition(0.0f);
Animation newanim;
newanim.phase_ = PHASE_FADEIN;
newanim.num_repeats_ = (looped ? 0: 1); // if looped, repeat 0 times (loop indefinetly) otherwise repeat one time.
newanim.fade_period_ = fadein;
newanim.high_priority_ = high_priority;
animations_[name] = newanim;
return true;
}
示例5: setAnimationMask
void GfxBody::setAnimationMask (const std::string &name, float v)
{
if (dead) THROW_DEAD(className);
Ogre::AnimationState *state = getAnimState(name);
state->setWeight(v);
state->setEnabled(v > 0.0f);
}
示例6: paintGL
/**
* @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();
}
示例7: id
void
PlayersManager::createPlayer(zappy::Player *player)
{
Ogre::Entity *ent;
Ogre::SceneNode *node;
Ogre::AnimationState *anim;
std::string id(NumberToString<unsigned int>(player->getId()));
OPlayer *toAdd;
ent = this->mSceneMgr->createEntity("Player" + id, "robot.mesh");
node = this->mSceneMgr->getRootSceneNode()->
createChildSceneNode(PLAYERNODENAME + id,
Ogre::Vector3(player->getX() * Constants::SquareSize,
0,
player->getY() * Constants::SquareSize));
ent->setQueryFlags(Constants::PLAYER_MASK);
anim = ent->getAnimationState("Idle");
anim->setLoop(true);
anim->setEnabled(true);
node->attachObject(ent);
player->setRendered(true);
toAdd = new OPlayer(ent, node);
toAdd->setSpell(this->mSceneMgr->createParticleSystem("Aureola" + id, "Examples/Aureola"));
toAdd->setBroad(this->mSceneMgr->createParticleSystem("Purple" + id, "Examples/PurpleFountain"));
this->mOPlayers.push_back(toAdd);
}
示例8: main
int main(int argc, char **argv)
{
if(argc <= 1 || argc > 2)
{
std::cout << "Invalid argument, it sould be : ./ogre_show_animationstate /path/name.mesh !\n";
return -1;
}
std::string nameMesh(argv[1]);
std::string pathMesh;
int index = nameMesh.size();
while(nameMesh[index] != '/')
{
index--;
if(index == 0)
{
pathMesh = "./";
break;
}
}
if(index != 0)
{
pathMesh = nameMesh.substr(0, index);
}
// Init
Ogre::Root* mRoot = new Ogre::Root();
new Ogre::DefaultHardwareBufferManager();
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./", "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(pathMesh, "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
// load mesh
Ogre::MeshPtr mesh =
Ogre::MeshManager::getSingleton().load(nameMesh, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// create & load a SkeletonInstance
Ogre::SkeletonInstance* skelInst = new Ogre::SkeletonInstance(mesh->getSkeleton());
skelInst->load();
// create & load an AnimationStateSet
Ogre::AnimationStateSet* animStateSet = new Ogre::AnimationStateSet();
mesh->_initAnimationState(animStateSet);
// show animation state
std::cout << "Animation states : \n";
Ogre::AnimationStateIterator iter = animStateSet->getAnimationStateIterator();
while(iter.hasMoreElements())
{
Ogre::AnimationState* animationState = iter.getNext();
std::cout << "\t- " << animationState->getAnimationName() << "\n";
}
return 0;
}
示例9: update
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;
}
示例10:
ProfessorController(Root* root)
{
mProfessorNode = root->getSceneManager("main")->getSceneNode("Professor");
mProfessorEntity = root->getSceneManager("main")->getEntity("Professor");
mWalkSpeed = 80.0f;
mDirection = Vector3::ZERO;
mAnimationState = mProfessorEntity->getAnimationState("Walk");
mAnimationState->setEnabled(true);
mAnimationState->setLoop(true);
}
示例11: stopAnimation
bool CAnimatedEntity::stopAnimation(const std::string &anim)
{
if(!_entity->getAllAnimationStates()->hasAnimationState(anim))
return false;
Ogre::AnimationState *animation = _entity->getAnimationState(anim);
animation->setEnabled(false);
// Si la animación a parar es la animación activa ya no lo estará.
if(animation == _currentAnimation)
_currentAnimation = 0;
return true;
} // stopAnimation
示例12: SetAnimationToEnd
void EC_OgreAnimationController::SetAnimationToEnd(const std::string& name)
{
Ogre::Entity* entity = GetEntity();
Ogre::AnimationState* animstate = GetAnimationState(entity, name);
if (!animstate)
return;
if (animstate)
{
SetAnimationTimePosition(name, animstate->getLength());
}
}
示例13: setAnimation
bool CAnimatedEntity::setAnimation(const std::string &anim, bool loop, int rewind, float fadeTime)
{
if(!_entity->getAllAnimationStates()->hasAnimationState(anim))
return false;
//comprobamos si la animación ya estaba ejecutandose
auto runningAnim = _runningAnimations.find(anim);
if(runningAnim != _runningAnimations.end()) {
if(runningAnim->second.state == FADE_OUT) {
runningAnim->second.state = FADE_IN;
//comprobamos que la animación no estaba justo para
//ser sacada
if(!_deletedAnims.empty()) {
auto delAnim = _deletedAnims.begin();
auto delEnd = _deletedAnims.end();
for(; delAnim!=delEnd; delAnim++) {
if ((*delAnim) == runningAnim->second.animation->getAnimationName()) {
_deletedAnims.erase(delAnim);
runningAnim->second.animation->setEnabled(true);
break;
}
}
}
}
runningAnim->second.direction = rewind;
return true;
}
//cogemos la animacion y la preparamos para ejecutarla
Ogre::AnimationState* animstate = _entity->getAnimationState(anim);
animstate->setEnabled(true);
animstate->setLoop(loop);
animstate->setWeight(0);
//seteamos la animación nueva para que haga fade-in, teniendo
//en cuenta el tiempo de fade que se le ha pasado
Animation animation;
animation.animation = animstate;
animation.state = FADE_IN;
animation.fadeTime = fadeTime;
animation.direction = rewind;
//metemos la animacion en la lista de animaciones ejecutandose
TAnim newAnim (anim,animation);
_runningAnimations.insert(newAnim);
return true;
} // setAnimation
示例14: _behaviorMove
void NPCCharacter::_behaviorMove(const Ogre::Vector3& target)
{
//Check for duplicate move calls and update lua function call with that info
//std::cout << target << std::endl;
if(_destination.squaredDistance(target) >= 5)
{
updateDestination(target,false);
_destination = target;
}
if(destinationReached())
{
_isBhvFinished = true;
}
else
{
_isBhvFinished = false;
}
//point the character in the direction it's traveling
Ogre::Vector3 vel = getVelocity();
float speed = vel.length();
vel.y = 0;
vel.normalise();
if(speed > .2f)
{
Ogre::Vector3 src = _node->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z;
src.y = 0;
//moving sufficiently fast, change to moving animation and point character
Utility::rotateToTarget(_node,vel,true);
//change animation if needed.
if(_animHandler.getSource() != nullptr)
{
Ogre::AnimationState* target = _animHandler.getTarget();
//this relies on the properties of the '&&' construct used by C++(if the first is false,
//then the if-statement is false. It DOESN'T check both fields.
if((target == nullptr && _animHandler.getSource()->getAnimationName() != "Walk") ||
(target != nullptr && target->getAnimationName() != "Walk"))
{
_animHandler.blend("Walk",AnimationBlender::BlendWhileAnimating,.2f,true);
}
}
}
//also have to reset the head, since I'm manually controlling it.
Ogre::Skeleton* skel = static_cast<Ogre::Entity*>(_movableObject)->getSkeleton();
Ogre::Bone* headBone = skel->getBone("Bip01_Head");
//not sure how to do this.
}
示例15: AnimState
CharacterAnimation::CharacterAnimation(Ogre::Entity* ent)
{
Ogre::AnimationStateSet * anims = ent->getAllAnimationStates();
Ogre::AnimationStateIterator it = anims->getAnimationStateIterator();
while(it.hasMoreElements())
{
Ogre::AnimationState * as = it.getNext();
as->setWeight(0);
Animations.insert(std::make_pair(as->getAnimationName(), AnimState(as, 0, 5, 5, 1)));
}
ent->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);
}