Operation Null Mind 0.4.1
A 2D roguelike top down shooter game made with SDL2
 
Loading...
Searching...
No Matches
vec2.h
Go to the documentation of this file.
1
70#include <SDL.h>
71#include <stdbool.h>
72
73#ifndef VEC2_H
74#define VEC2_H
75
80typedef struct Vec2
81{
82 float x;
83 float y;
85
87static const Vec2 Vec2_Zero = {0, 0};
89static const Vec2 Vec2_Up = {0, -1};
91static const Vec2 Vec2_Down = {0, 1};
93static const Vec2 Vec2_Left = {-1, 0};
95static const Vec2 Vec2_Right = {1, 0};
96
102float Vec2_Magnitude(Vec2 v);
103
110float Vec2_Distance(Vec2 a, Vec2 b);
111
118
125Vec2 Vec2_Add(Vec2 a, Vec2 b);
126
134
142
150
157Vec2 Vec2_Multiply(Vec2 v, float scalar);
158
165Vec2 Vec2_Divide(Vec2 v, float scalar);
166
173float Vec2_Dot(Vec2 a, Vec2 b);
174
182Vec2 Vec2_Lerp(Vec2 a, Vec2 b, float t);
183
190Vec2 Vec2_RotateDegrees(Vec2 v, float angle);
191
198Vec2 Vec2_RotateRadians(Vec2 v, float angle);
199
207Vec2 Vec2_RotateAroundRadians(Vec2 point, Vec2 center, float angle);
208
216Vec2 Vec2_RotateAroundDegrees(Vec2 point, Vec2 center, float angle);
217
224SDL_Rect Vec2_ToRect(Vec2 position, Vec2 size);
225
232SDL_Rect Vec2_ToCenteredRect(Vec2 position, Vec2 size);
233
240Vec2 Vec2_ToCenteredPosition(Vec2 position, Vec2 size);
241
248void Vec2_FromRect(SDL_Rect rect, Vec2* position, Vec2* size);
249
257Vec2 Vec2_Clamp(Vec2 v, Vec2 min, Vec2 max);
258
265Vec2 Vec2_Max(Vec2 a, Vec2 b);
266
273Vec2 Vec2_Min(Vec2 a, Vec2 b);
274
281
287Vec2 Vec2_FromPoint(SDL_Point point);
288
294SDL_Point Vec2_ToPoint(Vec2 v);
295
296bool Vec2_AreEqual(Vec2 a, Vec2 b);
297Vec2 Vec2_Square(float side);
298SDL_Rect Vec2_ToSquareRect(Vec2 position, float side);
299SDL_Rect Vec2_ToCenteredSquareRect(Vec2 position, float side);
300float Vec2_AngleBetween(Vec2 a, Vec2 b);
301#endif
A 2D vector structure.
Definition vec2.h:81
float y
The y-coordinate of the vector.
Definition vec2.h:83
float x
The x-coordinate of the vector.
Definition vec2.h:82
Vec2 Vec2_Normalize(Vec2 v)
Normalize a vector (make it unit length)
Definition vec2.c:49
Vec2 Vec2_RotateDegrees(Vec2 v, float angle)
Rotate a vector by an angle in degrees.
Definition vec2.c:168
Vec2 Vec2_ToCenteredPosition(Vec2 position, Vec2 size)
Convert a position and size to a centered position.
Definition vec2.c:242
Vec2 Vec2_RotateAroundRadians(Vec2 point, Vec2 center, float angle)
Rotate a point around a center by an angle in radians.
Definition vec2.c:182
float Vec2_AngleBetween(Vec2 a, Vec2 b)
Calculates the angle between two vectors in degrees.
Definition vec2.c:370
Vec2 Vec2_Divide(Vec2 v, float scalar)
Divide a vector by a scalar.
Definition vec2.c:121
float Vec2_Distance(Vec2 a, Vec2 b)
Calculate the distance between two vectors.
Definition vec2.c:38
SDL_Rect Vec2_ToSquareRect(Vec2 position, float side)
Definition vec2.c:354
Vec2 Vec2_Square(float side)
Definition vec2.c:350
Vec2 Vec2_Min(Vec2 a, Vec2 b)
Get the minimum of two vectors.
Definition vec2.c:300
SDL_Point Vec2_ToPoint(Vec2 v)
Convert a Vec2 to an SDL_Point.
Definition vec2.c:339
bool Vec2_AreEqual(Vec2 a, Vec2 b)
Definition vec2.c:346
float Vec2_Dot(Vec2 a, Vec2 b)
Calculate the dot product of two vectors.
Definition vec2.c:132
Vec2 Vec2_Max(Vec2 a, Vec2 b)
Get the maximum of two vectors.
Definition vec2.c:286
SDL_Rect Vec2_ToCenteredRect(Vec2 position, Vec2 size)
Convert a position and size to a centered SDL_Rect.
Definition vec2.c:225
float Vec2_Magnitude(Vec2 v)
Calculate the magnitude (length) of a vector.
Definition vec2.c:27
Vec2 Vec2_Decrement(Vec2 *a, Vec2 b)
Decrement vector a by vector b.
Definition vec2.c:97
Vec2 Vec2_Lerp(Vec2 a, Vec2 b, float t)
Linearly interpolate between two vectors.
Definition vec2.c:144
Vec2 Vec2_RotateAroundDegrees(Vec2 point, Vec2 center, float angle)
Rotate a point around a center by an angle in degrees.
Definition vec2.c:196
Vec2 Vec2_Multiply(Vec2 v, float scalar)
Multiply a vector by a scalar.
Definition vec2.c:110
Vec2 Vec2_RotateRadians(Vec2 v, float angle)
Rotate a vector by an angle in radians.
Definition vec2.c:155
void Vec2_FromRect(SDL_Rect rect, Vec2 *position, Vec2 *size)
Extract position and size from an SDL_Rect.
Definition vec2.c:256
SDL_Rect Vec2_ToCenteredSquareRect(Vec2 position, float side)
Definition vec2.c:358
Vec2 Vec2_FromPoint(SDL_Point point)
Convert an SDL_Point to a Vec2.
Definition vec2.c:326
Vec2 Vec2_Clamp(Vec2 v, Vec2 min, Vec2 max)
Clamp a vector between two vectors.
Definition vec2.c:272
SDL_Rect Vec2_ToRect(Vec2 position, Vec2 size)
Convert a position and size to an SDL_Rect.
Definition vec2.c:208
Vec2 Vec2_Subtract(Vec2 a, Vec2 b)
Subtract vector b from vector a.
Definition vec2.c:86
Vec2 Vec2_Add(Vec2 a, Vec2 b)
Add two vectors.
Definition vec2.c:62
Vec2 Vec2_Increment(Vec2 *a, Vec2 b)
Increment vector a by vector b.
Definition vec2.c:73
Vec2 Vec2_Abs(Vec2 v)
Get the absolute value of a vector.
Definition vec2.c:313