-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathFrontPanelDemo.cpp
603 lines (489 loc) · 19.8 KB
/
FrontPanelDemo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
//--------------------------------------------------------------------------------------
// FrontPanelDemo.cpp
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "FrontPanelDemo.h"
#include "ATGColors.h"
#include "ReadData.h"
extern void ExitSample() noexcept;
using namespace DirectX;
using namespace ATG;
using Microsoft::WRL::ComPtr;
namespace
{
// Vertex data structure used to
// create a constant buffer.
struct VS_CONSTANT_BUFFER
{
XMVECTOR vZero;
XMVECTOR vConstants;
XMVECTOR vWeight;
XMMATRIX matTranspose;
XMMATRIX matCameraTranspose;
XMMATRIX matViewTranspose;
XMMATRIX matProjTranspose;
XMVECTOR vLight;
XMVECTOR vLightDolphinSpace;
XMVECTOR vDiffuse;
XMVECTOR vAmbient;
XMVECTOR vFog;
XMVECTOR vCaustics;
};
// Pixel data structure used to
// create a constant buffer.
struct PS_CONSTANT_BUFFER
{
float fAmbient[4];
float fFogColor[4];
};
static_assert((sizeof(VS_CONSTANT_BUFFER) % 16) == 0, "CB must be 16 byte aligned");
static_assert((sizeof(PS_CONSTANT_BUFFER) % 16) == 0, "CB must be 16 byte aligned");
// Custom effect for sea floor
class SeaEffect : public IEffect
{
public:
SeaEffect(ID3D11Device* device, ID3D11PixelShader* pixelShader) :
m_pixelShader(pixelShader)
{
m_shaderBlob = DX::ReadData(L"SeaFloorVS.cso");
DX::ThrowIfFailed(device->CreateVertexShader(m_shaderBlob.data(), m_shaderBlob.size(), nullptr, m_vertexShader.ReleaseAndGetAddressOf()));
}
virtual void Apply(ID3D11DeviceContext* context) override
{
context->VSSetShader(m_vertexShader.Get(), nullptr, 0);
context->PSSetShader(m_pixelShader.Get(), nullptr, 0);
}
virtual void GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override
{
*pShaderByteCode = m_shaderBlob.data();
*pByteCodeLength = m_shaderBlob.size();
}
private:
ComPtr<ID3D11VertexShader> m_vertexShader;
ComPtr<ID3D11PixelShader> m_pixelShader;
std::vector<uint8_t> m_shaderBlob;
};
}
Sample::Sample() noexcept(false)
: m_frame(0),
m_paused(false),
m_wireframe(false),
m_currentCausticTextureView(0)
{
m_deviceResources = std::make_unique<DX::DeviceResources>();
// Set the water color to a nice blue.
SetWaterColor(0.0f, 0.5f, 1.0f);
// Set the ambient light.
m_ambient[0] = 0.25f;
m_ambient[1] = 0.25f;
m_ambient[2] = 0.25f;
m_ambient[3] = 0.25f;
}
// Initialize the Direct3D resources required to run.
void Sample::Initialize(IUnknown* window)
{
m_gamePad = std::make_unique<GamePad>();
m_frontPanelManager.CreateScreens();
m_deviceResources->SetWindow(window);
m_deviceResources->CreateDeviceResources();
CreateDeviceDependentResources();
m_deviceResources->CreateWindowSizeDependentResources();
CreateWindowSizeDependentResources();
if(m_frontPanelManager.IsAvailable())
{
auto& addDolphinAction = m_frontPanelManager.CreateButtonAction(
L"Add Dolphin",
L"Add a new dolphin to the scene.",
[this]() { AddNewDolphins(1); }
);
m_frontPanelManager.AssignActionToButton(addDolphinAction, XBOX_FRONT_PANEL_BUTTONS_BUTTON1);
auto& removeDolphinAction = m_frontPanelManager.CreateButtonAction(
L"Remove Dolphin",
L"Remove a dolphin from the scene.",
[this]() { RemoveDolphin(); }
);
m_frontPanelManager.AssignActionToButton(removeDolphinAction, XBOX_FRONT_PANEL_BUTTONS_BUTTON2);
auto& clearDolphinsActions = m_frontPanelManager.CreateButtonAction(
L"Clear Dolphins",
L"Remove all remaining dolphins from\nthe scene.",
[this]() { ClearDolphins(); }
);
m_frontPanelManager.AssignActionToButton(clearDolphinsActions, XBOX_FRONT_PANEL_BUTTONS_BUTTON3);
auto& toggleWireframeAction = m_frontPanelManager.CreateButtonAction(
L"Toggle Wireframe",
L"Toggles between solid and wireframe\n"
L"rendering.",
[this]() { ToggleWireframe(); }
);
m_frontPanelManager.AssignActionToButton(toggleWireframeAction, XBOX_FRONT_PANEL_BUTTONS_BUTTON4);
auto& togglePauseAction = m_frontPanelManager.CreateButtonAction(
L"Pause/Resume",
L"Toggles between pausing and unpausing\n"
L"the simulation.",
[this]() { TogglePause(); }
);
m_frontPanelManager.AssignActionToButton(togglePauseAction, XBOX_FRONT_PANEL_BUTTONS_BUTTON5);
m_frontPanelManager.CreateButtonAction(
L"Add 12 Dolphins",
L"Because, why not?",
[this]() { AddNewDolphins(12); }
);
}
}
#pragma region Frame Update
// Executes basic render loop.
void Sample::Tick()
{
PIXBeginEvent(PIX_COLOR_DEFAULT, L"Frame %llu", m_frame);
m_timer.Tick([&]()
{
Update(m_timer);
});
Render();
PIXEndEvent();
m_frame++;
}
// Updates the world.
void Sample::Update(DX::StepTimer const& timer)
{
PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");
float elapsedTime = float(timer.GetElapsedSeconds());
m_frontPanelManager.Update(timer);
if (!m_paused)
{
float totalTime = float(timer.GetTotalSeconds());
// Update all the dolphins
for (unsigned int i = 0; i < m_dolphins.size(); i++)
m_dolphins[i]->Update(totalTime, elapsedTime);
SetWaterColor(0.0f, 0.5f, 1.0f);
// Animate the caustic textures
m_currentCausticTextureView = (static_cast<unsigned int>(totalTime * 32)) % 32;
auto context = m_deviceResources->GetD3DDeviceContext();
D3D11_MAPPED_SUBRESOURCE mappedResource;
context->Map(m_VSConstantBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
{
VS_CONSTANT_BUFFER *vertShaderConstData = (VS_CONSTANT_BUFFER*)mappedResource.pData;
vertShaderConstData->vZero = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
vertShaderConstData->vConstants = XMVectorSet(1.0f, 0.5f, 0.2f, 0.05f);
// weight is for dolphins, so the value doesn't matter here (since we're setting it for the sea floor)
vertShaderConstData->vWeight = XMVectorSet(0, 0, 0, 0);
// Lighting vectors (in world space and in dolphin model space)
// and other constants
vertShaderConstData->vLight = XMVectorSet(0.00f, 1.00f, 0.00f, 0.00f);
vertShaderConstData->vLightDolphinSpace = XMVectorSet(0.00f, 1.00f, 0.00f, 0.00f);
vertShaderConstData->vDiffuse = XMVectorSet(1.00f, 1.00f, 1.00f, 1.00f);
vertShaderConstData->vAmbient = XMVectorSet(m_ambient[0], m_ambient[1], m_ambient[2], m_ambient[3]);
vertShaderConstData->vFog = XMVectorSet(0.50f, 50.00f, 1.00f / (50.0f - 1.0f), 0.00f);
vertShaderConstData->vCaustics = XMVectorSet(0.05f, 0.05f, sinf(totalTime) / 8, cosf(totalTime) / 10);
XMVECTOR vDeterminant;
XMMATRIX matDolphin = XMMatrixIdentity();
XMMATRIX matDolphinInv = XMMatrixInverse(&vDeterminant, matDolphin);
vertShaderConstData->vLightDolphinSpace = XMVector4Normalize(XMVector4Transform(vertShaderConstData->vLight, matDolphinInv));
// Vertex shader operations use transposed matrices
XMMATRIX mat, matCamera;
matCamera = XMMatrixMultiply(matDolphin, XMLoadFloat4x4(&m_matView));
mat = XMMatrixMultiply(matCamera, m_matProj);
vertShaderConstData->matTranspose = XMMatrixTranspose(mat);
vertShaderConstData->matCameraTranspose = XMMatrixTranspose(matCamera);
vertShaderConstData->matViewTranspose = XMMatrixTranspose(m_matView);
vertShaderConstData->matProjTranspose = XMMatrixTranspose(m_matProj);
}
context->Unmap(m_VSConstantBuffer.Get(), 0);
context->Map(m_PSConstantBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
{
PS_CONSTANT_BUFFER* pPsConstData = (PS_CONSTANT_BUFFER*)mappedResource.pData;
memcpy(pPsConstData->fAmbient, m_ambient, sizeof(m_ambient));
memcpy(pPsConstData->fFogColor, m_waterColor, sizeof(m_waterColor));
}
context->Unmap(m_PSConstantBuffer.Get(), 0);
auto pad = m_gamePad->GetState(0);
if (pad.IsConnected())
{
m_gamePadButtons.Update(pad);
if (pad.IsViewPressed())
{
ExitSample();
}
}
else
{
m_gamePadButtons.Reset();
}
}
PIXEndEvent();
}
#pragma endregion
#pragma region Frame Render
// Draws the scene.
void Sample::Render()
{
// Don't try to render anything before the first Update.
if (m_timer.GetFrameCount() == 0)
{
return;
}
// Prepare the render target to render a new frame.
m_deviceResources->Prepare();
Clear();
auto context = m_deviceResources->GetD3DDeviceContext();
PIXBeginEvent(context, PIX_COLOR_DEFAULT, L"Render");
SetWaterColor(0.0f, 0.5f, 1.0f);
// Set state
context->OMSetBlendState(m_states->Opaque(), 0, 0xffffffff);
context->RSSetState(m_wireframe ? m_states->Wireframe() : m_states->CullNone());
context->OMSetDepthStencilState(m_states->DepthDefault(), 0);
ID3D11SamplerState* pSamplers[] = { m_pSamplerMirror.Get(), m_states->LinearWrap() };
context->PSSetSamplers(0, 2, pSamplers);
context->VSSetConstantBuffers(0, 1, m_VSConstantBuffer.GetAddressOf());
context->PSSetConstantBuffers(0, 1, m_PSConstantBuffer.GetAddressOf());
/////////////////////////////////////////////////////
//
// Render sea floor
//
////////////////////////////////////////////////////
assert(!m_seafloor->meshes.empty());
assert(!m_seafloor->meshes[0]->meshParts.empty());
m_seafloor->meshes[0]->meshParts[0]->Draw(context, m_seaEffect.get(), m_seaFloorVertexLayout.Get(), [&]
{
context->PSSetShaderResources(0, 1, m_seaFloorTextureView.GetAddressOf());
context->PSSetShaderResources(1, 1, m_causticTextureViews[m_currentCausticTextureView].GetAddressOf());
});
/////////////////////////////////////////////////////
//
// Render Dolphins
//
////////////////////////////////////////////////////
for (unsigned int i = 0; i < m_dolphins.size(); i++)
DrawDolphin(*m_dolphins[i].get());
m_frontPanelManager.GPURender(m_deviceResources.get());
// Show the new frame.
PIXBeginEvent(context, PIX_COLOR_DEFAULT, L"Present");
m_deviceResources->Present();
m_graphicsMemory->Commit();
PIXEndEvent(context);
}
// Helper method to clear the back buffers.
void Sample::Clear()
{
auto context = m_deviceResources->GetD3DDeviceContext();
PIXBeginEvent(context, PIX_COLOR_DEFAULT, L"Clear");
// Clear the views.
auto renderTarget = m_deviceResources->GetRenderTargetView();
auto depthStencil = m_deviceResources->GetDepthStencilView();
// Use linear clear color for gamma-correct rendering.
context->ClearRenderTargetView(renderTarget, m_waterColor);
context->ClearDepthStencilView(depthStencil, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
context->OMSetRenderTargets(1, &renderTarget, depthStencil);
// Set the viewport.
auto viewport = m_deviceResources->GetScreenViewport();
context->RSSetViewports(1, &viewport);
PIXEndEvent(context);
}
#pragma endregion
#pragma region Message Handlers
// Message handlers
void Sample::OnSuspending()
{
auto context = m_deviceResources->GetD3DDeviceContext();
context->Suspend(0);
}
void Sample::OnResuming()
{
auto context = m_deviceResources->GetD3DDeviceContext();
context->Resume();
m_timer.ResetElapsedTime();
m_gamePadButtons.Reset();
}
#pragma endregion
#pragma region Direct3D Resources
// These are the resources that depend on the device.
void Sample::CreateDeviceDependentResources()
{
auto device = m_deviceResources->GetD3DDevice();
auto context = m_deviceResources->GetD3DDeviceContext();
m_graphicsMemory = std::make_unique<GraphicsMemory>(device, m_deviceResources->GetBackBufferCount());
m_frontPanelManager.CreateDeviceDependentResources(m_deviceResources.get());
////////////////////////////////
//
// Create constant buffers
//
////////////////////////////////
{
D3D11_BUFFER_DESC cbDesc;
cbDesc.ByteWidth = sizeof(VS_CONSTANT_BUFFER);
cbDesc.Usage = D3D11_USAGE_DYNAMIC;
cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbDesc.MiscFlags = 0;
DX::ThrowIfFailed(device->CreateBuffer(&cbDesc, NULL, m_VSConstantBuffer.GetAddressOf()));
cbDesc.ByteWidth = sizeof(PS_CONSTANT_BUFFER);
DX::ThrowIfFailed(device->CreateBuffer(&cbDesc, NULL, m_PSConstantBuffer.GetAddressOf()));
}
m_fxFactory = std::make_unique<EffectFactory>(device);
m_fxFactory->SetDirectory(L"Assets\\textures");
//////////////////////////////
// Create the dolphins
//////////////////////////////
for (unsigned int i = 0; i < 4; i++)
{
AddNewDolphins(1);
}
////////////////////////////////
//
// Create the textures resources
//
////////////////////////////////
m_fxFactory->CreateTexture(L"Seafloor.bmp", context, m_seaFloorTextureView.ReleaseAndGetAddressOf());
for (DWORD t = 0; t < 32; t++)
{
std::wstring path;
if (t < 10)
{
int count = _scwprintf(L"caust0%i.DDS", t);
path.resize(count + 1);
swprintf_s(&path[0], path.size(), L"caust0%i.DDS", t);
}
else
{
int count = _scwprintf(L"caust%i.DDS", t);
path.resize(count + 1);
swprintf_s(&path[0], path.size(), L"caust%i.DDS", t);
}
m_fxFactory->CreateTexture(path.c_str(), context, m_causticTextureViews[t].ReleaseAndGetAddressOf());
}
// Create the common pixel shader
{
auto blob = DX::ReadData(L"CausticsPS.cso");
DX::ThrowIfFailed(device->CreatePixelShader(blob.data(), blob.size(), nullptr, m_pixelShader.ReleaseAndGetAddressOf()));
}
////////////////////////////////
//
// Create the mesh resources
//
////////////////////////////////
// Create sea floor objects
m_seafloor = Model::CreateFromSDKMESH(device, L"assets\\mesh\\seafloor.sdkmesh", *m_fxFactory);
m_seaEffect = std::make_unique<SeaEffect>(device, m_pixelShader.Get());
m_seafloor->meshes[0]->meshParts[0]->CreateInputLayout(device, m_seaEffect.get(), m_seaFloorVertexLayout.ReleaseAndGetAddressOf());
{
D3D11_SAMPLER_DESC desc = {};
desc.AddressU = D3D11_TEXTURE_ADDRESS_MIRROR;
desc.AddressV = D3D11_TEXTURE_ADDRESS_MIRROR;
desc.AddressW = D3D11_TEXTURE_ADDRESS_MIRROR;
desc.MaxLOD = D3D11_FLOAT32_MAX;
desc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
DX::ThrowIfFailed(device->CreateSamplerState(&desc, m_pSamplerMirror.ReleaseAndGetAddressOf()));
}
m_states = std::make_unique<CommonStates>(device);
// Determine the aspect ratio
float fAspectRatio = 1920.0f / 1080.0f;
// Set the transform matrices
static const XMVECTORF32 c_vEyePt = { 0.0f, 0.0f, -5.0f, 0.0f };
static const XMVECTORF32 c_vLookatPt = { 0.0f, 0.0f, 0.0f, 0.0f };
static const XMVECTORF32 c_vUpVec = { 0.0f, 1.0f, 0.0f, 0.0f };
m_matView = XMMatrixLookAtLH(c_vEyePt, c_vLookatPt, c_vUpVec);
m_matProj = XMMatrixPerspectiveFovLH(XM_PI / 3, fAspectRatio, 1.0f, 10000.0f);
}
// Allocate all memory resources that change on a window SizeChanged event.
void Sample::CreateWindowSizeDependentResources()
{
m_frontPanelManager.CreateWindowSizeDependentResources(m_deviceResources.get());
}
#pragma endregion
void Sample::SetWaterColor(float red, float green, float blue)
{
m_waterColor[0] = red;
m_waterColor[1] = green;
m_waterColor[2] = blue;
m_waterColor[3] = 1.0f;
}
void Sample::DrawDolphin(Dolphin &dolphin)
{
auto context = m_deviceResources->GetD3DDeviceContext();
D3D11_MAPPED_SUBRESOURCE mappedResource;
context->Map(m_VSConstantBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
{
VS_CONSTANT_BUFFER* vertShaderConstData = (VS_CONSTANT_BUFFER*)mappedResource.pData;
vertShaderConstData->vZero = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
vertShaderConstData->vConstants = XMVectorSet(1.0f, 0.5f, 0.2f, 0.05f);
FLOAT fBlendWeight = dolphin.GetBlendWeight();
FLOAT fWeight1;
FLOAT fWeight2;
FLOAT fWeight3;
if (fBlendWeight > 0.0f)
{
fWeight1 = fabsf(fBlendWeight);
fWeight2 = 1.0f - fabsf(fBlendWeight);
fWeight3 = 0.0f;
}
else
{
fWeight1 = 0.0f;
fWeight2 = 1.0f - fabsf(fBlendWeight);
fWeight3 = fabsf(fBlendWeight);
}
vertShaderConstData->vWeight = XMVectorSet(fWeight1, fWeight2, fWeight3, 0.0f);
// Lighting vectors (in world space and in dolphin model space)
// and other constants
vertShaderConstData->vLight = XMVectorSet(0.00f, 1.00f, 0.00f, 0.00f);
vertShaderConstData->vLightDolphinSpace = XMVectorSet(0.00f, 1.00f, 0.00f, 0.00f);
vertShaderConstData->vDiffuse = XMVectorSet(1.00f, 1.00f, 1.00f, 1.00f);
vertShaderConstData->vAmbient = XMVectorSet(m_ambient[0], m_ambient[1], m_ambient[2], m_ambient[3]);
vertShaderConstData->vFog = XMVectorSet(0.50f, 50.00f, 1.00f / (50.0f - 1.0f), 0.00f);
float totalSeconds = float(m_timer.GetTotalSeconds());
vertShaderConstData->vCaustics = XMVectorSet(0.05f, 0.05f, sinf(totalSeconds) / 8, cosf(totalSeconds) / 10);
XMVECTOR vDeterminant;
XMMATRIX matDolphin = dolphin.GetWorld();
XMMATRIX matDolphinInv = XMMatrixInverse(&vDeterminant, matDolphin);
vertShaderConstData->vLightDolphinSpace = XMVector4Normalize(XMVector4Transform(vertShaderConstData->vLight, matDolphinInv));
// Vertex shader operations use transposed matrices
XMMATRIX mat, matCamera;
matCamera = XMMatrixMultiply(matDolphin, XMLoadFloat4x4(&m_matView));
mat = XMMatrixMultiply(matCamera, m_matProj);
vertShaderConstData->matTranspose = XMMatrixTranspose(mat);
vertShaderConstData->matCameraTranspose = XMMatrixTranspose(matCamera);
vertShaderConstData->matViewTranspose = XMMatrixTranspose(m_matView);
vertShaderConstData->matProjTranspose = XMMatrixTranspose(m_matProj);
}
context->Unmap(m_VSConstantBuffer.Get(), 0);
context->VSSetConstantBuffers(0, 1, m_VSConstantBuffer.GetAddressOf());
dolphin.Render(context, m_pixelShader.Get(), m_causticTextureViews[m_currentCausticTextureView].Get());
}
void Sample::AddNewDolphins(unsigned count)
{
auto device = m_deviceResources->GetD3DDevice();
auto context = m_deviceResources->GetD3DDeviceContext();
for (unsigned i = 0; i < count; ++i)
{
auto d = std::make_shared<Dolphin>();
d->Translate(XMVectorSet(0, -1.0f + 2.0f * float(rand() % 4), 10, 0));
d->Load(device, context, m_fxFactory.get());
m_dolphins.push_back(d);
}
}
void Sample::RemoveDolphin()
{
if (m_dolphins.size() > 0)
{
m_dolphins.pop_front();
}
}
void Sample::ClearDolphins()
{
m_dolphins.clear();
}
void Sample::ToggleWireframe()
{
m_wireframe = !m_wireframe;
}
void Sample::TogglePause()
{
m_paused = !m_paused;
}
void Sample::PauseSimulation(bool pause)
{
m_paused = pause;
}