Exam Done
This commit is contained in:
@@ -17,7 +17,7 @@ public:
|
||||
|
||||
virtual ~BaseScene() = default;
|
||||
|
||||
virtual void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr) = 0;
|
||||
virtual void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) = 0;
|
||||
|
||||
virtual void Update() = 0;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void DioramaScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr) {
|
||||
void DioramaScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) {
|
||||
|
||||
std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
||||
Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
|
||||
|
||||
@@ -7,7 +7,7 @@ class DioramaScene : public BaseScene {
|
||||
public:
|
||||
void Cleanup() override;
|
||||
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr) override;
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||
|
||||
std::vector<Mesh *> &GetMeshes() override;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "../Utils.h"
|
||||
#include "../Effects/Effect.h"
|
||||
|
||||
void InstancedScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr) {
|
||||
void InstancedScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) {
|
||||
m_DeviceContextPtr = DeviceContextPtr;
|
||||
|
||||
std::vector<VertexIn> vertices{};
|
||||
@@ -20,15 +20,30 @@ void InstancedScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *De
|
||||
std::shared_ptr<Material> cubeMaterial = std::make_shared<Material>();
|
||||
cubeMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/grass_block.png", DevicePtr);
|
||||
|
||||
// std::vector<InstancedData> instanceData;
|
||||
// for (int x = 0; x < 100; ++x) {
|
||||
// for (int y = 0; y < 100; ++y) {
|
||||
// InstancedData data;
|
||||
// float scale = 2;
|
||||
// //Generate sine wave based on x and y
|
||||
// float YOffset = sin(x * 0.5f + SDL_GetTicks() * 0.001f) + cos(y * 0.5f + SDL_GetTicks() * 0.001f);
|
||||
// //Add random but predictable randomness
|
||||
// YOffset += (x * 0.1f + y * 0.1f) * 0.1f;
|
||||
// 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);
|
||||
// instanceData.push_back(data);
|
||||
// }
|
||||
// }
|
||||
|
||||
std::vector<InstancedData> instanceData;
|
||||
for (int x = 0; x < 100; ++x) {
|
||||
for (int y = 0; y < 100; ++y) {
|
||||
InstancedData data;
|
||||
float scale = 2;
|
||||
//Generate sine wave based on x and y
|
||||
|
||||
//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);
|
||||
//Add random but predictable randomness
|
||||
YOffset += (x * 0.1f + y * 0.1f) * 0.1f;
|
||||
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);
|
||||
@@ -92,4 +107,5 @@ void InstancedScene::Update() {
|
||||
}
|
||||
m_instancedMeshes[0]->UpdateInstanceData(m_DeviceContextPtr, instanceData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
#include "BaseScene.h"
|
||||
#include "../Camera.h"
|
||||
#include "../InstancedMesh.h"
|
||||
#include "../PerlinNoise.hpp"
|
||||
|
||||
class InstancedScene : public BaseScene {
|
||||
public:
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr) override;
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||
|
||||
void Render(ID3D11DeviceContext* devicePtr, ID3D11RenderTargetView *renderTargetViewPtr, ID3D11DepthStencilView *depthStencilViewPtr, const Camera& camera) override;
|
||||
|
||||
@@ -27,6 +28,9 @@ private:
|
||||
//Kind of hack since InstancedMesh doesnt extend mesh
|
||||
std::vector<InstancedMesh*> m_instancedMeshes;
|
||||
std::vector<std::shared_ptr<Material>> m_materials;
|
||||
|
||||
const siv::PerlinNoise::seed_type seed = 123456u;
|
||||
const siv::PerlinNoise m_perlinNoise{seed};
|
||||
};
|
||||
|
||||
#endif //GP1_DIRECTX_INSTANCEDSCENE_H
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
#include <cassert>
|
||||
|
||||
|
||||
void MainScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr) {
|
||||
void MainScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) {
|
||||
|
||||
std::vector<VertexIn> vertices{};
|
||||
std::vector<uint32_t> indices{};
|
||||
|
||||
if (!Utils::ParseOBJNew("resources/vehicle.obj", vertices, indices, false)) {
|
||||
if (!Utils::ParseOBJNew("resources/vehicle.obj", vertices, indices, true)) {
|
||||
assert(true && "Model failed to load");
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
class MainScene : public BaseScene {
|
||||
public:
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr) override;
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||
|
||||
void Cleanup() override;
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include "../Utils.h"
|
||||
#include "../Effects/Effect.h"
|
||||
|
||||
void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr) {
|
||||
void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) {
|
||||
m_DeviceContextPtr = DeviceContextPtr;
|
||||
|
||||
m_Camera = camera;
|
||||
std::vector<VertexIn> vertices{};
|
||||
std::vector<uint32_t> indices{};
|
||||
|
||||
@@ -90,6 +90,7 @@ void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devic
|
||||
|
||||
auto* skyboxEffect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, skyboxMaterial, skyboxEffect));
|
||||
m_skyboxMesh = m_meshes.back();
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateScale(0.1f, 0.1f, 0.1f);
|
||||
@@ -133,4 +134,11 @@ void PlanetScene::Update() {
|
||||
}
|
||||
|
||||
m_instancedMeshes[0]->UpdateInstanceData(m_DeviceContextPtr, m_InstancedData);
|
||||
|
||||
//set the skybox to the camera
|
||||
Matrix skyboxMatrix = m_skyboxMesh->GetWorldMatrix();
|
||||
|
||||
Vector3 cameraPos = m_Camera->GetPosition();
|
||||
skyboxMatrix.SetTranslation(cameraPos);
|
||||
m_skyboxMesh->SetWorldMatrix(skyboxMatrix);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
class PlanetScene : public BaseScene {
|
||||
public:
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr) override;
|
||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||
|
||||
void Render(ID3D11DeviceContext* devicePtr, ID3D11RenderTargetView *renderTargetViewPtr, ID3D11DepthStencilView *depthStencilViewPtr, const Camera& camera) override;
|
||||
|
||||
@@ -29,6 +29,10 @@ private:
|
||||
std::vector<InstancedMesh*> m_instancedMeshes;
|
||||
std::vector<InstancedData> m_InstancedData;
|
||||
std::vector<std::shared_ptr<Material>> m_materials;
|
||||
|
||||
Mesh* m_skyboxMesh;
|
||||
|
||||
Camera* m_Camera;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user