MathFu
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Friends Groups Pages
glsl_mappings.h
Go to the documentation of this file.
1 /*
2 * Copyright 2014 Google Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef MATHFU_GLSL_MAPPINGS_H_
17 #define MATHFU_GLSL_MAPPINGS_H_
18 
19 #include "mathfu/matrix.h"
20 #include "mathfu/quaternion.h"
21 #include "mathfu/rect.h"
22 #include "mathfu/vector.h"
23 
24 /// @file mathfu/glsl_mappings.h
25 /// @brief GLSL compatible data types.
26 /// @addtogroup mathfu_glsl
27 ///
28 /// To simplify the use of MathFu template classes and make it possible to
29 /// write code that looks similar to
30 /// <a href="http://www.opengl.org/documentation/glsl/">GLSL</a> in C++,
31 /// MathFu provides a set of data types that are similar in style to
32 /// GLSL Vector and Matrix data types.
33 
34 /// @brief Namespace for MathFu library.
35 namespace mathfu {
36 
37 /// @addtogroup mathfu_glsl
38 /// @{
39 
40 /// 2-dimensional <code>float</code> Vector.
42 /// 3-dimensional <code>float</code> Vector.
44 /// 4-dimensional <code>float</code> Vector.
46 
47 /// 2-dimensional <code>int</code> Vector.
49 /// 3-dimensional <code>int</code> Vector.
51 /// 4-dimensional <code>int</code> Vector.
53 
54 /// 2x2 <code>float</code> Matrix.
56 /// 3x3 <code>float</code> Matrix.
58 /// 3x3 <code>float</code> Matrix.
60 
61 /// 2-dimensional <code>float</code> packed Vector (VectorPacked).
63 /// 3-dimensional <code>float</code> packed Vector (VectorPacked).
65 /// 4-dimensional <code>float</code> packed Vector (VectorPacked).
67 
68 /// 2-dimensional <code>int</code> packed Vector (VectorPacked).
70 /// 3-dimensional <code>int</code> packed Vector (VectorPacked).
72 /// 4-dimensional <code>int</code> packed Vector (VectorPacked).
74 
75 /// Float-based quaternion. Note that this is not technically
76 /// a GLES type, but is included for convenience.
78 
79 /// Rect composed of type <code>float</code>.
81 /// Rect composed of type <code>double</code>.
83 /// Rect composed of type <code>int</code>.
84 typedef Rect<int> recti;
85 
86 /// @brief Calculate the cross product of two 3-dimensional Vectors.
87 ///
88 /// @param v1 Vector to multiply
89 /// @param v2 Vector to multiply
90 /// @return 3-dimensional vector that contains the result.
91 template<class T>
92 inline Vector<T, 3> cross(const Vector<T, 3>& v1, const Vector<T, 3>& v2) {
93  return Vector<T, 3>::CrossProduct(v1,v2);
94 }
95 
96 /// @brief Calculate the dot product of two N-dimensional Vectors of any type.
97 ///
98 /// @param v1 Vector to multiply
99 /// @param v2 Vector to multiply
100 /// @return Scalar dot product result.
101 template<class TV>
102 inline typename TV::Scalar dot(const TV& v1, const TV& v2) {
103  return TV::DotProduct(v1,v2);
104 }
105 
106 /// @brief Normalize an N-dimensional Vector of an arbitrary type.
107 ///
108 /// @param v1 Vector to normalize.
109 /// @return Normalized vector.
110 template<class TV>
111 inline TV normalize(const TV& v1) {
112  return v1.Normalized();
113 }
114 
115 /// @}
116 
117 } // namespace mathfu
118 
119 #endif // MATHFU_GLSL_MAPPINGS_H_
Definition: vector_3.h:24
mathfu::Quaternion< float > quat
Definition: glsl_mappings.h:77
Vector< int, 4 > vec4i
4-dimensional int Vector.
Definition: glsl_mappings.h:52
VectorPacked< int, 3 > vec3i_packed
3-dimensional int packed Vector (VectorPacked).
Definition: glsl_mappings.h:71
Vector of d elements with type T.
Definition: vector.h:63
Rect of type T containing position (pos) and width.
Definition: rect.h:33
Vector< T, 3 > cross(const Vector< T, 3 > &v1, const Vector< T, 3 > &v2)
Calculate the cross product of two 3-dimensional Vectors.
Definition: glsl_mappings.h:92
Matrix stores a set of "rows" by "columns" elements of type T and provides functions that operate on ...
Definition: matrix.h:147
Rect< int > recti
Rect composed of type int.
Definition: glsl_mappings.h:84
VectorPacked< float, 4 > vec4_packed
4-dimensional float packed Vector (VectorPacked).
Definition: glsl_mappings.h:66
Rect< double > rectd
Rect composed of type double.
Definition: glsl_mappings.h:82
VectorPacked< int, 2 > vec2i_packed
2-dimensional int packed Vector (VectorPacked).
Definition: glsl_mappings.h:69
TV normalize(const TV &v1)
Normalize an N-dimensional Vector of an arbitrary type.
Definition: glsl_mappings.h:111
VectorPacked< float, 2 > vec2_packed
2-dimensional float packed Vector (VectorPacked).
Definition: glsl_mappings.h:62
Matrix class and functions.
Vector< float, 3 > vec3
3-dimensional float Vector.
Definition: glsl_mappings.h:43
Matrix< float, 4, 4 > mat4
3x3 float Matrix.
Definition: glsl_mappings.h:59
VectorPacked< float, 3 > vec3_packed
3-dimensional float packed Vector (VectorPacked).
Definition: glsl_mappings.h:64
Vector< float, 2 > vec2
2-dimensional float Vector.
Definition: glsl_mappings.h:41
Packed N-dimensional vector.
Definition: vector.h:121
Definition: vector_4_simd.h:38
Quaternion class and functions.
Vector< int, 2 > vec2i
2-dimensional int Vector.
Definition: glsl_mappings.h:48
Rect< float > rectf
Rect composed of type float.
Definition: glsl_mappings.h:80
Vector class and functions.
TV::Scalar dot(const TV &v1, const TV &v2)
Calculate the dot product of two N-dimensional Vectors of any type.
Definition: glsl_mappings.h:102
Vector< float, 4 > vec4
4-dimensional float Vector.
Definition: glsl_mappings.h:45
Stores a Quaternion of type T and provides a set of utility operations on each Quaternion.
Definition: quaternion.h:47
Matrix< float, 3, 3 > mat3
3x3 float Matrix.
Definition: glsl_mappings.h:57
Matrix< float, 2, 2 > mat2
2x2 float Matrix.
Definition: glsl_mappings.h:55
static Vector< T, 3 > CrossProduct(const Vector< T, 3 > &v1, const Vector< T, 3 > &v2)
Calculate the cross product of two vectors.
Definition: vector.h:446
Vector< int, 3 > vec3i
3-dimensional int Vector.
Definition: glsl_mappings.h:50
VectorPacked< int, 4 > vec4i_packed
4-dimensional int packed Vector (VectorPacked).
Definition: glsl_mappings.h:73