1 | /* graphene-ray.h: A ray emitted from an origin in a given direction |
2 | * |
3 | * SPDX-License-Identifier: MIT |
4 | * |
5 | * Copyright 2015 Emmanuele Bassi |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | * of this software and associated documentation files (the "Software"), to deal |
9 | * in the Software without restriction, including without limitation the rights |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11 | * copies of the Software, and to permit persons to whom the Software is |
12 | * furnished to do so, subject to the following conditions: |
13 | * |
14 | * The above copyright notice and this permission notice shall be included in |
15 | * all copies or substantial portions of the Software. |
16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23 | * THE SOFTWARE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if !defined(GRAPHENE_H_INSIDE) && !defined(GRAPHENE_COMPILATION) |
29 | #error "Only graphene.h can be included directly." |
30 | #endif |
31 | |
32 | #include "graphene-types.h" |
33 | #include "graphene-vec3.h" |
34 | |
35 | GRAPHENE_BEGIN_DECLS |
36 | |
37 | /** |
38 | * graphene_ray_t: |
39 | * |
40 | * A ray emitted from an origin in a given direction. |
41 | * |
42 | * The contents of the `graphene_ray_t` structure are private, and should not |
43 | * be modified directly. |
44 | * |
45 | * Since: 1.4 |
46 | */ |
47 | struct _graphene_ray_t |
48 | { |
49 | /*< private >*/ |
50 | GRAPHENE_PRIVATE_FIELD (graphene_vec3_t, origin); |
51 | GRAPHENE_PRIVATE_FIELD (graphene_vec3_t, direction); |
52 | }; |
53 | |
54 | /** |
55 | * graphene_ray_intersection_kind_t: |
56 | * @GRAPHENE_RAY_INTERSECTION_KIND_NONE: No intersection |
57 | * @GRAPHENE_RAY_INTERSECTION_KIND_ENTER: The ray is entering the intersected |
58 | * object |
59 | * @GRAPHENE_RAY_INTERSECTION_KIND_LEAVE: The ray is leaving the intersected |
60 | * object |
61 | * |
62 | * The type of intersection. |
63 | * |
64 | * Since: 1.10 |
65 | */ |
66 | typedef enum { |
67 | GRAPHENE_RAY_INTERSECTION_KIND_NONE, |
68 | GRAPHENE_RAY_INTERSECTION_KIND_ENTER, |
69 | GRAPHENE_RAY_INTERSECTION_KIND_LEAVE, |
70 | } graphene_ray_intersection_kind_t; |
71 | |
72 | GRAPHENE_AVAILABLE_IN_1_4 |
73 | graphene_ray_t * graphene_ray_alloc (void); |
74 | GRAPHENE_AVAILABLE_IN_1_4 |
75 | void graphene_ray_free (graphene_ray_t *r); |
76 | |
77 | GRAPHENE_AVAILABLE_IN_1_4 |
78 | graphene_ray_t * graphene_ray_init (graphene_ray_t *r, |
79 | const graphene_point3d_t *origin, |
80 | const graphene_vec3_t *direction); |
81 | GRAPHENE_AVAILABLE_IN_1_4 |
82 | graphene_ray_t * graphene_ray_init_from_ray (graphene_ray_t *r, |
83 | const graphene_ray_t *src); |
84 | GRAPHENE_AVAILABLE_IN_1_4 |
85 | graphene_ray_t * graphene_ray_init_from_vec3 (graphene_ray_t *r, |
86 | const graphene_vec3_t *origin, |
87 | const graphene_vec3_t *direction); |
88 | GRAPHENE_AVAILABLE_IN_1_4 |
89 | void graphene_ray_get_origin (const graphene_ray_t *r, |
90 | graphene_point3d_t *origin); |
91 | GRAPHENE_AVAILABLE_IN_1_4 |
92 | void graphene_ray_get_direction (const graphene_ray_t *r, |
93 | graphene_vec3_t *direction); |
94 | |
95 | GRAPHENE_AVAILABLE_IN_1_4 |
96 | void graphene_ray_get_position_at (const graphene_ray_t *r, |
97 | float t, |
98 | graphene_point3d_t *position); |
99 | GRAPHENE_AVAILABLE_IN_1_4 |
100 | float graphene_ray_get_distance_to_point (const graphene_ray_t *r, |
101 | const graphene_point3d_t *p); |
102 | GRAPHENE_AVAILABLE_IN_1_4 |
103 | float graphene_ray_get_distance_to_plane (const graphene_ray_t *r, |
104 | const graphene_plane_t *p); |
105 | |
106 | GRAPHENE_AVAILABLE_IN_1_4 |
107 | bool graphene_ray_equal (const graphene_ray_t *a, |
108 | const graphene_ray_t *b); |
109 | |
110 | GRAPHENE_AVAILABLE_IN_1_4 |
111 | void graphene_ray_get_closest_point_to_point (const graphene_ray_t *r, |
112 | const graphene_point3d_t *p, |
113 | graphene_point3d_t *res); |
114 | |
115 | GRAPHENE_AVAILABLE_IN_1_10 |
116 | graphene_ray_intersection_kind_t graphene_ray_intersect_sphere (const graphene_ray_t *r, |
117 | const graphene_sphere_t *s, |
118 | float *t_out); |
119 | GRAPHENE_AVAILABLE_IN_1_10 |
120 | bool graphene_ray_intersects_sphere (const graphene_ray_t *r, |
121 | const graphene_sphere_t *s); |
122 | GRAPHENE_AVAILABLE_IN_1_10 |
123 | graphene_ray_intersection_kind_t graphene_ray_intersect_box (const graphene_ray_t *r, |
124 | const graphene_box_t *b, |
125 | float *t_out); |
126 | GRAPHENE_AVAILABLE_IN_1_10 |
127 | bool graphene_ray_intersects_box (const graphene_ray_t *r, |
128 | const graphene_box_t *b); |
129 | GRAPHENE_AVAILABLE_IN_1_10 |
130 | graphene_ray_intersection_kind_t graphene_ray_intersect_triangle (const graphene_ray_t *r, |
131 | const graphene_triangle_t *t, |
132 | float *t_out); |
133 | GRAPHENE_AVAILABLE_IN_1_10 |
134 | bool graphene_ray_intersects_triangle (const graphene_ray_t *r, |
135 | const graphene_triangle_t *t); |
136 | |
137 | GRAPHENE_END_DECLS |
138 | |