1// 2// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. 3// Use of this source code is governed by a BSD-style license that can be 4// found in the LICENSE file. 5// 6 7#ifndef SAMPLE_UTIL_VECTOR_H 8#define SAMPLE_UTIL_VECTOR_H 9 10struct Vector2 11{ 12 union 13 { 14 struct 15 { 16 float x, y; 17 }; 18 float data[2]; 19 }; 20 21 Vector2(); 22 Vector2(float x, float y); 23 24 static float length(const Vector2 &vec); 25 static float lengthSquared(const Vector2 &vec); 26 27 static Vector2 normalize(const Vector2 &vec); 28}; 29 30struct Vector3 31{ 32 union 33 { 34 struct 35 { 36 float x, y, z; 37 }; 38 float data[3]; 39 }; 40 41 Vector3(); 42 Vector3(float x, float y, float z); 43 44 static float length(const Vector3 &vec); 45 static float lengthSquared(const Vector3 &vec); 46 47 static Vector3 normalize(const Vector3 &vec); 48 49 static float dot(const Vector3 &a, const Vector3 &b); 50 static Vector3 cross(const Vector3 &a, const Vector3 &b); 51}; 52 53Vector3 operator*(const Vector3 &a, const Vector3 &b); 54Vector3 operator*(const Vector3 &a, const float& b); 55Vector3 operator/(const Vector3 &a, const Vector3 &b); 56Vector3 operator/(const Vector3 &a, const float& b); 57Vector3 operator+(const Vector3 &a, const Vector3 &b); 58Vector3 operator-(const Vector3 &a, const Vector3 &b); 59 60struct Vector4 61{ 62 union 63 { 64 struct 65 { 66 float x, y, z, w; 67 }; 68 float data[4]; 69 }; 70 71 Vector4(); 72 Vector4(float x, float y, float z, float w); 73 74 static float length(const Vector4 &vec); 75 static float lengthSquared(const Vector4 &vec); 76 77 static Vector4 normalize(const Vector4 &vec); 78 79 static float dot(const Vector4 &a, const Vector4 &b); 80}; 81 82#endif // SAMPLE_UTIL_VECTOR_H 83