diff --git a/.gitignore b/.gitignore index 9491a2f..4ef6152 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ mono_crash.* # Build results -[Dd]ebug/ +#[Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ @@ -360,4 +360,37 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd + +intermediate-files/ + +.cache/ +.vscode/ +*.json +*.make +Makefile +*.sublime-* + +*.vcxproj + +*.sln + +*.vcxproj.filters + +*.code-workspace + +*.o + +*.d + +*.ninja* + +.idea/ + +Engine-Core/lib +Engine-Core/intermediate-files +Editor/bin +Editor/intermediate-files +Game/bin + +imgui.ini \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt index 8aa2645..3da13a2 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) [year] [fullname] +Copyright (c) 2025 Joseph Aquino Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Light.cpp b/Light.cpp deleted file mode 100644 index becbd66..0000000 --- a/Light.cpp +++ /dev/null @@ -1,192 +0,0 @@ -#include "Light.h" - -void Light::draw(sf::RenderWindow& window) -{ - if (hasFlags(Flags::visibility)) - { - window.draw(m_light.data(), m_light.size(), sf::PrimitiveType::TriangleFan); - } - - if (hasFlags(Flags::drawRays)) - { - sf::VertexArray tempRay(sf::PrimitiveType::Lines, 2); - tempRay[start].position = m_origin; - tempRay[start].color = m_rayColor; - tempRay[end].color = m_rayColor; - - for (auto& ray : m_rays) - { - tempRay[end].position = ray.position; - window.draw(tempRay); - } - } - - if (hasFlags(Flags::drawEndPoints)) - { - sf::CircleShape endPoint(5.f, 20u); - endPoint.setOrigin({ 5, 5 }); - endPoint.setFillColor(m_endPointColor); - - for (auto& ray : m_rays) - { - endPoint.setPosition(ray.position); - window.draw(endPoint); - } - } -} - - -void Light::processRays(const std::vector& polygons) -{ - m_light[0].position = m_origin; - if (m_center and m_offset) - { - constructPartialLight(polygons); - } - else - { - constructFullLight(polygons); - } -} - - -void Light::constructFullLight(const std::vector& polygons) -{ - createAndSortRays(polygons); - - calculateIntersects(polygons); - - for (auto& ray : m_rays) - { - m_light.emplace_back(ray); - } - - m_light.emplace_back(m_rays.front());//fully connect the triangle fan - -} - - -void Light::constructPartialLight(const std::vector& polygons) -{ - createAndSortRays(polygons, m_center.value() - m_offset.value(), m_center.value() + m_offset.value()); - - calculateIntersects(polygons); - - for (auto& ray : m_rays) - { - m_light.emplace_back(ray); - } - -} - - -void Light::createAndSortRays(const std::vector& polygons) -{ - - if (not hasFlags(Flags::infiniteLength)) - { - if (m_rayCount > 0) - { - float angleIncrement = 360.f / (float)m_rayCount; - for (int i = 0; i < m_rayCount; i++) m_rays.emplace_back(sf::Vertex{ constructVector( m_origin, sf::degrees(angleIncrement * i), m_rayLength ), m_lightColor }); - } - } - - sf::Angle angle; - const float infiniteLength = 5000.f * hasFlags(Flags::infiniteLength); - - for (auto& poly : polygons) - { - for (std::size_t i = 0; i < poly.getVertexCount() - 1; i++) - { - if (hasFlags(Flags::infiniteLength) ? false : distanceBetween(m_origin, poly[i].position) >= m_rayLength) continue; - - angle = sf::radians(std::atan2f(poly[i].position.y - m_origin.y, poly[i].position.x - m_origin.x)); - - m_rays.emplace_back(sf::Vertex{ poly[i].position, m_lightColor }); - m_rays.emplace_back(sf::Vertex{ constructVector( m_origin, angle + sf::radians(.00001f), m_rayLength + infiniteLength), m_lightColor }); - m_rays.emplace_back(sf::Vertex{ constructVector( m_origin, angle - sf::radians(.00001f), m_rayLength + infiniteLength), m_lightColor }); - } - } - - std::sort(m_rays.begin(), m_rays.end(), [&](const auto& lhs, const auto& rhs) { return (lhs.position - m_origin).angle().wrapUnsigned().asRadians() < (rhs.position - m_origin).angle().wrapUnsigned().asRadians(); }); -} - -// overload for bounded light -void Light::createAndSortRays(const std::vector& polygons, sf::Angle lowerAngleBounds, sf::Angle upperAngleBounds) -{ - const float infiniteLength = 5000.f * hasFlags(Flags::infiniteLength); - sf::Vertex lowerBound{ constructVector( m_origin, lowerAngleBounds, m_rayLength + infiniteLength), m_lightColor }; - sf::Vertex upperBound{ constructVector( m_origin, upperAngleBounds, m_rayLength + infiniteLength), m_lightColor }; - auto lowerBoundVector = lowerBound.position - m_origin; - auto upperBoundVector = upperBound.position - m_origin; - - if (not hasFlags(Flags::infiniteLength)) - { - sf::Vertex temp; - float angleIncrement = 360.f / (float)m_rayCount; - for (int i = 0; i < m_rayCount; i++) - { - temp = sf::Vertex{ constructVector(m_origin, sf::degrees(angleIncrement * i), m_rayLength), m_lightColor }; - - if (withinBounds(temp.position - m_origin, lowerBoundVector, upperBoundVector)) m_rays.emplace_back(temp); - } - } - - sf::Angle angle; - - for (auto& poly : polygons) - { - for (std::size_t i = 0; i < poly.getVertexCount() - 1; i++) - { - if (poly[i].position == m_origin) continue;// cannot pass zero vector to sf::Vector2::angleTo() - - if (hasFlags(Flags::infiniteLength) ? false : distanceBetween(m_origin, poly[i].position) >= m_rayLength) continue; - - if (not withinBounds(poly[i].position - m_origin, lowerBoundVector, upperBoundVector)) continue; - - angle = sf::radians(std::atan2f(poly[i].position.y - m_origin.y, poly[i].position.x - m_origin.x)); - - m_rays.emplace_back(sf::Vertex{ poly[i].position, m_lightColor }); - m_rays.emplace_back(sf::Vertex{ constructVector( m_origin, angle + sf::radians(.00001f), m_rayLength + infiniteLength), m_lightColor }); - m_rays.emplace_back(sf::Vertex{ constructVector( m_origin, angle - sf::radians(.00001f), m_rayLength + infiniteLength), m_lightColor }); - } - } - - m_rays.emplace_back(lowerBound); - m_rays.emplace_back(upperBound); - - std::sort(m_rays.begin(), m_rays.end(), [&](const auto& lhs, const auto& rhs) { return (lhs.position - m_origin).angleTo(upperBoundVector).wrapUnsigned().asRadians() < (rhs.position - m_origin).angleTo(upperBoundVector).wrapUnsigned().asRadians(); }); -} - -void Light::calculateIntersects(const std::vector& polygons) -{ - std::optional currentIntersect{}; - - for (auto& ray : m_rays) - { - sf::Vector2f closestIntersection = ray.position; - currentIntersect.reset(); - - for (auto& poly : polygons) - { - for (std::size_t i = 1; i <= poly.getVertexCount() - 1; i++) - { - currentIntersect = lineIntersect({ m_origin, ray.position }, { poly[i - 1].position , poly[i].position }); - - if (not currentIntersect) continue; - if ((closestIntersection - m_origin).length() < (currentIntersect.value() - m_origin).length()) continue; - - closestIntersection = currentIntersect.value(); - } - } - - ray.position = closestIntersection; - } - -} - -bool Light::withinBounds(sf::Vector2f point, sf::Vector2f lower, sf::Vector2f upper) -{ - return point.angleTo(upper).wrapUnsigned().asRadians() < (lower).angleTo(upper).wrapUnsigned().asRadians(); -} \ No newline at end of file diff --git a/Light.h b/Light.h deleted file mode 100644 index e31a4ce..0000000 --- a/Light.h +++ /dev/null @@ -1,117 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "Utility.hpp" - -class Light -{ -public: - Light() = default; - - Light(sf::Vector2f origin, bool visible = true) - : m_origin(origin) - { - m_light.push_back(sf::Vertex{ m_origin, m_lightColor}); - visible ? setFlags(Flags::visibility) : unsetFlags(Flags::visibility); - } - - Light(sf::Vector2f origin, sf::Angle center, sf::Angle offset, bool visible = true) - : m_center(center) - , m_offset(offset) - , m_origin(origin) - { - m_light.push_back(sf::Vertex{ m_origin, m_lightColor }); - visible ? setFlags(Flags::visibility) : unsetFlags(Flags::visibility); - } - -public: - enum class Flags - { - visibility = 1 << 0, - infiniteLength = 1 << 1, - drawRays = 1 << 2, - drawEndPoints = 1 << 3 - }; - - void addAngleBounds(sf::Angle center, sf::Angle offset) - { - m_center = center; - m_offset = offset; - } - - void removeAngleBounds() - { - m_center.reset(); - m_offset.reset(); - } - - void setFlags(Flags flags) { m_flags |= (int)flags; } - void unsetFlags(Flags flags) { m_flags &= ~(int)flags; } - void toggleFlags(Flags flags) { m_flags ^= (int)flags; } - bool hasFlags(Flags flags) const { return (m_flags & (int)flags) == (int)flags; } - - void setCenterAngle(sf::Angle center) { m_center = center; } - std::optional getCenterAngle() const { return m_center; } - - void setOffsetAngle(sf::Angle offset) { m_offset = offset; } - std::optional getOffsetAngle() const { return m_offset; } - - void setOrigin(sf::Vector2f point) { m_origin = point; } - sf::Vector2f getOrigin() const { return m_origin; } - - void setRayCount(int input) { m_rayCount = input; } - int getRayCount() const { return m_rayCount; }; - - float getRayLength() { return m_rayLength; } - void setRayLength(float input) { m_rayLength = input; } - - void draw(sf::RenderWindow& window); - - void clearRays() { m_rays.clear(); m_light.clear(); m_light.push_back(sf::Vertex{ {0.f,0.f}, m_lightColor }); } - - void changeLightColor(sf::Color color) { m_lightColor = color; } - void changeEndPointColor(sf::Color color) { m_endPointColor = color; } - void changeRayColor(sf::Color color) { m_rayColor = color; } - - void processRays(const std::vector& polygons); - -private: - std::vector m_light{}; - std::vector m_rays{}; - std::optional m_center{}; - std::optional m_offset{}; - sf::Vector2f m_origin{}; - sf::Color m_lightColor{ sf::Color::Yellow }; - sf::Color m_endPointColor{ sf::Color::Magenta }; - sf::Color m_rayColor{ sf::Color::Red }; - - float m_rayLength{ 500.f }; - int m_rayCount{ 500 }; - int m_flags{}; - - enum - { - start, - end - };//used for sf::VertexArray index - -private: - void constructFullLight(const std::vector& polygons); - void constructPartialLight(const std::vector& polygons); - - void createAndSortRays(const std::vector& polygons); - void createAndSortRays(const std::vector& polygons, sf::Angle lowerAngleBounds, sf::Angle upperAngleBounds);// for bounded light - - void calculateIntersects(const std::vector& polygons); - - bool withinBounds(sf::Vector2f point, sf::Vector2f lower, sf::Vector2f upper); -}; - diff --git a/Random.h b/Random.h deleted file mode 100644 index c1b4fea..0000000 --- a/Random.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once -#ifndef RANDOM_MT_H -#define RANDOM_MT_H - -#include -#include - -// This header-only Random namespace implements a self-seeding Mersenne Twister -// It can be included into as many code files as needed (The inline keyword avoids ODR violations) -// Freely redistributable, courtesy of learncpp.com -namespace Random -{ - // Returns a seeded Mersenne Twister - // Note: we'd prefer to return a std::seed_seq (to initialize a std::mt19937), but std::seed can't be copied, so it can't be returned by value. - // Instead, we'll create a std::mt19937, seed it, and then return the std::mt19937 (which can be copied). - inline std::mt19937 generate() - { - std::random_device rd{}; - - // Create seed_seq with clock and 7 random numbers from std::random_device - std::seed_seq ss{ - static_cast(std::chrono::steady_clock::now().time_since_epoch().count()), - rd(), rd(), rd(), rd(), rd(), rd(), rd() }; - - return std::mt19937{ ss }; - } - - // Here's our global std::mt19937 object. - // The inline keyword means we only have one global instance for our whole program. - inline std::mt19937 mt{ generate() }; // generates a seeded std::mt19937 and copies it into our global object - - // Generate a random int between [min, max] (inclusive) - inline int get(int min, int max) - { - return std::uniform_int_distribution{ min, max }(mt); - } - - // The following function templates can be used to generate random numbers - // when min and/or max are not type int - // See https://www.learncpp.com/cpp-tutorial/function-template-instantiation/ - // You can ignore these if you don't understand them - - // Generate a random value between [min, max] (inclusive) - // * min and max have same type - // * Return value has same type as min and max - // * Supported types: - // * short, int, long, long long - // * unsigned short, unsigned int, unsigned long, or unsigned long long - // Sample call: Random::get(1L, 6L); // returns long - // Sample call: Random::get(1u, 6u); // returns unsigned int - template - T get(T min, T max) - { - return std::uniform_int_distribution{min, max}(mt); - } - - // Generate a random value between [min, max] (inclusive) - // * min and max can have different types - // * Must explicitly specify return type as template type argument - // * min and max will be converted to the return type - // Sample call: Random::get(0, 6); // returns std::size_t - // Sample call: Random::get(0, 6u); // returns std::size_t - // Sample call: Random::get(0, 6u); // returns int - template - R get(S min, T max) - { - return get(static_cast(min), static_cast(max)); - } - - template - T getRandomNumber(U min, V max) - { - return static_cast(get(min, max)); - } -} - -#endif \ No newline at end of file diff --git a/Utility.hpp b/Utility.hpp deleted file mode 100644 index 6b72f38..0000000 --- a/Utility.hpp +++ /dev/null @@ -1,147 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "Random.h" - - - -template -inline T getRandomNumber(U min, V max) -{ - return static_cast(Random::get(min, max)); -} - -template -inline sf::Color createColor(T r, U g, V b, W a) -{ - return sf::Color(static_cast(r), static_cast(g), static_cast(b), static_cast(a)); -} - -template -inline sf::Color createColor(T r, U g, V b, std::uint8_t a = 255u) -{ - return sf::Color(static_cast(r), static_cast(g), static_cast(b), a); -} - -inline sf::Color getRandomColor() -{ - return sf::Color(getRandomNumber(0u, 255u), getRandomNumber(0u, 255u), getRandomNumber(0u, 255u)); -} - -template -inline T signage(T in) -{ - T zero{}; - if (in > zero) return ++zero; - if (in < zero) return --zero; - return zero; -} - -struct LineSegment -{ - sf::Vector2f startPoint{}; - - sf::Vector2f endPoint{}; -}; - -struct imguiColor -{ - float r{}; - float g{}; - float b{}; - float a{ 1.f }; - - sf::Color asSfColor() - { - return sf::Color(std::uint8_t(r * 255.f), std::uint8_t(g * 255.f), std::uint8_t(b * 255.f), std::uint8_t(a * 255.f)); - } -}; - -inline imguiColor constructImguiColor(sf::Color color) -{ - return imguiColor((float)color.r / 255.f, (float)color.g / 255.f, (float)color.b / 255.f, (float)color.a / 255.f); -} - -inline std::optional lineIntersect(LineSegment first, LineSegment second) -{ - sf::Vector2f firstVector = (first.endPoint - first.startPoint); - sf::Vector2f secondVector = (second.endPoint - second.startPoint); - - float lengthCrossProduct = firstVector.cross(secondVector); - - sf::Vector2f fms = second.startPoint - first.startPoint; //first line start point minus second - - float firstScalar = fms.cross(secondVector) / lengthCrossProduct; - float secondScalar = fms.cross(firstVector) / lengthCrossProduct; - - if ((firstScalar >= 0 and firstScalar <= 1) and (secondScalar >= 0 and secondScalar <= 1)) - return sf::Vector2f(first.startPoint.x + (firstScalar * firstVector.x), first.startPoint.y + (firstScalar * firstVector.y)); - else - return std::nullopt; -} - -inline sf::VertexArray constructRectangle(sf::Vector2f center, sf::Vector2f size, sf::Color color = sf::Color::Black) -{ - sf::VertexArray rectangle(sf::PrimitiveType::LineStrip, 5); - rectangle[0].color = color; - rectangle[1].color = color; - rectangle[2].color = color; - rectangle[3].color = color; - rectangle[4].color = color; - - rectangle[0].position = { center.x - size.x, center.y - size.y }; - rectangle[1].position = { center.x + size.x, center.y - size.y }; - rectangle[2].position = { center.x + size.x, center.y + size.y }; - rectangle[3].position = { center.x - size.x, center.y + size.y }; - rectangle[4].position = rectangle[0].position; - - return rectangle; -} - -inline sf::Vector2f constructVector(sf::Vector2f startPoint, sf::Angle angle, float length) -{ - return { startPoint.x + (length * std::cos(angle.asRadians())), startPoint.y + (length * std::sin(angle.asRadians())) }; -} - -inline sf::VertexArray constructRandomPolygon(sf::Vector2f center, int vertexLowerBound, int vertexUpperBound, int averageSize, sf::Color color = sf::Color::Black) -{ - std::size_t vertexCount = getRandomNumber(vertexLowerBound, vertexUpperBound); - sf::VertexArray polygon(sf::PrimitiveType::LineStrip, vertexCount); - - float angleIncrement = 360.f / (float)(vertexCount - 1); - float angleStart = getRandomNumber(0, 360); - - for (int i = 0; i < vertexCount - 1; i++) - { - float angleOffset = getRandomNumber(-(90 / (int)vertexCount), (90 / (int)vertexCount)); - polygon[i].color = color; - polygon[i].position = constructVector(center, sf::degrees(angleStart + (angleIncrement * i) + angleOffset), getRandomNumber((averageSize - 50), (averageSize + 50))); - } - polygon[vertexCount - 1].position = polygon[0].position; - polygon[vertexCount - 1].color = color; - return polygon; -} - -inline float distanceBetween(sf::Vector2f startPoint, sf::Vector2f endPoint) -{ - return sqrtf(powf(endPoint.x - startPoint.x, 2) + powf(endPoint.y - startPoint.y, 2)); -} - -inline sf::VertexArray constructVertexArray(sf::Shape& shape) -{ - sf::VertexArray result(sf::PrimitiveType::LineStrip); - auto& transform = shape.getTransform(); - - for (int i = 0; i < shape.getPointCount(); i++) - { - result.append(sf::Vertex{ transform.transformPoint(shape.getPoint(i)), sf::Color::Black }); - } - - result.append(result[0]); - return result; -} \ No newline at end of file diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 3456956..0000000 --- a/main.cpp +++ /dev/null @@ -1,278 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "Utility.hpp" -#include "Light.h" - - -auto window = sf::RenderWindow(sf::VideoMode({ 1920u, 1080u }), "Ray Casting Test"); - -Light light; -std::vector polygons; -sf::CircleShape circle{}; - -sf::Vector2f mousePos{}; -sf::Vector2f center{ 1920.f / 2.f, 1080.f / 2.f }; - -//imGui Variables -constexpr int numRaysBounds[2] = { 5, 500 }; -constexpr float rayLengthBounds[2] = {5.f, 5000.f}; -constexpr float offsetAngleBounds[2] = { 5.f, 175.f }; -constexpr int vertexMin{ 3 }; -constexpr int vertexMax{ 20 }; -constexpr float rotationSpeedScale{ 3.f }; -float polySize[2] = { 100.f, 100.f }; -int numRays{ 500 }; -int vertexBounds[2] = { 3, 10 }; -int averageSize{ 100 }; -float rayLength{ 500.f }; -imguiColor rayColor = constructImguiColor(sf::Color::Red); -imguiColor lightColor = constructImguiColor(sf::Color::Yellow); -imguiColor endPointColor = constructImguiColor(sf::Color::Magenta); -bool drawRays{ false }; -bool drawLight{ true }; -bool drawEndPoints{ false }; -bool boundedLight{ false }; -bool infiniteRayLength{ false }; -float lightCenterAngle{ 0.f }; -float lightOffsetAngle{ 45.f }; - -void GUI(); -void userInput(); -void render(); - -int main() -{ - //configure light with default imgui vatiables - drawRays ? light.setFlags(Light::Flags::drawRays) : light.unsetFlags(Light::Flags::drawRays); - drawLight ? light.setFlags(Light::Flags::visibility) : light.unsetFlags(Light::Flags::visibility); - boundedLight ? light.addAngleBounds(sf::degrees(lightCenterAngle), sf::degrees(lightOffsetAngle)) : light.removeAngleBounds(); - drawEndPoints ? light.setFlags(Light::Flags::drawEndPoints) : light.unsetFlags(Light::Flags::drawEndPoints); - infiniteRayLength ? light.setFlags(Light::Flags::infiniteLength) : light.unsetFlags(Light::Flags::infiniteLength); - - //sfml setup - sf::Clock clock; - window.setFramerateLimit(144); - if (!ImGui::SFML::Init(window)) - return -1; - - mousePos = center; - - polygons.emplace_back(constructRectangle(center, center)); - - circle.setOrigin({0,0}); - circle.setPosition(center); - circle.setRadius(200.f); - circle.setPointCount(30u); - polygons.emplace_back(constructVertexArray(circle)); - - //main game loop - while (window.isOpen()) - { - ImGui::SFML::Update(window, clock.restart()); - - light.clearRays(); - - userInput(); - - GUI(); - - light.setOrigin(mousePos); - light.processRays(polygons); - - render(); - - } - - ImGui::SFML::Shutdown(); -} - -void GUI() -{ - ImGui::Begin("Config"); - ImGui::Text("Controls:"); - ImGui::Indent(); - ImGui::Text("Right Click: place rectangle at mouse position"); - ImGui::Text("R: place a randomly sized polygon at mouse position"); - ImGui::Text("C: clear all polygons"); - ImGui::Text("Scroll wheel: increase/decrease light direction (if light is bounded)"); - ImGui::Unindent(); - if (ImGui::Checkbox("Render rays", &drawRays)) - { - light.toggleFlags(Light::Flags::drawRays); - } - - ImGui::SameLine(); - if (ImGui::Checkbox("Render end points", &drawEndPoints)) - { - light.toggleFlags(Light::Flags::drawEndPoints); - } - - ImGui::SameLine(); - if (ImGui::Checkbox("Render light", &drawLight)) - { - light.toggleFlags(Light::Flags::visibility); - } - - if (ImGui::Checkbox("Infinite ray length", &infiniteRayLength)) - { - light.toggleFlags(Light::Flags::infiniteLength); - } - - if (not infiniteRayLength) - { - ImGui::SliderInt("number of rays", &numRays, numRaysBounds[0], numRaysBounds[1]); - light.setRayCount(numRays); - - if (ImGui::InputFloat("Ray Length", &rayLength)) - { - rayLength = std::clamp(rayLength, rayLengthBounds[0], rayLengthBounds[1]); - } - light.setRayLength(rayLength); - } - - if (drawRays) - { - ImGui::ColorEdit4("Ray color", &rayColor.r); - } - - if (drawLight) - { - ImGui::ColorEdit4("Light color", &lightColor.r); - } - - if (drawEndPoints) - { - ImGui::ColorEdit4("End point color", &endPointColor.r); - } - - light.changeLightColor(lightColor.asSfColor()); - light.changeEndPointColor(endPointColor.asSfColor()); - light.changeRayColor(rayColor.asSfColor()); - - if(ImGui::Checkbox("Light is bounded", &boundedLight)) - { - boundedLight ? light.addAngleBounds(sf::degrees(lightCenterAngle), sf::degrees(lightOffsetAngle)) : light.removeAngleBounds(); - } - - if (boundedLight) - { - ImGui::SliderFloat("Light direction", &lightCenterAngle, 0.f, 359.f, "%.0f", ImGuiSliderFlags_::ImGuiSliderFlags_AlwaysClamp); - light.setCenterAngle(sf::degrees(lightCenterAngle)); - - ImGui::SliderFloat("Offset size", &lightOffsetAngle, offsetAngleBounds[0], offsetAngleBounds[1], "%.0f", ImGuiSliderFlags_::ImGuiSliderFlags_AlwaysClamp); - light.setOffsetAngle(sf::degrees(lightOffsetAngle)); - } - - ImGui::InputFloat2("rectangle Size (X,Y)", polySize, "%.1f"); - ImGui::Text("Random polygon config: "); - if (ImGui::SliderInt2("vertex count lower/upper bounds", vertexBounds, vertexMin, vertexMax)) - { - if (vertexBounds[0] > vertexBounds[1]) - vertexBounds[0] = vertexBounds[1]; - - if (vertexBounds[1] < vertexBounds[0]) - vertexBounds[0] = vertexBounds[1]; - } - - if (ImGui::InputInt("Average size", &averageSize)) - { - if (averageSize < 20) - { - averageSize = 20; - } - } - - ImGui::End(); -} - -void userInput() -{ - while (const std::optional event = window.pollEvent()) - { - ImGui::SFML::ProcessEvent(window, *event); - - if (event->is()) - { - window.close(); - } - - if (const auto* buttonPressed = event->getIf()) - { - switch (buttonPressed->scancode) - { - case sf::Keyboard::Scancode::C: - polygons.clear(); - polygons.emplace_back(constructRectangle(center, center)); - break; - - case sf::Keyboard::Scancode::R: - polygons.emplace_back(constructRandomPolygon(mousePos, vertexBounds[0] + 1, vertexBounds[1] + 1, averageSize)); - break; - - case sf::Keyboard::Scancode::Escape: - window.close(); - break; - - default: - break; - } - } - - if (const auto* mousePressed = event->getIf()) - { - switch (mousePressed->button) - { - case sf::Mouse::Button::Right: - polygons.emplace_back(constructRectangle((sf::Vector2f)mousePressed->position, { polySize[0], polySize[1] }, sf::Color::Black)); - break; - - default: - break; - } - } - - if (const auto* mouseWheelScrolled = event->getIf()) - { - switch (mouseWheelScrolled->wheel) - { - case sf::Mouse::Wheel::Vertical: - if (boundedLight) - { - lightCenterAngle += mouseWheelScrolled->delta * rotationSpeedScale; - if (lightCenterAngle > 359.f) lightCenterAngle = 0.f; - if (lightCenterAngle < 0.f) lightCenterAngle = 359.f; - } - break; - - default: - break; - } - } - - if (const auto* mouseMoved = event->getIf()) - { - mousePos = (sf::Vector2f)mouseMoved->position; - } - } -} - -void render() -{ - window.clear(sf::Color::White); - - light.draw(window); - - for (auto& poly : polygons) window.draw(poly); - - ImGui::SFML::Render(window); - - window.display(); -} \ No newline at end of file diff --git a/ray-casting-demos.sln b/ray-casting-demos.sln deleted file mode 100644 index 2c95890..0000000 --- a/ray-casting-demos.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.13.35919.96 d17.13 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ray-casting-demos", "ray-casting-demos.vcxproj", "{87FCE63B-6FB0-41AF-9DDA-1D3A9D26BA8A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {87FCE63B-6FB0-41AF-9DDA-1D3A9D26BA8A}.Debug|x64.ActiveCfg = Debug|x64 - {87FCE63B-6FB0-41AF-9DDA-1D3A9D26BA8A}.Debug|x64.Build.0 = Debug|x64 - {87FCE63B-6FB0-41AF-9DDA-1D3A9D26BA8A}.Debug|x86.ActiveCfg = Debug|Win32 - {87FCE63B-6FB0-41AF-9DDA-1D3A9D26BA8A}.Debug|x86.Build.0 = Debug|Win32 - {87FCE63B-6FB0-41AF-9DDA-1D3A9D26BA8A}.Release|x64.ActiveCfg = Release|x64 - {87FCE63B-6FB0-41AF-9DDA-1D3A9D26BA8A}.Release|x64.Build.0 = Release|x64 - {87FCE63B-6FB0-41AF-9DDA-1D3A9D26BA8A}.Release|x86.ActiveCfg = Release|Win32 - {87FCE63B-6FB0-41AF-9DDA-1D3A9D26BA8A}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {2124D0EB-5864-4A34-B80A-25A316955369} - EndGlobalSection -EndGlobal diff --git a/ray-casting-demos.vcxproj b/ray-casting-demos.vcxproj deleted file mode 100644 index b79e10d..0000000 --- a/ray-casting-demos.vcxproj +++ /dev/null @@ -1,156 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {87fce63b-6fb0-41af-9dda-1d3a9d26ba8a} - ray_casting_demos - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(SFML_DIR)\include;$(IMGUI_SFML_DIR);%(AdditionalIncludeDirectories) - stdcpp20 - AssemblyCode - - - Console - true - $(SFML_DIR)\lib;%(AdditionalLibraryDirectories) - sfml-graphics-d.lib;sfml-system-d.lib;sfml-window-d.lib;sfml-audio-d.lib;sfml-network-d.lib;opengl32.lib;%(AdditionalDependencies) - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(IMGUI_SFML_DIR);$(SFML_DIR)\include;%(AdditionalIncludeDirectories) - stdcpp20 - - - Windows - true - true - true - $(SFML_DIR)\lib;%(AdditionalLibraryDirectories) - sfml-graphics.lib;sfml-system.lib;sfml-window.lib;sfml-audio.lib;sfml-network.lib;opengl32.lib;%(AdditionalDependencies) - mainCRTStartup - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ray-casting-demos.vcxproj.filters b/ray-casting-demos.vcxproj.filters deleted file mode 100644 index 62e5d6f..0000000 --- a/ray-casting-demos.vcxproj.filters +++ /dev/null @@ -1,60 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {20b9a3b4-eb7c-4baa-be0b-c6e0d295c347} - - - {fe3c7015-3de6-4e35-adea-c623dcb78c0a} - - - {a5f9e058-615a-4f77-a4a5-50a0c3ab5cd7} - - - - - Source Files - - - Source Files\Imgui-sfml Files - - - Source Files\Imgui-sfml Files - - - Source Files\Imgui-sfml Files - - - Source Files\Imgui-sfml Files - - - Source Files\Imgui-sfml Files - - - Source Files\Classes - - - - - Header Files - - - Header Files - - - Header Files\Classes - - - \ No newline at end of file