Skip to content

Commit

Permalink
Add constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaweees committed Oct 16, 2024
1 parent 9333157 commit 6bbf7a8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions include/constants.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include <cstdint>

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
7 changes: 5 additions & 2 deletions include/display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ class Display {
SDL_Surface *surface;
SDL_Event *event;
SDL_Renderer *renderer;
Vector3D camera;
Vector3D rotation;
std::unique_ptr<FrameBuffer> frameBuffer;
std::vector<Vector3D> vertices;

Vector3D camera;
Vector3D rotation;

int prevTime;

public:
// Constructor to initialize memory
Display();
Expand Down
5 changes: 5 additions & 0 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

#include <SDL2/SDL.h>

#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) {
Expand Down Expand Up @@ -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));
}

Expand Down
4 changes: 3 additions & 1 deletion src/vector3d.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "../include/vector3d.hpp"

#include <cmath>

#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) {
Expand Down

0 comments on commit 6bbf7a8

Please sign in to comment.