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*)¢erBallWVP); 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(); // 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_LINELIST); // set constants mWVP = mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); D3D10_TECHNIQUE_DESC techDesc; mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex( p )->Apply(0); //mBox.draw(); mLine1.draw(); mLine2.draw(); mLine3.draw(); } // We specify DT_NOCLIP, so we do not care about width/height of the rect. RECT R = {5, 5, 0, 0}; mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK); mSwapChain->Present(0, 0); }
void CrateApp::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); md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // set constants mfxEyePosVar->SetRawValue(&mEyePos, 0, sizeof(D3DXVECTOR3)); mfxLightVar->SetRawValue(&mParallelLight, 0, sizeof(Light)); mWVP = mCrateWorld*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); mfxWorldVar->SetMatrix((float*)&mCrateWorld); mfxDiffuseMapVar->SetResource(mDiffuseMapRV); mfxSpecMapVar->SetResource(mSpecMapRV); // Don't transform texture coordinates, so just use identity transformation. D3DXMATRIX texMtx; D3DXMatrixIdentity(&texMtx); mfxTexMtxVar->SetMatrix((float*)&texMtx); D3D10_TECHNIQUE_DESC techDesc; mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex( p )->Apply(0); mCrateMesh.draw(); } // We specify DT_NOCLIP, so we do not care about width/height of the rect. RECT R = {5, 5, 0, 0}; mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK); mSwapChain->Present(0, 0); }
void RenderFrameDX10(void) { Vector4 vClearColor(0.0f, 0.0f, 0.0f, 0.0f); // 取得主畫面 ID3D10RenderTargetView *pRenderTargetView = GutGetDX10RenderTargetView(); ID3D10DepthStencilView *pDepthStencilView = GutGetDX10DepthStencilView(); g_pDevice->ClearRenderTargetView(pRenderTargetView, (float *)&vClearColor); g_pDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0); g_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP); ID3D10EffectTechnique *g_pShader = NULL; switch(g_iMode) { default: case 1: g_pShader = g_pDrawCurveFX->GetTechniqueByName("SinCurve"); break; case 2: { g_pShader = g_pDrawCurveFX->GetTechniqueByName("ZCurve"); Vector4 vNearFar(1.0f, 100.0f, 0.0f, 0.0f); Matrix4x4 proj_matrix = GutMatrixPerspectiveRH_DirectX(45.0f, 1.0f, vNearFar[0], vNearFar[1]); //Matrix4x4 proj_matrix = GutMatrixOrthoRH_DirectX(10.0f, 10.0f, vNearFar[0], vNearFar[1]); //Matrix4x4 proj_matrix = GutMatrixOrthoRH_OpenGL(10.0f, 10.0f, vNearFar[0], vNearFar[1]); //Matrix4x4 proj_matrix = GutMatrixPerspectiveRH_OpenGL(45.0f, 1.0f, vNearFar[0], vNearFar[1]); ID3D10EffectMatrixVariable *pMatrix = g_pDrawCurveFX->GetVariableByName("proj_matrix")->AsMatrix(); ID3D10EffectVectorVariable *pNearFarPlane = g_pDrawCurveFX->GetVariableByName("NearFarPlane")->AsVector(); pMatrix->SetMatrix(&proj_matrix[0][0]); pNearFarPlane->SetFloatVector(&vNearFar[0]); break; } } g_pShader->GetPassByIndex(0)->Apply(0); g_pDevice->Draw(2, 0); IDXGISwapChain *pSwapChain = GutGetDX10SwapChain(); pSwapChain->Present(1, 0); }
void ColoredTriangleApp::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->RSSetState(pRasterizer); md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff); md3dDevice->IASetInputLayout(mVertexLayout); md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // set constants mWVP = mView*mProj; D3D10_TECHNIQUE_DESC techDesc; mTech->GetDesc( &techDesc ); obj1.theta += D3DXVECTOR3(0,0.001f,0); obj1.setTrans(mWVP); mfxWVPVar->SetMatrix((float*)&obj1.objMatrix); DrawTriangle(techDesc); /*D3DXMatrixTranslation(&obj2.worldMatrix,obj2.pos.x,obj2.pos.y,obj2.pos.z); D3DXMatrixRotationY(&obj2.worldMatrix,rotAngle); rotAngle+= 0.001f; obj2.worldMatrix = obj2.worldMatrix*mWVP; mfxWVPVar->SetMatrix((float*)&obj2.worldMatrix); DrawTriangle(techDesc);*/ // 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); }
//render frame void DX10Renderer::RenderFrame() { //rotate light - shouldnt do this each frame but i'm lazy //*************************************************************************** //rotate light position /*XMFLOAT3 yaxis(0,1,0), o(0,0,0), u(0,1,0); XMMATRIX rotMatrix = XMMatrixRotationAxis( XMLoadFloat3(&yaxis), 0.01f); //new rotated light pos XMVECTOR olpos = XMLoadFloat3(&lightPos); XMVECTOR lpos = XMVector3TransformCoord( olpos , rotMatrix); XMStoreFloat3(&lightPos, lpos); //get new view matrix XMVECTOR fp = XMLoadFloat3( &o ), up = XMLoadFloat3( &u ); XMMATRIX vmat = XMMatrixLookAtLH( lpos, fp, up ); //create new light view proj matrix XMMATRIX lpmat = XMLoadFloat4x4(&lightProjMatrix); XMMATRIX lvpmat = XMMatrixMultiply(vmat, lpmat); XMStoreFloat4x4(&lightViewProjMatrix, lvpmat);*/ //set per frame variables //*************************************************************************** //effect vars ID3D10EffectMatrixVariable* pWorldMatrix = pEffect->GetVariableByName("world")->AsMatrix(); ID3D10EffectMatrixVariable* pViewProjMatrix = pEffect->GetVariableByName("viewProj")->AsMatrix(); ID3D10EffectMatrixVariable* pLightViewProjMatrix = pEffect->GetVariableByName("lightViewProj")->AsMatrix(); ID3D10EffectVectorVariable* pLightPos = pEffect->GetVariableByName("lightPos")->AsVector(); pLightPos->SetFloatVectorArray( (float*) &lightPos, 0, 3); pViewProjMatrix->SetMatrix( (float*) &camera.GetViewProjectionMatrix() ); pLightViewProjMatrix->SetMatrix( (float*) &lightViewProjMatrix ); //set topology to triangle list pD3DDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //create shadow map //*************************************************************************** //set render targets and viewport pD3DDevice->OMSetRenderTargets(0, 0, pShadowMapDepthView); pD3DDevice->RSSetViewports(1, &shadowMapViewport); pD3DDevice->ClearDepthStencilView( pShadowMapDepthView, D3D10_CLEAR_DEPTH, 1.0f, 0 ); //render scene int currMeshID = -1; for (unsigned int i=0; i < scene.size(); i++) { //set appropriate vertex buffers if ( currMeshID != scene[i].modelID ) { currMeshID = scene[i].modelID; pD3DDevice->IASetVertexBuffers( 0,1, &meshes[currMeshID].pVertexBuffer, &meshes[currMeshID].stride, &meshes[currMeshID].offset ); pD3DDevice->IASetIndexBuffer( meshes[currMeshID].pIndexBuffer, DXGI_FORMAT_R32_UINT, 0); } //set instance data and draw pWorldMatrix->SetMatrix((float*) &scene[i].world); pRenderShadowMapTechnique->GetPassByIndex(0)->Apply( 0 ); pD3DDevice->DrawIndexed(meshes[scene[i].modelID].numIndices, 0, 0); } //render final scene //*************************************************************************** //set render targets and viewports pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, pDepthStencilView); pD3DDevice->RSSetViewports(1, &viewport); pD3DDevice->ClearRenderTargetView( pRenderTargetView, D3DXCOLOR(0.6f,0.6f,0.6f,0) ); pD3DDevice->ClearDepthStencilView( pDepthStencilView, D3D10_CLEAR_DEPTH, 1.0f, 0 ); //bind shadow map texture and set shadow map bias pEffect->GetVariableByName("shadowMap")->AsShaderResource()->SetResource( pShadowMapSRView ); pEffect->GetVariableByName("shadowMapBias")->AsScalar()->SetFloat(shadowMapBias); int smSize[2] = { shadowMapViewport.Width, shadowMapViewport.Height }; pEffect->GetVariableByName("shadowMapSize")->AsVector()->SetIntVector(smSize); //render scene currMeshID = -1; for (unsigned int i=0; i < scene.size(); i++) { //set appropriate vertex buffers if ( currMeshID != scene[i].modelID ) { currMeshID = scene[i].modelID; pD3DDevice->IASetVertexBuffers( 0,1, &meshes[currMeshID].pVertexBuffer, &meshes[currMeshID].stride, &meshes[currMeshID].offset ); pD3DDevice->IASetIndexBuffer( meshes[currMeshID].pIndexBuffer, DXGI_FORMAT_R32_UINT, 0); } //set instance data and draw pWorldMatrix->SetMatrix((float*) &scene[i].world); pRenderTechnique->GetPassByIndex(0)->Apply( 0 ); pD3DDevice->DrawIndexed(meshes[scene[i].modelID].numIndices, 0, 0); } //render shadow map billboard //*************************************************************************** pD3DDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST); pBillboardTechnique->GetPassByIndex(0)->Apply( 0 ); pD3DDevice->DrawIndexed(1, 0, 0); //unbind shadow map as SRV pEffect->GetVariableByName("shadowMap")->AsShaderResource()->SetResource( 0 ); pBillboardTechnique->GetPassByIndex(0)->Apply( 0 ); //swap buffers pSwapChain->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); }
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); // set some variables for the shader int foo[1]; foo[0] = 0; // set the point to the shader technique D3D10_TECHNIQUE_DESC techDesc; mTech->GetDesc(&techDesc); //setting the color flip variable in the shader mfxFLIPVar->SetRawValue(&foo[0], 0, sizeof(int)); //draw the lines mWVP = xLine.getWorldMatrix()*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); xLine.setMTech(mTech); xLine.draw(); mWVP = yLine.getWorldMatrix() *mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); yLine.setMTech(mTech); yLine.draw(); mWVP = zLine.getWorldMatrix() *mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); zLine.setMTech(mTech); zLine.draw(); //draw the quad using the "old" method //compare how messy this is compared to the objectified geometry classes mWVP = quad1.getWorld()*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex( p )->Apply(0); quad1.draw(); } mWVP = quad2.getWorld()*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex( p )->Apply(0); quad2.draw(); } mWVP = quad3.getWorld()*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex( p )->Apply(0); quad3.draw(); } mWVP = quad4.getWorld()*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex( p )->Apply(0); quad4.draw(); } mWVP = quad5.getWorld()*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex( p )->Apply(0); quad5.draw(); } for(int i = 0; i < WALL_SIZE; ++i) { mWVP = wall[i].getWorld()*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex( p )->Apply(0); wall[i].draw(); } } // We specify DT_NOCLIP, so we do not care about width/height of the rect. RECT R = {5, 5, 0, 0}; mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK); mSwapChain->Present(0, 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); }
void ColoredCubeApp::drawScene() { int foo[1] = {0}; switch (gsm->getGameState()) { case GameStateManager::START_GAME: { foo[0] = 1; break; } case GameStateManager::IN_GAME: { foo[0] = 0; break; } case GameStateManager::END_GAME: { foo[0] = 1; break; } default: foo[0] = 0; break; } mfxBlack_WhiteVar->SetRawValue(&foo[0], 0, sizeof(int)); 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); md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //Get Camera viewMatrix mView = camera.getViewMatrix(); mProj = camera.getProjectionMatrix(); // set constants mWVP = mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); D3D10_TECHNIQUE_DESC techDesc; mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex( p )->Apply(0); //mBox.draw(); //mAxes.draw(); //mLine.draw(); //mTriangle.draw(); mQuad.draw(); //particleBox.draw(); } mWVP = gameObject1.getWorldMatrix() *mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); gameObject1.setMTech(mTech); gameObject1.draw(); for (int i = 0; i < MAX_NUM_ENEMIES; i++) { mWVP = enemyObjects[i].getWorldMatrix() *mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); enemyObjects[i].setMTech(mTech); enemyObjects[i].draw(); } for (int i = 0; i < MAX_NUM_BULLETS; i++) { mWVP = playerBullets[i].getWorldMatrix() *mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); playerBullets[i].setMTech(mTech); playerBullets[i].draw(); } for (int i = 0; i < MAX_NUM_EXP_PARTICLES; i++) { mWVP = particles[i].getWorldMatrix() *mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); particles[i].setMTech(mTech); particles[i].draw(); } for (int i = 0; i < MAX_NUM_STARS; i++) { mWVP = stars[i].getWorldMatrix() *mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); stars[i].setMTech(mTech); stars[i].draw(); } if(gsm->getGameState() == GameStateManager::END_GAME && score > 0) { std::wostringstream gameOverString; gameOverString.precision(6); gameOverString << "YOU WIN!\n"; gameOverString << "Score: " << score; gameOverString << "\nSpacebar to\nplay again."; finalScore = gameOverString.str(); RECT R2 = {GAME_WIDTH/2 - 100, GAME_HEIGHT/2 - 100, 0, 0}; endFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN); } else if(gsm->getGameState() == GameStateManager::END_GAME) { std::wostringstream gameOverString; gameOverString.precision(6); gameOverString << "YOU DIED!\n"; gameOverString << "Score: " << score; gameOverString << "\nSpacebar to\nplay again."; finalScore = gameOverString.str(); RECT R2 = {GAME_WIDTH/2 - 100, GAME_HEIGHT/2 - 100, 0, 0}; endFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN); } if(gsm->getGameState() == GameStateManager::START_GAME) { std::wostringstream gameOverString; gameOverString.precision(6); gameOverString << "Controls:\n"; gameOverString << "Move: A and D.\n"; gameOverString << "Shoot: Enter \n"; gameOverString << "Hit the spacebar to begin."; finalScore = gameOverString.str(); RECT R2 = {50, GAME_HEIGHT/2 - 100, 0, 0}; scoreFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN); } else { if (gsm->getGameState() == GameStateManager::IN_GAME) { std::wostringstream scoreString; scoreString.precision(6); scoreString << score; finalScore = scoreString.str(); RECT R2 = {GAME_WIDTH/2 + 50, GAME_HEIGHT + 65, 0, 0}; scoreFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN); } } std::wostringstream ts; ts.precision(6); ts << secondsRemaining; timeString = ts.str(); RECT R3 = {GAME_WIDTH/2 + 50, 20, 0, 0}; scoreFont->DrawText(0, timeString.c_str(), -1, &R3, DT_NOCLIP, GREEN); // We specify DT_NOCLIP, so we do not care about width/height of the rect. RECT R = {5, 5, 0, 0}; //mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK); mSwapChain->Present(0, 0); }
void ColoredCubeApp::updateScene(float dt) { for (int i = 0; i < MAX_NUM_STARS; i++) { stars[i].update(dt); } switch (gsm->getGameState()) { case GameStateManager::START_GAME: { D3DApp::updateScene(dt); gameObject1.update(dt); D3DXMATRIX w; D3DXMatrixTranslation(&w, 2, 2, 0); mfxWVPVar->SetMatrix(w); score = 0; // Build the view matrix. /*D3DXVECTOR3 pos(10.0f, 2.0f, 0.0f); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&mView, &pos, &target, &up);*/ if(GetAsyncKeyState(VK_SPACE) & 0x8000 && gsm->getGameState() != GameStateManager::IN_GAME) { gsm->setGameState(GameStateManager::IN_GAME); audio->playCue(SELECT); } Vector3 oldEnemyPositions[MAX_NUM_ENEMIES]; for (int i = 0; i < MAX_NUM_ENEMIES; i++) { oldEnemyPositions[i] = enemyObjects[i].getPosition(); } Vector3 oldBulletPositions[MAX_NUM_BULLETS]; for (int i = 0; i < MAX_NUM_BULLETS; i++) { oldBulletPositions[i] = playerBullets[i].getPosition(); } //Camera Object camera.update(dt); break; } case GameStateManager::IN_GAME: { //Generate a block every three seconds if (enemyBuffer.elapsedTime() > 2) { enemyBuffer.resetClock(); generateEnemy(enemyObjects, dt); } if (gameTimer.elapsedTime() >= 1) { gameTimer.resetClock(); secondsRemaining--; } for (int i = 0; i < MAX_NUM_BULLETS; i++) { playerBullets[i].update(dt); } for (int i = 0; i < MAX_NUM_EXP_PARTICLES; i++) { particles[i].update(dt); } if (camera.isCameraRecoiling()) { camera.cameraRecoil(dt); } if(explosionRunning) explosionTimer += dt; if (explosionTimer > .55) { explosionTimer = 0; explosionRunning = false; for (int i = 0; i < MAX_NUM_EXP_PARTICLES; i++) { particles[i].setInActive(); } } if(GetAsyncKeyState(VK_RETURN) & 0x8000) { if(shotRelease) { shootBullet(playerBullets, dt, gameObject1); //shotRelease = false; } } //if(!(GetAsyncKeyState(VK_RETURN) & 0x8000)) shotRelease = true; Vector3 oldEnemyPositions[MAX_NUM_ENEMIES]; for (int i = 0; i < MAX_NUM_ENEMIES; i++) { oldEnemyPositions[i] = enemyObjects[i].getPosition(); } Vector3 direction(0, 0, 0); Vector3 oldposition = gameObject1.getPosition(); D3DApp::updateScene(dt); gameObject1.update(dt); for (int i = 0; i < MAX_NUM_ENEMIES; i++) { enemyObjects[i].update(dt); } if((GetAsyncKeyState('A') & 0x8000) && !(GetAsyncKeyState('D') & 0x8000)) direction.z = -1.0f; if((GetAsyncKeyState('D') & 0x8000) && !(GetAsyncKeyState('A') & 0x8000)) direction.z = +1.0f; D3DXVec3Normalize(&direction, &direction); for (int i = 0; i < MAX_NUM_ENEMIES; i++) { //if they collide and are active if(gameObject1.collided(&enemyObjects[i]) && enemyObjects[i].getActiveState()) { audio->playCue(FAIL); enemyObjects[i].setInActive(); //score++; camera.cameraShake(dt); score = 0; gsm->setGameState(GameStateManager::END_GAME); } if (enemyObjects[i].getPosition().x > 7) { enemyObjects[i].setInActive(); } } for (int i = 0; i < MAX_NUM_BULLETS; i++) { for (int j = 0; j < MAX_NUM_ENEMIES; j++) { if(playerBullets[i].collided(&enemyObjects[j]) && enemyObjects[j].getActiveState()) { audio->playCue(BOOM); explosionTimer = 0; runExplosion(playerBullets[i].getPosition()); enemyObjects[j].setInActive(); playerBullets[i].setInActive(); score++; } } } gameObject1.setVelocity( direction * gameObject1.getSpeed()); if (gameObject1.getPosition().z < -PLAYER_Z_RANGE) { gameObject1.setPosition(Vector3(oldposition.x, oldposition.y, -PLAYER_Z_RANGE)); camera.setCameraMoveLeft(false); camera.setCameraMoveRight(true); } else if (gameObject1.getPosition().z > PLAYER_Z_RANGE) { gameObject1.setPosition(Vector3(oldposition.x, oldposition.y, PLAYER_Z_RANGE)); camera.setCameraMoveRight(false); camera.setCameraMoveLeft(true); } else { camera.setCameraMoveRight(true); camera.setCameraMoveLeft(true); } //Destroys bullet if too far away for (int i = 0; i < MAX_NUM_BULLETS; i++) { if(playerBullets[i].getPosition().x < -10 && playerBullets[i].getActiveState()) playerBullets[i].setInActive(); } D3DXMATRIX w; D3DXMatrixTranslation(&w, 2, 2, 0); mfxWVPVar->SetMatrix(w); //Camera Object camera.update(dt); //Get Camera viewMatrix mView = camera.getViewMatrix(); mProj = camera.getProjectionMatrix(); } if (secondsRemaining <= 0) { gsm->setGameState(GameStateManager::END_GAME); } case GameStateManager::END_GAME: { //D3DApp::updateScene(dt); //gameObject1.update(dt); if (camera.isCameraShaking()) { camera.cameraShake(dt); } D3DXMATRIX w; D3DXMatrixTranslation(&w, 2, 2, 0); mfxWVPVar->SetMatrix(w); //// Build the view matrix. //D3DXVECTOR3 pos(10.0f, 2.0f, 0.0f); //D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); //D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); //D3DXMatrixLookAtLH(&mView, &pos, &target, &up); if(GetAsyncKeyState(VK_SPACE) & 0x8000 && gsm->getGameState() != GameStateManager::IN_GAME) { restartGame(); gsm->setGameState(GameStateManager::IN_GAME); audio->playCue(SELECT); } //Camera Object camera.update(dt); break; } default: { throw(GameError(gameErrorNS::FATAL_ERROR, "Game State Error")); break; } } }
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()); } }
void ColoredCubeApp::drawLine(LineObject* line) { mWVP = line->getWorldMatrix()*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); line->setMTech(mTech); line->draw(); }
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); }