예제 #1
0
	void SetRotation(const Quat& rot)
	{
		if (mOverridingCamera){
			mOverridingCamera->SetRotation(rot);
			return;
		}
		mTransformation.SetRotation(rot);
		mViewPropertyChanged = true;
	}
예제 #2
0
파일: sceneloader.cpp 프로젝트: nigulo/cpp
void SceneLoader::LoadRotation(const XmlParser::XmlElement& rElement, Spatial* pSpatial) {
    Debug(string("Rotation: ") + rElement.GetInnerText());
    vector<string> data = Utils::Split(rElement.GetInnerText(), ",");
    float x = stof(data[0]);
    float y = stof(data[1]);
    float z = stof(data[2]);
    float a = stof(data[3]);
    Debug(string("RotVector x: ") + to_string(x));
    Debug(string("RotVector y: ") + to_string(y));
    Debug(string("RotVector z: ") + to_string(z));
    Debug(string("RotVector a: ") + to_string(a));
    Debug(pSpatial->Name());
    Transformation t = pSpatial->GetTransformation();
    t.SetRotation(Vector(x, y, z), a * M_PI / 180);
    pSpatial->SetTransformation(t);
    pSpatial->Transform();
}
예제 #3
0
	void Update(TIME_PRECISION dt){
		if (mCurPlayingAction)
		{
			if (mLastUpdatedFrame == gpTimer->GetFrame())
				return;

			mChanged = false;

			if (mPrevPlayingTime == mPlayingTime)
				return;

			TIME_PRECISION curTime = mPlayingTime;
			if (mReverse)
				mPlayingTime -= dt;
			else
				mPlayingTime += dt;

			mLastUpdatedFrame = gpTimer->GetFrame();
			// evaluate
			TIME_PRECISION normTime = curTime / mCurPlayingAction->mLength;
			bool cycled = mCycled;
			mCycled = false;
			if (mAnimationData->HasPosAnimation())
			{
				const Vec3 *p1 = 0, *p2 = 0;
				TIME_PRECISION interpol = 0;
				mAnimationData->PickPos(curTime, cycled, &p1, &p2, interpol);
				if (p1 && p2)
				{
					Vec3 pos = Lerp<Vec3>(*p1, *p2, interpol);
					mResult.SetTranslation(pos);
				}
			}

			if (mAnimationData->HasRotAnimation())
			{
				const Quat *r1 = 0, *r2 = 0;
				TIME_PRECISION interpol = 0;
				mAnimationData->PickRot(curTime, cycled, &r1, &r2, interpol);
				if (r1 && r2)
				{
					Quat rot = Slerp(*r1, *r2, interpol);
					mResult.SetRotation(rot);
				}
			}

			mPrevPlayingTime = curTime;
			mChanged = true;

			if ((!mReverse && mPlayingTime > mCurPlayingAction->mLength) ||
				(mReverse && mPlayingTime < 0))
			{
				if (mNextAction)
				{
					mCurPlayingAction = mNextAction;
					mReverse = mNextReverse;
					mNextAction = 0;
					if (mReverse)
					{
						mPlayingTime = mCurPlayingAction->mLength;
						mPrevPlayingTime = 0;
					}
					else
					{
						mPlayingTime = 0.f;
						mPrevPlayingTime = mCurPlayingAction->mLength;
					}
				}
				else
				{
					if (mReverse)
					{
						if (mCurPlayingAction->mLoop)
						{
							// mPlayingTime is negative
							mPlayingTime = mCurPlayingAction->mLength + mPlayingTime;
							mCycled = true;
						}
						else
						{
							mPlayingTime = 0.0f;
						}
					}
					else
					{
						if (mCurPlayingAction->mLoop)
						{
							mPlayingTime = mPlayingTime - mCurPlayingAction->mLength;
							mCycled = true;
						}
						else
						{
							mPlayingTime = mCurPlayingAction->mLength;
						}
					}

				}
			}
		}
	}