Wildvine Engine
Referencia Doxygen del codigo propio de Wildvine Engine.
Cargando...
Buscando...
Nada coincide
Vector2.h
Ir a la documentación de este archivo.
1
6/*
7 * MIT License
8 *
9 * Copyright (c) 2024 Roberto Charreton
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in all
19 * copies or substantial portions of the Software.
20 *
21 * In addition, any project or software that uses this library or class must include
22 * the following acknowledgment in the credits:
23 *
24 * "This project uses software developed by Roberto Charreton and Attribute Overload."
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33*/
34#pragma once
36namespace EU {
44 class
45 Vector2 {
46 public:
47 float x;
48 float y;
55 Vector2() : x(0), y(0) {}
56
65 Vector2(float x, float y) : x(x), y(y) {}
66
73 Vector2
74 operator+(const Vector2& other) const {
75 return Vector2(x + other.x, y + other.y);
76 }
77
84 Vector2
85 operator-(const Vector2& other) const {
86 return Vector2(x - other.x, y - other.y);
87 }
88
95 Vector2
96 operator*(float scalar) const {
97 return Vector2(x * scalar, y * scalar);
98 }
99
105 float
106 magnitude() const {
107 return EU::sqrt(x * x + y * y);
108 }
109
115 Vector2
116 normalize() const {
117 float mag = magnitude();
118 if (mag == 0) {
119 return Vector2(0, 0);
120 }
121 return Vector2(x / mag, y / mag);
122 }
123
129 const float* data() const {
130 return &x;
131 }
132 };
133}
134
135
Declara la API de EngineMath dentro del subsistema Utilities.
A 2D vector class.
Definition Vector2.h:45
Vector2 operator+(const Vector2 &other) const
Adds another vector to this vector.
Definition Vector2.h:74
const float * data() const
Returns a pointer to the quaternion's data.
Definition Vector2.h:129
Vector2 normalize() const
Normalizes the vector.
Definition Vector2.h:116
float y
The y-coordinate of the vector.
Definition Vector2.h:48
Vector2 operator*(float scalar) const
Multiplies this vector by a scalar.
Definition Vector2.h:96
float magnitude() const
Calculates the magnitude (length) of the vector.
Definition Vector2.h:106
Vector2()
Default constructor.
Definition Vector2.h:55
float x
The x-coordinate of the vector.
Definition Vector2.h:47
Vector2 operator-(const Vector2 &other) const
Subtracts another vector from this vector.
Definition Vector2.h:85
Vector2(float x, float y)
Parameterized constructor.
Definition Vector2.h:65
Definition Matrix2x2.h:35
float sqrt(float value)
Computes the square root using the Newton-Raphson method.
Definition EngineMath.h:47