Ejemplo n.º 1
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();
}
Ejemplo n.º 2
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();
}
Ejemplo n.º 3
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();
}
Ejemplo n.º 4
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();
}