Camera and rays

This commit is contained in:
Ben Kyd
2019-07-30 01:23:45 +01:00
parent f8dba5442b
commit 3bb08e48ca
8 changed files with 43 additions and 20 deletions

View File

@@ -3,15 +3,22 @@
#include "camera.hpp"
#include "scene.hpp"
Ray GeneratePrimaryRay(int x, int y, Scene& scene, float xSubPix, float ySubPix) {
// double dy = 1.0;
Ray GeneratePrimaryRay(int x, int y, Scene* scene, float xSubPix, float ySubPix) {
Camera* cam = scene->camera;
float dy = 1.0f;
float dx = 1.0f;
float px = (-(float)cam->w / 2.0f) + dx * ((float)x + xSubPix);
float py = (-(float)cam->h / 2.0f) + dy * ((float)y + ySubPix);
glm::vec3 p = cam->planeCenter + (cam->planeDirX * px) + (cam->planeDirY * py);
glm::vec3 dir = glm::normalize(p - cam->point);
return {cam->point, dir};
// double dy = 1.0;
// double dx = 1.0;
// double py = (- c->height / 2.0) + dy * ((double)y + 0.5);
// double px = (- c->width / 2.0) + dx * ((double)x + 0.5);
// double py = (- c->height / 2.0) + dy * ((double)y + 0.5);
// Vector3 p = vec3_add3(c->planeCenter,
// vec3_mult(c->planeDirectionX, px),
// vec3_mult(c->planeDirectionY, py));
// Vector3 u_r = vec3_unit(vec3_sub(p, c->position));
// return ray_make(c->position, u_r);
return {};
}