Esempio n. 1
0
bool NzMD5AnimParser::ParseFrame()
{
	unsigned int animatedComponentsCount = m_animatedComponents.size();
	if (animatedComponentsCount == 0)
	{
		Error("Animated components count is missing or invalid");
		return false;
	}

	unsigned int jointCount = m_joints.size();
	if (jointCount == 0)
	{
		Error("Joint count is invalid or missing");
		return false;
	}

	NzString line;

	unsigned int count = 0;
	do
	{
		if (!Advance())
			return false;

		unsigned int index = 0;
		unsigned int size = m_currentLine.GetSize();
		do
		{
			float f;
			int read;
			if (std::sscanf(&m_currentLine[index], "%f%n", &f, &read) != 1)
			{
				UnrecognizedLine(true);
				return false;
			}

			index += read;

			m_animatedComponents[count] = f;

			count++;
		}
		while (index < size);
	}
	while (count < animatedComponentsCount);

	m_frames[m_frameIndex].joints.resize(jointCount);

	for (unsigned int i = 0; i < jointCount; ++i)
	{
		NzQuaternionf jointOrient = m_joints[i].bindOrient;
		NzVector3f jointPos = m_joints[i].bindPos;
		unsigned int j = 0;

		if (m_joints[i].flags & 1) // Px
			jointPos.x = m_animatedComponents[m_joints[i].index + j++];

		if (m_joints[i].flags & 2) // Py
			jointPos.y = m_animatedComponents[m_joints[i].index + j++];

		if (m_joints[i].flags & 4) // Pz
			jointPos.z = m_animatedComponents[m_joints[i].index + j++];

		if (m_joints[i].flags & 8) // Qx
			jointOrient.x = m_animatedComponents[m_joints[i].index + j++];

		if (m_joints[i].flags & 16) // Qy
			jointOrient.y = m_animatedComponents[m_joints[i].index + j++];

		if (m_joints[i].flags & 32) // Qz
			jointOrient.z = m_animatedComponents[m_joints[i].index + j++];

		jointOrient.ComputeW();

		m_frames[m_frameIndex].joints[i].orient = jointOrient;
		m_frames[m_frameIndex].joints[i].pos = jointPos;
	}

	if (!Advance(false))
		return true;

	if (m_currentLine != '}')
	{
		#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
		Warning("Hierarchy braces closing not found");
		#endif

		// On tente de survivre à l'erreur
		m_keepLastLine = true;
	}

	return true;
}
Esempio n. 2
0
#include <Nazara/Math/Quaternion.hpp>
#include <catch.hpp>

SCENARIO("Quaternion", "[MATH][QUATERNION]")
{
	GIVEN("Two quaternions (0, 1, 0, 0)")
	{
		NzQuaternionf firstQuaternion(NzFromDegrees(180.f), NzVector3f::UnitX());
		NzQuaternionf secondQuaternion(0.f, 1.f, 0.f, 0.f);

		WHEN("We compare them")
		{
			THEN("They are the same and the proprieties of quaternions are respected")
			{
				REQUIRE(firstQuaternion == secondQuaternion);
				REQUIRE(firstQuaternion.ComputeW() == secondQuaternion.Normalize());
				REQUIRE(firstQuaternion.Conjugate() == secondQuaternion.Inverse());
				REQUIRE(firstQuaternion.DotProduct(secondQuaternion) == Approx(1.f));
			}
		}

		WHEN("We do some operations")
		{
			THEN("Multiply with a vectorX is identity")
			{
				REQUIRE((firstQuaternion * NzVector3f::UnitX()) == NzVector3f::UnitX());
			}

			AND_THEN("Multiply with a vectorY or Z is opposite")
			{
				REQUIRE((firstQuaternion * NzVector3f::UnitY()) == -NzVector3f::UnitY());