diff --git a/include/constants.hpp b/include/constants.hpp new file mode 100644 index 0000000..2c49b34 --- /dev/null +++ b/include/constants.hpp @@ -0,0 +1,10 @@ +#pragma once +#include + +namespace graphics { +// constexpr int WIDTH = 640; +constexpr int HEIGHT = 480; +constexpr int FRAME_RATE = 60; +constexpr int FRAME_TIME = 1000 / FRAME_RATE; +constexpr int FOV = 1; +} // namespace graphics diff --git a/include/display.hpp b/include/display.hpp index 6ab41f0..1e730e5 100644 --- a/include/display.hpp +++ b/include/display.hpp @@ -18,11 +18,14 @@ class Display { SDL_Surface *surface; SDL_Event *event; SDL_Renderer *renderer; - Vector3D camera; - Vector3D rotation; std::unique_ptr frameBuffer; std::vector vertices; + Vector3D camera; + Vector3D rotation; + + int prevTime; + public: // Constructor to initialize memory Display(); diff --git a/src/display.cpp b/src/display.cpp index 9e829d2..2f6fa92 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -2,12 +2,15 @@ #include +#include "../include/constants.hpp" #include "../include/vector3d.hpp" namespace graphics { Display::Display() { // Initialize the camera camera = Vector3D(0, 0, -5); + rotation = Vector3D(0, 0, 0); + prevTime = SDL_GetTicks(); // Initialize SDL if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { @@ -114,6 +117,8 @@ void Display::render() { frameBuffer->drawFilledRectangle( projectedPoint.x + (frameBuffer->getWidth() / 2), projectedPoint.y + (frameBuffer->getHeight() / 2), 4, 4, + projectedPoint.x * (frameBuffer->getWidth() / 2), + projectedPoint.y * (frameBuffer->getHeight() / 2), 4, 4, Color(0xFFFFFF00)); } diff --git a/src/vector3d.cpp b/src/vector3d.cpp index 9b1055d..88dfd20 100644 --- a/src/vector3d.cpp +++ b/src/vector3d.cpp @@ -1,9 +1,11 @@ #include "../include/vector3d.hpp" #include + +#include "../include/constants.hpp" namespace graphics { Vector2D Vector3D::project() const { - return Vector2D(x * 128 / z, y * 128 / z); + return Vector2D(x * FOV / z, y * FOV / z); } void Vector3D::rotateX(double theta) {