//----------------------------------------------- // 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; } }
//----------------------------------------------- // updateParticlesActor : // //----------------------------------------------- void CSceneParser::updateParticlesActor(float difTime, CParticle &particle, UAnimation &animation) { // Get the entity pointer. CEntityCL *entity = getEntity(Sid(Sid::npc, (uint64)particle.Actor)); if(!entity) { nlwarning("CSceneParser::updateParticlesActor : cannot get the actor %d.", (uint64)particle.Actor); return; } // If the entity has no skeleton -> Next particle. if(!entity->skeleton()) { nlwarning("The particle follow an entity %d without a skeleton.", (uint64)particle.Actor); return; } // Matrix 90° CMatrix m90; m90.identity(); m90.rotateZ((float)(Pi/2.0)); // Matrix of the entity. CMatrix mChar = entity->skeleton()->getMatrix(); mChar.setPos(entity->pos()); // Animate all instances. for(uint i = 0; i < particle.IGPtr->getNumInstance(); ++i ) { std::string iName = particle.IGPtr->getInstanceName(i); UInstance instance = particle.IGPtr->getByName(iName); if(!instance) continue; instance->setTransformMode(UTransformable::RotQuat); CMatrix mAnim; mAnim.identity(); // If the animation has no track of position. UTrack* trackPos = animation.getTrackByName("PathPos"); if(!trackPos) trackPos = animation.getTrackByName(string(iName + "." + "PathPos").c_str()); if(trackPos) { CVector pos; trackPos->interpolate(difTime, pos); mAnim.setPos(pos); } // If the animation has no track of rotation. UTrack* trackRot = animation.getTrackByName("PathRotQuat"); if(!trackRot) trackRot = animation.getTrackByName(string(iName + "." + "PathRotQuat").c_str()); if(trackRot) { CQuat rot; trackPos->interpolate(difTime, rot); mAnim.setRot(rot); } CMatrix mFinal = mChar * m90 * mAnim; instance->setPos(mFinal.getPos()); instance->setRotQuat(mFinal.getRot()); } }// updateParticlesActor //