コード例 #1
0
void WaterLandscapeDemoScene::OnRender(DXRenderer& dx, TimeT currentTime, TimeT deltaTime) const
{
    // Set the device up for rendering our landscape mesh.
    dx.GetDevice()->IASetInputLayout(mVertexLayout.Get());
    dx.GetDevice()->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    D3DXMATRIX projectionMatrix = mCamera->GetProjectionMatrix();
    
    // Load the landscape technique.
    ID3D10EffectTechnique * pTechnique = mLandscapeEffect->GetTechniqueByName("LandscapeTechnique");

    // Grab the shader variables we'll need.
    ID3D10EffectMatrixVariable * pWVP = mLandscapeEffect->GetVariableByName("gWVP")->AsMatrix();
    ID3D10EffectMatrixVariable * pWorldVar = mLandscapeEffect->GetVariableByName("gWorld")->AsMatrix();
    ID3D10EffectVariable * pFxEyePosVar = mLandscapeEffect->GetVariableByName("gEyePosW");
    ID3D10EffectVariable * pFxLightVar = mLandscapeEffect->GetVariableByName("gLight");
    ID3D10EffectScalarVariable * pFxLightType = mLandscapeEffect->GetVariableByName("gLightType")->AsScalar();

    // Set per frame constants
    D3DXVECTOR3 eyePos = mCamera->Position();
    D3DMATRIX view = mCamera->GetViewMatrix();
    Light selectedLight = mLights[mLightType];

    pFxEyePosVar->SetRawValue(&eyePos, 0, sizeof(D3DXVECTOR3));
    pFxLightVar->SetRawValue(&selectedLight, 0, sizeof(Light));
    pFxLightType->SetInt(mLightType);

    // Load the effect technique for cube
    D3D10_TECHNIQUE_DESC technique;
    pTechnique->GetDesc(&technique);

    // Apply the landscape technique.
    D3DXMATRIX landTransform;
    D3DXMATRIX waterTransform;

    D3DXMatrixIdentity(&landTransform);
    D3DXMatrixIdentity(&waterTransform);

    for (unsigned int passIndex = 0; passIndex < technique.Passes; ++passIndex)
    {
        ID3D10EffectPass * pPass = pTechnique->GetPassByIndex(passIndex);
        dx.SetDefaultRendering();

        // Draw the landscape mesh first
        D3DXMATRIX wvp = landTransform * view * projectionMatrix;

        pWVP->SetMatrix((float*)&wvp);
        pWorldVar->SetMatrix((float*)&landTransform);

        pPass->Apply(0);
        mTerrainMesh->Draw(dx.GetDevice());

        // Draw the water mesh
        wvp = waterTransform * view * projectionMatrix;

        pWVP->SetMatrix((float*)&wvp);
        pWorldVar->SetMatrix((float*)&waterTransform);

        pPass->Apply(0);
        mWaterMesh->Draw(dx.GetDevice());
    }
}
コード例 #2
0
void ColoredCubeApp::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 blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
	
	D3DXVECTOR3 pos(0.0f,45.0f,-50.0f);
	// set lighting shader variables
	mfxEyePosVar->SetRawValue(&pos, 0, sizeof(Vector3));
	mfxLightVar->SetRawValue(&lights[0], 0, sizeof(Light));
	mfxLightType->SetInt(lightType);

	// set some variables for the shader
	// set the point to the shader technique
	D3D10_TECHNIQUE_DESC techDesc;
	mTech->GetDesc(&techDesc);


	//setting the color flip variable in the shader

	//draw the floor
	floor.draw(mView, mProj, mfxWVPVar, mfxWorldVar, mTech);

	////// New Stuff added by Steve //////
	mWVP = player.getWorldMatrix()  *mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	mfxWorldVar->SetMatrix((float*)&player.getWorldMatrix());
	player.setMTech(mTech);
	player.draw();

	for (int i = 0; i < numberOfObstacles; i++) {
		mWVP = obstacles[i].getWorldMatrix() * mView * mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&obstacles[i].getWorldMatrix());
		obstacles[i].setMTech(mTech);
		obstacles[i].draw();
	}

	//Spectrum HUD
	for(int i = 0; i < 6; i++) {
		D3DXMATRIX a;
		D3DXMatrixRotationY(&a, 1.573f);
		mWVP = a * spectrum[i].getWorldMatrix() * mView * mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&spectrum[i].getWorldMatrix());
		spectrum[i].setMTech(mTech);
		spectrum[i].draw();
	}
	mWVP = cursor.getWorldMatrix() * mView * mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	mfxWorldVar->SetMatrix((float*)&cursor.getWorldMatrix());
	cursor.setMTech(mTech);
	cursor.draw();


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

	/////Text Drawing Section
	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	RECT R1 = {0, 0, 800, 600};
	RECT R2 = {0, 540, 800, 600};

	std::wostringstream outs;  
	
	outs.precision(6);
	string Hud = score.getString();

	/*outs << score.getString() << L"\n";
	outs << L"Blobs Available: " << ammo << L"\n";
	outs << L"Gallons Left: " << lives;
	std::wstring text = outs.str();
	mFont->DrawText(0, text.c_str(), -1, &R, DT_NOCLIP, BLACK);*/
	timesNew.draw(Hud, Vector2(5, 5));
	if (gameOver)
	{
		mFont->DrawText(0, L"Game Over!", -1, &R1, DT_CENTER | DT_VCENTER, BLACK);
	}
	float gameTime = mTimer.getGameTime();
	if (gameTime < 3.0f)
	{
		mFont->DrawText(0, L"Move your Box LEFT and RIGHT with A & D to avoid hitting the obstacles", -1, &R2, DT_CENTER | DT_VCENTER, BLACK);
	}
	else if (gameTime < 6.0f)
	{
		mFont->DrawText(0, L"Change the color of your Box by pressing the J and L keys.", -1, &R2, DT_CENTER | DT_VCENTER, BLACK);
	}
	else if (gameTime < 9.0f)
	{
		mFont->DrawText(0, L"The closer the color of your cube is to the floor, the higher the score multiplier!", -1, &R2, DT_CENTER | DT_VCENTER, BLACK);
	}
	if (activeMessage)
	{
		mFont->DrawText(0, message.c_str(), -1, &R2, DT_CENTER | DT_VCENTER, BLACK);
	}
	

	mSwapChain->Present(0, 0);
}
コード例 #3
0
void ColoredCubeApp::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 blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);

	mfxEyePosVar->SetRawValue(&player.getPosition(), 0, sizeof(D3DXVECTOR3));

	//set the number of lights to use
	mfxNumLights->SetInt(numLights);

	// set the light array
	lights[0] = flashLightObject.lightSource;
	//lights[2] = lightObject1.getLight();
	if(gamestate == level2)
	{
		for(int i = 0; i < ghosts.getNumEnemies(); i++)
		{
			lights[2+i] = ghosts.getEnemies()[i].getLight();
		}
	}
	for(int i = 0; i < numLightObjects; i++)
	{
		lights[2+ghosts.getNumEnemies()+i] = lamps[i].getLight();
	}
	lights[numLights-1] = endLight;

	mfxLightVar->SetRawValue(&lights[0], 0, numLights*sizeof(Light));
 
	// Don't transform texture coordinates, so just use identity transformation.
	D3DXMATRIX texMtx;
	D3DXMatrixIdentity(&texMtx);
	mfxTexMtxVar->SetMatrix((float*)&texMtx);

	// set the point to the shader technique
	D3D10_TECHNIQUE_DESC techDesc;
	mTech->GetDesc(&techDesc);

	//draw the maze
	maze.draw(mTech,mView,mProj);
	
	//draw the keys
	if(gamestate == level1)
	{
		for(int i = 0; i < totalKeys; i++)
		{
			keyObject[i].draw(mView,mProj,mTech);
		}
	}

	//draw the end cube
	endCube.draw(mView,mProj,mTech);

	//draw the origin
	origin.draw(mView, mProj, mTech);
	
	for(int i = 0; i < numLightObjects; i++)
	{
		lamps[i].draw(mView,mProj,mTech);
	}

	for(int i = 0; i < numBatteries; i++)
	{
		batteries[i].draw(mView,mProj,mTechColor2);
	}

	//flashLightObject.draw(mView,mProj,mTechColor2);
	//flashLightObject.hitBox.draw(mView,mProj,mTechColor2);
	
	//batteryObject.draw(mView,mProj,mTechColor2);
	//player.draw(mView,mProj,mTechColor2);
	ghosts.draw(mView,mProj,mTech);

	/*floor.draw(mView, mProj, mTech);
	wall1.draw(mView, mProj, mTech);
	wall2.draw(mView, mProj, mTech);
	wall3.draw(mView, mProj, mTech);
	wall4.draw(mView, mProj, mTech);*/
	//lightObject1.draw(mView,mProj,mTech);

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