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
35GRAPHENE_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 */
47struct _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 */
66typedef 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
72GRAPHENE_AVAILABLE_IN_1_4
73graphene_ray_t * graphene_ray_alloc (void);
74GRAPHENE_AVAILABLE_IN_1_4
75void graphene_ray_free (graphene_ray_t *r);
76
77GRAPHENE_AVAILABLE_IN_1_4
78graphene_ray_t * graphene_ray_init (graphene_ray_t *r,
79 const graphene_point3d_t *origin,
80 const graphene_vec3_t *direction);
81GRAPHENE_AVAILABLE_IN_1_4
82graphene_ray_t * graphene_ray_init_from_ray (graphene_ray_t *r,
83 const graphene_ray_t *src);
84GRAPHENE_AVAILABLE_IN_1_4
85graphene_ray_t * graphene_ray_init_from_vec3 (graphene_ray_t *r,
86 const graphene_vec3_t *origin,
87 const graphene_vec3_t *direction);
88GRAPHENE_AVAILABLE_IN_1_4
89void graphene_ray_get_origin (const graphene_ray_t *r,
90 graphene_point3d_t *origin);
91GRAPHENE_AVAILABLE_IN_1_4
92void graphene_ray_get_direction (const graphene_ray_t *r,
93 graphene_vec3_t *direction);
94
95GRAPHENE_AVAILABLE_IN_1_4
96void graphene_ray_get_position_at (const graphene_ray_t *r,
97 float t,
98 graphene_point3d_t *position);
99GRAPHENE_AVAILABLE_IN_1_4
100float graphene_ray_get_distance_to_point (const graphene_ray_t *r,
101 const graphene_point3d_t *p);
102GRAPHENE_AVAILABLE_IN_1_4
103float graphene_ray_get_distance_to_plane (const graphene_ray_t *r,
104 const graphene_plane_t *p);
105
106GRAPHENE_AVAILABLE_IN_1_4
107bool graphene_ray_equal (const graphene_ray_t *a,
108 const graphene_ray_t *b);
109
110GRAPHENE_AVAILABLE_IN_1_4
111void graphene_ray_get_closest_point_to_point (const graphene_ray_t *r,
112 const graphene_point3d_t *p,
113 graphene_point3d_t *res);
114
115GRAPHENE_AVAILABLE_IN_1_10
116graphene_ray_intersection_kind_t graphene_ray_intersect_sphere (const graphene_ray_t *r,
117 const graphene_sphere_t *s,
118 float *t_out);
119GRAPHENE_AVAILABLE_IN_1_10
120bool graphene_ray_intersects_sphere (const graphene_ray_t *r,
121 const graphene_sphere_t *s);
122GRAPHENE_AVAILABLE_IN_1_10
123graphene_ray_intersection_kind_t graphene_ray_intersect_box (const graphene_ray_t *r,
124 const graphene_box_t *b,
125 float *t_out);
126GRAPHENE_AVAILABLE_IN_1_10
127bool graphene_ray_intersects_box (const graphene_ray_t *r,
128 const graphene_box_t *b);
129GRAPHENE_AVAILABLE_IN_1_10
130graphene_ray_intersection_kind_t graphene_ray_intersect_triangle (const graphene_ray_t *r,
131 const graphene_triangle_t *t,
132 float *t_out);
133GRAPHENE_AVAILABLE_IN_1_10
134bool graphene_ray_intersects_triangle (const graphene_ray_t *r,
135 const graphene_triangle_t *t);
136
137GRAPHENE_END_DECLS
138

source code of gtk/subprojects/graphene/include/graphene-ray.h