Skip to content

Commit

Permalink
General Refactoring and HSGIL update
Browse files Browse the repository at this point in the history
  • Loading branch information
AsulconS committed Sep 16, 2023
1 parent 8ea8995 commit e286316
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 24 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.20)

# Disable CYGWIN Legacy Warning
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
Expand All @@ -13,8 +13,8 @@ set(FULL_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
# Project info
project(SPH VERSION ${FULL_VERSION})

# Set C++11 as the standard
set(CMAKE_CXX_STANDARD 11)
# Set C++17 as the standard
set(CMAKE_CXX_STANDARD 17)

# Output Dir
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>)
Expand All @@ -28,6 +28,13 @@ macro(build_cpp_source filename)
)
target_include_directories(${filename} PRIVATE include)
target_include_directories(${filename} PRIVATE include/HSGIL/external)
if(SPH_BUILD STREQUAL "Debug")
target_link_directories(${filename} PRIVATE lib/Debug)
elseif(SPH_BUILD STREQUAL "Release")
target_link_directories(${filename} PRIVATE lib/Release)
else()
message(FATAL_ERROR "Please, specify a valid build mode (Debug|Release)")
endif()
if(WIN32)
target_link_libraries(${filename} LINK_PUBLIC hsgil opengl32)
else()
Expand Down
Binary file removed default.png
Binary file not shown.
33 changes: 18 additions & 15 deletions fluid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ int main()
gil::Timer timer(true);

glm::vec3 viewPos {0.2f, 0.4f, 0.8f};
glm::vec3 boundaries = glm::vec3{sim.boundaryWidth, sim.boundaryHeight, sim.boundaryDepth};

gil::Shader shader("water");
gil::Shader volcanoShader("volcano");
Expand All @@ -234,19 +235,28 @@ int main()

while(window.isActive())
{
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Pre Processing
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
window.pollEvents();
if (inputHandler.onKeyTriggered(gil::KEY_ESCAPE))
{
window.close();
continue;
}
float deltaTime = timer.getDeltaTime();

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Input Processing
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
yRotControl = 0.0f;
if(inputHandler.onKeyDown(gil::KEY_A))
if(inputHandler.onKeyDown(gil::KEY_Q))
{
yRotControl -= 1.0f;
yRotControl += 1.0f;
}
if(inputHandler.onKeyDown(gil::KEY_D))
if(inputHandler.onKeyDown(gil::KEY_E))
{
yRotControl += 1.0f;
yRotControl -= 1.0f;
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -327,30 +337,23 @@ int main()
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glm::mat4 view;
glm::mat4 model;

float deltaTime = timer.getDeltaTime();
glm::mat4 model = glm::mat4(1.0f);
yRotationAngle += yRotControl * yRotationWeight * deltaTime;
glm::vec4 nvp4 = glm::rotate(glm::mat4(1.0f), yRotationAngle, glm::vec3{0.0f, 1.0f, 0.0f}) * glm::vec4{viewPos.x, viewPos.y, viewPos.z, 1.0f};
glm::vec3 nvp3 = {nvp4.x, nvp4.y, nvp4.z};
view = glm::lookAt(nvp3, glm::vec3{0.0f, 0.0f, 0.0f}, glm::vec3{0.0f, 1.0f, 0.0f});

shader.use();
shader.setMat4("view", view);
for(unsigned int i = 0; i < sim.particles.size(); ++i)
{
Particle& pi = sim.particles[i];

model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3{pi.r.x, pi.r.y, pi.r.z});
model = glm::rotate(glm::mat4(1.0f), yRotationAngle, glm::vec3{0.0f, 1.0f, 0.0f});
model = glm::translate(model, glm::vec3{pi.r.x, pi.r.y, pi.r.z} - 0.5f * boundaries);
shader.setMat4("model", model);

float zColorDepth {pi.r.z / sim.boundaryDepth};
shader.setVec3("colorDepth", {zColorDepth, zColorDepth, zColorDepth});

glBindVertexArray(sim.VAO);
glDrawArrays(GL_POINTS, 0, sim.particles.size());
glDrawArrays(GL_POINTS, 0, (GLsizei)sim.particles.size());
glBindVertexArray(0);
}

Expand Down
1 change: 1 addition & 0 deletions include/HSGIL/config/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ namespace luis = gil;
namespace erick = gil;
namespace yober = gil;
namespace pogdo = gil;
namespace zhong = gil;

#endif // HSGIL_COMMON_HPP
4 changes: 2 additions & 2 deletions include/HSGIL/math/vec2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ struct Vec2f
*/
struct Vec2i
{
int x;
int y;
uint32 x;
uint32 y;
};

using Vec2 = Vec2f;
Expand Down
37 changes: 37 additions & 0 deletions include/HSGIL/window/customization.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/********************************************************************************
* *
* HSGIL - Handy Scalable Graphics Integration Library *
* Copyright (c) 2019-2022 Adrian Bedregal *
* *
* This software is provided 'as-is', without any express or implied *
* warranty. In no event will the authors be held liable for any damages *
* arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must not *
* claim that you wrote the original software. If you use this software *
* in a product, an acknowledgment in the product documentation would be *
* appreciated but is not required. *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* 3. This notice may not be removed or altered from any source distribution. *
* *
********************************************************************************/

#ifndef HSGIL_WINDOW_CUSTOMIZATION_HPP
#define HSGIL_WINDOW_CUSTOMIZATION_HPP

namespace gil
{
enum class WindowStyle {
WINDOWED_STYLE,
BORDERLESS_STYLE,
BORDERLESS_FULLSCREEN_STYLE
};

} // namespace gil

#endif // HSGIL_WINDOW_CUSTOMIZATION_HPP
22 changes: 19 additions & 3 deletions include/HSGIL/window/iWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <HSGIL/config/common.hpp>

#include <HSGIL/window/inputHandler.hpp>
#include <HSGIL/window/customization.hpp>

namespace gil
{
Expand All @@ -48,7 +49,7 @@ class HSGIL_API IWindow
* @param t_title
* @param t_eventHandler
*/
IWindow(const uint32 t_width, const uint32 t_height, const char* t_title, InputHandler* t_inputHandler) : m_width {t_width}, m_height {t_height}, m_title {t_title}, m_ready {false}, m_inputHandler {t_inputHandler} {}
IWindow(const uint32 t_width, const uint32 t_height, const char* t_title, WindowStyle t_style, InputHandler* t_inputHandler) : m_windowWidth {t_width}, m_windowHeight {t_height}, m_title {t_title}, m_style {t_style}, m_ready {false}, m_inputHandler {t_inputHandler} {}
/**
* @brief Destroy the Window object
*
Expand Down Expand Up @@ -91,6 +92,18 @@ class HSGIL_API IWindow
* @return float value containing the current aspect ratio
*/
virtual float getAspectRatio() const = 0;
/**
* @brief Get the Window Rect object as Vec2i
*
* @return Vec2i vector containing width and height of the window in pixels
*/
virtual Vec2i getWindowRect() const = 0;
/**
* @brief Get the Workspace Rect object as Vec2i
*
* @return Vec2i vector containing width and height of the viewport in pixels
*/
virtual Vec2i getViewportRect() const = 0;

protected:
/**
Expand All @@ -99,9 +112,12 @@ class HSGIL_API IWindow
*/
virtual void initializeWindow() = 0;

uint32 m_width;
uint32 m_height;
uint32 m_windowWidth;
uint32 m_windowHeight;
uint32 m_viewportWidth;
uint32 m_viewportHeight;
const char* m_title;
WindowStyle m_style;

bool m_ready;

Expand Down
15 changes: 14 additions & 1 deletion include/HSGIL/window/renderingWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <HSGIL/window/iWindow.hpp>
#include <HSGIL/window/inputEvents.hpp>
#include <HSGIL/window/inputHandler.hpp>
#include <HSGIL/window/customization.hpp>

namespace gil
{
Expand All @@ -49,7 +50,7 @@ class HSGIL_API RenderingWindow : public IWindow
* @param t_width
* @param t_height
*/
explicit RenderingWindow(const uint32 t_width = 800u, const uint32 t_height = 600u, const char* t_title = "Untitled", InputHandler* t_inputHandler = nullptr);
explicit RenderingWindow(const uint32 t_width = 800u, const uint32 t_height = 600u, const char* t_title = "Untitled", WindowStyle t_style = WindowStyle::WINDOWED_STYLE, InputHandler* t_inputHandler = nullptr);
/**
* @brief Destroy the RenderingWindow object
*
Expand Down Expand Up @@ -98,6 +99,18 @@ class HSGIL_API RenderingWindow : public IWindow
* @return float
*/
virtual float getAspectRatio() const override;
/**
* @brief Get the Window Rect object as Vec2i
*
* @return Vec2i vector containing width and height of the window in pixels
*/
virtual Vec2i getWindowRect() const override;
/**
* @brief Get the Workspace Rect object as Vec2i
*
* @return Vec2i vector containing width and height of the viewport in pixels
*/
virtual Vec2i getViewportRect() const override;

protected:
/**
Expand Down
Binary file added lib/Debug/hsgil.pdb
Binary file not shown.
5 changes: 5 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ int main()
while(window.isActive())
{
window.pollEvents();
if (inputHandler.onKeyTriggered(gil::KEY_ESCAPE))
{
window.close();
continue;
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Input Processing
Expand Down
8 changes: 8 additions & 0 deletions old.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ int main()
return EXIT_FAILURE;
}

gil::InputHandler inputHandler;
window.setInputHandler(inputHandler);

SIM_State sim;
sim.nParticles = 100000;

Expand Down Expand Up @@ -209,6 +212,11 @@ int main()
while(window.isActive())
{
window.pollEvents();
if (inputHandler.onKeyTriggered(gil::KEY_ESCAPE))
{
window.close();
continue;
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Compute Density-Pressure
Expand Down

0 comments on commit e286316

Please sign in to comment.