void LitWavesApp::UpdateWaves(const GameTimer& gt) { // Every quarter second, generate a random wave. static float t_base = 0.0f; if((mTimer.TotalTime() - t_base) >= 0.25f) { t_base += 0.25f; int i = MathHelper::Rand(4, mWaves->RowCount() - 5); int j = MathHelper::Rand(4, mWaves->ColumnCount() - 5); float r = MathHelper::RandF(0.2f, 0.5f); mWaves->Disturb(i, j, r); } // Update the wave simulation. mWaves->Update(gt.DeltaTime()); // Update the wave vertex buffer with the new solution. auto currWavesVB = mCurrFrameResource->WavesVB.get(); for(int i = 0; i < mWaves->VertexCount(); ++i) { Vertex v; v.Pos = mWaves->Position(i); v.Normal = mWaves->Normal(i); currWavesVB->CopyData(i, v); } // Set the dynamic VB of the wave renderitem to the current frame VB. mWavesRitem->Geo->VertexBufferGPU = currWavesVB->Resource(); }
void CameraAndDynamicIndexingApp::UpdateMainPassCB(const GameTimer& gt) { XMMATRIX view = mCamera.GetView(); XMMATRIX proj = mCamera.GetProj(); XMMATRIX viewProj = XMMatrixMultiply(view, proj); XMMATRIX invView = XMMatrixInverse(&XMMatrixDeterminant(view), view); XMMATRIX invProj = XMMatrixInverse(&XMMatrixDeterminant(proj), proj); XMMATRIX invViewProj = XMMatrixInverse(&XMMatrixDeterminant(viewProj), viewProj); XMStoreFloat4x4(&mMainPassCB.View, XMMatrixTranspose(view)); XMStoreFloat4x4(&mMainPassCB.InvView, XMMatrixTranspose(invView)); XMStoreFloat4x4(&mMainPassCB.Proj, XMMatrixTranspose(proj)); XMStoreFloat4x4(&mMainPassCB.InvProj, XMMatrixTranspose(invProj)); XMStoreFloat4x4(&mMainPassCB.ViewProj, XMMatrixTranspose(viewProj)); XMStoreFloat4x4(&mMainPassCB.InvViewProj, XMMatrixTranspose(invViewProj)); mMainPassCB.EyePosW = mCamera.GetPosition3f(); mMainPassCB.RenderTargetSize = XMFLOAT2((float)mClientWidth, (float)mClientHeight); mMainPassCB.InvRenderTargetSize = XMFLOAT2(1.0f / mClientWidth, 1.0f / mClientHeight); mMainPassCB.NearZ = 1.0f; mMainPassCB.FarZ = 1000.0f; mMainPassCB.TotalTime = gt.TotalTime(); mMainPassCB.DeltaTime = gt.DeltaTime(); mMainPassCB.AmbientLight = { 0.25f, 0.25f, 0.35f, 1.0f }; mMainPassCB.Lights[0].Direction = { 0.57735f, -0.57735f, 0.57735f }; mMainPassCB.Lights[0].Strength = { 0.8f, 0.8f, 0.8f }; mMainPassCB.Lights[1].Direction = { -0.57735f, -0.57735f, 0.57735f }; mMainPassCB.Lights[1].Strength = { 0.4f, 0.4f, 0.4f }; mMainPassCB.Lights[2].Direction = { 0.0f, -0.707f, -0.707f }; mMainPassCB.Lights[2].Strength = { 0.2f, 0.2f, 0.2f }; auto currPassCB = mCurrFrameResource->PassCB.get(); currPassCB->CopyData(0, mMainPassCB); }
void TexWaves::UpdateWaves(const GameTimer& timer) { static float base = 0.0f; if ((timer.TotalTime() - base) >= 0.25f) { base += 0.25f; int i = MathHelper::Rand(4, _waves->RowCount() - 5); int j = MathHelper::Rand(4, _waves->ColumnCount() - 5); float r = MathHelper::RandF(0.2f, 0.5f); _waves->Disturb(i, j, r); } _waves->Update(timer.DeltaTime()); auto currWavesVB = _currFrameResource->WavesVB.get(); for (int i = 0; i < _waves->VertexCount(); i++) { FrameResource::Vertex v; v.Pos = _waves->Position(i); v.Normal = _waves->Normal(i); v.TexC.x = 0.5f + v.Pos.x / _waves->Width(); v.TexC.y = 0.5f + v.Pos.z / _waves->Depth(); currWavesVB->CopyData(i, v); } _wavesRenderItem->Geo->VertexBufferGPU = currWavesVB->Resource(); }
void LitWavesApp::UpdateMainPassCB(const GameTimer& gt) { XMMATRIX view = XMLoadFloat4x4(&mView); XMMATRIX proj = XMLoadFloat4x4(&mProj); XMMATRIX viewProj = XMMatrixMultiply(view, proj); XMMATRIX invView = XMMatrixInverse(&XMMatrixDeterminant(view), view); XMMATRIX invProj = XMMatrixInverse(&XMMatrixDeterminant(proj), proj); XMMATRIX invViewProj = XMMatrixInverse(&XMMatrixDeterminant(viewProj), viewProj); XMStoreFloat4x4(&mMainPassCB.View, XMMatrixTranspose(view)); XMStoreFloat4x4(&mMainPassCB.InvView, XMMatrixTranspose(invView)); XMStoreFloat4x4(&mMainPassCB.Proj, XMMatrixTranspose(proj)); XMStoreFloat4x4(&mMainPassCB.InvProj, XMMatrixTranspose(invProj)); XMStoreFloat4x4(&mMainPassCB.ViewProj, XMMatrixTranspose(viewProj)); XMStoreFloat4x4(&mMainPassCB.InvViewProj, XMMatrixTranspose(invViewProj)); mMainPassCB.EyePosW = mEyePos; mMainPassCB.RenderTargetSize = XMFLOAT2((float)mClientWidth, (float)mClientHeight); mMainPassCB.InvRenderTargetSize = XMFLOAT2(1.0f / mClientWidth, 1.0f / mClientHeight); mMainPassCB.NearZ = 1.0f; mMainPassCB.FarZ = 1000.0f; mMainPassCB.TotalTime = gt.TotalTime(); mMainPassCB.DeltaTime = gt.DeltaTime(); mMainPassCB.AmbientLight = { 0.25f, 0.25f, 0.35f, 1.0f }; XMVECTOR lightDir = -MathHelper::SphericalToCartesian(1.0f, mSunTheta, mSunPhi); XMStoreFloat3(&mMainPassCB.Lights[0].Direction, lightDir); mMainPassCB.Lights[0].Strength = { 1.0f, 1.0f, 0.9f }; auto currPassCB = mCurrFrameResource->PassCB.get(); currPassCB->CopyData(0, mMainPassCB); }
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ) { #ifdef _DEBUG // this is for enabling memory leak detection _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif MSG msg = { 0 }; double tempDT = 10.0; // create window HWND wndHandle = InitWindow(hInstance); //float test = 5; // window is valid if (wndHandle) { // display window ShowWindow(wndHandle, nCmdShow); //Create engine class Engine* engine = new Engine(); engine->Initialize(&wndHandle, &hInstance); GameTimer* time = GameTimer::GetInstance(); //test = AntTweakBar::GetInstance()->GetBar();s //AntTweakBar::GetInstance()->addSlider("test", test); time->Reset(); // enter message loop, loop until the message WM_QUIT is received. while (WM_QUIT != msg.message) { // read messages if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); // this will call the function WndProc below! DispatchMessage(&msg); } else { time->Tick(); double dt = time->DeltaTime(); CalculateFPS(wndHandle, *time); engine->Frame(&dt); // update/render goes here } } // finish the program engine->Release(); delete engine; //delete time; DestroyWindow(wndHandle); } // return how the program finished. return (int) msg.wParam; }
void TexWaves::AnimateMaterials(const GameTimer& timer) { auto waterMat = _materials["water"].get(); float& tu = waterMat->MatTransform(3, 0); float& tv = waterMat->MatTransform(3, 1); tu += 0.1f * timer.DeltaTime(); tv += 0.02f * timer.DeltaTime(); if (tu >= 1.0f) tu -= 1.0f; if (tv >= 1.0f) tv -= 1.0f; waterMat->MatTransform(3, 0) = tu; waterMat->MatTransform(3, 1) = tv; waterMat->NumFramesDirty = FrameResource::NumFrameResources; }
void WavesCSApp::AnimateMaterials(const GameTimer& gt) { // Scroll the water material texture coordinates. auto waterMat = mMaterials["water"].get(); float& tu = waterMat->MatTransform(3, 0); float& tv = waterMat->MatTransform(3, 1); tu += 0.1f * gt.DeltaTime(); tv += 0.02f * gt.DeltaTime(); if(tu >= 1.0f) tu -= 1.0f; if(tv >= 1.0f) tv -= 1.0f; waterMat->MatTransform(3, 0) = tu; waterMat->MatTransform(3, 1) = tv; // Material has changed, so need to update cbuffer. waterMat->NumFramesDirty = gNumFrameResources; }
void CameraAndDynamicIndexingApp::OnKeyboardInput(const GameTimer& gt) { const float dt = gt.DeltaTime(); if(GetAsyncKeyState('W') & 0x8000) mCamera.Walk(10.0f*dt); if(GetAsyncKeyState('S') & 0x8000) mCamera.Walk(-10.0f*dt); if(GetAsyncKeyState('A') & 0x8000) mCamera.Strafe(-10.0f*dt); if(GetAsyncKeyState('D') & 0x8000) mCamera.Strafe(10.0f*dt); mCamera.UpdateViewMatrix(); }
void DynamicIndexing::OnKeyboardInput(const GameTimer& timer) { const float dt = timer.DeltaTime(); if (GetAsyncKeyState('W') & 0x8000) _camera.Walk(10.0f*dt); if (GetAsyncKeyState('S') & 0x8000) _camera.Walk(-10.0f*dt); if (GetAsyncKeyState('A') & 0x8000) _camera.Strafe(-10.0f*dt); if (GetAsyncKeyState('D') & 0x8000) _camera.Strafe(10.0f*dt); _camera.UpdateViewMatrix(); }
void LitWavesApp::OnKeyboardInput(const GameTimer& gt) { const float dt = gt.DeltaTime(); if(GetAsyncKeyState(VK_LEFT) & 0x8000) mSunTheta -= 1.0f*dt; if(GetAsyncKeyState(VK_RIGHT) & 0x8000) mSunTheta += 1.0f*dt; if(GetAsyncKeyState(VK_UP) & 0x8000) mSunPhi -= 1.0f*dt; if(GetAsyncKeyState(VK_DOWN) & 0x8000) mSunPhi += 1.0f*dt; mSunPhi = MathHelper::Clamp(mSunPhi, 0.1f, XM_PIDIV2); }
void TexWaves::OnKeyboardInput(const GameTimer& timer) { float dt = timer.DeltaTime(); if (GetAsyncKeyState('1') & 0x8000) _isWireframe = true; else _isWireframe = false; if (GetAsyncKeyState(VK_LEFT) & 0x8000) _sunTheta -= 1.0f * dt; if (GetAsyncKeyState(VK_RIGHT) & 0x8000) _sunTheta += 1.0f * dt; if (GetAsyncKeyState(VK_UP) & 0x8000) _sunPhi -= 1.0f * dt; if (GetAsyncKeyState(VK_RIGHT) & 0x8000) _sunPhi += 1.0f * dt; _sunPhi = MathHelper::Clamp(_sunPhi, 0.1f, XM_PIDIV2); }
void TexWaves::UpdateMainPassCB(const GameTimer& timer) { XMMATRIX view = XMLoadFloat4x4(&_view); XMMATRIX proj = XMLoadFloat4x4(&_proj); XMMATRIX viewProj = XMMatrixMultiply(view, proj); XMMATRIX invView = XMMatrixInverse(&XMMatrixDeterminant(view), view); XMMATRIX invProj = XMMatrixInverse(&XMMatrixDeterminant(proj), proj); XMMATRIX invViewProj = XMMatrixInverse(&XMMatrixDeterminant(viewProj), viewProj); XMStoreFloat4x4(&_mainPassCB.View, XMMatrixTranspose(view)); XMStoreFloat4x4(&_mainPassCB.InvView, XMMatrixTranspose(invView)); XMStoreFloat4x4(&_mainPassCB.Proj, XMMatrixTranspose(proj)); XMStoreFloat4x4(&_mainPassCB.InvProj, XMMatrixTranspose(invProj)); XMStoreFloat4x4(&_mainPassCB.VP, XMMatrixTranspose(viewProj)); XMStoreFloat4x4(&_mainPassCB.InvVP, XMMatrixTranspose(invViewProj)); _mainPassCB.EyePosW = _eyePos; _mainPassCB.RenderTargetSize = XMFLOAT2((float)_clientWidth, (float)_clientHeight); _mainPassCB.InvRenderTargetSize = XMFLOAT2(1.0f / _clientWidth, 1.0f / _clientHeight); _mainPassCB.NearZ = 1.0f; _mainPassCB.FarZ = 1000.0f; _mainPassCB.TotalTime = timer.TotalTime(); _mainPassCB.DeltaTime = timer.DeltaTime(); _mainPassCB.AmbientLight = { 0.25f, 0.25f, 0.35f, 1.0f }; XMVECTOR lightDir = -MathHelper::SphericalToCartesian(1.0f, _sunTheta, _sunPhi); XMStoreFloat3(&_mainPassCB.Lights[0].Direction, lightDir); _mainPassCB.Lights[0].Strength = { 1.0f, 1.0f, 0.9f }; _mainPassCB.Lights[1].Direction = { 0.57735f, -0.57735f, 0.57735f }; _mainPassCB.Lights[1].Strength = { 0.9f, 0.9f, 0.9f }; _mainPassCB.Lights[2].Direction = { -0.57735f, -0.57735f, 0.57735f }; _mainPassCB.Lights[2].Strength = { 0.5f, 0.5f, 0.5f }; auto currPassCB = _currFrameResource->PassCB.get(); currPassCB->CopyData(0, _mainPassCB); }
Texture* HeightmapManager::getHeightmap(const unsigned __int64& id, const dvec2& offset, double scale, const vec3& faceNormal) { Texture* texture = mpCache->getTexture(id, true); if (texture != NULL) return texture; GameTimer timer; timer.Reset(); timer.Start(); texture = mpCache->getFreeTexture(id); mpGenerator->setGenerationTarget(texture); mpGenerator->generateHeightmap(offset, scale, faceNormal); timer.Tick(); std::cout << "Generated id: " << id << " in " << (timer.DeltaTime() * 1000.0) << "MS " << " Cache size: " << mpCache->getActiveCount() << " Free count: " << mpCache->getInactiveCount() << std::endl; return texture; }