SCM Repository
Annotation of /branches/pure-cfg/src/include/Diderot/inline-vec3.h
Parent Directory
|
Revision Log
Revision 1593 - (view) (download) (as text)
1 : | jhr | 710 | /*! \file inline-vec3.h |
2 : | * | ||
3 : | * \author John Reppy | ||
4 : | * | ||
5 : | * \brief inline functions for 3D vectors | ||
6 : | */ | ||
7 : | |||
8 : | /* | ||
9 : | * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) | ||
10 : | * All rights reserved. | ||
11 : | */ | ||
12 : | |||
13 : | #ifndef _DIDEROT_INLINE_VEC3_H_ | ||
14 : | #define _DIDEROT_INLINE_VEC3_H_ | ||
15 : | |||
16 : | #ifndef _DIDEROT_TYPES_H_ | ||
17 : | #include "Diderot/types.h" | ||
18 : | #endif | ||
19 : | |||
20 : | jhr | 1593 | STATIC_INLINE Diderot_vec3_t vec3 (Diderot_real_t a, Diderot_real_t b, Diderot_real_t c) |
21 : | jhr | 710 | { |
22 : | jhr | 1593 | return __extension__ (Diderot_vec3_t){ a, b, c, 0.0f }; |
23 : | jhr | 710 | } |
24 : | |||
25 : | jhr | 1593 | STATIC_INLINE Diderot_ivec3_t vec3rtoi (Diderot_vec3_t v) |
26 : | jhr | 710 | { |
27 : | jhr | 1593 | Diderot_union3_t u; |
28 : | jhr | 710 | u.v = v; |
29 : | jhr | 1593 | 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 : | jhr | 710 | } |
36 : | |||
37 : | jhr | 1593 | STATIC_INLINE Diderot_vec3_t vec3itor (Diderot_ivec3_t v) |
38 : | jhr | 710 | { |
39 : | union3i_t u; | ||
40 : | u.v = v; | ||
41 : | jhr | 1593 | 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 : | jhr | 710 | } |
43 : | |||
44 : | jhr | 1593 | STATIC_INLINE Diderot_vec3_t scale3 (Diderot_real_t s, Diderot_vec3_t v) |
45 : | jhr | 710 | { |
46 : | jhr | 1593 | return vec3(s, s, s) * v; |
47 : | jhr | 710 | } |
48 : | |||
49 : | jhr | 1593 | STATIC_INLINE Diderot_vec3_t clamp3 (Diderot_vec3_t lo, Diderot_vec3_t hi, Diderot_vec3_t v) |
50 : | jhr | 1297 | { |
51 : | // FIXME: there is probably a vectorized way to compute this | ||
52 : | jhr | 1593 | Diderot_union3_t a, b, c; |
53 : | jhr | 1297 | a.v = lo; b.v = hi; c.v = v; |
54 : | jhr | 1593 | return vec3( |
55 : | clamp(a.r[0], b.r[0], c.r[0]), | ||
56 : | clamp(a.r[1], b.r[1], c.r[1]), | ||
57 : | clamp(a.r[2], b.r[2], c.r[2])); | ||
58 : | jhr | 1297 | } |
59 : | |||
60 : | jhr | 1593 | STATIC_INLINE Diderot_vec3_t lerp3 (Diderot_vec3_t a, Diderot_vec3_t b, Diderot_real_t t) |
61 : | jhr | 756 | { |
62 : | jhr | 1593 | return a + scale3(t, b - a); |
63 : | jhr | 756 | } |
64 : | |||
65 : | jhr | 1593 | STATIC_INLINE Diderot_vec3_t floor3 (Diderot_vec3_t v) |
66 : | jhr | 710 | { |
67 : | jhr | 1593 | Diderot_union3_t u; |
68 : | jhr | 710 | u.v = v; |
69 : | jhr | 1593 | return vec3(FLOOR(u.r[0]), FLOOR(u.r[1]), FLOOR(u.r[2])); |
70 : | jhr | 710 | } |
71 : | |||
72 : | jhr | 1593 | STATIC_INLINE Diderot_ivec3_t truncToInt3 (Diderot_vec3_t v) |
73 : | jhr | 710 | { |
74 : | jhr | 1593 | Diderot_union3_t t; |
75 : | jhr | 710 | t.v = v; |
76 : | jhr | 1593 | return __extension__ (Diderot_ivec3_t){ |
77 : | (Diderot_int_t)TRUNC(t.r[0]), | ||
78 : | (Diderot_int_t)TRUNC(t.r[1]), | ||
79 : | (Diderot_int_t)TRUNC(t.r[2]), | ||
80 : | jhr | 710 | 0 }; |
81 : | } | ||
82 : | |||
83 : | jhr | 1593 | STATIC_INLINE Diderot_real_t dot3 (Diderot_vec3_t u, Diderot_vec3_t v) |
84 : | jhr | 749 | { |
85 : | jhr | 1593 | Diderot_union3_t uv = __extension__ (Diderot_union3_t)(u*v); |
86 : | jhr | 749 | return uv.r[0] + uv.r[1] + uv.r[2]; |
87 : | } | ||
88 : | |||
89 : | jhr | 1593 | STATIC_INLINE Diderot_real_t length3 (Diderot_vec3_t v) |
90 : | jhr | 749 | { |
91 : | jhr | 1593 | return SQRT(dot3(v, v)); |
92 : | jhr | 749 | } |
93 : | |||
94 : | jhr | 1593 | STATIC_INLINE Diderot_vec3_t normalize3 (Diderot_vec3_t v) |
95 : | jhr | 749 | { |
96 : | jhr | 1593 | return scale3(1.0 / length3(v), v); |
97 : | jhr | 749 | } |
98 : | |||
99 : | jhr | 1593 | STATIC_INLINE Diderot_vec3_t cross3 (Diderot_vec3_t u, Diderot_vec3_t v) |
100 : | jhr | 710 | { |
101 : | jhr | 1593 | Diderot_union3_t uu = (Diderot_union3_t)u; |
102 : | Diderot_union3_t uv = (Diderot_union3_t)v; | ||
103 : | return __extension__ (Diderot_vec3_t){ | ||
104 : | jhr | 710 | 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], | ||
106 : | uu.r[0]*uv.r[1] - uu.r[1]*uv.r[0], | ||
107 : | 0 }; | ||
108 : | } | ||
109 : | |||
110 : | #endif /* !_DIDEROT_INLINE_VEC3_H_ */ |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |