Commit 4cb6604b authored by Lukas Tietze's avatar Lukas Tietze

ImGui Spielereien

parent 0dba1ac1
......@@ -7,15 +7,27 @@ namespace app
class VkrtApp : public lib::IAppAdapter
{
private:
float currentHDeg = 0;
float colorChangeFactor = 5.f;
float sunAngle = 0;
float sunSpeedFactor = 5.f;
float moveSpeedFactor = 1.f;
float rotateSpeedFactor = 300.f;
struct
{
bool animate = true;
float currentHDeg = 0;
float changeSpeed = 5.f;
} background;
bool animateLight = true;
bool animateBackground = true;
struct
{
bool animate = true;
float y = 0.f;
float yMax = 2.f;
float yBase = 2.f;
float speed = 5.f;
} light;
struct
{
float moveSpeedFactor = 1.f;
float rotateSpeedFactor = 300.f;
} camera;
void HandleCameraMovement(lib::App &app, lib::time_diff_t delta);
void HandleOtherKeys(lib::App &app);
......
......@@ -3,6 +3,8 @@
#include "Util/Logging.hpp"
#include <cmath>
#include <sstream>
#include <iomanip>
#include "glm/glm.hpp"
#include "glm/gtx/rotate_vector.hpp"
......@@ -11,8 +13,8 @@ void app::VkrtApp::HandleCameraMovement(lib::App &app, lib::time_diff_t delta)
if (app.IsMouseCaptured())
{
auto &camera = app.GetContext().GetCameraModel();
auto moveSpeed = delta.count() * this->moveSpeedFactor;
auto rotateSpeed = delta.count() * this->rotateSpeedFactor;
auto moveSpeed = delta.count() * this->camera.moveSpeedFactor;
auto rotateSpeed = delta.count() * this->camera.rotateSpeedFactor;
auto sideWards = glm::cross(camera.GetViewDirection(), camera.GetUp());
if (app.IsKeyDown(GLFW_KEY_W))
......@@ -91,25 +93,25 @@ void app::VkrtApp::HandleOtherKeys(lib::App &app)
}
void app::VkrtApp::AnimateBackground(lib::App &app, lib::time_diff_t delta)
{
this->currentHDeg += delta.count() * this->colorChangeFactor;
this->background.currentHDeg += delta.count() * this->background.changeSpeed;
while (this->currentHDeg >= 360.f)
while (this->background.currentHDeg >= 360.f)
{
this->currentHDeg -= 360.f;
this->background.currentHDeg -= 360.f;
}
}
void app::VkrtApp::UpdateBackground(lib::App &app, lib::time_diff_t delta)
{
if (this->animateBackground)
if (this->background.animate)
{
this->AnimateBackground(app, delta);
}
auto &col = app.GetContext().GetClearColor();
auto hi = static_cast<uint32_t>(this->currentHDeg / 60.f);
auto f = (this->currentHDeg / 60.f - hi);
auto hi = static_cast<uint32_t>(this->background.currentHDeg / 60.f);
auto f = (this->background.currentHDeg / 60.f - hi);
switch (hi)
{
......@@ -137,26 +139,24 @@ void app::VkrtApp::UpdateBackground(lib::App &app, lib::time_diff_t delta)
void app::VkrtApp::AnimateLight(lib::App &app, lib::time_diff_t delta)
{
this->sunAngle += delta.count() * this->sunSpeedFactor;
this->light.y += delta.count() * this->light.speed;
if (this->sunAngle > 360.f)
while (this->light.y > this->light.yMax)
{
this->sunAngle -= 360.f;
this->light.y -= this->light.yMax;
}
}
void app::VkrtApp::UpdateLight(lib::App &app, lib::time_diff_t delta)
{
if (this->animateLight)
if (this->light.animate)
{
this->AnimateLight(app, delta);
}
auto &light = app.GetContext().GetMainLightSource();
auto &light = app.GetContext().GetLightSources()[0];
light.SetPosition(glm::rotate(light.GetPosition(),
glm::radians(delta.count() * this->sunSpeedFactor),
lib::axis::y));
light.SetPosition(light.GetPosition() + glm::vec3{0, this->light.yBase + this->light.y - this->light.yMax / 2.f, 0});
}
void app::VkrtApp::RenderUi(lib::App &app)
......@@ -165,20 +165,58 @@ void app::VkrtApp::RenderUi(lib::App &app)
{
ImGui::Begin("Szenenkonfiguration");
ImGui::SetWindowPos({app.GetWindowWidth() / 2.f, app.GetWindowHeight() / 2.f}, ImGuiCond_FirstUseEver);
ImGui::SetWindowSize({app.GetWindowWidth() / 2.f, app.GetWindowHeight() / 2.f}, ImGuiCond_FirstUseEver);
{
static glm::vec3 lightPos;
lightPos = app.GetContext().GetLightSources()[0].GetPosition();
ImGui::BeginGroup();
ImGui::Text("Lichtquelle:");
ImGui::SliderAngle("Rotation", &this->sunAngle, 0.f);
ImGui::Checkbox("Animieren", &this->animateLight);
ImGui::SliderFloat("Animationsgeschwindigkeit", &this->sunSpeedFactor, 0, 20.f);
ImGui::Checkbox("Animieren##L", &this->light.animate);
ImGui::SliderFloat("Geschwindigkeit##L", &this->light.speed, 0, 20.f);
ImGui::SliderFloat("Basis-Y##L", &this->light.yBase, 0.f, 4.f);
ImGui::SliderFloat("Y-Reichweite##L", &this->light.yMax, 0.f, 4.f);
ImGui::InputFloat("X", &lightPos.x, 0.5f, 4.f, 1);
ImGui::InputFloat("Y", &lightPos.y, 0.5f, 4.f, 1);
ImGui::InputFloat("Z", &lightPos.z, 0.5f, 4.f, 1);
ImGui::Separator();
ImGui::EndGroup();
app.GetContext().GetLightSources()[0].SetPosition(lightPos);
}
ImGui::Separator();
ImGui::BeginGroup();
ImGui::Text("Hintergrund:");
ImGui::Checkbox("Animieren##H", &this->background.animate);
ImGui::SliderFloat("Farbgrad##H", &this->background.currentHDeg, 0.f, 360.f);
ImGui::SliderFloat("Geschwindigkeit##H", &this->background.changeSpeed, 1.f, 10.f);
ImGui::EndGroup();
ImGui::Separator();
{
ImGui::Text("Hintergrund:");
ImGui::Checkbox("Animieren", &this->animateBackground);
static glm::vec3 camPos;
camPos = app.GetContext().GetCameraModel().GetPosition();
ImGui::BeginGroup();
ImGui::Text("Kamera:");
ImGui::InputFloat("X", &camPos.x, 0.5f, 4.f, 1);
ImGui::InputFloat("Y", &camPos.y, 0.5f, 4.f, 1);
ImGui::InputFloat("Z", &camPos.z, 0.5f, 4.f, 1);
ImGui::EndGroup();
app.GetContext().GetCameraModel().SetPosition(camPos);
}
ImGui::End();
}
ImGui::ShowDemoWindow();
ImGui::Render();
}
......
......@@ -64,20 +64,6 @@ namespace lib
*/
virtual const Camera &GetCameraModel() const = 0;
/**
* @brief Holt die Hauptlichtquelle. (in der vereinfachten Form gibt es nur eine Lichtquelle)
*
* @return LightSource& Die Lichtquelle.
*/
virtual LightSource &GetMainLightSource() = 0;
/**
* @brief Holt die Hauptlichtquelle. (in der vereinfachten Form gibt es nur eine Lichtquelle)
*
* @return const LightSource& Die Lichtquelle.
*/
virtual const LightSource &GetMainLightSource() const = 0;
/**
* @brief Holt die Sammlung der Lichtquellen.
*
......@@ -292,8 +278,6 @@ namespace lib
void ReloadModel() override;
Camera &GetCameraModel() override;
const Camera &GetCameraModel() const override;
LightSource &GetMainLightSource() override;
const LightSource &GetMainLightSource() const override;
std::vector<LightSource> &GetLightSources() override;
const std::vector<LightSource> &GetLightSources() const override;
glm::vec3 &GetClearColor() override;
......
......@@ -152,16 +152,6 @@ const lib::Camera &lib::CgContext::GetCameraModel() const
return this->camera;
}
lib::LightSource &lib::CgContext::GetMainLightSource()
{
return this->lightSources[0];
}
const lib::LightSource &lib::CgContext::GetMainLightSource() const
{
return this->lightSources[0];
}
std::vector<lib::LightSource> &lib::CgContext::GetLightSources()
{
return this->lightSources;
......
......@@ -478,9 +478,10 @@ void lib::CgContext::FindPhysicalDevice()
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
VK_NV_RAY_TRACING_EXTENSION_NAME,
VK_KHR_MAINTENANCE3_EXTENSION_NAME,
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
VK_EXT_SCALAR_BLOCK_LAYOUT_EXTENSION_NAME,
VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME,
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
};
for (const auto &deviceInfo : deviceInfos)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment