Gama C Library
Gama C API Documentation
position.h File Reference
#include "../_math.h"
#include <stddef.h>
#include <string.h>
#include "../str.h"

Go to the source code of this file.

Data Structures

struct  gm3Pos
 Represents a 3D position or vector. More...

Macros

#define gm3pos(x, y, z)
 Creates a new gm3Pos struct with the given coordinates.
#define gm3_pos_magnitude(p)
 Calculates the magnitude (length) of a gm3Pos vector.
#define gm3_pos_distance(a, b)
 Calculates the Euclidean distance between two gm3Pos points.
#define gm3_pos_from2(p, z)
 Creates a gm3Pos from a 2D gmPos and a Z-coordinate.
#define gm3_pos_project_simple(p)
 Performs a simple perspective projection of a 3D point onto a 2D plane.
#define gm3_pos_dot(a, b)
 Calculates the dot product of two gm3Pos vectors.
#define gm3_pos_cross(a, b)
 Calculates the cross product of two gm3Pos vectors (a x b).
#define gm3_pos_reset(p)
 Resets the coordinates of a gm3Pos struct to (0, 0, 0).

Functions

void gm3_pos_mul (gm3Pos *res, const gm3Pos *trans)
 Multiplies the components of a gm3Pos vector by the corresponding components of another gm3Pos vector (component-wise multiplication).
void gm3_pos_mul_scalar (gm3Pos *res, double s)
 Multiplies the components of a gm3Pos vector by a scalar value.
int gmg_pos3 (gmStr *str, gm3Pos pos)
 Converts a gm3Pos struct to a string representation for debugging.

Macro Definition Documentation

◆ gm3_pos_cross

#define gm3_pos_cross ( a,
b )
Value:
((gm3Pos){(a).y * (b).z - (a).z * (b).y, (a).z * (b).x - (a).x * (b).z, \
(a).x * (b).y - (a).y * (b).x})
Represents a 3D position or vector.
Definition position.h:11

Calculates the cross product of two gm3Pos vectors (a x b).

Parameters
aThe first gm3Pos vector.
bThe second gm3Pos vector.
Returns
A new gm3Pos vector representing the cross product.

◆ gm3_pos_distance

#define gm3_pos_distance ( a,
b )
Value:
sqrt(pow((a).x - (b).x, 2) + pow((a).y - (b).y, 2) + pow((a).z - (b).z, 2))
double pow(double base, double exp)
Calculates the base raised to the power of the exponent (base^exp).
Definition math.h:358
double sqrt(double x)
Calculates the square root of x.
Definition math.h:339

Calculates the Euclidean distance between two gm3Pos points.

Parameters
aThe first gm3Pos point.
bThe second gm3Pos point.
Returns
The distance between the two points.

◆ gm3_pos_dot

#define gm3_pos_dot ( a,
b )
Value:
((a).x * (b).x + (a).y * (b).y + (a).z * (b).z)

Calculates the dot product of two gm3Pos vectors.

Parameters
aThe first gm3Pos vector.
bThe second gm3Pos vector.
Returns
The dot product (scalar value).

◆ gm3_pos_from2

#define gm3_pos_from2 ( p,
z )
Value:
gm3pos((p).x, (p).y, z)
#define gm3pos(x, y, z)
Creates a new gm3Pos struct with the given coordinates.
Definition position.h:22

Creates a gm3Pos from a 2D gmPos and a Z-coordinate.

Parameters
pThe 2D gmPos.
zThe Z-coordinate.
Returns
A new gm3Pos instance.

◆ gm3_pos_magnitude

#define gm3_pos_magnitude ( p)
Value:
sqrt((p).x *(p).x + (p).y * (p).y + (p).z * (p).z)

Calculates the magnitude (length) of a gm3Pos vector.

Parameters
pThe gm3Pos vector.
Returns
The magnitude of the vector.

◆ gm3_pos_project_simple

#define gm3_pos_project_simple ( p)
Value:
gmpos((p).x / (p).z, (p).y / (p).z)

Performs a simple perspective projection of a 3D point onto a 2D plane.

This macro assumes a camera at the origin looking down the Z-axis, and projects the point onto the Z=1 plane.

Parameters
pThe gm3Pos to project.
Returns
A gmPos representing the 2D projected coordinates.

◆ gm3_pos_reset

#define gm3_pos_reset ( p)
Value:
memset(p, 0, sizeof(*p))

Resets the coordinates of a gm3Pos struct to (0, 0, 0).

Parameters
pA pointer to the gm3Pos struct to reset.

◆ gm3pos

#define gm3pos ( x,
y,
z )
Value:
((gm3Pos){x, y, z})

Creates a new gm3Pos struct with the given coordinates.

Parameters
xThe X-coordinate.
yThe Y-coordinate.
zThe Z-coordinate.
Returns
A new gm3Pos instance.

Function Documentation

◆ gm3_pos_mul()

void gm3_pos_mul ( gm3Pos * res,
const gm3Pos * trans )

Multiplies the components of a gm3Pos vector by the corresponding components of another gm3Pos vector (component-wise multiplication).

Parameters
resA pointer to the gm3Pos vector to modify (result stored here).
transThe gm3Pos vector to multiply by.

◆ gm3_pos_mul_scalar()

void gm3_pos_mul_scalar ( gm3Pos * res,
double s )

Multiplies the components of a gm3Pos vector by a scalar value.

Parameters
resA pointer to the gm3Pos vector to modify (result stored here).
sThe scalar value to multiply by.

◆ gmg_pos3()

int gmg_pos3 ( gmStr * str,
gm3Pos pos )

Converts a gm3Pos struct to a string representation for debugging.

Parameters
strA pointer to a gmStr buffer to append the string to.
posThe gm3Pos struct to convert.
Returns
0 on success.