include/scene.h
branchpyrit
changeset 47 320d5d466864
parent 46 6493fb65f0b1
child 49 558fde7da82a
equal deleted inserted replaced
46:6493fb65f0b1 47:320d5d466864
     1 /*
     1 /*
     2  * scene.h: classes for objects in scene
     2  * scene.h: classes for objects in scene
     3  *
     3  *
     4  * This file is part of Pyrit Ray Tracer.
     4  * This file is part of Pyrit Ray Tracer.
     5  *
     5  *
     6  * Copyright 2006, 2007  Radek Brich
     6  * Copyright 2006, 2007, 2008  Radek Brich
     7  *
     7  *
     8  * Permission is hereby granted, free of charge, to any person obtaining a copy
     8  * Permission is hereby granted, free of charge, to any person obtaining a copy
     9  * of this software and associated documentation files (the "Software"), to deal
     9  * of this software and associated documentation files (the "Software"), to deal
    10  * in the Software without restriction, including without limitation the rights
    10  * in the Software without restriction, including without limitation the rights
    11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    28 #define SCENE_H
    28 #define SCENE_H
    29 
    29 
    30 #include <vector>
    30 #include <vector>
    31 #include <typeinfo>
    31 #include <typeinfo>
    32 
    32 
       
    33 #include "sampler.h"
    33 #include "noise.h"
    34 #include "noise.h"
    34 #include "vector.h"
    35 #include "vector.h"
    35 #include "quaternion.h"
    36 #include "quaternion.h"
    36 
    37 
    37 /*
    38 /*
    54 	Ray(const Vector3 &ao, const Vector3 &adir):
    55 	Ray(const Vector3 &ao, const Vector3 &adir):
    55 		o(ao), dir(adir) {};
    56 		o(ao), dir(adir) {};
    56 };
    57 };
    57 
    58 
    58 /**
    59 /**
    59  * sample
       
    60  */
       
    61 class Sample
       
    62 {
       
    63 public:
       
    64 	Float x,y;
       
    65 };
       
    66 
       
    67 /**
       
    68  * A abstract sampler.
       
    69  * It generates screen samples in coordinates between [-1..1] for height
       
    70  * and [-w/h..w/h] for width. It works in phases: initSampleSet returns
       
    71  * number of samples for each phase, then samples can be generated using
       
    72  * nextSample method. The resulting colour of each sample should be returned
       
    73  * via saveSample method. The sampler should save the results to given buffer
       
    74  * and decide if other phase is needed. When the picture is complete,
       
    75  * initSampleSet returns zero and picture can be read from buffer.
       
    76  */
       
    77 class Sampler
       
    78 {
       
    79 public:
       
    80 	Float *buffer;
       
    81 	int w,h;
       
    82 
       
    83 	Sampler(Float *abuffer, int &aw, int &ah): buffer(abuffer), w(aw), h(ah) {};
       
    84 	void resetBuffer(Float *abuffer, int &aw, int &ah) { buffer = abuffer; w = aw; h = ah; };
       
    85 	virtual void init() = 0;
       
    86 	virtual int initSampleSet() = 0;
       
    87 	virtual Sample *nextSample(Sample *prev) = 0;
       
    88 	virtual void saveSample(Sample *samp, Colour &col) = 0;
       
    89 };
       
    90 
       
    91 /**
       
    92  * default sample
       
    93  */
       
    94 class DefaultSample: public Sample
       
    95 {
       
    96 	friend class DefaultSampler;
       
    97 	int sx,sy;
       
    98 };
       
    99 
       
   100 /**
       
   101  * Default sampler.
       
   102  */
       
   103 class DefaultSampler: public Sampler
       
   104 {
       
   105 	int phase;
       
   106 public:
       
   107 	DefaultSampler(Float *abuffer, int &aw, int &ah): Sampler(abuffer, aw, ah), phase(-1) {};
       
   108 	void init() { phase = 0; };
       
   109 	int initSampleSet();
       
   110 	Sample *nextSample(Sample *prev);
       
   111 	void saveSample(Sample *samp, Colour &col);
       
   112 };
       
   113 
       
   114 /**
       
   115  * a camera
    60  * a camera
   116  */
    61  */
   117 class Camera
    62 class Camera
   118 {
    63 {
   119 public:
    64 public:
   168  * texture
   113  * texture
   169  */
   114  */
   170 class Texture
   115 class Texture
   171 {
   116 {
   172 public:
   117 public:
       
   118 	virtual ~Texture() {};
   173 	virtual Colour evaluate(Vector3 point) = 0;
   119 	virtual Colour evaluate(Vector3 point) = 0;
   174 };
   120 };
   175 
   121 
   176 /**
   122 /**
   177  * material
   123  * material