]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/qvm/doc/source/tutorial.cpp
1 //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/qvm/operations.hpp>
7 #include <boost/qvm/map_mat_mat.hpp>
8 #include <boost/qvm/map_mat_vec.hpp>
9 #include <boost/qvm/map_vec_mat.hpp>
10 #include <boost/qvm/vec_access.hpp>
11 #include <boost/qvm/vec_traits_array.hpp>
12 #include <boost/qvm/quat.hpp>
13 #include <boost/qvm/vec.hpp>
14 #include <boost/qvm/mat.hpp>
15 #include <boost/qvm/swizzle.hpp>
16 using namespace boost::qvm
;
18 struct float3
{ float a
[3]; };
19 struct float4
{ float a
[4]; };
20 struct float33
{ float a
[3][3]; };
21 struct fquat
{ float a
[4]; };
33 static int const dim
=3;
34 typedef float scalar_type
;
36 template <int I
> static inline scalar_type
& write_element( float3
& v
) { return v
.a
[I
]; }
37 template <int I
> static inline scalar_type
read_element( float3
const & v
) { return v
.a
[I
]; }
39 static inline scalar_type
& write_element_idx( int i
, float3
& v
) { return v
.a
[i
]; }
40 static inline scalar_type
read_element_idx( int i
, float3
const & v
) { return v
.a
[i
]; }
47 static int const dim
=4;
48 typedef float scalar_type
;
50 template <int I
> static inline scalar_type
& write_element( float4
& v
) { return v
.a
[I
]; }
51 template <int I
> static inline scalar_type
read_element( float4
const & v
) { return v
.a
[I
]; }
53 static inline scalar_type
& write_element_idx( int i
, float4
& v
) { return v
.a
[i
]; }
54 static inline scalar_type
read_element_idx( int i
, float4
const & v
) { return v
.a
[i
]; }
61 typedef float scalar_type
;
62 static int const rows
=3;
63 static int const cols
=3;
65 template <int R
,int C
>
66 static inline scalar_type
& write_element( float33
& m
) { return m
.a
[R
][C
]; }
68 template <int R
,int C
>
69 static inline scalar_type
read_element( float33
const & m
) { return m
.a
[R
][C
]; }
71 static inline scalar_type
& write_element_idx( int r
, int c
, float33
& m
) { return m
.a
[r
][c
]; }
72 static inline scalar_type
read_element_idx( int r
, int c
, float33
const & m
) { return m
.a
[r
][c
]; }
79 typedef float scalar_type
;
81 template <int I
> static inline scalar_type
& write_element( float4
& v
) { return v
.a
[I
]; }
82 template <int I
> static inline scalar_type
read_element( float4
const & v
) { return v
.a
[I
]; }
84 static inline scalar_type
& write_element_idx( int i
, float4
& v
) { return v
.a
[i
]; }
85 static inline scalar_type
read_element_idx( int i
, float4
const & v
) { return v
.a
[i
]; }
94 quat
<float> rx
=rotx_quat(3.14159f
);
98 vec
<float,3> v
={0,1,0};
99 mat
<float,4,4> tr
=translation_mat(v
);
108 float33 m
= rotx_mat
<3>(3.14159f
);
113 float v
[3] = {0,0,7};
114 float3 vrot
= rotx_mat
<3>(3.14159f
) * v
;
119 float3 vrot
= transposed(rotx_mat
<3>(3.14159f
)) * v
;
124 YXZ(v
) = rotx_mat
<3>(3.14159f
) * v
;
129 float4 point
= XYZ1(v
); //{0,0,7,1}
130 float4 vector
= XYZ0(v
); //{0,0,7,0}
135 float4 v1
= ZZZZ(v
); //{7,7,7,7}
139 float v
[3] = {0,0,7};
145 multiply_column1( float33
& m
, float scalar
)