Ejemplo n.º 1
0
bool Model::ParseLine(const std::vector<ci_string> &token)
{
		if (token.empty() == false)
	{
		if (token[0].empty() == false && token[0][0] == '#')
		{
			return true;
		}
		else if (token[0] == "name")
		{
			assert(token.size() > 2);
			assert(token[1] == "=");

			mName = token[2];	
		}
		else if (token[0] == "position")
		{
			assert(token.size() > 4);
			assert(token[1] == "=");

			mPosition.x = static_cast<float>(atof(token[2].c_str()));
			mPosition.y = static_cast<float>(atof(token[3].c_str()));
			mPosition.z = static_cast<float>(atof(token[4].c_str()));
		}
		else if (token[0] == "rotation")
		{
			assert(token.size() > 4);
			assert(token[1] == "=");

			mRotationAxis.x = static_cast<float>(atof(token[2].c_str()));
			mRotationAxis.y = static_cast<float>(atof(token[3].c_str()));
			mRotationAxis.z = static_cast<float>(atof(token[4].c_str()));
			mRotationAngleInDegrees = static_cast<float>(atof(token[5].c_str()));

			glm::normalize(mRotationAxis);
		}
		else if (token[0] == "scaling")
		{
			assert(token.size() > 4);
			assert(token[1] == "=");

			mScaling.x = static_cast<float>(atof(token[2].c_str()));
			mScaling.y = static_cast<float>(atof(token[3].c_str()));
			mScaling.z = static_cast<float>(atof(token[4].c_str()));
		}
		else if (token[0] == "animation")
		{
			assert(token.size() > 2);
			assert(token[1] == "=");

			ci_string animName = token[2];
            
            mAnimation = World::GetInstance()->FindAnimation(animName);
			mAnimation->setCurrentModel(this);
		}
		else if (token[0] == "direction"){
			assert(token.size() > 4);
			assert(token[1] == "=");

			mStretchVec.x = static_cast<float>(atof(token[2].c_str()));
			mStretchVec.y = static_cast<float>(atof(token[3].c_str()));
			mStretchVec.z = static_cast<float>(atof(token[4].c_str()));
			normalize(mStretchVec);
		}
		else if (token[0] == "range"){
			assert(token.size() > 4);
			assert(token[1] == "=");
			assert(token[3] == "/");

			rangeNumerator = static_cast<int>(atof(token[2].c_str()));
			rangeDenominator = static_cast<int>(atof(token[4].c_str()));
		}
		else if (token[0] == "particlesystem")
		{
			assert(token.size() > 2);
			assert(token[1] == "=");
			assert(token[2] == "\"fire\"" || token[2] == "\"fountain\"" || "\"stars\""); // only to hardcoded particle systems


			ParticleEmitter* emitter = new ParticleEmitter(vec3(0.0f, 0.0f, 0.0f), this);
			ParticleDescriptor* desc = new ParticleDescriptor();

			if (token[2] == "\"fire\"")
			{
				desc->SetFireDescriptor();
			}
			else if (token[2] == "\"fountain\"")
			{
				desc->SetFountainDescriptor();
			}
			else if (token[2] == "\"stars\"")
			{
				desc->SetStarsDescriptor();
			}

			mParticleSystem = new ParticleSystem(emitter, desc);
			World::GetInstance()->AddParticleSystem(mParticleSystem);
		}
		else
		{
			return false;
		}
	}

	return true;
}