Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
vector2d.h File Reference

Detailed Description

Design Philosophy

These utility functions are can be used for signed integer vector 2D math. Vector math is useful for physics calculations.

Usage

No initialization or deinitialization is required. Each function will return a new vector and will not modify the vectors given as arguments. See the functions below for what is provided and how to use them.

Example

vec_t vecOne = {
.x = 3,
.y = 5,
};
vec_t vecTwo = {
.x = 8,
.y = 2,
};
vec_t vecSum = addVec2d(vecOne, vecTwo);
vec_t addVec2d(vec_t left, vec_t right)
Add two vectors and return the resulting vector.
Definition vector2d.c:11
int32_t x
The signed integer X component of the vector.
Definition vector2d.h:38
A 2D vector with signed integer X and Y components.
Definition vector2d.h:37

Go to the source code of this file.

Data Structures

struct  vec_t
 A 2D vector with signed integer X and Y components. More...
 

Functions

vec_t addVec2d (vec_t left, vec_t right)
 Add two vectors and return the resulting vector.
 
vec_t subVec2d (vec_t left, vec_t right)
 Subtract two vectors and return the resulting vector.
 
vec_t mulVec2d (vec_t vector, int32_t scalar)
 Multiply a vector by a scalar and return the result.
 
vec_t divVec2d (vec_t vector, int32_t scalar)
 Divide a vector by a scalar and return the result.
 
int32_t dotVec2d (vec_t left, vec_t right)
 Find the dot product of two vectors.
 
vec_t rotateVec2d (vec_t vector, int32_t degree)
 Rotate a vector by a number of degrees and return the result.
 
int32_t sqMagVec2d (vec_t vector)
 Return the squared magnitude of the given vector. The square root is not used because it is slow.
 

Data Structure Documentation

◆ vec_t

struct vec_t
Data Fields
int32_t x The signed integer X component of the vector.
int32_t y The signed integer Y component of the vector.

Function Documentation

◆ addVec2d()

vec_t addVec2d ( vec_t left,
vec_t right )

Add two vectors and return the resulting vector.

Parameters
leftOne vector to add
rightThe other vector to add
Returns
The sum of both vectors

◆ subVec2d()

vec_t subVec2d ( vec_t left,
vec_t right )

Subtract two vectors and return the resulting vector.

Parameters
leftThe vector to subtract from
rightThe other vector to subtract
Returns
The difference between the vectors

◆ mulVec2d()

vec_t mulVec2d ( vec_t vector,
int32_t scalar )

Multiply a vector by a scalar and return the result.

Parameters
vectorThe vector to multiply
scalarThe scalar to multiply by
Returns
The multiplied vector

◆ divVec2d()

vec_t divVec2d ( vec_t vector,
int32_t scalar )

Divide a vector by a scalar and return the result.

Parameters
vectorThe vector to divide
scalarThe scalar to divide by
Returns
The divided vector

◆ dotVec2d()

int32_t dotVec2d ( vec_t left,
vec_t right )

Find the dot product of two vectors.

Parameters
leftOne vector to dot
rightThe other vector to dot
Returns
The dot product of the two vectors

◆ rotateVec2d()

vec_t rotateVec2d ( vec_t vector,
int32_t degree )

Rotate a vector by a number of degrees and return the result.

Parameters
vectorThe vector to rotate
degreeThe angle to rotate clockwise by, in degrees
Returns
The rotated vector

◆ sqMagVec2d()

int32_t sqMagVec2d ( vec_t vector)

Return the squared magnitude of the given vector. The square root is not used because it is slow.

Parameters
vectorThe vector to get the squared magnitude for
Returns
The squared magnitude of the vector