diff options
author | Emmanuel Leblond <emmanuel.leblond@gmail.com> | 2017-04-15 00:16:25 +0200 |
---|---|---|
committer | Emmanuel Leblond <emmanuel.leblond@gmail.com> | 2017-04-15 00:29:43 +0200 |
commit | e5f7f656d685e228ee711a32d3f051aefea3698d (patch) | |
tree | 996033cab0f8d0400f3fada397f25bc20a17a583 | |
parent | 065261ccebd44fb5f8ed9d816d6a165b8c762565 (diff) |
Implement missing functions in gdnative vector2 and vector3 bindings
-rw-r--r-- | modules/gdnative/godot/godot_basis.h | 1 | ||||
-rw-r--r-- | modules/gdnative/godot/godot_vector2.cpp | 108 | ||||
-rw-r--r-- | modules/gdnative/godot/godot_vector2.h | 48 | ||||
-rw-r--r-- | modules/gdnative/godot/godot_vector3.cpp | 166 | ||||
-rw-r--r-- | modules/gdnative/godot/godot_vector3.h | 62 |
5 files changed, 303 insertions, 82 deletions
diff --git a/modules/gdnative/godot/godot_basis.h b/modules/gdnative/godot/godot_basis.h index a8f19bfde5..e65e5b6830 100644 --- a/modules/gdnative/godot/godot_basis.h +++ b/modules/gdnative/godot/godot_basis.h @@ -43,6 +43,7 @@ typedef struct godot_basis { #endif #include "../godot.h" +#include "godot_quat.h" void GDAPI godot_basis_new(godot_basis *p_basis); void GDAPI godot_basis_new_with_euler_quat(godot_basis *p_basis, const godot_quat *p_euler); diff --git a/modules/gdnative/godot/godot_vector2.cpp b/modules/gdnative/godot/godot_vector2.cpp index dce4c03b5d..e11cec2cfd 100644 --- a/modules/gdnative/godot/godot_vector2.cpp +++ b/modules/gdnative/godot/godot_vector2.cpp @@ -148,6 +148,114 @@ godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_a, const god return *a < *b; } +void GDAPI godot_vector2_abs(godot_vector2 *p_dest, const godot_vector2 *p_src) { + const Vector2 *src = (Vector2 *)p_src; + Vector2 *dest = (Vector2 *)p_dest; + *dest = src->abs(); +} + +godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_src) { + const Vector2 *src = (Vector2*)p_src; + return src->angle(); +} + + +godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_src, const godot_vector2 *p_to) { + const Vector2 *src = (Vector2*)p_src; + const Vector2 *to = (Vector2*)p_to; + return src->angle_to(*to); +} + +godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_src, const godot_vector2 *p_to) { + const Vector2 *src = (Vector2*)p_src; + const Vector2 *to = (Vector2*)p_to; + return src->angle_to_point(*to); +} + +void GDAPI godot_vector2_clamped(godot_vector2 *p_dest, const godot_vector2 *p_src, godot_real length) { + const Vector2 *src = (Vector2*)p_src; + Vector2 *dest = (Vector2*)p_dest; + *dest = src->clamped(length); +} + +void GDAPI godot_vector2_cubic_interpolate(godot_vector2 *p_dest, const godot_vector2 *p_src, + const godot_vector2 *p_b, const godot_vector2 *p_pre_a, + const godot_vector2 *p_post_b, godot_real t) { + Vector2 *dest = (Vector2*)p_dest; + const Vector2 *src = (Vector2*)p_src; + const Vector2 *b = (Vector2*)p_b; + const Vector2 *pre_a = (Vector2*)p_pre_a; + const Vector2 *post_b = (Vector2*)p_post_b; + *dest = src->cubic_interpolate(*b, *pre_a, *post_b, t); +} + +godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_src, const godot_vector2 *p_with) { + const Vector2 *src = (Vector2*)p_src; + const Vector2 *with = (Vector2*)p_with; + return src->dot(*with); +} + +void GDAPI godot_vector2_floor(godot_vector2 *p_dest, const godot_vector2 *p_src) { + const Vector2 *src = (Vector2*)p_src; + Vector2 *dest = (Vector2*)p_dest; + *dest = src->floor(); +} + +godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_src) { + const Vector2 *src = (Vector2*)p_src; + return src->aspect(); +} + +void GDAPI godot_vector2_linear_interpolate(godot_vector2 *p_dest, const godot_vector2 *p_src, + const godot_vector2 *p_b, godot_real t) { + Vector2 *dest = (Vector2*)p_dest; + const Vector2 *src = (Vector2*)p_src; + const Vector2 *b = (Vector2*)p_b; + *dest = src->linear_interpolate(*b, t); +} + +void GDAPI godot_vector2_reflect(godot_vector2 *p_dest, const godot_vector2 *p_src, + const godot_vector2 *p_vec) { + const Vector2 *src = (Vector2*)p_src; + const Vector2 *vec = (Vector2*)p_vec; + Vector2 *dest = (Vector2*)p_dest; + *dest = src->reflect(*vec); +} + +void GDAPI godot_vector2_rotated(godot_vector2 *p_dest, const godot_vector2 *p_src, godot_real phi) { + const Vector2 *src = (Vector2*)p_src; + Vector2 *dest = (Vector2*)p_dest; + *dest = src->rotated(phi); +} + +void GDAPI godot_vector2_slide(godot_vector2 *p_dest, const godot_vector2 *p_src, godot_vector2 *p_vec) { + const Vector2 *src = (Vector2*)p_src; + const Vector2 *vec = (Vector2*)p_vec; + Vector2 *dest = (Vector2*)p_dest; + *dest = src->slide(*vec); +} + +void GDAPI godot_vector2_snapped(godot_vector2 *p_dest, const godot_vector2 *p_src, godot_vector2 *p_by) { + const Vector2 *src = (Vector2*)p_src; + const Vector2 *by = (Vector2*)p_by; + Vector2 *dest = (Vector2*)p_dest; + *dest = src->snapped(*by); +} + +void GDAPI godot_vector2_tangent(godot_vector2 *p_dest, const godot_vector2 *p_src) { + const Vector2 *src = (Vector2*)p_src; + Vector2 *dest = (Vector2*)p_dest; + *dest = src->tangent(); +} + +void GDAPI godot_vector2_to_string(godot_string *p_dest, const godot_vector2 *p_src) { + const Vector2 *src = (Vector2*)p_src; + String *dest = (String*)p_dest; + *dest = "(" + *src + ")"; +} + + + #ifdef __cplusplus } #endif diff --git a/modules/gdnative/godot/godot_vector2.h b/modules/gdnative/godot/godot_vector2.h index afda8aa10b..c3bc8551ba 100644 --- a/modules/gdnative/godot/godot_vector2.h +++ b/modules/gdnative/godot/godot_vector2.h @@ -61,34 +61,26 @@ godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_v); godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_a, const godot_vector2 *p_b); godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_a, const godot_vector2 *p_b); -// @Incomplete -/* - * missing: - * - * angle_to - * angle_to_point - * dot - * cross_vector - * cross_scalar - * project - * plane_project - * clamped - * linear_interpolate - * cubic_interpolate - * cubic_interpolate_soft - * slide - * reflect - * angle - * abs - * rotated - * tangent - * floor - * snapped - * aspect - * - * - * to_string - */ +void GDAPI godot_vector2_abs(godot_vector2 *p_dest, const godot_vector2 *p_src); +godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_src); +godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_src, const godot_vector2 *p_to); +godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_src, const godot_vector2 *p_to); +void GDAPI godot_vector2_clamped(godot_vector2 *p_dest, const godot_vector2 *p_src, godot_real length); +void GDAPI godot_vector2_cubic_interpolate(godot_vector2 *p_dest, const godot_vector2 *p_src, + const godot_vector2 *p_b, const godot_vector2 *p_pre_a, + const godot_vector2 *p_post_b, godot_real t); +godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_src, const godot_vector2 *p_with); +void GDAPI godot_vector2_floor(godot_vector2 *p_dest, const godot_vector2 *p_src); +godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_src); +void GDAPI godot_vector2_linear_interpolate(godot_vector2 *p_dest, const godot_vector2 *p_src, + const godot_vector2 *p_b, godot_real t); +void GDAPI godot_vector2_reflect(godot_vector2 *p_dest, const godot_vector2 *p_src, + const godot_vector2 *p_vec); +void GDAPI godot_vector2_rotated(godot_vector2 *p_dest, const godot_vector2 *p_src, godot_real phi); +void GDAPI godot_vector2_slide(godot_vector2 *p_dest, const godot_vector2 *p_src, godot_vector2 *p_vec); +void GDAPI godot_vector2_snapped(godot_vector2 *p_dest, const godot_vector2 *p_src, godot_vector2 *p_by); +void GDAPI godot_vector2_tangent(godot_vector2 *p_dest, const godot_vector2 *p_src); +void GDAPI godot_vector2_to_string(godot_string *p_dest, const godot_vector2 *p_src); void GDAPI godot_vector2_operator_add(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b); void GDAPI godot_vector2_operator_subtract(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b); diff --git a/modules/gdnative/godot/godot_vector3.cpp b/modules/gdnative/godot/godot_vector3.cpp index f08bfbcf06..599420dd00 100644 --- a/modules/gdnative/godot/godot_vector3.cpp +++ b/modules/gdnative/godot/godot_vector3.cpp @@ -84,26 +84,116 @@ void GDAPI godot_vector3_normalized(godot_vector3 *p_dest, const godot_vector3 * *dest = src->normalized(); } -/* - * inverse - * zero - * snap - * snapped - * rotate - * rotated - * - * - * linear_interpolate - * cubic_interpolate - * cubic_interpolaten - * cross - * dot - * outer - * to_diagonal_matrix - * abs - * floor - * ceil - */ +void godot_vector3_inverse(godot_vector3 *p_dest, const godot_vector3 *p_src) { + Vector3 *dest = (Vector3*)p_dest; + const Vector3 *src = (Vector3*)p_src; + *dest = src->inverse(); +} + +void godot_vector3_zero(godot_vector3 *p_src) { + Vector3 *src = (Vector3*)p_src; + src->zero(); +} + +void godot_vector3_snap(godot_vector3 *p_src, godot_real val) { + Vector3 *src = (Vector3*)p_src; + src->snap(val); +} + +void godot_vector3_snapped(godot_vector3 *p_dest, const godot_vector3 *p_src, godot_real val) { + Vector3 *dest = (Vector3*)p_dest; + const Vector3 *src = (Vector3*)p_src; + *dest = src->snapped(val); +} + +void godot_vector3_rotate(godot_vector3 *p_src, const godot_vector3 *p_axis, godot_real phi) { + Vector3 *src = (Vector3*)p_src; + const Vector3 *axis = (Vector3*)p_axis; + src->rotate(*axis, phi); +} + +void godot_vector3_rotated(godot_vector3 *p_dest, const godot_vector3 *p_src, + const godot_vector3 *p_axis, godot_real phi) { + Vector3 *dest = (Vector3*)p_dest; + const Vector3 *src = (Vector3*)p_src; + const Vector3 *axis = (Vector3*)p_axis; + *dest = src->rotated(*axis, phi); +} + + +void godot_vector3_linear_interpolate(godot_vector3 *p_dest, const godot_vector3 *p_src, + const godot_vector3 *p_b, godot_real t) { + Vector3 *dest = (Vector3*)p_dest; + const Vector3 *src = (Vector3*)p_src; + const Vector3 *b = (Vector3*)p_b; + *dest = src->linear_interpolate(*b, t); +} + +void godot_vector3_cubic_interpolate(godot_vector3 *p_dest, const godot_vector3 *p_src, + const godot_vector3 *p_b, const godot_vector3 *p_pre_a, + const godot_vector3 *p_post_b, godot_real t) { + Vector3 *dest = (Vector3*)p_dest; + const Vector3 *src = (Vector3*)p_src; + const Vector3 *b = (Vector3*)p_b; + const Vector3 *pre_a = (Vector3*)p_pre_a; + const Vector3 *post_b = (Vector3*)p_post_b; + *dest = src->cubic_interpolate(*b, *pre_a, *post_b, t); +} + +void godot_vector3_cubic_interpolaten(godot_vector3 *p_dest, const godot_vector3 *p_src, + const godot_vector3 *p_b, const godot_vector3 *p_pre_a, + const godot_vector3 *p_post_b, godot_real t) { + Vector3 *dest = (Vector3*)p_dest; + const Vector3 *src = (Vector3*)p_src; + const Vector3 *b = (Vector3*)p_b; + const Vector3 *pre_a = (Vector3*)p_pre_a; + const Vector3 *post_b = (Vector3*)p_post_b; + *dest = src->cubic_interpolaten(*b, *pre_a, *post_b, t); +} + +void godot_vector3_cross(godot_vector3 *p_dest, const godot_vector3 *p_src, const godot_vector3 *p_b) { + Vector3 *dest = (Vector3*)p_dest; + const Vector3 *src = (Vector3*)p_src; + const Vector3 *b = (Vector3*)p_b; + *dest = src->cross(*b); +} + +godot_real godot_vector3_dot(const godot_vector3 *p_src, const godot_vector3 *p_b) { + const Vector3 *src = (Vector3*)p_src; + const Vector3 *b = (Vector3*)p_b; + return src->dot(*b); +} + +void godot_vector3_outer(godot_basis *p_dest, const godot_vector3 *p_src, const godot_vector3 *p_b) { + Basis *dest = (Basis*)p_dest; + const Vector3 *src = (Vector3*)p_src; + const Vector3 *b = (Vector3*)p_b; + *dest = src->outer(*b); +} + +void godot_vector3_to_diagonal_matrix(godot_basis *p_dest, const godot_vector3 *p_src) { + Basis *dest = (Basis*)p_dest; + const Vector3 *src = (Vector3*)p_src; + *dest = src->to_diagonal_matrix(); +} + +void godot_vector3_abs(godot_vector3 *p_dest, const godot_vector3 *p_src) { + Vector3 *dest = (Vector3*)p_dest; + const Vector3 *src = (Vector3*)p_src; + *dest = src->abs(); +} + +void godot_vector3_floor(godot_vector3 *p_dest, const godot_vector3 *p_src) { + Vector3 *dest = (Vector3*)p_dest; + const Vector3 *src = (Vector3*)p_src; + *dest = src->floor(); +} + +void godot_vector3_ceil(godot_vector3 *p_dest, const godot_vector3 *p_src) { + const Vector3 *src = (Vector3*)p_src; + Vector3 *dest = (Vector3*)p_dest; + *dest = src->ceil(); +} godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_a, const godot_vector3 *p_b) { Vector3 *a = (Vector3 *)p_a; @@ -117,10 +207,32 @@ godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_a, con return a->distance_squared_to(*b); } -/* - * slide - * reflect - */ +godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_a, const godot_vector3 *p_b) { + Vector3 *a = (Vector3 *)p_a; + Vector3 *b = (Vector3 *)p_b; + return a->angle_to(*b); +} + +void godot_vector3_slide(godot_vector3 *p_dest, const godot_vector3 *p_src, const godot_vector3 *p_vec) { + const Vector3 *src = (Vector3*)p_src; + const Vector3 *vec = (Vector3*)p_vec; + Vector3 *dest = (Vector3*)p_dest; + *dest = src->slide(*vec); +} + +void godot_vector3_bounce(godot_vector3 *p_dest, const godot_vector3 *p_src, const godot_vector3 *p_vec) { + const Vector3 *src = (Vector3*)p_src; + const Vector3 *vec = (Vector3*)p_vec; + Vector3 *dest = (Vector3*)p_dest; + *dest = src->bounce(*vec); +} + +void godot_vector3_reflect(godot_vector3 *p_dest, const godot_vector3 *p_src, const godot_vector3 *p_vec) { + const Vector3 *src = (Vector3*)p_src; + const Vector3 *vec = (Vector3*)p_vec; + Vector3 *dest = (Vector3*)p_dest; + *dest = src->reflect(*vec); +} void GDAPI godot_vector3_operator_add(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b) { Vector3 *dest = (Vector3 *)p_dest; @@ -174,6 +286,12 @@ godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_a, const god return *a < *b; } +void GDAPI godot_vector3_to_string(godot_string *p_dest, const godot_vector3 *p_src) { + const Vector3 *src = (Vector3*)p_src; + String *dest = (String*)p_dest; + *dest = "(" + *src + ")"; +} + #ifdef __cplusplus } #endif diff --git a/modules/gdnative/godot/godot_vector3.h b/modules/gdnative/godot/godot_vector3.h index b7dc40965d..51dd56c286 100644 --- a/modules/gdnative/godot/godot_vector3.h +++ b/modules/gdnative/godot/godot_vector3.h @@ -42,7 +42,12 @@ typedef struct godot_vector3 { } godot_vector3; #endif +#define GODOT_VECTOR3_AXIX_X 0 +#define GODOT_VECTOR3_AXIX_Y 1 +#define GODOT_VECTOR3_AXIX_Z 2 + #include "../godot.h" +#include "godot_basis.h" void GDAPI godot_vector3_new(godot_vector3 *p_v, const godot_real p_x, const godot_real p_y, const godot_real p_z); @@ -58,37 +63,36 @@ godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_v); void GDAPI godot_vector3_normalize(godot_vector3 *p_v); void GDAPI godot_vector3_normalized(godot_vector3 *p_dest, const godot_vector3 *p_src); -// @Incomplete - -/* - * inverse - * zero - * snap - * snapped - * rotate - * rotated - * - * - * linear_interpolate - * cubic_interpolate - * cubic_interpolaten - * cross - * dot - * outer - * to_diagonal_matrix - * abs - * floor - * ceil - */ +void GDAPI godot_vector3_inverse(godot_vector3 *p_dest, const godot_vector3 *p_src); +void GDAPI godot_vector3_zero(godot_vector3 *p_src); +void GDAPI godot_vector3_snap(godot_vector3 *p_src, godot_real val); +void GDAPI godot_vector3_snapped(godot_vector3 *p_dest, const godot_vector3 *p_src, godot_real val); +void GDAPI godot_vector3_rotate(godot_vector3 *p_src, const godot_vector3 *p_axis, godot_real phi); +void GDAPI godot_vector3_rotated(godot_vector3 *p_dest, const godot_vector3 *p_src, + const godot_vector3 *p_axis, godot_real phi); +void GDAPI godot_vector3_linear_interpolate(godot_vector3 *p_dest, const godot_vector3 *p_src, + const godot_vector3 *p_b, godot_real t); +void GDAPI godot_vector3_cubic_interpolate(godot_vector3 *p_dest, const godot_vector3 *p_src, + const godot_vector3 *p_b, const godot_vector3 *p_pre_a, + const godot_vector3 *p_post_b, godot_real t); +void GDAPI godot_vector3_cubic_interpolaten(godot_vector3 *p_dest, const godot_vector3 *p_src, + const godot_vector3 *p_b, const godot_vector3 *p_pre_a, + const godot_vector3 *p_post_b, godot_real t); +void GDAPI godot_vector3_cross(godot_vector3 *p_dest, const godot_vector3 *p_src, const godot_vector3 *p_b); +godot_real GDAPI godot_vector3_dot(const godot_vector3 *p_src, const godot_vector3 *p_b); +void GDAPI godot_vector3_outer(godot_basis *dest, const godot_vector3 *p_src, const godot_vector3 *p_b); +void GDAPI godot_vector3_to_diagonal_matrix(godot_basis *dest, const godot_vector3 *p_src); +void GDAPI godot_vector3_abs(godot_vector3 *p_dest, const godot_vector3 *p_src); +void GDAPI godot_vector3_floor(godot_vector3 *p_dest, const godot_vector3 *p_src); +void GDAPI godot_vector3_ceil(godot_vector3 *p_dest, const godot_vector3 *p_src); godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_a, const godot_vector3 *p_b); godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_a, const godot_vector3 *p_b); +godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_a, const godot_vector3 *p_b); -// @Incomplete -/* - * slide - * reflect - */ +void GDAPI godot_vector3_slide(godot_vector3 *p_dest, const godot_vector3 *p_src, const godot_vector3 *p_vec); +void GDAPI godot_vector3_bounce(godot_vector3 *p_dest, const godot_vector3 *p_src, const godot_vector3 *p_vec); +void GDAPI godot_vector3_reflect(godot_vector3 *p_dest, const godot_vector3 *p_src, const godot_vector3 *p_vec); void GDAPI godot_vector3_operator_add(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b); void GDAPI godot_vector3_operator_subtract(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b); @@ -100,9 +104,7 @@ void GDAPI godot_vector3_operator_divide_scalar(godot_vector3 *p_dest, const god godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_a, const godot_vector3 *p_b); godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_a, const godot_vector3 *p_b); -/* - * to_string - */ +void GDAPI godot_vector3_to_string(godot_string *p_dest, const godot_vector3 *p_src); #ifdef __cplusplus } |