Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector3 signed_angle_to is incorrect #708

Closed
Ventilador opened this issue May 11, 2024 · 0 comments · Fixed by #710
Closed

Vector3 signed_angle_to is incorrect #708

Ventilador opened this issue May 11, 2024 · 0 comments · Fixed by #710
Labels
bug c: core Core components

Comments

@Ventilador
Copy link

The implementation of signed_angle_to is incorrect in this line.

here is the snippet from godot's impl

real_t Vector3::signed_angle_to(const Vector3 &p_to, const Vector3 &p_axis) const {
	Vector3 cross_to = cross(p_to);
	real_t unsigned_angle = Math::atan2(cross_to.length(), dot(p_to)); // this line is incorrect in rust
	real_t sign = cross_to.dot(p_axis);
	return (sign < 0) ? -unsigned_angle : unsigned_angle;
}

in the gdext impl is backwards

pub fn signed_angle_to(self, to: Self, axis: Self) -> real {
        let cross_to = self.cross(to);

        // the atan2 is inverted here atan2(self dot to, cross.len)
        -- let unsigned_angle = self.dot(to).atan2(cross_to.length());

        // this is how it should be atan2(cross.len, self dot to);
        ++ let unsigned_angle = cross_to.length().atan2(self.dot(to));

        let sign = cross_to.dot(axis);
        if sign < 0.0 {
            -unsigned_angle
        } else {
            unsigned_angle
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug c: core Core components
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants