Wildvine Engine
Referencia Doxygen del codigo propio de Wildvine Engine.
Cargando...
Buscando...
Nada coincide
Vector3.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 Vector3 {
46 public:
47 float x;
48 float y;
49 float z;
56 Vector3() : x(0), y(0), z(0) {}
57
67 Vector3(float x, float y, float z) : x(x), y(y), z(z) {}
68
75 Vector3 operator+(const Vector3& other) const {
76 return Vector3(x + other.x, y + other.y, z + other.z);
77 }
78
79 // Operador += (para acumuladores de tangentes/bitangentes)
80 Vector3& operator+=(const Vector3& other) {
81 x += other.x; y += other.y; z += other.z;
82 return *this;
83 }
84
91 Vector3 operator-(const Vector3& other) const {
92 return Vector3(x - other.x, y - other.y, z - other.z);
93 }
94
101 Vector3 operator*(float scalar) const {
102 return Vector3(x * scalar, y * scalar, z * scalar);
103 }
104
110 float magnitude() const {
111 return EU::sqrt(x * x + y * y + z * z);
112 }
113
120 float mag = magnitude();
121 if (mag == 0) {
122 return Vector3(0, 0, 0);
123 }
124 return Vector3(x / mag, y / mag, z / mag);
125 }
126
127 void
129 Vector3(0, 0, 0);
130 }
131
132 void
133 one() {
134 Vector3(1,1,1);
135 }
136
137
138 // ---- helpers con tu Vector3 ----
139 float dot(const Vector3& a, const Vector3& b) {
140 return a.x * b.x + a.y * b.y + a.z * b.z;
141 }
142
143 Vector3 cross(const Vector3& a, const Vector3& b) {
144 return Vector3(
145 a.y * b.z - a.z * b.y,
146 a.z * b.x - a.x * b.z,
147 a.x * b.y - a.y * b.x
148 );
149 }
150
151 // Método para obtener un puntero a los datos como un arreglo
152 // @return: Puntero a los componentes del vector
153 float* data() { return &x; }
154 const float* data() const { return &x; }
155 };
156}
157
158
Declara la API de EngineMath dentro del subsistema Utilities.
A 3D vector class.
Definition Vector3.h:45
float x
The x-coordinate of the vector.
Definition Vector3.h:47
Vector3 & operator+=(const Vector3 &other)
Definition Vector3.h:80
void zero()
Definition Vector3.h:128
Vector3(float x, float y, float z)
Parameterized constructor.
Definition Vector3.h:67
Vector3 operator*(float scalar) const
Multiplies this vector by a scalar.
Definition Vector3.h:101
float magnitude() const
Calculates the magnitude (length) of the vector.
Definition Vector3.h:110
float z
The z-coordinate of the vector.
Definition Vector3.h:49
Vector3 operator+(const Vector3 &other) const
Adds another vector to this vector.
Definition Vector3.h:75
const float * data() const
Definition Vector3.h:154
Vector3 operator-(const Vector3 &other) const
Subtracts another vector from this vector.
Definition Vector3.h:91
float dot(const Vector3 &a, const Vector3 &b)
Definition Vector3.h:139
Vector3 normalize() const
Normalizes the vector.
Definition Vector3.h:119
void one()
Definition Vector3.h:133
float * data()
Definition Vector3.h:153
Vector3()
Default constructor.
Definition Vector3.h:56
float y
The y-coordinate of the vector.
Definition Vector3.h:48
Vector3 cross(const Vector3 &a, const Vector3 &b)
Definition Vector3.h:143
Definition Matrix2x2.h:35
float sqrt(float value)
Computes the square root using the Newton-Raphson method.
Definition EngineMath.h:47