예제 #1
0
Transformation<real> SceneImporter<real>::ReadTransformation( std::istream& stream )
{
	Transformation<real> transformation;

	ReadNextExactToken( stream, "Transformation" );
	ReadNextExactToken( stream, "(" );

	if ( TryReadClosingParenthesis( stream ) )
		return transformation;

	Vector3<real> rotation = ReadVector3( stream ); ReadNextExactToken( stream, "," );
	Vector3<real> translation = ReadVector3( stream ); ReadNextExactToken( stream, "," );
	Vector3<real> scale = ReadVector3( stream );
	ReadNextExactToken( stream, ")" );

	transformation.RotateX( rotation.X() );
	transformation.RotateY( rotation.Y() );
	transformation.RotateZ( rotation.Z() );
	transformation.SetTranslation( translation );
	transformation.SetScaleX( scale.X() );
	transformation.SetScaleY( scale.Y() );
	transformation.SetScaleZ( scale.Z() );

	return transformation;
}
예제 #2
0
	void SetTransformation(const Vec3& pos, const Quat& rot)
	{
		if (mOverridingCamera){
			mOverridingCamera->SetTransformation(pos, rot);
			return;
		}
		mTransformation.SetTranslation(pos);
		mTransformation.SetRotation(rot);
		mViewPropertyChanged = true;
	}
예제 #3
0
	void SetPosition(const Vec3& pos)
	{
		if (mOverridingCamera){
			mOverridingCamera->SetPosition(pos);
			return;
		}
		if (mTransformation.GetTranslation() == pos)
			return;
		mTransformation.SetTranslation(pos);
		mViewPropertyChanged = true;
	}
예제 #4
0
파일: sceneloader.cpp 프로젝트: nigulo/cpp
void SceneLoader::LoadTranslation(const XmlParser::XmlElement& rElement, Spatial* pSpatial) {
    Debug(string("Translation: ") + rElement.GetInnerText());
    vector<string> data = Utils::Split(rElement.GetInnerText(), ",");
    float x = stof(data[0]);
    float y = stof(data[1]);
    float z = stof(data[2]);
    Debug(string("Translation x: ") + to_string(x));
    Debug(string("Translation y: ") + to_string(y));
    Debug(string("Translation z: ") + to_string(z));
    Debug(pSpatial->Name());
    Transformation t = pSpatial->GetTransformation();
    t.SetTranslation(Vector(x, y, z));
    pSpatial->SetTransformation(t);
    pSpatial->Transform();
}
예제 #5
0
void TurntableCamera<real>::Update()
{
	Transformation<real> transformation;
	Vector3<real> initRotationAxis = Vector3<real>( 0, 1, 0 ) ^ mThetaAxis;

	if ( initRotationAxis.SquaredLength() > 1e-5 )
		transformation.SetRotationAxis( initRotationAxis.Normalized(), asin( initRotationAxis.Length() ) );

	transformation.RotateAxis( mPhiAxis, mPhi );
	transformation.RotateAxis( mThetaAxis, mTheta );

	Transformation<real> transformationT;
	transformationT.RotateAxis( mPhiAxis, mPhi );
	transformationT.RotateAxis( mThetaAxis, mTheta );
	transformation.SetTranslation( transformationT.GetRotation() * ( mPhiAxis ^ mThetaAxis ).Normalized() * mDistance + mCenter );

	this->SetLocalTransformation( transformation );

	Camera<real>::Update();
}
예제 #6
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;
						}
					}

				}
			}
		}
	}