diff --git a/src/definitions/camera.cpp b/src/definitions/camera.cpp index 472ae92..170cd5a 100644 --- a/src/definitions/camera.cpp +++ b/src/definitions/camera.cpp @@ -4,18 +4,22 @@ Camera::Camera(int width, int height) : position({0,0,0}), - direction({0,0,1}), - right({(float)width/(float)height,0,0}), - up({0,1,0}) { } + direction({0,0,1}), + right({(float)width/(float)height,0,0}), + up({0,1,0}), + width(width), + height(height) { } Camera::Camera(glm::vec3 position, glm::vec3 direction, glm::vec3 right, glm::vec3 up) : position(position), direction(direction), right(right), up(up) { } Camera::Camera(glm::vec3 position, int width, int height) : position(position), - direction({0,0,1}), - right({(float)width/(float)height,0,0}), - up({0,1,0}) { } + direction({0,0,1}), + right({(float)width/(float)height,0,0}), + up({0,1,0}), + width(width), + height(height) { } void Camera::LookAt(glm::vec3 position, glm::vec3 sky, glm::vec3 lookAt, float angle, int width, int height) { float rightL = width / (float) height; @@ -28,9 +32,9 @@ void Camera::LookAt(glm::vec3 position, glm::vec3 sky, glm::vec3 lookAt, float a Ray Camera::CastRay(int x, int y, float spX, float spY) { // TODO: ACTUALLY GET A WORKING CAMERA - float camX = (((float)x + spX) / (float)600 * 2.0f - 1.0f) * getAspectRatio(600, 600) * getFovAdjustment(45.0f); + float camX = (((float)x + spX) / (float)width * 2.0f - 1.0f) * getAspectRatio(width, height) * getFovAdjustment(45.0f); // 1.0 is taken first here as y is in the vertical - float camY = (1.0f - ((float)y + spY) / (float)600 * 2.0f) * getFovAdjustment(45.0f); + float camY = (1.0f - ((float)y + spY) / (float)height * 2.0f) * getFovAdjustment(45.0f); Ray ray{ {0.0f, 0.0f, 0.0f}, {camX, camY, -1.0f} }; ray.direction = glm::normalize(ray.direction); diff --git a/src/definitions/camera.hpp b/src/definitions/camera.hpp index d8384a6..54e6b64 100644 --- a/src/definitions/camera.hpp +++ b/src/definitions/camera.hpp @@ -17,6 +17,7 @@ public: glm::vec3 position; glm::vec3 direction, right, up; + int width, height; }; #endif diff --git a/src/definitions/primatives/mesh.cpp b/src/definitions/primatives/mesh.cpp new file mode 100644 index 0000000..ff240aa --- /dev/null +++ b/src/definitions/primatives/mesh.cpp @@ -0,0 +1,3 @@ +#include "mesh.hpp" + + diff --git a/src/definitions/primatives/mesh.hpp b/src/definitions/primatives/mesh.hpp new file mode 100644 index 0000000..58343b7 --- /dev/null +++ b/src/definitions/primatives/mesh.hpp @@ -0,0 +1,12 @@ +#ifndef INFERNO_DEFINITIONS_PRIMATIVES_MESH_H_ +#define INFERNO_DEFINITIONS_PRIMATIVES_MESH_H_ + +#include + +class Triangle; + +class Mesh { + std::vector triangles; +}; + +#endif diff --git a/src/definitions/scene.hpp b/src/definitions/scene.hpp index de91c50..f52b697 100644 --- a/src/definitions/scene.hpp +++ b/src/definitions/scene.hpp @@ -5,6 +5,7 @@ class Camera; class Primative; +class Mesh; class Scene { public: @@ -12,6 +13,7 @@ public: int w, h; Camera* camera; std::vector objects; + std::vector meshs; }; #endif diff --git a/src/engine/progressiverenderer.cpp b/src/engine/progressiverenderer.cpp index 2e91922..564a0cd 100644 --- a/src/engine/progressiverenderer.cpp +++ b/src/engine/progressiverenderer.cpp @@ -32,6 +32,7 @@ void ProgressiveRenderer::Render() { int frames = 0; auto startTime = std::chrono::high_resolution_clock::now(); + while (m_interface->Active) { auto frameStartTime = std::chrono::high_resolution_clock::now(); @@ -39,7 +40,7 @@ void ProgressiveRenderer::Render() { for (int x = 0; x < m_scene->w; x++) #pragma omp parallel for schedule(dynamic) for (int y = 0; y < m_scene->h; y++) { - + SDL_Event e; while (SDL_PollEvent(&e)) if (e.type == SDL_QUIT) m_interface->Close(); diff --git a/src/pixel.hpp b/src/pixel.hpp index 2e06f4e..771dfb6 100644 --- a/src/pixel.hpp +++ b/src/pixel.hpp @@ -11,11 +11,11 @@ struct Pixel { : r(r), g(g), b(b) { }; inline uint32_t argb() { - return a << 24 | r << 16 | g << 8| b; + return a << 24 | r << 16 | g << 8 | b; } inline uint32_t rgb() { - return 0xFF000000 | r << 16 | g << 8| b; + return 0xFF000000 | r << 16 | g << 8 | b; } inline void Clamp() { @@ -32,11 +32,11 @@ inline uint8_t Clamp(int n, int upper, int lower) { } inline uint32_t argb8888(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { - return a << 24 | r << 16 | g << 8| b; + return a << 24 | r << 16 | g << 8 | b; } inline uint32_t rgb888(uint8_t r, uint8_t g, uint8_t b) { - return 0xFF000000 | r << 16 | g << 8| b; + return 0xFF000000 | r << 16 | g << 8 | b; } #endif