-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgodot_math_extension.cpp
126 lines (98 loc) · 5.42 KB
/
godot_math_extension.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "godot_math_extension.h"
_GodotMathExtension *_GodotMathExtension::singleton = NULL;
void _GodotMathExtension::_bind_methods() {
ObjectTypeDB::bind_method(_MD("spherical_to_local_position:Vector3", "theta", "phi"), &_GodotMathExtension::spherical_to_local_position);
ObjectTypeDB::bind_method(_MD("quat_from_radians:Quat", "radians"), &_GodotMathExtension::quat_from_radians);
ObjectTypeDB::bind_method(_MD("ease_in", "t"), &_GodotMathExtension::ease_in);
ObjectTypeDB::bind_method(_MD("ease_out", "t"), &_GodotMathExtension::ease_out);
ObjectTypeDB::bind_method(_MD("exponetial", "t"), &_GodotMathExtension::exponetial);
ObjectTypeDB::bind_method(_MD("smooth_step", "t"), &_GodotMathExtension::smooth_step);
ObjectTypeDB::bind_method(_MD("smoother_step", "t"), &_GodotMathExtension::smoother_step);
ObjectTypeDB::bind_method(_MD("camera_get_position_distance", "camera", "pos"), &_GodotMathExtension::camera_get_position_distance);
//ObjectTypeDB::bind_method(_MD("get_2d_position_from_3d_position_with_screen_limits:Vector2", "camera", "position_3d", "screen_size", "screen_center", "screen_mins", "screen_max"), &_GodotMathExtension::get_2d_position_from_3d_position_with_screen_limits);
ObjectTypeDB::bind_method(_MD("get_2d_position_from_3d_position:Vector2", "camera", "position_3d"), &_GodotMathExtension::get_2d_position_from_3d_position);
ObjectTypeDB::bind_method(_MD("clamp_angle", "val", "ang_min", "ang_max"), &_GodotMathExtension::clamp_angle);
ObjectTypeDB::bind_method(_MD("adjust_facing:Vector3", "facing", "target", "step", "adjust_rate", "current_gn"), &_GodotMathExtension::adjust_facing);
ObjectTypeDB::bind_method(_MD("rotate_around:Transform", "transform", "point", "axis", "angle"), &_GodotMathExtension::rotate_around);
ObjectTypeDB::bind_method(_MD("inverse_lerp", "from", "to", "weight"), &_GodotMathExtension::inverse_lerp);
ObjectTypeDB::bind_method(_MD("base_log:float", "float", "float"), &_GodotMathExtension::base_log);
ObjectTypeDB::bind_method(_MD("transform_directon_vector:Vector3", "direction", "basis"), &_GodotMathExtension::transform_directon_vector);
BIND_CONSTANT(GME_MATH_TAU);
}
_GodotMathExtension *_GodotMathExtension::get_singleton() {
return singleton;
}
Vector3 _GodotMathExtension::spherical_to_local_position(real_t p_theta, real_t p_phi) {
return GodotMathExtension::spherical_to_local_position(p_theta, p_phi);
}
Quat _GodotMathExtension::quat_from_radians(Vector3 p_radians) {
return GodotMathExtension::quat_from_radians(p_radians);
}
real_t _GodotMathExtension::ease_in(real_t t) {
return GodotMathExtension::ease_in(t);
}
real_t _GodotMathExtension::ease_out(real_t t) {
return GodotMathExtension::ease_out(t);
}
real_t _GodotMathExtension::exponetial(real_t t) {
return GodotMathExtension::exponetial(t);
}
real_t _GodotMathExtension::smooth_step(real_t t) {
return GodotMathExtension::smooth_step(t);
}
real_t _GodotMathExtension::smoother_step(real_t t) {
return GodotMathExtension::smoother_step(t);
}
real_t _GodotMathExtension::camera_get_position_distance(const Object *p_camera, const Vector3 &p_pos) {
if (p_camera) {
const Camera *camera = p_camera->cast_to<Camera>();
if (camera)
return GodotMathExtension::camera_get_position_distance(camera, p_pos);
}
return 0.0f;
}
Vector2 _GodotMathExtension::get_2d_position_from_3d_position_with_screen_limits(const Object *p_camera, const Vector3 &p_position_3d,
const Vector2 &screen_size, const Vector2 &screen_center,
const Vector2 &screen_mins, const Vector2 &screen_max) {
if (p_camera) {
const Camera *camera = p_camera->cast_to<Camera>();
if (camera)
return GodotMathExtension::get_2d_position_from_3d_position_with_screen_limits(camera, p_position_3d, screen_size, screen_center, screen_mins, screen_max);
}
return Vector2();
}
Vector2 _GodotMathExtension::get_2d_position_from_3d_position(const Object *p_camera, const Vector3 &p_position_3d) {
if (p_camera) {
const Camera *camera = p_camera->cast_to<Camera>();
if (camera)
return GodotMathExtension::get_2d_position_from_3d_position(camera, p_position_3d);
}
return Vector2();
}
real_t _GodotMathExtension::clamp_angle(real_t val, real_t ang_min, real_t ang_max) {
return GodotMathExtension::clamp_angle(val, ang_min, ang_max);
}
Vector3 _GodotMathExtension::adjust_facing(const Vector3 &p_facing, const Vector3 &p_target, const real_t &p_step, const real_t &p_adjust_rate, const Vector3& p_current_gn) {
return GodotMathExtension::adjust_facing(p_facing, p_target, p_step, p_adjust_rate, p_current_gn);
}
Transform _GodotMathExtension::rotate_around(Transform p_transform, Vector3 p_point, Vector3 p_axis, real_t p_angle) {
return GodotMathExtension::rotate_around(p_transform, p_point, p_axis, p_angle);
};
real_t _GodotMathExtension::inverse_lerp(real_t p_from, real_t p_to, real_t p_weight) {
return GodotMathExtension::inverse_lerp(p_from, p_to, p_weight);
};
float _GodotMathExtension::base_log(float a, float new_base) {
if (new_base == 1.0) {
return NAN;
}
if (a != 1.0 && (new_base == 0.0 || Math::is_inf(new_base))) {
return NAN;
}
return Math::log(a) / Math::log(new_base);
}
Vector3 _GodotMathExtension::transform_directon_vector(const Vector3 &p_direction, const Matrix3 &p_basis) {
return GodotMathExtension::transform_directon_vector(p_direction, p_basis);
}
_GodotMathExtension::_GodotMathExtension() {
singleton = this;
}