Transform initial rework.

This commit is contained in:
Relintai 2023-05-26 17:31:55 +02:00
parent fdcd047f8e
commit 839fb76ebd
2 changed files with 158 additions and 127 deletions

View File

@ -39,29 +39,51 @@ extern "C" {
static_assert(sizeof(pandemonium_transform) == sizeof(Transform), "Transform size mismatch");
void GDAPI pandemonium_transform_new_with_axis_origin(pandemonium_transform *r_dest, const pandemonium_vector3 *p_x_axis, const pandemonium_vector3 *p_y_axis, const pandemonium_vector3 *p_z_axis, const pandemonium_vector3 *p_origin) {
const Vector3 *x_axis = (const Vector3 *)p_x_axis;
const Vector3 *y_axis = (const Vector3 *)p_y_axis;
const Vector3 *z_axis = (const Vector3 *)p_z_axis;
const Vector3 *origin = (const Vector3 *)p_origin;
Transform *dest = (Transform *)r_dest;
dest->basis.set_axis(0, *x_axis);
dest->basis.set_axis(1, *y_axis);
dest->basis.set_axis(2, *z_axis);
dest->origin = *origin;
pandemonium_transform GDAPI pandemonium_transform_inverse(const pandemonium_transform *p_self) {
pandemonium_transform dest;
const Transform *self = (const Transform *)p_self;
*((Transform *)&dest) = self->inverse();
return dest;
}
void GDAPI pandemonium_transform_new(pandemonium_transform *r_dest, const pandemonium_basis *p_basis, const pandemonium_vector3 *p_origin) {
const Basis *basis = (const Basis *)p_basis;
const Vector3 *origin = (const Vector3 *)p_origin;
Transform *dest = (Transform *)r_dest;
*dest = Transform(*basis, *origin);
pandemonium_transform GDAPI pandemonium_transform_affine_inverse(const pandemonium_transform *p_self) {
pandemonium_transform dest;
const Transform *self = (const Transform *)p_self;
*((Transform *)&dest) = self->affine_inverse();
return dest;
}
void GDAPI pandemonium_transform_new_with_quaternion(pandemonium_transform *r_dest, const pandemonium_quaternion *p_quaternion) {
const Quaternion *quaternion = (const Quaternion *)p_quaternion;
Transform *dest = (Transform *)r_dest;
*dest = Transform(*quaternion);
pandemonium_transform GDAPI pandemonium_transform_rotated(const pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, const 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(*axis, p_phi);
return dest;
}
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;
const Transform *self = (const Transform *)p_self;
const Vector3 *target = (const Vector3 *)p_target;
const Vector3 *up = (const Vector3 *)p_up;
*((Transform *)&dest) = self->looking_at(*target, *up);
return dest;
}
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;
const Vector3 *scale = (const Vector3 *)p_scale;
*((Transform *)&dest) = self->scaled(*scale);
return dest;
}
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;
const Vector3 *ofs = (const Vector3 *)p_ofs;
*((Transform *)&dest) = self->translated(*ofs);
return dest;
}
pandemonium_basis GDAPI pandemonium_transform_get_basis(const pandemonium_transform *p_self) {
@ -90,27 +112,6 @@ void GDAPI pandemonium_transform_set_origin(pandemonium_transform *p_self, const
self->origin = *v;
}
pandemonium_string GDAPI pandemonium_transform_as_string(const pandemonium_transform *p_self) {
pandemonium_string ret;
const Transform *self = (const Transform *)p_self;
memnew_placement(&ret, String(*self));
return ret;
}
pandemonium_transform GDAPI pandemonium_transform_inverse(const pandemonium_transform *p_self) {
pandemonium_transform dest;
const Transform *self = (const Transform *)p_self;
*((Transform *)&dest) = self->inverse();
return dest;
}
pandemonium_transform GDAPI pandemonium_transform_affine_inverse(const pandemonium_transform *p_self) {
pandemonium_transform dest;
const Transform *self = (const Transform *)p_self;
*((Transform *)&dest) = self->affine_inverse();
return dest;
}
pandemonium_transform GDAPI pandemonium_transform_orthonormalized(const pandemonium_transform *p_self) {
pandemonium_transform dest;
const Transform *self = (const Transform *)p_self;
@ -118,37 +119,46 @@ pandemonium_transform GDAPI pandemonium_transform_orthonormalized(const pandemon
return dest;
}
pandemonium_transform GDAPI pandemonium_transform_rotated(const pandemonium_transform *p_self, const pandemonium_vector3 *p_axis, const pandemonium_real p_phi) {
pandemonium_transform dest;
pandemonium_bool GDAPI pandemonium_transform_operator_equal(const pandemonium_transform *p_self, const pandemonium_transform *p_b) {
const Transform *self = (const Transform *)p_self;
const Vector3 *axis = (const Vector3 *)p_axis;
*((Transform *)&dest) = self->rotated(*axis, p_phi);
return dest;
const Transform *b = (const Transform *)p_b;
return *self == *b;
}
pandemonium_transform GDAPI pandemonium_transform_scaled(const pandemonium_transform *p_self, const pandemonium_vector3 *p_scale) {
pandemonium_transform dest;
pandemonium_vector3 GDAPI pandemonium_transform_xform_vector3(const pandemonium_transform *p_self, const pandemonium_vector3 *p_v) {
pandemonium_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const Vector3 *scale = (const Vector3 *)p_scale;
*((Transform *)&dest) = self->scaled(*scale);
return dest;
const Vector3 *v = (const Vector3 *)p_v;
*dest = self->xform(*v);
return raw_dest;
}
pandemonium_transform GDAPI pandemonium_transform_translated(const pandemonium_transform *p_self, const pandemonium_vector3 *p_ofs) {
pandemonium_transform dest;
pandemonium_aabb GDAPI pandemonium_transform_xform_aabb(const pandemonium_transform *p_self, const pandemonium_aabb *p_v) {
pandemonium_aabb raw_dest;
AABB *dest = (AABB *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const Vector3 *ofs = (const Vector3 *)p_ofs;
*((Transform *)&dest) = self->translated(*ofs);
return dest;
const AABB *v = (const AABB *)p_v;
*dest = self->xform(*v);
return raw_dest;
}
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;
pandemonium_vector3 GDAPI pandemonium_transform_xform_inv_vector3(const pandemonium_transform *p_self, const pandemonium_vector3 *p_v) {
pandemonium_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const Vector3 *target = (const Vector3 *)p_target;
const Vector3 *up = (const Vector3 *)p_up;
*((Transform *)&dest) = self->looking_at(*target, *up);
return dest;
const Vector3 *v = (const Vector3 *)p_v;
*dest = self->xform_inv(*v);
return raw_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;
const Transform *self = (const Transform *)p_self;
const AABB *v = (const AABB *)p_v;
*dest = self->xform_inv(*v);
return raw_dest;
}
pandemonium_plane GDAPI pandemonium_transform_xform_plane(const pandemonium_transform *p_self, const pandemonium_plane *p_v) {
@ -169,17 +179,6 @@ pandemonium_plane GDAPI pandemonium_transform_xform_inv_plane(const pandemonium_
return raw_dest;
}
void GDAPI pandemonium_transform_new_identity(pandemonium_transform *r_dest) {
Transform *dest = (Transform *)r_dest;
*dest = 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;
const Transform *b = (const Transform *)p_b;
return *self == *b;
}
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;
@ -189,40 +188,41 @@ pandemonium_transform GDAPI pandemonium_transform_operator_multiply(const pandem
return raw_dest;
}
pandemonium_vector3 GDAPI pandemonium_transform_xform_vector3(const pandemonium_transform *p_self, const pandemonium_vector3 *p_v) {
pandemonium_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
pandemonium_string GDAPI pandemonium_transform_as_string(const pandemonium_transform *p_self) {
pandemonium_string ret;
const Transform *self = (const Transform *)p_self;
const Vector3 *v = (const Vector3 *)p_v;
*dest = self->xform(*v);
return raw_dest;
memnew_placement(&ret, String(*self));
return ret;
}
pandemonium_vector3 GDAPI pandemonium_transform_xform_inv_vector3(const pandemonium_transform *p_self, const pandemonium_vector3 *p_v) {
pandemonium_vector3 raw_dest;
Vector3 *dest = (Vector3 *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const Vector3 *v = (const Vector3 *)p_v;
*dest = self->xform_inv(*v);
return raw_dest;
void GDAPI pandemonium_transform_new_with_axis_origin(pandemonium_transform *r_dest, const pandemonium_vector3 *p_x_axis, const pandemonium_vector3 *p_y_axis, const pandemonium_vector3 *p_z_axis, const pandemonium_vector3 *p_origin) {
const Vector3 *x_axis = (const Vector3 *)p_x_axis;
const Vector3 *y_axis = (const Vector3 *)p_y_axis;
const Vector3 *z_axis = (const Vector3 *)p_z_axis;
const Vector3 *origin = (const Vector3 *)p_origin;
Transform *dest = (Transform *)r_dest;
dest->basis.set_axis(0, *x_axis);
dest->basis.set_axis(1, *y_axis);
dest->basis.set_axis(2, *z_axis);
dest->origin = *origin;
}
pandemonium_aabb GDAPI pandemonium_transform_xform_aabb(const pandemonium_transform *p_self, const pandemonium_aabb *p_v) {
pandemonium_aabb raw_dest;
AABB *dest = (AABB *)&raw_dest;
const Transform *self = (const Transform *)p_self;
const AABB *v = (const AABB *)p_v;
*dest = self->xform(*v);
return raw_dest;
void GDAPI pandemonium_transform_new(pandemonium_transform *r_dest, const pandemonium_basis *p_basis, const pandemonium_vector3 *p_origin) {
const Basis *basis = (const Basis *)p_basis;
const Vector3 *origin = (const Vector3 *)p_origin;
Transform *dest = (Transform *)r_dest;
*dest = Transform(*basis, *origin);
}
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;
const Transform *self = (const Transform *)p_self;
const AABB *v = (const AABB *)p_v;
*dest = self->xform_inv(*v);
return raw_dest;
void GDAPI pandemonium_transform_new_with_quaternion(pandemonium_transform *r_dest, const pandemonium_quaternion *p_quaternion) {
const Quaternion *quaternion = (const Quaternion *)p_quaternion;
Transform *dest = (Transform *)r_dest;
*dest = Transform(*quaternion);
}
void GDAPI pandemonium_transform_new_identity(pandemonium_transform *r_dest) {
Transform *dest = (Transform *)r_dest;
*dest = Transform();
}
#ifdef __cplusplus

View File

@ -60,9 +60,33 @@ typedef struct {
extern "C" {
#endif
void GDAPI pandemonium_transform_new_with_axis_origin(pandemonium_transform *r_dest, const pandemonium_vector3 *p_x_axis, const pandemonium_vector3 *p_y_axis, const pandemonium_vector3 *p_z_axis, const pandemonium_vector3 *p_origin);
void GDAPI pandemonium_transform_new(pandemonium_transform *r_dest, const pandemonium_basis *p_basis, const pandemonium_vector3 *p_origin);
void GDAPI pandemonium_transform_new_with_quaternion(pandemonium_transform *r_dest, const pandemonium_quaternion *p_quaternion);
//void invert();
pandemonium_transform GDAPI pandemonium_transform_inverse(const pandemonium_transform *p_self);
//void affine_invert();
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;
//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 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);
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);
//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_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);
@ -70,39 +94,46 @@ 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);
pandemonium_string GDAPI pandemonium_transform_as_string(const pandemonium_transform *p_self);
pandemonium_transform GDAPI pandemonium_transform_inverse(const pandemonium_transform *p_self);
pandemonium_transform GDAPI pandemonium_transform_affine_inverse(const pandemonium_transform *p_self);
//void orthonormalize();
pandemonium_transform GDAPI pandemonium_transform_orthonormalized(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);
pandemonium_transform GDAPI pandemonium_transform_scaled(const pandemonium_transform *p_self, const pandemonium_vector3 *p_scale);
pandemonium_transform GDAPI pandemonium_transform_translated(const pandemonium_transform *p_self, const pandemonium_vector3 *p_ofs);
pandemonium_transform GDAPI pandemonium_transform_looking_at(const pandemonium_transform *p_self, const pandemonium_vector3 *p_target, const pandemonium_vector3 *p_up);
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);
void GDAPI pandemonium_transform_new_identity(pandemonium_transform *r_dest);
//void orthogonalize();
//Transform orthogonalized() const;
//bool is_equal_approx(const Transform &p_transform) const;
pandemonium_bool GDAPI pandemonium_transform_operator_equal(const pandemonium_transform *p_self, const pandemonium_transform *p_b);
pandemonium_transform GDAPI pandemonium_transform_operator_multiply(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_aabb GDAPI pandemonium_transform_xform_aabb(const pandemonium_transform *p_self, const pandemonium_aabb *p_v);
//_FORCE_INLINE_ PoolVector<Vector3> xform(const PoolVector<Vector3> &p_array) const;
//_FORCE_INLINE_ PoolVector<Vector3i> xform(const PoolVector<Vector3i> &p_array) const;
pandemonium_vector3 GDAPI pandemonium_transform_xform_inv_vector3(const pandemonium_transform *p_self, const pandemonium_vector3 *p_v);
pandemonium_aabb GDAPI pandemonium_transform_xform_aabb(const pandemonium_transform *p_self, const pandemonium_aabb *p_v);
//_FORCE_INLINE_ Vector3i xform_inv(const Vector3i &p_vector) const;
pandemonium_aabb GDAPI pandemonium_transform_xform_inv_aabb(const pandemonium_transform *p_self, const pandemonium_aabb *p_v);
//_FORCE_INLINE_ PoolVector<Vector3> xform_inv(const PoolVector<Vector3> &p_array) const;
//_FORCE_INLINE_ PoolVector<Vector3i> xform_inv(const PoolVector<Vector3i> &p_array) const;
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_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;
//_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_string GDAPI pandemonium_transform_as_string(const pandemonium_transform *p_self);
void GDAPI pandemonium_transform_new_with_axis_origin(pandemonium_transform *r_dest, const pandemonium_vector3 *p_x_axis, const pandemonium_vector3 *p_y_axis, const pandemonium_vector3 *p_z_axis, const pandemonium_vector3 *p_origin);
void GDAPI pandemonium_transform_new(pandemonium_transform *r_dest, const pandemonium_basis *p_basis, const pandemonium_vector3 *p_origin);
void GDAPI pandemonium_transform_new_with_quaternion(pandemonium_transform *r_dest, const pandemonium_quaternion *p_quaternion);
void GDAPI pandemonium_transform_new_identity(pandemonium_transform *r_dest);
#ifdef __cplusplus
}