camera bug and mesh class
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
|
||||
glm::vec3 position;
|
||||
glm::vec3 direction, right, up;
|
||||
int width, height;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
3
src/definitions/primatives/mesh.cpp
Normal file
3
src/definitions/primatives/mesh.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "mesh.hpp"
|
||||
|
||||
|
||||
12
src/definitions/primatives/mesh.hpp
Normal file
12
src/definitions/primatives/mesh.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef INFERNO_DEFINITIONS_PRIMATIVES_MESH_H_
|
||||
#define INFERNO_DEFINITIONS_PRIMATIVES_MESH_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
class Triangle;
|
||||
|
||||
class Mesh {
|
||||
std::vector<Triangle*> triangles;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -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<Primative*> objects;
|
||||
std::vector<Mesh*> meshs;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user