Skip to content

Commit

Permalink
[raymath] Hotfix for Vector2Angle() and Vector2LineAngle() (#3396)
Browse files Browse the repository at this point in the history
* Hotfix for Vector2LineAngle(), should probably be reviewed along with the rest of raylib angle functions to determine what coordinate system we want.

* Hotfix for Vector2LineAngle(), should probably be reviewed along with the rest of raylib angle functions to determine what coordinate system we want.

* [raymath] Hotfix for Vector2Angle and corresponding example

* [raymath] Hotfix for Vector2Angle and corresponding example

---------

Co-authored-by: Ray <[email protected]>
  • Loading branch information
Murlocohol and raysan5 authored Oct 10, 2023
1 parent f0d949f commit 9702a17
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 5 additions & 5 deletions examples/others/raymath_vector_angle.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(void)
//----------------------------------------------------------------------------------
float startangle;

if (angleMode == 0) startangle = -Vector2LineAngle(v0, v1)*RAD2DEG;
if (angleMode == 0) startangle = Vector2LineAngle(v0, v1)*RAD2DEG;
if (angleMode == 1) startangle = 0.0f;

v2 = GetMousePosition();
Expand Down Expand Up @@ -81,17 +81,17 @@ int main(void)

DrawLineEx(v0, v1, 2.0f, BLACK);
DrawLineEx(v0, v2, 2.0f, RED);
DrawCircleSector(v0, 40.0f, startangle, startangle - angle, 32, Fade(GREEN, 0.6f));

DrawCircleSector(v0, 40.0f, startangle, startangle + angle, 32, Fade(GREEN, 0.6f));
}
else if (angleMode == 1)
{
DrawText("MODE 1: Angle formed by line V1 to V2", 10, 10, 20, BLACK);

DrawLine(0, screenHeight/2, screenWidth, screenHeight/2, LIGHTGRAY);
DrawLineEx(v0, v2, 2.0f, RED);
DrawCircleSector(v0, 40.0f, startangle, startangle - angle, 32, Fade(GREEN, 0.6f));

DrawCircleSector(v0, 40.0f, startangle, startangle + angle, 32, Fade(GREEN, 0.6f));
}

DrawText("v0", v0.x, v0.y, 10, DARKGRAY);
Expand Down
3 changes: 1 addition & 2 deletions src/raymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ RMAPI float Vector2Angle(Vector2 v1, Vector2 v2)
float dot = v1.x*v2.x + v1.y*v2.y;
float det = v1.x*v2.y - v1.y*v2.x;

// TODO(10/9/2023): Currently angles move clockwise, determine if this is wanted behavior
result = -atan2f(det, dot);
result = atan2f(det, dot);

return result;
}
Expand Down

0 comments on commit 9702a17

Please sign in to comment.