cmdfx 0.1.1
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
util.h File Reference

Physics utilities for cmdfx. More...

Go to the source code of this file.

Classes

struct  CmdFX_Vector
 A 2D Vector. More...
 

Typedefs

typedef struct CmdFX_Vector CmdFX_Vector
 A 2D Vector.
 

Functions

CmdFX_VectorVector_create (int x, int y)
 Creates a new 2D Vector.
 
CmdFX_VectorVector_add (CmdFX_Vector *v1, CmdFX_Vector *v2)
 Adds two 2D Vectors.
 
CmdFX_VectorVector_addAll (CmdFX_Vector **vectors, int count)
 Adds multiple 2D Vectors.
 
CmdFX_VectorVector_subtract (CmdFX_Vector *v1, CmdFX_Vector *v2)
 Subtracts two 2D Vectors.
 
int Vector_multiply (CmdFX_Vector *v, double scalar)
 Multiplies a 2D Vector by a scalar.
 
int Vector_divide (CmdFX_Vector *v, double scalar)
 Divides a 2D Vector by a scalar.
 
int Vector_rotate (CmdFX_Vector *v, double radians)
 Rotates a 2D Vector by a specific number of radians.
 
int Vector_flipX (CmdFX_Vector *v)
 Flips a 2D Vector horizontally.
 
int Vector_flipY (CmdFX_Vector *v)
 Flips a 2D Vector vertically.
 
int Vector_flip (CmdFX_Vector *v)
 Flips a 2D Vector.
 
int Vector_dot (CmdFX_Vector *v1, CmdFX_Vector *v2)
 Multiplies a 2D Vector by a scalar.
 
double Vector_getMagnitude (CmdFX_Vector *v)
 Gets the magnitude of a 2D Vector.
 
double Vector_getAngle (CmdFX_Vector *v)
 Gets the angle of a 2D Vector.
 

Detailed Description

Physics utilities for cmdfx.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
0.1.1
Date
2025-02-09

Function Documentation

◆ Vector_add()

CmdFX_Vector * Vector_add ( CmdFX_Vector * v1,
CmdFX_Vector * v2 )

Adds two 2D Vectors.

Parameters
v1The first 2D Vector.
v2The second 2D Vector.
Returns
The sum of the two 2D Vectors.

◆ Vector_addAll()

CmdFX_Vector * Vector_addAll ( CmdFX_Vector ** vectors,
int count )

Adds multiple 2D Vectors.

Parameters
vectorsThe 2D Vectors.
countThe number of 2D Vectors.
Returns
The sum of the 2D Vectors.

◆ Vector_create()

CmdFX_Vector * Vector_create ( int x,
int y )

Creates a new 2D Vector.

This method creates a new 2D Vector with the given x and y coordinates. The vector must be freed with free when it is no longer needed.

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The new 2D Vector.

◆ Vector_divide()

int Vector_divide ( CmdFX_Vector * v,
double scalar )

Divides a 2D Vector by a scalar.

Parameters
vThe 2D Vector.
scalarThe scalar.
Returns
0 if successful, -1 if an error occurred.

◆ Vector_dot()

int Vector_dot ( CmdFX_Vector * v1,
CmdFX_Vector * v2 )

Multiplies a 2D Vector by a scalar.

Parameters
vThe 2D Vector.
scalarThe scalar.
Returns
The product of the 2D Vector and the scalar.

◆ Vector_flip()

int Vector_flip ( CmdFX_Vector * v)

Flips a 2D Vector.

Parameters
vThe 2D Vector.
Returns
0 if successful, -1 if an error occurred.

◆ Vector_flipX()

int Vector_flipX ( CmdFX_Vector * v)

Flips a 2D Vector horizontally.

Parameters
vThe 2D Vector.
Returns
0 if successful, -1 if an error occurred.

◆ Vector_flipY()

int Vector_flipY ( CmdFX_Vector * v)

Flips a 2D Vector vertically.

Parameters
vThe 2D Vector.
Returns
0 if successful, -1 if an error occurred.

◆ Vector_getAngle()

double Vector_getAngle ( CmdFX_Vector * v)

Gets the angle of a 2D Vector.

Parameters
vThe 2D Vector.
Returns
The angle of the 2D Vector, in radians.

◆ Vector_getMagnitude()

double Vector_getMagnitude ( CmdFX_Vector * v)

Gets the magnitude of a 2D Vector.

Parameters
vThe 2D Vector.
Returns
The magnitude of the 2D Vector.

◆ Vector_multiply()

int Vector_multiply ( CmdFX_Vector * v,
double scalar )

Multiplies a 2D Vector by a scalar.

Parameters
vThe 2D Vector.
scalarThe scalar.
Returns
0 if successful, -1 if an error occurred.

◆ Vector_rotate()

int Vector_rotate ( CmdFX_Vector * v,
double radians )

Rotates a 2D Vector by a specific number of radians.

This method rotates a 2D Vector by a specific number of radians. The rotation will be done around the origin.

Parameters
vThe 2D Vector.
radiansThe number of radians to rotate.
Returns
0 if successful, -1 if an error occurred.

◆ Vector_subtract()

CmdFX_Vector * Vector_subtract ( CmdFX_Vector * v1,
CmdFX_Vector * v2 )

Subtracts two 2D Vectors.

Parameters
v1The first 2D Vector.
v2The second 2D Vector.
Returns
The difference of the two 2D Vectors.