From 2346bba15973212158efd8c145e9be860e7f51dd Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 30 May 2023 00:49:24 +0200 Subject: [PATCH] Implemented the new apis for Transform. --- gdnative/transform.cpp | 153 ++++++++++++++++++++++++++++++++++++++++ include/gdn/transform.h | 55 ++++++++------- 2 files changed, 181 insertions(+), 27 deletions(-) diff --git a/gdnative/transform.cpp b/gdnative/transform.cpp index b0ebe6f..2cdb4f3 100644 --- a/gdnative/transform.cpp +++ b/gdnative/transform.cpp @@ -39,6 +39,11 @@ extern "C" { static_assert(sizeof(pandemonium_transform) == sizeof(Transform), "Transform size mismatch"); +void GDAPI pandemonium_transform_invert(pandemonium_transform *p_self) { + Transform *self = (Transform *)p_self; + self->invert(); +} + pandemonium_transform GDAPI pandemonium_transform_inverse(const pandemonium_transform *p_self) { pandemonium_transform dest; const Transform *self = (const Transform *)p_self; @@ -46,6 +51,10 @@ pandemonium_transform GDAPI pandemonium_transform_inverse(const pandemonium_tran return dest; } +void GDAPI pandemonium_transform_affine_invert(pandemonium_transform *p_self) { + Transform *self = (Transform *)p_self; + self->affine_invert(); +} pandemonium_transform GDAPI pandemonium_transform_affine_inverse(const pandemonium_transform *p_self) { pandemonium_transform dest; const Transform *self = (const Transform *)p_self; @@ -60,6 +69,37 @@ pandemonium_transform GDAPI pandemonium_transform_rotated(const pandemonium_tran *((Transform *)&dest) = self->rotated(*axis, p_phi); return dest; } +pandemonium_transform GDAPI pandemonium_transform_rotated_local(const pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, pandemonium_real p_phi) { + pandemonium_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + *((Transform *)&dest) = self->rotated_local(*axis, p_phi); + return dest; +} + +void GDAPI pandemonium_transform_rotate(pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, pandemonium_real p_phi) { + Transform *self = (Transform *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + self->rotate(*axis, p_phi); +} +void GDAPI pandemonium_transform_rotate_local(pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, pandemonium_real p_phi) { + Transform *self = (Transform *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + self->rotate_local(*axis, p_phi); +} +void GDAPI pandemonium_transform_rotate_basis(pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, pandemonium_real p_phi) { + Transform *self = (Transform *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + self->rotate_basis(*axis, p_phi); +} + +void GDAPI pandemonium_transform_set_look_at(pandemonium_transform *p_self, const pandemonium_vector3 *p_eye, const pandemonium_vector3 *p_target, const pandemonium_vector3 *p_up) { + Transform *self = (Transform *)p_self; + const Vector3 *eye = (const Vector3 *)p_eye; + const Vector3 *target = (const Vector3 *)p_target; + const Vector3 *up = (const Vector3 *)p_up; + self->set_look_at(*eye, *target, *up); +} pandemonium_transform GDAPI pandemonium_transform_looking_at(const pandemonium_transform *p_self, const pandemonium_vector3 *p_target, const pandemonium_vector3 *p_up) { pandemonium_transform dest; @@ -70,6 +110,11 @@ pandemonium_transform GDAPI pandemonium_transform_looking_at(const pandemonium_t return dest; } +void GDAPI pandemonium_transform_scale(pandemonium_transform *p_self, const pandemonium_vector3 *p_scale) { + Transform *self = (Transform *)p_self; + const Vector3 *scale = (const Vector3 *)p_scale; + self->scale(*scale); +} pandemonium_transform GDAPI pandemonium_transform_scaled(const pandemonium_transform *p_self, const pandemonium_vector3 *p_scale) { pandemonium_transform dest; const Transform *self = (const Transform *)p_self; @@ -78,6 +123,29 @@ pandemonium_transform GDAPI pandemonium_transform_scaled(const pandemonium_trans return dest; } +pandemonium_transform GDAPI pandemonium_transform_scaled_local(const pandemonium_transform *p_self, const pandemonium_vector3 *p_scale) { + pandemonium_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *scale = (const Vector3 *)p_scale; + *((Transform *)&dest) = self->scaled_local(*scale); + return dest; +} +void GDAPI pandemonium_transform_scale_basis(pandemonium_transform *p_self, const pandemonium_vector3 *p_scale) { + Transform *self = (Transform *)p_self; + const Vector3 *scale = (const Vector3 *)p_scale; + self->scale_basis(*scale); +} + +void GDAPI pandemonium_transform_translate_localr(pandemonium_transform *p_self, pandemonium_real p_tx, pandemonium_real p_ty, pandemonium_real p_tz) { + Transform *self = (Transform *)p_self; + self->translate_localr(p_tx, p_ty, p_tz); +} +void GDAPI pandemonium_transform_translate_localv(pandemonium_transform *p_self, const pandemonium_vector3 *p_translation) { + Transform *self = (Transform *)p_self; + const Vector3 *translation = (const Vector3 *)p_translation; + self->translate_localv(*translation); +} + pandemonium_transform GDAPI pandemonium_transform_translated(const pandemonium_transform *p_self, const pandemonium_vector3 *p_ofs) { pandemonium_transform dest; const Transform *self = (const Transform *)p_self; @@ -85,6 +153,13 @@ pandemonium_transform GDAPI pandemonium_transform_translated(const pandemonium_t *((Transform *)&dest) = self->translated(*ofs); return dest; } +pandemonium_transform GDAPI pandemonium_transform_translated_local(const pandemonium_transform *p_self, const pandemonium_vector3 *p_translation) { + pandemonium_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *translation = (const Vector3 *)p_translation; + *((Transform *)&dest) = self->translated_local(*translation); + return dest; +} pandemonium_basis GDAPI pandemonium_transform_get_basis(const pandemonium_transform *p_self) { pandemonium_basis dest; @@ -112,12 +187,31 @@ void GDAPI pandemonium_transform_set_origin(pandemonium_transform *p_self, const self->origin = *v; } +void GDAPI pandemonium_transform_orthonormalize(pandemonium_transform *p_self) { + Transform *self = (Transform *)p_self; + self->orthonormalize(); +} pandemonium_transform GDAPI pandemonium_transform_orthonormalized(const pandemonium_transform *p_self) { pandemonium_transform dest; const Transform *self = (const Transform *)p_self; *((Transform *)&dest) = self->orthonormalized(); return dest; } +void GDAPI pandemonium_transform_orthogonalize(pandemonium_transform *p_self) { + Transform *self = (Transform *)p_self; + self->orthogonalize(); +} +pandemonium_transform GDAPI pandemonium_transform_orthogonalized(const pandemonium_transform *p_self) { + pandemonium_transform dest; + const Transform *self = (const Transform *)p_self; + *((Transform *)&dest) = self->orthogonalized(); + return dest; +} +pandemonium_bool GDAPI pandemonium_transform_is_equal_approx(const pandemonium_transform *p_self, const pandemonium_transform *p_transform) { + const Transform *self = (const Transform *)p_self; + const Transform *transform = (const Transform *)p_transform; + return self->is_equal_approx(*transform); +} pandemonium_bool GDAPI pandemonium_transform_operator_equal(const pandemonium_transform *p_self, const pandemonium_transform *p_b) { const Transform *self = (const Transform *)p_self; @@ -133,6 +227,13 @@ pandemonium_vector3 GDAPI pandemonium_transform_xform_vector3(const pandemonium_ *dest = self->xform(*v); return raw_dest; } +pandemonium_vector3i GDAPI pandemonium_transform_xform_vector3i(const pandemonium_transform *p_self, const pandemonium_vector3i *p_vector) { + pandemonium_vector3i dest; + const Transform *self = (const Transform *)p_self; + const Vector3i *vector = (const Vector3i *)p_vector; + *((Vector3i *)&dest) = self->xform(*vector); + return dest; +} pandemonium_aabb GDAPI pandemonium_transform_xform_aabb(const pandemonium_transform *p_self, const pandemonium_aabb *p_v) { pandemonium_aabb raw_dest; @@ -152,6 +253,14 @@ pandemonium_vector3 GDAPI pandemonium_transform_xform_inv_vector3(const pandemon return raw_dest; } +pandemonium_vector3i GDAPI pandemonium_transform_xform_inv_vector3i(const pandemonium_transform *p_self, const pandemonium_vector3i *p_vector) { + pandemonium_vector3i dest; + const Transform *self = (const Transform *)p_self; + const Vector3i *vector = (const Vector3i *)p_vector; + *((Vector3i *)&dest) = self->xform_inv(*vector); + return dest; +} + pandemonium_aabb GDAPI pandemonium_transform_xform_inv_aabb(const pandemonium_transform *p_self, const pandemonium_aabb *p_v) { pandemonium_aabb raw_dest; AABB *dest = (AABB *)&raw_dest; @@ -179,6 +288,23 @@ pandemonium_plane GDAPI pandemonium_transform_xform_inv_plane(const pandemonium_ return raw_dest; } +pandemonium_plane GDAPI pandemonium_transform_xform_fast(const pandemonium_transform *p_self, const pandemonium_plane *p_plane, const pandemonium_basis *p_basis_inverse_transpose) { + pandemonium_plane dest; + const Transform *self = (const Transform *)p_self; + const Plane *plane = (const Plane *)p_plane; + const Basis *basis_inverse_transpose = (const Basis *)p_basis_inverse_transpose; + *((Plane *)&dest) = self->xform_fast(*plane, *basis_inverse_transpose); + return dest; +} +pandemonium_plane GDAPI pandemonium_transform_xform_inv_fast(const pandemonium_plane *p_plane, const pandemonium_transform *p_inverse, const pandemonium_basis *p_basis_transpose) { + pandemonium_plane dest; + const Plane *plane = (const Plane *)p_plane; + const Transform *inverse = (const Transform *)p_inverse; + const Basis *basis_transpose = (const Basis *)p_basis_transpose; + *((Plane *)&dest) = Transform::xform_inv_fast(*plane, *inverse, *basis_transpose); + return dest; +} + pandemonium_transform GDAPI pandemonium_transform_operator_multiply(const pandemonium_transform *p_self, const pandemonium_transform *p_b) { pandemonium_transform raw_dest; Transform *dest = (Transform *)&raw_dest; @@ -188,6 +314,33 @@ pandemonium_transform GDAPI pandemonium_transform_operator_multiply(const pandem return raw_dest; } +pandemonium_transform GDAPI pandemonium_transform_spherical_interpolate_with(const pandemonium_transform *p_self, const pandemonium_transform *p_transform, pandemonium_real p_c) { + pandemonium_transform dest; + const Transform *self = (const Transform *)p_self; + const Transform *transform = (const Transform *)p_transform; + *((Transform *)&dest) = self->spherical_interpolate_with(*transform, p_c); + return dest; +} +pandemonium_transform GDAPI pandemonium_transform_interpolate_with(const pandemonium_transform *p_self, const pandemonium_transform *p_transform, pandemonium_real p_c) { + pandemonium_transform dest; + const Transform *self = (const Transform *)p_self; + const Transform *transform = (const Transform *)p_transform; + *((Transform *)&dest) = self->interpolate_with(*transform, p_c); + return dest; +} + +pandemonium_transform GDAPI pandemonium_transform_inverse_xform(const pandemonium_transform *p_self, const pandemonium_transform *p_t) { + pandemonium_transform dest; + const Transform *self = (const Transform *)p_self; + const Transform *t = (const Transform *)p_t; + *((Transform *)&dest) = self->inverse_xform(*t); + return dest; +} +void GDAPI pandemonium_transform_set(pandemonium_transform *p_self, pandemonium_real xx, pandemonium_real xy, pandemonium_real xz, pandemonium_real yx, pandemonium_real yy, pandemonium_real yz, pandemonium_real zx, pandemonium_real zy, pandemonium_real zz, pandemonium_real tx, pandemonium_real ty, pandemonium_real tz) { + Transform *self = (Transform *)p_self; + self->set(xx, xy, xz, yx, yy, yz, zx, zy, zz, tx, ty, tz); +} + pandemonium_string GDAPI pandemonium_transform_as_string(const pandemonium_transform *p_self) { pandemonium_string ret; const Transform *self = (const Transform *)p_self; diff --git a/include/gdn/transform.h b/include/gdn/transform.h index 511d258..644aa5f 100644 --- a/include/gdn/transform.h +++ b/include/gdn/transform.h @@ -55,38 +55,39 @@ typedef struct { #include #include #include +#include #ifdef __cplusplus extern "C" { #endif -//void invert(); +void GDAPI pandemonium_transform_invert(pandemonium_transform *p_self); pandemonium_transform GDAPI pandemonium_transform_inverse(const pandemonium_transform *p_self); -//void affine_invert(); +void GDAPI pandemonium_transform_affine_invert(pandemonium_transform *p_self); pandemonium_transform GDAPI pandemonium_transform_affine_inverse(const pandemonium_transform *p_self); pandemonium_transform GDAPI pandemonium_transform_rotated(const pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, const pandemonium_real p_phi); -//Transform rotated_local(const Vector3 &p_axis, real_t p_phi) const; +pandemonium_transform GDAPI pandemonium_transform_rotated_local(const pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, pandemonium_real p_phi); -//void rotate(const Vector3 &p_axis, real_t p_phi); -//void rotate_local(const Vector3 &p_axis, real_t p_phi); -//void rotate_basis(const Vector3 &p_axis, real_t p_phi); +void GDAPI pandemonium_transform_rotate(pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, pandemonium_real p_phi); +void GDAPI pandemonium_transform_rotate_local(pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, pandemonium_real p_phi); +void GDAPI pandemonium_transform_rotate_basis(pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, pandemonium_real p_phi); + +void GDAPI pandemonium_transform_set_look_at(pandemonium_transform *p_self, const pandemonium_vector3 *p_eye, const pandemonium_vector3 *p_target, const pandemonium_vector3 *p_up); -//void set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const Vector3 &p_up); pandemonium_transform GDAPI pandemonium_transform_looking_at(const pandemonium_transform *p_self, const pandemonium_vector3 *p_target, const pandemonium_vector3 *p_up); -//void scale(const Vector3 &p_scale); +void GDAPI pandemonium_transform_scale(pandemonium_transform *p_self, const pandemonium_vector3 *p_scale); pandemonium_transform GDAPI pandemonium_transform_scaled(const pandemonium_transform *p_self, const pandemonium_vector3 *p_scale); -//Transform scaled_local(const Vector3 &p_scale) const; -//void scale_basis(const Vector3 &p_scale); +pandemonium_transform GDAPI pandemonium_transform_scaled_local(const pandemonium_transform *p_self, const pandemonium_vector3 *p_scale); +void GDAPI pandemonium_transform_scale_basis(pandemonium_transform *p_self, const pandemonium_vector3 *p_scale); + +void GDAPI pandemonium_transform_translate_localr(pandemonium_transform *p_self, pandemonium_real p_tx, pandemonium_real p_ty, pandemonium_real p_tz); +void GDAPI pandemonium_transform_translate_localv(pandemonium_transform *p_self, const pandemonium_vector3 *p_translation); -//void translate_local(real_t p_tx, real_t p_ty, real_t p_tz); -//void translate_local(const Vector3 &p_translation); -//void translate_localr(real_t p_tx, real_t p_ty, real_t p_tz); -//void translate_localv(const Vector3 &p_translation); pandemonium_transform GDAPI pandemonium_transform_translated(const pandemonium_transform *p_self, const pandemonium_vector3 *p_ofs); -//Transform translated_local(const Vector3 &p_translation) const; +pandemonium_transform GDAPI pandemonium_transform_translated_local(const pandemonium_transform *p_self, const pandemonium_vector3 *p_translation); pandemonium_basis GDAPI pandemonium_transform_get_basis(const pandemonium_transform *p_self); void GDAPI pandemonium_transform_set_basis(pandemonium_transform *p_self, const pandemonium_basis *p_v); @@ -94,22 +95,22 @@ void GDAPI pandemonium_transform_set_basis(pandemonium_transform *p_self, const pandemonium_vector3 GDAPI pandemonium_transform_get_origin(const pandemonium_transform *p_self); void GDAPI pandemonium_transform_set_origin(pandemonium_transform *p_self, const pandemonium_vector3 *p_v); -//void orthonormalize(); +void GDAPI pandemonium_transform_orthonormalize(pandemonium_transform *p_self); pandemonium_transform GDAPI pandemonium_transform_orthonormalized(const pandemonium_transform *p_self); -//void orthogonalize(); -//Transform orthogonalized() const; -//bool is_equal_approx(const Transform &p_transform) const; +void GDAPI pandemonium_transform_orthogonalize(pandemonium_transform *p_self); +pandemonium_transform GDAPI pandemonium_transform_orthogonalized(const pandemonium_transform *p_self); +pandemonium_bool GDAPI pandemonium_transform_is_equal_approx(const pandemonium_transform *p_self, const pandemonium_transform *p_transform); pandemonium_bool GDAPI pandemonium_transform_operator_equal(const pandemonium_transform *p_self, const pandemonium_transform *p_b); pandemonium_vector3 GDAPI pandemonium_transform_xform_vector3(const pandemonium_transform *p_self, const pandemonium_vector3 *p_v); -//_FORCE_INLINE_ Vector3i xform(const Vector3i &p_vector) const; +pandemonium_vector3i GDAPI pandemonium_transform_xform_vector3i(const pandemonium_transform *p_self, const pandemonium_vector3i *p_vector); pandemonium_aabb GDAPI pandemonium_transform_xform_aabb(const pandemonium_transform *p_self, const pandemonium_aabb *p_v); //_FORCE_INLINE_ PoolVector xform(const PoolVector &p_array) const; //_FORCE_INLINE_ PoolVector xform(const PoolVector &p_array) const; pandemonium_vector3 GDAPI pandemonium_transform_xform_inv_vector3(const pandemonium_transform *p_self, const pandemonium_vector3 *p_v); -//_FORCE_INLINE_ Vector3i xform_inv(const Vector3i &p_vector) const; +pandemonium_vector3i GDAPI pandemonium_transform_xform_inv_vector3i(const pandemonium_transform *p_self, const pandemonium_vector3i *p_vector); pandemonium_aabb GDAPI pandemonium_transform_xform_inv_aabb(const pandemonium_transform *p_self, const pandemonium_aabb *p_v); //_FORCE_INLINE_ PoolVector xform_inv(const PoolVector &p_array) const; //_FORCE_INLINE_ PoolVector xform_inv(const PoolVector &p_array) const; @@ -117,16 +118,16 @@ pandemonium_aabb GDAPI pandemonium_transform_xform_inv_aabb(const pandemonium_tr pandemonium_plane GDAPI pandemonium_transform_xform_plane(const pandemonium_transform *p_self, const pandemonium_plane *p_v); pandemonium_plane GDAPI pandemonium_transform_xform_inv_plane(const pandemonium_transform *p_self, const pandemonium_plane *p_v); -//_FORCE_INLINE_ Plane xform_fast(const Plane &p_plane, const Basis &p_basis_inverse_transpose) const; -//static _FORCE_INLINE_ Plane xform_inv_fast(const Plane &p_plane, const Transform &p_inverse, const Basis &p_basis_transpose); +pandemonium_plane GDAPI pandemonium_transform_xform_fast(const pandemonium_transform *p_self, const pandemonium_plane *p_plane, const pandemonium_basis *p_basis_inverse_transpose); +pandemonium_plane GDAPI pandemonium_transform_xform_inv_fast(const pandemonium_plane *p_plane, const pandemonium_transform *p_inverse, const pandemonium_basis *p_basis_transpose); pandemonium_transform GDAPI pandemonium_transform_operator_multiply(const pandemonium_transform *p_self, const pandemonium_transform *p_b); -//Transform spherical_interpolate_with(const Transform &p_transform, real_t p_c) const; -//Transform interpolate_with(const Transform &p_transform, real_t p_c) const; +pandemonium_transform GDAPI pandemonium_transform_spherical_interpolate_with(const pandemonium_transform *p_self, const pandemonium_transform *p_transform, pandemonium_real p_c); +pandemonium_transform GDAPI pandemonium_transform_interpolate_with(const pandemonium_transform *p_self, const pandemonium_transform *p_transform, pandemonium_real p_c); -//_FORCE_INLINE_ Transform inverse_xform(const Transform &t) const { -//void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz) { +pandemonium_transform GDAPI pandemonium_transform_inverse_xform(const pandemonium_transform *p_self, const pandemonium_transform *p_t); +void GDAPI pandemonium_transform_set(pandemonium_transform *p_self, pandemonium_real xx, pandemonium_real xy, pandemonium_real xz, pandemonium_real yx, pandemonium_real yy, pandemonium_real yz, pandemonium_real zx, pandemonium_real zy, pandemonium_real zz, pandemonium_real tx, pandemonium_real ty, pandemonium_real tz); pandemonium_string GDAPI pandemonium_transform_as_string(const pandemonium_transform *p_self);