diff --git a/include/arc/math/vector2.h b/include/arc/math/vector2.h index 11893bf..ba98114 100644 --- a/include/arc/math/vector2.h +++ b/include/arc/math/vector2.h @@ -13,8 +13,21 @@ typedef struct ARC_DVector2 { double x, y; } ARC_DVector2; +/** + * @brief normalizes a given ARC_Vector2 + * + * @param vector the ARC_Vecotr2 to normallize +*/ void ARC_Vector2_Normalize(ARC_Vector2 *vector); +/** + * @brief rotates a given ARC_Vector2 by a given angle in degrees + * + * @param vector the ARC_Vector2 to rotate + * @param angle the angle in degrees to rotate by +*/ +void ARC_Vector2_RotateDegree(ARC_Vector2 *vector, float angle); + #ifdef __cplusplus } #endif diff --git a/src/math/vector2.c b/src/math/vector2.c index c63bdf0..c0fdabe 100644 --- a/src/math/vector2.c +++ b/src/math/vector2.c @@ -5,4 +5,10 @@ void ARC_Vector2_Normalize(ARC_Vector2 *vector){ float length = sqrtf((vector->x * vector->x) + (vector->y * vector->y)); vector->x /= length; vector->y /= length; +} + +void ARC_Vector2_RotateDegree(ARC_Vector2 *vector, float angle){ + ARC_Vector2 temp = *vector; + vector->x = (temp.x * cos(angle)) - (temp.y * sin(angle)); + vector->y = (temp.x * sin(angle)) + (temp.y * cos(angle)); } \ No newline at end of file