Skip to content

Commit

Permalink
Implemented Vector2 rotation around a pivot point
Browse files Browse the repository at this point in the history
  • Loading branch information
iWas-Coder committed Nov 28, 2024
1 parent af307fb commit 910b594
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions carbon.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ CARBON_API f32 carbon_math_vec2_dot(CBN_Vec2 u, CBN_Vec2 v);
CARBON_API f32 carbon_math_vec3_dot(CBN_Vec3 u, CBN_Vec3 v);
CARBON_API CBN_Vec3 carbon_math_vec3_cross(CBN_Vec3 u, CBN_Vec3 v);
CARBON_API CBN_Vec2 carbon_math_vec2_rotate(CBN_Vec2 v, f32 angle);
CARBON_API CBN_Vec2 carbon_math_vec2_rotate_around_pivot(CBN_Vec2 v, f32 angle, CBN_Vec2 pivot);
CARBON_API u8 carbon_math_rect_contains_point(CBN_Rect r, CBN_Vec2 p);
CARBON_API CBN_Matrix carbon_math_mat_create(usz rows, usz cols);
CARBON_API void carbon_math_mat_destroy(CBN_Matrix *m);
Expand Down
5 changes: 5 additions & 0 deletions src/carbon_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ CBN_Vec2 carbon_math_vec2_rotate(CBN_Vec2 v, f32 angle) {
};
}

CBN_Vec2 carbon_math_vec2_rotate_around_pivot(CBN_Vec2 v, f32 angle, CBN_Vec2 pivot) {
CBN_Vec2 r = carbon_math_vec2_rotate((CBN_Vec2){{v.x - pivot.x, v.y - pivot.y}}, angle);
return (CBN_Vec2) {{r.x + pivot.x, r.y + pivot.y}};
}

u8 carbon_math_rect_contains_point(CBN_Rect r, CBN_Vec2 p) {
return (p.x >= r.x && p.x <= r.x + r.w) && (p.y >= r.y && p.y <= r.y + r.h);
}
Expand Down

0 comments on commit 910b594

Please sign in to comment.