diff --git a/main.cpp b/main.cpp index a5aff64..c132253 100644 --- a/main.cpp +++ b/main.cpp @@ -2,28 +2,16 @@ #include #include "SDL.h" -struct Vector2 -{ - float x, y; - Vector2() - { - this->x = 0.f; - this->y = 0.f; - } - Vector2(float x_, float y_) - { - this->x = x_; - this->y = y_; - } -}; +#include "stuff/objects/vector2.h" +#include "stuff/objects/vector.h" + +#include "stuff/globals/globals.h" +#include "stuff/callbacks/callbacks.h" int main(int argc, char** argv) { - bool running = true; - Vector2 mousePos; - - SDL_Window* window = nullptr;; - SDL_Surface* surface = nullptr;; + SDL_Window* window = nullptr; + SDL_Surface* surface = nullptr; SDL_Init(SDL_INIT_VIDEO); window = SDL_CreateWindow("threedee", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, SDL_WINDOW_SHOWN); @@ -31,25 +19,10 @@ int main(int argc, char** argv) SDL_Event eventHandler; - while (running) + while (global::running) { - while (SDL_PollEvent(&eventHandler)) - { - switch (eventHandler.type) - { - case SDL_QUIT: - running = false; - break; - case SDL_MOUSEMOTION: - mousePos = Vector2(eventHandler.motion.x, eventHandler.motion.y); - break; - } - } - SDL_Rect cursor; - cursor.x = mousePos.x; - cursor.y = mousePos.y; - cursor.w = 5; - cursor.h = 5; + callbacks::handleCallbacks(&eventHandler); + SDL_Rect cursor{ global::mousePos.x, global::mousePos.y, 5, 5 }; SDL_FillRect(surface, &cursor, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF)); SDL_UpdateWindowSurface(window); diff --git a/stuff/callbacks/callbacks.cpp b/stuff/callbacks/callbacks.cpp new file mode 100644 index 0000000..537a08b --- /dev/null +++ b/stuff/callbacks/callbacks.cpp @@ -0,0 +1,17 @@ +#include "callbacks.h" + +void callbacks::handleCallbacks(SDL_Event* eventHandler) +{ + while (SDL_PollEvent(eventHandler)) + { + switch (eventHandler->type) + { + case SDL_QUIT: + global::running = false; + break; + case SDL_MOUSEMOTION: + callbacks::mouseMotion(eventHandler); + break; + } + } +} \ No newline at end of file diff --git a/stuff/callbacks/callbacks.h b/stuff/callbacks/callbacks.h new file mode 100644 index 0000000..156f6b3 --- /dev/null +++ b/stuff/callbacks/callbacks.h @@ -0,0 +1,18 @@ +#pragma once +#include +#include "SDL.h" + +#include "../globals/globals.h" + +namespace callbacks +{ + inline void mouseMotion(SDL_Event* eventResponse) + { + global::mousePos = vector2(eventResponse->motion.x, eventResponse->motion.y); + } + inline void quit(SDL_Event* eventResponse) + { + global::running = false; + } + void handleCallbacks(SDL_Event* eventHandler); +} \ No newline at end of file diff --git a/stuff/globals/globals.cpp b/stuff/globals/globals.cpp new file mode 100644 index 0000000..39e0e16 --- /dev/null +++ b/stuff/globals/globals.cpp @@ -0,0 +1,4 @@ +#include "globals.h" + +bool global::running = true; +vector2 global::mousePos; \ No newline at end of file diff --git a/stuff/globals/globals.h b/stuff/globals/globals.h new file mode 100644 index 0000000..5f23df0 --- /dev/null +++ b/stuff/globals/globals.h @@ -0,0 +1,7 @@ +#pragma once +#include "../objects/vector.h" +namespace global +{ + extern bool running; + extern vector2 mousePos; +} \ No newline at end of file diff --git a/stuff/objects/vector.h b/stuff/objects/vector.h new file mode 100644 index 0000000..303e4e6 --- /dev/null +++ b/stuff/objects/vector.h @@ -0,0 +1,21 @@ +#pragma once +#include "vector2.h" +/* +vectors extend vector2s and hold 3D cartesian coordinates +*/ +struct vector : public vector2 +{ + float z; + vector() + { + this->x = 0.f; + this->y = 0.f; + this->z = 0.f; + } + vector(float x_, float y_, float z_) + { + this->x = x_; + this->y = y_; + this->z = z_; + } +}; \ No newline at end of file diff --git a/stuff/objects/vector2.h b/stuff/objects/vector2.h new file mode 100644 index 0000000..80ffcec --- /dev/null +++ b/stuff/objects/vector2.h @@ -0,0 +1,18 @@ +#pragma once +/* +vector2s hold 2D cartesian coordinates +*/ +struct vector2 +{ + float x, y; + vector2() + { + this->x = 0.f; + this->y = 0.f; + } + vector2(float x_, float y_) + { + this->x = x_; + this->y = y_; + } +}; \ No newline at end of file diff --git a/threedee.vcxproj b/threedee.vcxproj index a2357b3..6da5674 100644 --- a/threedee.vcxproj +++ b/threedee.vcxproj @@ -240,9 +240,15 @@ + + + + + + diff --git a/threedee.vcxproj.filters b/threedee.vcxproj.filters index d133ba0..51eca80 100644 --- a/threedee.vcxproj.filters +++ b/threedee.vcxproj.filters @@ -273,10 +273,28 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + Source Files + + Source Files + + + Source Files + \ No newline at end of file