From c610c4b94eda867a3f0b083038502dccb8116170 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 3 May 2022 16:12:52 +0200 Subject: Added source and related stubs --- CMakeLists.txt | 1 + ExampleSource.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ ExampleSource.h | 13 +++++++++++++ Killmail.h | 16 ++++++++++++++++ Location.h | 9 +++++++++ Owner.h | 10 ++++++++++ Ship.h | 8 ++++++++ Source.h | 12 ++++++++++++ main.cpp | 27 +++++++++++++-------------- 9 files changed, 129 insertions(+), 14 deletions(-) create mode 100644 ExampleSource.cpp create mode 100644 ExampleSource.h create mode 100644 Killmail.h create mode 100644 Location.h create mode 100644 Owner.h create mode 100644 Ship.h create mode 100644 Source.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b99e075..b0e7a6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ set(CMAKE_CXX_EXTENSIONS No) find_package(raylib 3 REQUIRED) add_executable( ${PROJECT_NAME} + ExampleSource.cpp main.cpp ) target_link_libraries(${PROJECT_NAME} raylib) diff --git a/ExampleSource.cpp b/ExampleSource.cpp new file mode 100644 index 0000000..e79e7ad --- /dev/null +++ b/ExampleSource.cpp @@ -0,0 +1,47 @@ +#include "ExampleSource.h" + +#include +#include + +#include + +#include "Killmail.h" + + +constexpr int AMOUNT {1000}; +constexpr float MAX {4.0f}; +constexpr float MIN {-4.0f}; +constexpr float STEP {0.1f}; + + +static float random_position(); + + +ExampleSource::ExampleSource() +{ +} + + +std::vector +ExampleSource::all() const +{ + std::vector killmails; + killmails.reserve(AMOUNT); + for (int i = 0; i < AMOUNT; ++i) { + Killmail km; + km.position = { + random_position(), + random_position(), + random_position(), + }; + killmails.push_back(std::move(km)); + } + return killmails; +} + + +float +random_position() +{ + return GetRandomValue(MIN / STEP, MAX / STEP) * STEP; +} diff --git a/ExampleSource.h b/ExampleSource.h new file mode 100644 index 0000000..2f45332 --- /dev/null +++ b/ExampleSource.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +#include "Killmail.h" +#include "Source.h" + + +struct ExampleSource : public Source +{ + ExampleSource(); + std::vector all() const override; +}; diff --git a/Killmail.h b/Killmail.h new file mode 100644 index 0000000..64cf972 --- /dev/null +++ b/Killmail.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include "Location.h" +#include "Owner.h" +#include "Ship.h" + + +struct Killmail +{ + Location location; + Owner owner; + Ship ship; + Vector3 position; +}; diff --git a/Location.h b/Location.h new file mode 100644 index 0000000..dbbb27b --- /dev/null +++ b/Location.h @@ -0,0 +1,9 @@ +#pragma once + + +struct Location +{ + const char* system; + const char* constellation; + const char* region; +}; diff --git a/Owner.h b/Owner.h new file mode 100644 index 0000000..b311f80 --- /dev/null +++ b/Owner.h @@ -0,0 +1,10 @@ +#pragma once + + +struct Owner +{ + const char* character; + const char* corporation; + const char* alliance; + const char* faction; +}; diff --git a/Ship.h b/Ship.h new file mode 100644 index 0000000..2ca6883 --- /dev/null +++ b/Ship.h @@ -0,0 +1,8 @@ +#pragma once + + +struct Ship +{ + const char* name; + const char* icon; +}; diff --git a/Source.h b/Source.h new file mode 100644 index 0000000..295a65b --- /dev/null +++ b/Source.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +#include "Killmail.h" + + +struct Source +{ + virtual ~Source() = default; + virtual std::vector all() const = 0; +}; diff --git a/main.cpp b/main.cpp index dfe0990..58c7347 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,13 @@ #include #include +#include #include #include +#include "ExampleSource.h" +#include "Source.h" + constexpr int AMOUNT {2000}; @@ -29,32 +33,27 @@ main(int argc, char* argv[]) camera.fovy = 45; camera.projection = CAMERA_PERSPECTIVE; SetCameraMode(camera, CAMERA_ORBITAL); - std::vector points; - points.reserve(AMOUNT); - for (int i = 0; i < AMOUNT; ++i) - points.push_back({ - GetRandomValue(-100, 100) * 0.05f, - GetRandomValue(-100, 100) * 0.05f, - GetRandomValue(-100, 100) * 0.05f}); + std::unique_ptr source = std::make_unique(); + auto killmails = source->all(); std::vector projected; while (!WindowShouldClose()) { UpdateCamera(&camera); projected.clear(); - projected.reserve(points.size()); + projected.reserve(killmails.size()); const int height = GetScreenHeight(); const int width = GetScreenWidth(); - for (const auto& point : points) { - const auto vec2 = GetWorldToScreen(point, camera); + for (const auto& km : killmails) { + const auto vec2 = GetWorldToScreen(km.position, camera); const float d = std::sqrt( - std::pow(camera.position.x - point.x, 2) + - std::pow(camera.position.y - point.y, 2) + - std::pow(camera.position.z - point.z, 2)); + std::pow(camera.position.x - km.position.x, 2) + + std::pow(camera.position.y - km.position.y, 2) + + std::pow(camera.position.z - km.position.z, 2)); if (0 > vec2.x || width < vec2.x || 0 > vec2.y || height < vec2.y) continue; projected.push_back(Entry{ - vec2, GetWorldToScreen({point.x, 0, point.z}, camera), d + vec2, GetWorldToScreen({km.position.x, 0, km.position.z}, camera), d }); } std::sort(projected.begin(), projected.end(), [](Entry& a, Entry& b){ return a.depth > b.depth; }); -- cgit v1.1