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 |
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: |