author | Radek Brich <radek.brich@devl.cz> |
Sat, 10 May 2008 14:29:37 +0200 | |
branch | pyrit |
changeset 95 | ca7d4c665531 |
parent 94 | 4c8abb8977dc |
permissions | -rw-r--r-- |
94 | 1 |
/** |
2 |
* @file vector.h |
|
3 |
* @brief Vector class with Colour alias |
|
44 | 4 |
* |
5 |
* This file is part of Pyrit Ray Tracer. |
|
6 |
* |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
7 |
* 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
|
8 |
* |
44 | 9 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
10 |
* of this software and associated documentation files (the "Software"), to deal |
|
11 |
* in the Software without restriction, including without limitation the rights |
|
12 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
13 |
* copies of the Software, and to permit persons to whom the Software is |
|
14 |
* furnished to do so, subject to the following conditions: |
|
15 |
* |
|
16 |
* The above copyright notice and this permission notice shall be included in |
|
17 |
* all copies or substantial portions of the Software. |
|
18 |
* |
|
19 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
20 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
21 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
22 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
23 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
24 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
25 |
* 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
|
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 |
|
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 |
#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
|
29 |
#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
|
30 |
|
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 <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
|
32 |
#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
|
33 |
|
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
34 |
#include "common.h" |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
35 |
#include "simd.h" |
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
36 |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
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
|
38 |
|
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
39 |
#define NO_SIMD_VECTOR |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
40 |
|
46 | 41 |
/** |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
42 |
* three (four) cell vector |
46 | 43 |
*/ |
91 | 44 |
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
|
45 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
46 |
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
|
47 |
// 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
|
48 |
union { |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
49 |
#ifndef NO_SIMD |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
50 |
mfloat4 mf4; |
91 | 51 |
#endif |
52 |
Float cell[4]; |
|
53 |
struct { Float x, y, z, w; }; |
|
54 |
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
|
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 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
// constructors |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
58 |
#ifndef NO_SIMD |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
59 |
Vector(mfloat4 m): mf4(m) {}; |
91 | 60 |
#endif |
61 |
Vector(): x(0.0f), y(0.0f), z(0.0f), w(1.0) {}; |
|
62 |
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
|
63 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
64 |
// 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
|
65 |
const Float &operator[](int index) const { return cell[index]; }; |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
66 |
Float &operator[](int index) { 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
|
67 |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
68 |
bool operator==(const 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
|
69 |
|
94 | 70 |
/** Normalize the vector */ |
91 | 71 |
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
|
72 |
{ |
91 | 73 |
const Float f = 1.0f / mag(); |
74 |
*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
|
75 |
return *this; |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
76 |
}; |
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
|
77 |
|
94 | 78 |
/** Get normalized copy of vector */ |
91 | 79 |
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
|
80 |
{ |
83
e3a2a5b26abb
vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
81 |
const Float f = 1.0f / v.mag(); |
e3a2a5b26abb
vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
82 |
return v * f; |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
83 |
}; |
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
|
84 |
|
94 | 85 |
/** Square magnitude */ |
91 | 86 |
Float mag2() const { return dot(*this, *this); }; |
94 | 87 |
|
88 |
/** Vector magnitude */ |
|
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
89 |
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
|
90 |
|
94 | 91 |
/** Get negative vector */ |
91 | 92 |
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
|
93 |
|
94 | 94 |
/** Accumulate. Useful for colors. */ |
91 | 95 |
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
|
96 |
{ |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
97 |
#ifdef NO_SIMD_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
|
98 |
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
|
99 |
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
|
100 |
z += v.z; |
91 | 101 |
#else |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
102 |
mf4 = madd(mf4, v.mf4); |
91 | 103 |
#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
|
104 |
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
|
105 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
106 |
|
94 | 107 |
/** Multiply by scalar */ |
91 | 108 |
Vector operator*=(const Float &f) |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
109 |
{ |
91 | 110 |
x *= f; |
111 |
y *= f; |
|
112 |
z *= f; |
|
113 |
return *this; |
|
114 |
}; |
|
115 |
||
94 | 116 |
/** Cut with scalar */ |
91 | 117 |
Vector operator/=(const Float &f) |
118 |
{ |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
119 |
Float finv = 1.0f / f; |
91 | 120 |
x *= finv; |
121 |
y *= finv; |
|
122 |
z *= finv; |
|
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
123 |
return *this; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
124 |
}; |
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
125 |
|
94 | 126 |
/** Sum of two vectors */ |
91 | 127 |
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
|
128 |
{ |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
129 |
#ifdef NO_SIMD_VECTOR |
91 | 130 |
return Vector(a.x + b.x, a.y + b.y, a.z + b.z); |
131 |
#else |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
132 |
return Vector(madd(a.mf4, b.mf4)); |
91 | 133 |
#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
|
134 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
135 |
|
94 | 136 |
/** Difference of two vectors */ |
91 | 137 |
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
|
138 |
{ |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
139 |
#ifdef NO_SIMD_VECTOR |
91 | 140 |
return Vector(a.x - b.x, a.y - b.y, a.z - b.z); |
141 |
#else |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
142 |
return Vector(msub(a.mf4, b.mf4)); |
91 | 143 |
#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
|
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 |
|
94 | 146 |
/** Dot product */ |
91 | 147 |
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
|
148 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
149 |
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
|
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 |
|
94 | 152 |
/** Cross product */ |
91 | 153 |
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
|
154 |
{ |
91 | 155 |
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
|
156 |
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
|
157 |
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
|
158 |
}; |
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 |
|
94 | 160 |
/** Get vector multiplied by scalar */ |
91 | 161 |
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
|
162 |
{ |
91 | 163 |
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
|
164 |
}; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
165 |
|
94 | 166 |
/** Get vector multiplied by scalar */ |
91 | 167 |
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
|
168 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
169 |
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
|
170 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
171 |
|
94 | 172 |
/** Get vector divided by scalar */ |
91 | 173 |
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
|
174 |
{ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
175 |
const Float finv = 1.0f / f; |
91 | 176 |
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
|
177 |
}; |
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
178 |
|
94 | 179 |
/** Get f/v, i.e. inverted vector multiplied by scalar */ |
91 | 180 |
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
|
181 |
{ |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
182 |
#ifdef NO_SIMD_VECTOR |
91 | 183 |
return Vector(f / v.x, f / v.y, f / v.z); |
184 |
#else |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
185 |
return Vector(mdiv(mset1(f), v.mf4)); |
91 | 186 |
#endif |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
187 |
}; |
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
188 |
|
94 | 189 |
/** Add scalar to the vector */ |
91 | 190 |
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
|
191 |
{ |
91 | 192 |
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
|
193 |
}; |
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
|
194 |
|
94 | 195 |
/** Subtract scalar from the vector */ |
91 | 196 |
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
|
197 |
{ |
91 | 198 |
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
|
199 |
}; |
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
|
200 |
|
94 | 201 |
/** Cell by cell product (only useful for colors) */ |
202 |
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
|
203 |
{ |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
204 |
#ifdef NO_SIMD_VECTOR |
91 | 205 |
return Vector(a.x * b.x, a.y * b.y, a.z * b.z); |
206 |
#else |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
207 |
return Vector(mmul(a.mf4, b.mf4)); |
91 | 208 |
#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
|
209 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
210 |
|
94 | 211 |
/** Write textual representation of the vector to stream */ |
91 | 212 |
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
|
213 |
{ |
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
214 |
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
|
215 |
}; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
216 |
|
94 | 217 |
/** Read the vector from stream */ |
91 | 218 |
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
|
219 |
{ |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
220 |
char s[10]; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
221 |
st.getline(s, 10, '('); |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
222 |
st >> v.x; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
223 |
st.getline(s, 10, ','); |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
224 |
st >> v.y; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
225 |
st.getline(s, 10, ','); |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
226 |
st >> v.z; |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
227 |
st.getline(s, 10, ')'); |
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
228 |
return st; |
74
09aedbf5f95f
kd-tree traversal - avoid dynamic memory allocation
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
229 |
}; |
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
|
230 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
231 |
|
94 | 232 |
/** Colour is a alias name of Vector. */ |
91 | 233 |
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
|
234 |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
235 |
#ifndef NO_SIMD |
94 | 236 |
/** |
237 |
* Packet of four Vectors |
|
238 |
*/ |
|
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
239 |
class VectorPacket |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
240 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
241 |
public: |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
242 |
union { |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
243 |
mfloat4 ma[3]; |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
244 |
struct { |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
245 |
mfloat4 mx; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
246 |
mfloat4 my; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
247 |
mfloat4 mz; |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
248 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
249 |
struct { |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
254 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
255 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
256 |
VectorPacket() {}; |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
257 |
VectorPacket(mfloat4 ax, mfloat4 ay, mfloat4 az): |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
258 |
mx(ax), my(ay), mz(az) {}; |
91 | 259 |
VectorPacket(const Vector &v): |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
260 |
mx(mset1(v.x)), my(mset1(v.y)), mz(mset1(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
|
261 |
|
91 | 262 |
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
|
263 |
{ |
91 | 264 |
return Vector(x[i], y[i], z[i]); |
265 |
}; |
|
266 |
||
267 |
void setVector(int i, const Vector &v) |
|
268 |
{ |
|
269 |
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
|
270 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
271 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
272 |
void normalize() |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
273 |
{ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
274 |
mfloat4 m,x,y,z; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
275 |
x = mmul(mx, mx); // x*x |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
276 |
y = mmul(my, my); // y*y |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
277 |
z = mmul(mz, mz); // z*z |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
278 |
m = madd(madd(x, y), z); // x*x + y*y + z*z |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
279 |
m = mdiv(mOne, msqrt(m)); // m = 1/sqrt(m) |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
280 |
mx = mmul(mx, m); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
281 |
my = mmul(my, m); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
282 |
mz = mmul(mz, m); |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
283 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
284 |
|
91 | 285 |
// accumulate |
286 |
VectorPacket operator+=(const VectorPacket &v) |
|
287 |
{ |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
288 |
mx = madd(mx, v.mx); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
289 |
my = madd(my, v.my); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
290 |
mz = madd(mz, v.mz); |
91 | 291 |
return *this; |
292 |
}; |
|
293 |
||
294 |
// add to non-masked components |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
295 |
VectorPacket selectiveAdd(const mfloat4 &mask, const VectorPacket &v) |
91 | 296 |
{ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
297 |
mx = mselect(mask, madd(mx, v.mx), mx); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
298 |
my = mselect(mask, madd(my, v.my), my); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
299 |
mz = mselect(mask, madd(mz, v.mz), mz); |
91 | 300 |
return *this; |
301 |
}; |
|
302 |
||
303 |
// add scalar to non-masked components |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
304 |
VectorPacket selectiveAdd(const mfloat4 &mask, const mfloat4 &m) |
91 | 305 |
{ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
306 |
mx = mselect(mask, madd(mx, m), mx); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
307 |
my = mselect(mask, madd(my, m), my); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
308 |
mz = mselect(mask, madd(mz, m), mz); |
91 | 309 |
return *this; |
310 |
}; |
|
311 |
||
87
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
312 |
// dot product |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
313 |
friend mfloat4 dot(const VectorPacket &a, const VectorPacket &b) |
87
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
314 |
{ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
315 |
return madd(madd( |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
316 |
mmul(a.mx, b.mx), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
317 |
mmul(a.my, b.my)), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
318 |
mmul(a.mz, b.mz)); |
87
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
319 |
}; |
1081e3dd3f3e
Sphere, Box - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
320 |
|
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
321 |
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
|
322 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
323 |
return VectorPacket( |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
324 |
madd(a.mx, b.mx), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
325 |
madd(a.my, b.my), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
326 |
madd(a.mz, b.mz)); |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
327 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
328 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
329 |
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
|
330 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
331 |
return VectorPacket( |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
332 |
msub(a.mx, b.mx), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
333 |
msub(a.my, b.my), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
334 |
msub(a.mz, b.mz)); |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
335 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
336 |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
337 |
friend VectorPacket operator*(const VectorPacket &v, const mfloat4 &m) |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
338 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
339 |
return VectorPacket( |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
340 |
mmul(v.mx, m), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
341 |
mmul(v.my, m), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
342 |
mmul(v.mz, m)); |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
343 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
344 |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
345 |
friend VectorPacket operator/(const mfloat4 &m, const VectorPacket &v) |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
346 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
347 |
return VectorPacket( |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
348 |
mdiv(m, v.mx), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
349 |
mdiv(m, v.my), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
350 |
mdiv(m, v.mz)); |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
351 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
352 |
|
91 | 353 |
// cell by cell product (only usable for colours) |
354 |
friend VectorPacket operator*(const VectorPacket &a, const VectorPacket &b) |
|
355 |
{ |
|
356 |
return VectorPacket( |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
357 |
mmul(a.mx, b.mx), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
358 |
mmul(a.my, b.my), |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
359 |
mmul(a.mz, b.mz)); |
91 | 360 |
}; |
361 |
||
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
362 |
// 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
|
363 |
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
|
364 |
{ |
86
ce6abe0aeeae
BBox - RayPacket intersection
Radek Brich <radek.brich@devl.cz>
parents:
84
diff
changeset
|
365 |
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
|
366 |
<< "," << 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
|
367 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
368 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
369 |
}; |
91 | 370 |
#endif |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
371 |
|
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
|
372 |
#endif |