libgpac
Documentation of the core library of GPAC
Loading...
Searching...
No Matches
math.c File Reference
#include <gpac/maths.h>

Macros

#define DISABLE_MATHS
 
#define SWAP_ROWS(a, b)   { Fixed *_tmp = a; (a)=(b); (b)=_tmp; }
 
#define XPLANE   0
 
#define YPLANE   1
 
#define ZPLANE   2
 

Functions

GF_EXPORT u32 gf_get_bit_size (u32 MaxVal)
 Field bit-size.
 
GF_EXPORT void gf_irect_union (GF_IRect *rc1, GF_IRect *rc2)
 
GF_EXPORT GF_Point2D gf_v2d_from_polar (Fixed length, Fixed angle)
 2D vector from polar coordinates
 
GF_EXPORT Fixed gf_v2d_len (GF_Point2D *vec)
 get 2D vector length
 
GF_EXPORT Fixed gf_v2d_distance (GF_Point2D *a, GF_Point2D *b)
 get distance between 2 points
 
GF_EXPORT Fixed gf_angle_diff (Fixed angle1, Fixed angle2)
 
GF_EXPORT void gf_mx2d_add_matrix (GF_Matrix2D *_this, GF_Matrix2D *from)
 2D matrix multiplication
 
GF_EXPORT void gf_mx2d_pre_multiply (GF_Matrix2D *_this, GF_Matrix2D *with)
 2D matrix pre-multiplication
 
GF_EXPORT void gf_mx2d_add_translation (GF_Matrix2D *_this, Fixed cx, Fixed cy)
 matrix translating
 
GF_EXPORT void gf_mx2d_add_rotation (GF_Matrix2D *_this, Fixed cx, Fixed cy, Fixed angle)
 matrix rotating
 
GF_EXPORT void gf_mx2d_add_scale (GF_Matrix2D *_this, Fixed scale_x, Fixed scale_y)
 matrix scaling
 
GF_EXPORT void gf_mx2d_add_scale_at (GF_Matrix2D *_this, Fixed scale_x, Fixed scale_y, Fixed cx, Fixed cy, Fixed angle)
 matrix uncentered scaling
 
GF_EXPORT void gf_mx2d_add_skew (GF_Matrix2D *_this, Fixed skew_x, Fixed skew_y)
 matrix skewing
 
GF_EXPORT void gf_mx2d_add_skew_x (GF_Matrix2D *_this, Fixed angle)
 matrix horizontal skewing
 
GF_EXPORT void gf_mx2d_add_skew_y (GF_Matrix2D *_this, Fixed angle)
 matrix vertical skewing
 
GF_EXPORT void gf_mx2d_inverse (GF_Matrix2D *_this)
 matrix inversing
 
GF_EXPORT Bool gf_mx2d_decompose (GF_Matrix2D *mx, GF_Point2D *scale, Fixed *rotate, GF_Point2D *translate)
 matrix decomposition
 
GF_EXPORT void gf_mx2d_apply_coords (GF_Matrix2D *_this, Fixed *x, Fixed *y)
 matrix coordinate transformation
 
GF_EXPORT void gf_mx2d_apply_point (GF_Matrix2D *_this, GF_Point2D *pt)
 matrix point transformation
 
GF_EXPORT void gf_mx2d_apply_rect (GF_Matrix2D *_this, GF_Rect *rc)
 matrix rectangle transformation
 
GF_EXPORT GF_IRect gf_rect_pixelize (GF_Rect *r)
 gets the pixelized version of a rectangle
 
GF_EXPORT void gf_rect_union (GF_Rect *rc1, GF_Rect *rc2)
 rectangle union
 
GF_EXPORT GF_Rect gf_rect_center (Fixed w, Fixed h)
 centers a rectangle
 
GF_EXPORT Bool gf_rect_overlaps (GF_Rect rc1, GF_Rect rc2)
 rectangle overlap test
 
GF_EXPORT Bool gf_rect_equal (GF_Rect *rc1, GF_Rect *rc2)
 rectangle identity test
 
GF_EXPORT void gf_rect_intersect (GF_Rect *rc1, GF_Rect *rc2)
 rectangle intersection
 
GF_EXPORT Fixed gf_vec_len_p (GF_Vec *v)
 get 3D vector length
 
GF_EXPORT Fixed gf_vec_len (GF_Vec v)
 get 3D vector length
 
GF_EXPORT Fixed gf_vec_lensq_p (GF_Vec *v)
 get 3D vector square length
 
GF_EXPORT Fixed gf_vec_lensq (GF_Vec v)
 get 3D vector square length
 
GF_EXPORT Fixed gf_vec_dot_p (GF_Vec *v1, GF_Vec *v2)
 get 3D vector dot product
 
GF_EXPORT Fixed gf_vec_dot (GF_Vec v1, GF_Vec v2)
 get 3D vector dot product
 
GF_EXPORT void gf_vec_norm (GF_Vec *v)
 vector normalization
 
GF_EXPORT GF_Vec gf_vec_scale_p (GF_Vec *v, Fixed f)
 vector scaling
 
GF_EXPORT GF_Vec gf_vec_scale (GF_Vec v, Fixed f)
 vector scaling
 
GF_EXPORT GF_Vec gf_vec_cross_p (GF_Vec *v1, GF_Vec *v2)
 vector cross product
 
GF_EXPORT GF_Vec gf_vec_cross (GF_Vec v1, GF_Vec v2)
 vector cross product
 
GF_EXPORT void gf_mx2d_from_mx (GF_Matrix2D *mat2D, GF_Matrix *mat)
 matrix to 2D matrix
 
GF_EXPORT void gf_mx_apply_rect (GF_Matrix *mat, GF_Rect *rc)
 matrix rectangle transformation
 
GF_EXPORT void gf_mx_add_matrix (GF_Matrix *mat, GF_Matrix *mul)
 matrices multiplication
 
GF_EXPORT void gf_mx_add_matrix_2d (GF_Matrix *mat, GF_Matrix2D *mat2D)
 2D matrix multiplication
 
GF_EXPORT void gf_mx_add_translation (GF_Matrix *mat, Fixed tx, Fixed ty, Fixed tz)
 matrix translation
 
GF_EXPORT void gf_mx_add_scale (GF_Matrix *mat, Fixed sx, Fixed sy, Fixed sz)
 matrix scaling
 
GF_EXPORT void gf_mx_add_rotation (GF_Matrix *mat, Fixed angle, Fixed x, Fixed y, Fixed z)
 matrix rotating
 
GF_EXPORT void gf_mx_from_mx2d (GF_Matrix *mat, GF_Matrix2D *mat2D)
 matrix constructor from 2D
 
GF_EXPORT Bool gf_mx_equal (GF_Matrix *mx1, GF_Matrix *mx2)
 matrix equality testing
 
GF_EXPORT void gf_mx_inverse (GF_Matrix *mx)
 affine matrix inversion
 
GF_EXPORT void gf_mx_transpose (GF_Matrix *mx)
 transpose 4x4 matrix
 
GF_EXPORT void gf_mx_apply_vec (GF_Matrix *mx, GF_Vec *pt)
 matrix point transformation
 
GF_EXPORT void gf_mx_ortho (GF_Matrix *mx, Fixed left, Fixed right, Fixed bottom, Fixed top, Fixed z_near, Fixed z_far)
 ortho matrix construction
 
GF_EXPORT 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
 
GF_EXPORT void gf_mx_perspective (GF_Matrix *mx, Fixed fieldOfView, Fixed aspectRatio, Fixed z_near, Fixed z_far)
 perspective matrix construction
 
GF_EXPORT void gf_mx_perspective_reverse_z (GF_Matrix *mx, Fixed fieldOfView, Fixed aspectRatio, Fixed z_near, Fixed z_far)
 perspective matrix with reverse Z construction
 
GF_EXPORT void gf_mx_lookat (GF_Matrix *mx, GF_Vec eye, GF_Vec center, GF_Vec upVector)
 creates look matrix
 
GF_Vec4 gf_quat_from_matrix (GF_Matrix *mx)
 
GF_EXPORT void gf_mx_get_yaw_pitch_roll (GF_Matrix *mx, Fixed *yaw, Fixed *pitch, Fixed *roll)
 matrix yaw pitch roll decomposition
 
GF_EXPORT void gf_mx_decompose (GF_Matrix *mx, GF_Vec *translate, GF_Vec *scale, GF_Vec4 *rotate, GF_Vec *shear)
 matrix decomposition
 
GF_EXPORT void gf_mx_apply_bbox_sphere (GF_Matrix *mx, GF_BBox *box)
 matrix box sphere transformation
 
GF_EXPORT void gf_mx_apply_bbox (GF_Matrix *mx, GF_BBox *box)
 matrix box transformation
 
GF_EXPORT void gf_mx_apply_bbox_4x4 (GF_Matrix *mx, GF_BBox *box)
 matrix box transformation
 
GF_EXPORT void gf_mx_rotate_vector (GF_Matrix *mx, GF_Vec *pt)
 matrix vector rotation
 
GF_EXPORT void gf_mx_rotation_matrix_from_vectors (GF_Matrix *mx, GF_Vec x, GF_Vec y, GF_Vec z)
 matrix initialization from vectors
 
GF_EXPORT void gf_mx_add_matrix_4x4 (GF_Matrix *mat, GF_Matrix *mul)
 non-affine matrix multiplication
 
GF_EXPORT void gf_mx_apply_vec_4x4 (GF_Matrix *mx, GF_Vec4 *vec)
 matrix 4D vector transformation
 
GF_EXPORT Bool gf_mx_inverse_4x4 (GF_Matrix *mx)
 non-affine matrix inversion
 
GF_EXPORT Bool gf_plane_intersect_line (GF_Plane *plane, GF_Vec *linepoint, GF_Vec *linevec, GF_Vec *outPoint)
 plane line intersection
 
GF_EXPORT GF_Ray gf_ray (GF_Vec start, GF_Vec end)
 ray constructor
 
GF_EXPORT void gf_mx_apply_ray (GF_Matrix *mx, GF_Ray *r)
 matrix ray transformation
 
GF_EXPORT Bool gf_ray_hit_box (GF_Ray *ray, GF_Vec box_min, GF_Vec box_max, GF_Vec *outPoint)
 ray box intersection test
 
GF_EXPORT Bool gf_ray_hit_sphere (GF_Ray *ray, GF_Vec *center, Fixed radius, GF_Vec *outPoint)
 ray sphere intersection test
 
GF_EXPORT Bool gf_ray_hit_triangle (GF_Ray *ray, GF_Vec *v0, GF_Vec *v1, GF_Vec *v2, Fixed *dist)
 ray triangle intersection test
 
GF_EXPORT GF_Vec gf_closest_point_to_line (GF_Vec line_pt, GF_Vec line_vec, GF_Vec pt)
 closest point on a line
 
GF_EXPORT GF_Vec4 gf_quat_to_rotation (GF_Vec4 *quat)
 quaternion to rotation
 
GF_EXPORT GF_Vec4 gf_quat_from_rotation (GF_Vec4 rot)
 quaternion from rotation
 
GF_EXPORT GF_Vec4 gf_quat_from_axis_cos (GF_Vec axis, Fixed cos_a)
 quaternion from axis and cos
 
static void gf_quat_conjugate (GF_Vec4 *quat)
 
GF_EXPORT GF_Vec4 gf_quat_get_inv (GF_Vec4 *quat)
 
GF_EXPORT GF_Vec4 gf_quat_multiply (GF_Vec4 *q1, GF_Vec4 *q2)
 quaternion multiplication
 
GF_EXPORT GF_Vec gf_quat_rotate (GF_Vec4 *quat, GF_Vec *vec)
 quaternion vector rotating
 
GF_EXPORT GF_Vec4 gf_quat_slerp (GF_Vec4 q1, GF_Vec4 q2, Fixed frac)
 quaternion interpolation
 
GF_EXPORT void gf_bbox_refresh (GF_BBox *b)
 
GF_EXPORT void gf_bbox_from_rect (GF_BBox *box, GF_Rect *rc)
 
GF_EXPORT void gf_rect_from_bbox (GF_Rect *rc, GF_BBox *box)
 
GF_EXPORT void gf_bbox_grow_point (GF_BBox *box, GF_Vec pt)
 bounding box expansion
 
GF_EXPORT void gf_bbox_union (GF_BBox *b1, GF_BBox *b2)
 
GF_EXPORT Bool gf_bbox_equal (GF_BBox *b1, GF_BBox *b2)
 
GF_EXPORT Bool gf_bbox_point_inside (GF_BBox *box, GF_Vec *p)
 
GF_EXPORT void gf_bbox_get_vertices (GF_Vec bmin, GF_Vec bmax, GF_Vec *vecs)
 get box vertices
 
GF_EXPORT void gf_mx_apply_plane (GF_Matrix *mx, GF_Plane *plane)
 matrix plane transformation
 
GF_EXPORT Fixed gf_plane_get_distance (GF_Plane *plane, GF_Vec *p)
 point to plane distance
 
GF_EXPORT u32 gf_plane_get_p_vertex_idx (GF_Plane *p)
 box p-vertex index
 
GF_EXPORT u32 gf_bbox_plane_relation (GF_BBox *box, GF_Plane *p)
 box-plane relation
 
GF_EXPORT u32 gf_get_next_pow2 (u32 s)
 Get power of 2.
 

Macro Definition Documentation

◆ DISABLE_MATHS

#define DISABLE_MATHS

◆ SWAP_ROWS

#define SWAP_ROWS (   a,
 
)    { Fixed *_tmp = a; (a)=(b); (b)=_tmp; }

◆ XPLANE

#define XPLANE   0

◆ YPLANE

#define YPLANE   1

◆ ZPLANE

#define ZPLANE   2

Function Documentation

◆ gf_quat_from_matrix()

GF_EXPORT GF_Vec4 gf_quat_from_matrix ( GF_Matrix mx)

◆ gf_quat_conjugate()

static void gf_quat_conjugate ( GF_Vec4 quat)
static