Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/staging/src/include/Diderot/inline-matrix.h
ViewVC logotype

Diff of /branches/staging/src/include/Diderot/inline-matrix.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1943, Thu Jul 5 16:29:06 2012 UTC revision 1944, Thu Jul 5 17:19:46 2012 UTC
# Line 50  Line 50 
50      dst[1].v = src[1].v;      dst[1].v = src[1].v;
51  }  }
52    
53  STATIC_INLINE void scale2x2 (Diderot_Mat2x2_t dst, float s, Diderot_Mat2x2_t src)  STATIC_INLINE void scale2x2 (Diderot_Mat2x2_t dst, Diderot_real_t s, Diderot_Mat2x2_t src)
54  {  {
55      Diderot_vec2_t scale = vec2(s, s);      Diderot_vec2_t scale = vec2(s, s);
56      dst[0].v = scale * src[0].v;      dst[0].v = scale * src[0].v;
# Line 98  Line 98 
98  }  }
99    
100  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
101  STATIC_INLINE float norm2x2 (Diderot_Mat2x2_t m)  STATIC_INLINE Diderot_real_t norm2x2 (Diderot_Mat2x2_t m)
102  {  {
103      return SQRT(dot2(m[0].v,m[0].v) + dot2(m[1].v,m[1].v));      return SQRT(dot2(m[0].v,m[0].v) + dot2(m[1].v,m[1].v));
104  }  }
105    
106    // matrix time matrix ":" product
107    STATIC_INLINE Diderot_real_t ddotMat2x2Mat2x2 (Diderot_Mat2x2_t m1, Diderot_Mat2x2_t m2)
108    {
109        return dot2(m1[0].v, m2[0].v) + dot2(m1[1].v, m2[1].v);
110    }
111    
112  /********** 3x3 matrix functions **********/  /********** 3x3 matrix functions **********/
113    
# Line 131  Line 136 
136      dst[1].v = src[1].v;      dst[1].v = src[1].v;
137      dst[2].v = src[2].v;      dst[2].v = src[2].v;
138  }  }
139  STATIC_INLINE void scale3x3 (Diderot_Mat3x3_t dst, float s, Diderot_Mat3x3_t src)  
140    STATIC_INLINE void scale3x3 (Diderot_Mat3x3_t dst, Diderot_real_t s, Diderot_Mat3x3_t src)
141  {  {
142      Diderot_vec3_t scale = vec3(s, s, s);      Diderot_vec3_t scale = vec3(s, s, s);
143      dst[0].v = scale * src[0].v;      dst[0].v = scale * src[0].v;
# Line 190  Line 196 
196  }  }
197    
198  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
199  STATIC_INLINE float norm3x3 (Diderot_Mat3x3_t m)  STATIC_INLINE Diderot_real_t norm3x3 (Diderot_Mat3x3_t m)
200  {  {
201      return SQRT(dot3(m[0].v,m[0].v) + dot3(m[1].v,m[1].v) + dot3(m[2].v,m[2].v));      return SQRT(dot3(m[0].v,m[0].v) + dot3(m[1].v,m[1].v) + dot3(m[2].v,m[2].v));
202  }  }
203    
204    // matrix time matrix ":" product
205    STATIC_INLINE Diderot_real_t ddotMat3x3Mat3x3 (Diderot_Mat3x3_t m1, Diderot_Mat3x3_t m2)
206    {
207        return dot3(m1[0].v,m2[0].v) + dot3(m1[1].v,m2[1].v) + dot3(m1[2].v,m2[2].v);
208    }
209    
210    
211  /********** 4x4 matrix functions **********/  /********** 4x4 matrix functions **********/
212    
213    STATIC_INLINE void zero4x4 (Diderot_Mat4x4_t dst)
214    {
215        dst[0].v = vec4(0.0, 0.0, 0.0, 0.0);
216        dst[1].v = vec4(0.0, 0.0, 0.0, 0.0);
217        dst[2].v = vec4(0.0, 0.0, 0.0, 0.0);
218        dst[3].v = vec4(0.0, 0.0, 0.0, 0.0);
219    }
220    
221    STATIC_INLINE void identity4x4 (Diderot_Mat4x4_t dst)
222    {
223        dst[0].v = vec4(1.0, 0.0, 0.0, 0.0);
224        dst[1].v = vec4(0.0, 1.0, 0.0, 0.0);
225        dst[2].v = vec4(0.0, 0.0, 1.0, 0.0);
226        dst[3].v = vec4(0.0, 0.0, 0.0, 1.0);
227    }
228    
229    STATIC_INLINE Diderot_vec4_t column4x4 (Diderot_Mat4x4_t m, int i)
230    {
231        return vec4(m[0].r[i], m[1].r[i], m[2].r[i], m[3].r[i]);
232    }
233    
234  STATIC_INLINE void copy4x4 (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)  STATIC_INLINE void copy4x4 (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)
235  {  {
236      dst[0].v = src[0].v;      dst[0].v = src[0].v;
# Line 206  Line 239 
239      dst[3].v = src[3].v;      dst[3].v = src[3].v;
240  }  }
241    
242  STATIC_INLINE Diderot_vec4_t column4x4 (Diderot_Mat4x4_t m, int i)  STATIC_INLINE void scale4x4 (Diderot_Mat4x4_t dst, Diderot_real_t s, Diderot_Mat4x4_t src)
243  {  {
244      return vec4(m[0].r[i], m[1].r[i], m[2].r[i], m[3].r[i]);      Diderot_vec4_t scale = vec4(s, s, s, s);
245        dst[0].v = scale * src[0].v;
246        dst[1].v = scale * src[1].v;
247        dst[2].v = scale * src[2].v;
248        dst[3].v = scale * src[3].v;
249    }
250    
251    STATIC_INLINE void add4x4 (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t a, Diderot_Mat4x4_t b)
252    {
253        dst[0].v = a[0].v + b[0].v;
254        dst[1].v = a[1].v + b[1].v;
255        dst[2].v = a[2].v + b[2].v;
256        dst[3].v = a[3].v + b[3].v;
257    }
258    
259    STATIC_INLINE void sub4x4 (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t a, Diderot_Mat4x4_t b)
260    {
261        dst[0].v = a[0].v - b[0].v;
262        dst[1].v = a[1].v - b[1].v;
263        dst[2].v = a[2].v - b[2].v;
264        dst[3].v = a[3].v - b[3].v;
265    }
266    
267    STATIC_INLINE Diderot_vec4_t mulVec4Mat4x4 (Diderot_vec4_t v, Diderot_Mat4x4_t m)
268    {
269        return vec4(
270            dot4(v, column4x4(m, 0)),
271            dot4(v, column4x4(m, 1)),
272            dot4(v, column4x4(m, 2)),
273            dot4(v, column4x4(m,3)));
274    }
275    
276    STATIC_INLINE Diderot_vec4_t mulMat4x4Vec4 (Diderot_Mat4x4_t m, Diderot_vec4_t v)
277    {
278        return vec4(dot4(m[0].v, v), dot4(m[1].v, v), dot4(m[2].v, v), dot4(m[3].v, v));
279  }  }
280    
281  STATIC_INLINE void transpose4x4 (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)  STATIC_INLINE void transpose4x4 (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)
# Line 220  Line 287 
287  }  }
288    
289  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
290  STATIC_INLINE float norm4x4 (Diderot_Mat4x4_t m)  STATIC_INLINE Diderot_real_t norm4x4 (Diderot_Mat4x4_t m)
291  {  {
292      return sqrt(dot4(m[0].v,m[0].v) + dot4(m[1].v,m[1].v) + dot4(m[2].v,m[2].v) + dot4(m[3].v,m[3].v));      return sqrt(dot4(m[0].v,m[0].v) + dot4(m[1].v,m[1].v) + dot4(m[2].v,m[2].v) + dot4(m[3].v,m[3].v));
293  }  }
294    
295    // matrix time matrix ":" product
296    STATIC_INLINE Diderot_real_t ddotMat4x4Mat4x4 (Diderot_Mat4x4_t m1, Diderot_Mat4x4_t m2)
297    {
298        return dot4(m1[0].v,m2[0].v) + dot4(m1[1].v,m2[1].v) + dot4(m1[2].v,m2[2].v) + dot4(m1[3].v,m2[3].v);
299    }
300    
301  #endif /* !_DIDEROT_INLINE_MATRIX_H_ */  #endif /* !_DIDEROT_INLINE_MATRIX_H_ */

Legend:
Removed from v.1943  
changed lines
  Added in v.1944

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0