mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 20:23:53 +00:00
Merge pull request #52430 from AnilBK/vector2-replacements
This commit is contained in:
commit
32ab77ef8f
@ -279,7 +279,7 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, const
|
||||
}
|
||||
|
||||
//construct matrix
|
||||
Transform2D res(Math::atan2(v.y, v.x), p1.lerp(p2, p_c));
|
||||
Transform2D res(v.angle(), p1.lerp(p2, p_c));
|
||||
res.scale_basis(s1.lerp(s2, p_c));
|
||||
return res;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ real_t Vector2::angle_to(const Vector2 &p_vector2) const {
|
||||
}
|
||||
|
||||
real_t Vector2::angle_to_point(const Vector2 &p_vector2) const {
|
||||
return Math::atan2(y - p_vector2.y, x - p_vector2.x);
|
||||
return (*this - p_vector2).angle();
|
||||
}
|
||||
|
||||
real_t Vector2::dot(const Vector2 &p_other) const {
|
||||
|
@ -2927,7 +2927,7 @@ void CanvasItemEditor::_draw_ruler_tool() {
|
||||
viewport->draw_string(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length())), HALIGN_LEFT, -1, font_size, font_color, outline_size, outline_color);
|
||||
|
||||
if (draw_secondary_lines) {
|
||||
const real_t horizontal_angle_rad = atan2(length_vector.y, length_vector.x);
|
||||
const real_t horizontal_angle_rad = length_vector.angle();
|
||||
const real_t vertical_angle_rad = Math_PI / 2.0 - horizontal_angle_rad;
|
||||
const int horizontal_angle = round(180 * horizontal_angle_rad / Math_PI);
|
||||
const int vertical_angle = round(180 * vertical_angle_rad / Math_PI);
|
||||
|
@ -727,7 +727,7 @@ void CPUParticles2D::_particles_process(double p_delta) {
|
||||
p.hue_rot_rand = Math::randf();
|
||||
p.anim_offset_rand = Math::randf();
|
||||
|
||||
real_t angle1_rad = Math::atan2(direction.y, direction.x) + Math::deg2rad((Math::randf() * 2.0 - 1.0) * spread);
|
||||
real_t angle1_rad = direction.angle() + Math::deg2rad((Math::randf() * 2.0 - 1.0) * spread);
|
||||
Vector2 rot = Vector2(Math::cos(angle1_rad), Math::sin(angle1_rad));
|
||||
p.velocity = rot * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], Math::randf());
|
||||
|
||||
|
@ -464,7 +464,7 @@ void NavigationRegion2D::_notification(int p_what) {
|
||||
draw_line(a, b, doors_color);
|
||||
|
||||
// Draw a circle to illustrate the margins.
|
||||
real_t angle = (b - a).angle();
|
||||
real_t angle = b.angle_to_point(a);
|
||||
draw_arc(a, radius, angle + Math_PI / 2.0, angle - Math_PI / 2.0 + Math_TAU, 10, doors_color);
|
||||
draw_arc(b, radius, angle - Math_PI / 2.0, angle + Math_PI / 2.0, 10, doors_color);
|
||||
}
|
||||
|
@ -456,7 +456,7 @@ void Bone2D::calculate_length_and_rotation() {
|
||||
if (child) {
|
||||
Vector2 child_local_pos = to_local(child->get_global_position());
|
||||
length = child_local_pos.length();
|
||||
bone_angle = Math::atan2(child_local_pos.normalized().y, child_local_pos.normalized().x);
|
||||
bone_angle = child_local_pos.normalized().angle();
|
||||
calculated = true;
|
||||
break;
|
||||
}
|
||||
|
@ -827,7 +827,7 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
|
||||
real_t dist = center.distance_to(bev->get_position());
|
||||
|
||||
if (dist <= center.x) {
|
||||
real_t rad = Math::atan2(bev->get_position().y - center.y, bev->get_position().x - center.x);
|
||||
real_t rad = bev->get_position().angle_to_point(center);
|
||||
h = ((rad >= 0) ? rad : (Math_TAU + rad)) / Math_TAU;
|
||||
s = CLAMP(dist / center.x, 0, 1);
|
||||
} else {
|
||||
@ -844,7 +844,7 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
|
||||
real_t dist = center.distance_to(bev->get_position());
|
||||
|
||||
if (dist >= center.x * 0.84 && dist <= center.x) {
|
||||
real_t rad = Math::atan2(bev->get_position().y - center.y, bev->get_position().x - center.x);
|
||||
real_t rad = bev->get_position().angle_to_point(center);
|
||||
h = ((rad >= 0) ? rad : (Math_TAU + rad)) / Math_TAU;
|
||||
spinning = true;
|
||||
} else {
|
||||
@ -889,12 +889,12 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
|
||||
Vector2 center = c->get_size() / 2.0;
|
||||
if (picker_type == SHAPE_VHS_CIRCLE) {
|
||||
real_t dist = center.distance_to(mev->get_position());
|
||||
real_t rad = Math::atan2(mev->get_position().y - center.y, mev->get_position().x - center.x);
|
||||
real_t rad = mev->get_position().angle_to_point(center);
|
||||
h = ((rad >= 0) ? rad : (Math_TAU + rad)) / Math_TAU;
|
||||
s = CLAMP(dist / center.x, 0, 1);
|
||||
} else {
|
||||
if (spinning) {
|
||||
real_t rad = Math::atan2(mev->get_position().y - center.y, mev->get_position().x - center.x);
|
||||
real_t rad = mev->get_position().angle_to_point(center);
|
||||
h = ((rad >= 0) ? rad : (Math_TAU + rad)) / Math_TAU;
|
||||
} else {
|
||||
real_t corner_x = (c == wheel_uv) ? center.x - Math_SQRT12 * c->get_size().width * 0.42 : 0;
|
||||
|
@ -144,7 +144,7 @@ void SkeletonModification2DTwoBoneIK::_execute(float p_delta) {
|
||||
// With modifications by TwistedTwigleg
|
||||
Vector2 target_difference = target->get_global_position() - joint_one_bone->get_global_position();
|
||||
float joint_one_to_target = target_difference.length();
|
||||
float angle_atan = Math::atan2(target_difference.y, target_difference.x);
|
||||
float angle_atan = target_difference.angle();
|
||||
|
||||
float bone_one_length = joint_one_bone->get_length() * MIN(joint_one_bone->get_global_scale().x, joint_one_bone->get_global_scale().y);
|
||||
float bone_two_length = joint_two_bone->get_length() * MIN(joint_two_bone->get_global_scale().x, joint_two_bone->get_global_scale().y);
|
||||
|
Loading…
Reference in New Issue
Block a user