summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2022-07-20 01:11:13 +0200
committerJuan Linietsky <reduzio@gmail.com>2022-07-23 14:00:01 +0200
commit455c06ecd466424cdf1b444a7c289b322390e795 (patch)
tree50c3f14dddba5e7dcd938450d360af2847be8e61 /core
parentfe929d4787b2b11390891fb03da1dda78b18eb65 (diff)
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.
Diffstat (limited to 'core')
-rw-r--r--core/core_constants.cpp3
-rw-r--r--core/extension/extension_api_dump.cpp14
-rw-r--r--core/extension/gdnative_interface.cpp12
-rw-r--r--core/extension/gdnative_interface.h3
-rw-r--r--core/io/marshalls.cpp104
-rw-r--r--core/io/resource_format_binary.cpp78
-rw-r--r--core/math/delaunay_3d.h4
-rw-r--r--core/math/math_fieldwise.cpp30
-rw-r--r--core/math/projection.cpp (renamed from core/math/camera_matrix.cpp)255
-rw-r--r--core/math/projection.h (renamed from core/math/camera_matrix.h)53
-rw-r--r--core/math/vector4.cpp102
-rw-r--r--core/math/vector4.h275
-rw-r--r--core/math/vector4i.cpp91
-rw-r--r--core/math/vector4i.h338
-rw-r--r--core/object/script_language.cpp3
-rw-r--r--core/templates/hashfuncs.h16
-rw-r--r--core/variant/binder_common.h3
-rw-r--r--core/variant/method_ptrcall.h3
-rw-r--r--core/variant/type_info.h3
-rw-r--r--core/variant/variant.cpp270
-rw-r--r--core/variant/variant.h16
-rw-r--r--core/variant/variant_call.cpp104
-rw-r--r--core/variant/variant_construct.cpp15
-rw-r--r--core/variant/variant_construct.h3
-rw-r--r--core/variant/variant_internal.h89
-rw-r--r--core/variant/variant_op.cpp131
-rw-r--r--core/variant/variant_op.h48
-rw-r--r--core/variant/variant_parser.cpp61
-rw-r--r--core/variant/variant_setget.cpp17
-rw-r--r--core/variant/variant_setget.h15
-rw-r--r--core/variant/variant_utility.cpp12
31 files changed, 2113 insertions, 58 deletions
diff --git a/core/core_constants.cpp b/core/core_constants.cpp
index 1753efad60..4a2d09d2a0 100644
--- a/core/core_constants.cpp
+++ b/core/core_constants.cpp
@@ -681,11 +681,14 @@ void register_global_constants() {
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3", Variant::VECTOR3);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3I", Variant::VECTOR3I);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_TRANSFORM2D", Variant::TRANSFORM2D);
+ BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR4", Variant::VECTOR4);
+ BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR4I", Variant::VECTOR4I);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PLANE", Variant::PLANE);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_QUATERNION", Variant::QUATERNION);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_AABB", Variant::AABB);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_BASIS", Variant::BASIS);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_TRANSFORM3D", Variant::TRANSFORM3D);
+ BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PROJECTION", Variant::PROJECTION);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_COLOR", Variant::COLOR);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_STRING_NAME", Variant::STRING_NAME);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_NODE_PATH", Variant::NODE_PATH);
diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp
index ecdb1e26dc..867b1fc637 100644
--- a/core/extension/extension_api_dump.cpp
+++ b/core/extension/extension_api_dump.cpp
@@ -131,11 +131,14 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
{ Variant::VECTOR3, vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) },
{ Variant::VECTOR3I, 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t) },
{ Variant::TRANSFORM2D, 6 * sizeof(float), 6 * sizeof(float), 6 * sizeof(double), 6 * sizeof(double) },
+ { Variant::VECTOR4, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) },
+ { Variant::VECTOR4I, 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t) },
{ Variant::PLANE, (vec3_elems + 1) * sizeof(float), (vec3_elems + 1) * sizeof(float), (vec3_elems + 1) * sizeof(double), (vec3_elems + 1) * sizeof(double) },
{ Variant::QUATERNION, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) },
{ Variant::AABB, (vec3_elems * 2) * sizeof(float), (vec3_elems * 2) * sizeof(float), (vec3_elems * 2) * sizeof(double), (vec3_elems * 2) * sizeof(double) },
{ Variant::BASIS, (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(double), (vec3_elems * 3) * sizeof(double) },
{ Variant::TRANSFORM3D, (vec3_elems * 4) * sizeof(float), (vec3_elems * 4) * sizeof(float), (vec3_elems * 4) * sizeof(double), (vec3_elems * 4) * sizeof(double) },
+ { Variant::PROJECTION, 4 * 4 * sizeof(float), 4 * 4 * sizeof(float), 4 * 4 * sizeof(double), 4 * 4 * sizeof(double) },
{ Variant::COLOR, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(float) },
{ Variant::STRING_NAME, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
{ Variant::NODE_PATH, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
@@ -169,11 +172,14 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
static_assert(type_size_array[Variant::VECTOR3][sizeof(void *)] == sizeof(Vector3), "Size of Vector3 mismatch");
static_assert(type_size_array[Variant::VECTOR3I][sizeof(void *)] == sizeof(Vector3i), "Size of Vector3i mismatch");
static_assert(type_size_array[Variant::TRANSFORM2D][sizeof(void *)] == sizeof(Transform2D), "Size of Transform2D mismatch");
+ static_assert(type_size_array[Variant::VECTOR4][sizeof(void *)] == sizeof(Vector4), "Size of Vector4 mismatch");
+ static_assert(type_size_array[Variant::VECTOR4I][sizeof(void *)] == sizeof(Vector4i), "Size of Vector4i mismatch");
static_assert(type_size_array[Variant::PLANE][sizeof(void *)] == sizeof(Plane), "Size of Plane mismatch");
static_assert(type_size_array[Variant::QUATERNION][sizeof(void *)] == sizeof(Quaternion), "Size of Quaternion mismatch");
static_assert(type_size_array[Variant::AABB][sizeof(void *)] == sizeof(AABB), "Size of AABB mismatch");
static_assert(type_size_array[Variant::BASIS][sizeof(void *)] == sizeof(Basis), "Size of Basis mismatch");
static_assert(type_size_array[Variant::TRANSFORM3D][sizeof(void *)] == sizeof(Transform3D), "Size of Transform3D mismatch");
+ static_assert(type_size_array[Variant::PROJECTION][sizeof(void *)] == sizeof(Projection), "Size of Projection mismatch");
static_assert(type_size_array[Variant::COLOR][sizeof(void *)] == sizeof(Color), "Size of Color mismatch");
static_assert(type_size_array[Variant::STRING_NAME][sizeof(void *)] == sizeof(StringName), "Size of StringName mismatch");
static_assert(type_size_array[Variant::NODE_PATH][sizeof(void *)] == sizeof(NodePath), "Size of NodePath mismatch");
@@ -256,6 +262,14 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
{ Variant::TRANSFORM2D, "x", 0, 0, 0, 0 },
{ Variant::TRANSFORM2D, "y", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) },
{ Variant::TRANSFORM2D, "origin", 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) },
+ { Variant::VECTOR4, "x", 0, 0, 0, 0 },
+ { Variant::VECTOR4, "y", sizeof(float), sizeof(float), sizeof(double), sizeof(double) },
+ { Variant::VECTOR4, "z", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) },
+ { Variant::VECTOR4, "w", 3 * sizeof(float), 3 * sizeof(float), 3 * sizeof(double), 3 * sizeof(double) },
+ { Variant::VECTOR4I, "x", 0, 0, 0, 0 },
+ { Variant::VECTOR4I, "y", sizeof(int32_t), sizeof(int32_t), sizeof(int32_t), sizeof(int32_t) },
+ { Variant::VECTOR4I, "z", 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t) },
+ { Variant::VECTOR4I, "w", 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t) },
{ Variant::PLANE, "normal", 0, 0, 0, 0 },
{ Variant::PLANE, "d", vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) },
{ Variant::QUATERNION, "x", 0, 0, 0, 0 },
diff --git a/core/extension/gdnative_interface.cpp b/core/extension/gdnative_interface.cpp
index 58103e3af3..ef0b590030 100644
--- a/core/extension/gdnative_interface.cpp
+++ b/core/extension/gdnative_interface.cpp
@@ -344,6 +344,10 @@ static GDNativeVariantFromTypeConstructorFunc gdnative_get_variant_from_type_con
return VariantTypeConstructor<Vector3i>::variant_from_type;
case GDNATIVE_VARIANT_TYPE_TRANSFORM2D:
return VariantTypeConstructor<Transform2D>::variant_from_type;
+ case GDNATIVE_VARIANT_TYPE_VECTOR4:
+ return VariantTypeConstructor<Vector4>::variant_from_type;
+ case GDNATIVE_VARIANT_TYPE_VECTOR4I:
+ return VariantTypeConstructor<Vector4i>::variant_from_type;
case GDNATIVE_VARIANT_TYPE_PLANE:
return VariantTypeConstructor<Plane>::variant_from_type;
case GDNATIVE_VARIANT_TYPE_QUATERNION:
@@ -354,6 +358,8 @@ static GDNativeVariantFromTypeConstructorFunc gdnative_get_variant_from_type_con
return VariantTypeConstructor<Basis>::variant_from_type;
case GDNATIVE_VARIANT_TYPE_TRANSFORM3D:
return VariantTypeConstructor<Transform3D>::variant_from_type;
+ case GDNATIVE_VARIANT_TYPE_PROJECTION:
+ return VariantTypeConstructor<Projection>::variant_from_type;
case GDNATIVE_VARIANT_TYPE_COLOR:
return VariantTypeConstructor<Color>::variant_from_type;
case GDNATIVE_VARIANT_TYPE_STRING_NAME:
@@ -421,6 +427,10 @@ static GDNativeTypeFromVariantConstructorFunc gdnative_get_type_from_variant_con
return VariantTypeConstructor<Vector3i>::type_from_variant;
case GDNATIVE_VARIANT_TYPE_TRANSFORM2D:
return VariantTypeConstructor<Transform2D>::type_from_variant;
+ case GDNATIVE_VARIANT_TYPE_VECTOR4:
+ return VariantTypeConstructor<Vector4>::type_from_variant;
+ case GDNATIVE_VARIANT_TYPE_VECTOR4I:
+ return VariantTypeConstructor<Vector4i>::type_from_variant;
case GDNATIVE_VARIANT_TYPE_PLANE:
return VariantTypeConstructor<Plane>::type_from_variant;
case GDNATIVE_VARIANT_TYPE_QUATERNION:
@@ -431,6 +441,8 @@ static GDNativeTypeFromVariantConstructorFunc gdnative_get_type_from_variant_con
return VariantTypeConstructor<Basis>::type_from_variant;
case GDNATIVE_VARIANT_TYPE_TRANSFORM3D:
return VariantTypeConstructor<Transform3D>::type_from_variant;
+ case GDNATIVE_VARIANT_TYPE_PROJECTION:
+ return VariantTypeConstructor<Projection>::type_from_variant;
case GDNATIVE_VARIANT_TYPE_COLOR:
return VariantTypeConstructor<Color>::type_from_variant;
case GDNATIVE_VARIANT_TYPE_STRING_NAME:
diff --git a/core/extension/gdnative_interface.h b/core/extension/gdnative_interface.h
index f106b805e7..dd86abe053 100644
--- a/core/extension/gdnative_interface.h
+++ b/core/extension/gdnative_interface.h
@@ -67,11 +67,14 @@ typedef enum {
GDNATIVE_VARIANT_TYPE_VECTOR3,
GDNATIVE_VARIANT_TYPE_VECTOR3I,
GDNATIVE_VARIANT_TYPE_TRANSFORM2D,
+ GDNATIVE_VARIANT_TYPE_VECTOR4,
+ GDNATIVE_VARIANT_TYPE_VECTOR4I,
GDNATIVE_VARIANT_TYPE_PLANE,
GDNATIVE_VARIANT_TYPE_QUATERNION,
GDNATIVE_VARIANT_TYPE_AABB,
GDNATIVE_VARIANT_TYPE_BASIS,
GDNATIVE_VARIANT_TYPE_TRANSFORM3D,
+ GDNATIVE_VARIANT_TYPE_PROJECTION,
/* misc types */
GDNATIVE_VARIANT_TYPE_COLOR,
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 8ee19f274e..2f69c10218 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -285,6 +285,46 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
}
} break;
+ case Variant::VECTOR4: {
+ Vector4 val;
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 4, ERR_INVALID_DATA);
+ val.x = decode_double(&buf[0]);
+ val.y = decode_double(&buf[sizeof(double)]);
+ val.z = decode_double(&buf[sizeof(double) * 2]);
+ val.w = decode_double(&buf[sizeof(double) * 3]);
+
+ if (r_len) {
+ (*r_len) += sizeof(double) * 4;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 4, ERR_INVALID_DATA);
+ val.x = decode_float(&buf[0]);
+ val.y = decode_float(&buf[sizeof(float)]);
+ val.z = decode_float(&buf[sizeof(float) * 2]);
+ val.w = decode_float(&buf[sizeof(float) * 3]);
+
+ if (r_len) {
+ (*r_len) += sizeof(float) * 4;
+ }
+ }
+ r_variant = val;
+
+ } break;
+ case Variant::VECTOR4I: {
+ ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
+ Vector4i val;
+ val.x = decode_uint32(&buf[0]);
+ val.y = decode_uint32(&buf[4]);
+ val.z = decode_uint32(&buf[8]);
+ val.w = decode_uint32(&buf[12]);
+ r_variant = val;
+
+ if (r_len) {
+ (*r_len) += 4 * 4;
+ }
+
+ } break;
case Variant::TRANSFORM2D: {
Transform2D val;
if (type & ENCODE_FLAG_64) {
@@ -457,6 +497,33 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = val;
} break;
+ case Variant::PROJECTION: {
+ Projection val;
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 16, ERR_INVALID_DATA);
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ val.matrix[i][j] = decode_double(&buf[(i * 4 + j) * sizeof(double)]);
+ }
+ }
+ if (r_len) {
+ (*r_len) += sizeof(double) * 16;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 62, ERR_INVALID_DATA);
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ val.matrix[i][j] = decode_float(&buf[(i * 4 + j) * sizeof(float)]);
+ }
+ }
+
+ if (r_len) {
+ (*r_len) += sizeof(float) * 16;
+ }
+ }
+ r_variant = val;
+
+ } break;
// misc types
case Variant::COLOR: {
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
@@ -1286,6 +1353,30 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 6 * sizeof(real_t);
} break;
+ case Variant::VECTOR4: {
+ if (buf) {
+ Vector4 v4 = p_variant;
+ encode_real(v4.x, &buf[0]);
+ encode_real(v4.y, &buf[sizeof(real_t)]);
+ encode_real(v4.z, &buf[sizeof(real_t) * 2]);
+ encode_real(v4.w, &buf[sizeof(real_t) * 3]);
+ }
+
+ r_len += 4 * sizeof(real_t);
+
+ } break;
+ case Variant::VECTOR4I: {
+ if (buf) {
+ Vector4i v4 = p_variant;
+ encode_uint32(v4.x, &buf[0]);
+ encode_uint32(v4.y, &buf[4]);
+ encode_uint32(v4.z, &buf[8]);
+ encode_uint32(v4.w, &buf[12]);
+ }
+
+ r_len += 4 * 4;
+
+ } break;
case Variant::PLANE: {
if (buf) {
Plane p = p_variant;
@@ -1354,6 +1445,19 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 12 * sizeof(real_t);
} break;
+ case Variant::PROJECTION: {
+ if (buf) {
+ Projection val = p_variant;
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ memcpy(&buf[(i * 4 + j) * sizeof(real_t)], &val.matrix[i][j], sizeof(real_t));
+ }
+ }
+ }
+
+ r_len += 16 * sizeof(real_t);
+
+ } break;
// misc types
case Variant::COLOR: {
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 0f4bc1e19c..016302c653 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -81,6 +81,9 @@ enum {
VARIANT_VECTOR3I = 47,
VARIANT_PACKED_INT64_ARRAY = 48,
VARIANT_PACKED_FLOAT64_ARRAY = 49,
+ VARIANT_VECTOR4 = 50,
+ VARIANT_VECTOR4I = 51,
+ VARIANT_PROJECTION = 52,
OBJECT_EMPTY = 0,
OBJECT_EXTERNAL_RESOURCE = 1,
OBJECT_INTERNAL_RESOURCE = 2,
@@ -237,6 +240,22 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
v.z = f->get_32();
r_v = v;
} break;
+ case VARIANT_VECTOR4: {
+ Vector4 v;
+ v.x = f->get_real();
+ v.y = f->get_real();
+ v.z = f->get_real();
+ v.w = f->get_real();
+ r_v = v;
+ } break;
+ case VARIANT_VECTOR4I: {
+ Vector4i v;
+ v.x = f->get_32();
+ v.y = f->get_32();
+ v.z = f->get_32();
+ v.w = f->get_32();
+ r_v = v;
+ } break;
case VARIANT_PLANE: {
Plane v;
v.normal.x = f->get_real();
@@ -306,6 +325,26 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
v.origin.z = f->get_real();
r_v = v;
} break;
+ case VARIANT_PROJECTION: {
+ Projection v;
+ v.matrix[0].x = f->get_real();
+ v.matrix[0].y = f->get_real();
+ v.matrix[0].z = f->get_real();
+ v.matrix[0].w = f->get_real();
+ v.matrix[1].x = f->get_real();
+ v.matrix[1].y = f->get_real();
+ v.matrix[1].z = f->get_real();
+ v.matrix[1].w = f->get_real();
+ v.matrix[2].x = f->get_real();
+ v.matrix[2].y = f->get_real();
+ v.matrix[2].z = f->get_real();
+ v.matrix[2].w = f->get_real();
+ v.matrix[3].x = f->get_real();
+ v.matrix[3].y = f->get_real();
+ v.matrix[3].z = f->get_real();
+ v.matrix[3].w = f->get_real();
+ r_v = v;
+ } break;
case VARIANT_COLOR: {
Color v; // Colors should always be in single-precision.
v.r = f->get_float();
@@ -1499,6 +1538,24 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const V
f->store_32(val.z);
} break;
+ case Variant::VECTOR4: {
+ f->store_32(VARIANT_VECTOR4);
+ Vector4 val = p_property;
+ f->store_real(val.x);
+ f->store_real(val.y);
+ f->store_real(val.z);
+ f->store_real(val.w);
+
+ } break;
+ case Variant::VECTOR4I: {
+ f->store_32(VARIANT_VECTOR4I);
+ Vector4i val = p_property;
+ f->store_32(val.x);
+ f->store_32(val.y);
+ f->store_32(val.z);
+ f->store_32(val.w);
+
+ } break;
case Variant::PLANE: {
f->store_32(VARIANT_PLANE);
Plane val = p_property;
@@ -1570,6 +1627,27 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const V
f->store_real(val.origin.z);
} break;
+ case Variant::PROJECTION: {
+ f->store_32(VARIANT_PROJECTION);
+ Projection val = p_property;
+ f->store_real(val.matrix[0].x);
+ f->store_real(val.matrix[0].y);
+ f->store_real(val.matrix[0].z);
+ f->store_real(val.matrix[0].w);
+ f->store_real(val.matrix[1].x);
+ f->store_real(val.matrix[1].y);
+ f->store_real(val.matrix[1].z);
+ f->store_real(val.matrix[1].w);
+ f->store_real(val.matrix[2].x);
+ f->store_real(val.matrix[2].y);
+ f->store_real(val.matrix[2].z);
+ f->store_real(val.matrix[2].w);
+ f->store_real(val.matrix[3].x);
+ f->store_real(val.matrix[3].y);
+ f->store_real(val.matrix[3].z);
+ f->store_real(val.matrix[3].w);
+
+ } break;
case Variant::COLOR: {
f->store_32(VARIANT_COLOR);
Color val = p_property;
diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h
index 4ab00e1f34..898c3c2d91 100644
--- a/core/math/delaunay_3d.h
+++ b/core/math/delaunay_3d.h
@@ -33,7 +33,7 @@
#include "core/io/file_access.h"
#include "core/math/aabb.h"
-#include "core/math/camera_matrix.h"
+#include "core/math/projection.h"
#include "core/math/vector3.h"
#include "core/string/print_string.h"
#include "core/templates/local_vector.h"
@@ -184,7 +184,7 @@ class Delaunay3D {
return true;
}
- CameraMatrix cm;
+ Projection cm;
cm.matrix[0][0] = p_points[p_simplex.points[0]].x;
cm.matrix[0][1] = p_points[p_simplex.points[1]].x;
diff --git a/core/math/math_fieldwise.cpp b/core/math/math_fieldwise.cpp
index 4be4809e3f..208f89f449 100644
--- a/core/math/math_fieldwise.cpp
+++ b/core/math/math_fieldwise.cpp
@@ -76,6 +76,36 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
return target;
}
+ case Variant::VECTOR3I: {
+ SETUP_TYPE(Vector3i)
+
+ /**/ TRY_TRANSFER_FIELD("x", x)
+ else TRY_TRANSFER_FIELD("y", y)
+ else TRY_TRANSFER_FIELD("z", z)
+
+ return target;
+ }
+ case Variant::VECTOR4: {
+ SETUP_TYPE(Vector4)
+
+ /**/ TRY_TRANSFER_FIELD("x", x)
+ else TRY_TRANSFER_FIELD("y", y)
+ else TRY_TRANSFER_FIELD("z", z)
+ else TRY_TRANSFER_FIELD("w", w)
+
+ return target;
+ }
+ case Variant::VECTOR4I: {
+ SETUP_TYPE(Vector4i)
+
+ /**/ TRY_TRANSFER_FIELD("x", x)
+ else TRY_TRANSFER_FIELD("y", y)
+ else TRY_TRANSFER_FIELD("z", z)
+ else TRY_TRANSFER_FIELD("w", w)
+
+ return target;
+ }
+
case Variant::PLANE: {
SETUP_TYPE(Plane)
diff --git a/core/math/camera_matrix.cpp b/core/math/projection.cpp
index 57c53b0adb..edf8bf36cd 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/projection.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* camera_matrix.cpp */
+/* projection.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "camera_matrix.h"
+#include "projection.h"
#include "core/math/aabb.h"
#include "core/math/math_funcs.h"
@@ -37,7 +37,7 @@
#include "core/math/transform_3d.h"
#include "core/string/print_string.h"
-float CameraMatrix::determinant() const {
+float Projection::determinant() const {
return matrix[0][3] * matrix[1][2] * matrix[2][1] * matrix[3][0] - matrix[0][2] * matrix[1][3] * matrix[2][1] * matrix[3][0] -
matrix[0][3] * matrix[1][1] * matrix[2][2] * matrix[3][0] + matrix[0][1] * matrix[1][3] * matrix[2][2] * matrix[3][0] +
matrix[0][2] * matrix[1][1] * matrix[2][3] * matrix[3][0] - matrix[0][1] * matrix[1][2] * matrix[2][3] * matrix[3][0] -
@@ -52,7 +52,7 @@ float CameraMatrix::determinant() const {
matrix[0][1] * matrix[1][0] * matrix[2][2] * matrix[3][3] + matrix[0][0] * matrix[1][1] * matrix[2][2] * matrix[3][3];
}
-void CameraMatrix::set_identity() {
+void Projection::set_identity() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
matrix[i][j] = (i == j) ? 1 : 0;
@@ -60,7 +60,7 @@ void CameraMatrix::set_identity() {
}
}
-void CameraMatrix::set_zero() {
+void Projection::set_zero() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
matrix[i][j] = 0;
@@ -68,7 +68,7 @@ void CameraMatrix::set_zero() {
}
}
-Plane CameraMatrix::xform4(const Plane &p_vec4) const {
+Plane Projection::xform4(const Plane &p_vec4) const {
Plane ret;
ret.normal.x = matrix[0][0] * p_vec4.normal.x + matrix[1][0] * p_vec4.normal.y + matrix[2][0] * p_vec4.normal.z + matrix[3][0] * p_vec4.d;
@@ -78,7 +78,22 @@ Plane CameraMatrix::xform4(const Plane &p_vec4) const {
return ret;
}
-void CameraMatrix::adjust_perspective_znear(real_t p_new_znear) {
+Vector4 Projection::xform(const Vector4 &p_vec4) const {
+ return Vector4(
+ matrix[0][0] * p_vec4.x + matrix[1][0] * p_vec4.y + matrix[2][0] * p_vec4.z + matrix[3][0] * p_vec4.w,
+ matrix[0][1] * p_vec4.x + matrix[1][1] * p_vec4.y + matrix[2][1] * p_vec4.z + matrix[3][1] * p_vec4.w,
+ matrix[0][2] * p_vec4.x + matrix[1][2] * p_vec4.y + matrix[2][2] * p_vec4.z + matrix[3][2] * p_vec4.w,
+ matrix[0][3] * p_vec4.x + matrix[1][3] * p_vec4.y + matrix[2][3] * p_vec4.z + matrix[3][3] * p_vec4.w);
+}
+Vector4 Projection::xform_inv(const Vector4 &p_vec4) const {
+ return Vector4(
+ matrix[0][0] * p_vec4.x + matrix[0][1] * p_vec4.y + matrix[0][2] * p_vec4.z + matrix[0][3] * p_vec4.w,
+ matrix[1][0] * p_vec4.x + matrix[1][1] * p_vec4.y + matrix[1][2] * p_vec4.z + matrix[1][3] * p_vec4.w,
+ matrix[2][0] * p_vec4.x + matrix[2][1] * p_vec4.y + matrix[2][2] * p_vec4.z + matrix[2][3] * p_vec4.w,
+ matrix[3][0] * p_vec4.x + matrix[3][1] * p_vec4.y + matrix[3][2] * p_vec4.z + matrix[3][3] * p_vec4.w);
+}
+
+void Projection::adjust_perspective_znear(real_t p_new_znear) {
real_t zfar = get_z_far();
real_t znear = p_new_znear;
@@ -87,7 +102,154 @@ void CameraMatrix::adjust_perspective_znear(real_t p_new_znear) {
matrix[3][2] = -2 * znear * zfar / deltaZ;
}
-void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) {
+Projection Projection::create_depth_correction(bool p_flip_y) {
+ Projection proj;
+ proj.set_depth_correction(p_flip_y);
+ return proj;
+}
+
+Projection Projection::create_light_atlas_rect(const Rect2 &p_rect) {
+ Projection proj;
+ proj.set_light_atlas_rect(p_rect);
+ return proj;
+}
+
+Projection Projection::create_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) {
+ Projection proj;
+ proj.set_perspective(p_fovy_degrees, p_aspect, p_z_near, p_z_far, p_flip_fov);
+ return proj;
+}
+
+Projection Projection::create_perspective_hmd(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist) {
+ Projection proj;
+ proj.set_perspective(p_fovy_degrees, p_aspect, p_z_near, p_z_far, p_flip_fov, p_eye, p_intraocular_dist, p_convergence_dist);
+ return proj;
+}
+
+Projection Projection::create_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_dist, real_t p_display_width, real_t p_display_to_lens, real_t p_oversample, real_t p_z_near, real_t p_z_far) {
+ Projection proj;
+ proj.set_for_hmd(p_eye, p_aspect, p_intraocular_dist, p_display_width, p_display_to_lens, p_oversample, p_z_near, p_z_far);
+ return proj;
+}
+
+Projection Projection::create_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
+ Projection proj;
+ proj.set_orthogonal(p_left, p_right, p_bottom, p_top, p_zfar, p_zfar);
+ return proj;
+}
+
+Projection Projection::create_orthogonal_aspect(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) {
+ Projection proj;
+ proj.set_orthogonal(p_size, p_aspect, p_znear, p_zfar, p_flip_fov);
+ return proj;
+}
+
+Projection Projection::create_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
+ Projection proj;
+ proj.set_frustum(p_left, p_right, p_bottom, p_top, p_near, p_far);
+ return proj;
+}
+
+Projection Projection::create_frustum_aspect(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov) {
+ Projection proj;
+ proj.set_frustum(p_size, p_aspect, p_offset, p_near, p_far, p_flip_fov);
+ return proj;
+}
+
+Projection Projection::create_fit_aabb(const AABB &p_aabb) {
+ Projection proj;
+ proj.scale_translate_to_fit(p_aabb);
+ return proj;
+}
+
+Projection Projection::perspective_znear_adjusted(real_t p_new_znear) const {
+ Projection proj = *this;
+ proj.adjust_perspective_znear(p_new_znear);
+ return proj;
+}
+
+Plane Projection::get_projection_plane(Planes p_plane) const {
+ const real_t *matrix = (const real_t *)this->matrix;
+
+ switch (p_plane) {
+ case PLANE_NEAR: {
+ Plane new_plane = Plane(matrix[3] + matrix[2],
+ matrix[7] + matrix[6],
+ matrix[11] + matrix[10],
+ matrix[15] + matrix[14]);
+
+ new_plane.normal = -new_plane.normal;
+ new_plane.normalize();
+ return new_plane;
+ } break;
+ case PLANE_FAR: {
+ Plane new_plane = Plane(matrix[3] - matrix[2],
+ matrix[7] - matrix[6],
+ matrix[11] - matrix[10],
+ matrix[15] - matrix[14]);
+
+ new_plane.normal = -new_plane.normal;
+ new_plane.normalize();
+ return new_plane;
+ } break;
+ case PLANE_LEFT: {
+ Plane new_plane = Plane(matrix[3] + matrix[0],
+ matrix[7] + matrix[4],
+ matrix[11] + matrix[8],
+ matrix[15] + matrix[12]);
+
+ new_plane.normal = -new_plane.normal;
+ new_plane.normalize();
+ return new_plane;
+ } break;
+ case PLANE_TOP: {
+ Plane new_plane = Plane(matrix[3] - matrix[1],
+ matrix[7] - matrix[5],
+ matrix[11] - matrix[9],
+ matrix[15] - matrix[13]);
+
+ new_plane.normal = -new_plane.normal;
+ new_plane.normalize();
+ return new_plane;
+ } break;
+ case PLANE_RIGHT: {
+ Plane new_plane = Plane(matrix[3] - matrix[0],
+ matrix[7] - matrix[4],
+ matrix[11] - matrix[8],
+ matrix[15] - matrix[12]);
+
+ new_plane.normal = -new_plane.normal;
+ new_plane.normalize();
+ return new_plane;
+ } break;
+ case PLANE_BOTTOM: {
+ Plane new_plane = Plane(matrix[3] + matrix[1],
+ matrix[7] + matrix[5],
+ matrix[11] + matrix[9],
+ matrix[15] + matrix[13]);
+
+ new_plane.normal = -new_plane.normal;
+ new_plane.normalize();
+ return new_plane;
+ } break;
+ }
+
+ return Plane();
+}
+
+Projection Projection::flipped_y() const {
+ Projection proj = *this;
+ proj.flip_y();
+ return proj;
+}
+
+Projection Projection ::jitter_offseted(const Vector2 &p_offset) const {
+ Projection proj = *this;
+ proj.add_jitter_offset(p_offset);
+ return proj;
+}
+
+void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) {
if (p_flip_fov) {
p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect);
}
@@ -113,7 +275,7 @@ void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_
matrix[3][3] = 0;
}
-void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist) {
+void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist) {
if (p_flip_fov) {
p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect);
}
@@ -145,13 +307,13 @@ void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_
set_frustum(left, right, -ymax, ymax, p_z_near, p_z_far);
// translate matrix by (modeltranslation, 0.0, 0.0)
- CameraMatrix cm;
+ Projection cm;
cm.set_identity();
cm.matrix[3][0] = modeltranslation;
*this = *this * cm;
}
-void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_dist, real_t p_display_width, real_t p_display_to_lens, real_t p_oversample, real_t p_z_near, real_t p_z_far) {
+void Projection::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_dist, real_t p_display_width, real_t p_display_to_lens, real_t p_oversample, real_t p_z_near, real_t p_z_far) {
// we first calculate our base frustum on our values without taking our lens magnification into account.
real_t f1 = (p_intraocular_dist * 0.5) / p_display_to_lens;
real_t f2 = ((p_display_width - p_intraocular_dist) * 0.5) / p_display_to_lens;
@@ -179,7 +341,7 @@ void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_
}
}
-void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
+void Projection::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
set_identity();
matrix[0][0] = 2.0 / (p_right - p_left);
@@ -191,7 +353,7 @@ void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom
matrix[3][3] = 1.0;
}
-void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) {
+void Projection::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) {
if (!p_flip_fov) {
p_size *= p_aspect;
}
@@ -199,7 +361,7 @@ void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear
set_orthogonal(-p_size / 2, +p_size / 2, -p_size / p_aspect / 2, +p_size / p_aspect / 2, p_znear, p_zfar);
}
-void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
+void Projection::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
ERR_FAIL_COND(p_right <= p_left);
ERR_FAIL_COND(p_top <= p_bottom);
ERR_FAIL_COND(p_far <= p_near);
@@ -231,7 +393,7 @@ void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, r
te[15] = 0;
}
-void CameraMatrix::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov) {
+void Projection::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov) {
if (!p_flip_fov) {
p_size *= p_aspect;
}
@@ -239,7 +401,7 @@ void CameraMatrix::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset,
set_frustum(-p_size / 2 + p_offset.x, +p_size / 2 + p_offset.x, -p_size / p_aspect / 2 + p_offset.y, +p_size / p_aspect / 2 + p_offset.y, p_near, p_far);
}
-real_t CameraMatrix::get_z_far() const {
+real_t Projection::get_z_far() const {
const real_t *matrix = (const real_t *)this->matrix;
Plane new_plane = Plane(matrix[3] - matrix[2],
matrix[7] - matrix[6],
@@ -252,7 +414,7 @@ real_t CameraMatrix::get_z_far() const {
return new_plane.d;
}
-real_t CameraMatrix::get_z_near() const {
+real_t Projection::get_z_near() const {
const real_t *matrix = (const real_t *)this->matrix;
Plane new_plane = Plane(matrix[3] + matrix[2],
matrix[7] + matrix[6],
@@ -263,7 +425,7 @@ real_t CameraMatrix::get_z_near() const {
return new_plane.d;
}
-Vector2 CameraMatrix::get_viewport_half_extents() const {
+Vector2 Projection::get_viewport_half_extents() const {
const real_t *matrix = (const real_t *)this->matrix;
///////--- Near Plane ---///////
Plane near_plane = Plane(matrix[3] + matrix[2],
@@ -291,7 +453,7 @@ Vector2 CameraMatrix::get_viewport_half_extents() const {
return Vector2(res.x, res.y);
}
-Vector2 CameraMatrix::get_far_plane_half_extents() const {
+Vector2 Projection::get_far_plane_half_extents() const {
const real_t *matrix = (const real_t *)this->matrix;
///////--- Far Plane ---///////
Plane far_plane = Plane(matrix[3] - matrix[2],
@@ -319,7 +481,7 @@ Vector2 CameraMatrix::get_far_plane_half_extents() const {
return Vector2(res.x, res.y);
}
-bool CameraMatrix::get_endpoints(const Transform3D &p_transform, Vector3 *p_8points) const {
+bool Projection::get_endpoints(const Transform3D &p_transform, Vector3 *p_8points) const {
Vector<Plane> planes = get_projection_planes(Transform3D());
const Planes intersections[8][3] = {
{ PLANE_FAR, PLANE_LEFT, PLANE_TOP },
@@ -342,7 +504,7 @@ bool CameraMatrix::get_endpoints(const Transform3D &p_transform, Vector3 *p_8poi
return true;
}
-Vector<Plane> CameraMatrix::get_projection_planes(const Transform3D &p_transform) const {
+Vector<Plane> Projection::get_projection_planes(const Transform3D &p_transform) const {
/** Fast Plane Extraction from combined modelview/projection matrices.
* References:
* https://web.archive.org/web/20011221205252/https://www.markmorley.com/opengl/frustumculling.html
@@ -425,13 +587,13 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform3D &p_transform
return planes;
}
-CameraMatrix CameraMatrix::inverse() const {
- CameraMatrix cm = *this;
+Projection Projection::inverse() const {
+ Projection cm = *this;
cm.invert();
return cm;
}
-void CameraMatrix::invert() {
+void Projection::invert() {
int i, j, k;
int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */
real_t pvt_val; /* Value of current pivot element */
@@ -529,18 +691,18 @@ void CameraMatrix::invert() {
}
}
-void CameraMatrix::flip_y() {
+void Projection::flip_y() {
for (int i = 0; i < 4; i++) {
matrix[1][i] = -matrix[1][i];
}
}
-CameraMatrix::CameraMatrix() {
+Projection::Projection() {
set_identity();
}
-CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const {
- CameraMatrix new_matrix;
+Projection Projection::operator*(const Projection &p_matrix) const {
+ Projection new_matrix;
for (int j = 0; j < 4; j++) {
for (int i = 0; i < 4; i++) {
@@ -555,7 +717,7 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const {
return new_matrix;
}
-void CameraMatrix::set_depth_correction(bool p_flip_y) {
+void Projection::set_depth_correction(bool p_flip_y) {
real_t *m = &matrix[0][0];
m[0] = 1;
@@ -576,7 +738,7 @@ void CameraMatrix::set_depth_correction(bool p_flip_y) {
m[15] = 1.0;
}
-void CameraMatrix::set_light_bias() {
+void Projection::set_light_bias() {
real_t *m = &matrix[0][0];
m[0] = 0.5;
@@ -597,7 +759,7 @@ void CameraMatrix::set_light_bias() {
m[15] = 1.0;
}
-void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) {
+void Projection::set_light_atlas_rect(const Rect2 &p_rect) {
real_t *m = &matrix[0][0];
m[0] = p_rect.size.width;
@@ -618,7 +780,7 @@ void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) {
m[15] = 1.0;
}
-CameraMatrix::operator String() const {
+Projection::operator String() const {
String str;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
@@ -629,22 +791,22 @@ CameraMatrix::operator String() const {
return str;
}
-real_t CameraMatrix::get_aspect() const {
+real_t Projection::get_aspect() const {
Vector2 vp_he = get_viewport_half_extents();
return vp_he.x / vp_he.y;
}
-int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const {
+int Projection::get_pixels_per_meter(int p_for_pixel_width) const {
Vector3 result = xform(Vector3(1, 0, -1));
return int((result.x * 0.5 + 0.5) * p_for_pixel_width);
}
-bool CameraMatrix::is_orthogonal() const {
+bool Projection::is_orthogonal() const {
return matrix[3][3] == 1.0;
}
-real_t CameraMatrix::get_fov() const {
+real_t Projection::get_fov() const {
const real_t *matrix = (const real_t *)this->matrix;
Plane right_plane = Plane(matrix[3] - matrix[0],
@@ -667,7 +829,7 @@ real_t CameraMatrix::get_fov() const {
}
}
-float CameraMatrix::get_lod_multiplier() const {
+float Projection::get_lod_multiplier() const {
if (is_orthogonal()) {
return get_viewport_half_extents().x;
} else {
@@ -678,14 +840,14 @@ float CameraMatrix::get_lod_multiplier() const {
//usage is lod_size / (lod_distance * multiplier) < threshold
}
-void CameraMatrix::make_scale(const Vector3 &p_scale) {
+void Projection::make_scale(const Vector3 &p_scale) {
set_identity();
matrix[0][0] = p_scale.x;
matrix[1][1] = p_scale.y;
matrix[2][2] = p_scale.z;
}
-void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) {
+void Projection::scale_translate_to_fit(const AABB &p_aabb) {
Vector3 min = p_aabb.position;
Vector3 max = p_aabb.position + p_aabb.size;
@@ -710,12 +872,12 @@ void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) {
matrix[3][3] = 1;
}
-void CameraMatrix::add_jitter_offset(const Vector2 &p_offset) {
+void Projection::add_jitter_offset(const Vector2 &p_offset) {
matrix[3][0] += p_offset.x;
matrix[3][1] += p_offset.y;
}
-CameraMatrix::operator Transform3D() const {
+Projection::operator Transform3D() const {
Transform3D tr;
const real_t *m = &matrix[0][0];
@@ -737,8 +899,13 @@ CameraMatrix::operator Transform3D() const {
return tr;
}
-
-CameraMatrix::CameraMatrix(const Transform3D &p_transform) {
+Projection::Projection(const Vector4 &p_x, const Vector4 &p_y, const Vector4 &p_z, const Vector4 &p_w) {
+ matrix[0] = p_x;
+ matrix[1] = p_y;
+ matrix[2] = p_z;
+ matrix[3] = p_w;
+}
+Projection::Projection(const Transform3D &p_transform) {
const Transform3D &tr = p_transform;
real_t *m = &matrix[0][0];
@@ -760,5 +927,5 @@ CameraMatrix::CameraMatrix(const Transform3D &p_transform) {
m[15] = 1.0;
}
-CameraMatrix::~CameraMatrix() {
+Projection::~Projection() {
}
diff --git a/core/math/camera_matrix.h b/core/math/projection.h
index a4051cee3b..ff65271417 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/projection.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* camera_matrix.h */
+/* projection.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -33,6 +33,7 @@
#include "core/math/math_defs.h"
#include "core/math/vector3.h"
+#include "core/math/vector4.h"
#include "core/templates/vector.h"
struct AABB;
@@ -41,7 +42,7 @@ struct Rect2;
struct Transform3D;
struct Vector2;
-struct CameraMatrix {
+struct Projection {
enum Planes {
PLANE_NEAR,
PLANE_FAR,
@@ -51,13 +52,24 @@ struct CameraMatrix {
PLANE_BOTTOM
};
- real_t matrix[4][4];
+ Vector4 matrix[4];
+
+ _FORCE_INLINE_ const Vector4 &operator[](const int p_axis) const {
+ DEV_ASSERT((unsigned int)p_axis < 4);
+ return matrix[p_axis];
+ }
+
+ _FORCE_INLINE_ Vector4 &operator[](const int p_axis) {
+ DEV_ASSERT((unsigned int)p_axis < 4);
+ return matrix[p_axis];
+ }
float determinant() const;
void set_identity();
void set_zero();
void set_light_bias();
void set_depth_correction(bool p_flip_y = true);
+
void set_light_atlas_rect(const Rect2 &p_rect);
void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov = false);
void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist);
@@ -68,6 +80,21 @@ struct CameraMatrix {
void set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov = false);
void adjust_perspective_znear(real_t p_new_znear);
+ static Projection create_depth_correction(bool p_flip_y);
+ static Projection create_light_atlas_rect(const Rect2 &p_rect);
+ static Projection create_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov = false);
+ static Projection create_perspective_hmd(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist);
+ static Projection create_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_dist, real_t p_display_width, real_t p_display_to_lens, real_t p_oversample, real_t p_z_near, real_t p_z_far);
+ static Projection create_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar);
+ static Projection create_orthogonal_aspect(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov = false);
+ static Projection create_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far);
+ static Projection create_frustum_aspect(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov = false);
+ static Projection create_fit_aabb(const AABB &p_aabb);
+ Projection perspective_znear_adjusted(real_t p_new_znear) const;
+ Plane get_projection_plane(Planes p_plane) const;
+ Projection flipped_y() const;
+ Projection jitter_offseted(const Vector2 &p_offset) const;
+
static real_t get_fovy(real_t p_fovx, real_t p_aspect) {
return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5)) * 2.0);
}
@@ -85,13 +112,16 @@ struct CameraMatrix {
Vector2 get_far_plane_half_extents() const;
void invert();
- CameraMatrix inverse() const;
+ Projection inverse() const;
- CameraMatrix operator*(const CameraMatrix &p_matrix) const;
+ Projection operator*(const Projection &p_matrix) const;
Plane xform4(const Plane &p_vec4) const;
_FORCE_INLINE_ Vector3 xform(const Vector3 &p_vec3) const;
+ Vector4 xform(const Vector4 &p_vec4) const;
+ Vector4 xform_inv(const Vector4 &p_vec4) const;
+
operator String() const;
void scale_translate_to_fit(const AABB &p_aabb);
@@ -102,7 +132,7 @@ struct CameraMatrix {
void flip_y();
- bool operator==(const CameraMatrix &p_cam) const {
+ bool operator==(const Projection &p_cam) const {
for (uint32_t i = 0; i < 4; i++) {
for (uint32_t j = 0; j < 4; j++) {
if (matrix[i][j] != p_cam.matrix[i][j]) {
@@ -113,18 +143,19 @@ struct CameraMatrix {
return true;
}
- bool operator!=(const CameraMatrix &p_cam) const {
+ bool operator!=(const Projection &p_cam) const {
return !(*this == p_cam);
}
float get_lod_multiplier() const;
- CameraMatrix();
- CameraMatrix(const Transform3D &p_transform);
- ~CameraMatrix();
+ Projection();
+ Projection(const Vector4 &p_x, const Vector4 &p_y, const Vector4 &p_z, const Vector4 &p_w);
+ Projection(const Transform3D &p_transform);
+ ~Projection();
};
-Vector3 CameraMatrix::xform(const Vector3 &p_vec3) const {
+Vector3 Projection::xform(const Vector3 &p_vec3) const {
Vector3 ret;
ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0];
ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1];
diff --git a/core/math/vector4.cpp b/core/math/vector4.cpp
new file mode 100644
index 0000000000..c2a6f8ead2
--- /dev/null
+++ b/core/math/vector4.cpp
@@ -0,0 +1,102 @@
+/*************************************************************************/
+/* vector4.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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. */
+/*************************************************************************/
+
+#include "vector4.h"
+
+#include "core/math/basis.h"
+#include "core/string/print_string.h"
+
+bool Vector4::is_equal_approx(const Vector4 &p_vec4) const {
+ return Math::is_equal_approx(x, p_vec4.x) && Math::is_equal_approx(y, p_vec4.y) && Math::is_equal_approx(z, p_vec4.z) && Math::is_equal_approx(w, p_vec4.w);
+}
+
+real_t Vector4::length() const {
+ return Math::sqrt(length_squared());
+}
+
+void Vector4::normalize() {
+ *this /= length();
+}
+
+Vector4 Vector4::normalized() const {
+ return *this / length();
+}
+
+bool Vector4::is_normalized() const {
+ return Math::is_equal_approx(length_squared(), 1, (real_t)UNIT_EPSILON); //use less epsilon
+}
+
+Vector4 Vector4::abs() const {
+ return Vector4(Math::abs(x), Math::abs(y), Math::abs(z), Math::abs(w));
+}
+
+Vector4 Vector4::sign() const {
+ return Vector4(SIGN(x), SIGN(y), SIGN(z), SIGN(w));
+}
+
+Vector4 Vector4::inverse() const {
+ return Vector4(1.0f / x, 1.0f / y, 1.0f / z, 1.0f / w);
+}
+
+Vector4::Axis Vector4::min_axis_index() const {
+ uint32_t min_index = 0;
+ real_t min_value = x;
+ for (uint32_t i = 1; i < 4; i++) {
+ if (operator[](i) < min_value) {
+ min_index = i;
+ min_value = operator[](i);
+ }
+ }
+ return Vector4::Axis(min_index);
+}
+
+Vector4::Axis Vector4::max_axis_index() const {
+ uint32_t max_index = 0;
+ real_t max_value = x;
+ for (uint32_t i = 1; i < 4; i++) {
+ if (operator[](i) > max_value) {
+ max_index = i;
+ max_value = operator[](i);
+ }
+ }
+ return Vector4::Axis(max_index);
+}
+
+Vector4 Vector4::clamp(const Vector4 &p_min, const Vector4 &p_max) const {
+ return Vector4(
+ CLAMP(x, p_min.x, p_max.x),
+ CLAMP(y, p_min.y, p_max.y),
+ CLAMP(z, p_min.z, p_max.z),
+ CLAMP(w, p_min.w, p_max.w));
+}
+
+Vector4::operator String() const {
+ return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ", " + String::num_real(z, false) + ", " + String::num_real(w, false) + ")";
+}
diff --git a/core/math/vector4.h b/core/math/vector4.h
new file mode 100644
index 0000000000..7dd8d7aff5
--- /dev/null
+++ b/core/math/vector4.h
@@ -0,0 +1,275 @@
+/*************************************************************************/
+/* vector4.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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
+
+#include "core/math/math_defs.h"
+#include "core/math/math_funcs.h"
+#include "core/math/vector3.h"
+#include "core/string/ustring.h"
+
+struct _NO_DISCARD_ Vector4 {
+ enum Axis {
+ AXIS_X,
+ AXIS_Y,
+ AXIS_Z,
+ AXIS_W,
+ };
+
+ union {
+ struct {
+ real_t x;
+ real_t y;
+ real_t z;
+ real_t w;
+ };
+ real_t components[4] = { 0, 0, 0, 0 };
+ };
+
+ _FORCE_INLINE_ real_t &operator[](int idx) {
+ return components[idx];
+ }
+ _FORCE_INLINE_ const real_t &operator[](int idx) const {
+ return components[idx];
+ }
+ _FORCE_INLINE_ real_t length_squared() const;
+ bool is_equal_approx(const Vector4 &p_vec4) const;
+ real_t length() const;
+ void normalize();
+ Vector4 normalized() const;
+ bool is_normalized() const;
+ Vector4 abs() const;
+ Vector4 sign() const;
+
+ Vector4::Axis min_axis_index() const;
+ Vector4::Axis max_axis_index() const;
+ Vector4 clamp(const Vector4 &p_min, const Vector4 &p_max) const;
+
+ 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);
+ _FORCE_INLINE_ void operator*=(const real_t &s);
+ _FORCE_INLINE_ void operator/=(const real_t &s);
+ _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;
+ _FORCE_INLINE_ Vector4 operator*(const real_t &s) const;
+ _FORCE_INLINE_ Vector4 operator/(const real_t &s) 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;
+ _FORCE_INLINE_ bool operator<=(const Vector4 &p_vec4) const;
+
+ operator String() const;
+
+ _FORCE_INLINE_ Vector4() {}
+
+ _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) {
+ }
+
+ Vector4(const Vector4 &p_vec4) :
+ x(p_vec4.x),
+ y(p_vec4.y),
+ z(p_vec4.z),
+ w(p_vec4.w) {
+ }
+
+ void operator=(const Vector4 &p_vec4) {
+ x = p_vec4.x;
+ y = p_vec4.y;
+ z = p_vec4.z;
+ w = p_vec4.w;
+ }
+};
+
+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;
+}
+void Vector4::operator*=(const real_t &s) {
+ x *= s;
+ y *= s;
+ z *= s;
+ w *= s;
+}
+
+void Vector4::operator/=(const real_t &s) {
+ *this *= 1.0f / s;
+}
+
+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 {
+ return Vector4(x, y, z, w);
+}
+
+Vector4 Vector4::operator*(const real_t &s) const {
+ return Vector4(x * s, y * s, z * s, w * s);
+}
+
+Vector4 Vector4::operator/(const real_t &s) const {
+ return *this * (1.0f / s);
+}
+
+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;
+}
+
+_FORCE_INLINE_ Vector4 operator*(const float p_scalar, const Vector4 &p_vec) {
+ return p_vec * p_scalar;
+}
+
+_FORCE_INLINE_ Vector4 operator*(const double p_scalar, const Vector4 &p_vec) {
+ return p_vec * p_scalar;
+}
+
+_FORCE_INLINE_ Vector4 operator*(const int32_t p_scalar, const Vector4 &p_vec) {
+ return p_vec * p_scalar;
+}
+
+_FORCE_INLINE_ Vector4 operator*(const int64_t p_scalar, const Vector4 &p_vec) {
+ return p_vec * p_scalar;
+}
+#endif // VECTOR4_H
diff --git a/core/math/vector4i.cpp b/core/math/vector4i.cpp
new file mode 100644
index 0000000000..8c571b02e3
--- /dev/null
+++ b/core/math/vector4i.cpp
@@ -0,0 +1,91 @@
+/*************************************************************************/
+/* vector4i.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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. */
+/*************************************************************************/
+
+#include "vector4i.h"
+
+#include "core/math/vector4.h"
+#include "core/string/ustring.h"
+
+void Vector4i::set_axis(const int p_axis, const int32_t p_value) {
+ ERR_FAIL_INDEX(p_axis, 4);
+ coord[p_axis] = p_value;
+}
+
+int32_t Vector4i::get_axis(const int p_axis) const {
+ ERR_FAIL_INDEX_V(p_axis, 4, 0);
+ return operator[](p_axis);
+}
+
+Vector4i::Axis Vector4i::min_axis_index() const {
+ uint32_t min_index = 0;
+ int32_t min_value = x;
+ for (uint32_t i = 1; i < 4; i++) {
+ if (operator[](i) < min_value) {
+ min_index = i;
+ min_value = operator[](i);
+ }
+ }
+ return Vector4i::Axis(min_index);
+}
+
+Vector4i::Axis Vector4i::max_axis_index() const {
+ uint32_t max_index = 0;
+ int32_t max_value = x;
+ for (uint32_t i = 1; i < 4; i++) {
+ if (operator[](i) > max_value) {
+ max_index = i;
+ max_value = operator[](i);
+ }
+ }
+ return Vector4i::Axis(max_index);
+}
+
+Vector4i Vector4i::clamp(const Vector4i &p_min, const Vector4i &p_max) const {
+ return Vector4i(
+ CLAMP(x, p_min.x, p_max.x),
+ CLAMP(y, p_min.y, p_max.y),
+ CLAMP(z, p_min.z, p_max.z),
+ CLAMP(w, p_min.w, p_max.w));
+}
+
+Vector4i::operator String() const {
+ return "(" + itos(x) + ", " + itos(y) + ", " + itos(z) + ", " + itos(w) + ")";
+}
+
+Vector4i::operator Vector4() const {
+ return Vector4(x, y, z, w);
+}
+
+Vector4i::Vector4i(const Vector4 &p_vec4) {
+ x = p_vec4.x;
+ y = p_vec4.y;
+ z = p_vec4.z;
+ w = p_vec4.w;
+}
diff --git a/core/math/vector4i.h b/core/math/vector4i.h
new file mode 100644
index 0000000000..37d905878f
--- /dev/null
+++ b/core/math/vector4i.h
@@ -0,0 +1,338 @@
+/*************************************************************************/
+/* vector4i.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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 VECTOR4I_H
+#define VECTOR4I_H
+
+#include "core/error/error_macros.h"
+#include "core/math/math_funcs.h"
+
+class String;
+struct Vector4;
+
+struct _NO_DISCARD_ Vector4i {
+ enum Axis {
+ AXIS_X,
+ AXIS_Y,
+ AXIS_Z,
+ AXIS_W,
+ };
+
+ union {
+ struct {
+ int32_t x;
+ int32_t y;
+ int32_t z;
+ int32_t w;
+ };
+
+ int32_t coord[4] = { 0 };
+ };
+
+ _FORCE_INLINE_ const int32_t &operator[](const int p_axis) const {
+ DEV_ASSERT((unsigned int)p_axis < 4);
+ return coord[p_axis];
+ }
+
+ _FORCE_INLINE_ int32_t &operator[](const int p_axis) {
+ DEV_ASSERT((unsigned int)p_axis < 4);
+ return coord[p_axis];
+ }
+
+ void set_axis(const int p_axis, const int32_t p_value);
+ int32_t get_axis(const int p_axis) const;
+
+ Vector4i::Axis min_axis_index() const;
+ Vector4i::Axis max_axis_index() const;
+
+ _FORCE_INLINE_ int64_t length_squared() const;
+ _FORCE_INLINE_ double length() const;
+
+ _FORCE_INLINE_ void zero();
+
+ _FORCE_INLINE_ Vector4i abs() const;
+ _FORCE_INLINE_ Vector4i sign() const;
+ Vector4i clamp(const Vector4i &p_min, const Vector4i &p_max) const;
+
+ /* Operators */
+
+ _FORCE_INLINE_ Vector4i &operator+=(const Vector4i &p_v);
+ _FORCE_INLINE_ Vector4i operator+(const Vector4i &p_v) const;
+ _FORCE_INLINE_ Vector4i &operator-=(const Vector4i &p_v);
+ _FORCE_INLINE_ Vector4i operator-(const Vector4i &p_v) const;
+ _FORCE_INLINE_ Vector4i &operator*=(const Vector4i &p_v);
+ _FORCE_INLINE_ Vector4i operator*(const Vector4i &p_v) const;
+ _FORCE_INLINE_ Vector4i &operator/=(const Vector4i &p_v);
+ _FORCE_INLINE_ Vector4i operator/(const Vector4i &p_v) const;
+ _FORCE_INLINE_ Vector4i &operator%=(const Vector4i &p_v);
+ _FORCE_INLINE_ Vector4i operator%(const Vector4i &p_v) const;
+
+ _FORCE_INLINE_ Vector4i &operator*=(const int32_t p_scalar);
+ _FORCE_INLINE_ Vector4i operator*(const int32_t p_scalar) const;
+ _FORCE_INLINE_ Vector4i &operator/=(const int32_t p_scalar);
+ _FORCE_INLINE_ Vector4i operator/(const int32_t p_scalar) const;
+ _FORCE_INLINE_ Vector4i &operator%=(const int32_t p_scalar);
+ _FORCE_INLINE_ Vector4i operator%(const int32_t p_scalar) const;
+
+ _FORCE_INLINE_ Vector4i operator-() const;
+
+ _FORCE_INLINE_ bool operator==(const Vector4i &p_v) const;
+ _FORCE_INLINE_ bool operator!=(const Vector4i &p_v) const;
+ _FORCE_INLINE_ bool operator<(const Vector4i &p_v) const;
+ _FORCE_INLINE_ bool operator<=(const Vector4i &p_v) const;
+ _FORCE_INLINE_ bool operator>(const Vector4i &p_v) const;
+ _FORCE_INLINE_ bool operator>=(const Vector4i &p_v) const;
+
+ operator String() const;
+ operator Vector4() const;
+
+ _FORCE_INLINE_ Vector4i() {}
+ Vector4i(const Vector4 &p_vec4);
+ _FORCE_INLINE_ Vector4i(const int32_t p_x, const int32_t p_y, const int32_t p_z, const int32_t p_w) {
+ x = p_x;
+ y = p_y;
+ z = p_z;
+ w = p_w;
+ }
+};
+
+int64_t Vector4i::length_squared() const {
+ return x * (int64_t)x + y * (int64_t)y + z * (int64_t)z + w * (int64_t)w;
+}
+
+double Vector4i::length() const {
+ return Math::sqrt((double)length_squared());
+}
+
+Vector4i Vector4i::abs() const {
+ return Vector4i(ABS(x), ABS(y), ABS(z), ABS(w));
+}
+
+Vector4i Vector4i::sign() const {
+ return Vector4i(SIGN(x), SIGN(y), SIGN(z), SIGN(w));
+}
+
+/* Operators */
+
+Vector4i &Vector4i::operator+=(const Vector4i &p_v) {
+ x += p_v.x;
+ y += p_v.y;
+ z += p_v.z;
+ w += p_v.w;
+ return *this;
+}
+
+Vector4i Vector4i::operator+(const Vector4i &p_v) const {
+ return Vector4i(x + p_v.x, y + p_v.y, z + p_v.z, w + p_v.w);
+}
+
+Vector4i &Vector4i::operator-=(const Vector4i &p_v) {
+ x -= p_v.x;
+ y -= p_v.y;
+ z -= p_v.z;
+ w -= p_v.w;
+ return *this;
+}
+
+Vector4i Vector4i::operator-(const Vector4i &p_v) const {
+ return Vector4i(x - p_v.x, y - p_v.y, z - p_v.z, w - p_v.w);
+}
+
+Vector4i &Vector4i::operator*=(const Vector4i &p_v) {
+ x *= p_v.x;
+ y *= p_v.y;
+ z *= p_v.z;
+ w *= p_v.w;
+ return *this;
+}
+
+Vector4i Vector4i::operator*(const Vector4i &p_v) const {
+ return Vector4i(x * p_v.x, y * p_v.y, z * p_v.z, w * p_v.w);
+}
+
+Vector4i &Vector4i::operator/=(const Vector4i &p_v) {
+ x /= p_v.x;
+ y /= p_v.y;
+ z /= p_v.z;
+ w /= p_v.w;
+ return *this;
+}
+
+Vector4i Vector4i::operator/(const Vector4i &p_v) const {
+ return Vector4i(x / p_v.x, y / p_v.y, z / p_v.z, w / p_v.w);
+}
+
+Vector4i &Vector4i::operator%=(const Vector4i &p_v) {
+ x %= p_v.x;
+ y %= p_v.y;
+ z %= p_v.z;
+ w %= p_v.w;
+ return *this;
+}
+
+Vector4i Vector4i::operator%(const Vector4i &p_v) const {
+ return Vector4i(x % p_v.x, y % p_v.y, z % p_v.z, w % p_v.w);
+}
+
+Vector4i &Vector4i::operator*=(const int32_t p_scalar) {
+ x *= p_scalar;
+ y *= p_scalar;
+ z *= p_scalar;
+ w *= p_scalar;
+ return *this;
+}
+
+Vector4i Vector4i::operator*(const int32_t p_scalar) const {
+ return Vector4i(x * p_scalar, y * p_scalar, z * p_scalar, w * p_scalar);
+}
+
+// Multiplication operators required to workaround issues with LLVM using implicit conversion.
+
+_FORCE_INLINE_ Vector4i operator*(const int32_t p_scalar, const Vector4i &p_vector) {
+ return p_vector * p_scalar;
+}
+
+_FORCE_INLINE_ Vector4i operator*(const int64_t p_scalar, const Vector4i &p_vector) {
+ return p_vector * p_scalar;
+}
+
+_FORCE_INLINE_ Vector4i operator*(const float p_scalar, const Vector4i &p_vector) {
+ return p_vector * p_scalar;
+}
+
+_FORCE_INLINE_ Vector4i operator*(const double p_scalar, const Vector4i &p_vector) {
+ return p_vector * p_scalar;
+}
+
+Vector4i &Vector4i::operator/=(const int32_t p_scalar) {
+ x /= p_scalar;
+ y /= p_scalar;
+ z /= p_scalar;
+ w /= p_scalar;
+ return *this;
+}
+
+Vector4i Vector4i::operator/(const int32_t p_scalar) const {
+ return Vector4i(x / p_scalar, y / p_scalar, z / p_scalar, w / p_scalar);
+}
+
+Vector4i &Vector4i::operator%=(const int32_t p_scalar) {
+ x %= p_scalar;
+ y %= p_scalar;
+ z %= p_scalar;
+ w %= p_scalar;
+ return *this;
+}
+
+Vector4i Vector4i::operator%(const int32_t p_scalar) const {
+ return Vector4i(x % p_scalar, y % p_scalar, z % p_scalar, w % p_scalar);
+}
+
+Vector4i Vector4i::operator-() const {
+ return Vector4i(-x, -y, -z, -w);
+}
+
+bool Vector4i::operator==(const Vector4i &p_v) const {
+ return (x == p_v.x && y == p_v.y && z == p_v.z && w == p_v.w);
+}
+
+bool Vector4i::operator!=(const Vector4i &p_v) const {
+ return (x != p_v.x || y != p_v.y || z != p_v.z || w != p_v.w);
+}
+
+bool Vector4i::operator<(const Vector4i &p_v) const {
+ if (x == p_v.x) {
+ if (y == p_v.y) {
+ if (z == p_v.z) {
+ return w < p_v.w;
+ } else {
+ return z < p_v.z;
+ }
+ } else {
+ return y < p_v.y;
+ }
+ } else {
+ return x < p_v.x;
+ }
+}
+
+bool Vector4i::operator>(const Vector4i &p_v) const {
+ if (x == p_v.x) {
+ if (y == p_v.y) {
+ if (z == p_v.z) {
+ return w > p_v.w;
+ } else {
+ return z > p_v.z;
+ }
+ } else {
+ return y > p_v.y;
+ }
+ } else {
+ return x > p_v.x;
+ }
+}
+
+bool Vector4i::operator<=(const Vector4i &p_v) const {
+ if (x == p_v.x) {
+ if (y == p_v.y) {
+ if (z == p_v.z) {
+ return w <= p_v.w;
+ } else {
+ return z < p_v.z;
+ }
+ } else {
+ return y < p_v.y;
+ }
+ } else {
+ return x < p_v.x;
+ }
+}
+
+bool Vector4i::operator>=(const Vector4i &p_v) const {
+ if (x == p_v.x) {
+ if (y == p_v.y) {
+ if (z == p_v.z) {
+ return w >= p_v.w;
+ } else {
+ return z > p_v.z;
+ }
+ } else {
+ return y > p_v.y;
+ }
+ } else {
+ return x > p_v.x;
+ }
+}
+
+void Vector4i::zero() {
+ x = y = z = w = 0;
+}
+
+#endif // VECTOR4I_H
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index 4623d0e525..226fd8b791 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -344,11 +344,14 @@ void ScriptLanguage::get_core_type_words(List<String> *p_core_type_words) const
p_core_type_words->push_back("Vector3");
p_core_type_words->push_back("Vector3i");
p_core_type_words->push_back("Transform2D");
+ p_core_type_words->push_back("Vector4");
+ p_core_type_words->push_back("Vector4i");
p_core_type_words->push_back("Plane");
p_core_type_words->push_back("Quaternion");
p_core_type_words->push_back("AABB");
p_core_type_words->push_back("Basis");
p_core_type_words->push_back("Transform3D");
+ p_core_type_words->push_back("Projection");
p_core_type_words->push_back("Color");
p_core_type_words->push_back("StringName");
p_core_type_words->push_back("NodePath");
diff --git a/core/templates/hashfuncs.h b/core/templates/hashfuncs.h
index 547534f26a..d85cdf7adc 100644
--- a/core/templates/hashfuncs.h
+++ b/core/templates/hashfuncs.h
@@ -40,6 +40,8 @@
#include "core/math/vector2i.h"
#include "core/math/vector3.h"
#include "core/math/vector3i.h"
+#include "core/math/vector4.h"
+#include "core/math/vector4i.h"
#include "core/object/object_id.h"
#include "core/string/node_path.h"
#include "core/string/string_name.h"
@@ -332,6 +334,13 @@ struct HashMapHasherDefault {
h = hash_murmur3_one_32(p_vec.z, h);
return hash_fmix32(h);
}
+ static _FORCE_INLINE_ uint32_t hash(const Vector4i &p_vec) {
+ uint32_t h = hash_murmur3_one_32(p_vec.x);
+ h = hash_murmur3_one_32(p_vec.y, h);
+ h = hash_murmur3_one_32(p_vec.z, h);
+ h = hash_murmur3_one_32(p_vec.w, h);
+ return hash_fmix32(h);
+ }
static _FORCE_INLINE_ uint32_t hash(const Vector2 &p_vec) {
uint32_t h = hash_murmur3_one_real(p_vec.x);
h = hash_murmur3_one_real(p_vec.y, h);
@@ -343,6 +352,13 @@ struct HashMapHasherDefault {
h = hash_murmur3_one_real(p_vec.z, h);
return hash_fmix32(h);
}
+ static _FORCE_INLINE_ uint32_t hash(const Vector4 &p_vec) {
+ uint32_t h = hash_murmur3_one_real(p_vec.x);
+ h = hash_murmur3_one_real(p_vec.y, h);
+ h = hash_murmur3_one_real(p_vec.z, h);
+ h = hash_murmur3_one_real(p_vec.w, h);
+ return hash_fmix32(h);
+ }
static _FORCE_INLINE_ uint32_t hash(const Rect2i &p_rect) {
uint32_t h = hash_murmur3_one_32(p_rect.position.x);
h = hash_murmur3_one_32(p_rect.position.y, h);
diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h
index 84f894dcbf..f0c3b1ce38 100644
--- a/core/variant/binder_common.h
+++ b/core/variant/binder_common.h
@@ -136,7 +136,10 @@ VARIANT_ENUM_CAST(Vector2::Axis);
VARIANT_ENUM_CAST(Vector2i::Axis);
VARIANT_ENUM_CAST(Vector3::Axis);
VARIANT_ENUM_CAST(Vector3i::Axis);
+VARIANT_ENUM_CAST(Vector4::Axis);
+VARIANT_ENUM_CAST(Vector4i::Axis);
VARIANT_ENUM_CAST(Basis::EulerOrder);
+VARIANT_ENUM_CAST(Projection::Planes);
VARIANT_ENUM_CAST(Error);
VARIANT_ENUM_CAST(Side);
diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h
index d0acf60c22..0ed70a5504 100644
--- a/core/variant/method_ptrcall.h
+++ b/core/variant/method_ptrcall.h
@@ -125,7 +125,10 @@ MAKE_PTRARG(Rect2);
MAKE_PTRARG(Rect2i);
MAKE_PTRARG_BY_REFERENCE(Vector3);
MAKE_PTRARG_BY_REFERENCE(Vector3i);
+MAKE_PTRARG_BY_REFERENCE(Vector4);
+MAKE_PTRARG_BY_REFERENCE(Vector4i);
MAKE_PTRARG(Transform2D);
+MAKE_PTRARG(Projection);
MAKE_PTRARG_BY_REFERENCE(Plane);
MAKE_PTRARG(Quaternion);
MAKE_PTRARG_BY_REFERENCE(AABB);
diff --git a/core/variant/type_info.h b/core/variant/type_info.h
index 1bd3a74289..7372c60754 100644
--- a/core/variant/type_info.h
+++ b/core/variant/type_info.h
@@ -144,12 +144,15 @@ MAKE_TYPE_INFO(Vector3, Variant::VECTOR3)
MAKE_TYPE_INFO(Vector2i, Variant::VECTOR2I)
MAKE_TYPE_INFO(Rect2i, Variant::RECT2I)
MAKE_TYPE_INFO(Vector3i, Variant::VECTOR3I)
+MAKE_TYPE_INFO(Vector4, Variant::VECTOR4)
+MAKE_TYPE_INFO(Vector4i, Variant::VECTOR4I)
MAKE_TYPE_INFO(Transform2D, Variant::TRANSFORM2D)
MAKE_TYPE_INFO(Plane, Variant::PLANE)
MAKE_TYPE_INFO(Quaternion, Variant::QUATERNION)
MAKE_TYPE_INFO(AABB, Variant::AABB)
MAKE_TYPE_INFO(Basis, Variant::BASIS)
MAKE_TYPE_INFO(Transform3D, Variant::TRANSFORM3D)
+MAKE_TYPE_INFO(Projection, Variant::PROJECTION)
MAKE_TYPE_INFO(Color, Variant::COLOR)
MAKE_TYPE_INFO(StringName, Variant::STRING_NAME)
MAKE_TYPE_INFO(NodePath, Variant::NODE_PATH)
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp
index ae92d7b5c4..6763dd66b0 100644
--- a/core/variant/variant.cpp
+++ b/core/variant/variant.cpp
@@ -83,6 +83,12 @@ String Variant::get_type_name(Variant::Type p_type) {
case VECTOR3I: {
return "Vector3i";
} break;
+ case VECTOR4: {
+ return "Vector4";
+ } break;
+ case VECTOR4I: {
+ return "Vector4i";
+ } break;
case PLANE: {
return "Plane";
@@ -102,6 +108,10 @@ String Variant::get_type_name(Variant::Type p_type) {
return "Transform3D";
} break;
+ case PROJECTION: {
+ return "Projection";
+
+ } break;
// misc types
case COLOR: {
@@ -298,6 +308,24 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
+ case VECTOR4: {
+ static const Type valid[] = {
+ VECTOR4I,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+ case VECTOR4I: {
+ static const Type valid[] = {
+ VECTOR4,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
case QUATERNION: {
static const Type valid[] = {
@@ -322,6 +350,16 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
TRANSFORM2D,
QUATERNION,
BASIS,
+ PROJECTION,
+ NIL
+ };
+
+ valid_types = valid;
+
+ } break;
+ case PROJECTION: {
+ static const Type valid[] = {
+ TRANSFORM3D,
NIL
};
@@ -604,6 +642,24 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
+ case VECTOR4: {
+ static const Type valid[] = {
+ VECTOR4I,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+ case VECTOR4I: {
+ static const Type valid[] = {
+ VECTOR4,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
case QUATERNION: {
static const Type valid[] = {
@@ -628,6 +684,16 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
TRANSFORM2D,
QUATERNION,
BASIS,
+ PROJECTION,
+ NIL
+ };
+
+ valid_types = valid;
+
+ } break;
+ case PROJECTION: {
+ static const Type valid[] = {
+ TRANSFORM3D,
NIL
};
@@ -858,6 +924,14 @@ bool Variant::is_zero() const {
return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i();
} break;
+ case VECTOR4: {
+ return *reinterpret_cast<const Vector4 *>(_data._mem) == Vector4();
+
+ } break;
+ case VECTOR4I: {
+ return *reinterpret_cast<const Vector4i *>(_data._mem) == Vector4i();
+
+ } break;
case PLANE: {
return *reinterpret_cast<const Plane *>(_data._mem) == Plane();
@@ -877,6 +951,10 @@ bool Variant::is_zero() const {
return *_data._transform3d == Transform3D();
} break;
+ case PROJECTION: {
+ return *_data._projection == Projection();
+
+ } break;
// misc types
case COLOR: {
@@ -998,6 +1076,14 @@ bool Variant::is_one() const {
return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(1, 1, 1);
} break;
+ case VECTOR4: {
+ return *reinterpret_cast<const Vector4 *>(_data._mem) == Vector4(1, 1, 1, 1);
+
+ } break;
+ case VECTOR4I: {
+ return *reinterpret_cast<const Vector4i *>(_data._mem) == Vector4i(1, 1, 1, 1);
+
+ } break;
case PLANE: {
return *reinterpret_cast<const Plane *>(_data._mem) == Plane(1, 1, 1, 1);
@@ -1084,6 +1170,12 @@ void Variant::reference(const Variant &p_variant) {
case VECTOR3I: {
memnew_placement(_data._mem, Vector3i(*reinterpret_cast<const Vector3i *>(p_variant._data._mem)));
} break;
+ case VECTOR4: {
+ memnew_placement(_data._mem, Vector4(*reinterpret_cast<const Vector4 *>(p_variant._data._mem)));
+ } break;
+ case VECTOR4I: {
+ memnew_placement(_data._mem, Vector4i(*reinterpret_cast<const Vector4i *>(p_variant._data._mem)));
+ } break;
case PLANE: {
memnew_placement(_data._mem, Plane(*reinterpret_cast<const Plane *>(p_variant._data._mem)));
} break;
@@ -1102,6 +1194,9 @@ void Variant::reference(const Variant &p_variant) {
case TRANSFORM3D: {
_data._transform3d = memnew(Transform3D(*p_variant._data._transform3d));
} break;
+ case PROJECTION: {
+ _data._projection = memnew(Projection(*p_variant._data._projection));
+ } break;
// misc types
case COLOR: {
@@ -1250,6 +1345,12 @@ void Variant::zero() {
case VECTOR3I:
*reinterpret_cast<Vector3i *>(this->_data._mem) = Vector3i();
break;
+ case VECTOR4:
+ *reinterpret_cast<Vector4 *>(this->_data._mem) = Vector4();
+ break;
+ case VECTOR4I:
+ *reinterpret_cast<Vector4i *>(this->_data._mem) = Vector4i();
+ break;
case PLANE:
*reinterpret_cast<Plane *>(this->_data._mem) = Plane();
break;
@@ -1291,7 +1392,9 @@ void Variant::_clear_internal() {
case TRANSFORM3D: {
memdelete(_data._transform3d);
} break;
-
+ case PROJECTION: {
+ memdelete(_data._projection);
+ } break;
// misc types
case STRING_NAME: {
reinterpret_cast<StringName *>(_data._mem)->~StringName();
@@ -1681,6 +1784,10 @@ String Variant::stringify(int recursion_count) const {
return operator Vector3();
case VECTOR3I:
return operator Vector3i();
+ case VECTOR4:
+ return operator Vector4();
+ case VECTOR4I:
+ return operator Vector4i();
case PLANE:
return operator Plane();
case AABB:
@@ -1691,6 +1798,8 @@ String Variant::stringify(int recursion_count) const {
return operator Basis();
case TRANSFORM3D:
return operator Transform3D();
+ case PROJECTION:
+ return operator Projection();
case STRING_NAME:
return operator StringName();
case NODE_PATH:
@@ -1812,6 +1921,10 @@ Variant::operator Vector2() const {
return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y);
} else if (type == VECTOR3I) {
return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y);
+ } else if (type == VECTOR4) {
+ return Vector2(reinterpret_cast<const Vector4 *>(_data._mem)->x, reinterpret_cast<const Vector4 *>(_data._mem)->y);
+ } else if (type == VECTOR4I) {
+ return Vector2(reinterpret_cast<const Vector4i *>(_data._mem)->x, reinterpret_cast<const Vector4i *>(_data._mem)->y);
} else {
return Vector2();
}
@@ -1826,6 +1939,10 @@ Variant::operator Vector2i() const {
return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y);
} else if (type == VECTOR3I) {
return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y);
+ } else if (type == VECTOR4) {
+ return Vector2(reinterpret_cast<const Vector4 *>(_data._mem)->x, reinterpret_cast<const Vector4 *>(_data._mem)->y);
+ } else if (type == VECTOR4I) {
+ return Vector2(reinterpret_cast<const Vector4i *>(_data._mem)->x, reinterpret_cast<const Vector4i *>(_data._mem)->y);
} else {
return Vector2i();
}
@@ -1860,6 +1977,10 @@ Variant::operator Vector3() const {
return Vector3(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
} else if (type == VECTOR2I) {
return Vector3(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0);
+ } else if (type == VECTOR4) {
+ return Vector3(reinterpret_cast<const Vector4 *>(_data._mem)->x, reinterpret_cast<const Vector4 *>(_data._mem)->y, reinterpret_cast<const Vector4 *>(_data._mem)->z);
+ } else if (type == VECTOR4I) {
+ return Vector3(reinterpret_cast<const Vector4i *>(_data._mem)->x, reinterpret_cast<const Vector4i *>(_data._mem)->y, reinterpret_cast<const Vector4i *>(_data._mem)->z);
} else {
return Vector3();
}
@@ -1874,11 +1995,52 @@ Variant::operator Vector3i() const {
return Vector3i(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
} else if (type == VECTOR2I) {
return Vector3i(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0);
+ } else if (type == VECTOR4) {
+ return Vector3i(reinterpret_cast<const Vector4 *>(_data._mem)->x, reinterpret_cast<const Vector4 *>(_data._mem)->y, reinterpret_cast<const Vector4 *>(_data._mem)->z);
+ } else if (type == VECTOR4I) {
+ return Vector3i(reinterpret_cast<const Vector4i *>(_data._mem)->x, reinterpret_cast<const Vector4i *>(_data._mem)->y, reinterpret_cast<const Vector4i *>(_data._mem)->z);
} else {
return Vector3i();
}
}
+Variant::operator Vector4() const {
+ if (type == VECTOR4) {
+ return *reinterpret_cast<const Vector4 *>(_data._mem);
+ } else if (type == VECTOR4I) {
+ return *reinterpret_cast<const Vector4i *>(_data._mem);
+ } else if (type == VECTOR2) {
+ return Vector4(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0, 0.0);
+ } else if (type == VECTOR2I) {
+ return Vector4(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0, 0.0);
+ } else if (type == VECTOR3) {
+ return Vector4(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y, reinterpret_cast<const Vector3 *>(_data._mem)->z, 0.0);
+ } else if (type == VECTOR3I) {
+ return Vector4(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y, reinterpret_cast<const Vector3i *>(_data._mem)->z, 0.0);
+ } else {
+ return Vector4();
+ }
+}
+
+Variant::operator Vector4i() const {
+ if (type == VECTOR4I) {
+ return *reinterpret_cast<const Vector4i *>(_data._mem);
+ } else if (type == VECTOR4) {
+ const Vector4 &v4 = *reinterpret_cast<const Vector4 *>(_data._mem);
+ return Vector4i(v4.x, v4.y, v4.z, v4.w);
+ } else if (type == VECTOR2) {
+ return Vector4i(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0, 0.0);
+ } else if (type == VECTOR2I) {
+ return Vector4i(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0, 0.0);
+ } else if (type == VECTOR3) {
+ return Vector4i(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y, reinterpret_cast<const Vector3 *>(_data._mem)->z, 0.0);
+ } else if (type == VECTOR3I) {
+ return Vector4i(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y, reinterpret_cast<const Vector3i *>(_data._mem)->z, 0.0);
+ } else {
+ return Vector4i();
+ }
+}
+
Variant::operator Plane() const {
if (type == PLANE) {
return *reinterpret_cast<const Plane *>(_data._mem);
@@ -1936,11 +2098,37 @@ Variant::operator Transform3D() const {
m.origin[0] = t.columns[2][0];
m.origin[1] = t.columns[2][1];
return m;
+ } else if (type == PROJECTION) {
+ return *_data._projection;
} else {
return Transform3D();
}
}
+Variant::operator Projection() const {
+ if (type == TRANSFORM3D) {
+ return *_data._transform3d;
+ } else if (type == BASIS) {
+ return Transform3D(*_data._basis, Vector3());
+ } else if (type == QUATERNION) {
+ return Transform3D(Basis(*reinterpret_cast<const Quaternion *>(_data._mem)), Vector3());
+ } else if (type == TRANSFORM2D) {
+ const Transform2D &t = *_data._transform2d;
+ Transform3D m;
+ m.basis.rows[0][0] = t.columns[0][0];
+ m.basis.rows[1][0] = t.columns[0][1];
+ m.basis.rows[0][1] = t.columns[1][0];
+ m.basis.rows[1][1] = t.columns[1][1];
+ m.origin[0] = t.columns[2][0];
+ m.origin[1] = t.columns[2][1];
+ return m;
+ } else if (type == PROJECTION) {
+ return *_data._projection;
+ } else {
+ return Projection();
+ }
+}
+
Variant::operator Transform2D() const {
if (type == TRANSFORM2D) {
return *_data._transform2d;
@@ -2384,6 +2572,16 @@ Variant::Variant(const Vector3i &p_vector3i) {
memnew_placement(_data._mem, Vector3i(p_vector3i));
}
+Variant::Variant(const Vector4 &p_vector4) {
+ type = VECTOR4;
+ memnew_placement(_data._mem, Vector4(p_vector4));
+}
+
+Variant::Variant(const Vector4i &p_vector4i) {
+ type = VECTOR4I;
+ memnew_placement(_data._mem, Vector4i(p_vector4i));
+}
+
Variant::Variant(const Vector2 &p_vector2) {
type = VECTOR2;
memnew_placement(_data._mem, Vector2(p_vector2));
@@ -2429,6 +2627,11 @@ Variant::Variant(const Transform3D &p_transform) {
_data._transform3d = memnew(Transform3D(p_transform));
}
+Variant::Variant(const Projection &pp_projection) {
+ type = PROJECTION;
+ _data._projection = memnew(Projection(pp_projection));
+}
+
Variant::Variant(const Transform2D &p_transform) {
type = TRANSFORM2D;
_data._transform2d = memnew(Transform2D(p_transform));
@@ -2656,6 +2859,12 @@ void Variant::operator=(const Variant &p_variant) {
case VECTOR3I: {
*reinterpret_cast<Vector3i *>(_data._mem) = *reinterpret_cast<const Vector3i *>(p_variant._data._mem);
} break;
+ case VECTOR4: {
+ *reinterpret_cast<Vector4 *>(_data._mem) = *reinterpret_cast<const Vector4 *>(p_variant._data._mem);
+ } break;
+ case VECTOR4I: {
+ *reinterpret_cast<Vector4i *>(_data._mem) = *reinterpret_cast<const Vector4i *>(p_variant._data._mem);
+ } break;
case PLANE: {
*reinterpret_cast<Plane *>(_data._mem) = *reinterpret_cast<const Plane *>(p_variant._data._mem);
} break;
@@ -2672,6 +2881,9 @@ void Variant::operator=(const Variant &p_variant) {
case TRANSFORM3D: {
*_data._transform3d = *(p_variant._data._transform3d);
} break;
+ case PROJECTION: {
+ *_data._projection = *(p_variant._data._projection);
+ } break;
// misc types
case COLOR: {
@@ -2817,6 +3029,12 @@ uint32_t Variant::recursive_hash(int recursion_count) const {
case VECTOR3I: {
return HashMapHasherDefault::hash(*reinterpret_cast<const Vector3i *>(_data._mem));
} break;
+ case VECTOR4: {
+ return HashMapHasherDefault::hash(*reinterpret_cast<const Vector4 *>(_data._mem));
+ } break;
+ case VECTOR4I: {
+ return HashMapHasherDefault::hash(*reinterpret_cast<const Vector4i *>(_data._mem));
+ } break;
case PLANE: {
uint32_t h = HASH_MURMUR3_SEED;
const Plane &p = *reinterpret_cast<const Plane *>(_data._mem);
@@ -2869,6 +3087,27 @@ uint32_t Variant::recursive_hash(int recursion_count) const {
h = hash_murmur3_one_real(t.origin.z, h);
return hash_fmix32(h);
} break;
+ case PROJECTION: {
+ uint32_t h = HASH_MURMUR3_SEED;
+ const Projection &t = *_data._projection;
+ h = hash_murmur3_one_real(t.matrix[0].x, h);
+ h = hash_murmur3_one_real(t.matrix[0].y, h);
+ h = hash_murmur3_one_real(t.matrix[0].z, h);
+ h = hash_murmur3_one_real(t.matrix[0].w, h);
+ h = hash_murmur3_one_real(t.matrix[1].x, h);
+ h = hash_murmur3_one_real(t.matrix[1].y, h);
+ h = hash_murmur3_one_real(t.matrix[1].z, h);
+ h = hash_murmur3_one_real(t.matrix[1].w, h);
+ h = hash_murmur3_one_real(t.matrix[2].x, h);
+ h = hash_murmur3_one_real(t.matrix[2].y, h);
+ h = hash_murmur3_one_real(t.matrix[2].z, h);
+ h = hash_murmur3_one_real(t.matrix[2].w, h);
+ h = hash_murmur3_one_real(t.matrix[3].x, h);
+ h = hash_murmur3_one_real(t.matrix[3].y, h);
+ h = hash_murmur3_one_real(t.matrix[3].z, h);
+ h = hash_murmur3_one_real(t.matrix[3].w, h);
+ return hash_fmix32(h);
+ } break;
// misc types
case COLOR: {
uint32_t h = HASH_MURMUR3_SEED;
@@ -3062,6 +3301,11 @@ uint32_t Variant::recursive_hash(int recursion_count) const {
(hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
(hash_compare_scalar((p_lhs).y, (p_rhs).y)) && \
(hash_compare_scalar((p_lhs).z, (p_rhs).z))
+#define hash_compare_vector4(p_lhs, p_rhs) \
+ (hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
+ (hash_compare_scalar((p_lhs).y, (p_rhs).y)) && \
+ (hash_compare_scalar((p_lhs).z, (p_rhs).z)) && \
+ (hash_compare_scalar((p_lhs).w, (p_rhs).w))
#define hash_compare_quaternion(p_lhs, p_rhs) \
(hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
@@ -3165,6 +3409,18 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count) const
return *l == *r;
} break;
+ case VECTOR4: {
+ const Vector4 *l = reinterpret_cast<const Vector4 *>(_data._mem);
+ const Vector4 *r = reinterpret_cast<const Vector4 *>(p_variant._data._mem);
+
+ return hash_compare_vector4(*l, *r);
+ } break;
+ case VECTOR4I: {
+ const Vector4i *l = reinterpret_cast<const Vector4i *>(_data._mem);
+ const Vector4i *r = reinterpret_cast<const Vector4i *>(p_variant._data._mem);
+
+ return *l == *r;
+ } break;
case PLANE: {
const Plane *l = reinterpret_cast<const Plane *>(_data._mem);
@@ -3215,6 +3471,18 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count) const
return hash_compare_vector3(l->origin, r->origin);
} break;
+ case PROJECTION: {
+ const Projection *l = _data._projection;
+ const Projection *r = p_variant._data._projection;
+
+ for (int i = 0; i < 4; i++) {
+ if (!(hash_compare_vector4(l->matrix[i], r->matrix[i]))) {
+ return false;
+ }
+ }
+
+ return true;
+ } break;
case COLOR: {
const Color *l = reinterpret_cast<const Color *>(_data._mem);
diff --git a/core/variant/variant.h b/core/variant/variant.h
index 872b374b13..465c31730c 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -38,6 +38,7 @@
#include "core/math/color.h"
#include "core/math/face3.h"
#include "core/math/plane.h"
+#include "core/math/projection.h"
#include "core/math/quaternion.h"
#include "core/math/rect2.h"
#include "core/math/rect2i.h"
@@ -47,6 +48,8 @@
#include "core/math/vector2i.h"
#include "core/math/vector3.h"
#include "core/math/vector3i.h"
+#include "core/math/vector4.h"
+#include "core/math/vector4i.h"
#include "core/object/object_id.h"
#include "core/os/keyboard.h"
#include "core/string/node_path.h"
@@ -91,11 +94,14 @@ public:
VECTOR3,
VECTOR3I,
TRANSFORM2D,
+ VECTOR4,
+ VECTOR4I,
PLANE,
QUATERNION,
AABB,
BASIS,
TRANSFORM3D,
+ PROJECTION,
// misc types
COLOR,
@@ -210,6 +216,7 @@ private:
::AABB *_aabb;
Basis *_basis;
Transform3D *_transform3d;
+ Projection *_projection;
PackedArrayRefBase *packed_array;
void *_ptr; //generic pointer
uint8_t _mem[sizeof(ObjData) > (sizeof(real_t) * 4) ? sizeof(ObjData) : (sizeof(real_t) * 4)]{ 0 };
@@ -234,11 +241,14 @@ private:
false, //VECTOR3,
false, //VECTOR3I,
true, //TRANSFORM2D,
+ false, //VECTOR4,
+ false, //VECTOR4I,
false, //PLANE,
false, //QUATERNION,
true, //AABB,
true, //BASIS,
true, //TRANSFORM,
+ true, //PROJECTION,
// misc types
false, //COLOR,
@@ -339,12 +349,15 @@ public:
operator Rect2i() const;
operator Vector3() const;
operator Vector3i() const;
+ operator Vector4() const;
+ operator Vector4i() const;
operator Plane() const;
operator ::AABB() const;
operator Quaternion() const;
operator Basis() const;
operator Transform2D() const;
operator Transform3D() const;
+ operator Projection() const;
operator Color() const;
operator NodePath() const;
@@ -409,12 +422,15 @@ public:
Variant(const Rect2i &p_rect2i);
Variant(const Vector3 &p_vector3);
Variant(const Vector3i &p_vector3i);
+ Variant(const Vector4 &p_vector4);
+ Variant(const Vector4i &p_vector4i);
Variant(const Plane &p_plane);
Variant(const ::AABB &p_aabb);
Variant(const Quaternion &p_quat);
Variant(const Basis &p_matrix);
Variant(const Transform2D &p_transform);
Variant(const Transform3D &p_transform);
+ Variant(const Projection &p_projection);
Variant(const Color &p_color);
Variant(const NodePath &p_node_path);
Variant(const ::RID &p_rid);
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 47943a563f..0ddb3a0f22 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -1725,6 +1725,31 @@ static void _register_variant_builtin_methods() {
bind_method(Vector3i, abs, sarray(), varray());
bind_method(Vector3i, clamp, sarray("min", "max"), varray());
+ /* Vector4 */
+
+ bind_method(Vector4, min_axis_index, sarray(), varray());
+ bind_method(Vector4, max_axis_index, sarray(), varray());
+ bind_method(Vector4, length, sarray(), varray());
+ bind_method(Vector4, length_squared, sarray(), varray());
+ bind_method(Vector4, sign, sarray(), varray());
+ bind_method(Vector4, abs, sarray(), varray());
+ bind_method(Vector4, clamp, sarray("min", "max"), varray());
+ bind_method(Vector4, normalized, sarray(), varray());
+ bind_method(Vector4, is_normalized, sarray(), varray());
+ bind_method(Vector4, dot, sarray("with"), varray());
+ bind_method(Vector4, inverse, sarray(), varray());
+ bind_method(Vector4, is_equal_approx, sarray("with"), varray());
+
+ /* Vector4i */
+
+ bind_method(Vector4i, min_axis_index, sarray(), varray());
+ bind_method(Vector4i, max_axis_index, sarray(), varray());
+ bind_method(Vector4i, length, sarray(), varray());
+ bind_method(Vector4i, length_squared, sarray(), varray());
+ bind_method(Vector4i, sign, sarray(), varray());
+ bind_method(Vector4i, abs, sarray(), varray());
+ bind_method(Vector4i, clamp, sarray("min", "max"), varray());
+
/* Plane */
bind_method(Plane, normalized, sarray(), varray());
@@ -1925,6 +1950,40 @@ static void _register_variant_builtin_methods() {
bind_method(Transform3D, interpolate_with, sarray("xform", "weight"), varray());
bind_method(Transform3D, is_equal_approx, sarray("xform"), varray());
+ /* Projection */
+
+ bind_static_method(Projection, create_depth_correction, sarray("flip_y"), varray());
+ bind_static_method(Projection, create_light_atlas_rect, sarray("rect"), varray());
+ bind_static_method(Projection, create_perspective, sarray("fovy", "aspect", "z_near", "z_far", "flip_fov"), varray(false));
+ bind_static_method(Projection, create_perspective_hmd, sarray("fovy", "aspect", "z_near", "z_far", "flip_fov", "eye", "intraocular_dist", " convergence_dist"), varray());
+ bind_static_method(Projection, create_for_hmd, sarray("eye", "aspect", "intraocular_dist", "display_width", "display_to_lens", "oversample", "z_near", "z_far"), varray());
+ bind_static_method(Projection, create_orthogonal, sarray("left", "right", "bottom", "top", "z_near", "z_far"), varray());
+ bind_static_method(Projection, create_orthogonal_aspect, sarray("size", "aspect", "z_near", "z_far", "flip_fov"), varray(false));
+ bind_static_method(Projection, create_frustum, sarray("left", "right", "bottom", "top", "z_near", "z_far"), varray());
+ bind_static_method(Projection, create_frustum_aspect, sarray("size", "aspect", "offset", "z_near", "z_far", "flip_fov"), varray(false));
+ bind_static_method(Projection, create_fit_aabb, sarray("aabb"), varray());
+
+ bind_method(Projection, determinant, sarray(), varray());
+ bind_method(Projection, perspective_znear_adjusted, sarray("new_znear"), varray());
+ bind_method(Projection, get_projection_plane, sarray("plane"), varray());
+ bind_method(Projection, flipped_y, sarray(), varray());
+ bind_method(Projection, jitter_offseted, sarray("offset"), varray());
+
+ bind_static_method(Projection, get_fovy, sarray("fovx", "aspect"), varray());
+
+ bind_method(Projection, get_z_far, sarray(), varray());
+ bind_method(Projection, get_z_near, sarray(), varray());
+ bind_method(Projection, get_aspect, sarray(), varray());
+ bind_method(Projection, get_fov, sarray(), varray());
+ bind_method(Projection, is_orthogonal, sarray(), varray());
+
+ bind_method(Projection, get_viewport_half_extents, sarray(), varray());
+ bind_method(Projection, get_far_plane_half_extents, sarray(), varray());
+
+ bind_method(Projection, inverse, sarray(), varray());
+ bind_method(Projection, get_pixels_per_meter, sarray("for_pixel_width"), varray());
+ bind_method(Projection, get_lod_multiplier, sarray(), varray());
+
/* Dictionary */
bind_method(Dictionary, size, sarray(), varray());
@@ -2253,6 +2312,19 @@ static void _register_variant_builtin_methods() {
_VariantCall::add_variant_constant(Variant::VECTOR3, "FORWARD", Vector3(0, 0, -1));
_VariantCall::add_variant_constant(Variant::VECTOR3, "BACK", Vector3(0, 0, 1));
+ _VariantCall::add_constant(Variant::VECTOR4, "AXIS_X", Vector4::AXIS_X);
+ _VariantCall::add_constant(Variant::VECTOR4, "AXIS_Y", Vector4::AXIS_Y);
+ _VariantCall::add_constant(Variant::VECTOR4, "AXIS_Z", Vector4::AXIS_Z);
+ _VariantCall::add_constant(Variant::VECTOR4, "AXIS_W", Vector4::AXIS_W);
+
+ _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_X", Vector4::AXIS_X);
+ _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_Y", Vector4::AXIS_Y);
+ _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_Z", Vector4::AXIS_Z);
+ _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_W", Vector4::AXIS_W);
+ _VariantCall::add_variant_constant(Variant::VECTOR4, "ZERO", Vector4(0, 0, 0, 0));
+ _VariantCall::add_variant_constant(Variant::VECTOR4, "ONE", Vector4(1, 1, 1, 1));
+ _VariantCall::add_variant_constant(Variant::VECTOR4, "INF", Vector4(INFINITY, INFINITY, INFINITY, INFINITY));
+
_VariantCall::add_constant(Variant::VECTOR3I, "AXIS_X", Vector3i::AXIS_X);
_VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Y", Vector3i::AXIS_Y);
_VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Z", Vector3i::AXIS_Z);
@@ -2261,6 +2333,19 @@ static void _register_variant_builtin_methods() {
_VariantCall::add_enum_constant(Variant::VECTOR3I, "Axis", "AXIS_Y", Vector3i::AXIS_Y);
_VariantCall::add_enum_constant(Variant::VECTOR3I, "Axis", "AXIS_Z", Vector3i::AXIS_Z);
+ _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_X", Vector4i::AXIS_X);
+ _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_Y", Vector4i::AXIS_Y);
+ _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_Z", Vector4i::AXIS_Z);
+ _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_W", Vector4i::AXIS_W);
+
+ _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_X", Vector4i::AXIS_X);
+ _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_Y", Vector4i::AXIS_Y);
+ _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_Z", Vector4i::AXIS_Z);
+ _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_W", Vector4i::AXIS_W);
+
+ _VariantCall::add_variant_constant(Variant::VECTOR4I, "ZERO", Vector4i(0, 0, 0, 0));
+ _VariantCall::add_variant_constant(Variant::VECTOR4I, "ONE", Vector4i(1, 1, 1, 1));
+
_VariantCall::add_variant_constant(Variant::VECTOR3I, "ZERO", Vector3i(0, 0, 0));
_VariantCall::add_variant_constant(Variant::VECTOR3I, "ONE", Vector3i(1, 1, 1));
_VariantCall::add_variant_constant(Variant::VECTOR3I, "LEFT", Vector3i(-1, 0, 0));
@@ -2338,6 +2423,25 @@ static void _register_variant_builtin_methods() {
_VariantCall::add_variant_constant(Variant::PLANE, "PLANE_XY", Plane(Vector3(0, 0, 1), 0));
_VariantCall::add_variant_constant(Variant::QUATERNION, "IDENTITY", Quaternion(0, 0, 0, 1));
+
+ _VariantCall::add_constant(Variant::PROJECTION, "PLANE_NEAR", Projection::PLANE_NEAR);
+ _VariantCall::add_constant(Variant::PROJECTION, "PLANE_FAR", Projection::PLANE_FAR);
+ _VariantCall::add_constant(Variant::PROJECTION, "PLANE_LEFT", Projection::PLANE_LEFT);
+ _VariantCall::add_constant(Variant::PROJECTION, "PLANE_TOP", Projection::PLANE_TOP);
+ _VariantCall::add_constant(Variant::PROJECTION, "PLANE_RIGHT", Projection::PLANE_RIGHT);
+ _VariantCall::add_constant(Variant::PROJECTION, "PLANE_BOTTOM", Projection::PLANE_BOTTOM);
+
+ _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_NEAR", Projection::PLANE_NEAR);
+ _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_FAR", Projection::PLANE_FAR);
+ _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_LEFT", Projection::PLANE_LEFT);
+ _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_TOP", Projection::PLANE_TOP);
+ _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_RIGHT", Projection::PLANE_RIGHT);
+ _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_BOTTOM", Projection::PLANE_BOTTOM);
+
+ Projection p;
+ _VariantCall::add_variant_constant(Variant::PROJECTION, "IDENTITY", p);
+ p.set_zero();
+ _VariantCall::add_variant_constant(Variant::PROJECTION, "ZERO", p);
}
void Variant::_register_variant_methods() {
diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp
index 78d5433d8c..3a0b6c1bb9 100644
--- a/core/variant/variant_construct.cpp
+++ b/core/variant/variant_construct.cpp
@@ -111,6 +111,16 @@ void Variant::_register_variant_constructors() {
add_constructor<VariantConstructor<Vector3i, Vector3>>(sarray("from"));
add_constructor<VariantConstructor<Vector3i, int64_t, int64_t, int64_t>>(sarray("x", "y", "z"));
+ add_constructor<VariantConstructNoArgs<Vector4>>(sarray());
+ add_constructor<VariantConstructor<Vector4, Vector4>>(sarray("from"));
+ add_constructor<VariantConstructor<Vector4, Vector4i>>(sarray("from"));
+ add_constructor<VariantConstructor<Vector4, double, double, double, double>>(sarray("x", "y", "z", "w"));
+
+ add_constructor<VariantConstructNoArgs<Vector4i>>(sarray());
+ add_constructor<VariantConstructor<Vector4i, Vector4i>>(sarray("from"));
+ add_constructor<VariantConstructor<Vector4i, Vector4>>(sarray("from"));
+ add_constructor<VariantConstructor<Vector4i, int64_t, int64_t, int64_t, int64_t>>(sarray("x", "y", "z", "w"));
+
add_constructor<VariantConstructNoArgs<Transform2D>>(sarray());
add_constructor<VariantConstructor<Transform2D, Transform2D>>(sarray("from"));
add_constructor<VariantConstructor<Transform2D, float, Vector2>>(sarray("rotation", "position"));
@@ -147,6 +157,11 @@ void Variant::_register_variant_constructors() {
add_constructor<VariantConstructor<Transform3D, Transform3D>>(sarray("from"));
add_constructor<VariantConstructor<Transform3D, Basis, Vector3>>(sarray("basis", "origin"));
add_constructor<VariantConstructor<Transform3D, Vector3, Vector3, Vector3, Vector3>>(sarray("x_axis", "y_axis", "z_axis", "origin"));
+ add_constructor<VariantConstructor<Transform3D, Projection>>(sarray("from"));
+
+ add_constructor<VariantConstructNoArgs<Projection>>(sarray());
+ add_constructor<VariantConstructor<Projection, Projection>>(sarray("from"));
+ add_constructor<VariantConstructor<Projection, Transform3D>>(sarray("from"));
add_constructor<VariantConstructNoArgs<Color>>(sarray());
add_constructor<VariantConstructor<Color, Color>>(sarray("from"));
diff --git a/core/variant/variant_construct.h b/core/variant/variant_construct.h
index 638c0136f3..58a0f34c1e 100644
--- a/core/variant/variant_construct.h
+++ b/core/variant/variant_construct.h
@@ -63,12 +63,15 @@ MAKE_PTRCONSTRUCT(Rect2);
MAKE_PTRCONSTRUCT(Rect2i);
MAKE_PTRCONSTRUCT(Vector3);
MAKE_PTRCONSTRUCT(Vector3i);
+MAKE_PTRCONSTRUCT(Vector4);
+MAKE_PTRCONSTRUCT(Vector4i);
MAKE_PTRCONSTRUCT(Transform2D);
MAKE_PTRCONSTRUCT(Plane);
MAKE_PTRCONSTRUCT(Quaternion);
MAKE_PTRCONSTRUCT(AABB);
MAKE_PTRCONSTRUCT(Basis);
MAKE_PTRCONSTRUCT(Transform3D);
+MAKE_PTRCONSTRUCT(Projection);
MAKE_PTRCONSTRUCT(Color);
MAKE_PTRCONSTRUCT(StringName);
MAKE_PTRCONSTRUCT(NodePath);
diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h
index e0cfb42e1e..961c0f3a51 100644
--- a/core/variant/variant_internal.h
+++ b/core/variant/variant_internal.h
@@ -138,6 +138,10 @@ public:
_FORCE_INLINE_ static const Vector3 *get_vector3(const Variant *v) { return reinterpret_cast<const Vector3 *>(v->_data._mem); }
_FORCE_INLINE_ static Vector3i *get_vector3i(Variant *v) { return reinterpret_cast<Vector3i *>(v->_data._mem); }
_FORCE_INLINE_ static const Vector3i *get_vector3i(const Variant *v) { return reinterpret_cast<const Vector3i *>(v->_data._mem); }
+ _FORCE_INLINE_ static Vector4 *get_vector4(Variant *v) { return reinterpret_cast<Vector4 *>(v->_data._mem); }
+ _FORCE_INLINE_ static const Vector4 *get_vector4(const Variant *v) { return reinterpret_cast<const Vector4 *>(v->_data._mem); }
+ _FORCE_INLINE_ static Vector4i *get_vector4i(Variant *v) { return reinterpret_cast<Vector4i *>(v->_data._mem); }
+ _FORCE_INLINE_ static const Vector4i *get_vector4i(const Variant *v) { return reinterpret_cast<const Vector4i *>(v->_data._mem); }
_FORCE_INLINE_ static Transform2D *get_transform2d(Variant *v) { return v->_data._transform2d; }
_FORCE_INLINE_ static const Transform2D *get_transform2d(const Variant *v) { return v->_data._transform2d; }
_FORCE_INLINE_ static Plane *get_plane(Variant *v) { return reinterpret_cast<Plane *>(v->_data._mem); }
@@ -150,6 +154,8 @@ public:
_FORCE_INLINE_ static const Basis *get_basis(const Variant *v) { return v->_data._basis; }
_FORCE_INLINE_ static Transform3D *get_transform(Variant *v) { return v->_data._transform3d; }
_FORCE_INLINE_ static const Transform3D *get_transform(const Variant *v) { return v->_data._transform3d; }
+ _FORCE_INLINE_ static Projection *get_projection(Variant *v) { return v->_data._projection; }
+ _FORCE_INLINE_ static const Projection *get_projection(const Variant *v) { return v->_data._projection; }
// Misc types.
_FORCE_INLINE_ static Color *get_color(Variant *v) { return reinterpret_cast<Color *>(v->_data._mem); }
@@ -224,6 +230,10 @@ public:
v->_data._transform3d = memnew(Transform3D);
v->type = Variant::TRANSFORM3D;
}
+ _FORCE_INLINE_ static void init_projection(Variant *v) {
+ v->_data._projection = memnew(Projection);
+ v->type = Variant::PROJECTION;
+ }
_FORCE_INLINE_ static void init_string_name(Variant *v) {
memnew_placement(v->_data._mem, StringName);
v->type = Variant::STRING_NAME;
@@ -331,12 +341,18 @@ public:
return get_vector3(v);
case Variant::VECTOR3I:
return get_vector3i(v);
+ case Variant::VECTOR4:
+ return get_vector4(v);
+ case Variant::VECTOR4I:
+ return get_vector4i(v);
case Variant::RECT2:
return get_rect2(v);
case Variant::RECT2I:
return get_rect2i(v);
case Variant::TRANSFORM3D:
return get_transform(v);
+ case Variant::PROJECTION:
+ return get_projection(v);
case Variant::TRANSFORM2D:
return get_transform2d(v);
case Variant::QUATERNION:
@@ -409,12 +425,18 @@ public:
return get_vector3(v);
case Variant::VECTOR3I:
return get_vector3i(v);
+ case Variant::VECTOR4:
+ return get_vector4(v);
+ case Variant::VECTOR4I:
+ return get_vector4i(v);
case Variant::RECT2:
return get_rect2(v);
case Variant::RECT2I:
return get_rect2i(v);
case Variant::TRANSFORM3D:
return get_transform(v);
+ case Variant::PROJECTION:
+ return get_projection(v);
case Variant::TRANSFORM2D:
return get_transform2d(v);
case Variant::QUATERNION:
@@ -599,6 +621,17 @@ struct VariantGetInternalPtr<Vector3i> {
};
template <>
+struct VariantGetInternalPtr<Vector4> {
+ static Vector4 *get_ptr(Variant *v) { return VariantInternal::get_vector4(v); }
+ static const Vector4 *get_ptr(const Variant *v) { return VariantInternal::get_vector4(v); }
+};
+
+template <>
+struct VariantGetInternalPtr<Vector4i> {
+ static Vector4i *get_ptr(Variant *v) { return VariantInternal::get_vector4i(v); }
+ static const Vector4i *get_ptr(const Variant *v) { return VariantInternal::get_vector4i(v); }
+};
+template <>
struct VariantGetInternalPtr<Transform2D> {
static Transform2D *get_ptr(Variant *v) { return VariantInternal::get_transform2d(v); }
static const Transform2D *get_ptr(const Variant *v) { return VariantInternal::get_transform2d(v); }
@@ -611,6 +644,12 @@ struct VariantGetInternalPtr<Transform3D> {
};
template <>
+struct VariantGetInternalPtr<Projection> {
+ static Projection *get_ptr(Variant *v) { return VariantInternal::get_projection(v); }
+ static const Projection *get_ptr(const Variant *v) { return VariantInternal::get_projection(v); }
+};
+
+template <>
struct VariantGetInternalPtr<Plane> {
static Plane *get_ptr(Variant *v) { return VariantInternal::get_plane(v); }
static const Plane *get_ptr(const Variant *v) { return VariantInternal::get_plane(v); }
@@ -772,6 +811,10 @@ VARIANT_ACCESSOR_NUMBER(Vector2::Axis)
VARIANT_ACCESSOR_NUMBER(Vector2i::Axis)
VARIANT_ACCESSOR_NUMBER(Vector3::Axis)
VARIANT_ACCESSOR_NUMBER(Vector3i::Axis)
+VARIANT_ACCESSOR_NUMBER(Vector4::Axis)
+VARIANT_ACCESSOR_NUMBER(Vector4i::Axis)
+
+VARIANT_ACCESSOR_NUMBER(Projection::Planes)
template <>
struct VariantInternalAccessor<Basis::EulerOrder> {
@@ -840,6 +883,17 @@ struct VariantInternalAccessor<Vector3i> {
};
template <>
+struct VariantInternalAccessor<Vector4> {
+ static _FORCE_INLINE_ const Vector4 &get(const Variant *v) { return *VariantInternal::get_vector4(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Vector4 &p_value) { *VariantInternal::get_vector4(v) = p_value; }
+};
+
+template <>
+struct VariantInternalAccessor<Vector4i> {
+ static _FORCE_INLINE_ const Vector4i &get(const Variant *v) { return *VariantInternal::get_vector4i(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Vector4i &p_value) { *VariantInternal::get_vector4i(v) = p_value; }
+};
+template <>
struct VariantInternalAccessor<Transform2D> {
static _FORCE_INLINE_ const Transform2D &get(const Variant *v) { return *VariantInternal::get_transform2d(v); }
static _FORCE_INLINE_ void set(Variant *v, const Transform2D &p_value) { *VariantInternal::get_transform2d(v) = p_value; }
@@ -852,6 +906,12 @@ struct VariantInternalAccessor<Transform3D> {
};
template <>
+struct VariantInternalAccessor<Projection> {
+ static _FORCE_INLINE_ const Projection &get(const Variant *v) { return *VariantInternal::get_projection(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const Projection &p_value) { *VariantInternal::get_projection(v) = p_value; }
+};
+
+template <>
struct VariantInternalAccessor<Plane> {
static _FORCE_INLINE_ const Plane &get(const Variant *v) { return *VariantInternal::get_plane(v); }
static _FORCE_INLINE_ void set(Variant *v, const Plane &p_value) { *VariantInternal::get_plane(v) = p_value; }
@@ -1041,6 +1101,8 @@ INITIALIZER_INT(Vector2::Axis)
INITIALIZER_INT(Vector2i::Axis)
INITIALIZER_INT(Vector3::Axis)
INITIALIZER_INT(Vector3i::Axis)
+INITIALIZER_INT(Vector4::Axis)
+INITIALIZER_INT(Vector4i::Axis)
template <>
struct VariantInitializer<double> {
@@ -1086,8 +1148,16 @@ template <>
struct VariantInitializer<Vector3i> {
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector3i>(v); }
};
+template <>
+struct VariantInitializer<Vector4> {
+ static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector4>(v); }
+};
template <>
+struct VariantInitializer<Vector4i> {
+ static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector4i>(v); }
+};
+template <>
struct VariantInitializer<Transform2D> {
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform2d(v); }
};
@@ -1116,6 +1186,10 @@ template <>
struct VariantInitializer<Transform3D> {
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform(v); }
};
+template <>
+struct VariantInitializer<Projection> {
+ static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_projection(v); }
+};
template <>
struct VariantInitializer<Color> {
@@ -1267,6 +1341,16 @@ struct VariantZeroAssigner<Vector3i> {
};
template <>
+struct VariantZeroAssigner<Vector4> {
+ static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_vector4(v) = Vector4(); }
+};
+
+template <>
+struct VariantZeroAssigner<Vector4i> {
+ static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_vector4i(v) = Vector4i(); }
+};
+
+template <>
struct VariantZeroAssigner<Transform2D> {
static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_transform2d(v) = Transform2D(); }
};
@@ -1297,6 +1381,11 @@ struct VariantZeroAssigner<Transform3D> {
};
template <>
+struct VariantZeroAssigner<Projection> {
+ static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_projection(v) = Projection(); }
+};
+
+template <>
struct VariantZeroAssigner<Color> {
static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_color(v) = Color(); }
};
diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp
index adace2b534..669e18b5f7 100644
--- a/core/variant/variant_op.cpp
+++ b/core/variant/variant_op.cpp
@@ -165,6 +165,70 @@ public:
static Variant::Type get_return_type() { return GetTypeInfo<Vector3>::VARIANT_TYPE; }
};
+//
+
+template <>
+class OperatorEvaluatorMul<Vector4, Vector4i, double> {
+public:
+ static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
+ const Vector4i &a = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_left);
+ const double &b = *VariantGetInternalPtr<double>::get_ptr(&p_right);
+ *r_ret = Vector4(a.x, a.y, a.z, a.w) * b;
+ r_valid = true;
+ }
+ static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
+ *VariantGetInternalPtr<Vector4>::get_ptr(r_ret) = Vector4(VariantGetInternalPtr<Vector4i>::get_ptr(left)->x, VariantGetInternalPtr<Vector4i>::get_ptr(left)->y, VariantGetInternalPtr<Vector4i>::get_ptr(left)->z, VariantGetInternalPtr<Vector4i>::get_ptr(left)->w) * *VariantGetInternalPtr<double>::get_ptr(right);
+ }
+ static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
+ PtrToArg<Vector4>::encode(Vector4(PtrToArg<Vector4i>::convert(left).x, PtrToArg<Vector4i>::convert(left).y, PtrToArg<Vector4i>::convert(left).z, PtrToArg<Vector4i>::convert(left).w) * PtrToArg<double>::convert(right), r_ret);
+ }
+ static Variant::Type get_return_type() { return GetTypeInfo<Vector4>::VARIANT_TYPE; }
+};
+
+template <>
+class OperatorEvaluatorMul<Vector4, double, Vector4i> {
+public:
+ static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
+ const Vector4i &a = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_right);
+ const double &b = *VariantGetInternalPtr<double>::get_ptr(&p_left);
+ *r_ret = Vector4(a.x, a.y, a.z, a.w) * b;
+ r_valid = true;
+ }
+ static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
+ *VariantGetInternalPtr<Vector4>::get_ptr(r_ret) = Vector4(VariantGetInternalPtr<Vector4i>::get_ptr(right)->x, VariantGetInternalPtr<Vector4i>::get_ptr(right)->y, VariantGetInternalPtr<Vector4i>::get_ptr(right)->z, VariantGetInternalPtr<Vector4i>::get_ptr(right)->w) * *VariantGetInternalPtr<double>::get_ptr(left);
+ }
+ static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
+ PtrToArg<Vector4>::encode(Vector4(PtrToArg<Vector4i>::convert(right).x, PtrToArg<Vector4i>::convert(right).y, PtrToArg<Vector4i>::convert(right).z, PtrToArg<Vector4i>::convert(right).w) * PtrToArg<double>::convert(left), r_ret);
+ }
+ static Variant::Type get_return_type() { return GetTypeInfo<Vector4>::VARIANT_TYPE; }
+};
+
+template <>
+class OperatorEvaluatorDivNZ<Vector4, Vector4i, double> {
+public:
+ static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
+ const Vector4i &a = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_left);
+ const double &b = *VariantGetInternalPtr<double>::get_ptr(&p_right);
+ if (unlikely(b == 0)) {
+ r_valid = false;
+ *r_ret = "Division by zero error";
+ return;
+ }
+ *r_ret = Vector4(a.x, a.y, a.z, a.w) / b;
+ r_valid = true;
+ }
+
+ static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
+ *VariantGetInternalPtr<Vector4>::get_ptr(r_ret) = Vector4(VariantGetInternalPtr<Vector4i>::get_ptr(left)->x, VariantGetInternalPtr<Vector4i>::get_ptr(left)->y, VariantGetInternalPtr<Vector4i>::get_ptr(left)->z, VariantGetInternalPtr<Vector4i>::get_ptr(left)->w) / *VariantGetInternalPtr<double>::get_ptr(right);
+ }
+
+ static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
+ PtrToArg<Vector4>::encode(Vector4(PtrToArg<Vector4i>::convert(left).x, PtrToArg<Vector4i>::convert(left).y, PtrToArg<Vector4i>::convert(left).z, PtrToArg<Vector4i>::convert(left).w) / PtrToArg<double>::convert(right), r_ret);
+ }
+
+ static Variant::Type get_return_type() { return GetTypeInfo<Vector4>::VARIANT_TYPE; }
+};
+
void Variant::_register_variant_operators() {
memset(operator_return_type_table, 0, sizeof(operator_return_type_table));
memset(operator_evaluator_table, 0, sizeof(operator_evaluator_table));
@@ -182,6 +246,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAdd<Vector2i, Vector2i, Vector2i>>(Variant::OP_ADD, Variant::VECTOR2I, Variant::VECTOR2I);
register_op<OperatorEvaluatorAdd<Vector3, Vector3, Vector3>>(Variant::OP_ADD, Variant::VECTOR3, Variant::VECTOR3);
register_op<OperatorEvaluatorAdd<Vector3i, Vector3i, Vector3i>>(Variant::OP_ADD, Variant::VECTOR3I, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorAdd<Vector4, Vector4, Vector4>>(Variant::OP_ADD, Variant::VECTOR4, Variant::VECTOR4);
+ register_op<OperatorEvaluatorAdd<Vector4i, Vector4i, Vector4i>>(Variant::OP_ADD, Variant::VECTOR4I, Variant::VECTOR4I);
register_op<OperatorEvaluatorAdd<Quaternion, Quaternion, Quaternion>>(Variant::OP_ADD, Variant::QUATERNION, Variant::QUATERNION);
register_op<OperatorEvaluatorAdd<Color, Color, Color>>(Variant::OP_ADD, Variant::COLOR, Variant::COLOR);
register_op<OperatorEvaluatorAddArray>(Variant::OP_ADD, Variant::ARRAY, Variant::ARRAY);
@@ -203,6 +269,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorSub<Vector2i, Vector2i, Vector2i>>(Variant::OP_SUBTRACT, Variant::VECTOR2I, Variant::VECTOR2I);
register_op<OperatorEvaluatorSub<Vector3, Vector3, Vector3>>(Variant::OP_SUBTRACT, Variant::VECTOR3, Variant::VECTOR3);
register_op<OperatorEvaluatorSub<Vector3i, Vector3i, Vector3i>>(Variant::OP_SUBTRACT, Variant::VECTOR3I, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorSub<Vector4, Vector4, Vector4>>(Variant::OP_SUBTRACT, Variant::VECTOR4, Variant::VECTOR4);
+ register_op<OperatorEvaluatorSub<Vector4i, Vector4i, Vector4i>>(Variant::OP_SUBTRACT, Variant::VECTOR4I, Variant::VECTOR4I);
register_op<OperatorEvaluatorSub<Quaternion, Quaternion, Quaternion>>(Variant::OP_SUBTRACT, Variant::QUATERNION, Variant::QUATERNION);
register_op<OperatorEvaluatorSub<Color, Color, Color>>(Variant::OP_SUBTRACT, Variant::COLOR, Variant::COLOR);
@@ -212,6 +280,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorMul<Vector2i, int64_t, Vector2i>>(Variant::OP_MULTIPLY, Variant::INT, Variant::VECTOR2I);
register_op<OperatorEvaluatorMul<Vector3, int64_t, Vector3>>(Variant::OP_MULTIPLY, Variant::INT, Variant::VECTOR3);
register_op<OperatorEvaluatorMul<Vector3i, int64_t, Vector3i>>(Variant::OP_MULTIPLY, Variant::INT, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorMul<Vector4, int64_t, Vector4>>(Variant::OP_MULTIPLY, Variant::INT, Variant::VECTOR4);
+ register_op<OperatorEvaluatorMul<Vector4i, int64_t, Vector4i>>(Variant::OP_MULTIPLY, Variant::INT, Variant::VECTOR4I);
register_op<OperatorEvaluatorMul<double, double, double>>(Variant::OP_MULTIPLY, Variant::FLOAT, Variant::FLOAT);
register_op<OperatorEvaluatorMul<double, double, int64_t>>(Variant::OP_MULTIPLY, Variant::FLOAT, Variant::INT);
@@ -219,6 +289,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorMul<Vector2, double, Vector2i>>(Variant::OP_MULTIPLY, Variant::FLOAT, Variant::VECTOR2I);
register_op<OperatorEvaluatorMul<Vector3, double, Vector3>>(Variant::OP_MULTIPLY, Variant::FLOAT, Variant::VECTOR3);
register_op<OperatorEvaluatorMul<Vector3, double, Vector3i>>(Variant::OP_MULTIPLY, Variant::FLOAT, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorMul<Vector4, double, Vector4>>(Variant::OP_MULTIPLY, Variant::FLOAT, Variant::VECTOR4);
+ register_op<OperatorEvaluatorMul<Vector4, double, Vector4i>>(Variant::OP_MULTIPLY, Variant::FLOAT, Variant::VECTOR4I);
register_op<OperatorEvaluatorMul<Vector2, Vector2, Vector2>>(Variant::OP_MULTIPLY, Variant::VECTOR2, Variant::VECTOR2);
register_op<OperatorEvaluatorMul<Vector2, Vector2, int64_t>>(Variant::OP_MULTIPLY, Variant::VECTOR2, Variant::INT);
@@ -236,6 +308,14 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorMul<Vector3i, Vector3i, int64_t>>(Variant::OP_MULTIPLY, Variant::VECTOR3I, Variant::INT);
register_op<OperatorEvaluatorMul<Vector3, Vector3i, double>>(Variant::OP_MULTIPLY, Variant::VECTOR3I, Variant::FLOAT);
+ register_op<OperatorEvaluatorMul<Vector4, Vector4, Vector4>>(Variant::OP_MULTIPLY, Variant::VECTOR4, Variant::VECTOR4);
+ register_op<OperatorEvaluatorMul<Vector4, Vector4, int64_t>>(Variant::OP_MULTIPLY, Variant::VECTOR4, Variant::INT);
+ register_op<OperatorEvaluatorMul<Vector4, Vector4, double>>(Variant::OP_MULTIPLY, Variant::VECTOR4, Variant::FLOAT);
+
+ register_op<OperatorEvaluatorMul<Vector4i, Vector4i, Vector4i>>(Variant::OP_MULTIPLY, Variant::VECTOR4I, Variant::VECTOR4I);
+ register_op<OperatorEvaluatorMul<Vector4i, Vector4i, int64_t>>(Variant::OP_MULTIPLY, Variant::VECTOR4I, Variant::INT);
+ register_op<OperatorEvaluatorMul<Vector4, Vector4i, double>>(Variant::OP_MULTIPLY, Variant::VECTOR4I, Variant::FLOAT);
+
register_op<OperatorEvaluatorMul<Quaternion, Quaternion, Quaternion>>(Variant::OP_MULTIPLY, Variant::QUATERNION, Variant::QUATERNION);
register_op<OperatorEvaluatorMul<Quaternion, Quaternion, int64_t>>(Variant::OP_MULTIPLY, Variant::QUATERNION, Variant::INT);
register_op<OperatorEvaluatorMul<Quaternion, Quaternion, double>>(Variant::OP_MULTIPLY, Variant::QUATERNION, Variant::FLOAT);
@@ -264,6 +344,11 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorXForm<Vector<Vector3>, Transform3D, Vector<Vector3>>>(Variant::OP_MULTIPLY, Variant::TRANSFORM3D, Variant::PACKED_VECTOR3_ARRAY);
register_op<OperatorEvaluatorXFormInv<Vector<Vector3>, Vector<Vector3>, Transform3D>>(Variant::OP_MULTIPLY, Variant::PACKED_VECTOR3_ARRAY, Variant::TRANSFORM3D);
+ register_op<OperatorEvaluatorXForm<Vector4, Projection, Vector4>>(Variant::OP_MULTIPLY, Variant::PROJECTION, Variant::VECTOR4);
+ register_op<OperatorEvaluatorXFormInv<Vector4, Vector4, Projection>>(Variant::OP_MULTIPLY, Variant::VECTOR4, Variant::PROJECTION);
+
+ register_op<OperatorEvaluatorMul<Projection, Projection, Projection>>(Variant::OP_MULTIPLY, Variant::PROJECTION, Variant::PROJECTION);
+
register_op<OperatorEvaluatorMul<Basis, Basis, Basis>>(Variant::OP_MULTIPLY, Variant::BASIS, Variant::BASIS);
register_op<OperatorEvaluatorMul<Basis, Basis, int64_t>>(Variant::OP_MULTIPLY, Variant::BASIS, Variant::INT);
register_op<OperatorEvaluatorMul<Basis, Basis, double>>(Variant::OP_MULTIPLY, Variant::BASIS, Variant::FLOAT);
@@ -309,6 +394,14 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorDivNZ<Vector3, Vector3i, double>>(Variant::OP_DIVIDE, Variant::VECTOR3I, Variant::FLOAT);
register_op<OperatorEvaluatorDivNZ<Vector3i, Vector3i, int64_t>>(Variant::OP_DIVIDE, Variant::VECTOR3I, Variant::INT);
+ register_op<OperatorEvaluatorDiv<Vector4, Vector4, Vector4>>(Variant::OP_DIVIDE, Variant::VECTOR4, Variant::VECTOR4);
+ register_op<OperatorEvaluatorDiv<Vector4, Vector4, double>>(Variant::OP_DIVIDE, Variant::VECTOR4, Variant::FLOAT);
+ register_op<OperatorEvaluatorDiv<Vector4, Vector4, int64_t>>(Variant::OP_DIVIDE, Variant::VECTOR4, Variant::INT);
+
+ register_op<OperatorEvaluatorDivNZ<Vector4i, Vector4i, Vector4i>>(Variant::OP_DIVIDE, Variant::VECTOR4I, Variant::VECTOR4I);
+ register_op<OperatorEvaluatorDivNZ<Vector4, Vector4i, double>>(Variant::OP_DIVIDE, Variant::VECTOR4I, Variant::FLOAT);
+ register_op<OperatorEvaluatorDivNZ<Vector4i, Vector4i, int64_t>>(Variant::OP_DIVIDE, Variant::VECTOR4I, Variant::INT);
+
register_op<OperatorEvaluatorDiv<Quaternion, Quaternion, double>>(Variant::OP_DIVIDE, Variant::QUATERNION, Variant::FLOAT);
register_op<OperatorEvaluatorDiv<Quaternion, Quaternion, int64_t>>(Variant::OP_DIVIDE, Variant::QUATERNION, Variant::INT);
@@ -323,6 +416,9 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorModNZ<Vector3i, Vector3i, Vector3i>>(Variant::OP_MODULE, Variant::VECTOR3I, Variant::VECTOR3I);
register_op<OperatorEvaluatorModNZ<Vector3i, Vector3i, int64_t>>(Variant::OP_MODULE, Variant::VECTOR3I, Variant::INT);
+ register_op<OperatorEvaluatorModNZ<Vector4i, Vector4i, Vector4i>>(Variant::OP_MODULE, Variant::VECTOR4I, Variant::VECTOR4I);
+ register_op<OperatorEvaluatorModNZ<Vector4i, Vector4i, int64_t>>(Variant::OP_MODULE, Variant::VECTOR4I, Variant::INT);
+
register_op<OperatorEvaluatorStringModNil>(Variant::OP_MODULE, Variant::STRING, Variant::NIL);
register_op<OperatorEvaluatorStringModT<bool>>(Variant::OP_MODULE, Variant::STRING, Variant::BOOL);
@@ -335,12 +431,15 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorStringModT<Rect2i>>(Variant::OP_MODULE, Variant::STRING, Variant::RECT2I);
register_op<OperatorEvaluatorStringModT<Vector3>>(Variant::OP_MODULE, Variant::STRING, Variant::VECTOR3);
register_op<OperatorEvaluatorStringModT<Vector3i>>(Variant::OP_MODULE, Variant::STRING, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorStringModT<Vector4>>(Variant::OP_MODULE, Variant::STRING, Variant::VECTOR4);
+ register_op<OperatorEvaluatorStringModT<Vector4i>>(Variant::OP_MODULE, Variant::STRING, Variant::VECTOR4I);
register_op<OperatorEvaluatorStringModT<Transform2D>>(Variant::OP_MODULE, Variant::STRING, Variant::TRANSFORM2D);
register_op<OperatorEvaluatorStringModT<Plane>>(Variant::OP_MODULE, Variant::STRING, Variant::PLANE);
register_op<OperatorEvaluatorStringModT<Quaternion>>(Variant::OP_MODULE, Variant::STRING, Variant::QUATERNION);
register_op<OperatorEvaluatorStringModT<::AABB>>(Variant::OP_MODULE, Variant::STRING, Variant::AABB);
register_op<OperatorEvaluatorStringModT<Basis>>(Variant::OP_MODULE, Variant::STRING, Variant::BASIS);
register_op<OperatorEvaluatorStringModT<Transform3D>>(Variant::OP_MODULE, Variant::STRING, Variant::TRANSFORM3D);
+ register_op<OperatorEvaluatorStringModT<Projection>>(Variant::OP_MODULE, Variant::STRING, Variant::PROJECTION);
register_op<OperatorEvaluatorStringModT<Color>>(Variant::OP_MODULE, Variant::STRING, Variant::COLOR);
register_op<OperatorEvaluatorStringModT<StringName>>(Variant::OP_MODULE, Variant::STRING, Variant::STRING_NAME);
@@ -372,6 +471,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorNeg<Vector2i, Vector2i>>(Variant::OP_NEGATE, Variant::VECTOR2I, Variant::NIL);
register_op<OperatorEvaluatorNeg<Vector3, Vector3>>(Variant::OP_NEGATE, Variant::VECTOR3, Variant::NIL);
register_op<OperatorEvaluatorNeg<Vector3i, Vector3i>>(Variant::OP_NEGATE, Variant::VECTOR3I, Variant::NIL);
+ register_op<OperatorEvaluatorNeg<Vector4, Vector4>>(Variant::OP_NEGATE, Variant::VECTOR4, Variant::NIL);
+ register_op<OperatorEvaluatorNeg<Vector4i, Vector4i>>(Variant::OP_NEGATE, Variant::VECTOR4I, Variant::NIL);
register_op<OperatorEvaluatorNeg<Quaternion, Quaternion>>(Variant::OP_NEGATE, Variant::QUATERNION, Variant::NIL);
register_op<OperatorEvaluatorNeg<Plane, Plane>>(Variant::OP_NEGATE, Variant::PLANE, Variant::NIL);
register_op<OperatorEvaluatorNeg<Color, Color>>(Variant::OP_NEGATE, Variant::COLOR, Variant::NIL);
@@ -382,6 +483,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorPos<Vector2i, Vector2i>>(Variant::OP_POSITIVE, Variant::VECTOR2I, Variant::NIL);
register_op<OperatorEvaluatorPos<Vector3, Vector3>>(Variant::OP_POSITIVE, Variant::VECTOR3, Variant::NIL);
register_op<OperatorEvaluatorPos<Vector3i, Vector3i>>(Variant::OP_POSITIVE, Variant::VECTOR3I, Variant::NIL);
+ register_op<OperatorEvaluatorPos<Vector4, Vector4>>(Variant::OP_POSITIVE, Variant::VECTOR4, Variant::NIL);
+ register_op<OperatorEvaluatorPos<Vector4i, Vector4i>>(Variant::OP_POSITIVE, Variant::VECTOR4I, Variant::NIL);
register_op<OperatorEvaluatorPos<Quaternion, Quaternion>>(Variant::OP_POSITIVE, Variant::QUATERNION, Variant::NIL);
register_op<OperatorEvaluatorPos<Plane, Plane>>(Variant::OP_POSITIVE, Variant::PLANE, Variant::NIL);
register_op<OperatorEvaluatorPos<Color, Color>>(Variant::OP_POSITIVE, Variant::COLOR, Variant::NIL);
@@ -409,11 +512,14 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorEqual<Vector3, Vector3>>(Variant::OP_EQUAL, Variant::VECTOR3, Variant::VECTOR3);
register_op<OperatorEvaluatorEqual<Vector3i, Vector3i>>(Variant::OP_EQUAL, Variant::VECTOR3I, Variant::VECTOR3I);
register_op<OperatorEvaluatorEqual<Transform2D, Transform2D>>(Variant::OP_EQUAL, Variant::TRANSFORM2D, Variant::TRANSFORM2D);
+ register_op<OperatorEvaluatorEqual<Vector4, Vector4>>(Variant::OP_EQUAL, Variant::VECTOR4, Variant::VECTOR4);
+ register_op<OperatorEvaluatorEqual<Vector4i, Vector4i>>(Variant::OP_EQUAL, Variant::VECTOR4I, Variant::VECTOR4I);
register_op<OperatorEvaluatorEqual<Plane, Plane>>(Variant::OP_EQUAL, Variant::PLANE, Variant::PLANE);
register_op<OperatorEvaluatorEqual<Quaternion, Quaternion>>(Variant::OP_EQUAL, Variant::QUATERNION, Variant::QUATERNION);
register_op<OperatorEvaluatorEqual<::AABB, ::AABB>>(Variant::OP_EQUAL, Variant::AABB, Variant::AABB);
register_op<OperatorEvaluatorEqual<Basis, Basis>>(Variant::OP_EQUAL, Variant::BASIS, Variant::BASIS);
register_op<OperatorEvaluatorEqual<Transform3D, Transform3D>>(Variant::OP_EQUAL, Variant::TRANSFORM3D, Variant::TRANSFORM3D);
+ register_op<OperatorEvaluatorEqual<Projection, Projection>>(Variant::OP_EQUAL, Variant::PROJECTION, Variant::PROJECTION);
register_op<OperatorEvaluatorEqual<Color, Color>>(Variant::OP_EQUAL, Variant::COLOR, Variant::COLOR);
register_op<OperatorEvaluatorEqual<StringName, String>>(Variant::OP_EQUAL, Variant::STRING_NAME, Variant::STRING);
@@ -451,6 +557,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::RECT2I, Variant::NIL>>(Variant::OP_EQUAL, Variant::RECT2I, Variant::NIL);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::VECTOR3, Variant::NIL>>(Variant::OP_EQUAL, Variant::VECTOR3, Variant::NIL);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::VECTOR3I, Variant::NIL>>(Variant::OP_EQUAL, Variant::VECTOR3I, Variant::NIL);
+ register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::VECTOR4, Variant::NIL>>(Variant::OP_EQUAL, Variant::VECTOR4, Variant::NIL);
+ register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::VECTOR4I, Variant::NIL>>(Variant::OP_EQUAL, Variant::VECTOR4I, Variant::NIL);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::TRANSFORM2D, Variant::NIL>>(Variant::OP_EQUAL, Variant::TRANSFORM2D, Variant::NIL);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::PLANE, Variant::NIL>>(Variant::OP_EQUAL, Variant::PLANE, Variant::NIL);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::QUATERNION, Variant::NIL>>(Variant::OP_EQUAL, Variant::QUATERNION, Variant::NIL);
@@ -485,6 +593,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::RECT2I>>(Variant::OP_EQUAL, Variant::NIL, Variant::RECT2I);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::VECTOR3>>(Variant::OP_EQUAL, Variant::NIL, Variant::VECTOR3);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::VECTOR3I>>(Variant::OP_EQUAL, Variant::NIL, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::VECTOR4>>(Variant::OP_EQUAL, Variant::NIL, Variant::VECTOR4);
+ register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::VECTOR4I>>(Variant::OP_EQUAL, Variant::NIL, Variant::VECTOR4I);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::TRANSFORM2D>>(Variant::OP_EQUAL, Variant::NIL, Variant::TRANSFORM2D);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::PLANE>>(Variant::OP_EQUAL, Variant::NIL, Variant::PLANE);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::QUATERNION>>(Variant::OP_EQUAL, Variant::NIL, Variant::QUATERNION);
@@ -522,12 +632,15 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorNotEqual<Rect2i, Rect2i>>(Variant::OP_NOT_EQUAL, Variant::RECT2I, Variant::RECT2I);
register_op<OperatorEvaluatorNotEqual<Vector3, Vector3>>(Variant::OP_NOT_EQUAL, Variant::VECTOR3, Variant::VECTOR3);
register_op<OperatorEvaluatorNotEqual<Vector3i, Vector3i>>(Variant::OP_NOT_EQUAL, Variant::VECTOR3I, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorNotEqual<Vector4, Vector4>>(Variant::OP_NOT_EQUAL, Variant::VECTOR4, Variant::VECTOR4);
+ register_op<OperatorEvaluatorNotEqual<Vector4i, Vector4i>>(Variant::OP_NOT_EQUAL, Variant::VECTOR4I, Variant::VECTOR4I);
register_op<OperatorEvaluatorNotEqual<Transform2D, Transform2D>>(Variant::OP_NOT_EQUAL, Variant::TRANSFORM2D, Variant::TRANSFORM2D);
register_op<OperatorEvaluatorNotEqual<Plane, Plane>>(Variant::OP_NOT_EQUAL, Variant::PLANE, Variant::PLANE);
register_op<OperatorEvaluatorNotEqual<Quaternion, Quaternion>>(Variant::OP_NOT_EQUAL, Variant::QUATERNION, Variant::QUATERNION);
register_op<OperatorEvaluatorNotEqual<::AABB, ::AABB>>(Variant::OP_NOT_EQUAL, Variant::AABB, Variant::AABB);
register_op<OperatorEvaluatorNotEqual<Basis, Basis>>(Variant::OP_NOT_EQUAL, Variant::BASIS, Variant::BASIS);
register_op<OperatorEvaluatorNotEqual<Transform3D, Transform3D>>(Variant::OP_NOT_EQUAL, Variant::TRANSFORM3D, Variant::TRANSFORM3D);
+ register_op<OperatorEvaluatorNotEqual<Projection, Projection>>(Variant::OP_NOT_EQUAL, Variant::PROJECTION, Variant::PROJECTION);
register_op<OperatorEvaluatorNotEqual<Color, Color>>(Variant::OP_NOT_EQUAL, Variant::COLOR, Variant::COLOR);
register_op<OperatorEvaluatorNotEqual<StringName, String>>(Variant::OP_NOT_EQUAL, Variant::STRING_NAME, Variant::STRING);
@@ -566,6 +679,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::VECTOR3, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::VECTOR3, Variant::NIL);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::VECTOR3I, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::VECTOR3I, Variant::NIL);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::TRANSFORM2D, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::TRANSFORM2D, Variant::NIL);
+ register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::VECTOR4, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::VECTOR4, Variant::NIL);
+ register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::VECTOR4I, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::VECTOR4I, Variant::NIL);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::PLANE, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::PLANE, Variant::NIL);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::QUATERNION, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::QUATERNION, Variant::NIL);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::AABB, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::AABB, Variant::NIL);
@@ -599,6 +714,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::RECT2I>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::RECT2I);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::VECTOR3>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::VECTOR3);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::VECTOR3I>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::VECTOR4>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::VECTOR4);
+ register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::VECTOR4I>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::VECTOR4I);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::TRANSFORM2D>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::TRANSFORM2D);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PLANE>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PLANE);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::QUATERNION>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::QUATERNION);
@@ -634,6 +751,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorLess<Vector2i, Vector2i>>(Variant::OP_LESS, Variant::VECTOR2I, Variant::VECTOR2I);
register_op<OperatorEvaluatorLess<Vector3, Vector3>>(Variant::OP_LESS, Variant::VECTOR3, Variant::VECTOR3);
register_op<OperatorEvaluatorLess<Vector3i, Vector3i>>(Variant::OP_LESS, Variant::VECTOR3I, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorLess<Vector4, Vector4>>(Variant::OP_LESS, Variant::VECTOR4, Variant::VECTOR4);
+ register_op<OperatorEvaluatorLess<Vector4i, Vector4i>>(Variant::OP_LESS, Variant::VECTOR4I, Variant::VECTOR4I);
register_op<OperatorEvaluatorLess<::RID, ::RID>>(Variant::OP_LESS, Variant::RID, Variant::RID);
register_op<OperatorEvaluatorLess<Array, Array>>(Variant::OP_LESS, Variant::ARRAY, Variant::ARRAY);
@@ -647,6 +766,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorLessEqual<Vector2i, Vector2i>>(Variant::OP_LESS_EQUAL, Variant::VECTOR2I, Variant::VECTOR2I);
register_op<OperatorEvaluatorLessEqual<Vector3, Vector3>>(Variant::OP_LESS_EQUAL, Variant::VECTOR3, Variant::VECTOR3);
register_op<OperatorEvaluatorLessEqual<Vector3i, Vector3i>>(Variant::OP_LESS_EQUAL, Variant::VECTOR3I, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorLessEqual<Vector4, Vector4>>(Variant::OP_LESS_EQUAL, Variant::VECTOR4, Variant::VECTOR4);
+ register_op<OperatorEvaluatorLessEqual<Vector4i, Vector4i>>(Variant::OP_LESS_EQUAL, Variant::VECTOR4I, Variant::VECTOR4I);
register_op<OperatorEvaluatorLessEqual<::RID, ::RID>>(Variant::OP_LESS_EQUAL, Variant::RID, Variant::RID);
register_op<OperatorEvaluatorLessEqual<Array, Array>>(Variant::OP_LESS_EQUAL, Variant::ARRAY, Variant::ARRAY);
@@ -661,6 +782,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorGreater<Vector2i, Vector2i>>(Variant::OP_GREATER, Variant::VECTOR2I, Variant::VECTOR2I);
register_op<OperatorEvaluatorGreater<Vector3, Vector3>>(Variant::OP_GREATER, Variant::VECTOR3, Variant::VECTOR3);
register_op<OperatorEvaluatorGreater<Vector3i, Vector3i>>(Variant::OP_GREATER, Variant::VECTOR3I, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorGreater<Vector4, Vector4>>(Variant::OP_GREATER, Variant::VECTOR4, Variant::VECTOR4);
+ register_op<OperatorEvaluatorGreater<Vector4i, Vector4i>>(Variant::OP_GREATER, Variant::VECTOR4I, Variant::VECTOR4I);
register_op<OperatorEvaluatorGreater<::RID, ::RID>>(Variant::OP_GREATER, Variant::RID, Variant::RID);
register_op<OperatorEvaluatorGreater<Array, Array>>(Variant::OP_GREATER, Variant::ARRAY, Variant::ARRAY);
@@ -674,6 +797,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorGreaterEqual<Vector2i, Vector2i>>(Variant::OP_GREATER_EQUAL, Variant::VECTOR2I, Variant::VECTOR2I);
register_op<OperatorEvaluatorGreaterEqual<Vector3, Vector3>>(Variant::OP_GREATER_EQUAL, Variant::VECTOR3, Variant::VECTOR3);
register_op<OperatorEvaluatorGreaterEqual<Vector3i, Vector3i>>(Variant::OP_GREATER_EQUAL, Variant::VECTOR3I, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorGreaterEqual<Vector4, Vector4>>(Variant::OP_GREATER_EQUAL, Variant::VECTOR4, Variant::VECTOR4);
+ register_op<OperatorEvaluatorGreaterEqual<Vector4i, Vector4i>>(Variant::OP_GREATER_EQUAL, Variant::VECTOR4I, Variant::VECTOR4I);
register_op<OperatorEvaluatorGreaterEqual<::RID, ::RID>>(Variant::OP_GREATER_EQUAL, Variant::RID, Variant::RID);
register_op<OperatorEvaluatorGreaterEqual<Array, Array>>(Variant::OP_GREATER_EQUAL, Variant::ARRAY, Variant::ARRAY);
@@ -788,12 +913,15 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorInDictionaryHas<Rect2i>>(Variant::OP_IN, Variant::RECT2I, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<Vector3>>(Variant::OP_IN, Variant::VECTOR3, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<Vector3i>>(Variant::OP_IN, Variant::VECTOR3I, Variant::DICTIONARY);
+ register_op<OperatorEvaluatorInDictionaryHas<Vector4>>(Variant::OP_IN, Variant::VECTOR4, Variant::DICTIONARY);
+ register_op<OperatorEvaluatorInDictionaryHas<Vector4i>>(Variant::OP_IN, Variant::VECTOR4I, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<Transform2D>>(Variant::OP_IN, Variant::TRANSFORM2D, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<Plane>>(Variant::OP_IN, Variant::PLANE, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<Quaternion>>(Variant::OP_IN, Variant::QUATERNION, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<::AABB>>(Variant::OP_IN, Variant::AABB, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<Basis>>(Variant::OP_IN, Variant::BASIS, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<Transform3D>>(Variant::OP_IN, Variant::TRANSFORM3D, Variant::DICTIONARY);
+ register_op<OperatorEvaluatorInDictionaryHas<Projection>>(Variant::OP_IN, Variant::PROJECTION, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<Color>>(Variant::OP_IN, Variant::COLOR, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<StringName>>(Variant::OP_IN, Variant::STRING_NAME, Variant::DICTIONARY);
@@ -825,12 +953,15 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorInArrayFind<Rect2i, Array>>(Variant::OP_IN, Variant::RECT2I, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<Vector3, Array>>(Variant::OP_IN, Variant::VECTOR3, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<Vector3i, Array>>(Variant::OP_IN, Variant::VECTOR3I, Variant::ARRAY);
+ register_op<OperatorEvaluatorInArrayFind<Vector4, Array>>(Variant::OP_IN, Variant::VECTOR4, Variant::ARRAY);
+ register_op<OperatorEvaluatorInArrayFind<Vector4i, Array>>(Variant::OP_IN, Variant::VECTOR4I, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<Transform2D, Array>>(Variant::OP_IN, Variant::TRANSFORM2D, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<Plane, Array>>(Variant::OP_IN, Variant::PLANE, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<Quaternion, Array>>(Variant::OP_IN, Variant::QUATERNION, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<::AABB, Array>>(Variant::OP_IN, Variant::AABB, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<Basis, Array>>(Variant::OP_IN, Variant::BASIS, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<Transform3D, Array>>(Variant::OP_IN, Variant::TRANSFORM3D, Variant::ARRAY);
+ register_op<OperatorEvaluatorInArrayFind<Projection, Array>>(Variant::OP_IN, Variant::PROJECTION, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<Color, Array>>(Variant::OP_IN, Variant::COLOR, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<StringName, Array>>(Variant::OP_IN, Variant::STRING_NAME, Variant::ARRAY);
diff --git a/core/variant/variant_op.h b/core/variant/variant_op.h
index 3e9bae1078..ec1ce67445 100644
--- a/core/variant/variant_op.h
+++ b/core/variant/variant_op.h
@@ -234,6 +234,30 @@ public:
static Variant::Type get_return_type() { return GetTypeInfo<Vector3i>::VARIANT_TYPE; }
};
+template <>
+class OperatorEvaluatorDivNZ<Vector4i, Vector4i, Vector4i> {
+public:
+ static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
+ const Vector4i &a = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_left);
+ const Vector4i &b = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_right);
+ if (unlikely(b.x == 0 || b.y == 0 || b.z == 0 || b.w == 0)) {
+ r_valid = false;
+ *r_ret = "Division by zero error";
+ return;
+ }
+ *r_ret = a / b;
+ r_valid = true;
+ }
+ static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
+ VariantTypeChanger<Vector4i>::change(r_ret);
+ *VariantGetInternalPtr<Vector4i>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector4i>::get_ptr(left) / *VariantGetInternalPtr<Vector4i>::get_ptr(right);
+ }
+ static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
+ PtrToArg<Vector4i>::encode(PtrToArg<Vector4i>::convert(left) / PtrToArg<Vector4i>::convert(right), r_ret);
+ }
+ static Variant::Type get_return_type() { return GetTypeInfo<Vector4i>::VARIANT_TYPE; }
+};
+
template <class R, class A, class B>
class OperatorEvaluatorMod {
public:
@@ -323,6 +347,30 @@ public:
static Variant::Type get_return_type() { return GetTypeInfo<Vector3i>::VARIANT_TYPE; }
};
+template <>
+class OperatorEvaluatorModNZ<Vector4i, Vector4i, Vector4i> {
+public:
+ static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
+ const Vector4i &a = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_left);
+ const Vector4i &b = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_right);
+ if (unlikely(b.x == 0 || b.y == 0 || b.z == 0 || b.w == 0)) {
+ r_valid = false;
+ *r_ret = "Module by zero error";
+ return;
+ }
+ *r_ret = a % b;
+ r_valid = true;
+ }
+ static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
+ VariantTypeChanger<Vector4i>::change(r_ret);
+ *VariantGetInternalPtr<Vector4i>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector4i>::get_ptr(left) % *VariantGetInternalPtr<Vector4i>::get_ptr(right);
+ }
+ static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
+ PtrToArg<Vector4i>::encode(PtrToArg<Vector4i>::convert(left) % PtrToArg<Vector4i>::convert(right), r_ret);
+ }
+ static Variant::Type get_return_type() { return GetTypeInfo<Vector4i>::VARIANT_TYPE; }
+};
+
template <class R, class A>
class OperatorEvaluatorNeg {
public:
diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp
index 259ca8a60d..1df5fa969e 100644
--- a/core/variant/variant_parser.cpp
+++ b/core/variant/variant_parser.cpp
@@ -649,6 +649,32 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = Vector3i(args[0], args[1], args[2]);
+ } else if (id == "Vector4") {
+ Vector<real_t> args;
+ Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str);
+ if (err) {
+ return err;
+ }
+
+ if (args.size() != 4) {
+ r_err_str = "Expected 4 arguments for constructor";
+ return ERR_PARSE_ERROR;
+ }
+
+ value = Vector4(args[0], args[1], args[2], args[3]);
+ } else if (id == "Vector4i") {
+ Vector<int32_t> args;
+ Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
+ if (err) {
+ return err;
+ }
+
+ if (args.size() != 4) {
+ r_err_str = "Expected 4 arguments for constructor";
+ return ERR_PARSE_ERROR;
+ }
+
+ value = Vector4i(args[0], args[1], args[2], args[3]);
} else if (id == "Transform2D" || id == "Matrix32") { //compatibility
Vector<real_t> args;
Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str);
@@ -731,6 +757,19 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = Transform3D(Basis(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]), Vector3(args[9], args[10], args[11]));
+ } else if (id == "Projection") { // "Transform" kept for compatibility with Godot <4.
+ Vector<real_t> args;
+ Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str);
+ if (err) {
+ return err;
+ }
+
+ if (args.size() != 16) {
+ r_err_str = "Expected 16 arguments for constructor";
+ return ERR_PARSE_ERROR;
+ }
+
+ value = Projection(Vector4(args[0], args[1], args[2], args[3]), Vector4(args[4], args[5], args[6], args[7]), Vector4(args[8], args[9], args[10], args[11]), Vector4(args[12], args[13], args[14], args[15]));
} else if (id == "Color") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -1534,6 +1573,14 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
Vector3i v = p_variant;
p_store_string_func(p_store_string_ud, "Vector3i(" + itos(v.x) + ", " + itos(v.y) + ", " + itos(v.z) + ")");
} break;
+ case Variant::VECTOR4: {
+ Vector4 v = p_variant;
+ p_store_string_func(p_store_string_ud, "Vector4(" + rtos_fix(v.x) + ", " + rtos_fix(v.y) + ", " + rtos_fix(v.z) + ")");
+ } break;
+ case Variant::VECTOR4I: {
+ Vector4i v = p_variant;
+ p_store_string_func(p_store_string_ud, "Vector4i(" + itos(v.x) + ", " + itos(v.y) + ", " + itos(v.z) + ")");
+ } break;
case Variant::PLANE: {
Plane p = p_variant;
p_store_string_func(p_store_string_ud, "Plane(" + rtos_fix(p.normal.x) + ", " + rtos_fix(p.normal.y) + ", " + rtos_fix(p.normal.z) + ", " + rtos_fix(p.d) + ")");
@@ -1596,6 +1643,20 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud, s + ")");
} break;
+ case Variant::PROJECTION: {
+ String s = "Projection(";
+ Projection t = p_variant;
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ if (i != 0 || j != 0) {
+ s += ", ";
+ }
+ s += rtos_fix(t.matrix[i][j]);
+ }
+ }
+
+ p_store_string_func(p_store_string_ud, s + ")");
+ } break;
// misc types
case Variant::COLOR: {
diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp
index 3839da495f..92dbf45f2a 100644
--- a/core/variant/variant_setget.cpp
+++ b/core/variant/variant_setget.cpp
@@ -77,6 +77,16 @@ void register_named_setters_getters() {
REGISTER_MEMBER(Vector3i, y);
REGISTER_MEMBER(Vector3i, z);
+ REGISTER_MEMBER(Vector4, x);
+ REGISTER_MEMBER(Vector4, y);
+ REGISTER_MEMBER(Vector4, z);
+ REGISTER_MEMBER(Vector4, w);
+
+ REGISTER_MEMBER(Vector4i, x);
+ REGISTER_MEMBER(Vector4i, y);
+ REGISTER_MEMBER(Vector4i, z);
+ REGISTER_MEMBER(Vector4i, w);
+
REGISTER_MEMBER(Rect2, position);
REGISTER_MEMBER(Rect2, size);
REGISTER_MEMBER(Rect2, end);
@@ -111,6 +121,11 @@ void register_named_setters_getters() {
REGISTER_MEMBER(Transform3D, basis);
REGISTER_MEMBER(Transform3D, origin);
+ REGISTER_MEMBER(Projection, x);
+ REGISTER_MEMBER(Projection, y);
+ REGISTER_MEMBER(Projection, z);
+ REGISTER_MEMBER(Projection, w);
+
REGISTER_MEMBER(Color, r);
REGISTER_MEMBER(Color, g);
REGISTER_MEMBER(Color, b);
@@ -809,6 +824,7 @@ INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(Color, double, float, 4)
INDEXED_SETGET_STRUCT_BULTIN_ACCESSOR(Transform2D, Vector2, .columns, 3)
INDEXED_SETGET_STRUCT_BULTIN_FUNC(Basis, Vector3, set_column, get_column, 3)
+INDEXED_SETGET_STRUCT_BULTIN_ACCESSOR(Projection, Vector4, .matrix, 4)
INDEXED_SETGET_STRUCT_TYPED_NUMERIC(PackedByteArray, int64_t, uint8_t)
INDEXED_SETGET_STRUCT_TYPED_NUMERIC(PackedInt32Array, int64_t, int32_t)
@@ -871,6 +887,7 @@ void register_indexed_setters_getters() {
REGISTER_INDEXED_MEMBER(Color);
REGISTER_INDEXED_MEMBER(Transform2D);
REGISTER_INDEXED_MEMBER(Basis);
+ REGISTER_INDEXED_MEMBER(Projection);
REGISTER_INDEXED_MEMBER(PackedByteArray);
REGISTER_INDEXED_MEMBER(PackedInt32Array);
diff --git a/core/variant/variant_setget.h b/core/variant/variant_setget.h
index bc4dc4b408..570277dc7a 100644
--- a/core/variant/variant_setget.h
+++ b/core/variant/variant_setget.h
@@ -281,6 +281,16 @@ SETGET_NUMBER_STRUCT(Vector3i, int64_t, x)
SETGET_NUMBER_STRUCT(Vector3i, int64_t, y)
SETGET_NUMBER_STRUCT(Vector3i, int64_t, z)
+SETGET_NUMBER_STRUCT(Vector4, double, x)
+SETGET_NUMBER_STRUCT(Vector4, double, y)
+SETGET_NUMBER_STRUCT(Vector4, double, z)
+SETGET_NUMBER_STRUCT(Vector4, double, w)
+
+SETGET_NUMBER_STRUCT(Vector4i, int64_t, x)
+SETGET_NUMBER_STRUCT(Vector4i, int64_t, y)
+SETGET_NUMBER_STRUCT(Vector4i, int64_t, z)
+SETGET_NUMBER_STRUCT(Vector4i, int64_t, w)
+
SETGET_STRUCT(Rect2, Vector2, position)
SETGET_STRUCT(Rect2, Vector2, size)
SETGET_STRUCT_FUNC(Rect2, Vector2, end, set_end, get_end)
@@ -315,6 +325,11 @@ SETGET_STRUCT_FUNC_INDEX(Basis, Vector3, z, set_column, get_column, 2)
SETGET_STRUCT(Transform3D, Basis, basis)
SETGET_STRUCT(Transform3D, Vector3, origin)
+SETGET_STRUCT_CUSTOM(Projection, Vector4, x, matrix[0])
+SETGET_STRUCT_CUSTOM(Projection, Vector4, y, matrix[1])
+SETGET_STRUCT_CUSTOM(Projection, Vector4, z, matrix[2])
+SETGET_STRUCT_CUSTOM(Projection, Vector4, w, matrix[3])
+
SETGET_NUMBER_STRUCT(Color, double, r)
SETGET_NUMBER_STRUCT(Color, double, g)
SETGET_NUMBER_STRUCT(Color, double, b)
diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp
index 2bca5f8284..c1a0ad73b0 100644
--- a/core/variant/variant_utility.cpp
+++ b/core/variant/variant_utility.cpp
@@ -132,6 +132,12 @@ struct VariantUtilityFunctions {
case Variant::VECTOR3I: {
return VariantInternalAccessor<Vector3i>::get(&x).abs();
} break;
+ case Variant::VECTOR4: {
+ return VariantInternalAccessor<Vector4>::get(&x).abs();
+ } break;
+ case Variant::VECTOR4I: {
+ return VariantInternalAccessor<Vector4i>::get(&x).abs();
+ } break;
default: {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
return Variant();
@@ -168,6 +174,12 @@ struct VariantUtilityFunctions {
case Variant::VECTOR3I: {
return VariantInternalAccessor<Vector3i>::get(&x).sign();
} break;
+ case Variant::VECTOR4: {
+ return VariantInternalAccessor<Vector4>::get(&x).sign();
+ } break;
+ case Variant::VECTOR4I: {
+ return VariantInternalAccessor<Vector4i>::get(&x).sign();
+ } break;
default: {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
return Variant();