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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/include/Diderot/inline-vec3.h
ViewVC logotype

Diff of /branches/pure-cfg/src/include/Diderot/inline-vec3.h

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

revision 1592, Tue Nov 1 09:41:35 2011 UTC revision 1593, Tue Nov 1 12:28:30 2011 UTC
# Line 17  Line 17 
17  #include "Diderot/types.h"  #include "Diderot/types.h"
18  #endif  #endif
19    
20  STATIC_INLINE vec3f_t vec3f (float a, float b, float c)  STATIC_INLINE Diderot_vec3_t vec3 (Diderot_real_t a, Diderot_real_t b, Diderot_real_t c)
21  {  {
22      return __extension__ (vec3f_t){ a, b, c, 0.0f };      return __extension__ (Diderot_vec3_t){ a, b, c, 0.0f };
23  }  }
24    
25  STATIC_INLINE vec3i_t vec3ftoi (vec3f_t v)  STATIC_INLINE Diderot_ivec3_t vec3rtoi (Diderot_vec3_t v)
26  {  {
27      union3f_t u;      Diderot_union3_t u;
28      u.v = v;      u.v = v;
29      return __extension__ (vec3i_t){ (int32_t)u.r[0], (int32_t)u.r[1], (int32_t)u.r[2], 0 };      return __extension__ (Diderot_ivec3_t){
30                (Diderot_int_t)u.r[0],
31                (Diderot_int_t)u.r[1],
32                (Diderot_int_t)u.r[2],
33                0
34            };
35  }  }
36    
37  STATIC_INLINE vec3f_t vec3itof (vec3i_t v)  STATIC_INLINE Diderot_vec3_t vec3itor (Diderot_ivec3_t v)
38  {  {
39      union3i_t u;      union3i_t u;
40      u.v = v;      u.v = v;
41      return __extension__ (vec3f_t){ (float)u.i[0], (float)u.i[1], (float)u.i[2], 0 };      return __extension__ (Diderot_vec3_t){ (Diderot_real_t)u.i[0], (Diderot_real_t)u.i[1], (Diderot_real_t)u.i[2], 0 };
42  }  }
43    
44  STATIC_INLINE vec3f_t scale3f (float s, vec3f_t v)  STATIC_INLINE Diderot_vec3_t scale3 (Diderot_real_t s, Diderot_vec3_t v)
45  {  {
46      return vec3f(s, s, s) * v;      return vec3(s, s, s) * v;
47  }  }
48    
49  STATIC_INLINE vec3f_t clamp3f (vec3f_t lo, vec3f_t hi, vec3f_t v)  STATIC_INLINE Diderot_vec3_t clamp3 (Diderot_vec3_t lo, Diderot_vec3_t hi, Diderot_vec3_t v)
50  {  {
51    // FIXME: there is probably a vectorized way to compute this    // FIXME: there is probably a vectorized way to compute this
52      union3f_t a, b, c;      Diderot_union3_t a, b, c;
53      a.v = lo; b.v = hi; c.v = v;      a.v = lo; b.v = hi; c.v = v;
54      return vec3f(      return vec3(
55          clampf(a.r[0], b.r[0], c.r[0]),          clamp(a.r[0], b.r[0], c.r[0]),
56          clampf(a.r[1], b.r[1], c.r[1]),          clamp(a.r[1], b.r[1], c.r[1]),
57          clampf(a.r[2], b.r[2], c.r[2]));          clamp(a.r[2], b.r[2], c.r[2]));
58  }  }
59    
60  STATIC_INLINE vec3f_t lerp3f (vec3f_t a, vec3f_t b, float t)  STATIC_INLINE Diderot_vec3_t lerp3 (Diderot_vec3_t a, Diderot_vec3_t b, Diderot_real_t t)
61  {  {
62      return a + scale3f(t, b - a);      return a + scale3(t, b - a);
63  }  }
64    
65  STATIC_INLINE vec3f_t floor3f (vec3f_t v)  STATIC_INLINE Diderot_vec3_t floor3 (Diderot_vec3_t v)
66  {  {
67      union3f_t u;      Diderot_union3_t u;
68      u.v = v;      u.v = v;
69      return vec3f(floorf(u.r[0]), floorf(u.r[1]), floorf(u.r[2]));      return vec3(FLOOR(u.r[0]), FLOOR(u.r[1]), FLOOR(u.r[2]));
70  }  }
71    
72  STATIC_INLINE vec3i_t truncToInt3f (vec3f_t v)  STATIC_INLINE Diderot_ivec3_t truncToInt3 (Diderot_vec3_t v)
73  {  {
74      union3f_t t;      Diderot_union3_t t;
75      t.v = v;      t.v = v;
76      return __extension__ (vec3i_t){      return __extension__ (Diderot_ivec3_t){
77          (int32_t)truncf(t.r[0]),          (Diderot_int_t)TRUNC(t.r[0]),
78          (int32_t)truncf(t.r[1]),          (Diderot_int_t)TRUNC(t.r[1]),
79          (int32_t)truncf(t.r[2]),          (Diderot_int_t)TRUNC(t.r[2]),
80          0 };          0 };
81  }  }
82    
83  STATIC_INLINE float dot3f (vec3f_t u, vec3f_t v)  STATIC_INLINE Diderot_real_t dot3 (Diderot_vec3_t u, Diderot_vec3_t v)
84  {  {
85      union3f_t uv = __extension__ (union3f_t)(u*v);      Diderot_union3_t uv = __extension__ (Diderot_union3_t)(u*v);
86      return uv.r[0] + uv.r[1] + uv.r[2];      return uv.r[0] + uv.r[1] + uv.r[2];
87  }  }
88    
89  STATIC_INLINE float length3f (vec3f_t v)  STATIC_INLINE Diderot_real_t length3 (Diderot_vec3_t v)
90  {  {
91      return sqrtf(dot3f(v, v));      return SQRT(dot3(v, v));
92  }  }
93    
94  STATIC_INLINE vec3f_t normalize3f (vec3f_t v)  STATIC_INLINE Diderot_vec3_t normalize3 (Diderot_vec3_t v)
95  {  {
96      return scale3f(1.0 / length3f(v), v);      return scale3(1.0 / length3(v), v);
97  }  }
98    
99  STATIC_INLINE vec3f_t cross3f (vec3f_t u, vec3f_t v)  STATIC_INLINE Diderot_vec3_t cross3 (Diderot_vec3_t u, Diderot_vec3_t v)
100  {  {
101      union3f_t uu = (union3f_t)u;      Diderot_union3_t uu = (Diderot_union3_t)u;
102      union3f_t uv = (union3f_t)v;      Diderot_union3_t uv = (Diderot_union3_t)v;
103      return __extension__ (vec3f_t){      return __extension__ (Diderot_vec3_t){
104          uu.r[1]*uv.r[2] - uu.r[2]*uv.r[1],          uu.r[1]*uv.r[2] - uu.r[2]*uv.r[1],
105          uu.r[2]*uv.r[0] - uu.r[0]*uv.r[2],          uu.r[2]*uv.r[0] - uu.r[0]*uv.r[2],
106          uu.r[0]*uv.r[1] - uu.r[1]*uv.r[0],          uu.r[0]*uv.r[1] - uu.r[1]*uv.r[0],

Legend:
Removed from v.1592  
changed lines
  Added in v.1593

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