author | Radek Brich <radek.brich@devl.cz> |
Wed, 23 Apr 2008 19:35:03 +0200 | |
branch | pyrit |
changeset 80 | 907929fa9b59 |
parent 78 | 9569e9f35374 |
child 85 | 907a634e5c02 |
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 |
/* |
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
2 |
* shapes.cc: shape classes |
44 | 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 |
|
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
27 |
#include "shapes.h" |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
28 |
#include "serialize.h" |
12
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
8
diff
changeset
|
29 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
30 |
bool Sphere::intersect(const Ray &ray, Float &dist) 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
|
31 |
{ |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
32 |
Vector3 V = ray.o - center; |
56
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
33 |
register Float d = -dot(V, ray.dir); |
22 | 34 |
register Float Det = d * d - (dot(V,V) - sqr_radius); |
56
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
35 |
register Float t1,t2; |
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
|
36 |
if (Det > 0) { |
56
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
37 |
Det = sqrtf(Det); |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
38 |
t1 = d - Det; |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
39 |
t2 = d + Det; |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
40 |
if (t1 > 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
|
41 |
{ |
56
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
42 |
if (t1 < dist) |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
43 |
{ |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
44 |
dist = t1; |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
45 |
return true; |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
46 |
} |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
47 |
} |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
48 |
else if (t2 > 0 && t2 < dist) |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
49 |
{ |
d4481fc43952
fix sphere transmissivity, rename demo.py to spheres_glass.py
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
50 |
dist = t2; |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
51 |
return 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
|
52 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
53 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
54 |
return false; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
55 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
|
40
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
57 |
/* if there should be CSG sometimes, this may be needed... */ |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
58 |
bool Sphere::intersect_all(const Ray &ray, Float dist, vector<Float> &allts) 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
|
59 |
{ |
22 | 60 |
//allts = new vector<Float>(); |
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
|
61 |
|
15
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
14
diff
changeset
|
62 |
Vector3 V = ((Ray)ray).o - center; |
22 | 63 |
Float Vd = - dot(V, ray.dir); |
64 |
Float Det = Vd * Vd - (dot(V,V) - sqr_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
|
65 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
66 |
if (Det > 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
|
67 |
Det = sqrtf(Det); |
22 | 68 |
Float t1 = Vd - Det; |
69 |
Float t2 = Vd + Det; |
|
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
|
70 |
if (t1 < 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
|
71 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
72 |
if (t2 > 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
|
73 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
74 |
// ray from inside of the sphere |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
75 |
allts.push_back(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
|
76 |
allts.push_back(t2); |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
77 |
return true; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
78 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
79 |
else |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
80 |
return false; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
81 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
82 |
else |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
83 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
84 |
allts.push_back(t1); |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
85 |
allts.push_back(t2); |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
86 |
return true; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
87 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
88 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
89 |
return false; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
90 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
91 |
|
38
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
92 |
bool Sphere::intersect_bbox(const BBox &bbox) const |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
93 |
{ |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
94 |
register float dmin = 0; |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
95 |
for (int i = 0; i < 3; i++) |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
96 |
{ |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
97 |
if (center[i] < bbox.L[i]) |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
98 |
dmin += (center[i] - bbox.L[i])*(center[i] - bbox.L[i]); |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
99 |
else |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
100 |
if (center[i] > bbox.H[i]) |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
101 |
dmin += (center[i] - bbox.H[i])*(center[i] - bbox.H[i]); |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
102 |
} |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
103 |
if (dmin <= sqr_radius) |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
104 |
return true; |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
105 |
return false; |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
106 |
}; |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
107 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
108 |
BBox Sphere::get_bbox() const |
12
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
8
diff
changeset
|
109 |
{ |
38
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
110 |
return BBox(center - radius, center + radius); |
8
e6567b740c5e
fixed virtual method get_bbox() for all shapes, default thread num changed to 4
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
111 |
} |
e6567b740c5e
fixed virtual method get_bbox() for all shapes, default thread num changed to 4
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
112 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
113 |
bool Box::intersect(const Ray &ray, Float &dist) 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
|
114 |
{ |
40
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
115 |
register Float tnear = -Inf; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
116 |
register Float tfar = Inf; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
117 |
register Float t1, t2; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
118 |
|
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
119 |
for (int i = 0; i < 3; i++) |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
120 |
{ |
40
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
121 |
if (ray.dir[i] == 0) { |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
122 |
/* ray is parallel to these planes */ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
123 |
if (ray.o[i] < L[i] || ray.o[i] > H[i]) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
124 |
return false; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
125 |
} |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
126 |
else |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
127 |
{ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
128 |
/* compute the intersection distance of the planes */ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
129 |
t1 = (L[i] - ray.o[i]) / ray.dir[i]; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
130 |
t2 = (H[i] - ray.o[i]) / ray.dir[i]; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
131 |
|
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
132 |
if (t1 > t2) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
133 |
swap(t1, t2); |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
134 |
|
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
135 |
if (t1 > tnear) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
136 |
tnear = t1; /* want largest Tnear */ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
137 |
if (t2 < tfar) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
138 |
tfar = t2; /* want smallest Tfar */ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
139 |
if (tnear > tfar || tfar < 0) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
140 |
return false; /* box missed; box is behind ray */ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
141 |
} |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
142 |
} |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
143 |
|
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
144 |
if (tnear < dist) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
145 |
{ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
146 |
dist = tnear; |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
147 |
return true; |
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
148 |
} |
40
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
149 |
return false; |
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
|
150 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
151 |
|
38
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
152 |
bool Box::intersect_bbox(const BBox &bbox) const |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
153 |
{ |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
154 |
return ( |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
155 |
H.x > bbox.L.x && L.x < bbox.H.x && |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
156 |
H.y > bbox.L.y && L.y < bbox.H.y && |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
157 |
H.z > bbox.L.z && L.z < bbox.H.z); |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
158 |
} |
5d043eeb09d9
realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
159 |
|
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
160 |
const Vector3 Box::normal(const Vector3 &P) const |
12
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
8
diff
changeset
|
161 |
{ |
40
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
162 |
register Vector3 l = P - L; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
163 |
register Vector3 h = H - P; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
164 |
|
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
165 |
if (l.x < h.x) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
166 |
h.x = -1; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
167 |
else |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
168 |
{ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
169 |
l.x = h.x; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
170 |
h.x = +1; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
171 |
} |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
172 |
|
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
173 |
if (l.y < h.y) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
174 |
h.y = -1; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
175 |
else |
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
|
176 |
{ |
40
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
177 |
l.y = h.y; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
178 |
h.y = +1; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
179 |
} |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
180 |
|
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
181 |
if (l.z < h.z) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
182 |
h.z = -1; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
183 |
else |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
184 |
{ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
185 |
l.z = h.z; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
186 |
h.z = +1; |
15
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
14
diff
changeset
|
187 |
} |
40
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
188 |
|
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
189 |
if (l.x > l.y) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
190 |
{ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
191 |
h.x = 0; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
192 |
if (l.y > l.z) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
193 |
h.y = 0; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
194 |
else |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
195 |
h.z = 0; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
196 |
} |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
197 |
else |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
198 |
{ |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
199 |
h.y = 0; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
200 |
if (l.x > l.z) |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
201 |
h.x = 0; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
202 |
else |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
203 |
h.z = 0; |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
204 |
} |
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
205 |
return h; |
8
e6567b740c5e
fixed virtual method get_bbox() for all shapes, default thread num changed to 4
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
206 |
} |
e6567b740c5e
fixed virtual method get_bbox() for all shapes, default thread num changed to 4
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
207 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
208 |
#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
|
209 |
inline void Plucker(const Vector3 &p, const Vector3 &q, Float* pl) |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
210 |
{ |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
211 |
pl[0] = p.x*q.y - q.x*p.y; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
212 |
pl[1] = p.x*q.z - q.x*p.z; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
213 |
pl[2] = p.x - q.x; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
214 |
pl[3] = p.y*q.z - q.y*p.z; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
215 |
pl[4] = p.z - q.z; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
216 |
pl[5] = q.y - p.y; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
217 |
} |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
218 |
|
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
219 |
inline Float Side(const Float* pla, const Float* plb) |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
220 |
{ |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
221 |
return pla[0]*plb[4] + pla[1]*plb[5] + pla[2]*plb[3] + pla[4]*plb[0] + pla[5]*plb[1] + pla[3]*plb[2]; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
222 |
} |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
223 |
#endif |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
224 |
|
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
225 |
Triangle::Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial) |
69
303583d2fb97
move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
226 |
: A(aA), B(aB), C(aC) |
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 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
228 |
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
|
229 |
|
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
230 |
const Vector3 c = B->P - A->P; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
231 |
const Vector3 b = C->P - A->P; |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
232 |
|
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
233 |
N = cross(c, b); |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
234 |
N.normalize(); |
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
|
235 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
236 |
#ifdef TRI_PLUCKER |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
237 |
Plucker(B->P,C->P,pla); |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
238 |
Plucker(C->P,A->P,plb); |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
239 |
Plucker(A->P,B->P,plc); |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
240 |
#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
|
241 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
242 |
#if defined(TRI_BARI) || defined(TRI_BARI_PRE) |
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
|
243 |
if (fabsf(N.x) > fabsf(N.y)) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
244 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
245 |
if (fabsf(N.x) > fabsf(N.z)) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
246 |
k = 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
|
247 |
else |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
248 |
k = 2; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
249 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
250 |
else |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
251 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
252 |
if (fabsf(N.y) > fabsf(N.z)) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
253 |
k = 1; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
254 |
else |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
255 |
k = 2; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
256 |
} |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
257 |
#endif |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
258 |
#ifdef TRI_BARI_PRE |
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
|
259 |
int u = (k + 1) % 3; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
260 |
int v = (k + 2) % 3; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
261 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
262 |
Float krec = 1.0 / N[k]; |
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
|
263 |
nu = N[u] * krec; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
264 |
nv = N[v] * krec; |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
265 |
nd = dot(N, A->P) * krec; |
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
|
266 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
267 |
// first line equation |
22 | 268 |
Float reci = 1.0f / (b[u] * c[v] - b[v] * c[u]); |
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 |
bnu = b[u] * reci; |
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 |
bnv = -b[v] * reci; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
271 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
272 |
// second line equation |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
273 |
cnu = -c[u] * reci; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
274 |
cnv = c[v] * reci; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
275 |
#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
|
276 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
277 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
278 |
bool Triangle::intersect(const Ray &ray, Float &dist) 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
|
279 |
{ |
25
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 plr[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 |
Plucker(ray.o, ray.o+ray.dir, plr); |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
283 |
const bool side0 = Side(plr, pla) >= 0.0; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
284 |
const bool side1 = Side(plr, plb) >= 0.0; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
285 |
if (side0 != side1) |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
286 |
return false; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
287 |
const bool side2 = Side(plr, plc) >= 0.0; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
288 |
if (side0 != side2) |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
289 |
return false; |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
290 |
const Float t = - dot( (ray.o - A->P), N) / dot(ray.dir,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
|
291 |
if(t <= Eps || t >= dist) |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
292 |
return false; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
293 |
dist = t; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
294 |
return true; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
295 |
#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
|
296 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
297 |
#if 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
|
298 |
static const int modulo3[5] = {0,1,2,0,1}; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
299 |
const Vector3 &O = ray.o; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
300 |
const Vector3 &D = ray.dir; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
301 |
register const int u = modulo3[k+1]; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
302 |
register const int v = modulo3[k+2]; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
303 |
#endif |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
304 |
#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
|
305 |
const Float t = (nd - O[k] - nu * O[u] - nv * O[v]) / (D[k] + nu * D[u] + nv * D[v]); |
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 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
307 |
if (t >= dist || t < Eps) |
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
|
308 |
return false; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
309 |
|
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
310 |
const Float hu = O[u] + t * D[u] - A->P[u]; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
311 |
const Float hv = O[v] + t * D[v] - A->P[v]; |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
312 |
const Float beta = hv * bnu + hu * bnv; |
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
|
313 |
|
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 |
if (beta < 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
|
315 |
return false; |
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 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
317 |
const Float gamma = hu * cnv + hv * cnu; |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
318 |
if (gamma < 0. || beta + gamma > 1.) |
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
|
319 |
return false; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
320 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
321 |
dist = t; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
322 |
return true; |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
323 |
#endif |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
324 |
|
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
325 |
#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
|
326 |
// original barycentric coordinates based intesection |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
327 |
// not optimized, just for reference |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
328 |
const Vector3 c = B - A; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
329 |
const Vector3 b = C - A; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
330 |
// distance test |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
331 |
const Float t = - dot( (O-A), N) / dot(D,N); |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
332 |
if (t < Eps || t > dist) |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
333 |
return false; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
334 |
|
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
335 |
// calc hitpoint |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
336 |
const Float Hu = O[u] + t * D[u] - A[u]; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
337 |
const Float Hv = O[v] + t * D[v] - A[v]; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
338 |
const Float beta = (b[u] * Hv - b[v] * Hu) / (b[u] * c[v] - b[v] * c[u]); |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
339 |
if (beta < 0) |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
340 |
return false; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
341 |
const Float gamma = (c[v] * Hu - c[u] * Hv) / (b[u] * c[v] - b[v] * c[u]); |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
342 |
if (gamma < 0) |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
343 |
return false; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
344 |
if (beta+gamma > 1) |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
345 |
return false; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
346 |
dist = t; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
347 |
return true; |
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
348 |
#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
|
349 |
} |
7
bf17f9f84c91
kd-tree: build algorithm - searching for all posible splits
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
350 |
|
36
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
351 |
bool Triangle::intersect_bbox(const BBox &bbox) const |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
352 |
{ |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
353 |
const Vector3 boxcenter = (bbox.L+bbox.H)*0.5; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
354 |
const Vector3 boxhalfsize = (bbox.H-bbox.L)*0.5; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
355 |
const Vector3 v0 = A->P - boxcenter; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
356 |
const Vector3 v1 = B->P - boxcenter; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
357 |
const Vector3 v2 = C->P - boxcenter; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
358 |
const Vector3 e0 = v1-v0; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
359 |
const Vector3 e1 = v2-v1; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
360 |
const Vector3 e2 = v0-v2; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
361 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
362 |
Float fex = fabsf(e0.x); |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
363 |
Float fey = fabsf(e0.y); |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
364 |
Float fez = fabsf(e0.z); |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
365 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
366 |
Float p0,p1,p2,min,max,rad; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
367 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
368 |
p0 = e0.z*v0.y - e0.y*v0.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
369 |
p2 = e0.z*v2.y - e0.y*v2.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
370 |
if(p0<p2) {min=p0; max=p2;} else {min=p2; max=p0;} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
371 |
rad = fez * boxhalfsize.y + fey * boxhalfsize.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
372 |
if(min>rad || max<-rad) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
373 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
374 |
p0 = -e0.z*v0.x + e0.x*v0.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
375 |
p2 = -e0.z*v2.x + e0.x*v2.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
376 |
if(p0<p2) {min=p0; max=p2;} else {min=p2; max=p0;} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
377 |
rad = fez * boxhalfsize.x + fex * boxhalfsize.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
378 |
if(min>rad || max<-rad) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
379 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
380 |
p1 = e0.y*v1.x - e0.x*v1.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
381 |
p2 = e0.y*v2.x - e0.x*v2.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
382 |
if(p2<p1) {min=p2; max=p1;} else {min=p1; max=p2;} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
383 |
rad = fey * boxhalfsize.x + fex * boxhalfsize.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
384 |
if(min>rad || max<-rad) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
385 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
386 |
fex = fabsf(e1.x); |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
387 |
fey = fabsf(e1.y); |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
388 |
fez = fabsf(e1.z); |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
389 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
390 |
p0 = e1.z*v0.y - e1.y*v0.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
391 |
p2 = e1.z*v2.y - e1.y*v2.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
392 |
if(p0<p2) {min=p0; max=p2;} else {min=p2; max=p0;} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
393 |
rad = fez * boxhalfsize.y + fey * boxhalfsize.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
394 |
if(min>rad || max<-rad) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
395 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
396 |
p0 = -e1.z*v0.x + e1.x*v0.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
397 |
p2 = -e1.z*v2.x + e1.x*v2.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
398 |
if(p0<p2) {min=p0; max=p2;} else {min=p2; max=p0;} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
399 |
rad = fez * boxhalfsize.x + fex * boxhalfsize.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
400 |
if(min>rad || max<-rad) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
401 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
402 |
p0 = e1.y*v0.x - e1.x*v0.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
403 |
p1 = e1.y*v1.x - e1.x*v1.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
404 |
if(p0<p1) {min=p0; max=p1;} else {min=p1; max=p0;} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
405 |
rad = fey * boxhalfsize.x + fex * boxhalfsize.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
406 |
if(min>rad || max<-rad) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
407 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
408 |
fex = fabsf(e2.x); |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
409 |
fey = fabsf(e2.y); |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
410 |
fez = fabsf(e2.z); |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
411 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
412 |
p0 = e2.z*v0.y - e2.y*v0.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
413 |
p1 = e2.z*v1.y - e2.y*v1.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
414 |
if(p0<p1) {min=p0; max=p1;} else {min=p1; max=p0;} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
415 |
rad = fez * boxhalfsize.y + fey * boxhalfsize.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
416 |
if(min>rad || max<-rad) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
417 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
418 |
p0 = -e2.z*v0.x + e2.x*v0.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
419 |
p1 = -e2.z*v1.x + e2.x*v1.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
420 |
if(p0<p1) {min=p0; max=p1;} else {min=p1; max=p0;} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
421 |
rad = fez * boxhalfsize.x + fex * boxhalfsize.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
422 |
if(min>rad || max<-rad) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
423 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
424 |
p1 = e2.y*v1.x - e2.x*v1.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
425 |
p2 = e2.y*v2.x - e2.x*v2.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
426 |
if(p2<p1) {min=p2; max=p1;} else {min=p1; max=p2;} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
427 |
rad = fey * boxhalfsize.x + fex * boxhalfsize.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
428 |
if(min>rad || max<-rad) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
429 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
430 |
/* test overlap in the {x,y,z}-directions */ |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
431 |
/* test in X-direction */ |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
432 |
min = v0.x; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
433 |
if (v1.x < min) min = v1.x; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
434 |
if (v2.x < min) min = v2.x; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
435 |
max = v0.x; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
436 |
if (v1.x > max) max = v1.x; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
437 |
if (v2.x > max) max = v2.x; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
438 |
if(min>boxhalfsize.x || max<-boxhalfsize.x) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
439 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
440 |
/* test in Y-direction */ |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
441 |
min = v0.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
442 |
if (v1.y < min) min = v1.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
443 |
if (v2.y < min) min = v2.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
444 |
max = v0.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
445 |
if (v1.y > max) max = v1.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
446 |
if (v2.y > max) max = v2.y; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
447 |
if(min>boxhalfsize.y || max<-boxhalfsize.y) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
448 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
449 |
/* test in Z-direction */ |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
450 |
min = v0.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
451 |
if (v1.z < min) min = v1.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
452 |
if (v2.z < min) min = v2.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
453 |
max = v0.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
454 |
if (v1.z > max) max = v1.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
455 |
if (v2.z > max) max = v2.z; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
456 |
if(min>boxhalfsize.z || max<-boxhalfsize.z) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
457 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
458 |
/* test if the box intersects the plane of the triangle */ |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
459 |
Vector3 vmin,vmax; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
460 |
Float v; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
461 |
for(int q=0;q<3;q++) |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
462 |
{ |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
463 |
v=v0[q]; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
464 |
if(N[q]>0.0f) |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
465 |
{ |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
466 |
vmin.cell[q]=-boxhalfsize[q] - v; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
467 |
vmax.cell[q]= boxhalfsize[q] - v; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
468 |
} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
469 |
else |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
470 |
{ |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
471 |
vmin.cell[q]= boxhalfsize[q] - v; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
472 |
vmax.cell[q]=-boxhalfsize[q] - v; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
473 |
} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
474 |
} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
475 |
if(dot(N,vmin)>0.0f) return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
476 |
if(dot(N,vmax)>=0.0f) return true; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
477 |
|
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
478 |
return false; |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
479 |
} |
b490093b0ac3
new virtual Shape::intersect_bbox
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
480 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
481 |
BBox Triangle::get_bbox() const |
7
bf17f9f84c91
kd-tree: build algorithm - searching for all posible splits
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
482 |
{ |
bf17f9f84c91
kd-tree: build algorithm - searching for all posible splits
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
483 |
BBox bbox = BBox(); |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
484 |
bbox.L = A->P; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
485 |
if (B->P.x < bbox.L.x) bbox.L.x = B->P.x; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
486 |
if (C->P.x < bbox.L.x) bbox.L.x = C->P.x; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
487 |
if (B->P.y < bbox.L.y) bbox.L.y = B->P.y; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
488 |
if (C->P.y < bbox.L.y) bbox.L.y = C->P.y; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
489 |
if (B->P.z < bbox.L.z) bbox.L.z = B->P.z; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
490 |
if (C->P.z < bbox.L.z) bbox.L.z = C->P.z; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
491 |
bbox.H = A->P; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
492 |
if (B->P.x > bbox.H.x) bbox.H.x = B->P.x; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
493 |
if (C->P.x > bbox.H.x) bbox.H.x = C->P.x; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
494 |
if (B->P.y > bbox.H.y) bbox.H.y = B->P.y; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
495 |
if (C->P.y > bbox.H.y) bbox.H.y = C->P.y; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
496 |
if (B->P.z > bbox.H.z) bbox.H.z = B->P.z; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
497 |
if (C->P.z > bbox.H.z) bbox.H.z = C->P.z; |
7
bf17f9f84c91
kd-tree: build algorithm - searching for all posible splits
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
498 |
return bbox; |
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
499 |
} |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
500 |
|
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
501 |
ostream & Sphere::dump(ostream &st) const |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
502 |
{ |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
503 |
return st << "(sphere," << center << "," << radius << ")"; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
504 |
} |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
505 |
|
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
506 |
ostream & Box::dump(ostream &st) const |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
507 |
{ |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
508 |
return st << "(box," << L << "," << H << ")"; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
509 |
} |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
510 |
|
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
511 |
ostream & Vertex::dump(ostream &st) const |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
512 |
{ |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
513 |
return st << "(v," << P << ")"; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
514 |
} |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
515 |
|
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
516 |
ostream & NormalVertex::dump(ostream &st) const |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
517 |
{ |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
518 |
return st << "(vn," << P << "," << N << ")"; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
519 |
} |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
520 |
|
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
521 |
ostream & Triangle::dump(ostream &st) const |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
522 |
{ |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
523 |
int idxA, idxB, idxC; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
524 |
if (!vertex_index.get(A, idxA)) |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
525 |
st << *A << "," << endl; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
526 |
if (!vertex_index.get(B, idxB)) |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
527 |
st << *B << "," << endl; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
528 |
if (!vertex_index.get(C, idxC)) |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
529 |
st << *C << "," << endl; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
530 |
return st << "(t," << idxA << "," << idxB << "," << idxC << ")"; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
531 |
} |