Compare commits
3 Commits
Shadows
...
12cbbb4dcb
| Author | SHA1 | Date | |
|---|---|---|---|
| 12cbbb4dcb | |||
| 2448bf3872 | |||
| a3a6011e43 |
@@ -193,7 +193,7 @@ const dae::Vector3 & dae::Camera::GetPosition() const {
|
|||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dae::Vector3 dae::Camera::GetRotation() const {
|
dae::Vector3 dae::Camera::GetRotation() const {
|
||||||
return {totalPitch, totalYaw, 0.f};
|
return {totalPitch, totalYaw, 0.f};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "Math/Matrix.h"
|
#include "Math/Matrix.h"
|
||||||
|
|
||||||
namespace dae {
|
namespace dae {
|
||||||
class Camera {
|
class Camera final {
|
||||||
public:
|
public:
|
||||||
Camera() = default;
|
Camera() = default;
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ namespace dae {
|
|||||||
const Vector3 & GetPosition() const;
|
const Vector3 & GetPosition() const;
|
||||||
void SetPosition(const Vector3& position);
|
void SetPosition(const Vector3& position);
|
||||||
|
|
||||||
const Vector3 GetRotation() const;
|
Vector3 GetRotation() const;
|
||||||
void SetRotation(const Vector3& rotation);
|
void SetRotation(const Vector3& rotation);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
//
|
|
||||||
// Created by Bram on 20/12/2024.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef GP1_DIRECTX_BASEEFFECT_H
|
#ifndef GP1_DIRECTX_BASEEFFECT_H
|
||||||
#define GP1_DIRECTX_BASEEFFECT_H
|
#define GP1_DIRECTX_BASEEFFECT_H
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ enum class CullMode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Effect: public BaseEffect {
|
class Effect final: public BaseEffect {
|
||||||
public:
|
public:
|
||||||
Effect(ID3D11Device *devicePtr, const std::wstring &filePath);
|
Effect(ID3D11Device *devicePtr, const std::wstring &filePath);
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include "BaseEffect.h"
|
#include "BaseEffect.h"
|
||||||
|
|
||||||
class FireEffect: public BaseEffect {
|
class FireEffect final: public BaseEffect {
|
||||||
public:
|
public:
|
||||||
FireEffect(ID3D11Device *devicePtr, const std::wstring &filePath);
|
FireEffect(ID3D11Device *devicePtr, const std::wstring &filePath);
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ void GamePadController::Init() {
|
|||||||
SDL_GameController *pController = SDL_GameControllerOpen(i);
|
SDL_GameController *pController = SDL_GameControllerOpen(i);
|
||||||
if (pController) {
|
if (pController) {
|
||||||
m_pGameControllers.push_back(pController);
|
m_pGameControllers.push_back(pController);
|
||||||
m_GamePads.push_back(GamePad());
|
m_GamePads.emplace_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ void GamePadController::Update() {
|
|||||||
SDL_GameController *pController = SDL_GameControllerOpen(i);
|
SDL_GameController *pController = SDL_GameControllerOpen(i);
|
||||||
if (pController) {
|
if (pController) {
|
||||||
m_pGameControllers.push_back(pController);
|
m_pGameControllers.push_back(pController);
|
||||||
m_GamePads.push_back(GamePad());
|
m_GamePads.emplace_back();
|
||||||
|
|
||||||
std::cout << GREEN << "New Controller Connected" << RESET << std::endl;
|
std::cout << GREEN << "New Controller Connected" << RESET << std::endl;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,6 @@ void GamePadController::Update() {
|
|||||||
std::cout << RED << "Controller Disconnected" << RESET << std::endl;
|
std::cout << RED << "Controller Disconnected" << RESET << std::endl;
|
||||||
--i; // Adjust index after removing the controller
|
--i; // Adjust index after removing the controller
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,17 @@
|
|||||||
#define GP1_DIRECTX_GAMEPADCONTROLLER_H
|
#define GP1_DIRECTX_GAMEPADCONTROLLER_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include "SDL_gamecontroller.h"
|
#include "SDL_gamecontroller.h"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
|
|
||||||
struct GamePad{
|
struct GamePad{
|
||||||
bool buttons[SDL_CONTROLLER_BUTTON_MAX];
|
std::array<bool, SDL_CONTROLLER_BUTTON_MAX> buttons{false};
|
||||||
float axis[SDL_CONTROLLER_AXIS_MAX];
|
std::array<float, SDL_CONTROLLER_AXIS_MAX> axis{0.0f};
|
||||||
|
|
||||||
bool prevButtons[SDL_CONTROLLER_BUTTON_MAX]{ false };
|
std::array<bool, SDL_CONTROLLER_BUTTON_MAX> prevButtons{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class GamePadButton {
|
enum class GamePadButton {
|
||||||
@@ -42,7 +43,7 @@ enum class GamePadButton {
|
|||||||
|
|
||||||
enum Controllers {PLAYER1, PLAYER2, PLAYER3, PLAYER4};
|
enum Controllers {PLAYER1, PLAYER2, PLAYER3, PLAYER4};
|
||||||
|
|
||||||
class GamePadController {
|
class GamePadController final {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static GamePadController& GetInstance()
|
static GamePadController& GetInstance()
|
||||||
@@ -66,7 +67,6 @@ private:
|
|||||||
GamePadController();
|
GamePadController();
|
||||||
std::vector<SDL_GameController*> m_pGameControllers;
|
std::vector<SDL_GameController*> m_pGameControllers;
|
||||||
std::vector<GamePad> m_GamePads;
|
std::vector<GamePad> m_GamePads;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
using namespace dae;
|
using namespace dae;
|
||||||
|
|
||||||
|
|
||||||
struct Sample
|
struct Sample final
|
||||||
{
|
{
|
||||||
Vector2 uv{};
|
Vector2 uv{};
|
||||||
Vector3 normal{};
|
Vector3 normal{};
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
#include "InstancedMesh.h"
|
#include "InstancedMesh.h"
|
||||||
|
|
||||||
InstancedMesh::InstancedMesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
|
InstancedMesh::InstancedMesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
|
||||||
std::shared_ptr<Material> material, BaseEffect *effectPtr, const std::vector<InstancedData> &instanceData)
|
std::shared_ptr<Material> material, std::unique_ptr<BaseEffect> effectPtr, const std::vector<InstancedData> &instanceData)
|
||||||
: m_EffectPtr(effectPtr),
|
: m_EffectPtr(std::move(effectPtr)),
|
||||||
m_InputLayoutPtr(nullptr),
|
m_InputLayoutPtr(nullptr),
|
||||||
m_VertexBufferPtr(nullptr),
|
m_VertexBufferPtr(nullptr),
|
||||||
m_IndexBufferPtr(nullptr),
|
m_IndexBufferPtr(nullptr),
|
||||||
@@ -152,9 +152,6 @@ InstancedMesh::~InstancedMesh() {
|
|||||||
m_InstanceBufferPtr = nullptr;
|
m_InstanceBufferPtr = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_EffectPtr;
|
|
||||||
m_EffectPtr = nullptr;
|
|
||||||
|
|
||||||
m_Material.reset();
|
m_Material.reset();
|
||||||
|
|
||||||
m_InstancedData.clear();
|
m_InstancedData.clear();
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ struct alignas(16) InstancedData {
|
|||||||
Vector4 color;
|
Vector4 color;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InstancedMesh {
|
class InstancedMesh final {
|
||||||
public:
|
public:
|
||||||
InstancedMesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
|
InstancedMesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
|
||||||
std::shared_ptr<Material> material, BaseEffect* effectPtr, const std::vector<InstancedData>& instanceData);
|
std::shared_ptr<Material> material, std::unique_ptr<BaseEffect> effectPtr, const std::vector<InstancedData>& instanceData);
|
||||||
|
|
||||||
~InstancedMesh();
|
~InstancedMesh();
|
||||||
|
|
||||||
@@ -26,7 +26,6 @@ public:
|
|||||||
|
|
||||||
Matrix GetWorldMatrix() const;
|
Matrix GetWorldMatrix() const;
|
||||||
|
|
||||||
|
|
||||||
Material* GetMaterial() const;
|
Material* GetMaterial() const;
|
||||||
|
|
||||||
void SetWorldMatrix(const Matrix &matrix);
|
void SetWorldMatrix(const Matrix &matrix);
|
||||||
@@ -40,7 +39,7 @@ public:
|
|||||||
void UpdateInstanceData(ID3D11DeviceContext* deviceContextPtr, const std::vector<InstancedData>& instanceData);
|
void UpdateInstanceData(ID3D11DeviceContext* deviceContextPtr, const std::vector<InstancedData>& instanceData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BaseEffect *m_EffectPtr;
|
std::unique_ptr<BaseEffect> m_EffectPtr;
|
||||||
|
|
||||||
Matrix m_WorldMatrix{};
|
Matrix m_WorldMatrix{};
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
struct Material {
|
struct Material final {
|
||||||
Texture *diffuseTexturePtr{nullptr};
|
Texture *diffuseTexturePtr{nullptr};
|
||||||
Texture *normalTexturePtr{nullptr};
|
Texture *normalTexturePtr{nullptr};
|
||||||
Texture *specularTexturePtr{nullptr};
|
Texture *specularTexturePtr{nullptr};
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
#include "Effects/Effect.h"
|
#include "Effects/Effect.h"
|
||||||
|
|
||||||
Mesh::Mesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices, std::shared_ptr<Material> material, BaseEffect* effectPtr) :
|
Mesh::Mesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices, std::shared_ptr<Material> material, std::unique_ptr<BaseEffect> effectPtr) :
|
||||||
m_EffectPtr(effectPtr),
|
m_EffectPtr(std::move(effectPtr)),
|
||||||
m_InputLayoutPtr(nullptr),
|
m_InputLayoutPtr(nullptr),
|
||||||
m_VertexBufferPtr(nullptr),
|
m_VertexBufferPtr(nullptr),
|
||||||
m_IndexBufferPtr(nullptr),
|
m_IndexBufferPtr(nullptr),
|
||||||
@@ -91,8 +91,6 @@ Mesh::~Mesh() {
|
|||||||
m_IndexBufferPtr->Release();
|
m_IndexBufferPtr->Release();
|
||||||
m_IndexBufferPtr = nullptr;
|
m_IndexBufferPtr = nullptr;
|
||||||
|
|
||||||
delete m_EffectPtr;
|
|
||||||
m_EffectPtr = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::Render(ID3D11DeviceContext *deviceContextPtr, const Matrix &worldViewProj) const {
|
void Mesh::Render(ID3D11DeviceContext *deviceContextPtr, const Matrix &worldViewProj) const {
|
||||||
|
|||||||
@@ -19,12 +19,10 @@ enum class PrimitiveTopology {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Mesh final {
|
class Mesh final {
|
||||||
public:
|
public:
|
||||||
Mesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
|
Mesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
|
||||||
std::shared_ptr<Material> material, BaseEffect* effectPtr);
|
std::shared_ptr<Material> material, std::unique_ptr<BaseEffect> effectPtr);
|
||||||
|
|
||||||
~Mesh();
|
~Mesh();
|
||||||
|
|
||||||
@@ -54,7 +52,7 @@ public:
|
|||||||
bool GetShouldRender() const { return m_ShouldRender; }
|
bool GetShouldRender() const { return m_ShouldRender; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BaseEffect *m_EffectPtr;
|
std::unique_ptr<BaseEffect> m_EffectPtr;
|
||||||
|
|
||||||
Matrix m_WorldMatrix{};
|
Matrix m_WorldMatrix{};
|
||||||
|
|
||||||
|
|||||||
@@ -36,14 +36,14 @@ namespace dae {
|
|||||||
|
|
||||||
InitializeSDLRasterizer();
|
InitializeSDLRasterizer();
|
||||||
|
|
||||||
m_pScene = new MainScene();
|
m_pScene = std::make_unique<MainScene>();
|
||||||
m_pScene->Initialize(m_DevicePtr, m_DeviceContextPtr, nullptr);
|
m_pScene->Initialize(m_DevicePtr, m_DeviceContextPtr, nullptr);
|
||||||
|
|
||||||
if (!m_pScene->GetMeshes().empty()) {
|
if (!m_pScene->GetMeshes().empty()) {
|
||||||
m_pFireMesh = m_pScene->GetMeshes().back();
|
m_pFireMesh = m_pScene->GetMeshes().back().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
float aspectRatio = static_cast<float>(m_Width) / static_cast<float>(m_Height);
|
const float aspectRatio = static_cast<float>(m_Width) / static_cast<float>(m_Height);
|
||||||
m_Camera = Camera({.0f, .0f, .0f}, 45.f);
|
m_Camera = Camera({.0f, .0f, .0f}, 45.f);
|
||||||
m_Camera.Initialize(45.f, {.0f, .0f, .0f}, aspectRatio);
|
m_Camera.Initialize(45.f, {.0f, .0f, .0f}, aspectRatio);
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,6 @@ namespace dae {
|
|||||||
m_DevicePtr->Release();
|
m_DevicePtr->Release();
|
||||||
|
|
||||||
m_pScene->Cleanup();
|
m_pScene->Cleanup();
|
||||||
delete m_pScene;
|
|
||||||
//SDL
|
//SDL
|
||||||
|
|
||||||
SDL_FreeSurface(m_pBackBuffer);
|
SDL_FreeSurface(m_pBackBuffer);
|
||||||
@@ -79,7 +78,7 @@ namespace dae {
|
|||||||
void Renderer::Update(const Timer *pTimer) {
|
void Renderer::Update(const Timer *pTimer) {
|
||||||
m_Camera.Update(pTimer);
|
m_Camera.Update(pTimer);
|
||||||
|
|
||||||
for (auto mesh: m_pScene->GetMeshes()) {
|
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||||
mesh->SetCameraPos(m_Camera.GetPosition());
|
mesh->SetCameraPos(m_Camera.GetPosition());
|
||||||
}
|
}
|
||||||
if (m_Rotating) {
|
if (m_Rotating) {
|
||||||
@@ -89,7 +88,7 @@ namespace dae {
|
|||||||
|
|
||||||
Matrix rotationMatrix = Matrix::CreateRotationY(rotationThisFrame);
|
Matrix rotationMatrix = Matrix::CreateRotationY(rotationThisFrame);
|
||||||
|
|
||||||
for (auto mesh: m_pScene->GetMeshes()) {
|
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||||
Matrix originalWorldMatrix = mesh->GetWorldMatrix();
|
Matrix originalWorldMatrix = mesh->GetWorldMatrix();
|
||||||
Matrix world = rotationMatrix * originalWorldMatrix;
|
Matrix world = rotationMatrix * originalWorldMatrix;
|
||||||
|
|
||||||
@@ -121,7 +120,7 @@ namespace dae {
|
|||||||
m_DeviceContextPtr->ClearDepthStencilView(m_DepthStencilViewPtr, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
|
m_DeviceContextPtr->ClearDepthStencilView(m_DepthStencilViewPtr, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
|
||||||
|
|
||||||
Matrix viewProjMatrix = m_Camera.GetViewProjectionMatrix();
|
Matrix viewProjMatrix = m_Camera.GetViewProjectionMatrix();
|
||||||
for (auto mesh: m_pScene->GetMeshes()) {
|
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||||
if (mesh->GetShouldRender()) {
|
if (mesh->GetShouldRender()) {
|
||||||
Matrix modelMatrix = mesh->GetWorldMatrix();
|
Matrix modelMatrix = mesh->GetWorldMatrix();
|
||||||
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
||||||
@@ -149,14 +148,14 @@ namespace dae {
|
|||||||
m_VerticiesScreenSpace.clear();
|
m_VerticiesScreenSpace.clear();
|
||||||
|
|
||||||
|
|
||||||
for (auto *currentMesh: m_pScene->GetMeshes()) {
|
for (auto& currentMesh: m_pScene->GetMeshes()) {
|
||||||
|
|
||||||
if (!currentMesh->GetShouldRender()) {
|
if (!currentMesh->GetShouldRender()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Matrix worldViewProjectionMatrix{currentMesh->GetWorldMatrix() * m_Camera.GetViewProjectionMatrix()};
|
const Matrix worldViewProjectionMatrix{currentMesh->GetWorldMatrix() * m_Camera.GetViewProjectionMatrix()};
|
||||||
VertexTransformationFunction(worldViewProjectionMatrix, currentMesh, currentMesh->GetVertices(), m_VerticiesScreenSpace);
|
VertexTransformationFunction(worldViewProjectionMatrix, currentMesh.get(), currentMesh->GetVertices(), m_VerticiesScreenSpace);
|
||||||
|
|
||||||
int numTriangles{};
|
int numTriangles{};
|
||||||
|
|
||||||
@@ -535,7 +534,7 @@ namespace dae {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::CycleCullMode() {
|
void Renderer::CycleCullMode() {
|
||||||
for (auto mesh: m_pScene->GetMeshes()) {
|
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||||
mesh->CycleCullMode();
|
mesh->CycleCullMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,7 +603,7 @@ namespace dae {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::NextSamplingState() {
|
void Renderer::NextSamplingState() {
|
||||||
for (auto mesh: m_pScene->GetMeshes()) {
|
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||||
mesh->NextSamplingState();
|
mesh->NextSamplingState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,7 +628,7 @@ namespace dae {
|
|||||||
|
|
||||||
void Renderer::ToggleNormals() {
|
void Renderer::ToggleNormals() {
|
||||||
m_useNormals = !m_useNormals;
|
m_useNormals = !m_useNormals;
|
||||||
for (auto mesh: m_pScene->GetMeshes()) {
|
for (auto& mesh: m_pScene->GetMeshes()) {
|
||||||
mesh->ToggleNormals();
|
mesh->ToggleNormals();
|
||||||
}
|
}
|
||||||
std::string mode = m_useNormals ? "ON" : "OFF";
|
std::string mode = m_useNormals ? "ON" : "OFF";
|
||||||
@@ -658,7 +657,6 @@ namespace dae {
|
|||||||
|
|
||||||
void Renderer::NextScene() {
|
void Renderer::NextScene() {
|
||||||
m_pScene->Cleanup();
|
m_pScene->Cleanup();
|
||||||
delete m_pScene;
|
|
||||||
|
|
||||||
//Calculate the next scene
|
//Calculate the next scene
|
||||||
int index = static_cast<int>(m_CurrentScene);
|
int index = static_cast<int>(m_CurrentScene);
|
||||||
@@ -667,27 +665,27 @@ namespace dae {
|
|||||||
|
|
||||||
switch (m_CurrentScene) {
|
switch (m_CurrentScene) {
|
||||||
case SceneNames::Main:
|
case SceneNames::Main:
|
||||||
m_pScene = new MainScene();
|
m_pScene = std::make_unique<MainScene>();
|
||||||
m_pFireMesh = nullptr;
|
m_pFireMesh = nullptr;
|
||||||
|
|
||||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Main" << RESET << std::endl;
|
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Main" << RESET << std::endl;
|
||||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||||
break;
|
break;
|
||||||
case SceneNames::Diorama:
|
case SceneNames::Diorama:
|
||||||
m_pScene = new DioramaScene();
|
m_pScene = std::make_unique<DioramaScene>();
|
||||||
|
|
||||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Diorama" << RESET << std::endl;
|
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Diorama" << RESET << std::endl;
|
||||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||||
break;
|
break;
|
||||||
case SceneNames::Instanced:
|
case SceneNames::Instanced:
|
||||||
m_pScene = new InstancedScene();
|
m_pScene = std::make_unique<InstancedScene>();
|
||||||
|
|
||||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Instanced" << RESET << std::endl;
|
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Instanced" << RESET << std::endl;
|
||||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SceneNames::Planet:
|
case SceneNames::Planet:
|
||||||
m_pScene = new PlanetScene();
|
m_pScene = std::make_unique<PlanetScene>();
|
||||||
|
|
||||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Planet" << RESET << std::endl;
|
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Planet" << RESET << std::endl;
|
||||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||||
@@ -705,7 +703,7 @@ namespace dae {
|
|||||||
|
|
||||||
if (m_CurrentScene == SceneNames::Main) {
|
if (m_CurrentScene == SceneNames::Main) {
|
||||||
//Kind of sloppy fix but hey :p
|
//Kind of sloppy fix but hey :p
|
||||||
m_pFireMesh = m_pScene->GetMeshes().back();
|
m_pFireMesh = m_pScene->GetMeshes().back().get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace dae
|
|||||||
|
|
||||||
Backendtype m_backendType{ Backendtype::DirectX };
|
Backendtype m_backendType{ Backendtype::DirectX };
|
||||||
|
|
||||||
BaseScene* m_pScene{};
|
std::unique_ptr<BaseScene> m_pScene{};
|
||||||
SceneNames m_CurrentScene{ SceneNames::Main };
|
SceneNames m_CurrentScene{ SceneNames::Main };
|
||||||
//Pos rot
|
//Pos rot
|
||||||
std::unordered_map<SceneNames, std::pair<Vector3, Vector3>> m_SceneCameraPositions{};
|
std::unordered_map<SceneNames, std::pair<Vector3, Vector3>> m_SceneCameraPositions{};
|
||||||
@@ -90,7 +90,7 @@ namespace dae
|
|||||||
float m_currentRotation{};
|
float m_currentRotation{};
|
||||||
bool m_UseUniformClearColor{ false };
|
bool m_UseUniformClearColor{ false };
|
||||||
|
|
||||||
ColorRGB m_UniformClearColor{ ColorRGB{0.1f * 255.f, 0.1f * 255.f, 0.1 * 255.f} };
|
const ColorRGB m_UniformClearColor{ ColorRGB{0.1f * 255.f, 0.1f * 255.f, 0.1 * 255.f} };
|
||||||
|
|
||||||
|
|
||||||
//DirectX vars
|
//DirectX vars
|
||||||
@@ -100,7 +100,7 @@ namespace dae
|
|||||||
HRESULT InitializeDirectX();
|
HRESULT InitializeDirectX();
|
||||||
void RenderDirectX() const;
|
void RenderDirectX() const;
|
||||||
|
|
||||||
ColorRGB DirectXClearColor{ .39f * 255.f, .59f * 255.f, .93f * 255.f };
|
const ColorRGB DirectXClearColor{ .39f * 255.f, .59f * 255.f, .93f * 255.f };
|
||||||
|
|
||||||
//Storing the mesh so i can deactivate it;
|
//Storing the mesh so i can deactivate it;
|
||||||
Mesh* m_pFireMesh{};
|
Mesh* m_pFireMesh{};
|
||||||
@@ -134,7 +134,7 @@ namespace dae
|
|||||||
bool m_isDepthBuffer{ false };
|
bool m_isDepthBuffer{ false };
|
||||||
|
|
||||||
|
|
||||||
ColorRGB m_ClearColorSoftware{ .39f * 255.f, .39f * 255.f, .39f * 255.f };
|
const ColorRGB m_ClearColorSoftware{ .39f * 255.f, .39f * 255.f, .39f * 255.f };
|
||||||
|
|
||||||
float* m_pDepthBufferPixels{};
|
float* m_pDepthBufferPixels{};
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public:
|
|||||||
|
|
||||||
virtual void Cleanup() = 0;
|
virtual void Cleanup() = 0;
|
||||||
|
|
||||||
virtual std::vector<Mesh*>& GetMeshes() = 0;
|
virtual std::vector<std::unique_ptr<Mesh>>& GetMeshes() = 0;
|
||||||
virtual std::vector<std::shared_ptr<Material>>& GetMaterials() = 0;
|
virtual std::vector<std::shared_ptr<Material>>& GetMaterials() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,19 +15,20 @@ void DioramaScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devi
|
|||||||
std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
||||||
Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
|
Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
|
||||||
for (const auto &mesh: materialMeshes) {
|
for (const auto &mesh: materialMeshes) {
|
||||||
if (mesh->vertices.size() > 0) {
|
if (!mesh->vertices.empty()) {
|
||||||
std::shared_ptr<Material> material = std::make_shared<Material>();
|
std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||||
BaseEffect *effect{nullptr};
|
std::unique_ptr<BaseEffect> effect{};
|
||||||
|
|
||||||
if (mesh->opacity_map != "") {
|
if (!mesh->opacity_map.empty()) {
|
||||||
effect = new FireEffect(DevicePtr, L"resources/Fire.fx");
|
effect = std::make_unique<FireEffect>(DevicePtr, L"resources/Fire.fx");
|
||||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||||
} else {
|
} else {
|
||||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||||
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
effect = std::make_unique<Effect>(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||||
}
|
}
|
||||||
|
auto newMesh = std::make_unique<Mesh>(DevicePtr, mesh->vertices, mesh->indices, material, std::move(effect));
|
||||||
|
m_meshes.push_back(std::move(newMesh));
|
||||||
|
|
||||||
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
|
|
||||||
|
|
||||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||||
worldMatrix *= Matrix::CreateScale(2.f, 2.f, 2.f);
|
worldMatrix *= Matrix::CreateScale(2.f, 2.f, 2.f);
|
||||||
@@ -42,13 +43,15 @@ void DioramaScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devi
|
|||||||
for (const auto &mesh: materialMeshes) {
|
for (const auto &mesh: materialMeshes) {
|
||||||
if (!mesh->vertices.empty()) {
|
if (!mesh->vertices.empty()) {
|
||||||
std::shared_ptr<Material> material = std::make_shared<Material>();
|
std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||||
BaseEffect *effect{nullptr};
|
auto effect = std::make_unique<Effect>(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||||
|
|
||||||
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
|
||||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/brok/" + mesh->diffuse_texture, DevicePtr);
|
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/brok/" + mesh->diffuse_texture, DevicePtr);
|
||||||
|
|
||||||
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
|
|
||||||
m_brokMeshses.push_back(m_meshes.back());
|
auto brokMesh = std::make_unique<Mesh>(DevicePtr, mesh->vertices, mesh->indices, material, std::move(effect));
|
||||||
|
m_brokMeshses.push_back(brokMesh.get());
|
||||||
|
m_meshes.push_back(std::move(brokMesh));
|
||||||
|
|
||||||
|
|
||||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||||
worldMatrix *= Matrix::CreateRotationY(3.14f / 2.f);
|
worldMatrix *= Matrix::CreateRotationY(3.14f / 2.f);
|
||||||
@@ -81,7 +84,7 @@ void DioramaScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Mesh *> &DioramaScene::GetMeshes() {
|
std::vector<std::unique_ptr<Mesh>> &DioramaScene::GetMeshes() {
|
||||||
return m_meshes;
|
return m_meshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,9 +93,6 @@ std::vector<std::shared_ptr<Material>> &DioramaScene::GetMaterials() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DioramaScene::Cleanup() {
|
void DioramaScene::Cleanup() {
|
||||||
for (Mesh *mesh: m_meshes) {
|
|
||||||
delete mesh;
|
|
||||||
}
|
|
||||||
m_meshes.clear();
|
m_meshes.clear();
|
||||||
m_materials.clear();
|
m_materials.clear();
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
|
|
||||||
#include "BaseScene.h"
|
#include "BaseScene.h"
|
||||||
|
|
||||||
class DioramaScene : public BaseScene {
|
class DioramaScene final : public BaseScene {
|
||||||
public:
|
public:
|
||||||
void Cleanup() override;
|
void Cleanup() override;
|
||||||
|
|
||||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||||
|
|
||||||
std::vector<Mesh *> &GetMeshes() override;
|
std::vector<std::unique_ptr<Mesh>> &GetMeshes() override;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ public:
|
|||||||
void Render(ID3D11DeviceContext* devicePtr, ID3D11RenderTargetView *renderTargetViewPtr, ID3D11DepthStencilView *depthStencilViewPtr, const Camera& camera) override;
|
void Render(ID3D11DeviceContext* devicePtr, ID3D11RenderTargetView *renderTargetViewPtr, ID3D11DepthStencilView *depthStencilViewPtr, const Camera& camera) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Mesh *> m_meshes{};
|
std::vector<std::unique_ptr<Mesh>> m_meshes{};
|
||||||
std::vector<std::shared_ptr<Material>> m_materials{};
|
std::vector<std::shared_ptr<Material>> m_materials{};
|
||||||
|
|
||||||
std::vector<Mesh*> m_brokMeshses{ nullptr };
|
std::vector<Mesh*> m_brokMeshses{ nullptr };
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ void InstancedScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *De
|
|||||||
float scale = 2;
|
float scale = 2;
|
||||||
|
|
||||||
//use the perlin noise to generate the YOffset
|
//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::CreateTranslation(x * scale, YOffset, y * scale);
|
||||||
data.worldMatrix *= Matrix::CreateScale(0.5f, 0.5f, 0.5f);
|
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);
|
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();
|
||||||
effect->NextSamplingState(); //Dirty hack
|
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() {
|
void InstancedScene::Cleanup() {
|
||||||
for (auto mesh: m_instancedMeshes) {
|
|
||||||
delete mesh;
|
|
||||||
}
|
|
||||||
m_instancedMeshes.clear();
|
m_instancedMeshes.clear();
|
||||||
|
|
||||||
for (auto mesh: m_meshes) {
|
|
||||||
delete mesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_meshes.clear();
|
m_meshes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Mesh *> &InstancedScene::GetMeshes() {
|
std::vector<std::unique_ptr<Mesh>> &InstancedScene::GetMeshes() {
|
||||||
return m_meshes;
|
return m_meshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +77,7 @@ std::vector<std::shared_ptr<Material>> &InstancedScene::GetMaterials() {
|
|||||||
void InstancedScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
void InstancedScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
||||||
ID3D11DepthStencilView *depthStencilViewPtr, const Camera &camera) {
|
ID3D11DepthStencilView *depthStencilViewPtr, const Camera &camera) {
|
||||||
Matrix viewProjMatrix = camera.GetViewProjectionMatrix();
|
Matrix viewProjMatrix = camera.GetViewProjectionMatrix();
|
||||||
for (auto mesh: m_instancedMeshes) {
|
for (auto& mesh: m_instancedMeshes) {
|
||||||
Matrix modelMatrix = mesh->GetWorldMatrix();
|
Matrix modelMatrix = mesh->GetWorldMatrix();
|
||||||
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
||||||
mesh->Render(devicePtr, worldViewProjMatrix);
|
mesh->Render(devicePtr, worldViewProjMatrix);
|
||||||
@@ -96,8 +92,9 @@ void InstancedScene::Update() {
|
|||||||
InstancedData data;
|
InstancedData data;
|
||||||
float scale = 2;
|
float scale = 2;
|
||||||
//Generate sine wave based on x and y and the SDL_GetTicks
|
//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);
|
float currentTick = static_cast<float>(SDL_GetTicks());
|
||||||
YOffset += (x * 0.1f + y * 0.1f) * 0.1f;
|
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::CreateTranslation(x * scale, YOffset, y * scale);
|
||||||
data.worldMatrix *= Matrix::CreateScale(0.5f, 0.5f, 0.5f);
|
data.worldMatrix *= Matrix::CreateScale(0.5f, 0.5f, 0.5f);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "../InstancedMesh.h"
|
#include "../InstancedMesh.h"
|
||||||
#include "../PerlinNoise.hpp"
|
#include "../PerlinNoise.hpp"
|
||||||
|
|
||||||
class InstancedScene : public BaseScene {
|
class InstancedScene final : public BaseScene {
|
||||||
public:
|
public:
|
||||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ public:
|
|||||||
|
|
||||||
void Cleanup() override;
|
void Cleanup() override;
|
||||||
|
|
||||||
std::vector<Mesh *> &GetMeshes() override;
|
std::vector<std::unique_ptr<Mesh>> &GetMeshes() override;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||||
|
|
||||||
@@ -24,9 +24,9 @@ private:
|
|||||||
|
|
||||||
ID3D11DeviceContext* m_DeviceContextPtr{};
|
ID3D11DeviceContext* m_DeviceContextPtr{};
|
||||||
|
|
||||||
std::vector<Mesh*> m_meshes;
|
std::vector<std::unique_ptr<Mesh>> m_meshes;
|
||||||
//Kind of hack since InstancedMesh doesnt extend mesh
|
//Kind of hack since InstancedMesh doesnt extend mesh
|
||||||
std::vector<InstancedMesh*> m_instancedMeshes;
|
std::vector<std::unique_ptr<InstancedMesh>> m_instancedMeshes;
|
||||||
std::vector<std::shared_ptr<Material>> m_materials;
|
std::vector<std::shared_ptr<Material>> m_materials;
|
||||||
|
|
||||||
const siv::PerlinNoise::seed_type seed = 123456u;
|
const siv::PerlinNoise::seed_type seed = 123456u;
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ void MainScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceC
|
|||||||
vehicleMaterial->specularTexturePtr = Texture::LoadFromFile("resources/vehicle_specular.png", DevicePtr);
|
vehicleMaterial->specularTexturePtr = Texture::LoadFromFile("resources/vehicle_specular.png", DevicePtr);
|
||||||
vehicleMaterial->glossTexturePtr = Texture::LoadFromFile("resources/vehicle_gloss.png", DevicePtr);
|
vehicleMaterial->glossTexturePtr = Texture::LoadFromFile("resources/vehicle_gloss.png", DevicePtr);
|
||||||
|
|
||||||
auto* effect = new Effect(DevicePtr, L"resources/PosCol3D.fx");
|
auto effect = std::make_unique<Effect>(DevicePtr, L"resources/PosCol3D.fx");
|
||||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, vehicleMaterial, effect));
|
auto vehicleMesh = std::make_unique<Mesh>(DevicePtr, vertices, indices, vehicleMaterial, std::move(effect));
|
||||||
|
m_meshes.push_back(std::move(vehicleMesh));
|
||||||
|
|
||||||
|
|
||||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||||
@@ -45,8 +46,9 @@ void MainScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceC
|
|||||||
std::shared_ptr<Material> FireMaterial = std::make_shared<Material>();
|
std::shared_ptr<Material> FireMaterial = std::make_shared<Material>();
|
||||||
FireMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/fireFX_diffuse.png", DevicePtr);
|
FireMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/fireFX_diffuse.png", DevicePtr);
|
||||||
|
|
||||||
auto* fireEffect = new FireEffect(DevicePtr, L"resources/Fire.fx");
|
auto fireEffect = std::make_unique<FireEffect>(DevicePtr, L"resources/Fire.fx");
|
||||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, FireMaterial, fireEffect));
|
auto fireMesh = std::make_unique<Mesh>(DevicePtr, vertices, indices, FireMaterial, std::move(fireEffect));
|
||||||
|
m_meshes.push_back(std::move(fireMesh));
|
||||||
|
|
||||||
worldMatrix = m_meshes.back()->GetWorldMatrix();
|
worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||||
worldMatrix *= Matrix::CreateTranslation(0, 0, 50.f);
|
worldMatrix *= Matrix::CreateTranslation(0, 0, 50.f);
|
||||||
@@ -55,13 +57,10 @@ void MainScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceC
|
|||||||
|
|
||||||
|
|
||||||
void MainScene::Cleanup() {
|
void MainScene::Cleanup() {
|
||||||
for (Mesh* mesh : m_meshes) {
|
|
||||||
delete mesh;
|
|
||||||
}
|
|
||||||
m_meshes.clear();
|
m_meshes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Mesh *> &MainScene::GetMeshes() {
|
std::vector<std::unique_ptr<Mesh>> &MainScene::GetMeshes() {
|
||||||
return m_meshes;
|
return m_meshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,13 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class MainScene : public BaseScene {
|
class MainScene final : public BaseScene {
|
||||||
public:
|
public:
|
||||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||||
|
|
||||||
void Cleanup() override;
|
void Cleanup() override;
|
||||||
|
|
||||||
std::vector<Mesh *> &GetMeshes() override;
|
std::vector<std::unique_ptr<Mesh>> &GetMeshes() override;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<Mesh*> m_meshes{};
|
std::vector<std::unique_ptr<Mesh>> m_meshes{};
|
||||||
std::vector<std::shared_ptr<Material>> m_materials{};
|
std::vector<std::shared_ptr<Material>> m_materials{};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -60,8 +60,9 @@ void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devic
|
|||||||
m_InstancedData.push_back(data);
|
m_InstancedData.push_back(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *rockEffect = new Effect(DevicePtr, L"resources/InstancedSimpleDiffuse.fx");
|
auto rockEffect = std::make_unique<Effect>(DevicePtr, L"resources/InstancedSimpleDiffuse.fx");
|
||||||
m_instancedMeshes.push_back(new InstancedMesh(DevicePtr, vertices, indices, rockMaterial, rockEffect, m_InstancedData));
|
auto rockMesh = std::make_unique<InstancedMesh>(DevicePtr, vertices, indices, rockMaterial, std::move(rockEffect), m_InstancedData);
|
||||||
|
m_instancedMeshes.push_back(std::move(rockMesh));
|
||||||
|
|
||||||
indices.clear();
|
indices.clear();
|
||||||
vertices.clear();
|
vertices.clear();
|
||||||
@@ -74,8 +75,10 @@ void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devic
|
|||||||
std::shared_ptr<Material> planetMaterial = std::make_shared<Material>();
|
std::shared_ptr<Material> planetMaterial = std::make_shared<Material>();
|
||||||
planetMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/planet/mars.png", DevicePtr);
|
planetMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/planet/mars.png", DevicePtr);
|
||||||
|
|
||||||
auto* planetEffect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
auto planetEffect = std::make_unique<Effect>(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, planetMaterial, planetEffect));
|
auto planetMesh = std::make_unique<Mesh>(DevicePtr, vertices, indices, planetMaterial, std::move(planetEffect));
|
||||||
|
m_planetMesh = planetMesh.get();
|
||||||
|
m_meshes.push_back(std::move(planetMesh));
|
||||||
|
|
||||||
indices.clear();
|
indices.clear();
|
||||||
vertices.clear();
|
vertices.clear();
|
||||||
@@ -88,9 +91,10 @@ void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devic
|
|||||||
std::shared_ptr<Material> skyboxMaterial = std::make_shared<Material>();
|
std::shared_ptr<Material> skyboxMaterial = std::make_shared<Material>();
|
||||||
skyboxMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/planet/skybox/space_nebula_6k.png", DevicePtr);
|
skyboxMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/planet/skybox/space_nebula_6k.png", DevicePtr);
|
||||||
|
|
||||||
auto* skyboxEffect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
auto skyboxEffect = std::make_unique<Effect>(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, skyboxMaterial, skyboxEffect));
|
auto skyBoxMesh = std::make_unique<Mesh>(DevicePtr, vertices, indices, skyboxMaterial, std::move(skyboxEffect));
|
||||||
m_skyboxMesh = m_meshes.back();
|
m_meshes.push_back(std::move(skyBoxMesh));
|
||||||
|
m_skyboxMesh = m_meshes.back().get();
|
||||||
|
|
||||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||||
worldMatrix *= Matrix::CreateScale(0.1f, 0.1f, 0.1f);
|
worldMatrix *= Matrix::CreateScale(0.1f, 0.1f, 0.1f);
|
||||||
@@ -98,19 +102,12 @@ void PlanetScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devic
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PlanetScene::Cleanup() {
|
void PlanetScene::Cleanup() {
|
||||||
for (auto mesh: m_instancedMeshes) {
|
|
||||||
delete mesh;
|
|
||||||
}
|
|
||||||
m_instancedMeshes.clear();
|
m_instancedMeshes.clear();
|
||||||
|
|
||||||
for (auto mesh: m_meshes) {
|
|
||||||
delete mesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_meshes.clear();
|
m_meshes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Mesh *> &PlanetScene::GetMeshes() {
|
std::vector<std::unique_ptr<Mesh>> &PlanetScene::GetMeshes() {
|
||||||
return m_meshes;
|
return m_meshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +118,7 @@ std::vector<std::shared_ptr<Material>> &PlanetScene::GetMaterials() {
|
|||||||
void PlanetScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
void PlanetScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
||||||
ID3D11DepthStencilView *depthStencilViewPtr, const Camera &camera) {
|
ID3D11DepthStencilView *depthStencilViewPtr, const Camera &camera) {
|
||||||
Matrix viewProjMatrix = camera.GetViewProjectionMatrix();
|
Matrix viewProjMatrix = camera.GetViewProjectionMatrix();
|
||||||
for (auto mesh: m_instancedMeshes) {
|
for (auto& mesh: m_instancedMeshes) {
|
||||||
Matrix modelMatrix = mesh->GetWorldMatrix();
|
Matrix modelMatrix = mesh->GetWorldMatrix();
|
||||||
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
||||||
mesh->Render(devicePtr, worldViewProjMatrix);
|
mesh->Render(devicePtr, worldViewProjMatrix);
|
||||||
@@ -137,8 +134,13 @@ void PlanetScene::Update() {
|
|||||||
|
|
||||||
//set the skybox to the camera
|
//set the skybox to the camera
|
||||||
Matrix skyboxMatrix = m_skyboxMesh->GetWorldMatrix();
|
Matrix skyboxMatrix = m_skyboxMesh->GetWorldMatrix();
|
||||||
|
|
||||||
Vector3 cameraPos = m_Camera->GetPosition();
|
Vector3 cameraPos = m_Camera->GetPosition();
|
||||||
skyboxMatrix.SetTranslation(cameraPos);
|
skyboxMatrix.SetTranslation(cameraPos);
|
||||||
m_skyboxMesh->SetWorldMatrix(skyboxMatrix);
|
m_skyboxMesh->SetWorldMatrix(skyboxMatrix);
|
||||||
|
|
||||||
|
//Rotate the planet slowly
|
||||||
|
Matrix planetMatrix = m_planetMesh->GetWorldMatrix();
|
||||||
|
planetMatrix *= Matrix::CreateRotationY(-0.0001f);
|
||||||
|
m_planetMesh->SetWorldMatrix(planetMatrix);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "BaseScene.h"
|
#include "BaseScene.h"
|
||||||
#include "../InstancedMesh.h"
|
#include "../InstancedMesh.h"
|
||||||
|
|
||||||
class PlanetScene : public BaseScene {
|
class PlanetScene final : public BaseScene {
|
||||||
public:
|
public:
|
||||||
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
void Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *DeviceContextPtr, Camera *camera) override;
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ public:
|
|||||||
|
|
||||||
void Cleanup() override;
|
void Cleanup() override;
|
||||||
|
|
||||||
std::vector<Mesh *> &GetMeshes() override;
|
std::vector<std::unique_ptr<Mesh>> &GetMeshes() override;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||||
|
|
||||||
@@ -24,13 +24,14 @@ private:
|
|||||||
|
|
||||||
ID3D11DeviceContext* m_DeviceContextPtr{};
|
ID3D11DeviceContext* m_DeviceContextPtr{};
|
||||||
|
|
||||||
std::vector<Mesh*> m_meshes;
|
std::vector<std::unique_ptr<Mesh>> m_meshes;
|
||||||
//Kind of hack since InstancedMesh doesnt extend mesh
|
//Kind of hack since InstancedMesh doesnt extend mesh
|
||||||
std::vector<InstancedMesh*> m_instancedMeshes;
|
std::vector<std::unique_ptr<InstancedMesh>> m_instancedMeshes;
|
||||||
std::vector<InstancedData> m_InstancedData;
|
std::vector<InstancedData> m_InstancedData;
|
||||||
std::vector<std::shared_ptr<Material>> m_materials;
|
std::vector<std::shared_ptr<Material>> m_materials;
|
||||||
|
|
||||||
Mesh* m_skyboxMesh;
|
Mesh* m_skyboxMesh;
|
||||||
|
Mesh* m_planetMesh;
|
||||||
|
|
||||||
Camera* m_Camera;
|
Camera* m_Camera;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
using namespace dae;
|
using namespace dae;
|
||||||
|
|
||||||
class Texture {
|
class Texture final {
|
||||||
public:
|
public:
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ private:
|
|||||||
ID3D11ShaderResourceView* m_TextureResourceViewPtr{};
|
ID3D11ShaderResourceView* m_TextureResourceViewPtr{};
|
||||||
ID3D11Texture2D* m_TexturePtr{};
|
ID3D11Texture2D* m_TexturePtr{};
|
||||||
|
|
||||||
SDL_Surface* m_SurfacePtr{ nullptr };
|
const SDL_Surface* m_SurfacePtr{ nullptr };
|
||||||
uint32_t* m_pSurfacePixels{ nullptr };
|
uint32_t* m_pSurfacePixels{ nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
namespace dae
|
namespace dae
|
||||||
{
|
{
|
||||||
class Timer
|
class Timer final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Timer();
|
Timer();
|
||||||
|
|||||||
@@ -395,4 +395,14 @@ namespace dae {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class DirectXDeleter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void operator()(T* p)
|
||||||
|
{
|
||||||
|
p->Release();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -129,8 +129,11 @@ int main(int argc, char *args[]) {
|
|||||||
//Create window + surfaces
|
//Create window + surfaces
|
||||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
||||||
|
|
||||||
const uint32_t width = 640;
|
const uint32_t width = 1600;
|
||||||
const uint32_t height = 480;
|
const uint32_t height = 900;
|
||||||
|
|
||||||
|
//// const uint32_t width = 640;
|
||||||
|
//// const uint32_t height = 480;
|
||||||
|
|
||||||
|
|
||||||
SDL_Window *pWindow = SDL_CreateWindow(
|
SDL_Window *pWindow = SDL_CreateWindow(
|
||||||
|
|||||||
Reference in New Issue
Block a user