include/raytracer.h
author Radek Brich <radek.brich@devl.cz>
Fri, 28 Mar 2008 00:53:20 +0100
branchpyrit
changeset 49 558fde7da82a
parent 48 a4913301c626
child 50 14a727b70d07
permissions -rw-r--r--
workaround for divide by zero bug in octree enable oversampling for DefaultSampler sampler and camera performance enhancements

/*
 * raytracer.h: Raytracer class
 *
 * This file is part of Pyrit Ray Tracer.
 *
 * Copyright 2006, 2007, 2008  Radek Brich
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef RAYTRACER_H
#define RAYTRACER_H

#include <vector>

#include "common.h"
#include "container.h"
#include "scene.h"

using namespace std;

class Raytracer;

struct RenderrowData {
	Raytracer *rt;
	int w;
	Vector3 eye, dfix, dx, dy;
	Float *iter;
};

/**
 * main ray tracer class
 */
class Raytracer
{
	Container *top;
	Sampler *sampler;
	Camera *camera;
	vector<Light*> lights;
	Colour bg_colour;
	int ao_samples;
	Float ao_distance, ao_angle;
	int num_threads;
	int max_depth;

	Vector3 SphereDistribute(int i, int n, Float extent, Vector3 &normal);
public:
	Raytracer(): top(NULL), camera(NULL), lights(), bg_colour(0.0, 0.0, 0.0),
		ao_samples(0), num_threads(2), max_depth(3) {};
	void render();
	Colour raytrace(Ray &ray, int depth, Shape *origin_shape);
	void addshape(Shape *shape) { top->addShape(shape); };
	void addlight(Light *light);
	void setSampler(Sampler *sampl) { sampler = sampl; };
	void setCamera(Camera *cam) { camera = cam; };
	void setTop(Container *atop) { top = atop; };
	Container *getTop() { return top; };

	void setMaxDepth(int newdepth) { max_depth = newdepth; };

	void ambientocclusion(int samples, Float distance, Float angle);
	void setThreads(int num) { num_threads = num; };
};

#endif