Wildvine Engine
Referencia Doxygen del codigo propio de Wildvine Engine.
Cargando...
Buscando...
Nada coincide
Vector4.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
35
37namespace EU {
45 class Vector4 {
46 public:
47 float x;
48 float y;
49 float z;
50 float w;
57 Vector4() : x(0), y(0), z(0), w(0) {}
58
69 Vector4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
70
77 Vector4 operator+(const Vector4& other) const {
78 return Vector4(x + other.x, y + other.y, z + other.z, w + other.w);
79 }
80
87 Vector4 operator-(const Vector4& other) const {
88 return Vector4(x - other.x, y - other.y, z - other.z, w - other.w);
89 }
90
97 Vector4 operator*(float scalar) const {
98 return Vector4(x * scalar, y * scalar, z * scalar, w * scalar);
99 }
100
106 float magnitude() const {
107 return EU::sqrt(x * x + y * y + z * z + w * w);
108 }
109
116 float mag = magnitude();
117 if (mag == 0) {
118 return Vector4(0, 0, 0, 0);
119 }
120 return Vector4(x / mag, y / mag, z / mag, w / mag);
121 }
122
128 const float* data() const {
129 return &x;
130 }
131 };
132}
133
134
Declara la API de EngineMath dentro del subsistema Utilities.
A 4D vector class.
Definition Vector4.h:45
float magnitude() const
Calculates the magnitude (length) of the vector.
Definition Vector4.h:106
Vector4(float x, float y, float z, float w)
Parameterized constructor.
Definition Vector4.h:69
Vector4()
Default constructor.
Definition Vector4.h:57
Vector4 operator*(float scalar) const
Multiplies this vector by a scalar.
Definition Vector4.h:97
Vector4 operator-(const Vector4 &other) const
Subtracts another vector from this vector.
Definition Vector4.h:87
const float * data() const
Returns a pointer to the quaternion's data.
Definition Vector4.h:128
float w
The w-coordinate of the vector.
Definition Vector4.h:50
float z
The z-coordinate of the vector.
Definition Vector4.h:49
float x
The x-coordinate of the vector.
Definition Vector4.h:47
float y
The y-coordinate of the vector.
Definition Vector4.h:48
Vector4 operator+(const Vector4 &other) const
Adds another vector to this vector.
Definition Vector4.h:77
Vector4 normalize() const
Normalizes the vector.
Definition Vector4.h:115
Definition Matrix2x2.h:35
float sqrt(float value)
Computes the square root using the Newton-Raphson method.
Definition EngineMath.h:47