Beispiel #1
0
CullingDemo::CullingDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();
	
	mTerrain = new Terrain(513, 513, 4.0f, 4.0f, 
		"coastMountain513.raw",  
		"grass.dds",
		"dirt.dds",
		"rock.dds",
		"blend_coastal.dds",
		1.5f, 0.0f);

	D3DXVECTOR3 toSun(1.0f, 1.0f, 1.0f);
	D3DXVec3Normalize(&toSun, &toSun);
	mTerrain->setDirToSunW(toSun);

	// Initialize camera.
	gCamera->pos().y = 250.0f;
	gCamera->setSpeed(50.0f);

	mGfxStats->addVertices(mTerrain->getNumVertices());
	mGfxStats->addTriangles(mTerrain->getNumTriangles());

	onResetDevice();
}
AmbientDiffuseDemo::AmbientDiffuseDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	mGfxStats = new GfxStats();

	mCameraRadius    = 10.0f;
	mCameraRotationY = 1.2 * D3DX_PI;
	mCameraHeight    = 5.0f;

	mLightVecW    = D3DXVECTOR3(0.0, 0.0f, -1.0f);
	mDiffuseMtrl  = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f);
	mDiffuseLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mAmbientMtrl  = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f);
	mAmbientLight = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f);

	D3DXMatrixIdentity(&mWorld);

	HR(D3DXCreateTeapot(gd3dDevice, &mTeapot, 0));
	buildFX();

	onResetDevice();

	InitAllVertexDeclarations();
}
Beispiel #3
0
CameraDemo::CameraDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();

	mTerrain = new Terrain(257, 257, 10.0f, 10.0f, 
		"heightmap17_257.raw",  
		"grass.dds",
		"dirt.dds",
		"stone.dds",
		"blend_hm17.dds",
		3.0f, 0.0f);

	mTerrain->setDirToSunW(D3DXVECTOR3(0.0f, 1.0f, 0.0f));

	// Initialize camera.
	gCamera->pos() = D3DXVECTOR3(-200.0f, 300.0f, 0.0f);

	mGfxStats->addVertices(mTerrain->getNumVertices());
	mGfxStats->addTriangles(mTerrain->getNumTriangles());

	onResetDevice();
}
Beispiel #4
0
bool D3DApp::isDeviceLost()
{
	// Get the state of the graphics device.
	HRESULT hr = gd3dDevice->TestCooperativeLevel();

	// If the device is lost and cannot be reset yet then
	// sleep for a bit and we'll try again on the next 
	// message loop cycle.
	if( hr == D3DERR_DEVICELOST )
	{
		Sleep(20);
		return true;
	}
	// Driver error, exit.
	else if( hr == D3DERR_DRIVERINTERNALERROR )
	{
		MessageBox(0, "Internal Driver Error...Exiting", 0, 0);
		PostQuitMessage(0);
		return true;
	}
	// The device is lost but we can reset and restore it.
	else if( hr == D3DERR_DEVICENOTRESET )
	{
		onLostDevice();
		HR(gd3dDevice->Reset(&md3dPP));
		onResetDevice();
		return false;
	}
	else
		return false;
}
Beispiel #5
0
XFileDemo::XFileDemo(HINSTANCE hInstance, std::wstring winCaption)
	: D3DApp(hInstance, winCaption)
{
	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();

	mCameraRadius    = 12.0f;
	mCameraRotationY = 1.2f * D3DX_PI;
	mCameraHeight    = 6.0f;

	mLight.dirW    = D3DXVECTOR3(0.0f, 1.0f, 2.0f);
	D3DXVec3Normalize(&mLight.dirW, &mLight.dirW);
	mLight.ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
	mLight.diffuse = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	mLight.spec    = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);

	LoadXFile(L"../src/chap14/XFileDemo/Dwarf.x", &mMesh, mMtrl, mTex);
	D3DXMatrixIdentity(&mWorld);

	HR(D3DXCreateTextureFromFile(gd3dDevice, L"../src/chap14/XFileDemo/whitetex.dds", &mWhiteTex));

	mGfxStats->addVertices(mMesh->GetNumVertices());
	mGfxStats->addTriangles(mMesh->GetNumFaces());

	buildFX();
	
	onResetDevice();
}
Beispiel #6
0
DiffuseCubeDemo::DiffuseCubeDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	mGfxStats = new GfxStats();

	mCameraRadius    = 10.0f;
	mCameraRotationY = 1.2 * D3DX_PI;
	mCameraHeight    = 5.0f;

	mLightVecW    = D3DXVECTOR3(-0.5, 0.75f, -2.0f);
	D3DXVec3Normalize(&mLightVecW, &mLightVecW);
	mDiffuseMtrl  = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f);
	mDiffuseLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

	D3DXMatrixIdentity(&mWorld);

	buildVertexBuffer();
	buildIndexBuffer();
	buildFX();

	onResetDevice();

	InitAllVertexDeclarations();
}
Beispiel #7
0
ProjTexDemo::ProjTexDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();
	mSky = new Sky("grassenvmap1024.dds", 10000.0f);

	LoadXFile("shapes.x", &mSceneMesh, mSceneMtrls, mSceneTextures);
	D3DXMatrixIdentity(&mSceneWorld);

	HR(D3DXCreateTextureFromFile(gd3dDevice, "whitetex.dds", &mWhiteTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "skull.dds", &mSkullTex));

	// Build light projective texture matrix.
	D3DXMATRIX lightView;
	D3DXVECTOR3 lightPosW(60.0f, 90.0f, 0.0f);
	D3DXVECTOR3 lightTargetW(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 lightUpW(0.0f, 1.0f, 0.0f);
	D3DXMatrixLookAtLH(&lightView, &lightPosW, &lightTargetW, &lightUpW);

	D3DXMATRIX lightLens;
	float lightFOV = D3DX_PI*0.30f;
	D3DXMatrixPerspectiveFovLH(&lightLens, lightFOV, 1.0f, 1.0f, 200.0f);

	mLightWVP = mSceneWorld*lightView*lightLens;

	// Setup a spotlight corresponding to the projector.
	D3DXVECTOR3 lightDirW = lightTargetW - lightPosW;
	D3DXVec3Normalize(&lightDirW, &lightDirW);
	mLight.posW      = lightPosW;
	mLight.dirW      = lightDirW;
	mLight.ambient   = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
	mLight.diffuse   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mLight.spec      = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	mLight.spotPower = 8.0f;

	// Initialize camera.
	gCamera->pos().y = 100.0f;
	gCamera->pos().z = -100.0f;
	gCamera->setSpeed(50.0f);

	mGfxStats->addVertices(mSceneMesh->GetNumVertices());
	mGfxStats->addTriangles(mSceneMesh->GetNumFaces());

	mGfxStats->addVertices(mSky->getNumVertices());
	mGfxStats->addTriangles(mSky->getNumTriangles());

	buildFX();

	onResetDevice();
}
Beispiel #8
0
SphereCylDemo::SphereCylDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();

	mCameraRadius    = 50.0f;
	mCameraRotationY = 1.2 * D3DX_PI;
	mCameraHeight    = 20.0f;

	mAmbientLight   = WHITE;
	mDiffuseLight   = WHITE;
	mSpecLight      = WHITE;
	mLightVecW      = D3DXVECTOR3(0.0, 0.0f, -1.0f);

	mGridMtrl     = Mtrl(WHITE*0.7f, WHITE, WHITE*0.5f, 16.0f);
	mCylinderMtrl = Mtrl(WHITE*0.4f, WHITE, WHITE*0.8f, 8.0f);
	mSphereMtrl   = Mtrl(WHITE*0.4f, WHITE, WHITE*0.8f, 8.0f);

	HR(D3DXCreateCylinder(gd3dDevice, 1.0f, 1.0f, 6.0f, 20, 20, &mCylinder, 0));
	HR(D3DXCreateSphere(gd3dDevice, 1.0f, 20, 20, &mSphere, 0));

	genSphericalTexCoords();
	genCylTexCoords(Z_AXIS);

	HR(D3DXCreateTextureFromFile(gd3dDevice, "marble.bmp", &mSphereTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "stone2.dds", &mCylTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "ground0.dds", &mGridTex));

	buildGeoBuffers();
	buildFX();

	// If you look at the drawCylinders and drawSpheres functions, you see
	// that we draw 14 cylinders and 14 spheres.
	int numCylVerts    = mCylinder->GetNumVertices() * 14;
	int numSphereVerts = mSphere->GetNumVertices()   * 14;
	int numCylTris     = mCylinder->GetNumFaces()    * 14;
	int numSphereTris  = mSphere->GetNumFaces()      * 14;

	mGfxStats->addVertices(mNumGridVertices);
	mGfxStats->addVertices(numCylVerts);
	mGfxStats->addVertices(numSphereVerts);
	mGfxStats->addTriangles(mNumGridTriangles);
	mGfxStats->addTriangles(numCylTris);
	mGfxStats->addTriangles(numSphereTris);

	onResetDevice();
}
Beispiel #9
0
MirrorDemo::MirrorDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();


	mCameraRadius    = 15.0f;
	mCameraRotationY = 1.4f * D3DX_PI;
	mCameraHeight    = 5.0f;

	mLightVecW     = D3DXVECTOR3(0.0, 0.707f, -0.707f);
	mDiffuseLight  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mAmbientLight  = D3DXCOLOR(0.6f, 0.6f, 0.6f, 1.0f);
	mSpecularLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

	mWhiteMtrl.ambient   = WHITE;
	mWhiteMtrl.diffuse   = WHITE;
	mWhiteMtrl.spec      = WHITE * 0.8f;
	mWhiteMtrl.specPower = 16.0f;


	D3DXMatrixIdentity(&mRoomWorld);
	D3DXMatrixTranslation(&mTeapotWorld, 0.0f, 3.0f, -6.0f);

	HR(D3DXCreateTextureFromFile(gd3dDevice, "checkboard.dds", &mFloorTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "brick2.dds", &mWallTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "ice.dds", &mMirrorTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "brick1.dds", &mTeapotTex));

	HR(D3DXCreateTeapot(gd3dDevice, &mTeapot, 0));

	// Generate texture coordinates for the teapot.
	genSphericalTexCoords();

	// Room geometry count.
	mGfxStats->addVertices(24);
	mGfxStats->addTriangles(8);

	// We draw the teapot twice--once normal and once reflected.
	mGfxStats->addVertices(mTeapot->GetNumVertices() * 2);
	mGfxStats->addTriangles(mTeapot->GetNumFaces()   * 2);

	buildRoomGeometry();
	buildFX();

	onResetDevice();
}
Beispiel #10
0
SkeletonClass::SkeletonClass(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	mUp = D3DXVECTOR3(0.0f, 1.0f, 0.0f);

	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	mCameraRadius    = 50.0f;
	mCameraRotationY = 1.75f * D3DX_PI;
	mCameraRotationX = 1.75f * D3DX_PI;

	InitAllVertexDeclarations();

	skyBox = new Sky("cubeMap.dds", 10000);
	skyBox->Create(gd3dDevice);

    // repleace or add to the following object creation
	m_Objects.push_back(new Cylinder(5, 5, 10, 25, 25));
    m_Objects[0]->Create( gd3dDevice );

	m_Objects.push_back(new Sphere(5, 25, 25));
	m_Objects[1]->Create(gd3dDevice);

	m_Objects.push_back(new Cone(5,10,25));
	m_Objects[2]->Create(gd3dDevice);

	m_Objects.push_back(new BaseObject3D());
	m_Objects[3]->Create(gd3dDevice);

	mLightPos = D3DXVECTOR3(50, 100, 1);

	mWireFrameOn = false;
	mTextureOn = true;
	GfxStats::GetInstance()->setTextureOn(mTextureOn);
	mNormalMappingOn = true;
	GfxStats::GetInstance()->setNormalMappingOn(mNormalMappingOn);
	mReflectionOn = true;
	GfxStats::GetInstance()->setReflectionOn(mReflectionOn);
	mCurrentObject = 0;
	mSpecularOn = true;
	mDiffuseOn = true;
	mPhongOn = true;

	mReflectSpecBlend = 1;
	mNormalStrength = 0.7f;
	mSpecularCoefficient = 2;
	GfxStats::GetInstance()->setSpecularcoefficient(mSpecularCoefficient);

	onResetDevice();
}
Beispiel #11
0
void D3DApp::enableFullScreenMode(BOOL enable)
{
	// Switch to fullscreen mode.
	if( enable )
	{
		// Are we already in fullscreen mode?
		if( !md3dPP.Windowed ) 
			return;

		int width  = GetSystemMetrics(SM_CXSCREEN);
		int height = GetSystemMetrics(SM_CYSCREEN);

		md3dPP.BackBufferFormat = D3DFMT_X8R8G8B8;
		md3dPP.BackBufferWidth  = width;
		md3dPP.BackBufferHeight = height;
		md3dPP.Windowed         = false;

		// Change the window style to a more fullscreen friendly style.
		SetWindowLongPtr(mhMainWnd, GWL_STYLE, WS_POPUP);

		// If we call SetWindowLongPtr, MSDN states that we need to call
		// SetWindowPos for the change to take effect.  In addition, we 
		// need to call this function anyway to update the window dimensions.
		SetWindowPos(mhMainWnd, HWND_TOP, 0, 0, width, height, SWP_NOZORDER | SWP_SHOWWINDOW);	
	}
	// Switch to windowed mode.
	else
	{
		// Are we already in windowed mode?
		if( md3dPP.Windowed ) 
			return;

		RECT R = {0, 0, 800, 600};
		AdjustWindowRect(&R, WS_OVERLAPPEDWINDOW, false);
		md3dPP.BackBufferFormat = D3DFMT_UNKNOWN;
		md3dPP.BackBufferWidth  = 800;
		md3dPP.BackBufferHeight = 600;
		md3dPP.Windowed         = true;
	
		// Change the window style to a more windowed friendly style.
		SetWindowLongPtr(mhMainWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);

		// If we call SetWindowLongPtr, MSDN states that we need to call
		// SetWindowPos for the change to take effect.  In addition, we 
		// need to call this function anyway to update the window dimensions.
		SetWindowPos(mhMainWnd, HWND_TOP, 100, 100, R.right, R.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
	}

	// Reset the device with the changes.
	onLostDevice();
	HR(gd3dDevice->Reset(&md3dPP));
	onResetDevice();
}
Beispiel #12
0
GateDemo::GateDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	mGfxStats = new GfxStats();

	mCameraRadius    = 6.0f;
	mCameraRotationY = 1.2 * D3DX_PI;
	mCameraHeight    = 3.0f;

	mLightVecW     = D3DXVECTOR3(0.0, 0.707f, -0.707f);
	mDiffuseLight  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mAmbientLight  = D3DXCOLOR(0.6f, 0.6f, 0.6f, 1.0f);
	mSpecularLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

	mGroundMtrl.ambient   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mGroundMtrl.diffuse   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mGroundMtrl.spec      = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f);
	mGroundMtrl.specPower = 8.0f;

	mGateMtrl.ambient   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mGateMtrl.diffuse   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mGateMtrl.spec      = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	mGateMtrl.specPower = 8.0f;

	D3DXMatrixIdentity(&mGroundWorld);
	D3DXMatrixIdentity(&mGateWorld);

	HR(D3DXCreateTextureFromFile(gd3dDevice, "ground0.dds", &mGroundTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "gatea.dds", &mGateTex));

	buildGridGeometry();
	buildGateGeometry();

	mGfxStats->addVertices(mNumGridVertices);
	mGfxStats->addTriangles(mNumGridTriangles);

	// Add gate quad vertices.
	mGfxStats->addVertices(4);
	mGfxStats->addTriangles(2);

	buildFX();

	onResetDevice();

	InitAllVertexDeclarations();
}
Beispiel #13
0
GunDemo::GunDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();

	// World space units are meters.  
	mTerrain = new Terrain(257, 257, 2.0f, 2.0f, 
		"heightmap1_257.raw",  
		"mud.dds",
		"stone.dds",
		"snow.dds",
		"blend_hm1.dds",
		0.4f, 0.0f);

	D3DXVECTOR3 toSun(1.0f, 1.0f, 1.0f);
	D3DXVec3Normalize(&toSun, &toSun);
	mTerrain->setDirToSunW(toSun);

	// Initialize camera.
	gCamera->pos() = D3DXVECTOR3(55.0f, 50.0f, 25.0f);
	gCamera->setSpeed(40.0f);

	// Initialize the particle system.
	D3DXMATRIX psysWorld;
	D3DXMatrixIdentity(&psysWorld);

	// Gun bullets spread over a long distance and there is not
	// a high bullet count, so not really worth trying to cull.
	AABB psysBox; 
	psysBox.maxPt = D3DXVECTOR3(INFINITY, INFINITY, INFINITY);
	psysBox.minPt = D3DXVECTOR3(-INFINITY, -INFINITY, -INFINITY);

	// Accelerate due to gravity.  However, since the bullets travel at 
	// such a high velocity, the effect of gravity of not really observed.
	mPSys = new Gun("gun.fx", "GunTech", "bolt.dds", 
		D3DXVECTOR3(0, -9.8f, 0.0f), psysBox, 100, -1.0f);
	mPSys->setWorldMtx(psysWorld);              

	mGfxStats->addVertices(mTerrain->getNumVertices());
	mGfxStats->addTriangles(mTerrain->getNumTriangles());

	onResetDevice();
}
Beispiel #14
0
SprinklerDemo::SprinklerDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();

	// World space units are meters.  
	mTerrain = new Terrain(257, 257, 2.0f, 2.0f, 
		"heightmap1_257.raw",  
		"mud.dds",
		"stone.dds",
		"snow.dds",
		"blend_hm1.dds",
		0.4f, 0.0f);

	D3DXVECTOR3 toSun(1.0f, 1.0f, 1.0f);
	D3DXVec3Normalize(&toSun, &toSun);
	mTerrain->setDirToSunW(toSun);

	// Initialize camera.
	gCamera->pos() = D3DXVECTOR3(55.0f, 50.0f, 25.0f);
	gCamera->setSpeed(40.0f);

	// Initialize the particle system.
	D3DXMATRIX psysWorld;
	D3DXMatrixTranslation(&psysWorld, 
		55.0f, mTerrain->getHeight(55.0f, 55.0f), 55.0f);

	// Don't cull, but in practice you'd want to figure out a
	// bounding box based on the settings of the system.
	AABB psysBox; 
	psysBox.maxPt = D3DXVECTOR3(INFINITY, INFINITY, INFINITY);
	psysBox.minPt = D3DXVECTOR3(-INFINITY, -INFINITY, -INFINITY);

	// Accelerate due to wind and gravity.
	mPSys = new Sprinkler("sprinkler.fx", "SprinklerTech", "bolt.dds", 
		D3DXVECTOR3(-3.0f, -9.8f, 0.0f), psysBox, 2000, 0.003f);
	mPSys->setWorldMtx(psysWorld);

	mGfxStats->addVertices(mTerrain->getNumVertices());
	mGfxStats->addTriangles(mTerrain->getNumTriangles());

	onResetDevice();
}
Beispiel #15
0
SpotlightDemo::SpotlightDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	mGfxStats = new GfxStats();

	mCameraRadius    = 50.0f;
	mCameraRotationY = 1.2 * D3DX_PI;
	mCameraHeight    = 20.0f;

	mAmbientLight   = 0.4f*WHITE;
	mDiffuseLight   = WHITE;
	mSpecLight      = WHITE;
	mAttenuation012 = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
	mSpotPower      = 16.0f;

	mGridMtrl     = Mtrl(BLUE, BLUE, WHITE, 16.0f);
	mCylinderMtrl = Mtrl(RED, RED, WHITE, 8.0f);
	mSphereMtrl   = Mtrl(GREEN, GREEN, WHITE, 8.0f);

	HR(D3DXCreateCylinder(gd3dDevice, 1.0f, 1.0f, 6.0f, 20, 20, &mCylinder, 0));
	HR(D3DXCreateSphere(gd3dDevice, 1.0f, 20, 20, &mSphere, 0));

	buildGeoBuffers();
	buildFX();

	// If you look at the drawCylinders and drawSpheres functions, you see
	// that we draw 14 cylinders and 14 spheres.
	int numCylVerts    = mCylinder->GetNumVertices() * 14;
	int numSphereVerts = mSphere->GetNumVertices()   * 14;
	int numCylTris     = mCylinder->GetNumFaces()    * 14;
	int numSphereTris  = mSphere->GetNumFaces()      * 14;

	mGfxStats->addVertices(mNumGridVertices);
	mGfxStats->addVertices(numCylVerts);
	mGfxStats->addVertices(numSphereVerts);
	mGfxStats->addTriangles(mNumGridTriangles);
	mGfxStats->addTriangles(numCylTris);
	mGfxStats->addTriangles(numSphereTris);

	onResetDevice();

	InitAllVertexDeclarations();
}
Beispiel #16
0
TriGridDemo::TriGridDemo(HINSTANCE hInstance, std::wstring winCaption)
	: D3DApp(hInstance, winCaption)
{
	mGfxStats = new GfxStats();

	mCameraRadius    = 10.0f;
	mCameraRotationY = 1.2 * D3DX_PI;
	mCameraHeight    = 5.0f;

	buildGeoBuffers();
	buildFX();

	onResetDevice();

	InitAllVertexDeclarations();
}
Beispiel #17
0
Graphics::Graphics()
{
	mBufferFactory = new BufferFactory();

	initBuffers();
	initEffect();
	initFonts();

	mWhiteTexture = loadTexture("data/imgs/white.bmp");

	// TESTING.. 
	D3DVERTEXELEMENT9 elems[MAX_FVF_DECL_SIZE];
	UINT numElems = 0;
	VertexPNT::Decl->GetDeclaration(elems, &numElems);
	D3DXCreateMesh(2, 4, D3DXMESH_MANAGED, elems, gd3dDevice, &mRayMesh);
	
	onResetDevice();
}
Beispiel #18
0
FireRingDemo::FireRingDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();

	mTerrain = new Terrain(257, 257, 2.0f, 2.0f, 
		"heightmap1_257.raw",  
		"mud.dds",
		"stone.dds",
		"snow.dds",
		"blend_hm1.dds",
		0.4f, 0.0f);

	D3DXVECTOR3 toSun(1.0f, 1.0f, 1.0f);
	D3DXVec3Normalize(&toSun, &toSun);
	mTerrain->setDirToSunW(toSun);

	// Initialize camera.
	gCamera->pos() = D3DXVECTOR3(55.0f, 50.0f, 25.0f);
	gCamera->setSpeed(40.0f);

	// Initialize the particle system.
	D3DXMATRIX psysWorld;
	D3DXMatrixTranslation(&psysWorld, 55.0f, 45.0f, 55.0f);
	AABB psysBox;
	psysBox.minPt = D3DXVECTOR3(-15.0f, -15.0f, -15.0f);
	psysBox.maxPt = D3DXVECTOR3( 15.0f,  15.0f,  15.0f);
	mPSys = new FireRing("firering.fx", "FireRingTech", "torch.dds", 
		D3DXVECTOR3(0.0f, 0.9f, 0.0f), psysBox, 1500, 0.0025f);
	mPSys->setWorldMtx(psysWorld);

	mGfxStats->addVertices(mTerrain->getNumVertices());
	mGfxStats->addTriangles(mTerrain->getNumTriangles());

	onResetDevice();
}
Beispiel #19
0
StencilMirrorDemo::StencilMirrorDemo(HINSTANCE hInstance, std::wstring winCaption)
	: D3DApp(hInstance, winCaption)
{
	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();

	mCameraRadius    = 15.0f;
	mCameraRotationY = 1.4f * D3DX_PI;
	mCameraHeight    = 5.0f;

	mLightVecW     = D3DXVECTOR3(0.0f, 0.707f, -0.707f);
	mDiffuseLight  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mAmbientLight  = D3DXCOLOR(0.6f, 0.6f, 0.6f, 1.0f);
	mSpecularLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

	mWhiteMtrl.ambient   = WHITE;
	mWhiteMtrl.diffuse   = WHITE;
	mWhiteMtrl.spec      = WHITE * 0.8f;
	mWhiteMtrl.specPower = 16.0f;

	D3DXMatrixIdentity(&mRoomWorld);
	D3DXMatrixTranslation(&mTeapotWorld, 0.0f, 3.0f, -6.0f);

	HR(D3DXCreateTextureFromFile(gd3dDevice, L"../src/chap13/StencilMirror/checkboard.dds", &mFloorTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, L"../src/chap13/StencilMirror/brick2.dds", &mWallTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, L"../src/chap13/StencilMirror/ice.dds", &mMirrorTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, L"../src/chap13/StencilMirror/brick1.dds", &mTeapotTex));
	
	HR(D3DXCreateTeapot(gd3dDevice, &mTeapot, 0));

	genSphericalTexCoords();

	mGfxStats->addVertices(24);
	mGfxStats->addTriangles(8);
	mGfxStats->addVertices(mTeapot->GetNumVertices()*2);
	mGfxStats->addTriangles(mTeapot->GetNumFaces()*2);

	buildRoomGeometry();
	buildFX();
	
	onResetDevice();
}
Beispiel #20
0
MultiTexDemo::MultiTexDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	mGfxStats = new GfxStats();

	mCameraRadius    = 6.0f;
	mCameraRotationY = 1.2 * D3DX_PI;
	mCameraHeight    = 3.0f;

	mLightVecW     = D3DXVECTOR3(0.0, 0.707f, -0.707f);
	mDiffuseMtrl   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mDiffuseLight  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mAmbientMtrl   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mAmbientLight  = D3DXCOLOR(0.6f, 0.6f, 0.6f, 1.0f);
	mSpecularMtrl  = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f);
	mSpecularLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mSpecularPower = 8.0f;

	D3DXMatrixIdentity(&mWorld);

	// Load textures from file.
	HR(D3DXCreateTextureFromFile(gd3dDevice, "grass0.dds", &mTex0));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "stone2.dds", &mTex1));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "ground0.dds", &mTex2));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "blendmap.jpg", &mBlendMap));
	
	buildGridGeometry();
	mGfxStats->addVertices(mNumGridVertices);
	mGfxStats->addTriangles(mNumGridTriangles);

	buildFX();

	onResetDevice();

	InitAllVertexDeclarations();
}
Beispiel #21
0
Game::Game(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	gMyGameWorld = new MyGameWorld();
	gMyGameWorld->Initialize();

	mFPS = 0.0f;
	mMilliSecPerFrame = 0.0f;

	D3DXFONT_DESC fontDesc;
	fontDesc.Height          = 18;
    fontDesc.Width           = 0;
    fontDesc.Weight          = 0;
    fontDesc.MipLevels       = 1;
    fontDesc.Italic          = false;
    fontDesc.CharSet         = DEFAULT_CHARSET;
    fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
    fontDesc.Quality         = DEFAULT_QUALITY;
    fontDesc.PitchAndFamily  = DEFAULT_PITCH | FF_DONTCARE;
    strcpy_s(fontDesc.FaceName, _T("Times New Roman"));

	HR(D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont));

	if(!SUCCEEDED(D3DXCreateSprite(gd3dDevice, &mSprite)))
	{
		MessageBox(0, "Sprite Creation Failed", "Uh Oh", MB_ICONEXCLAMATION);
	}

	buildFX();

	onResetDevice();

	InitAllVertexDeclarations();
}
Beispiel #22
0
TerrainDemo::TerrainDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();

	mCameraRadius    = 75.0f;
	mCameraRotationY = 1.3f * D3DX_PI;
	mCameraHeight    = 35.0f;

	mTerrain = new Terrain(257, 257, 0.5f, 0.5f, 
		"heightmap17_257.raw",  
		"grass.dds",
		"dirt.dds",
		"stone.dds",
		"blend_hm17.dds",
		0.2f, 0.0f);

	mTerrain->setDirToSunW(D3DXVECTOR3(0.0f, 1.0f, 0.0f));


	// Scale the mesh down.
	D3DXMatrixIdentity(&mWorld);

	mGfxStats->addVertices(mTerrain->getNumVertices());
	mGfxStats->addTriangles(mTerrain->getNumTriangles());

	onResetDevice();
}
AmbientDiffuseDemo::AmbientDiffuseDemo(HINSTANCE hInstance, std::wstring winCaption)
    : D3DApp(hInstance, winCaption)
{
    mGfxStats = new GfxStats();

    mCameraRadius    = 10.0f;
    mCameraRotationY = 1.2 * D3DX_PI;
    mCameraHeight    = 5.0f;

    mLightVecW    = D3DXVECTOR3(0.0f, 0.0f, -1.0f);
    mDiffuseMtrl  = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f);
    mDiffuseLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
    mAmbientMtrl  = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f);
    mAmbientLight = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f);

    D3DXMatrixIdentity(&mWorld);

    HR(D3DXCreateTeapot(gd3dDevice, &mTeapot, 0));
    buildFX();

    onResetDevice();

    InitAllVertexDeclarations();
}
Beispiel #24
0
WaterDemo::WaterDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
    : D3DApp(hInstance, winCaption, devType, requestedVP)
{
    if(!checkDeviceCaps())
    {
        MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
        PostQuitMessage(0);
    }

    InitAllVertexDeclarations();

    mLight.dirW = D3DXVECTOR3(0.0f, -2.0f, -1.0f);
    D3DXVec3Normalize(&mLight.dirW, &mLight.dirW);
    mLight.ambient = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f);
    mLight.diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
    mLight.spec    = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f);

    mGfxStats = new GfxStats();
    mSky = new Sky("grassenvmap1024.dds", 10000.0f);

    D3DXMATRIX waterWorld;
    D3DXMatrixTranslation(&waterWorld, 0.0f, 2.0f, 0.0f);

    Mtrl waterMtrl;
    waterMtrl.ambient   = D3DXCOLOR(0.26f, 0.23f, 0.3f, 0.90f);
    waterMtrl.diffuse   = D3DXCOLOR(0.26f, 0.23f, 0.3f, 0.90f);
    waterMtrl.spec      = 1.0f*WHITE;
    waterMtrl.specPower = 64.0f;

    Water::InitInfo waterInitInfo;
    waterInitInfo.dirLight = mLight;
    waterInitInfo.mtrl     = waterMtrl;
    waterInitInfo.vertRows         = 128;
    waterInitInfo.vertCols         = 128;
    waterInitInfo.dx               = 1.0f;
    waterInitInfo.dz               = 1.0f;
    waterInitInfo.waveMapFilename0 = "wave0.dds";
    waterInitInfo.waveMapFilename1 = "wave1.dds";
    waterInitInfo.waveMapVelocity0 = D3DXVECTOR2(0.05f, 0.08f);
    waterInitInfo.waveMapVelocity1 = D3DXVECTOR2(-0.02f, 0.1f);
    waterInitInfo.texScale = 16.0f;
    waterInitInfo.toWorld = waterWorld;

    mWater = new Water(waterInitInfo);
    mWater->setEnvMap(mSky->getEnvMap());

    ID3DXMesh* tempMesh = 0;
    LoadXFile("BasicColumnScene.x", &tempMesh, mSceneMtrls, mSceneTextures);

    // Get the vertex declaration for the NMapVertex.
    D3DVERTEXELEMENT9 elems[MAX_FVF_DECL_SIZE];
    UINT numElems = 0;
    HR(NMapVertex::Decl->GetDeclaration(elems, &numElems));

    // Clone the mesh to the NMapVertex format.
    ID3DXMesh* clonedTempMesh = 0;
    HR(tempMesh->CloneMesh(D3DXMESH_MANAGED, elems, gd3dDevice, &clonedTempMesh));

    // Now use D3DXComputeTangentFrameEx to build the TNB-basis for each vertex
    // in the mesh.

    HR(D3DXComputeTangentFrameEx(
           clonedTempMesh, // Input mesh
           D3DDECLUSAGE_TEXCOORD, 0, // Vertex element of input tex-coords.
           D3DDECLUSAGE_BINORMAL, 0, // Vertex element to output binormal.
           D3DDECLUSAGE_TANGENT, 0,  // Vertex element to output tangent.
           D3DDECLUSAGE_NORMAL, 0,   // Vertex element to output normal.
           0, // Options
           0, // Adjacency
           0.01f, 0.25f, 0.01f, // Thresholds for handling errors
           &mSceneMesh, // Output mesh
           0));         // Vertex Remapping

    // Done with temps.
    ReleaseCOM(tempMesh);
    ReleaseCOM(clonedTempMesh);

    D3DXMatrixIdentity(&mSceneWorld);
    D3DXMatrixIdentity(&mSceneWorldInv);

    HR(D3DXCreateTextureFromFile(gd3dDevice, "floor_nmap.bmp", &mSceneNormalMaps[0]));
    HR(D3DXCreateTextureFromFile(gd3dDevice, "bricks_nmap.bmp", &mSceneNormalMaps[1]));

    HR(D3DXCreateTextureFromFile(gd3dDevice, "whitetex.dds", &mWhiteTex));

    // Initialize camera.
    gCamera->pos().y = 7.0f;
    gCamera->pos().z = -30.0f;
    gCamera->setSpeed(10.0f);

    mGfxStats->addVertices(mSceneMesh->GetNumVertices());
    mGfxStats->addTriangles(mSceneMesh->GetNumFaces());

    mGfxStats->addVertices(mWater->getNumVertices());
    mGfxStats->addTriangles(mWater->getNumTriangles());

    mGfxStats->addVertices(mSky->getNumVertices());
    mGfxStats->addTriangles(mSky->getNumTriangles());


    buildFX();

    onResetDevice();
}
Beispiel #25
0
PropsDemo::PropsDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mTime = 0.0f;

	mGfxStats = new GfxStats();

	// Set path to art resources.
	SetCurrentDirectory("Art/");

	// World space units are meters.  
	mTerrain = new Terrain(257, 257, 2.0f, 2.0f, 
		"castlehm257.raw", "grass.dds",	"dirt.dds",	
		"rock.dds", "blend_castle.dds", 0.5f, 0.0f);

	D3DXVECTOR3 toSun(-1.0f, 3.0f, 1.0f);
	D3DXVec3Normalize(&toSun, &toSun);
	mTerrain->setDirToSunW(toSun);

	// Setup water.
	D3DXMATRIX waterWorld;
	D3DXMatrixTranslation(&waterWorld, 8.0f, 35.0f, -80.0f);
	mWater = new Water(33, 33, 20, 20, waterWorld);

	// Initialize camera.
	gCamera->pos() = D3DXVECTOR3(8.0f, 35.0f, -100.0f);
	gCamera->setSpeed(20.0f);
	mFreeCamera = false;

	buildCastle();
	buildTrees();
	buildGrass();

	HR(D3DXCreateTextureFromFile(gd3dDevice, "grassfin0.dds", &mGrassTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "whitetex.dds", &mWhiteTex));

	buildFX();

	mLight.dirW    = -toSun;
	D3DXVec3Normalize(&mLight.dirW, &mLight.dirW);
	mLight.ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mLight.diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mLight.spec    = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight)));
	HR(mGrassFX->SetValue(mhGrassDirToSunW, &(-mLight.dirW), sizeof(D3DXVECTOR3)));

	mGfxStats->addVertices(mTerrain->getNumVertices());
	mGfxStats->addTriangles(mTerrain->getNumTriangles());
	mGfxStats->addVertices(mWater->getNumVertices());
	mGfxStats->addTriangles(mWater->getNumTriangles());
	mGfxStats->addVertices(mCastle.mesh->GetNumVertices());
	mGfxStats->addTriangles(mCastle.mesh->GetNumFaces());
	mGfxStats->addVertices(mTrees[0].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[0].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mTrees[1].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[1].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mTrees[2].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[2].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mTrees[3].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[3].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mGrassMesh->GetNumVertices());
	mGfxStats->addTriangles(mGrassMesh->GetNumFaces());

	onResetDevice();
}
EngineMain::EngineMain(HINSTANCE hInstance, std::wstring winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{

	if(!checkDeviceCaps())
	{
		MessageBox(0, L"checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	
	Shaders::InitAll();
	InitAllVertexDeclarations();
	

	m_GfxStats = new GfxStats();

	m_DirLight.Direction	= D3DXVECTOR3(0.0f, 1.0f, 2.0f);
	D3DXVec3Normalize(&m_DirLight.Direction, &m_DirLight.Direction);
	m_DirLight.Ambient		= D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
	m_DirLight.Diffuse		= D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	m_DirLight.Specular		= D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);



	camera.SetPosition(D3DXVECTOR3(0.0f, 0.0f, -10.0f));
	camera.SetTarget(D3DXVECTOR3(0.0f, 3.0f, 0.0f));
	camera.SetRotation(D3DXVECTOR3(0.0f, 1.0f, 0.0f));

	

	dwarf =  new Model(L"dwarf.x");
	skull =	 new Model(L"skullocc.x");
	tiny  =  new Model(L"tiny.x");

	m_GfxStats->addVertices(skull->m_Model->GetNumVertices());
	m_GfxStats->addTriangles(skull->m_Model->GetNumFaces());
	m_GfxStats->addVertices(dwarf->m_Model->GetNumVertices());
	m_GfxStats->addTriangles(dwarf->m_Model->GetNumFaces());
	m_GfxStats->addVertices(tiny->m_Model->GetNumVertices());
	m_GfxStats->addTriangles(tiny->m_Model->GetNumFaces());

	skull->InitModel(D3DXVECTOR3(-4.0f, 3.0f, 100.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f), 0.0f);
	skull->Scale(0.5f);
	dwarf->InitModel(D3DXVECTOR3(0.0f, 3.0f, -10.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f), 0.0f);
	dwarf->Scale(1.0f);
	tiny->InitModel(D3DXVECTOR3(0.0f, 3.0f, -10.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f), 0.0f);
	tiny->Scale(0.01f);

#pragma region Grid
	mLightVecW     = D3DXVECTOR3(0.0, 0.707f, -0.707f);
	mDiffuseMtrl   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mDiffuseLight  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mAmbientMtrl   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mAmbientLight  = D3DXCOLOR(0.6f, 0.6f, 0.6f, 1.0f);
	mSpecularMtrl  = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f);
	mSpecularLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mSpecularPower = 8.0f;
	
	std::wstring groundTex = utf8ToUTF16(std::string("../Render/models/ground0.dds"));
	HR(D3DXCreateTextureFromFile(g_d3dDevice, groundTex.c_str(), &mGroundTex));

	buildFX();
	buildGridGeometry();

#pragma endregion

	onResetDevice();
}
Beispiel #27
0
LRESULT D3DApp::msgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
	// Is the application in a minimized or maximized state?
	static bool minOrMaxed = false;

	RECT clientRect = {0, 0, 0, 0};
	switch( msg )
	{

	// WM_ACTIVE is sent when the window is activated or deactivated.
	// We pause the game when the main window is deactivated and 
	// unpause it when it becomes active.
	case WM_ACTIVATE:
		if( LOWORD(wParam) == WA_INACTIVE )
			mAppPaused = true;
		else
			mAppPaused = false;
		return 0;


	// WM_SIZE is sent when the user resizes the window.  
	case WM_SIZE:
		if( gd3dDevice )
		{
			md3dPP.BackBufferWidth  = LOWORD(lParam);
			md3dPP.BackBufferHeight = HIWORD(lParam);

			if( wParam == SIZE_MINIMIZED )
			{
				mAppPaused = true;
				minOrMaxed = true;
			}
			else if( wParam == SIZE_MAXIMIZED )
			{
				mAppPaused = false;
				minOrMaxed = true;
				onLostDevice();
				HR(gd3dDevice->Reset(&md3dPP));
				onResetDevice();
			}
			// Restored is any resize that is not a minimize or maximize.
			// For example, restoring the window to its default size
			// after a minimize or maximize, or from dragging the resize
			// bars.
			else if( wParam == SIZE_RESTORED )
			{
				mAppPaused = false;

				// Are we restoring from a mimimized or maximized state, 
				// and are in windowed mode?  Do not execute this code if 
				// we are restoring to full screen mode.
				if( minOrMaxed && md3dPP.Windowed )
				{
					onLostDevice();
					HR(gd3dDevice->Reset(&md3dPP));
					onResetDevice();
				}
				else
				{
					// No, which implies the user is resizing by dragging
					// the resize bars.  However, we do not reset the device
					// here because as the user continuously drags the resize
					// bars, a stream of WM_SIZE messages is sent to the window,
					// and it would be pointless (and slow) to reset for each
					// WM_SIZE message received from dragging the resize bars.
					// So instead, we reset after the user is done resizing the
					// window and releases the resize bars, which sends a
					// WM_EXITSIZEMOVE message.
				}
				minOrMaxed = false;
			}
		}
		return 0;


	// WM_EXITSIZEMOVE is sent when the user releases the resize bars.
	// Here we reset everything based on the new window dimensions.
	case WM_EXITSIZEMOVE:
		GetClientRect(mhMainWnd, &clientRect);
		md3dPP.BackBufferWidth  = clientRect.right;
		md3dPP.BackBufferHeight = clientRect.bottom;
		onLostDevice();
		HR(gd3dDevice->Reset(&md3dPP));
		onResetDevice();

		return 0;

	// WM_CLOSE is sent when the user presses the 'X' button in the
	// caption bar menu.
	case WM_CLOSE:
		DestroyWindow(mhMainWnd);
		return 0;

	// WM_DESTROY is sent when the window is being destroyed.
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;

	case WM_KEYDOWN:
		EventKeyPress(wParam, lParam);
		return 0;

	case WM_MOUSEMOVE:
		EventMouseMove(wParam, lParam);
		return 0;
	
	case WM_MOUSEWHEEL:
		EventMouseWheel(wParam, lParam);
		return 0;

	case WM_RBUTTONUP:
		EventRightButton(wParam, lParam, false);
		return 0;

	case WM_RBUTTONDOWN:
		EventRightButton(wParam, lParam, true);
		return 0;

	//case WM_KEYDOWN:
	//	return 0;
	}
	return DefWindowProc(mhMainWnd, msg, wParam, lParam);
}
Beispiel #28
0
Evolution::Evolution(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD reqVertPrcs)
    : D3DApp(hInstance, winCaption, devType, reqVertPrcs)
{
    if(!checkDeviceCaps())
    {
        MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
        PostQuitMessage(0);
    }

    if ( D3DXCreateTextureFromFile(gd3dDevice, "Lifeform.bmp", &mLifeformTex) )
    {
        MessageBox(0, "Lifeform.bmp not found! D:", 0, 0);
        PostQuitMessage(0);
    }
    if ( D3DXCreateTextureFromFile(gd3dDevice, "CarnParts.bmp", &mCarnTex) )
    {
        MessageBox(0, "CarnParts.bmp not found! D:", 0, 0);
        PostQuitMessage(0);
    }
    if ( D3DXCreateTextureFromFile(gd3dDevice, "SightParts.bmp", &mSightTex) )
    {
        MessageBox(0, "SightParts.bmp not found! D:", 0, 0);
        PostQuitMessage(0);
    }
    if ( D3DXCreateTextureFromFile(gd3dDevice, "Food.bmp", &mFoodTex) )
    {
        MessageBox(0, "Food.bmp not found! D:", 0, 0);
        PostQuitMessage(0);
    }
    if ( D3DXCreateTextureFromFile(gd3dDevice, "Egg.bmp", &mEggTex) )
    {
        MessageBox(0, "Egg.bmp not found! D:", 0, 0);
        PostQuitMessage(0);
    }


    D3DXFONT_DESC fontDesc;
    fontDesc.Height				= 18;
    fontDesc.Width				= 0;
    fontDesc.Weight				= FW_SEMIBOLD;
    fontDesc.MipLevels			= 1;
    fontDesc.Italic				= false;
    fontDesc.CharSet			= DEFAULT_CHARSET;
    fontDesc.OutputPrecision	= OUT_DEFAULT_PRECIS;
    fontDesc.Quality			= DEFAULT_QUALITY;
    fontDesc.PitchAndFamily		= DEFAULT_PITCH | FF_DONTCARE;
    _tcscpy(fontDesc.FaceName, _T("Times New Roman"));

    HR(D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont));

    mGfxStats = new GfxStats();

    mCameraPos = D3DXVECTOR3(0.0f, 0.0f, -800.0f);

    mTimeSpeed = 1.0f;
    mTrueTime = 0.0f;
    mCoolTime = 0.0f;

    mbFollow = false;
    mFollowNumber = 0.0f;
    mFollowPos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);

    mbLStart = true;
    mbEFStart = true;

    mbDrawInfo = false;

    buildBuffers();
    buildFX();

    onResetDevice();

    InitAllVertexDeclarations();
}
Beispiel #29
0
RobotArmDemo::RobotArmDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();
	
	// Initialize Camera Settings
	mCameraRadius    = 9.0f;
	mCameraRotationY = 1.5f * D3DX_PI;
	mCameraHeight    = 0.0f;

	// Setup a directional light.
	mLight.dirW    = D3DXVECTOR3(0.0f, 1.0f, 2.0f);
	D3DXVec3Normalize(&mLight.dirW, &mLight.dirW);
	mLight.ambient = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	mLight.diffuse = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	mLight.spec    = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);

	// Load the bone .X file mesh.
	LoadXFile("bone.x", &mBoneMesh, mMtrl, mTex);
	D3DXMatrixIdentity(&mWorld);

	// Create the white dummy texture.
	HR(D3DXCreateTextureFromFile(gd3dDevice, "whitetex.dds", &mWhiteTex));

	// Initialize the bones relative to their parent frame.
	// The root is special--its parent frame is the world space.
	// As such, its position and angle are ignored--its 
	// toWorldXForm should be set explicitly (that is, the world
	// transform of the entire skeleton).
	//
	// *------*------*------*------
	//    0      1      2      3

	for(int i = 1; i < NUM_BONES; ++i) // Ignore root.
	{
		// Describe each bone frame relative to its parent frame.
		mBones[i].pos    = D3DXVECTOR3(2.0f, 0.0f, 0.0f);
		mBones[i].zAngle = 0.0f;
	}
	// Root frame at center of world.
	mBones[0].pos    = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	mBones[0].zAngle = 0.0f;


	// Start off with the last (leaf) bone:
	mBoneSelected = NUM_BONES-1;

	mGfxStats->addVertices(mBoneMesh->GetNumVertices() * NUM_BONES);
	mGfxStats->addTriangles(mBoneMesh->GetNumFaces() * NUM_BONES);

	buildFX();

	onResetDevice();
}
Beispiel #30
0
SolarSysDemo::SolarSysDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();
	
	// Initialize Camera Settings
	mCameraRadius    = 25.0f;
	mCameraRotationY = 1.2f * D3DX_PI;
	mCameraHeight    = 10.0f;

	// Setup a directional light.
	mLight.dirW    = D3DXVECTOR3(0.0f, 1.0f, 2.0f);
	D3DXVec3Normalize(&mLight.dirW, &mLight.dirW);
	mLight.ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mLight.diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mLight.spec    = D3DXCOLOR(0.6f, 0.6f, 0.6f, 1.0f);

	// Create a sphere to represent a solar object.
	HR(D3DXCreateSphere(gd3dDevice, 1.0f, 30, 30, &mSphere, 0));
	genSphericalTexCoords();
	D3DXMatrixIdentity(&mWorld);

	// Create the textures.
	HR(D3DXCreateTextureFromFile(gd3dDevice, "sun.dds", &mSunTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "planet1.dds", &mPlanet1Tex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "planet2.dds", &mPlanet2Tex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "planet3.dds", &mPlanet3Tex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "moon.dds", &mMoonTex));

	// Initialize default white material.
	mWhiteMtrl.ambient = WHITE;
	mWhiteMtrl.diffuse = WHITE;
	mWhiteMtrl.spec    = WHITE * 0.5f;
	mWhiteMtrl.specPower = 48.0f;

	//==================================================
	// Specify how the solar object frames are related.

	D3DXVECTOR3 pos[NUM_OBJECTS] = 
	{
		D3DXVECTOR3(0.0f, 0.0f, 0.0f),
		D3DXVECTOR3(7.0f, 0.0f, 7.0f),
		D3DXVECTOR3(-9.0f, 0.0f, 0.0f),
		D3DXVECTOR3(7.0f, 0.0f, -6.0f),
		D3DXVECTOR3(5.0f, 0.0f, 0.0f),
		D3DXVECTOR3(-5.0f, 0.0f, 0.0f),
		D3DXVECTOR3(3.0f, 0.0f, 0.0f),
		D3DXVECTOR3(2.0f, 0.0f, -2.0f),
		D3DXVECTOR3(-2.0f, 0.0f, 0.0f),
		D3DXVECTOR3(0.0f, 0.0f, 2.0f)
	};

	mObject[0].set(SUN, pos[0], 0.0f, -1, 2.5f, mSunTex);  // Sun
	mObject[1].set(PLANET, pos[1], 0.0f, 0, 1.5f, mPlanet1Tex);// P1
	mObject[2].set(PLANET, pos[2], 0.0f, 0, 1.2f, mPlanet2Tex);// P2
	mObject[3].set(PLANET, pos[3], 0.0f, 0, 0.8f, mPlanet3Tex);// P3

	mObject[4].set(MOON, pos[4], 0.0f, 1, 0.5f, mMoonTex); // M1P1
	mObject[5].set(MOON, pos[5], 0.0f, 1, 0.5f, mMoonTex); // M2P1
	mObject[6].set(MOON, pos[6], 0.0f, 2, 0.4f, mMoonTex); // M1P2
	mObject[7].set(MOON, pos[7], 0.0f, 3, 0.3f, mMoonTex); // M1P3
	mObject[8].set(MOON, pos[8], 0.0f, 3, 0.3f, mMoonTex); // M2P3
	mObject[9].set(MOON, pos[9], 0.0f, 3, 0.3f, mMoonTex); // M3P3


	//==================================================
 
	mGfxStats->addVertices(mSphere->GetNumVertices() * NUM_OBJECTS);
	mGfxStats->addTriangles(mSphere->GetNumFaces() * NUM_OBJECTS);

	buildFX();

	onResetDevice();
}