Ejemplo n.º 1
0
	// ----------------------------------------------------------------------------
	void CInterfaceTrack::update (double currentTime)
	{
		float currentValue;
		UTrack *pTrack = dynamic_cast<UTrack*>(_TrackKeyFramer);
		if (pTrack == NULL) return;
		pTrack->interpolate((TAnimationTime)currentTime, currentValue);

		// Update the targets
		CInterfaceExprValue expr;
		expr.setDouble(currentValue);
		for (uint i = 0; i < _Targets.size(); ++i)
			_Targets[i].affect(expr);
	}
Ejemplo n.º 2
0
//-----------------------------------------------
// updateParticlesNoActor :
//
//-----------------------------------------------
void CSceneParser::updateParticlesNoActor(float difTime, CParticle &particle, UAnimation &animation)
{
	// 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);

		// 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);
			instance->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;
			if(trackRot->interpolate(difTime, rot))
				instance->setRotQuat(rot);
			else
				nlwarning("CSceneParser::updateParticles : Not a Quat!");
		}
	}
}// updateParticlesNoActor //
Ejemplo n.º 3
0
// ------------------------------------------------------------------------------------------------
void CCharacter3D::animate (double globalTime)
{
	if (!_AnimationSet) return;
	_PlayListManager->animate (globalTime);

	animblink (globalTime);

	if (_CurrentSetup.AnimPlayed == -1) return;
	// take correct 3D animId
	uint	animID= _CurrentSetup.AnimPlayed;
	bool	applyRaceScalePos= true;

	if(!_CopyAnim)
	{
		if (_CurrentSetup.Male && animID < _AnimMale.size())
		{
			applyRaceScalePos = _AnimMale[animID].ApplyRaceScalePos;
			// animId is now the correct 3D animId
			animID = _AnimMale[animID].AnimId;
		}
		else if (!_CurrentSetup.Male && animID < _AnimFemale.size())
		{
			applyRaceScalePos = _AnimFemale[animID].ApplyRaceScalePos;
			// animId is now the correct 3D animId
			animID = _AnimFemale[animID].AnimId;
		}
		else
			return;
	}

	// get the animation
	if(animID==UAnimationSet::NotFound)
		return;
	UAnimation *pAnim = _AnimationSet->getAnimation (animID);
	if (pAnim == NULL) return;
	UTrack *pTrack = pAnim->getTrackByName("pos");
	CVector animPos;
	if (pTrack == NULL) return;

	// Compute animation time (wrapped)
	double wrappedTime=(globalTime-_PlayList->getTimeOrigin(0))*_PlayList->getSpeedFactor(0);
	// Mod repeat the time
	{
		float length=pAnim->getEndTime ()-pAnim->getBeginTime();
		if (wrappedTime>=0)
			wrappedTime=pAnim->getBeginTime()+(float)fmod ((float)wrappedTime, length);
		else
			wrappedTime=pAnim->getBeginTime()+(float)fmod ((float)wrappedTime, length)+length;
	}
	pTrack->interpolate((float)wrappedTime, animPos);

	// apply race scale pos only if animation need it
	if(applyRaceScalePos)
		animPos *= getGenderInfo(_CurrentSetup.People, _CurrentSetup.Male)->CharacterScalePos;
	// always apply custom scale pos
	animPos *= _CustomScalePos;
	_PelvisPos = animPos;
	// update skeleton pelvis pos
	if (!_Skeleton.empty())
	{
		_Skeleton.setPos(_PelvisPos);
		// update skeleton spawn script pos
		_Skeleton.setSSSWOPos(_Root.getMatrix().getPos());
		_Skeleton.setSSSWODir(_Root.getMatrix().getJ());
	}
}
Ejemplo n.º 4
0
//-----------------------------------------------
// 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 //
Ejemplo n.º 5
0
//-----------------------------------------------
// updateCamera :
// Update the camera (position, target, roll, fov)
//-----------------------------------------------
void CSceneParser::updateCamera(double timeInSec)
{
	// If there is a play list for the camera.
	if(_PlayList)
	{
		// Get the Id of the animation in the slot 0.
		uint idAnim = _PlayList->getAnimation(0);
		if(idAnim != UPlayList::empty)
		{
			UAnimation *animation = _AnimationSet->getAnimation(idAnim);
			if(animation)
			{
				// Get Camera informations from the animation (Pos, Target, Roll).
				UTrack* trackRollCam	= animation->getTrackByName("Camera.roll");
				UTrack* trackFovCam		= animation->getTrackByName("Camera.fov");
				UTrack* trackPosCam		= animation->getTrackByName("Camera.PathPos");
				UTrack* trackPosTarget	= animation->getTrackByName("Camera.Target.PathPos");
				if(trackPosCam && trackPosTarget)
				{
					float rollCam = 0.f;
					CVector posCam;
					CVector posTarget;
					float difTime = (float)(timeInSec-_TimeStart);

					if(trackRollCam)
						trackRollCam->interpolate(difTime, rollCam);
					trackPosCam->interpolate(difTime, posCam);
					trackPosTarget->interpolate(difTime, posTarget);

					// Update camera transformations.
					UCamera cam = Scene->getCam();
					if(cam)
					{
						cam->setTransformMode(UTransformable::RotQuat);
						cam->lookAt(posCam, posTarget, rollCam);
						if(trackFovCam)
						{
							float fov;
							trackFovCam->interpolate(difTime, fov);
							CFrustum	fr= cam->getFrustum();
							// change only the fov
							cam->setPerspective(fov, fr.getAspectRatio(), fr.Near, fr.Far);
						}
					}

					// Update camera transformations for the Root.
					cam = SceneRoot->getCam();
					if(cam)
					{
						cam->setTransformMode(UTransformable::RotQuat);
						cam->lookAt(posCam, posTarget, rollCam);
						if(trackFovCam)
						{
							float fov;
							trackFovCam->interpolate(difTime, fov);
							CFrustum	fr= cam->getFrustum();
							// change only the fov
							cam->setPerspective(fov, fr.getAspectRatio(), fr.Near, fr.Far);
						}
					}
				}
			}
		}
	}
}// updateCamera //