Archeus 0.0.0
A C library and game engine that focuses on documentation
Loading...
Searching...
No Matches
vector2.c File Reference
#include "arc/math/vector2.h"
#include <math.h>

Go to the source code of this file.

Functions

void ARC_Vector2_Normalize (ARC_Vector2 *vector)
 normalizes a given ARC_Vector2
 
void ARC_Vector2_RotateDegree (ARC_Vector2 *vector, float angle)
 rotates a given ARC_Vector2 by a given angle in degrees
 

Function Documentation

◆ ARC_Vector2_Normalize()

void ARC_Vector2_Normalize ( ARC_Vector2 * vector)

normalizes a given ARC_Vector2

Parameters
vectorthe ARC_Vecotr2 to normallize

Definition at line 4 of file vector2.c.

4 {
5 float length = sqrtf((vector->x * vector->x) + (vector->y * vector->y));
6 if(length == 0){
7 return;
8 }
9
10 vector->x /= length;
11 vector->y /= length;
12}
float x
Definition vector2.h:9
float y
Definition vector2.h:9

References ARC_Vector2::x, and ARC_Vector2::y.

◆ ARC_Vector2_RotateDegree()

void ARC_Vector2_RotateDegree ( ARC_Vector2 * vector,
float angle )

rotates a given ARC_Vector2 by a given angle in degrees

Parameters
vectorthe ARC_Vector2 to rotate
anglethe angle in degrees to rotate by

Definition at line 14 of file vector2.c.

14 {
15 ARC_Vector2 temp = *vector;
16 vector->x = (temp.x * cos(angle)) - (temp.y * sin(angle));
17 vector->y = (temp.x * sin(angle)) + (temp.y * cos(angle));
18}

References ARC_Vector2::x, and ARC_Vector2::y.