1 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML
1.0 Strict//EN'
2 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
>
3 <html xmlns='http://www.w3.org/
1999/xhtml' xml:lang='en' lang='en'
>
5 <meta http-equiv='Content-Type' content='text/html; charset=utf-
8'
/>
6 <title>accessing vector elements by swizzling
</title>
7 <link href='reno.css' type='text/css' rel='stylesheet'
/>
14 <h1>QVM: Quaternions, Vectors, Matrices
</h1>
16 <!-- Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc. -->
17 <!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
18 <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
19 <div class=
"RenoIncludeDIV"><div class=
"RenoAutoDIV"><h3>Accessing Vector Elements by Swizzling
</h3>
21 <div class=
"RenoIncludeDIV"><p><span class=
"RenoEscape">#<!--<wiki>`#</wiki>--></span>include
<<span class=
"RenoLink"><a href=
"boost_qvm_swizzle_hpp.html">boost/qvm/swizzle.hpp
</a></span>></p>
24 namespace
<span class=
"RenoLink"><a href=
"qvm.html">qvm
</a></span>
26 <span class=
"RenoIncludeSPAN"> //*** Accessing vector elements by swizzling ***
28 <span class=
"RenoIncludeSPAN">//
2D
<span class=
"RenoLink"><a href=
"view_proxy.html">view proxies
</a></span>, only
<span class=
"RenoLink"><a href=
"SFINAE_enable_if.html">enabled if
</a></span>:
29 //
<span class=
"RenoLink"><a href=
"is_vec.html">is_vec
</a></span><V
>::value
30 template
<class V
> -unspecified-
2D-vector-type- XX( V
& v );
31 template
<class V
> -unspecified-
2D-vector-type- XY( V
& v );
32 template
<class V
> -unspecified-
2D-vector-type- XZ( V
& v );
33 template
<class V
> -unspecified-
2D-vector-type- XW( V
& v );
34 template
<class V
> -unspecified-
2D-vector-type- X0( V
& v );
35 template
<class V
> -unspecified-
2D-vector-type- X1( V
& v );
36 template
<class V
> -unspecified-
2D-vector-type- YX( V
& v );
37 template
<class V
> -unspecified-
2D-vector-type- YY( V
& v );
38 template
<class V
> -unspecified-
2D-vector-type- YZ( V
& v );
39 template
<class V
> -unspecified-
2D-vector-type- YW( V
& v );
40 template
<class V
> -unspecified-
2D-vector-type- Y0( V
& v );
41 template
<class V
> -unspecified-
2D-vector-type- Y1( V
& v );
42 template
<class V
> -unspecified-
2D-vector-type- ZX( V
& v );
43 template
<class V
> -unspecified-
2D-vector-type- ZY( V
& v );
44 template
<class V
> -unspecified-
2D-vector-type- ZZ( V
& v );
45 template
<class V
> -unspecified-
2D-vector-type- ZW( V
& v );
46 template
<class V
> -unspecified-
2D-vector-type- Z0( V
& v );
47 template
<class V
> -unspecified-
2D-vector-type- Z1( V
& v );
48 template
<class V
> -unspecified-
2D-vector-type- WX( V
& v );
49 template
<class V
> -unspecified-
2D-vector-type- WY( V
& v );
50 template
<class V
> -unspecified-
2D-vector-type- WZ( V
& v );
51 template
<class V
> -unspecified-
2D-vector-type- WW( V
& v );
52 template
<class V
> -unspecified-
2D-vector-type- W0( V
& v );
53 template
<class V
> -unspecified-
2D-vector-type- W1( V
& v );
55 -unspecified-
2D-vector-type- _00();
56 -unspecified-
2D-vector-type- _01();
57 -unspecified-
2D-vector-type- _10();
58 -unspecified-
2D-vector-type- _11();
60 //
3D
<span class=
"RenoLink"><a href=
"view_proxy.html">view proxies
</a></span>, only
<span class=
"RenoLink"><a href=
"SFINAE_enable_if.html">enabled if
</a></span>:
61 //
<span class=
"RenoLink"><a href=
"is_vec.html">is_vec
</a></span><V
>::value
62 template
<class V
> -unspecified-
3D-vector-type- XXX( V
& v );
64 template
<class V
> -unspecified-
3D-vector-type- XXW( V
& v );
65 template
<class V
> -unspecified-
3D-vector-type- XX0( V
& v );
66 template
<class V
> -unspecified-
3D-vector-type- XX1( V
& v );
67 template
<class V
> -unspecified-
3D-vector-type- XYX( V
& v );
69 template
<class V
> -unspecified-
3D-vector-type- XY1( V
& v );
71 template
<class V
> -unspecified-
3D-vector-type- WW1( V
& v );
73 -unspecified-
3D-vector-type- _000();
74 -unspecified-
3D-vector-type- _001();
75 -unspecified-
3D-vector-type- _010();
77 -unspecified-
3D-vector-type- _111();
79 //
4D
<span class=
"RenoLink"><a href=
"view_proxy.html">view proxies
</a></span>, only
<span class=
"RenoLink"><a href=
"SFINAE_enable_if.html">enabled if
</a></span>:
80 //
<span class=
"RenoLink"><a href=
"is_vec.html">is_vec
</a></span><V
>::value
81 template
<class V
> -unspecified-
4D-vector-type- XXXX( V
& v );
83 template
<class V
> -unspecified-
4D-vector-type- XXXW( V
& v );
84 template
<class V
> -unspecified-
4D-vector-type- XXX0( V
& v );
85 template
<class V
> -unspecified-
4D-vector-type- XXX1( V
& v );
86 template
<class V
> -unspecified-
4D-vector-type- XXYX( V
& v );
88 template
<class V
> -unspecified-
4D-vector-type- XXY1( V
& v );
90 template
<class V
> -unspecified-
4D-vector-type- WWW1( V
& v );
92 -unspecified-
4D-vector-type- _0000();
93 -unspecified-
4D-vector-type- _0001();
94 -unspecified-
4D-vector-type- _0010();
96 -unspecified-
4D-vector-type- _1111();
</span> </span>
99 </div><p>Swizzling allows zero-overhead direct access to a (possibly rearranged) subset of the elements of
2D,
3D and
4D vectors. For example, if
<i>v
</i> is a
4D vector, the expression
<i>(v,YX)
</i> is a
2D
<span class=
"RenoLink"><a href=
"view_proxy.html">view proxy
</a></span> whose
<i>X
</i> element refers to the
<i>Y
</i> element of
<i>v
</i>, and whose
<i>Y
</i> element refers to the
<i>X
</i> element of
<i>v
</i>. Like other
<span class=
"RenoLink"><a href=
"view_proxy.html">view proxies
</a></span> <i>YX
</i> is an lvalue, that is, if
<i>v2
</i> is a
2D vector, one could write:
</p>
100 <pre>YX(v) = v2;
</pre>
101 <p>The above will leave the
<i>Z
</i> and
<i>W
</i> elements of
<i>v
</i> unchanged but assign the
<i>Y
</i> element of
<i>v2
</i> to the
<i>X
</i> element of
<i>v
</i> and the
<i>X
</i> element of
<i>v2
</i> to the
<i>Y
</i> element of
<i>v
</i>.
</p>
102 <p>It is also possible to repeat the same vector element in rvalue swizzling: the expression
<i>ZZZ(v)
</i> is a
3D vector whose
<i>X
</i>,
<i>Y
</i> and
<i>Z
</i> elements all refer to the
<i>Z
</i> element of
<i>v
</i>.
</p>
103 </div><div class=
"RenoAutoDIV"><div class=
"RenoHR"><hr/></div>
104 See also:
<span class=
"RenoPageList"><a href=
"index.html">Boost QVM
</a> |
<a href=
"boost_qvm_swizzle2_hpp.html">boost/qvm/swizzle2.hpp
</a> |
<a href=
"boost_qvm_swizzle3_hpp.html">boost/qvm/swizzle3.hpp
</a> |
<a href=
"boost_qvm_swizzle4_hpp.html">boost/qvm/swizzle4.hpp
</a> |
<a href=
"Synopsis.html">Synopsis
</a> |
<a href=
"transform_point.html">transform_point
</a> |
<a href=
"transform_vector.html">transform_vector
</a></span>
106 <!-- Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc. -->
107 <!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
108 <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
111 <a class=
"logo" href=
"http://jigsaw.w3.org/css-validator/check/referer"><img class=
"logo_pic" src=
"valid-css.png" alt=
"Valid CSS" height=
"31" width=
"88"/></a>
112 <a class=
"logo" href=
"http://validator.w3.org/check?uri=referer"><img class=
"logo_pic" src=
"valid-xhtml.png" alt=
"Valid XHTML 1.0" height=
"31" width=
"88"/></a>
113 <small>Copyright (c)
2008-
2016 by Emil Dotchevski and Reverge Studios, Inc.
<br/>
114 Distributed under the
<a href=
"http://www.boost.org/LICENSE_1_0.txt">Boost Software License, Version
1.0</a>.
</small>