diff --git a/main.cpp b/main.cpp index df2b31c..b6cfce9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,11 @@ #include #include +#include #include "SDL.h" #include "stuff/objects/vector2.h" #include "stuff/objects/vector3.h" +#include "stuff/objects/ray2D.h" #include "stuff/globals/globals.h" #include "stuff/callbacks/callbacks.h" @@ -13,21 +15,35 @@ int main(int argc, char** argv) { SDL_Window* window = nullptr; SDL_Surface* surface = nullptr; + SDL_Renderer* renderer = nullptr; SDL_Init(SDL_INIT_VIDEO); window = SDL_CreateWindow("threedee", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, SDL_WINDOW_SHOWN); surface = SDL_GetWindowSurface(window); + renderer = SDL_CreateRenderer(window, -1, NULL); + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_Event eventHandler; global::entList.push_back(square(200, 200, 50)); + //global::entList3D.push_back(cube(200, 200, 100, 50)); + while (global::running) { callbacks::handleCallbacks(&eventHandler); - global::entList.run(surface); + //SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 0, 0, 0)); + + ray2D ray = ray2D::trace(vector2(0, 200), vector2(1, 0)); + //SDL_RenderClear(renderer); + SDL_RenderDrawLine(renderer, ray.start.x, ray.start.y, ray.end.x, ray.end.y); + SDL_RenderPresent(renderer); + + + //global::entList.run(surface); + //global::entList3D.run(surface); - SDL_UpdateWindowSurface(window); + //SDL_UpdateWindowSurface(window); SDL_Delay(1); } SDL_DestroyWindow(window); diff --git a/stuff/globals/globals.cpp b/stuff/globals/globals.cpp index ee16eff..b7023da 100644 --- a/stuff/globals/globals.cpp +++ b/stuff/globals/globals.cpp @@ -2,4 +2,5 @@ bool global::running = true; vector2 global::mousePos; -entityList2D global::entList; \ No newline at end of file +entityList2D global::entList; +entityList3D global::entList3D; \ No newline at end of file diff --git a/stuff/globals/globals.h b/stuff/globals/globals.h index 22c187b..ea68238 100644 --- a/stuff/globals/globals.h +++ b/stuff/globals/globals.h @@ -1,9 +1,11 @@ #pragma once #include "../objects/vector3.h" #include "../objects/entityList2D.h" +#include "../objects/entityList3D.h" namespace global { extern bool running; extern vector2 mousePos; extern entityList2D entList; + extern entityList3D entList3D; } \ No newline at end of file diff --git a/stuff/objects/camera.h b/stuff/objects/camera.h new file mode 100644 index 0000000..dd88965 --- /dev/null +++ b/stuff/objects/camera.h @@ -0,0 +1,5 @@ +#pragma once +struct camera +{ + +}; \ No newline at end of file diff --git a/stuff/objects/cube.h b/stuff/objects/cube.h index a25ab4c..3057056 100644 --- a/stuff/objects/cube.h +++ b/stuff/objects/cube.h @@ -16,7 +16,7 @@ struct cube : public square } void run(SDL_Surface* surface) { - SDL_Rect rect{ this->x, this->y, this->radius, this->radius }; - SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF)); + //SDL_Rect rect{ this->x, this->y, this->radius, this->radius }; + //SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF)); } }; \ No newline at end of file diff --git a/stuff/objects/ray2D.h b/stuff/objects/ray2D.h new file mode 100644 index 0000000..41a0d6c --- /dev/null +++ b/stuff/objects/ray2D.h @@ -0,0 +1,40 @@ +#pragma once +#include "../globals/globals.h" + +#include "vector2.h" + +//temp +bool inRect(vector2 point, vector2 a, vector2 b) +{ + return (point.x > a.x && point.y > a.y && point.x < b.x && point.y < b.y); +} + +struct ray2D +{ + vector2 start; + vector2 end; + float dist; + static ray2D trace(vector2 start, vector2 direction) + { + ray2D ray { start, start, 19 }; + vector2 point = start; + bool hit = false; + while (!hit) + { + for (square object : global::entList) + { + if (inRect(point, vector2(object.x - (object.radius / 2), object.y - (object.radius / 2)), vector2(object.x + (object.radius / 2), object.y + (object.radius / 2)))) + { + ray.start = start; + ray.end = point; + ray.dist = 19; + hit = true; + break; + } + } + point.x += direction.x; + point.y += direction.y; + } + return ray; + } +}; \ No newline at end of file diff --git a/threedee.vcxproj b/threedee.vcxproj index 9dfc5d1..8fed1ec 100644 --- a/threedee.vcxproj +++ b/threedee.vcxproj @@ -241,10 +241,12 @@ + + diff --git a/threedee.vcxproj.filters b/threedee.vcxproj.filters index 6d7f0a2..8c50236 100644 --- a/threedee.vcxproj.filters +++ b/threedee.vcxproj.filters @@ -297,6 +297,12 @@ Header Files + + Header Files + + + Header Files +