Exemple #1
0
void CubeMapApp::drawScene()
{
	D3DApp::drawScene();
	
	
	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);
	
	md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dDevice->IASetInputLayout(InputLayout::PosNormalTex);

	// Set per frame constants.
	mfxEyePosVar->SetRawValue(&GetCamera().position(), 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mParallelLight, 0, sizeof(Light));
	
	mfxCubeMapVar->SetResource(mEnvMapRV);
	

	D3DXMATRIX view = GetCamera().view();
	D3DXMATRIX proj = GetCamera().proj();

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );

    for(UINT i = 0; i < techDesc.Passes; ++i)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex(i);

		//
		// draw center ball
		//
		D3DXMATRIX centerBallWVP = mCenterBallWorld*view*proj;
		mfxWVPVar->SetMatrix((float*)&centerBallWVP);
		mfxWorldVar->SetMatrix((float*)&mCenterBallWorld);
		mfxTexMtxVar->SetMatrix((float*)&mIdentityTexMtx);
		mfxDiffuseMapVar->SetResource(mBallMapRV);
		mfxSpecMapVar->SetResource(mDefaultSpecMapRV);
		mfxCubeMapEnabledVar->SetBool(true);
		mfxReflectMtrlVar->SetFloatVector((float*)&mReflectAll);
		pass->Apply(0);
		mBall.draw();		
    }

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	md3dDevice->RSSetState(0);
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, WHITE);

	mSwapChain->Present(0, 0);
}
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();

	//Step through animation frame
	animationTimeElapsed += mTimer.getGameTime() - animationTimePrev;
	animationTimePrev = mTimer.getGameTime();
	if(animationTimeElapsed > 0.0666f)
	{
		animationTimeElapsed = 0.0f;
		frameOfAnimation++;
		if(frameOfAnimation > fireFrameCount-1)
		{
			frameOfAnimation = 0;
		}
	}

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Set per frame constants
	mfxEyePosVar->SetRawValue(&mCameraPos, 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mLights[0], 0, sizeof(Light));
	mfxLightVar2->SetRawValue(&mLights[1], 0, sizeof(Light));

	mfxCubeMapVR->SetResource(mCubeMapRV);
   
	// set constants
	mWVP = mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP); //set gWVP in color.fx to mWVP

	mTree.setEyePos(mCameraPos);
	mTree.setLights(mLights, 2);
	mTree.draw(mView, mProj);
	mObjBox.setEyePos(mCameraPos);
	mObjBox.setLights(mLights, 2);
	mObjBox.draw(mView, mProj);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex( p ); //zero is always used in D3D10
		D3DXMATRIX texMtx;
        
		mWVP = mBoxWorld*mView*mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&mBoxWorld);
		mfxDiffuseMapVar->SetResource(mCrateMapRV);
		//mfxDiffuseMapVar->SetResource(mFireAnimationMapRVs[frameOfAnimation]);
		mfxSpecularMapVar->SetResource(mSpecularMapRV);
		mfxNormalMapVR->SetResource(mDefaultNormalMapRV);
		mfxReflectEnabledVar->SetBool(false);
		D3DXMatrixIdentity(&texMtx);
		mfxTexMtxVar->SetMatrix((float*)&texMtx);
		pass->Apply(0);
		mBox.draw();

		mWVP = mPlaneWorld*mView*mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&mPlaneWorld);
		mfxDiffuseMapVar->SetResource(mGrassMapRV);
		mfxNormalMapVR->SetResource(mBrickNormalMapRV);
		mfxReflectEnabledVar->SetBool(true);
		D3DXMATRIX s;
		D3DXMatrixScaling(&s, 5.0f, 5.0f, 1.0f);
		texMtx = s;
		D3DXMatrixIdentity(&texMtx);
		mfxTexMtxVar->SetMatrix((float*)&texMtx);
		pass->Apply(0);
		mPlane.draw();
    }

	mSky.draw(mWVP);

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	md3dDevice->RSSetState(0);
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);

	mSwapChain->Present(0, 0);
}