Skip to content

Commit

Permalink
Minor Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidtKate committed Dec 11, 2020
1 parent 96f4f43 commit 195ed7b
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 60 deletions.
16 changes: 8 additions & 8 deletions MiniSolarSystem/MiniSolarSystem.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)bin\int\$(Platform)\$(Configuration)\</IntDir>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
Expand Down Expand Up @@ -216,9 +214,10 @@
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent>
<Command>xcopy /E /Y "$(ProjectDir)resources" "$(TargetDir)resources\"
xcopy /F /Y "$(ProjectDir)imgui.ini" "$(TargetDir)"</Command>
<Message>Copying resources to output directory...</Message>
<Command>if $(ConfigurationName) == Release xcopy /E /Y "$(ProjectDir)resources" "$(TargetDir)resources\"
if $(ConfigurationName) == Release xcopy /F /Y "$(ProjectDir)imgui.ini" "$(TargetDir)"</Command>
<Message>
</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down Expand Up @@ -261,9 +260,10 @@ xcopy /F /Y "$(ProjectDir)imgui.ini" "$(TargetDir)"</Command>
<PostBuildEvent />
<PostBuildEvent />
<PostBuildEvent>
<Command>xcopy /E /Y "$(ProjectDir)resources" "$(TargetDir)resources\"
xcopy /F /Y "$(ProjectDir)imgui.ini" "$(TargetDir)"</Command>
<Message>Copying resources to output directory...</Message>
<Command>if $(ConfigurationName) == Release xcopy /E /Y "$(ProjectDir)resources" "$(TargetDir)resources\"
if $(ConfigurationName) == Release xcopy /F /Y "$(ProjectDir)imgui.ini" "$(TargetDir)"</Command>
<Message>
</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
9 changes: 8 additions & 1 deletion MiniSolarSystem/include/Managers/PlanetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ class PlanetManager
return s_planetManager;
}

void AddPlanet(Planet* a_planet) { m_planets.push_back(a_planet); }
void AddPlanet(Planet* a_planet)
{
if (a_planet)
{
m_planets.push_back(a_planet);
}
}

const std::vector<Planet*> GetPlanets() const { return m_planets; }

private:
Expand Down
6 changes: 3 additions & 3 deletions MiniSolarSystem/include/Objects/Planet.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Planet : public Object
{
public:

Planet(re::Transform a_transform, float a_mass, float a_radius, glm::vec3 a_initialVelocity, const std::string& a_texturePath, re::Shader& a_shader);
Planet(re::Transform a_transform, float a_mass, float a_radius, const glm::vec3& a_initialVelocity, const std::string& a_texturePath, re::Shader& a_shader);
~Planet() = default;

void Update(float a_deltaTime);
Expand All @@ -23,8 +23,8 @@ class Planet : public Object
const glm::vec3& GetRotation() const { return m_mesh->GetTransform().GetRotation(); };
const glm::vec3& GetScale() const { return m_mesh->GetTransform().GetScale(); };

const float GetMass() const { return m_mass; }
const float GetRadius() const { return m_radius; }
float GetMass() const { return m_mass; }
float GetRadius() const { return m_radius; }

private:

Expand Down
2 changes: 1 addition & 1 deletion MiniSolarSystem/include/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Scene
~Scene() = default;

void Init();
void Update(float a_deltaTime, GLFWwindow* a_window);
void Update(float a_deltaTime, GLFWwindow& a_window);

private:

Expand Down
62 changes: 33 additions & 29 deletions MiniSolarSystem/source/DebugWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#include "imgui/imgui.h"

DebugWindow::DebugWindow(re::Camera* a_camera, re::PointLight* a_light)
: m_camera(a_camera), m_light(a_light)
{
}
: m_camera(a_camera), m_light(a_light) {}

void DebugWindow::Update()
{
Expand All @@ -21,35 +19,41 @@ void DebugWindow::Update()
ImGui::Text("Amount of drawables: %i", re::Renderer::GetInstance().stats.drawables);
ImGui::End();

// Camera settings window
ImGui::Begin("Camera");
ImGui::SliderFloat("Speed", &m_cameraSpeed, 1.0f, 100.0f);
ImGui::SliderFloat("Sensitivity", &m_cameraSensitivity, 0.1f, 0.4f);
ImGui::End();

m_camera->SetCameraSpeed(m_cameraSpeed);
m_camera->SetCameraSensitivity(m_cameraSensitivity);

// Renderer settings window
ImGui::Begin("Renderer");
if (ImGui::InputFloat3("Light Position", m_lightPosition))
if (m_camera)
{
m_light->SetPosition(glm::vec3(m_lightPosition[0], m_lightPosition[1], m_lightPosition[2]));
// Camera settings window
ImGui::Begin("Camera");
ImGui::SliderFloat("Speed", &m_cameraSpeed, 1.0f, 100.0f);
ImGui::SliderFloat("Sensitivity", &m_cameraSensitivity, 0.1f, 0.4f);
ImGui::End();

m_camera->SetCameraSpeed(m_cameraSpeed);
m_camera->SetCameraSensitivity(m_cameraSensitivity);
}

if (ImGui::ColorPicker3("Light Color", m_lightColor))
if (m_light)
{
m_light->SetColor(glm::vec3(m_lightColor[0], m_lightColor[1], m_lightColor[2]));
// Renderer settings window
ImGui::Begin("Renderer");
if (ImGui::InputFloat3("Light Position", m_lightPosition))
{
m_light->SetPosition(glm::vec3(m_lightPosition[0], m_lightPosition[1], m_lightPosition[2]));
}

if (ImGui::ColorPicker3("Light Color", m_lightColor))
{
m_light->SetColor(glm::vec3(m_lightColor[0], m_lightColor[1], m_lightColor[2]));
}

if (ImGui::SliderFloat("Light Ambient Coefficient", &m_lightAmbientCoef, 0.1f, 0.5f))
{
m_light->SetAmbientCoefficient(m_lightAmbientCoef);
}

if (ImGui::SliderFloat("Light Specular Coefficient", &m_lightSpecularCoef, 0.1f, 1.f))
{
m_light->SetSpecularCoefficient(m_lightSpecularCoef);
}
ImGui::End();
}

if (ImGui::SliderFloat("Light Ambient Coefficient", &m_lightAmbientCoef, 0.1f, 0.5f))
{
m_light->SetAmbientCoefficient(m_lightAmbientCoef);
}

if (ImGui::SliderFloat("Light Specular Coefficient", &m_lightSpecularCoef, 0.1f, 1.f))
{
m_light->SetSpecularCoefficient(m_lightSpecularCoef);
}
ImGui::End();
}
2 changes: 1 addition & 1 deletion MiniSolarSystem/source/Objects/Planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "Managers/PlanetManager.h"

Planet::Planet(re::Transform a_transform, float a_mass, float a_radius, glm::vec3 a_initialVelocity, const std::string& a_texturePath, re::Shader& a_shader)
Planet::Planet(re::Transform a_transform, float a_mass, float a_radius, const glm::vec3& a_initialVelocity, const std::string& a_texturePath, re::Shader& a_shader)
: m_mass(a_mass), m_radius(a_radius), m_currVelocity(a_initialVelocity), m_shader(&a_shader)
{
m_mesh = std::make_unique<re::Mesh>("resources/models/planet.obj", a_texturePath, a_transform, a_shader);
Expand Down
3 changes: 1 addition & 2 deletions MiniSolarSystem/source/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ void Scene::Init()
m_camera = std::make_unique<re::Camera>(glm::vec3(0.0f, 0.0f, 200.0f), 70.f, static_cast<float>(SCREENWIDTH) / static_cast<float>(SCREENHEIGHT), 0.01f, 1000.0f);

// Create point light
//PointLight* pointLight = new PointLight(glm::vec3(10.f), glm::vec3(1.f), *m_shader, *m_camera);
m_pointLight = std::make_unique<re::PointLight>(glm::vec3(10.f), glm::vec3(1.f), *m_shader, *m_camera);
re::Renderer::GetInstance().AddLight(m_pointLight.get());

// Create debugwindow
m_debugWindow = std::make_unique<DebugWindow>(m_camera.get(), m_pointLight.get());
}

void Scene::Update(float a_deltaTime, GLFWwindow* a_window)
void Scene::Update(float a_deltaTime, GLFWwindow& a_window)
{
// Clear frame
re::Renderer::GetInstance().Clear();
Expand Down
8 changes: 3 additions & 5 deletions MiniSolarSystem/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#define SCREENHEIGHT 800

int main()
{
GLFWwindow* window;

{
if (!glfwInit())
{
std::cout << "GLFW Init Failed!" << std::endl;
Expand All @@ -22,7 +20,7 @@ int main()
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Create window
window = glfwCreateWindow(SCREENWIDTH, SCREENHEIGHT, "Mini Solar System", NULL, NULL);
GLFWwindow* window = glfwCreateWindow(SCREENWIDTH, SCREENHEIGHT, "Mini Solar System", NULL, NULL);
if (!window)
{
glfwTerminate();
Expand Down Expand Up @@ -75,7 +73,7 @@ int main()
lastFrame = currentFrame;

// Update Scene
scene->Update(deltaTime, window);
scene->Update(deltaTime, *window);

// Draw ImGui
ImGui::Render();
Expand Down
2 changes: 1 addition & 1 deletion Renderer/include/Renderer/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace re
Camera(const glm::vec3& a_pos, float a_fov, float a_aspect, float a_zNear, float a_zFar);
~Camera() = default;

void Update(float a_deltaTime, GLFWwindow* a_window);
void Update(float a_deltaTime, GLFWwindow& a_window);

glm::mat4 GetViewProjection() const { return m_projection * glm::lookAt(m_pos, m_pos + m_forward, m_up); }
void SetCameraSpeed(float a_newCameraSpeed) { m_cameraSpeed = a_newCameraSpeed; }
Expand Down
1 change: 1 addition & 0 deletions Renderer/include/Renderer/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace re
void RemoveDrawable(Drawable* a_drawable);

void AddLight(PointLight* a_light);
void RemoveLight(PointLight* a_light);

void Update(float a_deltaTime);
void Draw(Shader& a_shader, Camera& a_camera) const;
Expand Down
16 changes: 8 additions & 8 deletions Renderer/source/Renderer/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ namespace re
m_projection = glm::perspective(a_fov, a_aspect, a_zNear, a_zFar);
}

void Camera::Update(float a_deltaTime, GLFWwindow* a_window)
void Camera::Update(float a_deltaTime, GLFWwindow& a_window)
{
// Keyboard movement
if (glfwGetKey(a_window, GLFW_KEY_W) == GLFW_PRESS)
if (glfwGetKey(&a_window, GLFW_KEY_W) == GLFW_PRESS)
{
m_pos += (m_forward * m_cameraSpeed) * a_deltaTime;
}
if (glfwGetKey(a_window, GLFW_KEY_S) == GLFW_PRESS)
if (glfwGetKey(&a_window, GLFW_KEY_S) == GLFW_PRESS)
{
m_pos -= (m_forward * m_cameraSpeed) * a_deltaTime;
}
if (glfwGetKey(a_window, GLFW_KEY_A) == GLFW_PRESS)
if (glfwGetKey(&a_window, GLFW_KEY_A) == GLFW_PRESS)
{
m_pos -= (glm::normalize(glm::cross(m_forward, m_up)) * m_cameraSpeed) * a_deltaTime;
}
if (glfwGetKey(a_window, GLFW_KEY_D) == GLFW_PRESS)
if (glfwGetKey(&a_window, GLFW_KEY_D) == GLFW_PRESS)
{
m_pos += (glm::normalize(glm::cross(m_forward, m_up)) * m_cameraSpeed) * a_deltaTime;
}

glfwGetCursorPos(a_window, &xCurPos, &yCurPos);
glfwGetCursorPos(&a_window, &xCurPos, &yCurPos);

// Mouse movement
if (glfwGetMouseButton(a_window, GLFW_MOUSE_BUTTON_2) == GLFW_PRESS)
if (glfwGetMouseButton(&a_window, GLFW_MOUSE_BUTTON_2) == GLFW_PRESS)
{
if (firstMouse)
{
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace re
m_forward = glm::normalize(direction);
}

if (glfwGetMouseButton(a_window, GLFW_MOUSE_BUTTON_2) == GLFW_RELEASE)
if (glfwGetMouseButton(&a_window, GLFW_MOUSE_BUTTON_2) == GLFW_RELEASE)
{
lastX = xCurPos;
lastY = yCurPos;
Expand Down
15 changes: 14 additions & 1 deletion Renderer/source/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,26 @@ namespace re
{
if (a_drawable != nullptr)
{
// Use erase-remove idiom
m_drawables.erase(std::remove(m_drawables.begin(), m_drawables.end(), a_drawable), m_drawables.end());
}
}

void Renderer::AddLight(PointLight* a_light)
{
m_lights.push_back(a_light);
if (a_light != nullptr)
{
m_lights.push_back(a_light);
}
}

void Renderer::RemoveLight(PointLight* a_light)
{
if (a_light != nullptr)
{
// Use erase-remove idiom
m_lights.erase(std::remove(m_lights.begin(), m_lights.end(), a_light), m_lights.end());
}
}

void Renderer::Update(float)
Expand Down

0 comments on commit 195ed7b

Please sign in to comment.