added operator<<(ostream, Ray) to util/Ray, main/Scene now calculating rays

git-svn-id: svn://anubis/fart/trunk@38 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-01-23 15:15:35 +00:00
parent f03b19a022
commit 7d461477b3
3 changed files with 20 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include <map> #include <map>
#include <math.h>
#include "BMP.h" #include "BMP.h"
#include "shapes/Shape.h" #include "shapes/Shape.h"
#include "shapes/Sphere.h" #include "shapes/Sphere.h"
@ -94,7 +95,7 @@ void Scene::render()
{ {
for (int j = 0; j < m_width; j++) 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) 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 // TODO: um... real work
pixel[BMP_RED] = 0; pixel[BMP_RED] = 0;
pixel[BMP_GREEN] = 0; pixel[BMP_GREEN] = 0;

View File

@ -1,5 +1,6 @@
#include "Ray.h" #include "Ray.h"
#include <iostream>
Ray::Ray() Ray::Ray()
{ {
@ -24,3 +25,9 @@ Vector Ray::getPositionAt(double dist) const
v[2] = m_origin[2] + dist * m_direction[2]; v[2] = m_origin[2] + dist * m_direction[2];
return v; return v;
} }
std::ostream & operator<<(std::ostream & out, const Ray & r)
{
out << "(" << r.getOrigin() << " -> " << r.getDirection() << ")";
return out;
}

View File

@ -3,6 +3,7 @@
#define RAY_H RAY_H #define RAY_H RAY_H
#include "Vector.h" #include "Vector.h"
#include <iostream>
class Ray class Ray
{ {
@ -19,5 +20,7 @@ class Ray
Vector m_direction; Vector m_direction;
}; };
std::ostream & operator<<(std::ostream & out, const Ray & r);
#endif #endif