diff --git a/main/Scene.cc b/main/Scene.cc index ba0aef8..79994e2 100644 --- a/main/Scene.cc +++ b/main/Scene.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include "BMP.h" #include "shapes/Shape.h" #include "shapes/Sphere.h" @@ -94,7 +95,7 @@ void Scene::render() { for (int j = 0; j < m_width; j++) { - renderPixel(i, j, &m_data[3 * (m_width * i + j)]); + renderPixel(j, i, &m_data[3 * (m_width * i + j)]); } } @@ -108,6 +109,14 @@ void Scene::render() void Scene::renderPixel(int x, int y, unsigned char * pixel) { + /* calculate the ray going from the camera through this pixel */ + double rx = (x + 0.5) - (m_width >> 1); + double rz = (m_height >> 1) - (y + 0.5); + /* ry is calculated based on the field of view */ + double ry = (m_height / 2.0) / atan(m_vfov / 2.0); + + Ray ray(Vector(0, 0, 0), Vector(rx, ry, rz)); + // TODO: um... real work pixel[BMP_RED] = 0; pixel[BMP_GREEN] = 0; diff --git a/util/Ray.cc b/util/Ray.cc index 1d48344..88baf51 100644 --- a/util/Ray.cc +++ b/util/Ray.cc @@ -1,5 +1,6 @@ #include "Ray.h" +#include Ray::Ray() { @@ -24,3 +25,9 @@ Vector Ray::getPositionAt(double dist) const v[2] = m_origin[2] + dist * m_direction[2]; return v; } + +std::ostream & operator<<(std::ostream & out, const Ray & r) +{ + out << "(" << r.getOrigin() << " -> " << r.getDirection() << ")"; + return out; +} diff --git a/util/Ray.h b/util/Ray.h index b7221b6..5700090 100644 --- a/util/Ray.h +++ b/util/Ray.h @@ -3,6 +3,7 @@ #define RAY_H RAY_H #include "Vector.h" +#include class Ray { @@ -19,5 +20,7 @@ class Ray Vector m_direction; }; +std::ostream & operator<<(std::ostream & out, const Ray & r); + #endif