author | Radek Brich <radek.brich@devl.cz> |
Fri, 02 May 2008 13:27:47 +0200 | |
branch | pyrit |
changeset 91 | 9d66d323c354 |
parent 87 | 1081e3dd3f3e |
child 92 | 9af5c039b678 |
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 |
/* |
91 | 2 |
* vector.h: Vector class with Colour alias |
44 | 3 |
* |
4 |
* This file is part of Pyrit Ray Tracer. |
|
5 |
* |
|
6 |
* Copyright 2006, 2007 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 VECTOR_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 VECTOR_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 <math.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
|
31 |
#include <iostream> |
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 |
|
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
33 |
#include "common.h" |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
34 |
|
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
|
35 |
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
|
36 |
|
46 | 37 |
/** |
38 |
* three cell vector |
|
39 |
*/ |
|
91 | 40 |
class Vector |
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 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
42 |
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
|
43 |
// data |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
44 |
union { |
91 | 45 |
#ifndef NO_SSE |
46 |
__m128 mps; |
|
47 |
#endif |
|
48 |
Float cell[4]; |
|
49 |
struct { Float x, y, z, w; }; |
|
50 |
struct { Float r, g, b, a; }; |
|
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
|
51 |
}; |
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 |
// constructors |
91 | 54 |
#ifndef NO_SSE |
55 |
Vector(__m128 m): mps(m) {}; |
|
56 |
#endif |
|
57 |
Vector(): x(0.0f), y(0.0f), z(0.0f), w(1.0) {}; |
|
58 |
Vector(Float ax, Float ay, Float az): x(ax), y(ay), z(az), w(1.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
|
59 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
60 |
// index operator |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
61 |
const Float &operator[](int index) const { return cell[index]; }; |
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
|
62 |
|
91 | 63 |
bool operator==(Vector &v) const { return x==v.x && y==v.y && z==v.z; }; |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
14
diff
changeset
|
64 |
|
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 |
// normalize |
91 | 66 |
Vector 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
|
67 |
{ |
91 | 68 |
const Float f = 1.0f / mag(); |
69 |
*this *= f; |
|
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 |
return *this; |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
71 |
}; |
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
|
72 |
|
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 |
// get normalized copy |
91 | 74 |
friend Vector normalize(const Vector &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
|
75 |
{ |
83
e3a2a5b26abb
vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
76 |
const Float f = 1.0f / v.mag(); |
e3a2a5b26abb
vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
77 |
return v * f; |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
78 |
}; |
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
|
79 |
|
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 |
// square magnitude, magnitude |
91 | 81 |
Float mag2() const { return dot(*this, *this); }; |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
82 |
Float mag() const { return sqrtf(mag2()); }; |
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
|
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 |
// negative |
91 | 85 |
Vector operator-() const { return Vector(-x, -y, -z); }; |
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
|
86 |
|
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 |
// accumulate |
91 | 88 |
Vector operator+=(const Vector &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
|
89 |
{ |
91 | 90 |
#ifdef NO_SSE |
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
|
91 |
x += v.x; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
92 |
y += v.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
|
93 |
z += v.z; |
91 | 94 |
#else |
95 |
mps = _mm_add_ps(mps, v.mps); |
|
96 |
#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
|
97 |
return *this; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
98 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
99 |
|
91 | 100 |
// multiply |
101 |
Vector operator*=(const Float &f) |
|
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
102 |
{ |
91 | 103 |
x *= f; |
104 |
y *= f; |
|
105 |
z *= f; |
|
106 |
return *this; |
|
107 |
}; |
|
108 |
||
109 |
||
110 |
// cut |
|
111 |
Vector operator/=(const Float &f) |
|
112 |
{ |
|
113 |
Float finv = 1./f; |
|
114 |
x *= finv; |
|
115 |
y *= finv; |
|
116 |
z *= finv; |
|
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
117 |
return *this; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
118 |
}; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
119 |
|
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 |
// sum |
91 | 121 |
friend Vector operator+(const Vector &a, const Vector &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
|
122 |
{ |
91 | 123 |
#ifdef NO_SSE |
124 |
return Vector(a.x + b.x, a.y + b.y, a.z + b.z); |
|
125 |
#else |
|
126 |
return Vector(_mm_add_ps(a.mps, b.mps)); |
|
127 |
#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
|
128 |
}; |
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 |
// difference |
91 | 131 |
friend Vector operator-(const Vector &a, const Vector &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
|
132 |
{ |
91 | 133 |
#ifdef NO_SSE |
134 |
return Vector(a.x - b.x, a.y - b.y, a.z - b.z); |
|
135 |
#else |
|
136 |
return Vector(_mm_sub_ps(a.mps, b.mps)); |
|
137 |
#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
|
138 |
}; |
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 |
// dot product |
91 | 141 |
friend Float dot(const Vector &a, const Vector &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
|
142 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
143 |
return a.x * b.x + a.y * b.y + a.z * b.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
|
144 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
145 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
146 |
// cross product |
91 | 147 |
friend Vector cross(const Vector &a, const Vector &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
|
148 |
{ |
91 | 149 |
return Vector(a.y * b.z - a.z * b.y, |
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 |
a.z * b.x - a.x * b.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
|
151 |
a.x * b.y - a.y * b.x); |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
152 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
153 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
154 |
// product of vector and scalar |
91 | 155 |
friend Vector operator*(const Vector &v, const Float &f) |
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
|
156 |
{ |
91 | 157 |
return Vector(f * v.x, f * v.y, f * v.z); |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
158 |
}; |
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
|
159 |
|
91 | 160 |
friend Vector operator*(const Float &f, const Vector &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
|
161 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
162 |
return v * f; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
163 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
164 |
|
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
165 |
// scalar division |
91 | 166 |
friend Vector operator/(const Vector &v, const Float &f) |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
167 |
{ |
91 | 168 |
const Float finv = 1./f; |
169 |
return Vector(v.x * finv, v.y * finv, v.z * finv); |
|
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
170 |
}; |
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
171 |
|
91 | 172 |
friend Vector operator/(const Float &f, const Vector &v) |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
173 |
{ |
91 | 174 |
#ifdef NO_SSE |
175 |
return Vector(f / v.x, f / v.y, f / v.z); |
|
176 |
#else |
|
177 |
return Vector(_mm_div_ps(_mm_set_ps1(f), v.mps)); |
|
178 |
#endif |
|
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
179 |
}; |
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
180 |
|
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
|
181 |
// vector plus scalar |
91 | 182 |
friend Vector operator+(const Vector &v, const Float &f) |
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
|
183 |
{ |
91 | 184 |
return Vector(v.x + f, v.y + f, v.z + f); |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
185 |
}; |
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
|
186 |
|
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
|
187 |
// vector minus scalar |
91 | 188 |
friend Vector operator-(const Vector &v, const Float &f) |
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
|
189 |
{ |
91 | 190 |
return Vector(v.x - f, v.y - f, v.z - f); |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
191 |
}; |
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
|
192 |
|
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
|
193 |
// cell by cell product (only usable for colours) |
91 | 194 |
friend Vector operator*(const Vector &a, const Vector &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
|
195 |
{ |
91 | 196 |
#ifdef NO_SSE |
197 |
return Vector(a.x * b.x, a.y * b.y, a.z * b.z); |
|
198 |
#else |
|
199 |
return Vector(_mm_mul_ps(a.mps, b.mps)); |
|
200 |
#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
|
201 |
}; |
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 |
|
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
203 |
// write |
91 | 204 |
friend ostream & operator<<(ostream &st, const Vector &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
|
205 |
{ |
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
206 |
return st << "(" << v.x << "," << v.y << "," << v.z << ")"; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
207 |
}; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
208 |
|
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
209 |
// read |
91 | 210 |
friend istream & operator>>(istream &st, Vector &v) |
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
211 |
{ |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
212 |
char s[10]; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
213 |
st.getline(s, 10, '('); |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
214 |
st >> v.x; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
215 |
st.getline(s, 10, ','); |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
216 |
st >> v.y; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
217 |
st.getline(s, 10, ','); |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
218 |
st >> v.z; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
219 |
st.getline(s, 10, ')'); |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
220 |
return st; |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
221 |
}; |
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
|
222 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
223 |
|
91 | 224 |
typedef Vector Colour; |
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
|
225 |
|
91 | 226 |
#ifndef NO_SSE |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
227 |
class VectorPacket |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
228 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
229 |
public: |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
230 |
union { |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
231 |
__m128 ma[3]; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
232 |
struct { |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
233 |
__m128 mx; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
234 |
__m128 my; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
235 |
__m128 mz; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
236 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
237 |
struct { |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
238 |
float x[4]; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
239 |
float y[4]; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
240 |
float z[4]; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
241 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
242 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
243 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
244 |
VectorPacket() {}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
245 |
VectorPacket(__m128 ax, __m128 ay, __m128 az): |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
246 |
mx(ax), my(ay), mz(az) {}; |
91 | 247 |
VectorPacket(const Vector &v): |
87
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
248 |
mx(_mm_set_ps1(v.x)), my(_mm_set_ps1(v.y)), mz(_mm_set_ps1(v.z)) {}; |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
249 |
|
91 | 250 |
Vector getVector(int i) const |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
251 |
{ |
91 | 252 |
return Vector(x[i], y[i], z[i]); |
253 |
}; |
|
254 |
||
255 |
void setVector(int i, const Vector &v) |
|
256 |
{ |
|
257 |
x[i] = v.x; y[i] = v.y; z[i] = v.z; |
|
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
258 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
259 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
260 |
void normalize() |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
261 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
262 |
__m128 m,x,y,z; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
263 |
x = _mm_mul_ps(mx, mx); // x*x |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
264 |
y = _mm_mul_ps(my, my); // y*y |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
265 |
z = _mm_mul_ps(mz, mz); // z*z |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
266 |
m = _mm_add_ps(x, y); |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
267 |
m = _mm_add_ps(m, z); // x*x + y*y + z*z |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
268 |
m = _mm_sqrt_ps(m); |
86
ce6abe0aeeae
BBox - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
269 |
m = _mm_div_ps(mOne, m); // m = 1/sqrt(m) |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
270 |
mx = _mm_mul_ps(mx, m); |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
271 |
my = _mm_mul_ps(my, m); |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
272 |
mz = _mm_mul_ps(mz, m); |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
273 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
274 |
|
91 | 275 |
// accumulate |
276 |
VectorPacket operator+=(const VectorPacket &v) |
|
277 |
{ |
|
278 |
mx = _mm_add_ps(mx, v.mx); |
|
279 |
my = _mm_add_ps(my, v.my); |
|
280 |
mz = _mm_add_ps(mz, v.mz); |
|
281 |
return *this; |
|
282 |
}; |
|
283 |
||
284 |
// add to non-masked components |
|
285 |
VectorPacket selectiveAdd(__m128 mask, const VectorPacket &v) |
|
286 |
{ |
|
287 |
mx = _mm_or_ps(_mm_and_ps(mask, _mm_add_ps(mx, v.mx)), |
|
288 |
_mm_andnot_ps(mask, mx)); |
|
289 |
my = _mm_or_ps(_mm_and_ps(mask, _mm_add_ps(my, v.my)), |
|
290 |
_mm_andnot_ps(mask, my)); |
|
291 |
mz = _mm_or_ps(_mm_and_ps(mask, _mm_add_ps(mz, v.mz)), |
|
292 |
_mm_andnot_ps(mask, mz)); |
|
293 |
return *this; |
|
294 |
}; |
|
295 |
||
296 |
// add scalar to non-masked components |
|
297 |
VectorPacket selectiveAdd(__m128 mask, const __m128 m) |
|
298 |
{ |
|
299 |
mx = _mm_or_ps(_mm_and_ps(mask, _mm_add_ps(mx, m)), |
|
300 |
_mm_andnot_ps(mask, mx)); |
|
301 |
my = _mm_or_ps(_mm_and_ps(mask, _mm_add_ps(my, m)), |
|
302 |
_mm_andnot_ps(mask, my)); |
|
303 |
mz = _mm_or_ps(_mm_and_ps(mask, _mm_add_ps(mz, m)), |
|
304 |
_mm_andnot_ps(mask, mz)); |
|
305 |
return *this; |
|
306 |
}; |
|
307 |
||
87
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
308 |
// dot product |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
309 |
friend __m128 dot(const VectorPacket &a, const VectorPacket &b) |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
310 |
{ |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
311 |
return _mm_add_ps(_mm_add_ps( |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
312 |
_mm_mul_ps(a.mx, b.mx), |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
313 |
_mm_mul_ps(a.my, b.my)), |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
314 |
_mm_mul_ps(a.mz, b.mz)); |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
315 |
}; |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
316 |
|
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
317 |
friend VectorPacket operator+(const VectorPacket &a, const VectorPacket &b) |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
318 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
319 |
return VectorPacket( |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
320 |
_mm_add_ps(a.mx, b.mx), |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
321 |
_mm_add_ps(a.my, b.my), |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
322 |
_mm_add_ps(a.mz, b.mz)); |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
323 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
324 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
325 |
friend VectorPacket operator-(const VectorPacket &a, const VectorPacket &b) |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
326 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
327 |
return VectorPacket( |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
328 |
_mm_sub_ps(a.mx, b.mx), |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
329 |
_mm_sub_ps(a.my, b.my), |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
330 |
_mm_sub_ps(a.mz, b.mz)); |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
331 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
332 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
333 |
friend VectorPacket operator*(const VectorPacket &v, const __m128 &m) |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
334 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
335 |
return VectorPacket( |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
336 |
_mm_mul_ps(v.mx, m), |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
337 |
_mm_mul_ps(v.my, m), |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
338 |
_mm_mul_ps(v.mz, m)); |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
339 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
340 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
341 |
friend VectorPacket operator/(const __m128 &m, const VectorPacket &v) |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
342 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
343 |
return VectorPacket( |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
344 |
_mm_div_ps(m, v.mx), |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
345 |
_mm_div_ps(m, v.my), |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
346 |
_mm_div_ps(m, v.mz)); |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
347 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
348 |
|
91 | 349 |
// cell by cell product (only usable for colours) |
350 |
friend VectorPacket operator*(const VectorPacket &a, const VectorPacket &b) |
|
351 |
{ |
|
352 |
return VectorPacket( |
|
353 |
_mm_mul_ps(a.mx, b.mx), |
|
354 |
_mm_mul_ps(a.my, b.my), |
|
355 |
_mm_mul_ps(a.mz, b.mz)); |
|
356 |
}; |
|
357 |
||
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
358 |
// write to character stream |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
359 |
friend ostream & operator<<(ostream &st, const VectorPacket &v) |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
360 |
{ |
86
ce6abe0aeeae
BBox - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
361 |
return st << "[" << v.getVector(0) << "," << v.getVector(1) |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
362 |
<< "," << v.getVector(2) << "," << v.getVector(3) << ")"; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
363 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
364 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
365 |
}; |
91 | 366 |
#endif |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
367 |
|
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
|
368 |
#endif |