private void UpdateWaves(GameTimer gt) { // Every quarter second, generate a random wave. if ((Timer.TotalTime - _tBase) >= 0.25f) { _tBase += 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); } // Update the wave simulation. _waves.Update(gt.DeltaTime); // Update the wave vertex buffer with the new solution. UploadBuffer <Vertex> currWavesVB = CurrFrameResource.WavesVB; for (int i = 0; i < _waves.VertexCount; ++i) { var v = new Vertex { Pos = _waves.Position(i), Color = Color.Blue.ToVector4() }; currWavesVB.CopyData(i, ref v); } // Set the dynamic VB of the wave renderitem to the current frame VB. _wavesRitem.Geo.VertexBufferGPU = currWavesVB.Resource; }
private void UpdateWaves(GameTimer gt) { // Every quarter second, generate a random wave. if ((Timer.TotalTime - _tBase) >= 0.25f) { _tBase += 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); } // Update the wave simulation. _waves.Update(gt.DeltaTime); // Update the wave vertex buffer with the new solution. UploadBuffer <Vertex> currWavesVB = CurrFrameResource.WavesVB; for (int i = 0; i < _waves.VertexCount; ++i) { var v = new Vertex { Pos = _waves.Position(i), Normal = _waves.Normal(i), }; // Derive tex-coords from position by // mapping [-w/2,w/2] --> [0,1] v.TexC = new Vector2( 0.5f + v.Pos.X / _waves.Width, 0.5f - v.Pos.Z / _waves.Depth); currWavesVB.CopyData(i, ref v); } // Set the dynamic VB of the wave renderitem to the current frame VB. _wavesRitem.Geo.VertexBufferGPU = currWavesVB.Resource; }