sphere drawing, but stretched horizontally... have to figure that out yet

git-svn-id: svn://anubis/fart/trunk@40 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2009-01-23 16:00:43 +00:00
1 parent 97b9fa9eab
commit a1c81e5adc
4 files changed
+28 -8

No files matched your search

+21 -7
View File
@@ -52,6 +52,9 @@ Scene::Scene(map<string, const char *> options,
m_verbose = true;
}
}
/* view plane distance is calculated based on the field of view */
m_view_plane_dist = (m_height / 2.0) / atan(m_vfov / 2.0);
}
Scene::~Scene()
@@ -69,8 +72,8 @@ Scene::~Scene()
void Scene::load(const char * filename)
{
/* TODO: parse file somehow */
Shape * shape = new Sphere(2.0);
m_transform.translate(2.0, 6.0, 1.0);
Shape * shape = new Sphere(1.0);
m_transform.translate(2.0, 2.0, 0.0);
shape->setTransform(m_transform);
m_shapes.push_back(shape);
}
@@ -110,12 +113,10 @@ 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);
double rx = (x + 0.5) - (m_width / 2.0);
double rz = (m_height / 2.0) - (y + 0.5);
Ray ray(Vector(0, 0, 0), Vector(rx, ry, rz));
Ray ray(Vector(0, 0, 0), Vector(rx, m_view_plane_dist, rz));
/* loop through all shapes in the scene */
for (vector<Shape *>::iterator it = m_shapes.begin();
@@ -128,5 +129,18 @@ void Scene::renderPixel(int x, int y, unsigned char * pixel)
/* then intersect this inversely transformed ray with the shape */
Solver::Result intersections = (*it)->intersect(transformed_ray);
if (intersections.numResults > 0)
{
pixel[BMP_RED] = 0xFF;
pixel[BMP_GREEN] = 0xFF;
pixel[BMP_BLUE] = 0xFF;
}
else
{
pixel[BMP_RED] = 0x0;
pixel[BMP_GREEN] = 0x0;
pixel[BMP_BLUE] = 0x0;
}
}
}
+1
View File
@@ -31,6 +31,7 @@ class Scene
/* private data */
std::vector<Shape *> m_shapes;
Transform m_transform;
double m_view_plane_dist;
/* framebuffer */
unsigned char * m_data;