⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 map.cpp

📁 3D赛车游戏源代码-用Visual Studio 2005
💻 CPP
字号:
#include "StdAfx.h"
#include "Map.h"
#include "MathUtil.h"
#include "../res/ModelLoadManager.h"
#include "SceneManager.h"
#include "../model/Model.h"

CMap::CMap()
{
	m_iWidth = 0;
	m_iHeight = 0;
}

bool CMap::LoadFromFile(const char *filename)
{
	ifstream inf(filename);
	
	if (!inf)
	{
		return false;
	}

	inf >> m_iWidth >> m_iHeight;

	char buf[64];
	int iCount = 0;
	inf >> iCount;
	Vector3 position;
	float xrot, yrot, zrot;
	CMatrix44F mat;
	m_SceneElems.resize(iCount);

	for (int i=0; i<iCount; ++i)
	{
		CStaticActor &actor = m_SceneElems[i];
		inf >> buf >> position.x >> position.y >> position.z >> xrot >> yrot >> zrot;
		actor.LoadModel(buf);
		mat.SetupTranslation(position);
		
		float rad = 0.0f;

		if (xrot != 0.0f)
		{
			rad = degToRad(xrot);
			mat.Rotate(1, rad);
		}

		if (yrot != 0.0f)
		{
			rad = degToRad(yrot);
			mat.Rotate(2, rad);
		}

		if (zrot != 0.0f)
		{
			rad = degToRad(zrot);
			mat.Rotate(3, rad);
		}

		if (i == 0)
		{
			g_SceneManager.AddObjectToQuadTree(&actor, (float)m_iWidth, (float)m_iHeight);
		}
		else
		{
			actor.SetTransform(mat);
			actor.AddToScene();
		}
		
	}

	return false;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -