libgpac
Documentation of the core library of GPAC
Math 3d

3D Mathematics More...

+ Collaboration diagram for Math 3d:

Data Structures

struct  GF_Vec
 3D point or vector More...
 
struct  GF_Vec4
 4D vector More...
 
struct  GF_Matrix
 3D matrix More...
 
struct  GF_BBox
 3D Bounding Box More...
 
struct  GF_Plane
 Plane object. More...
 
struct  GF_Ray
 3D Ray More...
 

Macros

#define gf_vec_equal(v1, v2)
 
#define gf_vec_rev(v)
 
#define gf_vec_diff(res, v1, v2)
 
#define gf_vec_add(res, v1, v2)
 
#define gf_quat_len(v)
 
#define gf_quat_norm(v)
 
#define gf_mx_init(_obj)
 matrix initialization More...
 
#define gf_mx_is_identity(_obj)   ((!(_obj).m[1] && !(_obj).m[2] && !(_obj).m[3] && !(_obj).m[4] && !(_obj).m[6] && !(_obj).m[7] && !(_obj).m[8] && !(_obj).m[9] && !(_obj).m[11] && !(_obj).m[12] && !(_obj).m[13] && !(_obj).m[14] && ((_obj).m[0]==FIX_ONE) && ((_obj).m[5]==FIX_ONE)&& ((_obj).m[10]==FIX_ONE)&& ((_obj).m[15]==FIX_ONE)) ? 1 : 0)
 
#define gf_mx_copy(_obj, from)
 matrix copy More...
 

Enumerations

enum  { GF_BBOX_FRONT , GF_BBOX_INTER , GF_BBOX_BACK }
 

Functions

Fixed gf_vec_len (GF_Vec v)
 get 3D vector length More...
 
Fixed gf_vec_len_p (GF_Vec *v)
 get 3D vector length More...
 
Fixed gf_vec_lensq (GF_Vec v)
 get 3D vector square length More...
 
Fixed gf_vec_lensq_p (GF_Vec *v)
 get 3D vector square length More...
 
Fixed gf_vec_dot (GF_Vec v1, GF_Vec v2)
 get 3D vector dot product More...
 
Fixed gf_vec_dot_p (GF_Vec *v1, GF_Vec *v2)
 get 3D vector dot product More...
 
void gf_vec_norm (GF_Vec *v)
 vector normalization More...
 
GF_Vec gf_vec_scale (GF_Vec v, Fixed f)
 vector scaling More...
 
GF_Vec gf_vec_scale_p (GF_Vec *v, Fixed f)
 vector scaling More...
 
GF_Vec gf_vec_cross (GF_Vec v1, GF_Vec v2)
 vector cross product More...
 
GF_Vec gf_vec_cross_p (GF_Vec *v1, GF_Vec *v2)
 vector cross product More...
 
GF_Vec4 gf_quat_to_rotation (GF_Vec4 *quat)
 quaternion to rotation More...
 
GF_Vec4 gf_quat_from_rotation (GF_Vec4 rot)
 quaternion from rotation More...
 
GF_Vec4 gf_quat_get_inv (GF_Vec4 *quat)
 
GF_Vec4 gf_quat_multiply (GF_Vec4 *q1, GF_Vec4 *q2)
 quaternion multiplication More...
 
GF_Vec gf_quat_rotate (GF_Vec4 *quat, GF_Vec *vec)
 quaternion vector rotating More...
 
GF_Vec4 gf_quat_from_axis_cos (GF_Vec axis, Fixed cos_a)
 quaternion from axis and cos More...
 
GF_Vec4 gf_quat_slerp (GF_Vec4 q1, GF_Vec4 q2, Fixed frac)
 quaternion interpolation More...
 
void gf_bbox_refresh (GF_BBox *b)
 
void gf_bbox_from_rect (GF_BBox *box, GF_Rect *rc)
 
void gf_rect_from_bbox (GF_Rect *rc, GF_BBox *box)
 
void gf_bbox_grow_point (GF_BBox *box, GF_Vec pt)
 bounding box expansion More...
 
void gf_bbox_union (GF_BBox *b1, GF_BBox *b2)
 
Bool gf_bbox_equal (GF_BBox *b1, GF_BBox *b2)
 
Bool gf_bbox_point_inside (GF_BBox *box, GF_Vec *p)
 
void gf_bbox_get_vertices (GF_Vec bmin, GF_Vec bmax, GF_Vec *vecs)
 get box vertices More...
 
void gf_mx_from_mx2d (GF_Matrix *mx, GF_Matrix2D *mat2D)
 matrix constructor from 2D More...
 
Bool gf_mx_equal (GF_Matrix *mx1, GF_Matrix *mx2)
 matrix equality testing More...
 
void gf_mx_add_translation (GF_Matrix *mx, Fixed tx, Fixed ty, Fixed tz)
 matrix translation More...
 
void gf_mx_add_scale (GF_Matrix *mx, Fixed sx, Fixed sy, Fixed sz)
 matrix scaling More...
 
void gf_mx_add_rotation (GF_Matrix *mx, Fixed angle, Fixed x, Fixed y, Fixed z)
 matrix rotating More...
 
void gf_mx_add_matrix (GF_Matrix *mx, GF_Matrix *mul)
 matrices multiplication More...
 
void gf_mx_add_matrix_2d (GF_Matrix *mx, GF_Matrix2D *mat2D)
 2D matrix multiplication More...
 
void gf_mx_inverse (GF_Matrix *mx)
 affine matrix inversion More...
 
void gf_mx_transpose (GF_Matrix *mx)
 transpose 4x4 matrix More...
 
void gf_mx_apply_vec (GF_Matrix *mx, GF_Vec *pt)
 matrix point transformation More...
 
void gf_mx_apply_rect (GF_Matrix *_this, GF_Rect *rc)
 matrix rectangle transformation More...
 
void gf_mx_ortho (GF_Matrix *mx, Fixed left, Fixed right, Fixed bottom, Fixed top, Fixed z_near, Fixed z_far)
 ortho matrix construction More...
 
void gf_mx_ortho_reverse_z (GF_Matrix *mx, Fixed left, Fixed right, Fixed bottom, Fixed top, Fixed z_near, Fixed z_far)
 ortho matrix with reverse Z construction More...
 
void gf_mx_perspective (GF_Matrix *mx, Fixed fov, Fixed aspect_ratio, Fixed z_near, Fixed z_far)
 perspective matrix construction More...
 
void gf_mx_perspective_reverse_z (GF_Matrix *mx, Fixed fov, Fixed aspect_ratio, Fixed z_near, Fixed z_far)
 perspective matrix with reverse Z construction More...
 
void gf_mx_lookat (GF_Matrix *mx, GF_Vec position, GF_Vec target, GF_Vec up_vector)
 creates look matrix More...
 
void gf_mx_apply_bbox (GF_Matrix *mx, GF_BBox *b)
 matrix box transformation More...
 
void gf_mx_apply_bbox_4x4 (GF_Matrix *mx, GF_BBox *b)
 matrix box transformation More...
 
void gf_mx_apply_bbox_sphere (GF_Matrix *mx, GF_BBox *box)
 matrix box sphere transformation More...
 
void gf_mx_add_matrix_4x4 (GF_Matrix *mat, GF_Matrix *mul)
 non-affine matrix multiplication More...
 
Bool gf_mx_inverse_4x4 (GF_Matrix *mx)
 non-affine matrix inversion More...
 
void gf_mx_apply_vec_4x4 (GF_Matrix *mx, GF_Vec4 *vec)
 matrix 4D vector transformation More...
 
void gf_mx_get_yaw_pitch_roll (GF_Matrix *mx, Fixed *yaw, Fixed *pitch, Fixed *roll)
 matrix yaw pitch roll decomposition More...
 
void gf_mx_decompose (GF_Matrix *mx, GF_Vec *translate, GF_Vec *scale, GF_Vec4 *rotate, GF_Vec *shear)
 matrix decomposition More...
 
void gf_mx_rotate_vector (GF_Matrix *mx, GF_Vec *pt)
 matrix vector rotation More...
 
void gf_mx_rotation_matrix_from_vectors (GF_Matrix *mx, GF_Vec x_axis, GF_Vec y_axis, GF_Vec z_axis)
 matrix initialization from vectors More...
 
void gf_mx2d_from_mx (GF_Matrix2D *mx2d, GF_Matrix *mx)
 matrix to 2D matrix More...
 
void gf_mx_apply_plane (GF_Matrix *mx, GF_Plane *plane)
 matrix plane transformation More...
 
Fixed gf_plane_get_distance (GF_Plane *plane, GF_Vec *p)
 point to plane distance More...
 
GF_Vec gf_closest_point_to_line (GF_Vec line_pt, GF_Vec line_vec, GF_Vec pt)
 closest point on a line More...
 
u32 gf_plane_get_p_vertex_idx (GF_Plane *p)
 box p-vertex index More...
 
Bool gf_plane_intersect_line (GF_Plane *plane, GF_Vec *linepoint, GF_Vec *linevec, GF_Vec *outPoint)
 plane line intersection More...
 
u32 gf_bbox_plane_relation (GF_BBox *box, GF_Plane *p)
 box-plane relation More...
 
GF_Ray gf_ray (GF_Vec start, GF_Vec end)
 ray constructor More...
 
void gf_mx_apply_ray (GF_Matrix *mx, GF_Ray *r)
 matrix ray transformation More...
 
Bool gf_ray_hit_box (GF_Ray *ray, GF_Vec min_edge, GF_Vec max_edge, GF_Vec *out_point)
 ray box intersection test More...
 
Bool gf_ray_hit_sphere (GF_Ray *ray, GF_Vec *center, Fixed radius, GF_Vec *out_point)
 ray sphere intersection test More...
 
Bool gf_ray_hit_triangle (GF_Ray *ray, GF_Vec *v0, GF_Vec *v1, GF_Vec *v2, Fixed *dist)
 ray triangle intersection test More...
 

Detailed Description

This section documents mathematic tools for 3D geometry operations


Data Structure Documentation

◆ GF_Vec

struct GF_Vec

The 3D point object is used in all the GPAC framework for both point and vector representation.

Data Fields
Fixed x
Fixed y
Fixed z

◆ GF_Vec4

struct GF_Vec4

The 4D vector object is used in all the GPAC framework for 4 dimension vectors, VRML Rotations and quaternions representation.

Data Fields
Fixed x
Fixed y
Fixed z
Fixed q

◆ GF_Matrix

struct GF_Matrix

The 3D matrix object used in GPAC. The matrix is oriented like OpenGL matrices (column-major ordering), with the translation part at the end of the coefficients list.

Note
Unless specified otherwise, the matrix object is always expected to represent an affine transformation.
Data Fields
Fixed m[16]

◆ GF_BBox

struct GF_BBox

The 3D Bounding Box is a 3D Axis-Aligned Bounding Box used to in various tools of the GPAC framework for bounds estimation of a 3D object. It features an axis-aligned box and a sphere bounding volume for fast intersection tests.

+ Collaboration diagram for GF_BBox:
Data Fields
GF_Vec min_edge

minimum x, y, and z of the object

GF_Vec max_edge

maximum x, y, and z of the object

GF_Vec center

center of the bounding box.

Note
this is computed from min_edge and max_edge
Fixed radius

radius of the bounding sphere for this box.

Note
this is computed from min_edge and max_edge
Bool is_set

the bbox center and radius are valid

◆ GF_Plane

struct GF_Plane
+ Collaboration diagram for GF_Plane:
Data Fields
GF_Vec normal

normal vector to the plane

Fixed d

distance from origin of the plane

◆ GF_Ray

struct GF_Ray

The 3D ray object is used in GPAC for all collision and mouse interaction tests

+ Collaboration diagram for GF_Ray:
Data Fields
GF_Vec orig

origin point of the ray

GF_Vec dir

normalized direction vector of the ray

Macro Definition Documentation

◆ gf_vec_equal

#define gf_vec_equal (   v1,
  v2 
)

macro evaluating to 1 if vectors are equal, 0 otherwise

◆ gf_vec_rev

#define gf_vec_rev (   v)

macro reversing a vector v = v

◆ gf_vec_diff

#define gf_vec_diff (   res,
  v1,
  v2 
)

macro performing the minus operation res = v1 - v2

◆ gf_vec_add

#define gf_vec_add (   res,
  v1,
  v2 
)

macro performing the add operation res = v1 + v2

◆ gf_quat_len

#define gf_quat_len (   v)

gets the len of a quaternion

◆ gf_quat_norm

#define gf_quat_norm (   v)

normalizes a quaternion

◆ gf_mx_init

#define gf_mx_init (   _obj)

Inits the matrix to the identity matrix

◆ gf_mx_is_identity

#define gf_mx_is_identity (   _obj)    ((!(_obj).m[1] && !(_obj).m[2] && !(_obj).m[3] && !(_obj).m[4] && !(_obj).m[6] && !(_obj).m[7] && !(_obj).m[8] && !(_obj).m[9] && !(_obj).m[11] && !(_obj).m[12] && !(_obj).m[13] && !(_obj).m[14] && ((_obj).m[0]==FIX_ONE) && ((_obj).m[5]==FIX_ONE)&& ((_obj).m[10]==FIX_ONE)&& ((_obj).m[15]==FIX_ONE)) ? 1 : 0)

macro to check if a matrix is the identity matrix

◆ gf_mx_copy

#define gf_mx_copy (   _obj,
  from 
)

Copies the matrix _from to the matrix _obj

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Classification types for box/plane position used in gf_bbox_plane_relation

Enumerator
GF_BBOX_FRONT 

box is in front of the plane

GF_BBOX_INTER 

box intersects the plane

GF_BBOX_BACK 

box is back of the plane

Function Documentation

◆ gf_vec_len()

Fixed gf_vec_len ( GF_Vec  v)

Gets the length of a 3D vector

Parameters
vthe target vector
Returns
length of the vector

◆ gf_vec_len_p()

Fixed gf_vec_len_p ( GF_Vec v)

Gets the length of a 3D vector

Parameters
vthe target vector
Returns
length of the vector

◆ gf_vec_lensq()

Fixed gf_vec_lensq ( GF_Vec  v)

Gets the square length of a 3D vector

Parameters
vthe target vector
Returns
square length of the vector

◆ gf_vec_lensq_p()

Fixed gf_vec_lensq_p ( GF_Vec v)

Gets the square length of a 3D vector

Parameters
vthe target vector
Returns
square length of the vector

◆ gf_vec_dot()

Fixed gf_vec_dot ( GF_Vec  v1,
GF_Vec  v2 
)

Gets the dot product of two vectors

Parameters
v1first vector
v2second vector
Returns
dot product of the vectors

◆ gf_vec_dot_p()

Fixed gf_vec_dot_p ( GF_Vec v1,
GF_Vec v2 
)

Gets the dot product of two vectors

Parameters
v1first vector
v2second vector
Returns
dot product of the vectors

◆ gf_vec_norm()

void gf_vec_norm ( GF_Vec v)

Normalize the vector, eg make its length equal to FIX_ONE

Parameters
vvector to normalize

◆ gf_vec_scale()

GF_Vec gf_vec_scale ( GF_Vec  v,
Fixed  f 
)

Scales a vector by a given amount

Parameters
vvector to scale
fscale factor
Returns
scaled vector

◆ gf_vec_scale_p()

GF_Vec gf_vec_scale_p ( GF_Vec v,
Fixed  f 
)

Scales a vector by a given amount

Parameters
vvector to scale
fscale factor
Returns
scaled vector

◆ gf_vec_cross()

GF_Vec gf_vec_cross ( GF_Vec  v1,
GF_Vec  v2 
)

Gets the cross product of two vectors

Parameters
v1first vector
v2second vector
Returns
cross-product vector

◆ gf_vec_cross_p()

GF_Vec gf_vec_cross_p ( GF_Vec v1,
GF_Vec v2 
)

Gets the cross product of two vectors

Parameters
v1first vector
v2second vector
Returns
cross-product vector

◆ gf_quat_to_rotation()

GF_Vec4 gf_quat_to_rotation ( GF_Vec4 quat)

Transforms a quaternion to a Rotation, expressed as a 4 dimension vector with x,y,z for axis and q for rotation angle

Parameters
quatthe quaternion to transform
Returns
the rotation value

◆ gf_quat_from_rotation()

GF_Vec4 gf_quat_from_rotation ( GF_Vec4  rot)

Transforms a Rotation to a quaternion

Parameters
rotthe rotation to transform
Returns
the quaternion value

◆ gf_quat_get_inv()

GF_Vec4 gf_quat_get_inv ( GF_Vec4 quat)

Inverses a quaternion

Parameters
quatthe quaternion to inverse
Returns
the inverted quaternion

◆ gf_quat_multiply()

GF_Vec4 gf_quat_multiply ( GF_Vec4 q1,
GF_Vec4 q2 
)

Multiplies two quaternions

Parameters
q1the first quaternion
q2the second quaternion
Returns
the resulting quaternion

◆ gf_quat_rotate()

GF_Vec gf_quat_rotate ( GF_Vec4 quat,
GF_Vec vec 
)

Rotates a vector with a quaternion

Parameters
quatthe quaternion modelizing the rotation
vecthe vector to rotate
Returns
the resulting vector

◆ gf_quat_from_axis_cos()

GF_Vec4 gf_quat_from_axis_cos ( GF_Vec  axis,
Fixed  cos_a 
)

Constructs a quaternion from an axis and a cosinus value (shortcut to gf_quat_from_rotation)

Parameters
axisthe rotation axis
cos_athe rotation cosinus value
Returns
the resulting quaternion

◆ gf_quat_slerp()

GF_Vec4 gf_quat_slerp ( GF_Vec4  q1,
GF_Vec4  q2,
Fixed  frac 
)

Interpolates two quaternions using spherical linear interpolation

Parameters
q1the first quaternion
q2the second quaternion
fracthe fraction of the interpolation, between 0 and FIX_ONE
Returns
the interpolated quaternion

◆ gf_bbox_refresh()

void gf_bbox_refresh ( GF_BBox b)

updates information of the bounding box based on the edge information

Parameters
bthe target bounding box

◆ gf_bbox_from_rect()

void gf_bbox_from_rect ( GF_BBox box,
GF_Rect rc 
)

builds a bounding box from a 2D rectangle

Parameters
boxthe bounding box to build
rcthe source rectangle

◆ gf_rect_from_bbox()

void gf_rect_from_bbox ( GF_Rect rc,
GF_BBox box 
)

builds a rectangle from a 3D bounding box.

Note
The z dimension is lost and no projection is performed
Parameters
rcthe destination rectangle
boxthe source bounding box

◆ gf_bbox_grow_point()

void gf_bbox_grow_point ( GF_BBox box,
GF_Vec  pt 
)

Checks if a point is inside a bounding box and updates the bounding box to include it if not the case

Parameters
boxthe bounding box object
ptthe 3D point to check

◆ gf_bbox_union()

void gf_bbox_union ( GF_BBox b1,
GF_BBox b2 
)

performs the union of two bounding boxes

Parameters
b1the first bounding box
b2the bounding box to add

◆ gf_bbox_equal()

Bool gf_bbox_equal ( GF_BBox b1,
GF_BBox b2 
)

checks if two bounding boxes are equal or not

Parameters
b1the first bounding box
b2the second bounding box
Returns
GF_TRUE if equal

◆ gf_bbox_point_inside()

Bool gf_bbox_point_inside ( GF_BBox box,
GF_Vec p 
)

checks if a point is inside a bounding box or not

Parameters
boxthe bounding box
pthe point to check
Returns
GF_TRUE if point is inside

◆ gf_bbox_get_vertices()

void gf_bbox_get_vertices ( GF_Vec  bmin,
GF_Vec  bmax,
GF_Vec vecs 
)

Returns the 8 bounding box vertices given the minimum and maximum edge. Vertices are ordered to respect "p-vertex indexes", (vertex from a box closest to plane) and so that n-vertex (vertex from a box farthest from plane) is 7-p_vx_idx

Parameters
bminminimum edge of the box
bmaxmaximum edge of the box
vecslist of 8 3D points used to store the vertices.

◆ gf_mx_from_mx2d()

void gf_mx_from_mx2d ( GF_Matrix mx,
GF_Matrix2D mat2D 
)

Initializes a 3D matrix from a 2D matrix.

Note
all z-related coefficients will be set to default.
Parameters
mxthe target matrix to initialize
mat2Dthe source 2D matrix

◆ gf_mx_equal()

Bool gf_mx_equal ( GF_Matrix mx1,
GF_Matrix mx2 
)

Tests if two matrices are equal or not.

Parameters
mx1the first matrix
mx2the first matrix
Returns
GF_TRUE if matrices are same, GF_FALSE otherwise

◆ gf_mx_add_translation()

void gf_mx_add_translation ( GF_Matrix mx,
Fixed  tx,
Fixed  ty,
Fixed  tz 
)

Translates a matrix

Parameters
mxthe matrix being transformed. Once the function is called, contains the result matrix
txhorizontal translation
tyvertical translation
tzdepth translation

◆ gf_mx_add_scale()

void gf_mx_add_scale ( GF_Matrix mx,
Fixed  sx,
Fixed  sy,
Fixed  sz 
)

Scales a matrix

Parameters
mxthe matrix being transformed. Once the function is called, contains the result matrix
sxhorizontal translation scaling
syvertical translation scaling
szdepth translation scaling

◆ gf_mx_add_rotation()

void gf_mx_add_rotation ( GF_Matrix mx,
Fixed  angle,
Fixed  x,
Fixed  y,
Fixed  z 
)

Rotates a matrix

Parameters
mxthe matrix being transformed. Once the function is called, contains the result matrix
anglerotation angle in radians
xhorizontal coordinate of rotation axis
yvertical coordinate of rotation axis
zdepth coordinate of rotation axis

◆ gf_mx_add_matrix()

void gf_mx_add_matrix ( GF_Matrix mx,
GF_Matrix mul 
)

Multiplies a matrix with another one mx = mx*mul

Parameters
mxthe matrix being transformed. Once the function is called, contains the result matrix
multhe matrix to add

◆ gf_mx_add_matrix_2d()

void gf_mx_add_matrix_2d ( GF_Matrix mx,
GF_Matrix2D mat2D 
)

Adds a 2D affine matrix to a matrix

Parameters
mxthe matrix
mat2Dthe matrix to premultiply

◆ gf_mx_inverse()

void gf_mx_inverse ( GF_Matrix mx)

Inverses an affine matrix.

Warning
Results are undefined if the matrix is not an affine one
Parameters
mxthe matrix to inverse

◆ gf_mx_transpose()

void gf_mx_transpose ( GF_Matrix mx)

Transposes a 4x4 matrix

Parameters
mxthe matrix to transpose

◆ gf_mx_apply_vec()

void gf_mx_apply_vec ( GF_Matrix mx,
GF_Vec pt 
)

Applies a 3D matrix transformation to a 3D point

Parameters
mxtransformation matrix
ptpointer to 3D point. Once the function is called, pt contains the transformed point

◆ gf_mx_apply_rect()

void gf_mx_apply_rect ( GF_Matrix _this,
GF_Rect rc 
)

Applies a 3D matrix transformation to a rectangle, giving the enclosing rectangle of the transformed one.

Note
all depth information are discarded.
Parameters
_thistransformation matrix
rcpointer to rectangle. Once the function is called, rc contains the transformed rectangle

◆ gf_mx_ortho()

void gf_mx_ortho ( GF_Matrix mx,
Fixed  left,
Fixed  right,
Fixed  bottom,
Fixed  top,
Fixed  z_near,
Fixed  z_far 
)

Creates an orthogonal projection matrix. This assume the NDC Z lies in [-1,1]

Parameters
mxmatrix to initialize
leftmin horizontal coordinate of viewport
rightmax horizontal coordinate of viewport
bottommin vertical coordinate of viewport
topmax vertical coordinate of viewport
z_nearmin depth coordinate of viewport
z_farmax depth coordinate of viewport

◆ gf_mx_ortho_reverse_z()

void gf_mx_ortho_reverse_z ( GF_Matrix mx,
Fixed  left,
Fixed  right,
Fixed  bottom,
Fixed  top,
Fixed  z_near,
Fixed  z_far 
)

Creates an orthogonal projection matrix with reverse Z. This assume the NDC Z lies in [0,1], not [-1,1]

Parameters
mxmatrix to initialize
leftmin horizontal coordinate of viewport
rightmax horizontal coordinate of viewport
bottommin vertical coordinate of viewport
topmax vertical coordinate of viewport
z_nearmin depth coordinate of viewport
z_farmax depth coordinate of viewport

◆ gf_mx_perspective()

void gf_mx_perspective ( GF_Matrix mx,
Fixed  fov,
Fixed  aspect_ratio,
Fixed  z_near,
Fixed  z_far 
)

Creates a perspective projection matrix. This assume the NDC Z lies in [-1,1]

Parameters
mxmatrix to initialize
fovcamera field of view angle in radian
aspect_ratioviewport aspect ratio
z_nearmin depth coordinate of viewport
z_farmax depth coordinate of viewport

◆ gf_mx_perspective_reverse_z()

void gf_mx_perspective_reverse_z ( GF_Matrix mx,
Fixed  fov,
Fixed  aspect_ratio,
Fixed  z_near,
Fixed  z_far 
)

Creates a perspective projection matrix with reverse Z. This assume the NDC Z lies in [0,1]

Parameters
mxmatrix to initialize
fovcamera field of view angle in radian
aspect_ratioviewport aspect ratio
z_nearmin depth coordinate of viewport
z_farmax depth coordinate of viewport

◆ gf_mx_lookat()

void gf_mx_lookat ( GF_Matrix mx,
GF_Vec  position,
GF_Vec  target,
GF_Vec  up_vector 
)

Creates a transformation matrix looking at a given direction from a given point (camera matrix).

Parameters
mxmatrix to initialize
positionposition
targetlook direction
up_vectorvector describing the up direction

◆ gf_mx_apply_bbox()

void gf_mx_apply_bbox ( GF_Matrix mx,
GF_BBox b 
)

Applies a 3D matrix transformation to a bounding box, giving the enclosing box of the transformed one

Parameters
mxtransformation matrix
bpointer to bounding box. Once the function is called, contains the transformed bounding box

◆ gf_mx_apply_bbox_4x4()

void gf_mx_apply_bbox_4x4 ( GF_Matrix mx,
GF_BBox b 
)

Applies a 3D matrix transformation using perspective division to a bounding box, giving the enclosing box of the transformed one

Parameters
mxtransformation matrix
bpointer to bounding box. Once the function is called, contains the transformed bounding box

◆ gf_mx_apply_bbox_sphere()

void gf_mx_apply_bbox_sphere ( GF_Matrix mx,
GF_BBox box 
)

Applies a 3D matrix transformation to a bounding box, computing only the enclosing sphere of the transformed one.

Parameters
mxtransformation matrix
boxpointer to bounding box. Once the function is called, contains the transformed bounding sphere

◆ gf_mx_add_matrix_4x4()

void gf_mx_add_matrix_4x4 ( GF_Matrix mat,
GF_Matrix mul 
)

Multiplies two non-affine matrices mx = mx*mul

Parameters
matthe target matrix
multhe matrix we multiply with

◆ gf_mx_inverse_4x4()

Bool gf_mx_inverse_4x4 ( GF_Matrix mx)

Inverses a non-affine matrices

Parameters
mxthe target matrix
Returns
1 if inversion was done, 0 if inversion not possible.

◆ gf_mx_apply_vec_4x4()

void gf_mx_apply_vec_4x4 ( GF_Matrix mx,
GF_Vec4 vec 
)

Applies a 3D non-affine matrix transformation to a 4 dimension vector

Parameters
mxtransformation matrix
vecpointer to the vector. Once the function is called, contains the transformed vector

◆ gf_mx_get_yaw_pitch_roll()

void gf_mx_get_yaw_pitch_roll ( GF_Matrix mx,
Fixed yaw,
Fixed pitch,
Fixed roll 
)

Extracts yaw, pitch and roll info from a matrix

Parameters
mxthe matrix to decompose
yawthe extracted yaw angle in radians
pitchthe extracted pitch angle in radians
rollthe extracted roll angle in radians

◆ gf_mx_decompose()

void gf_mx_decompose ( GF_Matrix mx,
GF_Vec translate,
GF_Vec scale,
GF_Vec4 rotate,
GF_Vec shear 
)

Decomposes a matrix into translation, scale, shear and rotate

Parameters
mxthe matrix to decompose
translatethe decomposed translation part
scalethe decomposed scaling part
rotatethe decomposed rotation part, expressed as a Rotataion (axis + angle)
shearthe decomposed shear part

◆ gf_mx_rotate_vector()

void gf_mx_rotate_vector ( GF_Matrix mx,
GF_Vec pt 
)

Rotates a vector with a given matrix, ignoring any translation.

Parameters
mxtransformation matrix
ptpointer to 3D vector. Once the function is called, pt contains the transformed vector

◆ gf_mx_rotation_matrix_from_vectors()

void gf_mx_rotation_matrix_from_vectors ( GF_Matrix mx,
GF_Vec  x_axis,
GF_Vec  y_axis,
GF_Vec  z_axis 
)

Inits a matrix to rotate the local axis in the given vectors

Parameters
mxmatrix to initialize
x_axistarget normalized X axis
y_axistarget normalized Y axis
z_axistarget normalized Z axis

◆ gf_mx2d_from_mx()

void gf_mx2d_from_mx ( GF_Matrix2D mx2d,
GF_Matrix mx 
)

Inits a 2D matrix by removing all depth info from a 3D matrix

Parameters
mx2d2D matrix to initialize
mx3D matrix to use

◆ gf_mx_apply_plane()

void gf_mx_apply_plane ( GF_Matrix mx,
GF_Plane plane 
)

Transorms a plane by a given matrix

Parameters
mxthe matrix to use
planepointer to 3D plane. Once the function is called, plane contains the transformed plane

◆ gf_plane_get_distance()

Fixed gf_plane_get_distance ( GF_Plane plane,
GF_Vec p 
)

Gets the distance between a point and a plne

Parameters
planethe plane to use
ppointer to ^point to check
Returns
the distance between the place and the point

◆ gf_closest_point_to_line()

GF_Vec gf_closest_point_to_line ( GF_Vec  line_pt,
GF_Vec  line_vec,
GF_Vec  pt 
)

Gets the closest point on a line from a given point in space

Parameters
line_pta point of the line to test
line_vecthe normalized direction vector of the line
ptthe point to check
Returns
the closest point on the line to the desired point

◆ gf_plane_get_p_vertex_idx()

u32 gf_plane_get_p_vertex_idx ( GF_Plane p)

Gets the p-vertex index for a given plane. The p-vertex index is the index of the closest vertex of a bounding box to the plane. The vertices of a box are always ordered in GPAC? cf gf_bbox_get_vertices

Parameters
pthe plane to check
Returns
the p-vertex index value, ranging from 0 to 7

◆ gf_plane_intersect_line()

Bool gf_plane_intersect_line ( GF_Plane plane,
GF_Vec linepoint,
GF_Vec linevec,
GF_Vec outPoint 
)

Checks for the intersection of a plane and a line

Parameters
planeplane to test
linepointa point on the line to test
linevecnormalized direction vector of the line to test
outPointoptional pointer to retrieve the intersection point, NULL otherwise
Returns
1 if line and plane intersect, 0 otherwise

◆ gf_bbox_plane_relation()

u32 gf_bbox_plane_relation ( GF_BBox box,
GF_Plane p 
)

Gets the spatial relation between a box and a plane

Parameters
boxthe box to check
pthe plane to check
Returns
the relation type

◆ gf_ray()

GF_Ray gf_ray ( GF_Vec  start,
GF_Vec  end 
)

Constructs a ray object

Parameters
startstarting point of the ray
endend point of the ray, or any point on the ray
Returns
the ray object

◆ gf_mx_apply_ray()

void gf_mx_apply_ray ( GF_Matrix mx,
GF_Ray r 
)

Transforms a ray by a given transformation matrix

Parameters
mxthe matrix to use
rpointer to the ray. Once the function is called, contains the transformed ray

◆ gf_ray_hit_box()

Bool gf_ray_hit_box ( GF_Ray ray,
GF_Vec  min_edge,
GF_Vec  max_edge,
GF_Vec out_point 
)

Checks if a ray intersects a box or not

Parameters
raythe ray to check
min_edgethe minimum edge of the box to check
max_edgethe maximum edge of the box to check
out_pointoptional location of a 3D point to store the intersection, NULL otherwise.
Returns
retuns 1 if the ray intersects the box, 0 otherwise

◆ gf_ray_hit_sphere()

Bool gf_ray_hit_sphere ( GF_Ray ray,
GF_Vec center,
Fixed  radius,
GF_Vec out_point 
)

Checks if a ray intersects a box or not

Parameters
raythe ray to check
centerthe center of the sphere to check. If NULL, the origin (0,0,0)is used
radiusthe radius of the sphere to check
out_pointoptional location of a 3D point to store the intersection, NULL otherwise
Returns
retuns 1 if the ray intersects the sphere, 0 otherwise

◆ gf_ray_hit_triangle()

Bool gf_ray_hit_triangle ( GF_Ray ray,
GF_Vec v0,
GF_Vec v1,
GF_Vec v2,
Fixed dist 
)

Checks if a ray intersects a triangle or not

Parameters
raythe ray to check
v0first vertex of the triangle
v1second vertex of the triangle
v2third vertex of the triangle
distoptional location of a fixed number to store the intersection distance from ray origin if any, NULL otherwise
Returns
retuns 1 if the ray intersects the triangle, 0 otherwise