//----------------------------------------------- // updateActors : // Update Actors. //----------------------------------------------- void CSceneParser::updateActors() { // All actors in the scene. for(map<uint, CActor>::iterator itActor = _Actors.begin(); itActor != _Actors.end(); ++itActor) { // Get a reference on the actor. CActor &actor = (*itActor).second; // If there is no actor to follow -> next actor. if(actor.Actor < 0) continue; // Get the entity pointer. CEntityCL *entity = getEntity(Sid(Sid::npc, (uint64)actor.Id)); if(!entity) { nlwarning("CSceneParser::updateActors : Cannot get the actor %d.", actor.Id); continue; } // Get the target entity pointer. CEntityCL *entityTarget = getEntity(Sid(Sid::npc, (uint64)actor.Actor)); if(!entityTarget) { nlwarning("CSceneParser::updateActors : Cannot get the targeted actor %d.", actor.Actor); continue; } // Changes the entity position. entity->pacsPos(entityTarget->pos()); } }// updateActors //
//----------------------------------------------- // resetActors : // Reset all actors. //----------------------------------------------- void CSceneParser::resetActors() { // Create new entities from actors map<uint, CActor>::iterator itActor; for(itActor = _Actors.begin(); itActor != _Actors.end(); ++itActor) { // Get a reference on the actor. CActor &actor = (*itActor).second; // Get the Sid. Sid entityId(Sid::npc, (uint64)actor.Id); // Find the actor. CEntityCL *entity = getEntity(entityId); if(entity) { // Position the entity. entity->pacsPos(actor.Pos); // Position the skeleton at the same position as the entity. if(entity->skeleton()) { entity->skeleton()->setPos(actor.Pos); entity->skeleton()->setRotQuat(actor.Rot); } } // Reset entity animations. resetAnimatedSceneObject(entityId); } }// resetActors //
// Constructor for moving object, it not create entity (mesh, skeleton) but build animation on pre-exist entity CAnimatedSceneObject::CAnimatedSceneObject( const CEntityId& Id, const list < std::string >& Animations ) { _Id = Id; _ObjectName = ""; _ClusterIG = ""; _MeshName = ""; _SkeletonName = ""; _Distance = 0; _Skeleton = NULL; _Instance = NULL; CEntityCL *entity = getEntity(Id); if(entity) { _Skeleton = *entity->skeleton(); _Transform = _Skeleton; _Position = _Skeleton->getPos(); _Rotation = _Skeleton->getRotQuat(); // create play list manager and animation set _PlayListManager = Scene->createPlayListManager(); _AnimationSet = Driver->createAnimationSet(); //fill animation set for( list< string >::const_iterator its = Animations.begin(); its != Animations.end(); ++its ) { uint idAnim; try { idAnim = _AnimationSet->addAnimation( ( *its + string(".anim") ).c_str(), (*its).c_str() ); } catch(Exception &) { idAnim = UAnimationSet::NotFound; if( idAnim == UAnimationSet::NotFound) { nlwarning( "CAnimatedSceneObject::CAnimatedSceneObject Animation %s not found for entity CEntityId(%u,%f)", (*its).c_str(), Id.Type, (double)(sint64)Id.Id ); continue; } } _MapAnimation.insert( make_pair( *its, idAnim ) ); } // build animation set _AnimationSet->build(); // create playlist _PlayList = _PlayListManager->createPlayList( _AnimationSet ); _Status = SAnimationStatus(); _Status.SequenceAnim = 1; _Status.ApplyDisplacement = 1; // register skeleton in playlist _PlayList->registerTransform( *entity->skeleton() ); // Snap to ground(the snap check if it's a flyer). entity->pacsPos(_Position); entity->snapToGround(); _Position = entity->pos(); CMatrix current; current.identity (); current.setRot (_Rotation); // Rotation 90 degrees CMatrix rot90; rot90.identity (); rot90.rotateZ (-(float)Pi/2); current *= rot90; _Transform->unfreezeHRC(); _Transform->setPos(_Position); _Transform->setRotQuat(current.getRot()); _Transform->freezeHRC(); _IdAnimationPlayed = -1; if( _Id.Type == RYZOMID::npc ) { sendEndSequenceMessage( _Id, 1 ); } } else { _PlayList = NULL; _AnimationSet = NULL; _PlayListManager = NULL; } }