コード例 #1
0
ファイル: main.cpp プロジェクト: Team306/BigProject
void CubeMapApp::initApp()
{
	D3DApp::initApp();

	fx::InitAll(md3dDevice);
	InputLayout::InitAll(md3dDevice);
	GetTextureMgr().init(md3dDevice);


	mTech                = fx::CubeMapFX->GetTechniqueByName("CubeMapTech");
	mfxLightVar          = fx::CubeMapFX->GetVariableByName("gLight");
	mfxEyePosVar         = fx::CubeMapFX->GetVariableByName("gEyePosW");
	mfxWVPVar            = fx::CubeMapFX->GetVariableByName("gWVP")->AsMatrix();
	mfxWorldVar          = fx::CubeMapFX->GetVariableByName("gWorld")->AsMatrix();
	mfxTexMtxVar         = fx::CubeMapFX->GetVariableByName("gTexMtx")->AsMatrix();
	mfxReflectMtrlVar    = fx::CubeMapFX->GetVariableByName("gReflectMtrl")->AsVector();
	mfxCubeMapEnabledVar = fx::CubeMapFX->GetVariableByName("gCubeMapEnabled")->AsScalar();
	mfxDiffuseMapVar     = fx::CubeMapFX->GetVariableByName("gDiffuseMap")->AsShaderResource();
	mfxSpecMapVar        = fx::CubeMapFX->GetVariableByName("gSpecMap")->AsShaderResource();
	mfxCubeMapVar        = fx::CubeMapFX->GetVariableByName("gCubeMap")->AsShaderResource();

 
	//mClearColor = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);

	GetCamera().position() = D3DXVECTOR3(0.0f, 1.8f, -10.0f);

	mBallMapRV        = GetTextureMgr().createTex(L"blackdiffuse.dds");
	//mSpecMapRV        = GetTextureMgr().createTex(L"spec.dds");
	mDefaultSpecMapRV = GetTextureMgr().createTex(L"defaultspec.dds");
	mEnvMapRV         = GetTextureMgr().createCubeTex(L"grassenvmap1024.dds");

	mFloor.init(md3dDevice, 41, 21, 1.0f);
	mBase.init(md3dDevice, 2.0f);
	mBall.init(md3dDevice, 0.5f, 30, 30);
	mColumn.init(md3dDevice, 0.25f, 1.0f, 3.0f, 30, 30);
	mSky.init(md3dDevice, mEnvMapRV, 5000.0f);

 
	mParallelLight.dir      = D3DXVECTOR3(0.57735f, -0.57735f, 0.57735f);
	mParallelLight.ambient  = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f);
	mParallelLight.diffuse  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mParallelLight.specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
}
コード例 #2
0
ファイル: Winmain.cpp プロジェクト: GameProject/Tower
bool InitWindowsApp(HINSTANCE instanceHandle, int show)
{
	//ShowCursor(0);

	// The first task to creating a window is to describe some of its 
	// characteristics by filling out a WNDCLASS structure.
	WNDCLASS wc;
	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc; 
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = instanceHandle;
	wc.hIcon         = LoadIcon(0, IDI_APPLICATION);
	wc.hCursor       = LoadCursor(0, IDC_CROSS);
	wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = L"BasicWndClass";

	// Next, we register this WNDCLASS instance with Windows so that we can 
	// create a window based on it.
	if(!RegisterClass(&wc)) 
	{
		MessageBox(0, L"RegisterClass FAILED", 0, 0);
		return false;
	}

	// With our WNDCLASS instance registered, we can create a window with the
	// CreateWindow function.  This function returns a handle to the window it
	// creates (an HWND).  If the creation failed, the handle will have the value
	// of zero.  A window handle is a way to refer to the window, which is internally
	// managed by Windows.  Many of the Win32 API functions that operate on windows
	// require an HWND so that they know what window to act on.

	RECT rc;
	rc.left = 0;
	rc.top = 0;
	rc.right = SCREEN_WIDTH;
	rc.bottom = SCREEN_HEIGHT;
	AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);

	g_Hwnd = CreateWindow(
		L"BasicWndClass",	 // Registered WNDCLASS instance to use.
		L"Gruppuppgift",	// window title
		WS_OVERLAPPEDWINDOW, // style flags
		CW_USEDEFAULT,		 // x-coordinate
		CW_USEDEFAULT,       // y-coordinate
		rc.right - rc.left,        // width
		rc.bottom - rc.top,       // height
		0,               // parent window
		0,               // menu handle
		instanceHandle,      // app instance
		0);              // extra creation parameters

	if(g_Hwnd == 0)
	{
		MessageBox(0, L"CreateWindow FAILED", 0, 0);
		return false;
	}

	// Even though we just created a window, it is not initially shown.  
	// Therefore, the final step is to show and update the window we just
	// created, which can be done with the following two function calls.
	// Observe that we pass the handle to the window we want to show and
	// update so that these functions know which window to show and update.

	ShowWindow(g_Hwnd, show);
	UpdateWindow(g_Hwnd);

	//________________________________

	// Fill out a DXGI_SWAP_CHAIN_DESC to describe our swap chain.
	DXGI_SWAP_CHAIN_DESC sd;
	sd.BufferDesc.Width  = SCREEN_WIDTH;
	sd.BufferDesc.Height = SCREEN_HEIGHT;
	sd.BufferDesc.RefreshRate.Numerator = 60;
	sd.BufferDesc.RefreshRate.Denominator = 1;
	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

	// No multisampling.
	sd.SampleDesc.Count   = 1;
	sd.SampleDesc.Quality = 0;

	sd.BufferUsage  = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	sd.BufferCount  = 1;
	sd.OutputWindow = g_Hwnd;
	sd.Windowed     = true;
	sd.SwapEffect   = DXGI_SWAP_EFFECT_DISCARD;
	sd.Flags        = 0;

	D3D10CreateDeviceAndSwapChain(
		0,                 //default adapter
		D3D10_DRIVER_TYPE_HARDWARE,
		0,                 // no software device
		0, 
		D3D10_SDK_VERSION,
		&sd,
		&mSwapChain,
		&md3dDevice);

	ID3D10Texture2D* backBuffer;
	mSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&backBuffer);
	md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView);
	backBuffer->Release();
	backBuffer = 0;

	
	// Create depth stencil texture
	D3D10_TEXTURE2D_DESC descDepth;
	ZeroMemory( &descDepth, sizeof(descDepth) );
	descDepth.Width = SCREEN_WIDTH;
	descDepth.Height = SCREEN_HEIGHT;
	descDepth.MipLevels = 1;
	descDepth.ArraySize = 1;
	descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	descDepth.SampleDesc.Count = 1;
	descDepth.SampleDesc.Quality = 0;
	descDepth.Usage = D3D10_USAGE_DEFAULT;
	descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
	descDepth.CPUAccessFlags = 0;
	descDepth.MiscFlags = 0;
	md3dDevice->CreateTexture2D( &descDepth, NULL, &mDepthStencil );

	// Create the depth stencil view
	D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
	ZeroMemory( &descDSV, sizeof(descDSV) );
	descDSV.Format = descDepth.Format;
	descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
	descDSV.Texture2D.MipSlice = 0;

	// Bind the render target view and depth/stencil view to the pipeline.
	md3dDevice->CreateDepthStencilView( mDepthStencil, &descDSV, &mDepthStencilView );
	md3dDevice->OMSetRenderTargets( 1, &mRenderTargetView, mDepthStencilView );

	// Set the viewport transform.
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.Width    = SCREEN_WIDTH;
	vp.Height   = SCREEN_HEIGHT;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	md3dDevice->RSSetViewports(1, &vp);
	//________________________________

	Effects::InitAll(md3dDevice);
	fxU.init(md3dDevice, Effects::MeshFX);

	Terrain::InitInfo tii;
	tii.CellSpacing = 1.0f;
	tii.HeightmapFilename = L"flat513.raw";
	tii.HeightOffset = -30.0f;
	tii.HeightScale = 0.2f;
	tii.NumCols = 513;
	tii.NumRows = 513;
	land.init(md3dDevice, tii);
	//mTerrain.init(md3dDevice, (std::string)"Textures/Terrain/HeightMap.raw", 0.35f, -50.0f, 0.1f, 512, 512);

	//Cube c;
	//c.init(md3dDevice, D3DXVECTOR3(2.0f, 2.0f, 2.0f), D3DXVECTOR3(-16.0f, land.getHeight(-16.0f, -16.0f)+1.0f, -16.0f));
	//mCubes.push_back(c);
	//nr.push_back(0);

	nrOfTowers.push_back(0);
	
	mCubes.resize(10);
	for(int i = 0; i < mCubes.size();i++)
	{
		mCubes[i].init(i, md3dDevice, D3DXVECTOR3(5.0f,5.0f,5.0f), D3DXVECTOR3(0.0f, land.getHeight(0.0f,0.0f), 0.0f), (i*0.50f+0.50f));
		nr.push_back(0);
	}
	pWave = new wave(1, 20, md3dDevice, &land);
	pWave->initMonsters();
	
	mPyramid.init(md3dDevice, D3DXVECTOR3(2.0f, 2.0f, 2.0f), D3DXVECTOR3(-16.0f, land.getHeight(-16.0f, -16.0f)+5.0f, -16.0f));
	mCylinder.init(md3dDevice, 1.0f, D3DXVECTOR3(-2.0f, land.getHeight(-2.0f, -8.0f)+1.0f, -8.0f));

	//GetCamera().setPosY(land.getHeight(GetCamera().getPos().x, GetCamera().getPos().z));
	GetCamera().setLens(0.30f*pi, (float)SCREEN_WIDTH/SCREEN_HEIGHT, 1.0f, 1000.0f);

	fire.init(md3dDevice, Effects::FireFX, L"Textures/Particle/flare0.dds", 500);
	fire.setEmitPos(D3DXVECTOR3(-2.0f, land.getHeight(-5.0f, 2.0f)+2.5f, -8.0f));

	rain.init(md3dDevice, Effects::RainFX, L"Textures/Particle/raindrop.gif", 1000);

	sky.init(md3dDevice, L"Textures/Terrain/grassenvmap1024.dds", 5000.0f);
	
	//Trees
	D3DXVECTOR3 treeCenters[6];

	float x = -20.0f;
	float z = 20.0f;
	treeCenters[0] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = -23.0f;
	z = 16.0f;
	treeCenters[1] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = -3.0f;
	z = 18.0f;
	treeCenters[2] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = 22.0f;
	z = 13.0f;
	treeCenters[3] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = 17.0f;
	z = -23.0f;
	treeCenters[4] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = 22.0f;
	z = -20.0f;
	treeCenters[5] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);
	mTrees.init(md3dDevice, treeCenters, 6, L"Textures/Wood/tree3.dds");

	//QuadTree
	qtc.init(md3dDevice, &land, GetCamera().proj(), GetCamera().view());

	//init GUI
	gui.Init(md3dDevice,SCREEN_WIDTH,SCREEN_HEIGHT);
	//set gui callback
	gui.SetCallback(OnGUIEvent);
	//adding a button
	gui.AddButton(PLACE_TOWER,L"test.png",10,10,100,100);

	GetTowerScript().Init("tower");

	return true;
}