Do alot of stuff
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "../pch.h"
|
||||
#include "Effect.h"
|
||||
#include "../Utils.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
@@ -53,8 +54,6 @@ Effect::Effect(ID3D11Device *devicePtr, const std::wstring &filePath)
|
||||
m_UseNormalMapVariablePtr->SetBool(m_UseNormalMap);
|
||||
|
||||
|
||||
|
||||
|
||||
constexpr int vectorSize{ 4 };
|
||||
constexpr float lightDirection[vectorSize]{ .577f, -.577f, .577f, 0.f };
|
||||
m_LightPosVariablePtr->SetFloatVector(lightDirection);
|
||||
@@ -132,15 +131,12 @@ void Effect::NextSamplingState() {
|
||||
switch(m_TechniqueType){
|
||||
case TechniqueType::Point:
|
||||
m_TechniqueType = TechniqueType::Linear;
|
||||
std::cout << "Linear" << std::endl;
|
||||
break;
|
||||
case TechniqueType::Linear:
|
||||
m_TechniqueType = TechniqueType::Anisotropic;
|
||||
std::cout << "Anisotropic" << std::endl;
|
||||
break;
|
||||
case TechniqueType::Anisotropic:
|
||||
m_TechniqueType = TechniqueType::Point;
|
||||
std::cout << "Point" << std::endl;
|
||||
break;
|
||||
}
|
||||
m_SamplerVariablePtr->SetSampler(0,m_SamplerStates[static_cast<int>(m_TechniqueType)]);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "GamePadController.h"
|
||||
#include "Utils.h"
|
||||
|
||||
GamePadController::GamePadController() = default;
|
||||
|
||||
@@ -24,10 +25,11 @@ void GamePadController::Init() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void GamePadController::Update() {
|
||||
//Check for new controllers
|
||||
const int numJoysticks = SDL_NumJoysticks();
|
||||
if(numJoysticks > m_pGameControllers.size()){
|
||||
for (int i = 0; i < numJoysticks; i++) {
|
||||
@@ -46,7 +48,7 @@ void GamePadController::Update() {
|
||||
m_pGameControllers.push_back(pController);
|
||||
m_GamePads.push_back(GamePad());
|
||||
|
||||
std::cout << "New Controller Connected" << std::endl;
|
||||
std::cout << GREEN << "New Controller Connected" << RESET << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,9 +61,10 @@ void GamePadController::Update() {
|
||||
SDL_GameControllerClose(pController);
|
||||
m_pGameControllers.erase(m_pGameControllers.begin() + i);
|
||||
m_GamePads.erase(m_GamePads.begin() + i);
|
||||
std::cout << "Controller Disconnected" << std::endl;
|
||||
std::cout << RED << "Controller Disconnected" << RESET << std::endl;
|
||||
--i; // Adjust index after removing the controller
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +72,10 @@ void GamePadController::Update() {
|
||||
SDL_GameController *pController = m_pGameControllers[i];
|
||||
GamePad &gamePad = m_GamePads[i];
|
||||
|
||||
for (int j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++) {
|
||||
gamePad.prevButtons[j] = gamePad.buttons[j];
|
||||
}
|
||||
|
||||
for (int j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++) {
|
||||
gamePad.buttons[j] = SDL_GameControllerGetButton(pController, (SDL_GameControllerButton) j);
|
||||
}
|
||||
@@ -79,16 +86,22 @@ void GamePadController::Update() {
|
||||
}
|
||||
}
|
||||
|
||||
bool GamePadController::IsButtonDown(Controllers controller, int button) const {
|
||||
return m_GamePads[controller].buttons[button];
|
||||
bool GamePadController::IsButtonDown(Controllers controller, GamePadButton button) const {
|
||||
return m_GamePads[controller].buttons[static_cast<int>(button)];
|
||||
}
|
||||
|
||||
bool GamePadController::IsButtonUp(Controllers controller, int button) const {
|
||||
return !m_GamePads[controller].buttons[button];
|
||||
bool GamePadController::IsButtonUp(Controllers controller, GamePadButton button) const {
|
||||
return !m_GamePads[controller].buttons[static_cast<int>(button)];
|
||||
}
|
||||
|
||||
float GamePadController::GetAxis(Controllers controller, int axis) const {
|
||||
return m_GamePads[controller].axis[axis];
|
||||
}
|
||||
|
||||
bool GamePadController::isButtonPressed(Controllers controller, GamePadButton button) const {
|
||||
if(controller >= m_GamePads.size())
|
||||
return false;
|
||||
return m_GamePads[controller].buttons[static_cast<int>(button)] &&
|
||||
!m_GamePads[controller].prevButtons[static_cast<int>(button)];
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,34 @@
|
||||
struct GamePad{
|
||||
bool buttons[SDL_CONTROLLER_BUTTON_MAX];
|
||||
float axis[SDL_CONTROLLER_AXIS_MAX];
|
||||
|
||||
bool prevButtons[SDL_CONTROLLER_BUTTON_MAX]{ false };
|
||||
};
|
||||
|
||||
enum class GamePadButton {
|
||||
Invalid = -1,
|
||||
A = 0,
|
||||
B,
|
||||
X,
|
||||
Y,
|
||||
Back,
|
||||
Guide,
|
||||
Start,
|
||||
LeftStick,
|
||||
RightStick,
|
||||
LeftBumper,
|
||||
RightBumper,
|
||||
DPadUp,
|
||||
DPadDown,
|
||||
DPadLeft,
|
||||
DPadRight,
|
||||
Misc1, // Share button or similar
|
||||
Paddle1, // Elite paddle P1
|
||||
Paddle2, // Elite paddle P3
|
||||
Paddle3, // Elite paddle P2
|
||||
Paddle4, // Elite paddle P4
|
||||
Touchpad, // PS4/PS5 touchpad button
|
||||
Max
|
||||
};
|
||||
|
||||
enum Controllers {PLAYER1, PLAYER2, PLAYER3, PLAYER4};
|
||||
@@ -26,8 +54,9 @@ public:
|
||||
~GamePadController();
|
||||
void Init();
|
||||
void Update();
|
||||
bool IsButtonDown(Controllers controller, int button) const;
|
||||
bool IsButtonUp(Controllers controller, int button) const;
|
||||
bool IsButtonDown(Controllers controller, GamePadButton button) const;
|
||||
bool isButtonPressed(Controllers controller, GamePadButton button) const;
|
||||
bool IsButtonUp(Controllers controller, GamePadButton button) const;
|
||||
|
||||
float GetAxis(Controllers controller, int axis) const;
|
||||
|
||||
@@ -37,6 +66,7 @@ private:
|
||||
GamePadController();
|
||||
std::vector<SDL_GameController*> m_pGameControllers;
|
||||
std::vector<GamePad> m_GamePads;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef GP1_DIRECTX_MATERIAL_H
|
||||
#define GP1_DIRECTX_MATERIAL_H
|
||||
|
||||
|
||||
#include "Texture.h"
|
||||
|
||||
struct Material {
|
||||
@@ -18,5 +17,4 @@ struct Material {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif //GP1_DIRECTX_MATERIAL_H
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "Effects/Effect.h"
|
||||
#include "Effects/FireEffect.h"
|
||||
#include "HitTest.h"
|
||||
#include "Scenes/MainScene.h"
|
||||
#include "Scenes/DioramaScene.h"
|
||||
|
||||
|
||||
|
||||
namespace dae {
|
||||
|
||||
@@ -18,73 +22,21 @@ namespace dae {
|
||||
const HRESULT result = InitializeDirectX();
|
||||
if (result == S_OK) {
|
||||
m_IsInitialized = true;
|
||||
std::cout << "DirectX is initialized and ready!\n";
|
||||
std::cout << GREEN << "DirectX is initialized and ready!" << RESET << std::endl;
|
||||
} else {
|
||||
std::cout << "DirectX initialization failed!\n";
|
||||
std::cout << RED << "DirectX initialization failed!" << RESET << std::endl;
|
||||
}
|
||||
|
||||
InitializeSDLRasterizer();
|
||||
|
||||
std::vector<VertexIn> vertices{};
|
||||
std::vector<uint32_t> indices{};
|
||||
|
||||
if (Utils::ParseOBJNew("resources/vehicle.obj", vertices, indices, false)) {
|
||||
std::cout << "Model Loaded" << std::endl;
|
||||
|
||||
} else {
|
||||
std::cout << "Model failed to load" << std::endl;
|
||||
assert(true && "Model failed to load");
|
||||
}
|
||||
|
||||
std::cout << "Vertices: " << vertices.size() << " Indices: " << indices.size() << std::endl;
|
||||
|
||||
std::shared_ptr<Material> vehicleMaterial = std::make_shared<Material>();
|
||||
vehicleMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/vehicle_diffuse.png", m_DevicePtr);
|
||||
vehicleMaterial->normalTexturePtr = Texture::LoadFromFile("resources/vehicle_normal.png", m_DevicePtr);
|
||||
vehicleMaterial->specularTexturePtr = Texture::LoadFromFile("resources/vehicle_specular.png", m_DevicePtr);
|
||||
vehicleMaterial->glossTexturePtr = Texture::LoadFromFile("resources/vehicle_gloss.png", m_DevicePtr);
|
||||
|
||||
Effect* effect = new Effect(m_DevicePtr, L"resources/PosCol3D.fx");
|
||||
m_meshes.push_back(new Mesh(m_DevicePtr, vertices, indices, vehicleMaterial, effect));
|
||||
|
||||
|
||||
|
||||
indices.clear();
|
||||
vertices.clear();
|
||||
if(Utils::ParseOBJNew("resources/fireFX.obj", vertices, indices, false)){
|
||||
std::cout << "Model Loaded" << std::endl;
|
||||
} else {
|
||||
std::cout << "Model failed to load" << std::endl;
|
||||
assert(true && "Model failed to load");
|
||||
}
|
||||
|
||||
std::shared_ptr<Material> FireMaterial = std::make_shared<Material>();
|
||||
FireMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/fireFX_diffuse.png", m_DevicePtr);
|
||||
|
||||
FireEffect* fireEffect = new FireEffect(m_DevicePtr, L"resources/Fire.fx");
|
||||
m_meshes.push_back(new Mesh(m_DevicePtr, vertices, indices, FireMaterial, fireEffect));
|
||||
|
||||
m_pFireMesh = m_meshes.back();
|
||||
|
||||
//
|
||||
// std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
||||
// Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, m_DevicePtr);
|
||||
// for (const auto &mesh: materialMeshes) {
|
||||
// if(mesh->vertices.size() > 0) {
|
||||
// Effect *effect = new Effect(m_DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
// std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||
// material->diffuseTexturePtr = Texture::LoadFromFile("./resources/" + mesh->diffuse_texture, m_DevicePtr);
|
||||
// m_meshes.push_back(new Mesh(m_DevicePtr, mesh->vertices, mesh->indices, material, effect));
|
||||
// Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
// worldMatrix *= Matrix::CreateScale(2.f, 2.f, 2.f);
|
||||
// m_meshes.back()->SetWorldMatrix(worldMatrix);
|
||||
// }
|
||||
// }
|
||||
m_pScene = new MainScene();
|
||||
m_pScene->Initialize(m_DevicePtr);
|
||||
|
||||
m_pFireMesh = m_pScene->GetMeshes().back();
|
||||
|
||||
float aspectRatio = static_cast<float>(m_Width) / static_cast<float>(m_Height);
|
||||
m_Camera = Camera({.0f, 5.0f, -64.f}, 45.f);
|
||||
m_Camera.Initialize(45.f, {.0f, 5.0f, -64.f}, aspectRatio);
|
||||
m_Camera = Camera({.0f, .0f, .0f}, 45.f);
|
||||
m_Camera.Initialize(45.f, {.0f, .0f, .0f}, aspectRatio);
|
||||
}
|
||||
|
||||
Renderer::~Renderer() {
|
||||
@@ -104,10 +56,8 @@ namespace dae {
|
||||
|
||||
m_DevicePtr->Release();
|
||||
|
||||
for (auto mesh: m_meshes) {
|
||||
delete mesh;
|
||||
}
|
||||
|
||||
m_pScene->Cleanup();
|
||||
delete m_pScene;
|
||||
//SDL
|
||||
|
||||
SDL_FreeSurface(m_pBackBuffer);
|
||||
@@ -120,16 +70,24 @@ namespace dae {
|
||||
void Renderer::Update(const Timer *pTimer) {
|
||||
m_Camera.Update(pTimer);
|
||||
|
||||
for (auto mesh: m_meshes) {
|
||||
for (auto mesh: m_pScene->GetMeshes()) {
|
||||
mesh->SetCameraPos(m_Camera.GetPosition());
|
||||
}
|
||||
if (m_Rotating) {
|
||||
m_currentRotation += pTimer->GetElapsed();
|
||||
Matrix world = Matrix::CreateRotationY(m_currentRotation);
|
||||
for (auto mesh: m_meshes) {
|
||||
float rotationThisFrame = pTimer->GetElapsed() * (45.0f * TO_RADIANS); // 45 degrees/sec to radians/sec
|
||||
|
||||
m_currentRotation += rotationThisFrame;
|
||||
|
||||
Matrix rotationMatrix = Matrix::CreateRotationY(rotationThisFrame);
|
||||
|
||||
for (auto mesh : m_pScene->GetMeshes()) {
|
||||
Matrix originalWorldMatrix = mesh->GetWorldMatrix();
|
||||
Matrix world = rotationMatrix * originalWorldMatrix;
|
||||
|
||||
mesh->SetWorldMatrix(world);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Renderer::Render() {
|
||||
@@ -145,18 +103,14 @@ namespace dae {
|
||||
|
||||
void Renderer::RenderDirectX() const {
|
||||
//Clear back buffer
|
||||
if(m_UniformClearColor){
|
||||
const float clearColor[] = {static_cast<float>(r) / 255.f, static_cast<float>(g) / 255.f, static_cast<float>(b) / 255.f, 1.f};
|
||||
m_DeviceContextPtr->ClearRenderTargetView(m_RenderTargetViewPtr, clearColor);
|
||||
} else {
|
||||
const float clearColor[] = {1.f / 255.f, 0.f / 255.f, 76.f / 255.f, 1.f};
|
||||
m_DeviceContextPtr->ClearRenderTargetView(m_RenderTargetViewPtr, clearColor);
|
||||
}
|
||||
ColorRGB ChosenClearColor = m_UseUniformClearColor ? m_UniformClearColor: DirectXClearColor;
|
||||
const float clearColor[] = {static_cast<float>(ChosenClearColor.r) / 255.f, static_cast<float>(ChosenClearColor.g) / 255.f, static_cast<float>(ChosenClearColor.b) / 255.f, 1.f};
|
||||
m_DeviceContextPtr->ClearRenderTargetView(m_RenderTargetViewPtr, clearColor);
|
||||
|
||||
m_DeviceContextPtr->ClearDepthStencilView(m_DepthStencilViewPtr, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
|
||||
|
||||
Matrix viewProjMatrix = m_Camera.GetViewProjectionMatrix();
|
||||
for (auto mesh: m_meshes) {
|
||||
for (auto mesh: m_pScene->GetMeshes()) {
|
||||
if(mesh->GetShouldRender()){
|
||||
Matrix modelMatrix = mesh->GetWorldMatrix();
|
||||
Matrix worldViewProjMatrix = modelMatrix * viewProjMatrix;
|
||||
@@ -170,19 +124,19 @@ namespace dae {
|
||||
}
|
||||
|
||||
void Renderer::RenderSDL() {
|
||||
SDL_FillRect(m_pBackBuffer, nullptr, m_ClearColor);
|
||||
ColorRGB ChosenClearColor = m_UseUniformClearColor ? m_UniformClearColor : m_ClearColorSoftware;
|
||||
SDL_FillRect(m_pBackBuffer, nullptr, SDL_MapRGB(m_pBackBuffer->format, ChosenClearColor.r, ChosenClearColor.g, ChosenClearColor.b));
|
||||
|
||||
SDL_LockSurface(m_pBackBuffer);
|
||||
std::fill_n(m_pDepthBufferPixels, m_Width * m_Height, std::numeric_limits<float>::max());
|
||||
|
||||
SDL_FillRect(m_pBackBuffer, nullptr, m_ClearColor);
|
||||
|
||||
ColorRGB finalColor{};
|
||||
constexpr int numVerticies = 3;
|
||||
|
||||
m_VerticiesScreenSpace.clear();
|
||||
|
||||
|
||||
for (auto* currentMesh: m_meshes) {
|
||||
for (auto* currentMesh: m_pScene->GetMeshes()) {
|
||||
|
||||
if(!currentMesh->GetShouldRender()){
|
||||
continue;
|
||||
@@ -479,6 +433,9 @@ namespace dae {
|
||||
|
||||
void Renderer::ToggleDepthBuffer() {
|
||||
m_isDepthBuffer = !m_isDepthBuffer;
|
||||
|
||||
std::string mode = m_isDepthBuffer ? "ON" : "OFF";
|
||||
std::cout << MAGENTA << "[SOFTWARE]" << BLUE << " Depth Buffer " << mode << RESET << std::endl;
|
||||
}
|
||||
|
||||
ColorRGB Renderer::ShadePixel(const Sample &sample) {
|
||||
@@ -515,7 +472,6 @@ namespace dae {
|
||||
normal = tangentToWorld.TransformVector(normalMapSample).Normalized();
|
||||
}
|
||||
|
||||
|
||||
const ColorRGB diffuseSample{ currentMaterial->diffuseTexturePtr->Sample(sample.uv) };
|
||||
double invPi = 1.0 / PI;
|
||||
const ColorRGB lambert{ diffuseSample * lightIntensity * invPi };
|
||||
@@ -558,68 +514,151 @@ namespace dae {
|
||||
}
|
||||
|
||||
void Renderer::CycleCullMode() {
|
||||
for(auto mesh: m_meshes){
|
||||
for(auto mesh: m_pScene->GetMeshes()){
|
||||
mesh->CycleCullMode();
|
||||
}
|
||||
|
||||
std::string mode;
|
||||
switch(m_CullMode){
|
||||
case CullMode::None:
|
||||
m_CullMode = CullMode::Front;
|
||||
mode = "Front";
|
||||
break;
|
||||
case CullMode::Front:
|
||||
m_CullMode = CullMode::Back;
|
||||
mode = "Back";
|
||||
break;
|
||||
case CullMode::Back:
|
||||
m_CullMode = CullMode::None;
|
||||
mode = "None";
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << MAGENTA << "[HARDWARE]" << BLUE << " Cull Mode = " << mode << RESET << std::endl;
|
||||
}
|
||||
|
||||
void Renderer::ToggleBoundingBox() {
|
||||
m_isHitbox = !m_isHitbox;
|
||||
|
||||
std::string mode = m_isHitbox ? "ON" : "OFF";
|
||||
std::cout << MAGENTA << "[SOFTWARE]" << BLUE << " Hitbox " << mode << RESET << std::endl;
|
||||
}
|
||||
|
||||
void Renderer::CycleRenderingMode() {
|
||||
|
||||
std::string mode;
|
||||
|
||||
switch (m_ShadeMode) {
|
||||
case ShadeMode::ObservedArea:
|
||||
m_ShadeMode = ShadeMode::Diffuse;
|
||||
std::cout << "Diffuse" << std::endl;
|
||||
mode = "Diffuse";
|
||||
break;
|
||||
case ShadeMode::Diffuse:
|
||||
m_ShadeMode = ShadeMode::Specular;
|
||||
std::cout << "Specular" << std::endl;
|
||||
mode = "Specular";
|
||||
break;
|
||||
case ShadeMode::Specular:
|
||||
m_ShadeMode = ShadeMode::Combined;
|
||||
std::cout << "Combined" << std::endl;
|
||||
mode = "Combined";
|
||||
break;
|
||||
case ShadeMode::Combined:
|
||||
m_ShadeMode = ShadeMode::ObservedArea;
|
||||
std::cout << "Observed Area" << std::endl;
|
||||
mode = "Observed Area";
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << MAGENTA << "[SOFTWARE]" << BLUE << " Shading Mode = " << mode << RESET << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void Renderer::SwitchBackend() {
|
||||
if (m_backendType == Backendtype::DirectX) {
|
||||
m_backendType = Backendtype::SDL;
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Rasterizer mode = SOFTWARE" << RESET << std::endl;
|
||||
} else {
|
||||
m_backendType = Backendtype::DirectX;
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Rasterizer mode = HARDWARE" << RESET << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::NextSamplingState() {
|
||||
for(auto mesh: m_meshes){
|
||||
for(auto mesh: m_pScene->GetMeshes()){
|
||||
mesh->NextSamplingState();
|
||||
}
|
||||
|
||||
std::string mode;
|
||||
switch(m_TechniqueType){
|
||||
case TechniqueType::Point:
|
||||
m_TechniqueType = TechniqueType::Linear;
|
||||
mode = "Linear";
|
||||
break;
|
||||
case TechniqueType::Linear:
|
||||
m_TechniqueType = TechniqueType::Anisotropic;
|
||||
mode = "Anisotropic";
|
||||
break;
|
||||
case TechniqueType::Anisotropic:
|
||||
m_TechniqueType = TechniqueType::Point;
|
||||
mode = "Point";
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << MAGENTA << "[HARDWARE]" << BLUE << " Texture Sampling Mode = " << mode << RESET << std::endl;
|
||||
}
|
||||
|
||||
void Renderer::ToggleNormals() {
|
||||
m_useNormals = !m_useNormals;
|
||||
for(auto mesh: m_meshes){
|
||||
for(auto mesh: m_pScene->GetMeshes()){
|
||||
mesh->ToggleNormals();
|
||||
}
|
||||
std::string mode = m_useNormals ? "ON" : "OFF";
|
||||
std::cout << MAGENTA << "[SOFTWARE]" << BLUE << " Normal Map " << mode << RESET << std::endl;
|
||||
}
|
||||
|
||||
void Renderer::ToggleRotation() {
|
||||
m_Rotating = !m_Rotating;
|
||||
std::string mode = m_Rotating ? "ON" : "OFF";
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Model Rotation " << mode << RESET << std::endl;
|
||||
}
|
||||
|
||||
void Renderer::ToggleUniformClearColor() {
|
||||
m_UniformClearColor = !m_UniformClearColor;
|
||||
m_UseUniformClearColor = !m_UseUniformClearColor;
|
||||
std::string mode = m_UseUniformClearColor ? "ON" : "OFF";
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Uniform Clear Color " << mode << RESET << std::endl;
|
||||
}
|
||||
|
||||
void Renderer::ToggleFireFX() {
|
||||
m_pFireMesh->SetShouldRender(!m_pFireMesh->GetShouldRender());
|
||||
if(m_pFireMesh != nullptr){
|
||||
m_pFireMesh->SetShouldRender(!m_pFireMesh->GetShouldRender());
|
||||
std::string mode = m_pFireMesh->GetShouldRender() ? "ON" : "OFF";
|
||||
std::cout << MAGENTA << "[HARDWARE]" << BLUE << " FireFX " << mode << RESET << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::NextScene() {
|
||||
m_pScene->Cleanup();
|
||||
delete m_pScene;
|
||||
if(m_CurrentScene == SceneNames::Main){
|
||||
m_pScene = new DioramaScene();
|
||||
m_pFireMesh = nullptr;
|
||||
m_CurrentScene = SceneNames::Diorama;
|
||||
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Diorama" << RESET << std::endl;
|
||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||
|
||||
} else {
|
||||
m_pScene = new MainScene();
|
||||
m_CurrentScene = SceneNames::Main;
|
||||
|
||||
std::cout << MAGENTA << "[SHARED]" << BLUE << " Scene = Main" << RESET << std::endl;
|
||||
std::cout << MAGENTA << "This could take a second" << RESET << std::endl;
|
||||
}
|
||||
m_pScene->Initialize(m_DevicePtr);
|
||||
|
||||
|
||||
if(m_CurrentScene == SceneNames::Main) {
|
||||
//Kind of sloppy fix but hey :p
|
||||
m_pFireMesh = m_pScene->GetMeshes().back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "Mesh.h"
|
||||
#include "Camera.h"
|
||||
#include "HitTest.h"
|
||||
#include "Scenes/BaseScene.h"
|
||||
#include "Effects/Effect.h"
|
||||
|
||||
struct SDL_Window;
|
||||
struct SDL_Surface;
|
||||
@@ -19,6 +21,11 @@ enum class ShadeMode{
|
||||
Combined
|
||||
};
|
||||
|
||||
enum class SceneNames{
|
||||
Main,
|
||||
Diorama
|
||||
};
|
||||
|
||||
namespace dae
|
||||
{
|
||||
class Renderer final
|
||||
@@ -55,6 +62,8 @@ namespace dae
|
||||
|
||||
void ToggleFireFX();
|
||||
|
||||
void NextScene();
|
||||
|
||||
private:
|
||||
// Common vars
|
||||
SDL_Window* m_pWindow{};
|
||||
@@ -62,16 +71,18 @@ namespace dae
|
||||
int m_Width{};
|
||||
int m_Height{};
|
||||
|
||||
std::vector<Mesh*> m_meshes{};
|
||||
std::vector<std::shared_ptr<Material>> m_materials{};
|
||||
|
||||
Backendtype m_backendType{ Backendtype::DirectX };
|
||||
|
||||
BaseScene* m_pScene{};
|
||||
SceneNames m_CurrentScene{ SceneNames::Main };
|
||||
|
||||
Camera m_Camera{};
|
||||
|
||||
bool m_Rotating{ false };
|
||||
float m_currentRotation{};
|
||||
bool m_UniformClearColor{ false };
|
||||
bool m_UseUniformClearColor{ false };
|
||||
|
||||
ColorRGB m_UniformClearColor{ ColorRGB{0.1f * 255.f, 0.1f * 255.f, 0.1 * 255.f} };
|
||||
|
||||
|
||||
//DirectX vars
|
||||
@@ -81,9 +92,14 @@ namespace dae
|
||||
HRESULT InitializeDirectX();
|
||||
void RenderDirectX() const;
|
||||
|
||||
ColorRGB DirectXClearColor{ .39f * 255.f, .59f * 255.f, .93f * 255.f };
|
||||
|
||||
//Storing the mesh so i can deactivate it;
|
||||
Mesh* m_pFireMesh{};
|
||||
|
||||
TechniqueType m_TechniqueType{ TechniqueType::Linear };
|
||||
CullMode m_CullMode{ CullMode::Back };
|
||||
|
||||
ID3D11Device* m_DevicePtr{};
|
||||
ID3D11DeviceContext* m_DeviceContextPtr{};
|
||||
IDXGISwapChain* m_SwapChainPtr{};
|
||||
@@ -110,14 +126,10 @@ namespace dae
|
||||
bool m_isDepthBuffer{ false };
|
||||
|
||||
|
||||
Uint8 r{100};
|
||||
Uint8 g{100};
|
||||
Uint8 b{100};
|
||||
Uint32 m_ClearColor{ Uint32(255 << 24) + Uint32(r << 16) + Uint32(g << 8) + Uint32(b) };
|
||||
ColorRGB m_ClearColorSoftware{ .39f * 255.f, .39f * 255.f, .39f * 255.f };
|
||||
|
||||
float* m_pDepthBufferPixels{};
|
||||
|
||||
std::vector<VertexOut> m_VerticiesScreenSpace{};
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
5
project/src/Scenes/BaseScene.cpp
Normal file
5
project/src/Scenes/BaseScene.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Bram on 25/12/2024.
|
||||
//
|
||||
|
||||
#include "BaseScene.h"
|
||||
32
project/src/Scenes/BaseScene.h
Normal file
32
project/src/Scenes/BaseScene.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef GP1_DIRECTX_BASESCENE_H
|
||||
#define GP1_DIRECTX_BASESCENE_H
|
||||
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "../Mesh.h"
|
||||
#include "../Material.h"
|
||||
|
||||
|
||||
class BaseScene {
|
||||
public:
|
||||
BaseScene() = default;
|
||||
|
||||
virtual ~BaseScene() = default;
|
||||
|
||||
virtual void Initialize(ID3D11Device *DevicePtr) = 0;
|
||||
|
||||
// virtual void Update() = 0;
|
||||
|
||||
// virtual void Render() = 0;
|
||||
|
||||
virtual void Cleanup() = 0;
|
||||
|
||||
virtual std::vector<Mesh*>& GetMeshes() = 0;
|
||||
virtual std::vector<std::shared_ptr<Material>>& GetMaterials() = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif //GP1_DIRECTX_BASESCENE_H
|
||||
80
project/src/Scenes/DioramaScene.cpp
Normal file
80
project/src/Scenes/DioramaScene.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// Created by Bram on 25/12/2024.
|
||||
//
|
||||
|
||||
#include "DioramaScene.h"
|
||||
#include "../Utils.h"
|
||||
#include "../Effects/Effect.h"
|
||||
#include "../Effects/FireEffect.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
void DioramaScene::Initialize(ID3D11Device *DevicePtr) {
|
||||
|
||||
std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
||||
Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
|
||||
for (const auto &mesh: materialMeshes) {
|
||||
if(mesh->vertices.size() > 0) {
|
||||
std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||
BaseEffect *effect{ nullptr };
|
||||
|
||||
if(mesh->opacity_map != ""){
|
||||
// std::cout << "Opacity map found" << mesh->opacity_map << std::endl;
|
||||
effect = new FireEffect(DevicePtr, L"resources/Fire.fx");
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||
// material-> = Texture::LoadFromFile("./resources/" + mesh->opacity_map, DevicePtr);
|
||||
} else {
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
|
||||
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
}
|
||||
|
||||
|
||||
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateScale(2.f, 2.f, 2.f);
|
||||
worldMatrix *= Matrix::CreateScale(-1.f, 1.f, 1.f);
|
||||
m_meshes.back()->SetWorldMatrix(worldMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
materialMeshes.clear();
|
||||
Utils::LoadObjWithMaterials("resources/brok/brok.obj", materialMeshes, true, DevicePtr);
|
||||
for (const auto &mesh: materialMeshes) {
|
||||
if(mesh->vertices.size() > 0) {
|
||||
std::shared_ptr<Material> material = std::make_shared<Material>();
|
||||
BaseEffect *effect{ nullptr };
|
||||
|
||||
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
|
||||
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/brok/" + mesh->diffuse_texture, DevicePtr);
|
||||
|
||||
|
||||
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateRotationY(3.14f / 2.f);
|
||||
worldMatrix *= Matrix::CreateScale(0.021f, 0.021f, 0.021f);
|
||||
worldMatrix *= Matrix::CreateScale(-1.f, 1.f, 1.f);
|
||||
worldMatrix *= Matrix::CreateTranslation(-8.55f, 12.33f, 0.69f);
|
||||
m_meshes.back()->SetWorldMatrix(worldMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Mesh *> &DioramaScene::GetMeshes() {
|
||||
return m_meshes;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Material>> &DioramaScene::GetMaterials() {
|
||||
return m_materials;
|
||||
}
|
||||
|
||||
void DioramaScene::Cleanup() {
|
||||
for (Mesh *mesh : m_meshes) {
|
||||
delete mesh;
|
||||
}
|
||||
m_meshes.clear();
|
||||
m_materials.clear();
|
||||
}
|
||||
21
project/src/Scenes/DioramaScene.h
Normal file
21
project/src/Scenes/DioramaScene.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef GP1_DIRECTX_DIORAMASCENE_H
|
||||
#define GP1_DIRECTX_DIORAMASCENE_H
|
||||
|
||||
#include "BaseScene.h"
|
||||
|
||||
class DioramaScene : public BaseScene {
|
||||
public:
|
||||
void Cleanup() override;
|
||||
|
||||
void Initialize(ID3D11Device *DevicePtr) override;
|
||||
|
||||
std::vector<Mesh *> &GetMeshes() override;
|
||||
|
||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||
private:
|
||||
std::vector<Mesh *> m_meshes{};
|
||||
std::vector<std::shared_ptr<Material>> m_materials{};
|
||||
|
||||
};
|
||||
|
||||
#endif //GP1_DIRECTX_DIORAMASCENE_H
|
||||
71
project/src/Scenes/MainScene.cpp
Normal file
71
project/src/Scenes/MainScene.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// Created by Bram on 25/12/2024.
|
||||
//
|
||||
|
||||
#include "MainScene.h"
|
||||
#include "../pch.h"
|
||||
#include "../Utils.h"
|
||||
#include "../Effects/Effect.h"
|
||||
#include "../Effects/FireEffect.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
|
||||
void MainScene::Initialize(ID3D11Device *DevicePtr) {
|
||||
|
||||
std::vector<VertexIn> vertices{};
|
||||
std::vector<uint32_t> indices{};
|
||||
|
||||
if (!Utils::ParseOBJNew("resources/vehicle.obj", vertices, indices, false)) {
|
||||
assert(true && "Model failed to load");
|
||||
}
|
||||
|
||||
std::shared_ptr<Material> vehicleMaterial = std::make_shared<Material>();
|
||||
vehicleMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/vehicle_diffuse.png", DevicePtr);
|
||||
vehicleMaterial->normalTexturePtr = Texture::LoadFromFile("resources/vehicle_normal.png", DevicePtr);
|
||||
vehicleMaterial->specularTexturePtr = Texture::LoadFromFile("resources/vehicle_specular.png", DevicePtr);
|
||||
vehicleMaterial->glossTexturePtr = Texture::LoadFromFile("resources/vehicle_gloss.png", DevicePtr);
|
||||
|
||||
auto* effect = new Effect(DevicePtr, L"resources/PosCol3D.fx");
|
||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, vehicleMaterial, effect));
|
||||
|
||||
|
||||
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateTranslation(0, 0, 50.f);
|
||||
m_meshes.back()->SetWorldMatrix(worldMatrix);
|
||||
|
||||
|
||||
|
||||
indices.clear();
|
||||
vertices.clear();
|
||||
if(!Utils::ParseOBJNew("resources/fireFX.obj", vertices, indices, false)){
|
||||
assert(true && "Model failed to load");
|
||||
}
|
||||
|
||||
std::shared_ptr<Material> FireMaterial = std::make_shared<Material>();
|
||||
FireMaterial->diffuseTexturePtr = Texture::LoadFromFile("resources/fireFX_diffuse.png", DevicePtr);
|
||||
|
||||
auto* fireEffect = new FireEffect(DevicePtr, L"resources/Fire.fx");
|
||||
m_meshes.push_back(new Mesh(DevicePtr, vertices, indices, FireMaterial, fireEffect));
|
||||
|
||||
worldMatrix = m_meshes.back()->GetWorldMatrix();
|
||||
worldMatrix *= Matrix::CreateTranslation(0, 0, 50.f);
|
||||
m_meshes.back()->SetWorldMatrix(worldMatrix);
|
||||
}
|
||||
|
||||
|
||||
void MainScene::Cleanup() {
|
||||
for (Mesh* mesh : m_meshes) {
|
||||
delete mesh;
|
||||
}
|
||||
m_meshes.clear();
|
||||
}
|
||||
|
||||
std::vector<Mesh *> &MainScene::GetMeshes() {
|
||||
return m_meshes;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Material>> &MainScene::GetMaterials() {
|
||||
return m_materials;
|
||||
}
|
||||
|
||||
32
project/src/Scenes/MainScene.h
Normal file
32
project/src/Scenes/MainScene.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef GP1_DIRECTX_MAINSCENE_H
|
||||
#define GP1_DIRECTX_MAINSCENE_H
|
||||
|
||||
|
||||
#include "BaseScene.h"
|
||||
#include "../Mesh.h"
|
||||
#include "../Material.h"
|
||||
#include "../Camera.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class MainScene : public BaseScene {
|
||||
public:
|
||||
void Initialize(ID3D11Device* DevicePtr) override;
|
||||
|
||||
void Cleanup() override;
|
||||
|
||||
std::vector<Mesh *> &GetMeshes() override;
|
||||
|
||||
std::vector<std::shared_ptr<Material>> &GetMaterials() override;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Mesh*> m_meshes{};
|
||||
std::vector<std::shared_ptr<Material>> m_materials{};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //GP1_DIRECTX_MAINSCENE_H
|
||||
@@ -6,6 +6,24 @@
|
||||
#include "Mesh.h"
|
||||
#include "tiny_obj_loader.h"
|
||||
|
||||
#define RESET "\033[0m"
|
||||
#define BLACK "\033[30m" /* Black */
|
||||
#define RED "\033[31m" /* Red */
|
||||
#define GREEN "\033[32m" /* Green */
|
||||
#define YELLOW "\033[33m" /* Yellow */
|
||||
#define BLUE "\033[34m" /* Blue */
|
||||
#define MAGENTA "\033[35m" /* Magenta */
|
||||
#define CYAN "\033[36m" /* Cyan */
|
||||
#define WHITE "\033[37m" /* White */
|
||||
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
|
||||
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
|
||||
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
|
||||
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
|
||||
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
|
||||
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
|
||||
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
|
||||
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
|
||||
|
||||
namespace dae {
|
||||
namespace Utils {
|
||||
//Just parses vertices and indices
|
||||
@@ -262,6 +280,7 @@ namespace dae {
|
||||
std::vector<uint32_t> indices;
|
||||
int material_id = -1; // Material ID associated with this mesh
|
||||
std::string diffuse_texture; // Path to the diffuse texture
|
||||
std::string opacity_map;
|
||||
};
|
||||
|
||||
|
||||
@@ -272,8 +291,7 @@ namespace dae {
|
||||
std::vector<tinyobj::material_t> materials;
|
||||
std::string warn, err;
|
||||
|
||||
std::string basepath = "resources/";
|
||||
|
||||
std::string basepath = fileName.substr(0, fileName.find_last_of("/\\") + 1);
|
||||
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, fileName.c_str(), basepath.c_str())) {
|
||||
if (!warn.empty()) {
|
||||
std::cerr << "Warning: " << warn << std::endl;
|
||||
@@ -284,17 +302,19 @@ namespace dae {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear and prepare the meshes array
|
||||
meshes.clear();
|
||||
|
||||
// Create Mesh objects for each material
|
||||
meshes.resize(materials.size());
|
||||
for (size_t i = 0; i < materials.size(); ++i) {
|
||||
meshes[i] = std::make_unique<MaterialMesh>();
|
||||
meshes[i]->material_id = static_cast<int>(i);
|
||||
meshes[i]->diffuse_texture = materials[i].diffuse_texname;
|
||||
}
|
||||
|
||||
// Check and assign opacity map
|
||||
if (!materials[i].alpha_texname.empty()) {
|
||||
meshes[i]->opacity_map = materials[i].alpha_texname;
|
||||
}
|
||||
}
|
||||
// Default Mesh for faces with no material
|
||||
auto defaultMesh = std::make_unique<MaterialMesh>();
|
||||
defaultMesh->material_id = -1;
|
||||
@@ -357,10 +377,15 @@ namespace dae {
|
||||
targetMesh->vertices.push_back(vertex);
|
||||
}
|
||||
|
||||
// Push indices in the default order
|
||||
targetMesh->indices.push_back(tempIndices[0]);
|
||||
targetMesh->indices.push_back(tempIndices[1]);
|
||||
targetMesh->indices.push_back(tempIndices[2]);
|
||||
if (flipAxisAndWinding) {
|
||||
targetMesh->indices.push_back(tempIndices[0]);
|
||||
targetMesh->indices.push_back(tempIndices[2]);
|
||||
targetMesh->indices.push_back(tempIndices[1]);
|
||||
} else {
|
||||
targetMesh->indices.push_back(tempIndices[0]);
|
||||
targetMesh->indices.push_back(tempIndices[1]);
|
||||
targetMesh->indices.push_back(tempIndices[2]);
|
||||
}
|
||||
|
||||
index_offset += fv;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "Renderer.h"
|
||||
#include "GamePadController.h"
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace dae;
|
||||
|
||||
@@ -18,6 +19,106 @@ void ShutDown(SDL_Window *pWindow) {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PrintInfo(){
|
||||
std::cout << YELLOW << "[Key Bindings - SHARED]" << RESET << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F1] | [A]" << BLUE << " Toggle Rasterizer Mode" << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F2] | [B]" << BLUE << " Toggle Rotation" << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F9] | [Right Shoulder]" << BLUE << " Cycle Cull Mode" << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F10] | [Left Shoulder]" << BLUE << " Toggle Uniform Clear Color" << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F11] | [Start]" << BLUE << " Toggle Print FPS" <<std::endl;
|
||||
std::cout << RESET << std::endl;
|
||||
|
||||
|
||||
std::cout << YELLOW << "[Key Bindings - HARDWARE]" << RESET << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F3] | [Dpad UP]" << BLUE << " Toggle FireFX mesh" << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F4] | [Dpad DOWN]" << BLUE << " Toggle Texture Sampling States" << std::endl;
|
||||
std::cout << RESET << std::endl;
|
||||
|
||||
std::cout << YELLOW << "[Key Bindings - SOFTWARE]" << RESET << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F5] | [X]" << BLUE << " Cycle Shading Mode" << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F6] | [Dpad LEFT]" << BLUE << " Toggle Normal Mapping" << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F7] | [Y]" << BLUE << " Toggle Depth Buffer" << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[F8] | [Dpad RIGHT]" << BLUE << " Toggle BoundingBox" << std::endl;
|
||||
std::cout << RESET << std::endl;
|
||||
|
||||
std::cout << YELLOW << "[Key Bindings - CUSTOM]" << RESET << std::endl;
|
||||
std::cout << "\t" << BOLDWHITE "[N] | [Back]" << BLUE << " Next Scene" << std::endl;
|
||||
std::cout << RESET << std::endl;
|
||||
//empty line
|
||||
}
|
||||
|
||||
void CheckController(Renderer* pRenderer, bool& printFPS){
|
||||
//Check for controller buttons
|
||||
Controllers controller = Controllers::PLAYER1;
|
||||
GamePadController* pGamePad = &GamePadController::GetInstance();
|
||||
|
||||
auto isButtonDown = [pGamePad, controller](GamePadButton button){
|
||||
return pGamePad->isButtonPressed(controller, button);
|
||||
};
|
||||
|
||||
if(isButtonDown(GamePadButton::A)){
|
||||
//Switch backend
|
||||
pRenderer->SwitchBackend();
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::B)){
|
||||
//Toggle rotation
|
||||
pRenderer->ToggleRotation();
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::X)){
|
||||
//Cycle shading mode
|
||||
pRenderer->CycleRenderingMode();
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::Y)){
|
||||
//Toggle Depth Buffer
|
||||
pRenderer->ToggleDepthBuffer();
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::DPadUp)){
|
||||
//Toggle FireFX mesh
|
||||
pRenderer->ToggleFireFX();
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::DPadDown)){
|
||||
//Toggle texture sampling states
|
||||
pRenderer->NextSamplingState();
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::DPadLeft)){
|
||||
//Toggle normal mapping
|
||||
pRenderer->ToggleNormals();
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::DPadRight)){
|
||||
//Toggle BoundingBox
|
||||
pRenderer->ToggleBoundingBox();
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::RightBumper)){
|
||||
//Cycle Cull mode
|
||||
pRenderer->CycleCullMode();
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::LeftBumper)){
|
||||
//Toggle Uniform Clear Color
|
||||
pRenderer->ToggleUniformClearColor();
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::Start)){
|
||||
//Toggle Print fps
|
||||
printFPS = !printFPS;
|
||||
}
|
||||
|
||||
if(isButtonDown(GamePadButton::Back)){
|
||||
//Next Scene
|
||||
pRenderer->NextScene();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *args[]) {
|
||||
//Unreferenced parameters
|
||||
(void) argc;
|
||||
@@ -41,12 +142,14 @@ int main(int argc, char *args[]) {
|
||||
|
||||
|
||||
int joysticks = SDL_NumJoysticks();
|
||||
std::cout << "Number of joysticks connected: " << joysticks << std::endl;
|
||||
std::cout << RESET << "Number of joysticks connected: " << RED << joysticks << RESET << std::endl;
|
||||
|
||||
GamePadController::GetInstance().Init();
|
||||
|
||||
PrintInfo();
|
||||
|
||||
//Initialize "framework"
|
||||
|
||||
//Initialize "framework"
|
||||
const auto pTimer = new Timer();
|
||||
const auto pRenderer = new Renderer(pWindow);
|
||||
|
||||
@@ -67,53 +170,59 @@ int main(int argc, char *args[]) {
|
||||
case SDL_KEYUP: {
|
||||
SDL_Scancode scancode = e.key.keysym.scancode;
|
||||
if(scancode == SDL_SCANCODE_F1){
|
||||
//Switch backend
|
||||
//Switch backend | button A
|
||||
pRenderer->SwitchBackend();
|
||||
}
|
||||
if(scancode == SDL_SCANCODE_F2){
|
||||
//toggle rotation
|
||||
//toggle rotation | Button B
|
||||
pRenderer->ToggleRotation();
|
||||
}
|
||||
if(scancode == SDL_SCANCODE_F9){
|
||||
// Cycle Cull mode
|
||||
// Cycle Cull mode | Right shoulder
|
||||
pRenderer->CycleCullMode();
|
||||
}
|
||||
if(scancode == SDL_SCANCODE_F10){
|
||||
// Toggle Uniform Clear Color
|
||||
// Toggle Uniform Clear Color | left shoulder
|
||||
pRenderer->ToggleUniformClearColor();
|
||||
}
|
||||
if(scancode == SDL_SCANCODE_F11){
|
||||
// toggle Print fps
|
||||
// toggle Print fps | Home button
|
||||
printFPS = !printFPS;
|
||||
}
|
||||
|
||||
//Hardware
|
||||
if (scancode == SDL_SCANCODE_F3){
|
||||
// Toggle FireFX mesh
|
||||
// Toggle FireFX mesh | DPAD UP
|
||||
pRenderer->ToggleFireFX();
|
||||
}
|
||||
if (scancode == SDL_SCANCODE_F4){
|
||||
//Toggle texture sampling states
|
||||
//Toggle texture sampling states | DPAD DOWN
|
||||
pRenderer->NextSamplingState();
|
||||
}
|
||||
//Software
|
||||
if(scancode == SDL_SCANCODE_F5){
|
||||
//Cycle shading mode
|
||||
//Cycle shading mode | Button X
|
||||
pRenderer->CycleRenderingMode();
|
||||
}
|
||||
if(scancode == SDL_SCANCODE_F6){
|
||||
//Toggle normal mapping
|
||||
//Toggle normal mapping | DPAD LEFT
|
||||
pRenderer->ToggleNormals();
|
||||
}
|
||||
if(scancode == SDL_SCANCODE_F7){
|
||||
//Toggle Depth Buffer
|
||||
//Toggle Depth Buffer | Button Y
|
||||
pRenderer->ToggleDepthBuffer();
|
||||
}
|
||||
if(scancode == SDL_SCANCODE_F8) {
|
||||
//Toggle BoundingBox
|
||||
//Toggle BoundingBox | DPAD RIGHT
|
||||
pRenderer->ToggleBoundingBox();
|
||||
}
|
||||
|
||||
//Custom
|
||||
if(scancode == SDL_SCANCODE_N){
|
||||
//Next Scene | Button Back
|
||||
pRenderer->NextScene();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -122,6 +231,9 @@ int main(int argc, char *args[]) {
|
||||
}
|
||||
|
||||
GamePadController::GetInstance().Update();
|
||||
|
||||
CheckController(pRenderer, printFPS);
|
||||
|
||||
//--------- Update ---------
|
||||
pRenderer->Update(pTimer);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user