Unique Ptrs, Const correctness
This commit is contained in:
@@ -43,7 +43,9 @@ void InstancedScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *De
|
||||
float scale = 2;
|
||||
|
||||
//use the perlin noise to generate the YOffset
|
||||
float YOffset = sin(x * 0.5f + SDL_GetTicks() * 0.001f) + cos(y * 0.5f + SDL_GetTicks() * 0.001f);
|
||||
float currentTick = static_cast<float>(SDL_GetTicks());
|
||||
|
||||
float YOffset = sin(x * 0.5f +currentTick * 0.001f) + cos(y * 0.5f + currentTick * 0.001f);
|
||||
data.worldMatrix = Matrix::CreateTranslation(x * scale, YOffset, y * scale);
|
||||
data.worldMatrix *= Matrix::CreateScale(0.5f, 0.5f, 0.5f);
|
||||
data.color = Vector4(float(x) / 255.f, float(y) / 255.f, 1.f, 1.0f);
|
||||
@@ -51,26 +53,20 @@ void InstancedScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *De
|
||||
}
|
||||
}
|
||||
|
||||
auto *effect = new Effect(DevicePtr, L"resources/InstancedSimpleDiffuse.fx");
|
||||
auto effect = std::make_unique<Effect>(DevicePtr, L"resources/InstancedSimpleDiffuse.fx");
|
||||
effect->NextSamplingState();
|
||||
effect->NextSamplingState(); //Dirty hack
|
||||
m_instancedMeshes.push_back(new InstancedMesh(DevicePtr, vertices, indices, cubeMaterial, effect, instanceData));
|
||||
|
||||
auto cubeMesh = std::make_unique<InstancedMesh>(DevicePtr, vertices, indices, cubeMaterial, std::move(effect), instanceData);
|
||||
m_instancedMeshes.push_back(std::move(cubeMesh));
|
||||
}
|
||||
|
||||
void InstancedScene::Cleanup() {
|
||||
for (auto mesh: m_instancedMeshes) {
|
||||
delete mesh;
|
||||
}
|
||||
m_instancedMeshes.clear();
|
||||
|
||||
for (auto mesh: m_meshes) {
|
||||
delete mesh;
|
||||
}
|
||||
|
||||
m_meshes.clear();
|
||||
}
|
||||
|
||||
std::vector<Mesh *> &InstancedScene::GetMeshes() {
|
||||
std::vector<std::unique_ptr<Mesh>> &InstancedScene::GetMeshes() {
|
||||
return m_meshes;
|
||||
}
|
||||
|
||||
@@ -81,7 +77,7 @@ std::vector<std::shared_ptr<Material>> &InstancedScene::GetMaterials() {
|
||||
void InstancedScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
||||
ID3D11DepthStencilView *depthStencilViewPtr, const Camera &camera) {
|
||||
Matrix viewProjMatrix = camera.GetViewProjectionMatrix();
|
||||
for (auto mesh: m_instancedMeshes) {
|
||||
for (auto& mesh: m_instancedMeshes) {
|
||||
Matrix modelMatrix = mesh->GetWorldMatrix();
|
||||
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
||||
mesh->Render(devicePtr, worldViewProjMatrix);
|
||||
@@ -96,8 +92,9 @@ void InstancedScene::Update() {
|
||||
InstancedData data;
|
||||
float scale = 2;
|
||||
//Generate sine wave based on x and y and the SDL_GetTicks
|
||||
float YOffset = sin(x * 0.5f + SDL_GetTicks() * 0.001f) + cos(y * 0.5f + SDL_GetTicks() * 0.001f);
|
||||
YOffset += (x * 0.1f + y * 0.1f) * 0.1f;
|
||||
float currentTick = static_cast<float>(SDL_GetTicks());
|
||||
float YOffset = sin(static_cast<float>(x) * 0.5f + currentTick * 0.001f) + cos(static_cast<float>(y) * 0.5f + currentTick * 0.001f);
|
||||
YOffset += (static_cast<float>(x) * 0.1f + static_cast<float>(y) * 0.1f) * 0.1f;
|
||||
|
||||
data.worldMatrix = Matrix::CreateTranslation(x * scale, YOffset, y * scale);
|
||||
data.worldMatrix *= Matrix::CreateScale(0.5f, 0.5f, 0.5f);
|
||||
|
||||
Reference in New Issue
Block a user