📄 math.h
字号:
void gf_rect_from_bbox(GF_Rect *rc, GF_BBox *box);/*!\brief bounding box expansion * *Checks if a point is inside a bounding box and updates the bounding box to include it if not the case *\param box the bounding box object *\param pt the 3D point to check*/void gf_bbox_grow_point(GF_BBox *box, GF_Vec pt);/*!performs the union of two bounding boxes*/void gf_bbox_union(GF_BBox *b1, GF_BBox *b2);/*!checks if two bounding boxes are equal or not*/Bool gf_bbox_equal(GF_BBox *b1, GF_BBox *b2);/*!checks if a point is inside a bounding box or not*/Bool gf_bbox_point_inside(GF_BBox *box, GF_Vec *p);/*!\brief get box vertices * *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 *\param bmin minimum edge of the box *\param bmax maximum edge of the box *\param vecs list of 8 3D points used to store the vertices.*/void gf_bbox_get_vertices(GF_Vec bmin, GF_Vec bmax, GF_Vec *vecs);/*!\brief matrix initialization *\hideinitializer * *Inits the matrix to the identity matrix*/#define gf_mx_init(_obj) { memset((_obj).m, 0, sizeof(Fixed)*16); (_obj).m[0] = (_obj).m[5] = (_obj).m[10] = (_obj).m[15] = FIX_ONE; }/*!\brief matrix copy *\hideinitializer * *Copies the matrix _from to the matrix _obj*/#define gf_mx_copy(_obj, from) memcpy(&(_obj), &(from), sizeof(GF_Matrix));/*!\brief matrix constructor from 2D * *Initializes a 3D matrix from a 2D matrix.\note all z-related coefficients will be set to default.*/void gf_mx_from_mx2d(GF_Matrix *mx, GF_Matrix2D *mat2D);/*!\brief matrix identity testing * *Tests if two matrices are equal or not. \return 1 if matrices are same, 0 otherwise*/Bool gf_mx_equal(GF_Matrix *mx1, GF_Matrix *mx2);/*!\brief matrix translation * *Translates a matrix *\param mx the matrix being transformed. Once the function is called, contains the result matrix *\param tx horizontal translation *\param ty vertical translation *\param tz depth translation*/void gf_mx_add_translation(GF_Matrix *mx, Fixed tx, Fixed ty, Fixed tz);/*!\brief matrix scaling * *Scales a matrix *\param mx the matrix being transformed. Once the function is called, contains the result matrix *\param sx horizontal translation scaling *\param sy vertical translation scaling *\param sz depth translation scaling*/void gf_mx_add_scale(GF_Matrix *mx, Fixed sx, Fixed sy, Fixed sz);/*!\brief matrix rotating * *Rotates a matrix *\param mx the matrix being transformed. Once the function is called, contains the result matrix *\param angle rotation angle in radians *\param x horizontal coordinate of rotation axis *\param y vertical coordinate of rotation axis *\param z depth coordinate of rotation axis*/void gf_mx_add_rotation(GF_Matrix *mx, Fixed angle, Fixed x, Fixed y, Fixed z);/*!\brief matrices multiplication * *Multiplies a matrix with another one mx = mx*mul *\param mx the matrix being transformed. Once the function is called, contains the result matrix *\param mul the matrix to add*/void gf_mx_add_matrix(GF_Matrix *mx, GF_Matrix *mul);/*!\brief affine matrix inversion * *Inverses an affine matrix.\warning Results are undefined if the matrix is not an affine one *\param mx the matrix to inverse */void gf_mx_inverse(GF_Matrix *mx);/*!\brief matrix point transformation * *Applies a 3D matrix transformation to a 3D point *\param mx transformation matrix *\param pt pointer to 3D point. Once the function is called, pt contains the transformed point*/void gf_mx_apply_vec(GF_Matrix *mx, GF_Vec *pt);/*!\brief matrix rectangle transformation * *Applies a 3D matrix transformation to a rectangle, giving the enclosing rectangle of the transformed one.\note all depth information are discarded. *\param _this transformation matrix *\param rc pointer to rectangle. Once the function is called, rc contains the transformed rectangle*/void gf_mx_apply_rect(GF_Matrix *_this, GF_Rect *rc);/*!\brief ortho matrix construction * *Creates an orthogonal projection matrix *\param mx matrix to initialize *\param left min horizontal coordinate of viewport *\param right max horizontal coordinate of viewport *\param bottom min vertical coordinate of viewport *\param top max vertical coordinate of viewport *\param z_near min depth coordinate of viewport *\param z_far max depth coordinate of viewport*/void gf_mx_ortho(GF_Matrix *mx, Fixed left, Fixed right, Fixed bottom, Fixed top, Fixed z_near, Fixed z_far);/*!\brief perspective matrix construction * *Creates a perspective projection matrix *\param mx matrix to initialize *\param foc camera field of view angle in radian *\param aspect_ratio viewport aspect ratio *\param z_near min depth coordinate of viewport *\param z_far max depth coordinate of viewport*/void gf_mx_perspective(GF_Matrix *mx, Fixed foc, Fixed aspect_ratio, Fixed z_near, Fixed z_far);/*!\brief creates look matrix * *Creates a transformation matrix looking at a given direction from a given point (camera matrix). *\param mx matrix to initialize *\param position position *\param target look direction *\param up_vector vector describing the up direction*/void gf_mx_lookat(GF_Matrix *mx, GF_Vec position, GF_Vec target, GF_Vec up_vector);/*!\brief matrix box transformation * *Applies a 3D matrix transformation to a bounding box, giving the enclosing box of the transformed one *\param mx transformation matrix *\param b pointer to bounding box. Once the function is called, contains the transformed bounding box*/void gf_mx_apply_bbox(GF_Matrix *mx, GF_BBox *b);/*!\brief non-affine matrix multiplication * *Multiplies two non-affine matrices mx = mx*mul*/void gf_mx_add_matrix_4x4(GF_Matrix *mat, GF_Matrix *mul);/*!\brief non-affine matrix inversion * *Inverses a non-affine matrices *\return 1 if inversion was done, 0 if inversion not possible.*/Bool gf_mx_inverse_4x4(GF_Matrix *mx);/*!\brief matrix 4D vector transformation * *Applies a 3D non-affine matrix transformation to a 4 dimension vector *\param mx transformation matrix *\param vec pointer to the vector. Once the function is called, contains the transformed vector*/void gf_mx_apply_vec_4x4(GF_Matrix *mx, GF_Vec4 *vec);/*!\brief matrix decomposition * *Decomposes a matrix into translation, scale, shear and rotate *\param mx the matrix to decompose *\param translate the decomposed translation part *\param scale the decomposed scaling part *\param rotate the decomposed rotation part, expressed as a Rotataion (axis + angle) *\param shear the decomposed shear part */void gf_mx_decompose(GF_Matrix *mx, GF_Vec *translate, GF_Vec *scale, GF_Vec4 *rotate, GF_Vec *shear);/*!\brief matrix vector rotation * *Rotates a vector with a given matrix, ignoring any translation. *\param mx transformation matrix *\param pt pointer to 3D vector. Once the function is called, pt contains the transformed vector */void gf_mx_rotate_vector(GF_Matrix *mx, GF_Vec *pt);/*!\brief matrix initialization from vectors * *Inits a matrix to rotate the local axis in the given vectors \param mx matrix to initialize \param x_axis target normalized X axis \param y_axis target normalized Y axis \param z_axis target normalized Z axis*/void gf_mx_rotation_matrix_from_vectors(GF_Matrix *mx, GF_Vec x_axis, GF_Vec y_axis, GF_Vec z_axis);/*!\brief matrix to 2D matrix * *Inits a 2D matrix by removing all depth info from a 3D matrix *\param mx2d 2D matrix to initialize *\param mx 3D matrix to use*/void gf_mx2d_from_mx(GF_Matrix2D *mx2d, GF_Matrix *mx);/*!\brief Plane object*/typedef struct{ /*!normal vector to the plane*/ GF_Vec normal; /*!distance from origin of the plane*/ Fixed d;} GF_Plane;/*!\brief matrix plane transformation * *Transorms a plane by a given matrix *\param mx the matrix to use *\param plane pointer to 3D plane. Once the function is called, plane contains the transformed plane */void gf_mx_apply_plane(GF_Matrix *mx, GF_Plane *plane);/*!\brief point to plane distance * *Gets the distance between a point and a plne *\param plane the plane to use *\param p pointer to ^point to check *\return the distance between the place and the point */Fixed gf_plane_get_distance(GF_Plane *plane, GF_Vec *p);/*!\brief closest point on a line * *Gets the closest point on a line from a given point in space *\param line_pt a point of the line to test *\param line_vec the normalized direction vector of the line *\param pt the point to check *\return the closest point on the line to the desired point */GF_Vec gf_closest_point_to_line(GF_Vec line_pt, GF_Vec line_vec, GF_Vec pt);/*!\brief box p-vertex index * *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 \ref gf_bbox_get_vertices *\param p the plane to check *\return the p-vertex index value, ranging from 0 to 7*/u32 gf_plane_get_p_vertex_idx(GF_Plane *p);/*!\brief plane line intersection * *Checks for the intersection of a plane and a line *\param plane plane to test *\param linepoint a point on the line to test *\param linevec normalized direction vector of the line to test *\param outPoint optional pointer to retrieve the intersection point, NULL otherwise *\return 1 if line and plane intersect, 0 otherwise*/Bool gf_plane_intersect_line(GF_Plane *plane, GF_Vec *linepoint, GF_Vec *linevec, GF_Vec *outPoint);/*!Classification types for box/plane position used in \ref gf_bbox_plane_relation*/enum { /*!box is in front of the plane*/ GF_BBOX_FRONT, /*!box intersects the plane*/ GF_BBOX_INTER, /*!box is back of the plane*/ GF_BBOX_BACK};/*!\brief box-plane relation * *Gets the spatial relation between a box and a plane *\param box the box to check *\param p the plane to check *\return the relation type */u32 gf_bbox_plane_relation(GF_BBox *box, GF_Plane *p);/*!\brief 3D Ray * *The 3D ray object is used in GPAC for all collision and mouse interaction tests*/typedef struct{ /*!origin point of the ray*/ GF_Vec orig; /*!normalized direction vector of the ray*/ GF_Vec dir;} GF_Ray;/*!\brief ray constructor * *Constructs a ray object *\param start starting point of the ray *\param end end point of the ray, or any point on the ray *\return the ray object*/GF_Ray gf_ray(GF_Vec start, GF_Vec end);/*!\brief matrix ray transformation * *Transforms a ray by a given transformation matrix *\param mx the matrix to use *\param r pointer to the ray. Once the function is called, contains the transformed ray*/void gf_mx_apply_ray(GF_Matrix *mx, GF_Ray *r);/*!\brief ray box intersection test * *Checks if a ray intersects a box or not *\param ray the ray to check *\param min_edge the minimum edge of the box to check *\param max_edge the maximum edge of the box to check *\param out_point optional location of a 3D point to store the intersection, NULL otherwise. *\return retuns 1 if the ray intersects the box, 0 otherwise*/Bool gf_ray_hit_box(GF_Ray *ray, GF_Vec min_edge, GF_Vec max_edge, GF_Vec *out_point);/*!\brief ray sphere intersection test * *Checks if a ray intersects a box or not *\param ray the ray to check *\param center the center of the sphere to check. If NULL, the origin (0,0,0)is used *\param radius the radius of the sphere to check *\param out_point optional location of a 3D point to store the intersection, NULL otherwise *\return retuns 1 if the ray intersects the sphere, 0 otherwise*/Bool gf_ray_hit_sphere(GF_Ray *ray, GF_Vec *center, Fixed radius, GF_Vec *out_point);/*!\brief ray triangle intersection test * *Checks if a ray intersects a triangle or not *\param ray the ray to check *\param v0 first vertex of the triangle *\param v1 second vertex of the triangle *\param v2 third vertex of the triangle *\param dist optional location of a fixed number to store the intersection distance from ray origin if any, NULL otherwise *\return retuns 1 if the ray intersects the triangle, 0 otherwise*/Bool gf_ray_hit_triangle(GF_Ray *ray, GF_Vec *v0, GF_Vec *v1, GF_Vec *v2, Fixed *dist);/*same as above and performs backface cull (solid meshes)*//*!\brief ray triangle intersection test * *Checks if a ray intersects a triangle or not, performing backface culling. For parameters details, look at \ref gf_ray_hit_triangle_backcull */Bool gf_ray_hit_triangle_backcull(GF_Ray *ray, GF_Vec *v0, GF_Vec *v1, GF_Vec *v2, Fixed *dist);/*! @} *//*! @} */#ifdef __cplusplus}#endif#endif /*_GF_MATH_H_*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -