|
Untitled
|
#include "mathf.h"#include "types.h"#include <limits.h>#include <math.h>#include <stdlib.h>#include "utilities.h"#include <string.h>Go to the source code of this file.
Macros | |
| #define | DEGREES_TO_RAD (3.14159265358979323846 / 180.0) |
Functions | |
| int | vector_alloc (Vector *v, size_t i) |
| int | vector_push (Vector *v, void *o) |
| void * | vector_expand (Vector *v, size_t i) |
| void | init_vector (Vector *v, size_t i, size_t type_size) |
| void | free_vector (Vector *v) |
| mat4 | compose_2d_transform (vec2 transform, float angle, vec2 scale) |
| uint16_t | float32_to_float16 (float f) |
| float | mod289 (float x) |
| vec4 | perm (vec4 x) |
| vec3 | vec3_fract (vec3 x) |
| vec4 | vec4_fract (vec4 x) |
| float | fbm_noise (vec3 p) |
| float | fbm (vec3 p) |
| bool | test_sphere_aabb (vec3 light_pos, float light_radius, vec3 min, vec3 max) |
| void | init_aabb (AABB *a, vec3 center, vec3 extents) |
| bool | aabbs_intersect (AABB *a, AABB *b) |
| void | calculate_aabb_extents (AABB *aabb) |
| void | calculate_aabb_bounds (AABB *aabb) |
| float | triangle_area (vec3 a, vec3 b, vec3 c) |
| bool | is_similar_plane (vec3 n1, vec3 n2, vec3 p1, vec3 p2, float epsilon) |
| bool | ray_intersects_triangle (vec3 origin, vec3 dir, vec3 a, vec3 b, vec3 c, float *out_t, vec3 *out_hit_point, vec3 *barycentric) |
| bool | compute_barycentric (const vec2 uv0, const vec2 uv1, const vec2 uv2, const vec2 p, float *b0, float *b1, float *b2) |
| void | compute_3d_barycentric (vec3 a, vec3 b, vec3 c, vec3 p, float *wA, float *wB, float *wC) |
| vec3 | generate_bounce (uint32_t i, uint32_t N) |
| vec3 | generate_sphere_dir (int i, int N) |
| AABB | transform_aabb_by_position (AABB aabb, vec3 pos) |
| AABB | transform_aabb_by_model_matrix (AABB aabb, mat4 mat) |
| AABB | transform_aabb_by_model_matrix_rotation (AABB aabb, mat4 mat) |
| bool | vec4_equal (vec4 a, vec4 b, float eps) |
| bool | vec3_equal (vec3 a, vec3 b, float eps) |
| bool | triangles_are_contiguous (Triangle *a, Triangle *b) |
| bool | mesh_faces_are_contiguous (MeshFace *a, vec3 *a_verts, MeshFace *b, vec3 *b_verts) |
| int | leftmost_point (vec3 *points, int count) |
| int | leftmost_pointr (vec3 *points, int count) |
| size_t | leftmost_pointi (vec3 *points, size_t *indices, size_t count) |
| size_t | leftmost_pointri (vec3 *points, size_t *indices, size_t count) |
| size_t | leftmost_pointv2 (vec2 *points, size_t count) |
| bool | ccwv2 (vec2 p, vec2 a, vec2 b) |
| bool | ccw (vec3 p, vec3 a, vec3 b) |
| bool | ccwr (vec3 p, vec3 a, vec3 b) |
| void | compute_convex_hull (vec3 *points, int count, vec3 *out_hull, int *out_count, vec3 normal) |
| void | compute_hull_faces (vec3 *points, size_t *indices, size_t count, size_t *out_hull, size_t *out_count, vec3 normal) |
| void | compute_aabb_from_points (vec3 *points, int point_count, AABB *aabb) |
| int | clip_against_plane (const vec3 *in, int in_count, vec3 *out, vec3 plane_point, vec3 plane_normal) |
| int | clip_pts_against_plane (ClipVertex *in, int in_count, ClipVertex *out, vec3 plane_point, vec3 plane_normal) |
| int | clip_tri_against_plane (Vector *points, Vector *faces, vec3 plane, vec3 plane_point, vec3 face_points[3], vec3 j_normal) |
| bool | perform_clip (Vector *points, Vector *faces, vec3 planes[6], vec3 plane_points[6], vec3 face_points[3], vec3 normal) |
| void | clip_triangle (Vector *points, Vector *faces, vec3 planes[6], vec3 plane_points[6], vec3 a, vec3 b, vec3 c, vec3 normal) |
| bool | point_in_triangle (vec3 P, vec3 A, vec3 B, vec3 C) |
| vec3 | project_point_plane (vec3 point, vec3 plane_point, vec3 normal) |
| vec3 | closest_point_segment (vec3 p, vec3 a, vec3 b) |
| float | point_to_segment_dist (vec2 p, vec2 a, vec2 b) |
| vec3 | segment_plane_distance (vec3 proposed, vec3 pts[3], vec3 normal) |
| vec3 | point_triangle_distance (vec3 proposed, vec3 pts[3], vec3 normal) |
| vec3 | closest_point_triangle (vec3 p, vec3 a, vec3 b, vec3 c) |
| vec3 | spherical_to_cartesian (float azimuth_deg, float elevation_deg, float radius) |
| #define DEGREES_TO_RAD (3.14159265358979323846 / 180.0) |
Definition at line 1381 of file utilities.c.
Referenced by spherical_to_cartesian().
| int vector_alloc | ( | Vector * | v, |
| size_t | i ) |
Definition at line 12 of file utilities.c.
References Vector::buffer, Vector::type_size, and vector_alloc().
Referenced by vector_alloc(), vector_expand(), and vector_push().
| int vector_push | ( | Vector * | v, |
| void * | o ) |
Definition at line 25 of file utilities.c.
References Vector::buffer, Vector::capacity, Vector::count, Vector::type_size, vector_alloc(), and vector_push().
Referenced by vector_push().
| void * vector_expand | ( | Vector * | v, |
| size_t | i ) |
Definition at line 49 of file utilities.c.
References Vector::buffer, Vector::capacity, Vector::count, Vector::type_size, vector_alloc(), and vector_expand().
Referenced by a_star_aportal(), add_horizon_face_to_hull_faces(), add_image_to_registry(), add_mesh_to_buffer(), add_text_box(), build_adjacency_map(), build_light_bvh(), build_uv_islands(), check_face_visibility(), check_horizon_edges(), clean_up_hull(), clip_tri_against_plane(), compute_mesh_hulls(), create_menu(), deduplicate(), find_free_in_vector(), find_free_mn(), GPU_unwrap_mesh_to_buffers(), incremental_hull(), init_default_textures(), init_globals(), init_mesh(), init_mesh_tri_bvh(), init_new_audio_portal(), init_new_material(), init_player(), init_scene_bvh(), init_vertex_layouts(), load_filenames(), load_gltf(), perform_clip(), read_json_msdf(), recalculate_audio_portal_paths(), render_audio_menu(), render_light_menu(), render_lprobe_menu(), setup_initial_hull_points(), subdivide_light_bvh(), subdivide_mesh_tri_bvh(), subdivide_scene_bvh(), vector_expand(), and walk_coplanar_adjacency().
| void init_vector | ( | Vector * | v, |
| size_t | i, | ||
| size_t | type_size ) |
Definition at line 74 of file utilities.c.
References Vector::buffer, Vector::capacity, Vector::count, init_vector(), and Vector::type_size.
Referenced by a_star_aportal(), add_all_meshes_to_buffer(), add_all_text_boxes_to_draw_buffer(), build_adjacency_map(), build_light_bvh(), build_uv_islands(), clean_up_hull(), clip_triangle(), compute_mesh_hulls(), deduplicate(), FILE_DIR_REGISTRY_INIT(), FONTS_INIT(), GPU_upload_scene_data(), incremental_hull(), init_globals(), init_lightmap_data(), init_mesh(), init_mesh_tri_bvh(), init_new_audio_portal(), init_player(), init_scene_bvh(), init_vector(), init_vertex_layouts(), load_aportals(), load_gltf(), load_lightmap_from_binary(), load_ui(), MN_INIT(), read_alloc_vector(), read_vector(), recalculate_audio_portal_paths(), scene_load(), setup_initial_hull_points(), SKIN_INIT(), and UI_INIT().
| void free_vector | ( | Vector * | v | ) |
Definition at line 90 of file utilities.c.
References Vector::buffer, and free_vector().
Referenced by free_vector().
Definition at line 97 of file utilities.c.
References mat4::a0, mat4::a1, mat4::a2, mat4::a3, mat4::b0, mat4::b1, mat4::b2, mat4::b3, mat4::c0, mat4::c1, mat4::c2, mat4::c3, compose_2d_transform(), mat4::d0, mat4::d1, mat4::d2, mat4::d3, vec2::x, and vec2::y.
Referenced by compose_2d_transform(), GPU_upload_singular_element(), and GPU_upload_singular_text_box().
| uint16_t float32_to_float16 | ( | float | f | ) |
Definition at line 110 of file utilities.c.
References float32_to_float16().
Referenced by float32_to_float16().
| float mod289 | ( | float | x | ) |
Definition at line 133 of file utilities.c.
References mod289().
Definition at line 138 of file utilities.c.
References mod289(), perm(), vec4_add(), vec4_mul(), vec4_scale(), vec4::w, vec4::x, vec4::y, and vec4::z.
Referenced by apply_mapping_to_point(), fbm_noise(), perm(), and render().
Definition at line 160 of file utilities.c.
References vec3_fract(), vec3::x, vec3::y, and vec3::z.
Referenced by vec3_fract().
Definition at line 175 of file utilities.c.
References vec4_fract(), vec4::w, vec4::x, vec4::y, and vec4::z.
Referenced by fbm_noise(), and vec4_fract().
| float fbm_noise | ( | vec3 | p | ) |
Definition at line 192 of file utilities.c.
References fbm_noise(), perm(), vec2_add(), vec2_scale(), vec3_mul(), vec3_scale(), vec3_sub(), vec4_add(), vec4_fract(), vec4_scale(), vec4::w, vec2::x, vec3::x, vec4::x, vec2::y, vec3::y, vec4::y, vec3::z, and vec4::z.
Referenced by fbm(), and fbm_noise().
| float fbm | ( | vec3 | p | ) |
Definition at line 221 of file utilities.c.
References fbm(), fbm_noise(), vec3_add(), and vec3_scale().
Referenced by compute_hull_centroid(), fbm(), and precompute_fbm_texture().
Definition at line 246 of file utilities.c.
References test_sphere_aabb(), vec3_clamp(), vec3_dot(), and vec3_sub().
Definition at line 258 of file utilities.c.
References AABB::center, AABB::extents, init_aabb(), AABB::max_x, AABB::max_y, AABB::max_z, AABB::min_x, AABB::min_y, AABB::min_z, vec3::x, vec3::y, and vec3::z.
Referenced by init_aabb().
Definition at line 276 of file utilities.c.
References aabbs_intersect(), AABB::max_x, AABB::max_y, AABB::max_z, AABB::min_x, AABB::min_y, and AABB::min_z.
Referenced by aabbs_intersect(), compute_hull_centroid(), PC_traverse_collision_bvh(), PC_traverse_scene_bvh(), and player_find_collision().
| void calculate_aabb_extents | ( | AABB * | aabb | ) |
Definition at line 298 of file utilities.c.
References calculate_aabb_extents(), AABB::center, AABB::extents, AABB::max_x, AABB::max_y, AABB::max_z, AABB::min_x, AABB::min_y, AABB::min_z, vec3::x, vec3::y, and vec3::z.
Referenced by build_light_bvh(), calculate_aabb_extents(), compute_aabb_from_points(), compute_hull_centroid(), load_gltf(), subdivide_light_bvh(), subdivide_mesh_tri_bvh(), and subdivide_scene_bvh().
| void calculate_aabb_bounds | ( | AABB * | aabb | ) |
Definition at line 305 of file utilities.c.
References calculate_aabb_bounds(), AABB::center, AABB::extents, AABB::max_x, AABB::max_y, AABB::max_z, AABB::min_x, AABB::min_y, AABB::min_z, vec3::x, vec3::y, and vec3::z.
Referenced by build_light_bvh(), calculate_aabb_bounds(), compute_hull_centroid(), init_player(), process_sdl_event(), render_aabb_widget(), render_light_menu(), and transform_aabb_by_position().
Definition at line 318 of file utilities.c.
References triangle_area(), vec3::x, vec3::y, and vec3::z.
Referenced by assign_uvs(), build_light_bvh(), build_uv_islands(), compute_mesh_hulls(), triangle_area(), and walk_coplanar_adjacency().
Definition at line 330 of file utilities.c.
References is_similar_plane(), and vec3_dot().
Referenced by compute_mesh_hulls(), and is_similar_plane().
| bool ray_intersects_triangle | ( | vec3 | origin, |
| vec3 | dir, | ||
| vec3 | a, | ||
| vec3 | b, | ||
| vec3 | c, | ||
| float * | out_t, | ||
| vec3 * | out_hit_point, | ||
| vec3 * | barycentric ) |
Definition at line 341 of file utilities.c.
References ray_intersects_triangle(), vec3_add(), vec3_cross(), vec3_dot(), vec3_scale(), vec3_sub(), vec3::x, vec3::y, and vec3::z.
| bool compute_barycentric | ( | const vec2 | uv0, |
| const vec2 | uv1, | ||
| const vec2 | uv2, | ||
| const vec2 | p, | ||
| float * | b0, | ||
| float * | b1, | ||
| float * | b2 ) |
Definition at line 385 of file utilities.c.
References compute_barycentric(), vec2::x, and vec2::y.
Referenced by compute_barycentric(), and compute_hull_centroid().
Definition at line 409 of file utilities.c.
References compute_3d_barycentric(), vec3_cross(), vec3_length(), and vec3_sub().
| vec3 generate_bounce | ( | uint32_t | i, |
| uint32_t | N ) |
Definition at line 429 of file utilities.c.
References generate_bounce(), M_PI, and rand().
Referenced by compute_hull_centroid(), and generate_bounce().
| vec3 generate_sphere_dir | ( | int | i, |
| int | N ) |
Definition at line 449 of file utilities.c.
References generate_sphere_dir(), and M_PI.
Definition at line 466 of file utilities.c.
References calculate_aabb_bounds(), AABB::center, transform_aabb_by_position(), and vec3_add().
Referenced by compute_hull_centroid(), player_find_collision(), and transform_aabb_by_position().
Definition at line 474 of file utilities.c.
References AABB::center, AABB::extents, mat4_mul_direction(), mat4_mul_point(), AABB::max_x, AABB::max_y, AABB::max_z, AABB::min_x, AABB::min_y, AABB::min_z, transform_aabb_by_model_matrix(), vec3::x, vec3::y, and vec3::z.
Definition at line 499 of file utilities.c.
References AABB::center, AABB::extents, mat4_mul_direction(), AABB::max_x, AABB::max_y, AABB::max_z, AABB::min_x, AABB::min_y, AABB::min_z, transform_aabb_by_model_matrix_rotation(), vec3::x, vec3::y, and vec3::z.
Referenced by compute_hull_centroid(), and transform_aabb_by_model_matrix_rotation().
Definition at line 525 of file utilities.c.
References vec4_equal(), vec4::w, vec4::x, vec4::y, and vec4::z.
Referenced by check_equivalencyv4(), compute_hull_centroid(), and vec4_equal().
Definition at line 541 of file utilities.c.
References vec3_equal(), vec3::x, vec3::y, and vec3::z.
Referenced by check_equivalencyv3(), check_horizon_edges(), clean_up_hull(), clip_manifold(), compute_hull_centroid(), compute_mesh_hulls(), deduplicate(), EPA_check_horizon_edges(), GJK(), incremental_hull(), mesh_faces_are_contiguous(), triangles_are_contiguous(), and vec3_equal().
Definition at line 557 of file utilities.c.
References A, B, C, Point::pos, Triangle::pts, triangles_are_contiguous(), and vec3_equal().
Referenced by compute_hull_centroid(), and triangles_are_contiguous().
Definition at line 578 of file utilities.c.
References MeshFace::indices, mesh_faces_are_contiguous(), and vec3_equal().
Referenced by compute_hull_centroid(), compute_mesh_hulls(), and mesh_faces_are_contiguous().
| int leftmost_point | ( | vec3 * | points, |
| int | count ) |
Definition at line 611 of file utilities.c.
References leftmost_point().
Referenced by compute_convex_hull(), and leftmost_point().
| int leftmost_pointr | ( | vec3 * | points, |
| int | count ) |
Definition at line 621 of file utilities.c.
References leftmost_pointr().
Referenced by compute_convex_hull(), and leftmost_pointr().
| size_t leftmost_pointi | ( | vec3 * | points, |
| size_t * | indices, | ||
| size_t | count ) |
Definition at line 631 of file utilities.c.
References leftmost_pointi().
Referenced by leftmost_pointi().
| size_t leftmost_pointri | ( | vec3 * | points, |
| size_t * | indices, | ||
| size_t | count ) |
Definition at line 641 of file utilities.c.
References leftmost_pointri().
Referenced by leftmost_pointri().
| size_t leftmost_pointv2 | ( | vec2 * | points, |
| size_t | count ) |
Definition at line 651 of file utilities.c.
References leftmost_pointv2().
Referenced by compute_hull_faces(), and leftmost_pointv2().
Definition at line 662 of file utilities.c.
References ccwv2(), vec2::x, and vec2::y.
Referenced by ccwv2(), and compute_hull_faces().
Definition at line 667 of file utilities.c.
References ccw(), vec3::x, and vec3::y.
Referenced by ccw(), and compute_convex_hull().
Definition at line 671 of file utilities.c.
References ccwr(), vec3::y, and vec3::z.
Referenced by ccwr(), and compute_convex_hull().
| void compute_convex_hull | ( | vec3 * | points, |
| int | count, | ||
| vec3 * | out_hull, | ||
| int * | out_count, | ||
| vec3 | normal ) |
Definition at line 676 of file utilities.c.
References ccw(), ccwr(), compute_convex_hull(), leftmost_point(), leftmost_pointr(), and vec3::z.
Referenced by compute_convex_hull().
| void compute_hull_faces | ( | vec3 * | points, |
| size_t * | indices, | ||
| size_t | count, | ||
| size_t * | out_hull, | ||
| size_t * | out_count, | ||
| vec3 | normal ) |
Definition at line 718 of file utilities.c.
References B, ccwv2(), compute_hull_faces(), leftmost_pointv2(), vec3_cross(), vec3_dot(), vec3_normalize(), vec2::x, vec2::y, and vec3::z.
Referenced by compute_hull_faces(), and compute_mesh_hulls().
Definition at line 768 of file utilities.c.
References calculate_aabb_extents(), compute_aabb_from_points(), AABB::max_x, AABB::max_y, AABB::max_z, AABB::min_x, AABB::min_y, AABB::min_z, vec3::x, vec3::y, and vec3::z.
Referenced by compute_aabb_from_points(), compute_hull_centroid(), incremental_hull(), and init_mesh_tri_bvh().
| int clip_against_plane | ( | const vec3 * | in, |
| int | in_count, | ||
| vec3 * | out, | ||
| vec3 | plane_point, | ||
| vec3 | plane_normal ) |
Definition at line 794 of file utilities.c.
References A, B, clip_against_plane(), vec3_add(), vec3_dot(), vec3_scale(), and vec3_sub().
Referenced by clip_against_plane(), and perform_clip().
| int clip_pts_against_plane | ( | ClipVertex * | in, |
| int | in_count, | ||
| ClipVertex * | out, | ||
| vec3 | plane_point, | ||
| vec3 | plane_normal ) |
Definition at line 838 of file utilities.c.
References A, B, clip_pts_against_plane(), ClipVertex::edge0, ClipVertex::edge1, ClipVertex::p, vec3_add(), vec3_dot(), vec3_scale(), and vec3_sub().
Referenced by clip_manifold(), and clip_pts_against_plane().
| int clip_tri_against_plane | ( | Vector * | points, |
| Vector * | faces, | ||
| vec3 | plane, | ||
| vec3 | plane_point, | ||
| vec3 | face_points[3], | ||
| vec3 | j_normal ) |
Definition at line 932 of file utilities.c.
References CAST_VEC, clip_tri_against_plane(), Vector::count, MeshFace::indices, MeshFace::normal, vec3_add(), vec3_dot(), vec3_length(), vec3_scale(), vec3_sub(), and vector_expand().
Referenced by clip_tri_against_plane().
| bool perform_clip | ( | Vector * | points, |
| Vector * | faces, | ||
| vec3 | planes[6], | ||
| vec3 | plane_points[6], | ||
| vec3 | face_points[3], | ||
| vec3 | normal ) |
Definition at line 1078 of file utilities.c.
References clip_against_plane(), Vector::count, MeshFace::indices, MeshFace::normal, perform_clip(), planes, vec3_cross(), vec3_length(), vec3_sub(), and vector_expand().
Referenced by clip_triangle(), and perform_clip().
| void clip_triangle | ( | Vector * | points, |
| Vector * | faces, | ||
| vec3 | planes[6], | ||
| vec3 | plane_points[6], | ||
| vec3 | a, | ||
| vec3 | b, | ||
| vec3 | c, | ||
| vec3 | normal ) |
Definition at line 1122 of file utilities.c.
References Vector::buffer, Vector::capacity, CAST_VEC, clip_triangle(), Vector::count, MeshFace::indices, init_vector(), perform_clip(), and planes.
Referenced by clip_triangle().
Definition at line 1204 of file utilities.c.
References A, B, C, point_in_triangle(), vec3_dot(), and vec3_sub().
Referenced by point_in_triangle().
Definition at line 1235 of file utilities.c.
References project_point_plane(), vec3_dot(), vec3_scale(), and vec3_sub().
Referenced by compute_hull_centroid(), epa(), point_triangle_distance(), and project_point_plane().
Definition at line 1244 of file utilities.c.
References clamp(), closest_point_segment(), vec3_add(), vec3_dot(), vec3_scale(), and vec3_sub().
Referenced by clip_manifold(), closest_point_segment(), compute_hull_centroid(), and point_triangle_distance().
Definition at line 1256 of file utilities.c.
References point_to_segment_dist(), vec2::x, and vec2::y.
Referenced by point_to_segment_dist().
Definition at line 1273 of file utilities.c.
References segment_plane_distance(), vec3_add(), vec3_dot(), vec3_scale(), and vec3_sub().
Referenced by segment_plane_distance().
Definition at line 1288 of file utilities.c.
References closest_point_segment(), point_triangle_distance(), project_point_plane(), vec3_length(), and vec3_sub().
Referenced by point_triangle_distance().
Definition at line 1327 of file utilities.c.
References closest_point_triangle(), vec3_add(), vec3_dot(), vec3_scale(), and vec3_sub().
Referenced by clip_manifold(), closest_point_triangle(), collision(), and compute_hull_centroid().
| vec3 spherical_to_cartesian | ( | float | azimuth_deg, |
| float | elevation_deg, | ||
| float | radius ) |
Definition at line 1382 of file utilities.c.
References DEGREES_TO_RAD, and spherical_to_cartesian().
Referenced by spherical_to_cartesian().