1 | /* graphene-point3d.h: Point in 3D space |
2 | * |
3 | * SPDX-License-Identifier: MIT |
4 | * |
5 | * Copyright 2014 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 | |
34 | GRAPHENE_BEGIN_DECLS |
35 | |
36 | /** |
37 | * GRAPHENE_POINT3D_INIT: |
38 | * @_x: the X coordinate |
39 | * @_y: the Y coordinate |
40 | * @_z: the Z coordinate |
41 | * |
42 | * Initializes a #graphene_point3d_t to the given coordinates when declaring it. |
43 | * |
44 | * Since: 1.0 |
45 | */ |
46 | #define GRAPHENE_POINT3D_INIT(_x,_y,_z) (graphene_point3d_t) { .x = (_x), .y = (_y), .z = (_z) } |
47 | |
48 | /** |
49 | * GRAPHENE_POINT3D_INIT_ZERO: |
50 | * |
51 | * Initializes a #graphene_point3d_t to (0, 0, 0) when declaring it. |
52 | * |
53 | * Since: 1.0 |
54 | */ |
55 | #define GRAPHENE_POINT3D_INIT_ZERO GRAPHENE_POINT3D_INIT (0.f, 0.f, 0.f) |
56 | |
57 | /** |
58 | * graphene_point3d_t: |
59 | * @x: the X coordinate |
60 | * @y: the Y coordinate |
61 | * @z: the Z coordinate |
62 | * |
63 | * A point with three components: X, Y, and Z. |
64 | * |
65 | * Since: 1.0 |
66 | */ |
67 | struct _graphene_point3d_t |
68 | { |
69 | float x; |
70 | float y; |
71 | float z; |
72 | }; |
73 | |
74 | GRAPHENE_AVAILABLE_IN_1_0 |
75 | graphene_point3d_t * graphene_point3d_alloc (void); |
76 | GRAPHENE_AVAILABLE_IN_1_0 |
77 | void graphene_point3d_free (graphene_point3d_t *p); |
78 | |
79 | GRAPHENE_AVAILABLE_IN_1_0 |
80 | graphene_point3d_t * graphene_point3d_init (graphene_point3d_t *p, |
81 | float x, |
82 | float y, |
83 | float z); |
84 | GRAPHENE_AVAILABLE_IN_1_0 |
85 | graphene_point3d_t * graphene_point3d_init_from_point (graphene_point3d_t *p, |
86 | const graphene_point3d_t *src); |
87 | GRAPHENE_AVAILABLE_IN_1_0 |
88 | graphene_point3d_t * graphene_point3d_init_from_vec3 (graphene_point3d_t *p, |
89 | const graphene_vec3_t *v); |
90 | GRAPHENE_AVAILABLE_IN_1_0 |
91 | void graphene_point3d_to_vec3 (const graphene_point3d_t *p, |
92 | graphene_vec3_t *v); |
93 | |
94 | GRAPHENE_AVAILABLE_IN_1_0 |
95 | bool graphene_point3d_equal (const graphene_point3d_t *a, |
96 | const graphene_point3d_t *b); |
97 | GRAPHENE_AVAILABLE_IN_1_0 |
98 | bool graphene_point3d_near (const graphene_point3d_t *a, |
99 | const graphene_point3d_t *b, |
100 | float epsilon); |
101 | |
102 | GRAPHENE_AVAILABLE_IN_1_0 |
103 | void graphene_point3d_scale (const graphene_point3d_t *p, |
104 | float factor, |
105 | graphene_point3d_t *res); |
106 | GRAPHENE_AVAILABLE_IN_1_0 |
107 | void graphene_point3d_cross (const graphene_point3d_t *a, |
108 | const graphene_point3d_t *b, |
109 | graphene_point3d_t *res); |
110 | GRAPHENE_AVAILABLE_IN_1_0 |
111 | float graphene_point3d_dot (const graphene_point3d_t *a, |
112 | const graphene_point3d_t *b); |
113 | GRAPHENE_AVAILABLE_IN_1_0 |
114 | float graphene_point3d_length (const graphene_point3d_t *p); |
115 | GRAPHENE_AVAILABLE_IN_1_0 |
116 | void graphene_point3d_normalize (const graphene_point3d_t *p, |
117 | graphene_point3d_t *res); |
118 | GRAPHENE_AVAILABLE_IN_1_4 |
119 | float graphene_point3d_distance (const graphene_point3d_t *a, |
120 | const graphene_point3d_t *b, |
121 | graphene_vec3_t *delta); |
122 | |
123 | GRAPHENE_AVAILABLE_IN_1_0 |
124 | void graphene_point3d_interpolate (const graphene_point3d_t *a, |
125 | const graphene_point3d_t *b, |
126 | double factor, |
127 | graphene_point3d_t *res); |
128 | |
129 | GRAPHENE_AVAILABLE_IN_1_4 |
130 | void graphene_point3d_normalize_viewport (const graphene_point3d_t *p, |
131 | const graphene_rect_t *viewport, |
132 | float z_near, |
133 | float z_far, |
134 | graphene_point3d_t *res); |
135 | |
136 | GRAPHENE_AVAILABLE_IN_1_0 |
137 | const graphene_point3d_t * graphene_point3d_zero (void); |
138 | |
139 | GRAPHENE_END_DECLS |
140 | |