Ejemplo n.º 1
0
void Game_Update()
{
	if(!bShowModel)
	{
		if(MFInput_WasPressed(Key_Up, IDD_Keyboard) && menuIndex > 0)
			--menuIndex;
		else if(MFInput_WasPressed(Key_Down, IDD_Keyboard) && menuIndex < (int)models.size()-1)
			++menuIndex;
		else if(MFInput_WasPressed(Key_Return, IDD_Keyboard) && models.size() > 0)
		{
			bShowModel = true;

			// load model
			pModel = MFModel_CreateWithAnimation(models[menuIndex].CStr());
		}
	}
	else
	{
		if(MFInput_WasPressed(Key_Escape, IDD_Keyboard))
		{
			if(pModel)
			{
				MFModel_Destroy(pModel);
				pModel = NULL;
			}

			models.clear();
			Scan("data:");

			if(models.size() <= (size_t)menuIndex)
				menuIndex = models.size() ? (int)models.size() - 1 : 0;
			bShowModel = false;
			return;
		}

		if(pModel)
		{
			if(MFInput_Read(Mouse_LeftButton, IDD_Mouse) > 0.f)
			{
				yaw += -MFInput_Read(Mouse_XDelta, IDD_Mouse) * 0.02f;
				pitch += -MFInput_Read(Mouse_YDelta, IDD_Mouse) * 0.015f;
			}
			if(MFInput_Read(Mouse_MiddleButton, IDD_Mouse) > 0.f)
			{
				zoom *= 1.f + -MFInput_Read(Mouse_YDelta, IDD_Mouse) * 0.02f;
			}

			// calculate a spinning world matrix
			MFMatrix world;
			world.SetTranslation(MakeVector(0, -0.25f, 1) * zoom);
			world.RotateY(yaw);
			world.RotateX(pitch);

			// set world matrix to the model
			MFModel_SetWorldMatrix(pModel, world);

			// advance the animation
			MFAnimation *pAnim = MFModel_GetAnimation(pModel);
			if(pAnim)
			{
				float start, end;
				MFAnimation_GetFrameRange(pAnim, &start, &end);
	
				static float time = 0.f;
				time += MFSystem_TimeDelta();// * 500;
				while(time >= end)
					time -= end;
				MFAnimation_SetFrame(pAnim, time);
			}
		}
	}
}
Ejemplo n.º 2
0
void LoadTextXFile(const char *pText)
{
	const char *pTok = GetNextToken(pText, &pText);

	while(pTok)
	{
		if(!MFString_Compare(pTok, "Header"))
		{
			SkipToken(pText, "{");

			int maj = GetInt(pText, &pText);
			int min = GetInt(pText, &pText);
			int flag = GetInt(pText, &pText);

//			printf("XFile V%d.%d, 0x%X\n", maj, min, flag);

			pTok = GetNextToken(pText, &pText);
			while(MFString_Compare(pTok, "}"))
			{
				pTok = GetNextToken(pText, &pText);
			}
		}
		else if(!MFString_Compare(pTok, "Frame"))
		{
			pText = ParseFrame(pText, MFMatrix::identity, -1);
		}
		else if(!MFString_Compare(pTok, "Mesh"))
		{
			gMeshChunks.push(XMeshChunk::Create(MFMatrix::identity, pText, ""));
			SkipSection(pText);
		}
		else if(!MFString_Compare(pTok, "AnimationSet"))
		{
			gAnimSets.push(pText);
			SkipSection(pText);
		}
		else if(!MFString_Compare(pTok, "template"))
		{
//			const char *pName = GetNextToken(pText, &pText);
			SkipSection(pText);
		}
		else
		{
			MFDebug_Warn(4, MFStr("Unknown token '%s'\n", pTok));
			SkipSection(pText);
		}

		pTok = GetNextToken(pText, &pText);
	}

	int a;
	for(a=0; a<gMeshChunks.size(); a++)
	{
		ParseMesh(gMeshChunks[a].pMesh, gMeshChunks[a].mat, gMeshChunks[a].frameName);
	}

	for(a=0; a<gAnimSets.size(); a++)
	{
		ParseAnimationSet(gAnimSets[a]);
	}

	gMeshChunks.clear();
}