Example #1
0
	void CAnimation::update()
	{
		const bool isRunning = SceneManager::instance().isRunning();
		if(!isRunning && !mPreviewMode)
		{
			// Make sure attached CBone components match the position of the skeleton bones even when the component is not
			// otherwise running.

			HRenderable animatedRenderable = SO()->getComponent<CRenderable>();
			if(animatedRenderable)
			{
				HMesh mesh = animatedRenderable->getMesh();
				if(mesh.isLoaded())
				{
					const SPtr<Skeleton>& skeleton = mesh->getSkeleton();
					if(skeleton)
					{
						for (auto& entry : mMappingInfos)
						{
							if(!entry.isMappedToBone)
								continue;

							const UINT32 numBones = skeleton->getNumBones();
							for (UINT32 j = 0; j < numBones; j++)
							{
								if (skeleton->getBoneInfo(j).name == entry.bone->getBoneName())
								{
									Matrix4 bindPose = skeleton->getInvBindPose(j).inverseAffine();
									bindPose = SO()->getTransform().getMatrix() * bindPose;

									Vector3 position, scale;
									Quaternion rotation;
									bindPose.decomposition(position, rotation, scale);

									entry.sceneObject->setWorldPosition(position);
									entry.sceneObject->setWorldRotation(rotation);
									entry.sceneObject->setWorldScale(scale);

									break;
								}
							}
						}
					}
				}
			}
		}

		if (mInternal == nullptr || !isRunning)
			return;

		HAnimationClip newPrimaryClip = mInternal->getClip(0);
		if (newPrimaryClip != mPrimaryPlayingClip)
			_refreshClipMappings();

		if (_scriptUpdateFloatProperties)
			_scriptUpdateFloatProperties();
	}
Example #2
0
	//-----------------------------------------------------------------------
	void DualQuaternion::fromTransformationMatrix (const Matrix4& kTrans)
	{
		Vector3 pos;
		Vector3 scale;
		Quaternion rot;

		kTrans.decomposition(pos, scale, rot);
		fromRotationTranslation(rot, pos);
	}
void DualQuaternionTests::testMatrix()
{
	Matrix4 transform;
	Vector3 translation(10, 4, 0);
	Vector3 scale = Vector3::UNIT_SCALE;
	Quaternion rotation;
	rotation.FromAngleAxis(Radian(Math::PI), Vector3::UNIT_Z);
	transform.makeTransform(translation, scale, rotation);

	DualQuaternion dQuat;
	dQuat.fromTransformationMatrix(transform);
	Matrix4 transformResult;
	dQuat.toTransformationMatrix(transformResult);

	Vector3 translationResult;
	Vector3 scaleResult;
	Quaternion rotationResult;
	transformResult.decomposition(translationResult, scaleResult, rotationResult);

	CPPUNIT_ASSERT(translationResult.positionEquals(translation));
	CPPUNIT_ASSERT(scaleResult.positionEquals(scale));
	CPPUNIT_ASSERT(rotationResult.equals(rotation, Radian(0.001)));
}