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:
parent
f03b19a022
commit
7d461477b3
@ -3,6 +3,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <math.h>
|
||||
#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;
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
#include "Ray.h"
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#define RAY_H RAY_H
|
||||
|
||||
#include "Vector.h"
|
||||
#include <iostream>
|
||||
|
||||
class Ray
|
||||
{
|
||||
@ -19,5 +20,7 @@ class Ray
|
||||
Vector m_direction;
|
||||
};
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, const Ray & r);
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user