Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
/**************************************************************************/
|
|
|
|
/* vector4.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef VECTOR4_H
|
|
|
|
#define VECTOR4_H
|
|
|
|
|
2022-10-06 11:00:15 +08:00
|
|
|
#include "core/error/error_macros.h"
|
2024-04-08 22:51:34 +08:00
|
|
|
#include "core/math/math_defs.h"
|
|
|
|
#include "core/typedefs.h"
|
2022-10-06 11:00:15 +08:00
|
|
|
|
|
|
|
class String;
|
2024-04-08 22:51:34 +08:00
|
|
|
struct Vector4i;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
|
2024-04-12 23:02:26 +08:00
|
|
|
struct [[nodiscard]] Vector4 {
|
2022-09-20 06:50:35 +08:00
|
|
|
static const int AXIS_COUNT = 4;
|
|
|
|
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
enum Axis {
|
|
|
|
AXIS_X,
|
|
|
|
AXIS_Y,
|
|
|
|
AXIS_Z,
|
|
|
|
AXIS_W,
|
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
real_t x;
|
|
|
|
real_t y;
|
|
|
|
real_t z;
|
|
|
|
real_t w;
|
|
|
|
};
|
2024-09-26 20:02:00 +08:00
|
|
|
real_t coord[4] = { 0, 0, 0, 0 };
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
};
|
|
|
|
|
2024-02-18 06:24:59 +08:00
|
|
|
_FORCE_INLINE_ real_t &operator[](int p_axis) {
|
2022-07-26 04:49:18 +08:00
|
|
|
DEV_ASSERT((unsigned int)p_axis < 4);
|
2024-09-26 20:02:00 +08:00
|
|
|
return coord[p_axis];
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
}
|
2024-02-18 06:24:59 +08:00
|
|
|
_FORCE_INLINE_ const real_t &operator[](int p_axis) const {
|
2022-07-26 04:49:18 +08:00
|
|
|
DEV_ASSERT((unsigned int)p_axis < 4);
|
2024-09-26 20:02:00 +08:00
|
|
|
return coord[p_axis];
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
}
|
2022-08-07 18:25:05 +08:00
|
|
|
|
|
|
|
Vector4::Axis min_axis_index() const;
|
|
|
|
Vector4::Axis max_axis_index() const;
|
|
|
|
|
2023-01-30 00:45:22 +08:00
|
|
|
Vector4 min(const Vector4 &p_vector4) const {
|
|
|
|
return Vector4(MIN(x, p_vector4.x), MIN(y, p_vector4.y), MIN(z, p_vector4.z), MIN(w, p_vector4.w));
|
|
|
|
}
|
|
|
|
|
2024-03-03 21:37:52 +08:00
|
|
|
Vector4 minf(real_t p_scalar) const {
|
|
|
|
return Vector4(MIN(x, p_scalar), MIN(y, p_scalar), MIN(z, p_scalar), MIN(w, p_scalar));
|
|
|
|
}
|
|
|
|
|
2023-01-30 00:45:22 +08:00
|
|
|
Vector4 max(const Vector4 &p_vector4) const {
|
|
|
|
return Vector4(MAX(x, p_vector4.x), MAX(y, p_vector4.y), MAX(z, p_vector4.z), MAX(w, p_vector4.w));
|
|
|
|
}
|
|
|
|
|
2024-03-03 21:37:52 +08:00
|
|
|
Vector4 maxf(real_t p_scalar) const {
|
|
|
|
return Vector4(MAX(x, p_scalar), MAX(y, p_scalar), MAX(z, p_scalar), MAX(w, p_scalar));
|
|
|
|
}
|
|
|
|
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
_FORCE_INLINE_ real_t length_squared() const;
|
|
|
|
bool is_equal_approx(const Vector4 &p_vec4) const;
|
2022-09-02 08:32:33 +08:00
|
|
|
bool is_zero_approx() const;
|
2022-08-11 16:12:27 +08:00
|
|
|
bool is_finite() const;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
real_t length() const;
|
|
|
|
void normalize();
|
|
|
|
Vector4 normalized() const;
|
|
|
|
bool is_normalized() const;
|
2022-07-26 04:49:18 +08:00
|
|
|
|
2022-08-07 18:25:05 +08:00
|
|
|
real_t distance_to(const Vector4 &p_to) const;
|
2022-08-08 23:05:55 +08:00
|
|
|
real_t distance_squared_to(const Vector4 &p_to) const;
|
2022-08-07 18:25:05 +08:00
|
|
|
Vector4 direction_to(const Vector4 &p_to) const;
|
|
|
|
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
Vector4 abs() const;
|
|
|
|
Vector4 sign() const;
|
2022-07-26 04:49:18 +08:00
|
|
|
Vector4 floor() const;
|
|
|
|
Vector4 ceil() const;
|
|
|
|
Vector4 round() const;
|
2024-02-18 06:24:59 +08:00
|
|
|
Vector4 lerp(const Vector4 &p_to, real_t p_weight) const;
|
|
|
|
Vector4 cubic_interpolate(const Vector4 &p_b, const Vector4 &p_pre_a, const Vector4 &p_post_b, real_t p_weight) const;
|
|
|
|
Vector4 cubic_interpolate_in_time(const Vector4 &p_b, const Vector4 &p_pre_a, const Vector4 &p_post_b, real_t p_weight, real_t p_b_t, real_t p_pre_a_t, real_t p_post_b_t) const;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
|
2024-02-18 06:24:59 +08:00
|
|
|
Vector4 posmod(real_t p_mod) const;
|
2022-08-07 18:25:05 +08:00
|
|
|
Vector4 posmodv(const Vector4 &p_modv) const;
|
|
|
|
void snap(const Vector4 &p_step);
|
2024-03-03 21:37:52 +08:00
|
|
|
void snapf(real_t p_step);
|
2022-08-07 18:25:05 +08:00
|
|
|
Vector4 snapped(const Vector4 &p_step) const;
|
2024-03-03 21:37:52 +08:00
|
|
|
Vector4 snappedf(real_t p_step) const;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
Vector4 clamp(const Vector4 &p_min, const Vector4 &p_max) const;
|
2024-03-03 21:37:52 +08:00
|
|
|
Vector4 clampf(real_t p_min, real_t p_max) const;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
|
|
|
|
Vector4 inverse() const;
|
|
|
|
_FORCE_INLINE_ real_t dot(const Vector4 &p_vec4) const;
|
|
|
|
|
|
|
|
_FORCE_INLINE_ void operator+=(const Vector4 &p_vec4);
|
|
|
|
_FORCE_INLINE_ void operator-=(const Vector4 &p_vec4);
|
|
|
|
_FORCE_INLINE_ void operator*=(const Vector4 &p_vec4);
|
|
|
|
_FORCE_INLINE_ void operator/=(const Vector4 &p_vec4);
|
2024-02-18 06:24:59 +08:00
|
|
|
_FORCE_INLINE_ void operator*=(real_t p_s);
|
|
|
|
_FORCE_INLINE_ void operator/=(real_t p_s);
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
_FORCE_INLINE_ Vector4 operator+(const Vector4 &p_vec4) const;
|
|
|
|
_FORCE_INLINE_ Vector4 operator-(const Vector4 &p_vec4) const;
|
|
|
|
_FORCE_INLINE_ Vector4 operator*(const Vector4 &p_vec4) const;
|
|
|
|
_FORCE_INLINE_ Vector4 operator/(const Vector4 &p_vec4) const;
|
|
|
|
_FORCE_INLINE_ Vector4 operator-() const;
|
2024-02-18 06:24:59 +08:00
|
|
|
_FORCE_INLINE_ Vector4 operator*(real_t p_s) const;
|
|
|
|
_FORCE_INLINE_ Vector4 operator/(real_t p_s) const;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
|
|
|
|
_FORCE_INLINE_ bool operator==(const Vector4 &p_vec4) const;
|
|
|
|
_FORCE_INLINE_ bool operator!=(const Vector4 &p_vec4) const;
|
|
|
|
_FORCE_INLINE_ bool operator>(const Vector4 &p_vec4) const;
|
|
|
|
_FORCE_INLINE_ bool operator<(const Vector4 &p_vec4) const;
|
|
|
|
_FORCE_INLINE_ bool operator>=(const Vector4 &p_vec4) const;
|
|
|
|
_FORCE_INLINE_ bool operator<=(const Vector4 &p_vec4) const;
|
|
|
|
|
|
|
|
operator String() const;
|
2024-04-08 22:51:34 +08:00
|
|
|
operator Vector4i() const;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
|
|
|
|
_FORCE_INLINE_ Vector4() {}
|
2024-04-08 22:51:34 +08:00
|
|
|
_FORCE_INLINE_ Vector4(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
|
|
|
|
x = p_x;
|
|
|
|
y = p_y;
|
|
|
|
z = p_z;
|
|
|
|
w = p_w;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
real_t Vector4::dot(const Vector4 &p_vec4) const {
|
|
|
|
return x * p_vec4.x + y * p_vec4.y + z * p_vec4.z + w * p_vec4.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
real_t Vector4::length_squared() const {
|
|
|
|
return dot(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Vector4::operator+=(const Vector4 &p_vec4) {
|
|
|
|
x += p_vec4.x;
|
|
|
|
y += p_vec4.y;
|
|
|
|
z += p_vec4.z;
|
|
|
|
w += p_vec4.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Vector4::operator-=(const Vector4 &p_vec4) {
|
|
|
|
x -= p_vec4.x;
|
|
|
|
y -= p_vec4.y;
|
|
|
|
z -= p_vec4.z;
|
|
|
|
w -= p_vec4.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Vector4::operator*=(const Vector4 &p_vec4) {
|
|
|
|
x *= p_vec4.x;
|
|
|
|
y *= p_vec4.y;
|
|
|
|
z *= p_vec4.z;
|
|
|
|
w *= p_vec4.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Vector4::operator/=(const Vector4 &p_vec4) {
|
|
|
|
x /= p_vec4.x;
|
|
|
|
y /= p_vec4.y;
|
|
|
|
z /= p_vec4.z;
|
|
|
|
w /= p_vec4.w;
|
|
|
|
}
|
2024-02-18 06:24:59 +08:00
|
|
|
void Vector4::operator*=(real_t p_s) {
|
|
|
|
x *= p_s;
|
|
|
|
y *= p_s;
|
|
|
|
z *= p_s;
|
|
|
|
w *= p_s;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
}
|
|
|
|
|
2024-02-18 06:24:59 +08:00
|
|
|
void Vector4::operator/=(real_t p_s) {
|
|
|
|
*this *= 1.0f / p_s;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector4 Vector4::operator+(const Vector4 &p_vec4) const {
|
|
|
|
return Vector4(x + p_vec4.x, y + p_vec4.y, z + p_vec4.z, w + p_vec4.w);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector4 Vector4::operator-(const Vector4 &p_vec4) const {
|
|
|
|
return Vector4(x - p_vec4.x, y - p_vec4.y, z - p_vec4.z, w - p_vec4.w);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector4 Vector4::operator*(const Vector4 &p_vec4) const {
|
|
|
|
return Vector4(x * p_vec4.x, y * p_vec4.y, z * p_vec4.z, w * p_vec4.w);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector4 Vector4::operator/(const Vector4 &p_vec4) const {
|
|
|
|
return Vector4(x / p_vec4.x, y / p_vec4.y, z / p_vec4.z, w / p_vec4.w);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector4 Vector4::operator-() const {
|
2022-08-07 18:25:05 +08:00
|
|
|
return Vector4(-x, -y, -z, -w);
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
}
|
|
|
|
|
2024-02-18 06:24:59 +08:00
|
|
|
Vector4 Vector4::operator*(real_t p_s) const {
|
|
|
|
return Vector4(x * p_s, y * p_s, z * p_s, w * p_s);
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
}
|
|
|
|
|
2024-02-18 06:24:59 +08:00
|
|
|
Vector4 Vector4::operator/(real_t p_s) const {
|
|
|
|
return *this * (1.0f / p_s);
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Vector4::operator==(const Vector4 &p_vec4) const {
|
|
|
|
return x == p_vec4.x && y == p_vec4.y && z == p_vec4.z && w == p_vec4.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Vector4::operator!=(const Vector4 &p_vec4) const {
|
|
|
|
return x != p_vec4.x || y != p_vec4.y || z != p_vec4.z || w != p_vec4.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Vector4::operator<(const Vector4 &p_v) const {
|
|
|
|
if (x == p_v.x) {
|
|
|
|
if (y == p_v.y) {
|
|
|
|
if (z == p_v.z) {
|
|
|
|
return w < p_v.w;
|
|
|
|
}
|
|
|
|
return z < p_v.z;
|
|
|
|
}
|
|
|
|
return y < p_v.y;
|
|
|
|
}
|
|
|
|
return x < p_v.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Vector4::operator>(const Vector4 &p_v) const {
|
|
|
|
if (x == p_v.x) {
|
|
|
|
if (y == p_v.y) {
|
|
|
|
if (z == p_v.z) {
|
|
|
|
return w > p_v.w;
|
|
|
|
}
|
|
|
|
return z > p_v.z;
|
|
|
|
}
|
|
|
|
return y > p_v.y;
|
|
|
|
}
|
|
|
|
return x > p_v.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Vector4::operator<=(const Vector4 &p_v) const {
|
|
|
|
if (x == p_v.x) {
|
|
|
|
if (y == p_v.y) {
|
|
|
|
if (z == p_v.z) {
|
|
|
|
return w <= p_v.w;
|
|
|
|
}
|
|
|
|
return z < p_v.z;
|
|
|
|
}
|
|
|
|
return y < p_v.y;
|
|
|
|
}
|
|
|
|
return x < p_v.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Vector4::operator>=(const Vector4 &p_v) const {
|
|
|
|
if (x == p_v.x) {
|
|
|
|
if (y == p_v.y) {
|
|
|
|
if (z == p_v.z) {
|
|
|
|
return w >= p_v.w;
|
|
|
|
}
|
|
|
|
return z > p_v.z;
|
|
|
|
}
|
|
|
|
return y > p_v.y;
|
|
|
|
}
|
|
|
|
return x > p_v.x;
|
|
|
|
}
|
|
|
|
|
2024-02-18 06:24:59 +08:00
|
|
|
_FORCE_INLINE_ Vector4 operator*(float p_scalar, const Vector4 &p_vec) {
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
return p_vec * p_scalar;
|
|
|
|
}
|
|
|
|
|
2024-02-18 06:24:59 +08:00
|
|
|
_FORCE_INLINE_ Vector4 operator*(double p_scalar, const Vector4 &p_vec) {
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
return p_vec * p_scalar;
|
|
|
|
}
|
|
|
|
|
2024-02-18 06:24:59 +08:00
|
|
|
_FORCE_INLINE_ Vector4 operator*(int32_t p_scalar, const Vector4 &p_vec) {
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
return p_vec * p_scalar;
|
|
|
|
}
|
|
|
|
|
2024-02-18 06:24:59 +08:00
|
|
|
_FORCE_INLINE_ Vector4 operator*(int64_t p_scalar, const Vector4 &p_vec) {
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
return p_vec * p_scalar;
|
|
|
|
}
|
2022-07-24 05:41:51 +08:00
|
|
|
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
#endif // VECTOR4_H
|