OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VectorTypes.h
Go to the documentation of this file.
1 /* Copyright (c) 2012-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #ifndef VECTORTYPES_H
22 #define VECTORTYPES_H
23 
24 #include <cmath>
25 
26 namespace MaliSDK
27 {
32  class Vec3f
33  {
34  public:
35  float x, y, z;
36 
45  static float dot(Vec3f& vector1, Vec3f& vector2)
46  {
47  return (vector1.x * vector2.x + vector1.y * vector2.y + vector1.z * vector2.z);
48  }
49 
53  void normalize(void)
54  {
55  float length = sqrt(x * x + y * y + z * z);
56 
57  x /= length;
58  y /= length;
59  z /= length;
60  }
61 
69  static Vec3f cross(const Vec3f& vector1, const Vec3f& vector2)
70  {
71  /* Floating point vector to be returned. */
72  Vec3f crossProduct;
73 
74  crossProduct.x = (vector1.y * vector2.z) - (vector1.z * vector2.y);
75  crossProduct.y = (vector1.z * vector2.x) - (vector1.x * vector2.z);
76  crossProduct.z = (vector1.x * vector2.y) - (vector1.y * vector2.x);
77 
78  return crossProduct;
79  }
80  };
81 
86  class Vec4f
87  {
88  public:
89  float x, y, z, w;
90 
94  void normalize(void)
95  {
96  float length = sqrt(x * x + y * y + z * z + w * w);
97 
98  x /= length;
99  y /= length;
100  z /= length;
101  w /= length;
102  }
103  };
104 }
105 #endif /* VECTORTYPES_H */
106 
static float dot(Vec3f &vector1, Vec3f &vector2)
Calculate dot product between two 3D floating point vectors.
Definition: VectorTypes.h:45
static Vec3f cross(const Vec3f &vector1, const Vec3f &vector2)
Calculate cross product between two 3D floating point vectors.
Definition: VectorTypes.h:69
A 3D floating point vector.
Definition: VectorTypes.h:83
GLfloat GLfloat GLfloat w
Definition: gl2ext.h:2701
void normalize(void)
Normalize 4D floating point vector.
Definition: VectorTypes.h:94
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
GLenum GLuint GLenum GLsizei length
Definition: gl2ext.h:134
GLint y
Definition: gl2ext.h:179
void normalize(void)
Normalize 3D floating point vector.
Definition: VectorTypes.h:53