Use the PerspectiveCamera to generate primary rays.
This commit is contained in:
parent
899064ce42
commit
25b246d3ed
2 changed files with 10 additions and 5 deletions
12
src/scene.cc
12
src/scene.cc
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
Scene::Scene()
|
Scene::Scene()
|
||||||
: width(640), height(480),
|
: width(640), height(480),
|
||||||
|
camera(new PerspectiveCamera()),
|
||||||
max_depth(5),
|
max_depth(5),
|
||||||
min_weight(1e-4),
|
min_weight(1e-4),
|
||||||
ambient(new AmbientLight()),
|
ambient(new AmbientLight()),
|
||||||
|
@ -30,6 +31,11 @@ Scene::Scene()
|
||||||
|
|
||||||
Scene::~Scene()
|
Scene::~Scene()
|
||||||
{
|
{
|
||||||
|
if (camera) {
|
||||||
|
delete camera;
|
||||||
|
camera = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (ambient != NULL) {
|
if (ambient != NULL) {
|
||||||
delete ambient;
|
delete ambient;
|
||||||
}
|
}
|
||||||
|
@ -130,11 +136,7 @@ Scene::render()
|
||||||
Vector3 o, d;
|
Vector3 o, d;
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
// Assemble a ray and trace it.
|
primary_ray = camera->compute_primary_ray(x, width, y, height);
|
||||||
o = Vector3(x, y, -1000);
|
|
||||||
d = Vector3(0, 0, 1);
|
|
||||||
d.normalize();
|
|
||||||
primary_ray = Ray(o, d);
|
|
||||||
Color c = trace_ray(primary_ray);
|
Color c = trace_ray(primary_ray);
|
||||||
pixels[y * width + x] = c;
|
pixels[y * width + x] = c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "basics.h"
|
#include "basics.h"
|
||||||
|
#include "camera.h"
|
||||||
|
|
||||||
|
|
||||||
class AmbientLight;
|
class AmbientLight;
|
||||||
|
@ -49,6 +50,8 @@ private:
|
||||||
// Pixel dimensions of the image.
|
// Pixel dimensions of the image.
|
||||||
int width, height;
|
int width, height;
|
||||||
|
|
||||||
|
Camera *camera;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ray tracing parameters. max_depth indicates the maximum depth of the ray tree. min_weight indicates the minimum
|
* Ray tracing parameters. max_depth indicates the maximum depth of the ray tree. min_weight indicates the minimum
|
||||||
* specular weight to apply before giving up.
|
* specular weight to apply before giving up.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue