91 { |
91 { |
92 p = lookat - from; u = cross(up, p); |
92 p = lookat - from; u = cross(up, p); |
93 p.normalize(); u.normalize(); |
93 p.normalize(); u.normalize(); |
94 v = cross(p, u); |
94 v = cross(p, u); |
95 }; |
95 }; |
|
96 |
|
97 #ifndef NO_SIMD |
|
98 void *operator new(size_t size) { return _mm_malloc(size, 16); }; |
|
99 void operator delete(void *p) { _mm_free(p); }; |
|
100 #endif |
96 |
101 |
97 const Vector &getEye() const { return eye; }; |
102 const Vector &getEye() const { return eye; }; |
98 const Vector &getp() const { return p; }; |
103 const Vector &getp() const { return p; }; |
99 const Vector &getu() const { return u; }; |
104 const Vector &getu() const { return u; }; |
100 const Vector &getv() const { return v; }; |
105 const Vector &getv() const { return v; }; |
120 mfloat4 m1x,m1y,m1z; |
125 mfloat4 m1x,m1y,m1z; |
121 mfloat4 m2x,m2y,m2z; |
126 mfloat4 m2x,m2y,m2z; |
122 mfloat4 m; |
127 mfloat4 m; |
123 |
128 |
124 // m1(xyz) = u * samples[i].x |
129 // m1(xyz) = u * samples[i].x |
125 m1x = mset1(u.x); |
130 m1x = mshuffle(u.mf4, u.mf4, mShuffle0); // u.x |
126 m1y = mset1(u.y); |
131 m1y = mshuffle(u.mf4, u.mf4, mShuffle1); // u.y |
127 m1z = mset1(u.z); |
132 m1z = mshuffle(u.mf4, u.mf4, mShuffle2); // u.z |
128 m = mset(samples[3].x, samples[2].x, samples[1].x, samples[0].x); |
133 m = mset(samples[3].x, samples[2].x, samples[1].x, samples[0].x); |
129 m1x = mmul(m1x, m); |
134 m1x = mmul(m1x, m); |
130 m1y = mmul(m1y, m); |
135 m1y = mmul(m1y, m); |
131 m1z = mmul(m1z, m); |
136 m1z = mmul(m1z, m); |
132 |
137 |
133 // m2(xyz) = v * samples[i].y |
138 // m2(xyz) = v * samples[i].y |
134 m2x = mset1(v.x); |
139 m2x = mshuffle(v.mf4, v.mf4, mShuffle0); // v.x |
135 m2y = mset1(v.y); |
140 m2y = mshuffle(v.mf4, v.mf4, mShuffle1); // v.y |
136 m2z = mset1(v.z); |
141 m2z = mshuffle(v.mf4, v.mf4, mShuffle2); // v.z |
137 m = mset(samples[3].y, samples[2].y, samples[1].y, samples[0].y); |
142 m = mset(samples[3].y, samples[2].y, samples[1].y, samples[0].y); |
138 m2x = mmul(m2x, m); |
143 m2x = mmul(m2x, m); |
139 m2y = mmul(m2y, m); |
144 m2y = mmul(m2y, m); |
140 m2z = mmul(m2z, m); |
145 m2z = mmul(m2z, m); |
141 |
146 |
149 m1x = mmul(m1x, m); |
154 m1x = mmul(m1x, m); |
150 m1y = mmul(m1y, m); |
155 m1y = mmul(m1y, m); |
151 m1z = mmul(m1z, m); |
156 m1z = mmul(m1z, m); |
152 |
157 |
153 // m1(xyz) = p - m1 = p - (u*samples[i].x + v*samples[i].y)*F = dir |
158 // m1(xyz) = p - m1 = p - (u*samples[i].x + v*samples[i].y)*F = dir |
154 m2x = mset1(p.x); |
159 m2x = mshuffle(p.mf4, p.mf4, mShuffle0); // p.x |
155 m2y = mset1(p.y); |
160 m2y = mshuffle(p.mf4, p.mf4, mShuffle1); // p.y |
156 m2z = mset1(p.z); |
161 m2z = mshuffle(p.mf4, p.mf4, mShuffle2); // p.z |
157 rays.dir.mx = msub(m2x, m1x); |
162 rays.dir.mx = msub(m2x, m1x); |
158 rays.dir.my = msub(m2y, m1y); |
163 rays.dir.my = msub(m2y, m1y); |
159 rays.dir.mz = msub(m2z, m1z); |
164 rays.dir.mz = msub(m2z, m1z); |
160 |
165 |
161 // copy origin |
166 // copy origin |
162 rays.o.mx = mset1(eye.x); |
167 rays.o.mx = mshuffle(eye.mf4, eye.mf4, mShuffle0); // eye.x |
163 rays.o.my = mset1(eye.y); |
168 rays.o.my = mshuffle(eye.mf4, eye.mf4, mShuffle1); // eye.y |
164 rays.o.mz = mset1(eye.z); |
169 rays.o.mz = mshuffle(eye.mf4, eye.mf4, mShuffle2); // eye.z |
165 |
170 |
166 rays.dir.normalize(); |
171 rays.dir.normalize(); |
167 rays.invdir = mOne/rays.dir; |
172 rays.invdir = mOne / rays.dir; |
168 }; |
173 }; |
169 #endif |
174 #endif |
170 }; |
175 }; |
171 |
176 |
172 /** |
177 /** |