BasicModel::BasicModel(ID3D11Device* device, TextureMgr& texMgr,
	const std::string& modelFilename,
	const std::wstring& texturePath,
	MeshGeometry::Type type)
	:
	ModelMesh(type)
{
	std::vector<M3dMaterial> mats;
	//M3DLoader m3dLoader;
	//m3dLoader.LoadM3d(modelFilename, Vertices, Indices, Subsets, mats);
	//test code
	OBJLoader objLoader;
	objLoader.LoadOBJ(device, modelFilename, BasicVertices,	Indices, Subsets, mats, true, true);
	ModelMesh.SetVertices(device, &BasicVertices[0], BasicVertices.size());
	ModelMesh.SetIndices(device, &Indices[0], Indices.size());
	ModelMesh.SetSubsetTable(Subsets);

	SubsetCount = mats.size();

	for (UINT i = 0; i < SubsetCount; ++i)
	{
		Material newMat;
		Mat.push_back(mats[i].Mat);

		ID3D11ShaderResourceView* diffuseMapSRV =
			texMgr.CreateTexture(texturePath + mats[i].DiffuseMapName);
		DiffuseMapSRV.push_back(diffuseMapSRV);

		//ID3D11ShaderResourceView* normalMapSRV = texMgr.CreateTexture(texturePath + mats[i].NormalMapName);
		//NormalMapSRV.push_back(normalMapSRV);
	}
}
Exemple #2
0
void test() {
	LruMgr* lmgr = new LruMgr();
	TextureMgr* tmgr = new TextureMgr();
	tmgr->SetFilter(std::bind(&LruMgr::CaculFunc, lmgr, std::placeholders::_1, std::placeholders::_2));
	lmgr->SetRmCb(std::bind(&TextureMgr::Remove, tmgr, std::placeholders::_1));

	tmgr->AddObj("aaa");
	tmgr->AddObj("bbb");
	tmgr->AddObj("ccc");
	tmgr->AddObj("ddd");
	tmgr->AddObj("eee");
	tmgr->AddObj("fff");
	tmgr->AddObj("bbb");
	tmgr->AddObj("ddd");
	tmgr->AddObj("bbb");

	lmgr->Snapshot();
	delete lmgr;
	lmgr = nullptr;
}
bool DuckHuntMain::Init()
{
	if (!D3DApp::Init())
		return false;

	// Must init Effects first since InputLayouts depend on shader signatures.
	Effects::InitAll(md3dDevice);
	InputLayouts::InitAll(md3dDevice);
	RenderStates::InitAll(md3dDevice);
	mCrosshair = new Crosshair(md3dDevice);
	mTexMgr.Init(md3dDevice);
	DuckHuntMain::ShowCursors(false);
	mSky = new Sky(md3dDevice, L"Textures/desertcube1024.dds", 5000.0f);
	mSmap = new ShadowMap(md3dDevice, SMapSize, SMapSize);
	Terrain::InitInfo tii;
	tii.HeightMapFilename = L"Textures/myT5.raw";
	tii.LayerMapFilename0 = L"Textures/grass.dds";
	tii.LayerMapFilename1 = L"Textures/darkdirt.dds";
	tii.LayerMapFilename2 = L"Textures/stone.dds";
	tii.LayerMapFilename3 = L"Textures/lightdirt.dds";
	tii.LayerMapFilename4 = L"Textures/snow.dds";
	tii.BlendMapFilename = L"Textures/blend.dds";
	tii.HeightScale = 50.0f;
	tii.HeightmapWidth = 2049;
	tii.HeightmapHeight = 2049;
	tii.CellSpacing = 0.5f;

	mTerrain.Init(md3dDevice, md3dImmediateContext, tii);
	//Sound
	result = FMOD::System_Create(&mSystem);
	result = mSystem->init(32, FMOD_INIT_NORMAL, 0);
	result = mSystem->createSound("Sounds/GunFire.wav", FMOD_DEFAULT, 0, &mGunFire);
	result = mGunFire->setMode(FMOD_LOOP_OFF);






	mCam.SetLens(0.25f*MathHelper::Pi, AspectRatio(), 1.0f, 1000.0f);
	mSsao = new Ssao(md3dDevice, md3dImmediateContext, mClientWidth, mClientHeight, mCam.GetFovY(), mCam.GetFarZ());

	BuildScreenQuadGeometryBuffers();

	testModelDuck = new BasicModel(md3dDevice, mTexMgr, "Models\\duck.obj", L"Textures\\DUCK.jpg");



	BasicModelInstance testInstanceDuck;
	BasicModelInstance testInstanceDuck2;
	BasicModelInstance testInstanceDuck3;
	BasicModelInstance testInstanceDuck4;

	testInstanceDuck.Model = testModelDuck;
	testInstanceDuck2.Model = testModelDuck;
	testInstanceDuck3.Model = testModelDuck;
	testInstanceDuck4.Model = testModelDuck;



	//Duck 1
	XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, -1.0f);
	XMMATRIX modelRot = XMMatrixRotationY(0.0f);
	XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f);
	//Duck 2
	XMMATRIX modelScale2 = XMMatrixScaling(2.0f, 2.0f, -1.0f);
	XMMATRIX modelRot2 = XMMatrixRotationY(-1.0f);
	XMMATRIX modelOffset2 = XMMatrixTranslation(1.0f, 1.0f, -1.0f);
	//Duck3
	XMMATRIX modelScale3 = XMMatrixScaling(1.5f, 1.5f, 1.5f);
	XMMATRIX modelRot3 = XMMatrixRotationY(0.5f);
	XMMATRIX modelOffset3 = XMMatrixTranslation(2.0f, 1.0f, -1.0f);
	//Duck4
	XMMATRIX modelScale4 = XMMatrixScaling(0.5f, 0.5f, -1.0f);
	XMMATRIX modelRot4 = XMMatrixRotationY(1.0f);
	XMMATRIX modelOffset4 = XMMatrixTranslation(0.5f, 1.0f, -1.0f);


	//Duck 1
	XMStoreFloat4x4(&testInstanceDuck.World, modelScale*modelRot*modelOffset);
	mModelInstances.push_back(testInstanceDuck);

	//Duck 2
	XMStoreFloat4x4(&testInstanceDuck2.World, modelScale2*modelRot2*modelOffset2);
	mModelInstances.push_back(testInstanceDuck2);

	//Duck 3
	XMStoreFloat4x4(&testInstanceDuck3.World, modelScale3*modelRot3*modelOffset3);
	mModelInstances.push_back(testInstanceDuck3);

	//Duck 4
	XMStoreFloat4x4(&testInstanceDuck4.World, modelScale4*modelRot4*modelOffset4);
	mModelInstances.push_back(testInstanceDuck4);


	//create collision box
	for (unsigned i = 0; i < mModelInstances.size(); i++)
	{
		mModelInstances[i].Model->CreateCollisionBox(mModelInstances[i].Model->BasicVertices);
	}






	//
	// Compute scene bounding box.
	//

	XMFLOAT3 minPt(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity);
	XMFLOAT3 maxPt(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity);
	for (UINT i = 0; i < mModelInstances.size(); ++i)
	{
		for (UINT j = 0; j < mModelInstances[i].Model->BasicVertices.size(); ++j)
		{
			XMFLOAT3 P = mModelInstances[i].Model->BasicVertices[j].Pos;

			minPt.x = MathHelper::Min(minPt.x, P.x);
			minPt.y = MathHelper::Min(minPt.x, P.x);
			minPt.z = MathHelper::Min(minPt.x, P.x);

			maxPt.x = MathHelper::Max(maxPt.x, P.x);
			maxPt.y = MathHelper::Max(maxPt.x, P.x);
			maxPt.z = MathHelper::Max(maxPt.x, P.x);
		}
	}

	//
	// Derive scene bounding sphere from bounding box.
	//
	mSceneBounds.Center = XMFLOAT3(
		0.5f*(minPt.x + maxPt.x),
		0.5f*(minPt.y + maxPt.y),
		0.5f*(minPt.z + maxPt.z));

	XMFLOAT3 extent(
		0.5f*(maxPt.x - minPt.x),
		0.5f*(maxPt.y - minPt.y),
		0.5f*(maxPt.z - minPt.z));

	mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z);

	return true;
}
Exemple #4
0
void Game::loadResources() {
	Log::Out << "Game: Loading resources..." << endl;
	istream* resourcesFile = Pack::GetInstance()->GetStream("resources.json");

	if (!resourcesFile->good()) {
		Log::Out << "Couldn't load file resources.json" << endl;
		return;
	}

	Json::Value root;
	(*resourcesFile) >> root;
	delete resourcesFile;

	Log::Out << "Game: Initializing Scanlines..." << endl;
	Json::Value shaders = root["outputShaders"];
	if (Json::Value::null != shaders) {
		ShaderMgr* shaderMgr = ShaderMgr::GetInstance();
		for (Json::Value::iterator itShaderDesc = shaders.begin(); itShaderDesc != shaders.end(); ++itShaderDesc) {
			vector<Shader*> shaderPtrs;
			Json::Value child = *itShaderDesc;
			string name = child["name"].asString();
			Json::Value pathArray = child["shaderPaths"];
			for (Json::Value::iterator itShaderPath = pathArray.begin(); itShaderPath != pathArray.end(); ++itShaderPath) {
				string shaderFile = itShaderPath->asString();
				ShaderType shaderType = shaderFile.find(".vertex") == string::npos ? Fragment : Vertex;
				stringstream ss;
				ss << "Loading " << ((shaderType == Vertex) ? "vertex" : "fragment") << " shader: " << shaderFile;
				drawStatusMsg(ss.str());
				shaderPtrs.push_back(shaderMgr->LoadShader(shaderFile, shaderType));
			}
			Program* p = new Program(shaderPtrs);
			if (p->ProgramId != 0) {
				p->Textures.push_back(_g->GetFramebufferTexture());
			}
			Json::Value texArray = child["additionalTextures"];
			for (Json::Value::iterator itTexturePath = texArray.begin(); itTexturePath != texArray.end(); ++itTexturePath) {
				string texPath = itTexturePath->asString();
				p->Textures.push_back(Frame(texPath).Texture);
			}
			this->_blitProgramMap[name] = p;
			if (child.isMember("default") && child["default"].asBool()) {
				this->_blitProgram = p;
			}
		}
		if (this->_blitProgram == NULL && this->_blitProgramMap.size() > 0) {
			this->_blitProgram = (this->_blitProgramMap.end())->second;
		}
	}

	Json::Value images = root["images"];
	if (Json::Value::null != images) {
		TextureMgr* texMgr = TextureMgr::GetInstance();
		for (Json::Value::iterator img = images.begin(); img != images.end(); ++img) {
			string file = img->asString();
			stringstream ss;
			ss << "Loading image: " << file;
			drawStatusMsg(ss.str());
			texMgr->LoadTexture(file);
		}
	}
	Json::Value music = root["music"];
	if (Json::Value::null != music) {
		MusicManager* musicMgr = MusicManager::GetInstance();
		for (Json::Value::iterator mus = music.begin(); mus != music.end(); ++mus) {
			string file = mus->asString();
			stringstream ss;
			ss << "Loading song " << file;
			drawStatusMsg(ss.str());
			musicMgr->LoadMusic(mus->asString());
		}
	}
	Json::Value effects = root["fx"];
	if (Json::Value::null != effects) {
		MusicManager* musicMgr = MusicManager::GetInstance();
		for (Json::Value::iterator fx = effects.begin(); fx != effects.end(); ++fx) {
			stringstream ss;
			string file = fx->asString();
			ss << "Loading effect " << file;
			drawStatusMsg(ss.str());
			musicMgr->LoadMusic(fx->asString());
		}
	}
	drawStatusMsg("Done!");
}
bool Game::Init(HINSTANCE hInstance)
{
	if (!D3DApp::Init())
		return false;

	// Must init Effects first since InputLayouts depend on shader signatures.
	Effects::InitAll(md3dDevice);
	InputLayouts::InitAll(md3dDevice);

	mTexMgr.Init(md3dDevice);

	mSky = new Sky(md3dDevice, L"Textures//sunsetcube1024.dds", 5000.0f);

	/// create the player
	PlayerOne = new Player(md3dDevice, mTexMgr, "Models\\gawky.obj", L"Textures\\", 0.0f, 10.0f, 0.0f);
	ModelLoader* modelLoader = new ModelLoader();
	if( !PlayerOne->init( md3dDevice, modelLoader, mTexMgr, L"Textures\\" ) ) {
		wchar_t msgbuf[256];
		wsprintf( msgbuf, L"\nPlayer Init Failed!!!\n\n");
		OutputDebugString( msgbuf );
		return false;
	}

	//// load  the level models
	theEnemies = new Enemies(md3dDevice, mTexMgr);
	Objects = new TheObjects(md3dDevice, mTexMgr);
	Level1 = new LevelBuilder(md3dDevice, mTexMgr);

	Objects->createObject(branch, 60.0f, 0.25f, 55.0f, ctStumble, 1);
	Objects->createObject(branch, 0.0f, 0.25f, 20.0f, ctStumble, 1);

	Objects->createObject(orange, 80.0f, 30.0f, 20.0f, ctCollect, 1);
	Objects->createObject(orange, 20.0f, 4.0f, 20.0f, ctCollect, 1);
	Objects->createObject(orange, -80.0f, 10.0f, -60.0f, ctCollect, 1);

	//Objects->createObject(gatetwo, -95.0f, 8.5f, 0.0f, ctStumble, 7);

	theEnemies->createEnemy(simpleEnemy, -85.0f, 9.0f, 78.0f, -65.f, 9.0f, 78.0f, NULL, 0, 0, 0, 0, 0, 3, 15, ctEnemy);
	theEnemies->createEnemy(simpleEnemy, 55.0f, 3.0f, 80.0f, 55.0f, 3.0f, 60.0f, NULL, 0, 0, 0, 0, 0, 3, 15, ctEnemy);
	theEnemies->createEnemy(simpleEnemy, 0.0f, 3.0f, 45.0f, 0.0f, 3.0f, 25.0f, NULL, 0, 0, 0, 0, 0, 3, 15, ctEnemy);

	Level1->createLevelParts(Ground, 0, -1.8, 0, 0, 7, 0);

	///left side 3 platforms
	Level1->createLevelParts(Platform, -76, 2.1, 26.6, 0, 7, 0);
	Level1->createLevelParts(Platform, -76, 9.1, 50.82, 0, 7, 0);
	Level1->createLevelParts(Platform, -76, 2.1, 74.2, 0, 7, 0);

	///rightside 3 platforms
	Level1->createLevelParts(Platform, 73, 2.1, 75.6, 0, 7, 0);
	Level1->createLevelParts(Platform, 73, 9.1, 50.82, 0, 7, 0);
	Level1->createLevelParts(Platform, 73, 14.0, 15.82, 0, 7, 0);

	///the tree's
	Level1->createLevelParts(SmallTree, -56, 15.4, 86.8, 0, 7, 0);
	Level1->createLevelParts(SmallTree, -56, 15.4, 72.8, 0, 7, 0);
	Level1->createLevelParts(SmallTree, -56, 15.4, 58.8, 0, 7, 0);

	/// large tree
	Level1->createLevelParts(TreeTrunk, 0, 14, 57.6, 0, 7, 0);
	Level1->createLevelParts(TreeTop, 0, 61.6, 57.6, 0, 7, 0);

	// the Fence
	Level1->createLevelParts(Fence1, 87, 5, 0, 0, 7, 0);
	Level1->createLevelParts(FencePart2, -95, 6, 48, 0, 7, 0);
	Level1->createLevelParts(FencePart2, -95, 6, -48, 0, 7, 0);


	Level1->createLevelParts(Fence2, -5, 6, 91, 0, 7, 0);
	Level1->createLevelParts(Fence2, -5, 6, -91, 0, 7, 0);
	//cattails
	Level1->createLevelParts(Cattail, 84, 5.6, -47.6, 0, 7, 0);
	Level1->createLevelParts(Cattail, 77, 5.6, -47.6, 0, 7, 0);
	Level1->createLevelParts(Cattail, 68.25, 5.6, -47.6, 0, 7, 0);
	Level1->createLevelParts(Cattail, 59.5, 5.6, -47.6, 0, 7, 0);
	Level1->createLevelParts(Cattail, 50.75, 5.6, -47.6, 0, 7, 0);
	/// the House
	Level1->createLevelParts(HouseSide, 43.4, 14, -70.0, 0, 7, 0);
	Level1->createLevelParts(HouseSide, 7, 14, -70.0, 0, 7, 0);
	Level1->createLevelParts(HouseBack, 24.5, 14, -82.6, 0, 7, 0);
	Level1->createLevelParts(HouseRoof, 24.5, 34.0, -70.5, 0, 6, 0);

	/// build the sandbox
		

	Level1->createLevelParts(SandBox, -60.9, 1.4, -68.0, 0, 7, 0);


	////2nd section of level
	////offset everything by -250 and -15

	//the barn
	int x2o = -230;
	int y2o = 0;
	int z2o = 0;

	Level1->createLevelParts(lvl2Ground, 0 + x2o, -5 + y2o, 0.0 + z2o, ctLevel, 14, 0);
	Level1->createLevelParts(barnback, -81.56 + x2o, 22.8 + y2o, 136.8 + z2o, ctLevel, 23, 0);
	Level1->createLevelParts(barnside, -124.34 + x2o, 23.58 + y2o, 100.92 + z2o, ctLevel, 25, 0);
	Level1->createLevelParts(barnside, -36.34 + x2o, 23.58 + y2o, 100.92 + z2o, ctLevel, 25, 0);
	Level1->createLevelParts(barnfrontside, -44.74 + x2o, 23.74 + y2o, 64.96 + z2o, ctLevel, 25, 0);
	Level1->createLevelParts(barnfrontside2, -117.21 + x2o, 22.8 + y2o, 64.96 + z2o, ctLevel, 25, 0);
	Level1->createLevelParts(barnfronttop, -80.47 + x2o, 64.38 + y2o, 64.96 + z2o, ctLevel, 25, 0);
	Level1->createLevelParts(barnroof, -81.56 + x2o, 75.84 + y2o, 102.79 + z2o, ctLevel, 25, 0);
	/// 1.57 = 90 degrees
	Level1->createLevelParts(Fence1, -139 + x2o, 7 + y2o, 0 + z2o, ctLevel, 11, 0);

	Level1->createLevelParts(Fence1, 0 + x2o, 7 + y2o, 139 + z2o, ctLevel, 11, 1.57);
	Level1->createLevelParts(Fence1, 0 + x2o, 7 + y2o, -139 + z2o, ctLevel, 11, 1.57);

	//bails


	//bottom Row

	Level1->createLevelParts(squarebail, -114 + x2o, 0 + y2o, 129 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -114 + x2o, 11.6 + y2o, 129 + z2o, ctLevel, 7, 0);

	Level1->createLevelParts(squarebail, -114 + x2o, 0 + y2o, 120.2 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -114 + x2o, 0 + y2o, 111.48 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -114 + x2o, 0 + y2o, 102.9 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -100 + x2o, 0 + y2o, 128.98 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -86.68 + x2o, 0 + y2o, 128.98 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -86.68 + x2o, 5.5 + y2o, 128.98 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -86.68 + x2o, 11.6 + y2o, 128.98 + z2o, ctLevel, 7, 0);

	Level1->createLevelParts(squarebail, -103 + x2o, 0 + y2o, 118 + z2o, ctLevel, 7, 1.57);
	Level1->createLevelParts(squarebail, -93.9 + x2o, 0 + y2o, 118 + z2o, ctLevel, 7, 1.57);
	Level1->createLevelParts(squarebail, -84.98 + x2o, 0 + y2o, 118 + z2o, ctLevel, 7, 1.57);
	Level1->createLevelParts(squarebail, -103 + x2o, 0 + y2o, 104.9 + z2o, ctLevel, 7, 1.57);
	Level1->createLevelParts(squarebail, -93.9 + x2o, 0 + y2o, 104.9 + z2o, ctLevel, 7, 1.57);
	Level1->createLevelParts(squarebail, -85 + x2o, 0 + y2o, 104.9 + z2o, ctLevel, 7, 1.57);
	Level1->createLevelParts(squarebail, -114 + x2o, 5.5 + y2o, 120.2 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -114 + x2o, 11.6 + y2o, 120.2 + z2o, ctLevel, 7, 0);

	Level1->createLevelParts(squarebail, -114 + x2o, 5.5 + y2o, 111.48 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -100.6 + x2o, 5.5 + y2o, 128.9 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -100.6 + x2o, 11.6 + y2o, 128.9 + z2o, ctLevel, 7, 0);

	//
	Level1->createLevelParts(squarebail, -72.7 + x2o, 0 + y2o, 128.9 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -72.7 + x2o, 5.5 + y2o, 128.9 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -72.7 + x2o, 11.6 + y2o, 128.9 + z2o, ctLevel, 7, 0);


	Level1->createLevelParts(squarebail, -72.7 + x2o, 0 + y2o, 119.9 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -72.7 + x2o, 5.5 + y2o, 119.9 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -72.7 + x2o, 11.6 + y2o, 119.9 + z2o, ctLevel, 7, 0);

	Level1->createLevelParts(squarebail, -72.7 + x2o, 0 + y2o, 111.2 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -72.7 + x2o, 5.5 + y2o, 111.2 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -72.7 + x2o, 11.6 + y2o, 111.2 + z2o, ctLevel, 7, 0);

	Level1->createLevelParts(squarebail, -72.7 + x2o, 0 + y2o, 102.4 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -72.7 + x2o, 5.5 + y2o, 102.4 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -72.7 + x2o, 11.6 + y2o, 102.4 + z2o, ctLevel, 7, 0);

	Level1->createLevelParts(squarebail, -72.7 + x2o, 0 + y2o, 94 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -72.7 + x2o, 5.5 + y2o, 94 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -72.7 + x2o, 11.6 + y2o, 94 + z2o, ctLevel, 7, 0);


	//

	Level1->createLevelParts(squarebail, -59 + x2o, 11.6 + y2o, 128.9 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -59 + x2o, 11.6 + y2o, 119.9 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -59 + x2o, 11.6 + y2o, 111.2 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -59 + x2o, 11.6 + y2o, 102.4 + z2o, ctLevel, 7, 0);

	Level1->createLevelParts(squarebail, -59 + x2o, 0 + y2o, 94 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -59 + x2o, 5.5 + y2o, 94 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -59 + x2o, 11.6 + y2o, 94 + z2o, ctLevel, 7, 0);


	//
	Level1->createLevelParts(squarebail, -45.3 + x2o, 11.6 + y2o, 128.9 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -45.3 + x2o, 11.6 + y2o, 119.9 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -45.3 + x2o, 11.6 + y2o, 111.2 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, -45.3 + x2o, 11.6 + y2o, 102.4 + z2o, ctLevel, 7, 0);


	//
	Level1->createLevelParts(squarebail, 40 + x2o, 0 + y2o, -43 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, 40 + x2o, 5.5 + y2o, -43 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, 40 + x2o, 11.6 + y2o, -43 + z2o, ctLevel, 7, 0);
	//
	Level1->createLevelParts(squarebail, 54 + x2o, 0 + y2o, -43 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, 54 + x2o, 5.5 + y2o, -43 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, 54 + x2o, 11.6 + y2o, -43 + z2o, ctLevel, 7, 0);
	//
	Level1->createLevelParts(squarebail, 68.5 + x2o, 0 + y2o, -43 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, 68.5 + x2o, 5.5 + y2o, -43 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, 68.5 + x2o, 11.6 + y2o, -43 + z2o, ctLevel, 7, 0);
	//
	Level1->createLevelParts(squarebail, 54 + x2o, 0 + y2o, -52 + z2o, ctLevel, 7, 0);
	Level1->createLevelParts(squarebail, 54 + x2o, 5.5 + y2o, -52 + z2o, ctLevel, 7, 0);
	//
	Level1->createLevelParts(squarebail, 40 + x2o, 0 + y2o, -52 + z2o, ctLevel, 7, 0);


	Level1->createLevelParts(squarebail, -45.3 + x2o, 0 + y2o, 94 + z2o, ctNothing, 7, 0);
	Level1->createLevelParts(squarebail, -45.3 + x2o, 5.5 + y2o, 94 + z2o, ctNothing, 7, 0);
	Level1->createLevelParts(squarebail, -45.3 + x2o, 11.6 + y2o, 94 + z2o, ctLevel, 7, 0);

	Level1->createLevelParts(roundbail, 41 + x2o, 9 + y2o, 52 + z2o, ctLevel, 14, 0);
	Level1->createLevelParts(roundbail, 67 + x2o, 9 + y2o, 52 + z2o, ctLevel, 14, 0);

	Level1->createLevelParts(woodpile, -130 + x2o, 4 + y2o, -127 + z2o, ctLevel, 1, 1.57);

	Objects->createObject(branch, 20 + x2o, -3 + y2o, -70 + z2o, ctStumble, 1);

	Objects->createObject(orange, 54 + x2o, 4 + y2o, 32 + z2o, ctCollect, 1);
	Objects->createObject(orange, 54 + x2o, 4 + y2o, -7 + z2o, ctCollect, 1);

	Objects->createObject(orange, -59 + x2o, 4 + y2o, 111 + z2o, ctCollect, 1);
	Objects->createObject(orange, -45 + x2o, 4 + y2o, 111 + z2o, ctCollect, 1);
	//
	Objects->createObject(orange, 54 + x2o, 35 + y2o, 53 + z2o, ctCollect, 1);
	Objects->createObject(orange, 54 + x2o, 35 + y2o, 13 + z2o, ctCollect, 1);
	Objects->createObject(orange, 54 + x2o, 35 + y2o, -27 + z2o, ctCollect, 1);

	theEnemies->createEnemy(simpleEnemy, 31 + x2o, 2 + y2o, -6 + z2o, 76 + x2o, 2 + y2o, -6 + z2o, NULL, 0, 0, NULL, 0, 0, 3, 15, ctEnemy);
	theEnemies->createEnemy(simpleEnemy, 76 + x2o, 2 + y2o, 32 + z2o, 31 + x2o, 2 + y2o, 32 + z2o, NULL, 0, 0, NULL, 0, 0, 3, 15, ctEnemy);

	theEnemies->createEnemy(simpleEnemy, 27 + x2o, 2 + y2o, -62 + z2o, 27 + x2o, 2 + y2o, -42 + z2o, NULL, 0, 0, NULL, 0, 0, 3, 15, ctEnemy);
	theEnemies->createEnemy(simpleEnemy, 47 + x2o, 2 + y2o, -62 + z2o, 27 + x2o, 2 + y2o, -62 + z2o, NULL, 0, 0, NULL, 0, 0, 3, 15, ctEnemy);

	///unkillable enemies must be placed at the end
	theEnemies->createEnemy(tractor, 4.0f + x2o, 13 + y2o, 88.0f + z2o, 4 + x2o, 13 + y2o, -96 + z2o, 103 + x2o, 13 + y2o, -96 + z2o, 103 + x2o, 13 + y2o, 88 + z2o, 1, 30, ctUnkillable);
	theEnemies->createEnemy(tractor, 103 + x2o, 13 + y2o, -96 + z2o, 103 + x2o, 13 + y2o, 88 + z2o, 4.0f + x2o, 13 + y2o, 88.0f + z2o, 4 + x2o, 13 + y2o, -96 + z2o, 1, 30, ctUnkillable);

	theEnemies->CreateBoundingBox();
	Objects->CreateBoundingBox();
	Level1->CreateBoundingBox();

	////////

	/////////////////////////////////////////////////////////
	std::vector <XNA::AxisAlignedBox> temp;
	temp = Level1->getLevelPartsCollisions();
	for (UINT i = 0; i < temp.size(); i++)
	{
		LevelCollisions.push_back(temp[i]);
	}

	temp = Objects->getObjectCollisions();
	for (UINT i = 0; i < temp.size(); i++)
	{
		LevelCollisions.push_back(temp[i]);
		totCollect++;
	}


	temp = theEnemies->getEnemyCollisions();
	for (UINT i = 0; i < temp.size(); i++)
	{
		LevelCollisions.push_back(temp[i]);
		totEnemy++;
	}


	//////////////////////////////////////////////////////////

	
	// create sound object
	HRESULT result;\
	// init the sound object
	result = SoundSystem::Init(mhMainWnd);
	if (!result) {
		MessageBox(mhMainWnd, L"Could not initialize FMOD_Ex Sound!", L"Error", MB_OK);
		return true;	// returning true or we'll drop out of game init = let game play even if sound load fails
	}


	return true;
}
bool ManageTextureScreen::Update()
{
    assert( m_ScreenMgr );

    Vehicle* veh = m_ScreenMgr->GetVehiclePtr();
    vector< Geom* > select_vec = veh->GetActiveGeomPtrVec();

    if ( select_vec.size() != 1 )
    {
        Hide();
        return false;
    }

    // Redo list on each update.
    m_TextureMgrUI->compChoice->clear();
    m_CompDropDownList.clear();

    std::vector<Geom *> geomVec = veh->FindGeomVec( veh->GetGeomVec() );
    for( int i = 0; i < ( int )geomVec.size(); i++ )
    {
        CompDropDownItem item;
        item.GeomName = geomVec[i]->GetName();
        item.GeomID = geomVec[i]->GetID();

        // Hack to add duplicate names
        char str[256];
        sprintf( str, "%d", i );
        item.GUIIndex = m_TextureMgrUI->compChoice->add( str );

        m_CompDropDownList.push_back( item );
    }
    // Fill Hacked char array with correct names.
    for( int i = 0; i < ( int )m_CompDropDownList.size(); i++ )
    {
        m_TextureMgrUI->compChoice->replace( m_CompDropDownList[i].GUIIndex, m_CompDropDownList[i].GeomName.c_str() );
    }

    // Set compChoice to current selected and update texture dropdown list.
    for( int i = 0; i < ( int )m_CompDropDownList.size(); i++ )
    {
        if( m_CompDropDownList[i].GeomID == select_vec[0]->GetID() )
        {
            m_TextureMgrUI->compChoice->value( m_CompDropDownList[i].GUIIndex );

            // Update Texture Dropdown List. //

            // Redo texture list on each update.
            m_TextureMgrUI->textureChoice->clear();
            m_TexDropDownList.clear();

            // Clear preview window.
            VSPGraphic::Viewport * viewport = m_GlWin->getGraphicEngine()->getDisplay()->getViewport();
            assert( viewport );
            viewport->getBackground()->removeImage();

            // Load Textures...
            TextureMgr * texMgr = select_vec[0]->m_GuiDraw.getTextureMgr();
            std::vector<Texture*> texInfos = texMgr->FindTextureVec( texMgr->GetTextureVec() );
            for( int j = 0; j < ( int )texInfos.size(); j++ )
            {
                TexDropDownItem item;
                item.TexInfo = texInfos[j];

                // Hack to add duplicate names
                char str[256];
                sprintf( str, "%d", j );
                item.GUIIndex = m_TextureMgrUI->textureChoice->add( str );

                m_TexDropDownList.push_back( item );
            }
            // Fill Hacked char array with correct names.
            for( int j = 0; j < ( int )m_TexDropDownList.size(); j++ )
            {
                m_TextureMgrUI->textureChoice->replace( m_TexDropDownList[j].GUIIndex, m_TexDropDownList[j].TexInfo->GetName().c_str() );
            }
            if( !m_TexDropDownList.empty() )
            {
                if( m_SelectedTexItem )
                {
                    m_TextureMgrUI->textureChoice->value( m_SelectedTexItem->GUIIndex );
                }
                else
                {
                    // On refresh list, if nothing is selected, pick last item on list.
                    m_TextureMgrUI->textureChoice->value( m_TexDropDownList[m_TexDropDownList.size() - 1].GUIIndex );
                }
                UpdateCurrentSelected();

                assert( m_SelectedTexItem );

                viewport->getBackground()->attachImage( VSPGraphic::GlobalTextureRepo()->
                    get2DTexture( m_SelectedTexItem->TexInfo->m_FileName.c_str() ) );
            }
            else
            {
                ResetCurrentSelected();

                // Force redraw empty list.
                m_TextureMgrUI->textureChoice->redraw();
            }

            // Update Sliders and Buttons.
            if( m_SelectedTexItem )
            {
                Texture * info = select_vec[0]->m_GuiDraw.getTextureMgr()->FindTexture( m_SelectedTexItem->TexInfo->GetID() );

                m_TextureMgrUI->textureNameInput->value( info->GetName().c_str() );

                m_UScaleSlider.Update( info->m_UScale.GetID() );
                m_WScaleSlider.Update( info->m_WScale.GetID() );

                m_UPosSlider.Update( info->m_U.GetID() );
                m_WPosSlider.Update( info->m_W.GetID() );

                m_TransparencySlider.Update( info->m_Transparency.GetID() );

                m_FlipUButton.Update( info->m_FlipU.GetID() );
                m_FlipWButton.Update( info->m_FlipW.GetID() );
            }
            break;
        }
    }
    m_GlWin->redraw();
    return true;
}