author | Radek Brich <radek.brich@devl.cz> |
Mon, 21 Apr 2008 19:35:27 +0200 | |
branch | pyrit |
changeset 76 | 3b60fd0bea64 |
parent 73 | a5127346fbcd |
child 78 | 9569e9f35374 |
permissions | -rw-r--r-- |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
/* |
44 | 2 |
* scene.h: classes for objects in scene |
3 |
* |
|
4 |
* This file is part of Pyrit Ray Tracer. |
|
5 |
* |
|
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
6 |
* Copyright 2006, 2007, 2008 Radek Brich |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
* |
44 | 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 |
|
10 |
* in the Software without restriction, including without limitation the rights |
|
11 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12 |
* copies of the Software, and to permit persons to whom the Software is |
|
13 |
* furnished to do so, subject to the following conditions: |
|
14 |
* |
|
15 |
* The above copyright notice and this permission notice shall be included in |
|
16 |
* all copies or substantial portions of the Software. |
|
17 |
* |
|
18 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
19 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
20 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
21 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
22 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
23 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
24 |
* THE SOFTWARE. |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
25 |
*/ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
26 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
#ifndef SCENE_H |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
#define SCENE_H |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
29 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
30 |
#include <vector> |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
31 |
#include <typeinfo> |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
|
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
33 |
#include "sampler.h" |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
34 |
#include "noise.h" |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
35 |
#include "vector.h" |
34
28f6e8b9d5d1
quaternion moved to extra header file
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
36 |
#include "quaternion.h" |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
38 |
/* |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
39 |
triangle intersection alghoritm |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
40 |
chooses are: |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
41 |
TRI_PLUCKER |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
42 |
TRI_BARI |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
43 |
TRI_BARI_PRE |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
44 |
*/ |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
45 |
#if !defined(TRI_PLUCKER) && !defined(TRI_BARI) && !defined(TRI_BARI_PRE) |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
46 |
# define TRI_BARI_PRE |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
47 |
#endif |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
48 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
using namespace std; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
50 |
|
12
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
51 |
class Ray |
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
52 |
{ |
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
53 |
public: |
15
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
14
diff
changeset
|
54 |
Vector3 o, dir; |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
55 |
Ray(): o(), dir() {}; |
15
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
14
diff
changeset
|
56 |
Ray(const Vector3 &ao, const Vector3 &adir): |
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
14
diff
changeset
|
57 |
o(ao), dir(adir) {}; |
12
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
58 |
}; |
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
59 |
|
46 | 60 |
/** |
61 |
* a camera |
|
62 |
*/ |
|
19
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
63 |
class Camera |
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
64 |
{ |
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
65 |
public: |
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
66 |
Vector3 eye, p, u, v; |
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
67 |
Float F; |
19
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
68 |
|
73
a5127346fbcd
correct camera angle of view
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
69 |
Camera(): eye(0,0,10), p(0,0,-1), u(-1,0,0), v(0,1,0), F(2.*tan(M_PI/8.)) {}; |
19
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
70 |
Camera(const Vector3 &C, const Vector3 &ap, const Vector3 &au, const Vector3 &av): |
73
a5127346fbcd
correct camera angle of view
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
71 |
eye(C), p(ap), u(au), v(av), F(2.*tan(M_PI/8.)) {}; |
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
72 |
Camera(const Vector3 &from, const Vector3 &lookat, const Vector3 &up): |
73
a5127346fbcd
correct camera angle of view
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
73 |
eye(from), F(2.*tan(M_PI/8.)) |
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
74 |
{ |
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
75 |
p = lookat - from; u = cross(up, p); |
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
76 |
p.normalize(); u.normalize(); |
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
77 |
v = cross(p, u); |
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
78 |
}; |
19
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
79 |
void setEye(const Vector3 &aeye) { eye = aeye; }; |
73
a5127346fbcd
correct camera angle of view
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
80 |
void setAngle(const Float angle) { F = 2.*tan(angle/2.); }; |
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
81 |
void rotate(const Quaternion &q); |
22 | 82 |
void move(const Float fw, const Float left, const Float up); |
46 | 83 |
|
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
84 |
Ray makeRay(Sample &samp) |
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
85 |
{ |
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
86 |
Vector3 dir = p - (u*samp.x + v*samp.y)*F; |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
87 |
dir.normalize(); |
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
88 |
return Ray(eye, dir); |
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
89 |
}; |
19
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
90 |
}; |
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
91 |
|
46 | 92 |
/** |
93 |
* axis-aligned bounding box |
|
94 |
*/ |
|
7
bf17f9f84c91
kd-tree: build algorithm - searching for all posible splits
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
95 |
class BBox |
bf17f9f84c91
kd-tree: build algorithm - searching for all posible splits
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
96 |
{ |
bf17f9f84c91
kd-tree: build algorithm - searching for all posible splits
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
97 |
public: |
bf17f9f84c91
kd-tree: build algorithm - searching for all posible splits
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
98 |
Vector3 L; |
14
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
99 |
Vector3 H; |
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
100 |
BBox(): L(), H() {}; |
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
101 |
BBox(const Vector3 aL, const Vector3 aH): L(aL), H(aH) {}; |
22 | 102 |
Float w() { return H.x-L.x; }; |
103 |
Float h() { return H.y-L.y; }; |
|
104 |
Float d() { return H.z-L.z; }; |
|
105 |
bool intersect(const Ray &ray, Float &a, Float &b); |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
106 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
107 |
|
46 | 108 |
/** |
109 |
* light object |
|
110 |
*/ |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
111 |
class Light |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
112 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
113 |
public: |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
114 |
Vector3 pos; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
115 |
Colour colour; |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
116 |
bool cast_shadows; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
117 |
|
40
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
118 |
Light(): |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
119 |
pos(Vector3(0,0,0)), colour(Colour(1,1,1)), cast_shadows(true) {}; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
120 |
Light(const Vector3 &position, const Colour &acolour): |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
121 |
pos(position), colour(acolour), cast_shadows(true) {}; |
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
122 |
void castShadows(bool cast) { cast_shadows = cast; }; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
123 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
124 |
|
46 | 125 |
/** |
126 |
* texture |
|
127 |
*/ |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
128 |
class Texture |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
129 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
130 |
public: |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
131 |
virtual ~Texture() {}; |
42 | 132 |
virtual Colour evaluate(Vector3 point) = 0; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
133 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
134 |
|
46 | 135 |
/** |
136 |
* material |
|
137 |
*/ |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
138 |
class Material |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
139 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
140 |
public: |
42 | 141 |
Colour colour; |
69
303583d2fb97
move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
142 |
Texture *texture; |
22 | 143 |
Float ambient, diffuse, specular, shininess; // Phong constants |
31 | 144 |
Float reflectivity; // how much reflective is the surface |
145 |
Float transmissivity, refract_index; // part of light which can be refracted; index of refraction |
|
69
303583d2fb97
move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
146 |
bool smooth; // triangle smoothing |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
147 |
|
69
303583d2fb97
move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
148 |
Material(const Colour &acolour): colour(acolour), texture(NULL), smooth(false) |
42 | 149 |
{ |
31 | 150 |
ambient = 0.2; |
151 |
diffuse = 0.8; |
|
152 |
specular = 0.2; |
|
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
153 |
shininess = 0.5; |
31 | 154 |
reflectivity = 0.2; |
155 |
transmissivity = 0.0; |
|
156 |
refract_index = 1.3; |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
157 |
} |
31 | 158 |
|
159 |
void setPhong(const Float amb, const Float dif, const Float spec, const Float shin) |
|
160 |
{ ambient = amb; diffuse = dif; specular = spec; shininess = shin; }; |
|
161 |
void setReflectivity(const Float refl) { reflectivity = refl; }; |
|
162 |
void setTransmissivity(const Float trans, const Float rindex) |
|
163 |
{ transmissivity = trans; refract_index = rindex; }; |
|
69
303583d2fb97
move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
164 |
void setSmooth(bool sm) { smooth = sm; }; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
165 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
166 |
|
46 | 167 |
/** |
168 |
* shape |
|
169 |
*/ |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
170 |
class Shape |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
171 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
172 |
public: |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
173 |
Material *material; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
174 |
Shape() {}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
175 |
virtual ~Shape() {}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
176 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
177 |
// first intersection point |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
178 |
virtual bool intersect(const Ray &ray, Float &dist) const = 0; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
179 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
180 |
// all intersections (only for CSG) |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
181 |
virtual bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const = 0; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
182 |
|
36
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
183 |
// intersection with AABB |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
184 |
virtual bool intersect_bbox(const BBox &bbox) const = 0; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
185 |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
186 |
// normal at point P |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
187 |
virtual const Vector3 normal(const Vector3 &P) const = 0; |
7
bf17f9f84c91
kd-tree: build algorithm - searching for all posible splits
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
188 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
189 |
virtual BBox get_bbox() const = 0; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
190 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
191 |
|
46 | 192 |
/** |
193 |
* list of shapes |
|
194 |
*/ |
|
24
d0d76e8a5203
new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
195 |
class ShapeList: public vector<Shape*> |
d0d76e8a5203
new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
196 |
{ |
d0d76e8a5203
new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
197 |
}; |
d0d76e8a5203
new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
198 |
|
46 | 199 |
/** |
200 |
* sphere shape |
|
201 |
*/ |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
202 |
class Sphere: public Shape |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
203 |
{ |
22 | 204 |
Float sqr_radius; |
205 |
Float inv_radius; |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
206 |
public: |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
207 |
Vector3 center; |
22 | 208 |
Float radius; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
209 |
|
22 | 210 |
Sphere(const Vector3 &acenter, const Float aradius, Material *amaterial): |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
211 |
sqr_radius(aradius*aradius), inv_radius(1.0f/aradius), |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
212 |
center(acenter), radius(aradius) { material = amaterial; } |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
213 |
bool intersect(const Ray &ray, Float &dist) const; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
214 |
bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const; |
38
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
215 |
bool intersect_bbox(const BBox &bbox) const; |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
216 |
const Vector3 normal(const Vector3 &P) const { return (P - center) * inv_radius; }; |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
217 |
BBox get_bbox() const; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
218 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
219 |
|
46 | 220 |
/** |
221 |
* box shape |
|
222 |
*/ |
|
14
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
223 |
class Box: public Shape |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
224 |
{ |
14
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
225 |
Vector3 L; |
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
226 |
Vector3 H; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
227 |
public: |
14
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
228 |
Box(const Vector3 &aL, const Vector3 &aH, Material *amaterial): L(aL), H(aH) |
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
229 |
{ |
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
230 |
for (int i = 0; i < 3; i++) |
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
231 |
if (L.cell[i] > H.cell[i]) |
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
232 |
swap(L.cell[i], H.cell[i]); |
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
233 |
material = amaterial; |
fc18ac4833f2
replace Plane with axis-aligned Box (because infinite Plane is not usable with kd-tree)
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
234 |
}; |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
235 |
bool intersect(const Ray &ray, Float &dist) const; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
236 |
bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const { return false; }; |
38
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
237 |
bool intersect_bbox(const BBox &bbox) const; |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
238 |
const Vector3 normal(const Vector3 &P) const; |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
239 |
BBox get_bbox() const { return BBox(L, H); }; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
240 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
241 |
|
46 | 242 |
/** |
243 |
* triangle vertex |
|
244 |
*/ |
|
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
245 |
class Vertex |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
246 |
{ |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
247 |
public: |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
248 |
Vector3 P; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
249 |
Vertex(const Vector3 &aP): P(aP) {}; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
250 |
}; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
251 |
|
46 | 252 |
/** |
253 |
* triangle vertex with normal |
|
254 |
*/ |
|
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
255 |
class NormalVertex: public Vertex |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
256 |
{ |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
257 |
public: |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
258 |
Vector3 N; |
69
303583d2fb97
move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
259 |
NormalVertex(const NormalVertex *v): Vertex(v->P), N(v->N) {}; |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
260 |
NormalVertex(const Vector3 &aP): Vertex(aP) {}; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
261 |
NormalVertex(const Vector3 &aP, const Vector3 &aN): Vertex(aP), N(aN) {}; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
262 |
const Vector3 &getNormal() { return N; }; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
263 |
void setNormal(const Vector3 &aN) { N = aN; }; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
264 |
}; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
265 |
|
46 | 266 |
/** |
267 |
* triangle shape |
|
268 |
*/ |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
269 |
class Triangle: public Shape |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
270 |
{ |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
271 |
#ifdef TRI_BARI_PRE |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
272 |
Float nu, nv, nd; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
273 |
int k; // dominant axis |
22 | 274 |
Float bnu, bnv; |
275 |
Float cnu, cnv; |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
276 |
#endif |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
277 |
#ifdef TRI_BARI |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
278 |
int k; // dominant axis |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
279 |
#endif |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
280 |
#ifdef TRI_PLUCKER |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
281 |
Float pla[6], plb[6], plc[6]; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
282 |
#endif |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
283 |
Vector3 N; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
284 |
const Vector3 smooth_normal(const Vector3 &P) const |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
285 |
{ |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
286 |
#ifdef TRI_BARI_PRE |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
287 |
const Vector3 &NA = static_cast<NormalVertex*>(A)->N; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
288 |
const Vector3 &NB = static_cast<NormalVertex*>(B)->N; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
289 |
const Vector3 &NC = static_cast<NormalVertex*>(C)->N; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
290 |
static const int modulo3[5] = {0,1,2,0,1}; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
291 |
register const int ku = modulo3[k+1]; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
292 |
register const int kv = modulo3[k+2]; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
293 |
const Float pu = P[ku] - A->P[ku]; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
294 |
const Float pv = P[kv] - A->P[kv]; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
295 |
const Float u = pv * bnu + pu * bnv; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
296 |
const Float v = pu * cnv + pv * cnu; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
297 |
Vector3 n = NA + u * (NB - NA) + v * (NC - NA); |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
298 |
n.normalize(); |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
299 |
return n; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
300 |
#else |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
301 |
return N; // not implemented for other algorithms |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
302 |
#endif |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
303 |
}; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
304 |
public: |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
305 |
Vertex *A, *B, *C; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
306 |
|
60
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
307 |
Triangle() {}; |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
308 |
Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial); |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
309 |
bool intersect(const Ray &ray, Float &dist) const; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
310 |
bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const {return false;}; |
36
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
311 |
bool intersect_bbox(const BBox &bbox) const; |
69
303583d2fb97
move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
312 |
const Vector3 normal(const Vector3 &P) const { return (material->smooth ? smooth_normal(P) : N); }; |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
313 |
const Vector3 getNormal() const { return N; }; |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
314 |
BBox get_bbox() const; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
315 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
316 |
|
60
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
317 |
template <class T> class Array |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
318 |
{ |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
319 |
T *array; |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
320 |
public: |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
321 |
Array(int n) { array = new T[n]; }; |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
322 |
~Array() { delete[] array; }; |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
323 |
const T &operator[](int i) const { return array[i]; }; |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
324 |
}; |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
325 |
|
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
326 |
typedef Array<Vertex> VertexArray; |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
327 |
typedef Array<NormalVertex> NormalVertexArray; |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
328 |
typedef Array<Triangle> TriangleArray; |
a23b5089b9c3
moving to SCons build system
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
329 |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
330 |
#endif |