1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module graphene.Ray;
26 
27 private import glib.ConstructionException;
28 private import glib.MemorySlice;
29 private import gobject.ObjectG;
30 private import graphene.Box;
31 private import graphene.Plane;
32 private import graphene.Point3D;
33 private import graphene.Sphere;
34 private import graphene.Triangle;
35 private import graphene.Vec3;
36 private import graphene.c.functions;
37 public  import graphene.c.types;
38 private import gtkd.Loader;
39 
40 
41 /**
42  * A ray emitted from an origin in a given direction.
43  * 
44  * The contents of the `graphene_ray_t` structure are private, and should not
45  * be modified directly.
46  *
47  * Since: 1.4
48  */
49 public class Ray
50 {
51 	/** the main Gtk struct */
52 	protected graphene_ray_t* graphene_ray;
53 	protected bool ownedRef;
54 
55 	/** Get the main Gtk struct */
56 	public graphene_ray_t* getRayStruct(bool transferOwnership = false)
57 	{
58 		if (transferOwnership)
59 			ownedRef = false;
60 		return graphene_ray;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected void* getStruct()
65 	{
66 		return cast(void*)graphene_ray;
67 	}
68 
69 	/**
70 	 * Sets our main struct and passes it to the parent class.
71 	 */
72 	public this (graphene_ray_t* graphene_ray, bool ownedRef = false)
73 	{
74 		this.graphene_ray = graphene_ray;
75 		this.ownedRef = ownedRef;
76 	}
77 
78 	~this ()
79 	{
80 		if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef )
81 			graphene_ray_free(graphene_ray);
82 	}
83 
84 
85 	/** */
86 	public static GType getType()
87 	{
88 		return graphene_ray_get_type();
89 	}
90 
91 	/**
92 	 * Allocates a new #graphene_ray_t structure.
93 	 *
94 	 * The contents of the returned structure are undefined.
95 	 *
96 	 * Returns: the newly allocated #graphene_ray_t.
97 	 *     Use graphene_ray_free() to free the resources allocated by
98 	 *     this function
99 	 *
100 	 * Since: 1.4
101 	 *
102 	 * Throws: ConstructionException GTK+ fails to create the object.
103 	 */
104 	public this()
105 	{
106 		auto __p = graphene_ray_alloc();
107 
108 		if(__p is null)
109 		{
110 			throw new ConstructionException("null returned by alloc");
111 		}
112 
113 		this(cast(graphene_ray_t*) __p);
114 	}
115 
116 	/**
117 	 * Checks whether the two given #graphene_ray_t are equal.
118 	 *
119 	 * Params:
120 	 *     b = a #graphene_ray_t
121 	 *
122 	 * Returns: `true` if the given rays are equal
123 	 *
124 	 * Since: 1.4
125 	 */
126 	public bool equal(Ray b)
127 	{
128 		return graphene_ray_equal(graphene_ray, (b is null) ? null : b.getRayStruct()) != 0;
129 	}
130 
131 	/**
132 	 * Frees the resources allocated by graphene_ray_alloc().
133 	 *
134 	 * Since: 1.4
135 	 */
136 	public void free()
137 	{
138 		graphene_ray_free(graphene_ray);
139 		ownedRef = false;
140 	}
141 
142 	/**
143 	 * Computes the point on the given #graphene_ray_t that is closest to the
144 	 * given point @p.
145 	 *
146 	 * Params:
147 	 *     p = a #graphene_point3d_t
148 	 *     res = return location for the closest point3d
149 	 *
150 	 * Since: 1.4
151 	 */
152 	public void getClosestPointToPoint(Point3D p, out Point3D res)
153 	{
154 		graphene_point3d_t* outres = sliceNew!graphene_point3d_t();
155 
156 		graphene_ray_get_closest_point_to_point(graphene_ray, (p is null) ? null : p.getPoint3DStruct(), outres);
157 
158 		res = ObjectG.getDObject!(Point3D)(outres, true);
159 	}
160 
161 	/**
162 	 * Retrieves the direction of the given #graphene_ray_t.
163 	 *
164 	 * Params:
165 	 *     direction = return location for the direction
166 	 *
167 	 * Since: 1.4
168 	 */
169 	public void getDirection(out Vec3 direction)
170 	{
171 		graphene_vec3_t* outdirection = sliceNew!graphene_vec3_t();
172 
173 		graphene_ray_get_direction(graphene_ray, outdirection);
174 
175 		direction = ObjectG.getDObject!(Vec3)(outdirection, true);
176 	}
177 
178 	/**
179 	 * Computes the distance of the origin of the given #graphene_ray_t from the
180 	 * given plane.
181 	 *
182 	 * If the ray does not intersect the plane, this function returns `INFINITY`.
183 	 *
184 	 * Params:
185 	 *     p = a #graphene_plane_t
186 	 *
187 	 * Returns: the distance of the origin of the ray from the plane
188 	 *
189 	 * Since: 1.4
190 	 */
191 	public float getDistanceToPlane(Plane p)
192 	{
193 		return graphene_ray_get_distance_to_plane(graphene_ray, (p is null) ? null : p.getPlaneStruct());
194 	}
195 
196 	/**
197 	 * Computes the distance of the closest approach between the
198 	 * given #graphene_ray_t @r and the point @p.
199 	 *
200 	 * The closest approach to a ray from a point is the distance
201 	 * between the point and the projection of the point on the
202 	 * ray itself.
203 	 *
204 	 * Params:
205 	 *     p = a #graphene_point3d_t
206 	 *
207 	 * Returns: the distance of the point
208 	 *
209 	 * Since: 1.4
210 	 */
211 	public float getDistanceToPoint(Point3D p)
212 	{
213 		return graphene_ray_get_distance_to_point(graphene_ray, (p is null) ? null : p.getPoint3DStruct());
214 	}
215 
216 	/**
217 	 * Retrieves the origin of the given #graphene_ray_t.
218 	 *
219 	 * Params:
220 	 *     origin = return location for the origin
221 	 *
222 	 * Since: 1.4
223 	 */
224 	public void getOrigin(out Point3D origin)
225 	{
226 		graphene_point3d_t* outorigin = sliceNew!graphene_point3d_t();
227 
228 		graphene_ray_get_origin(graphene_ray, outorigin);
229 
230 		origin = ObjectG.getDObject!(Point3D)(outorigin, true);
231 	}
232 
233 	/**
234 	 * Retrieves the coordinates of a point at the distance @t along the
235 	 * given #graphene_ray_t.
236 	 *
237 	 * Params:
238 	 *     t = the distance along the ray
239 	 *     position = return location for the position
240 	 *
241 	 * Since: 1.4
242 	 */
243 	public void getPositionAt(float t, out Point3D position)
244 	{
245 		graphene_point3d_t* outposition = sliceNew!graphene_point3d_t();
246 
247 		graphene_ray_get_position_at(graphene_ray, t, outposition);
248 
249 		position = ObjectG.getDObject!(Point3D)(outposition, true);
250 	}
251 
252 	/**
253 	 * Initializes the given #graphene_ray_t using the given @origin
254 	 * and @direction values.
255 	 *
256 	 * Params:
257 	 *     origin = the origin of the ray
258 	 *     direction = the direction vector
259 	 *
260 	 * Returns: the initialized ray
261 	 *
262 	 * Since: 1.4
263 	 */
264 	public Ray init(Point3D origin, Vec3 direction)
265 	{
266 		auto __p = graphene_ray_init(graphene_ray, (origin is null) ? null : origin.getPoint3DStruct(), (direction is null) ? null : direction.getVec3Struct());
267 
268 		if(__p is null)
269 		{
270 			return null;
271 		}
272 
273 		return ObjectG.getDObject!(Ray)(cast(graphene_ray_t*) __p);
274 	}
275 
276 	/**
277 	 * Initializes the given #graphene_ray_t using the origin and direction
278 	 * values of another #graphene_ray_t.
279 	 *
280 	 * Params:
281 	 *     src = a #graphene_ray_t
282 	 *
283 	 * Returns: the initialized ray
284 	 *
285 	 * Since: 1.4
286 	 */
287 	public Ray initFromRay(Ray src)
288 	{
289 		auto __p = graphene_ray_init_from_ray(graphene_ray, (src is null) ? null : src.getRayStruct());
290 
291 		if(__p is null)
292 		{
293 			return null;
294 		}
295 
296 		return ObjectG.getDObject!(Ray)(cast(graphene_ray_t*) __p);
297 	}
298 
299 	/**
300 	 * Initializes the given #graphene_ray_t using the given vectors.
301 	 *
302 	 * Params:
303 	 *     origin = a #graphene_vec3_t
304 	 *     direction = a #graphene_vec3_t
305 	 *
306 	 * Returns: the initialized ray
307 	 *
308 	 * Since: 1.4
309 	 */
310 	public Ray initFromVec3(Vec3 origin, Vec3 direction)
311 	{
312 		auto __p = graphene_ray_init_from_vec3(graphene_ray, (origin is null) ? null : origin.getVec3Struct(), (direction is null) ? null : direction.getVec3Struct());
313 
314 		if(__p is null)
315 		{
316 			return null;
317 		}
318 
319 		return ObjectG.getDObject!(Ray)(cast(graphene_ray_t*) __p);
320 	}
321 
322 	/**
323 	 * Intersects the given #graphene_ray_t @r with the given
324 	 * #graphene_box_t @b.
325 	 *
326 	 * Params:
327 	 *     b = a #graphene_box_t
328 	 *     tOut = the distance of the point on the ray that intersects the box
329 	 *
330 	 * Returns: the type of intersection
331 	 *
332 	 * Since: 1.10
333 	 */
334 	public graphene_ray_intersection_kind_t intersectBox(Box b, out float tOut)
335 	{
336 		return graphene_ray_intersect_box(graphene_ray, (b is null) ? null : b.getBoxStruct(), &tOut);
337 	}
338 
339 	/**
340 	 * Intersects the given #graphene_ray_t @r with the given
341 	 * #graphene_sphere_t @s.
342 	 *
343 	 * Params:
344 	 *     s = a #graphene_sphere_t
345 	 *     tOut = the distance of the point on the ray that intersects the sphere
346 	 *
347 	 * Returns: the type of intersection
348 	 *
349 	 * Since: 1.10
350 	 */
351 	public graphene_ray_intersection_kind_t intersectSphere(Sphere s, out float tOut)
352 	{
353 		return graphene_ray_intersect_sphere(graphene_ray, (s is null) ? null : s.getSphereStruct(), &tOut);
354 	}
355 
356 	/**
357 	 * Intersects the given #graphene_ray_t @r with the given
358 	 * #graphene_triangle_t @t.
359 	 *
360 	 * Params:
361 	 *     t = a #graphene_triangle_t
362 	 *     tOut = the distance of the point on the ray that intersects the triangle
363 	 *
364 	 * Returns: the type of intersection
365 	 *
366 	 * Since: 1.10
367 	 */
368 	public graphene_ray_intersection_kind_t intersectTriangle(Triangle t, out float tOut)
369 	{
370 		return graphene_ray_intersect_triangle(graphene_ray, (t is null) ? null : t.getTriangleStruct(), &tOut);
371 	}
372 
373 	/**
374 	 * Checks whether the given #graphene_ray_t @r intersects the
375 	 * given #graphene_box_t @b.
376 	 *
377 	 * See also: graphene_ray_intersect_box()
378 	 *
379 	 * Params:
380 	 *     b = a #graphene_box_t
381 	 *
382 	 * Returns: `true` if the ray intersects the box
383 	 *
384 	 * Since: 1.10
385 	 */
386 	public bool intersectsBox(Box b)
387 	{
388 		return graphene_ray_intersects_box(graphene_ray, (b is null) ? null : b.getBoxStruct()) != 0;
389 	}
390 
391 	/**
392 	 * Checks if the given #graphene_ray_t @r intersects the
393 	 * given #graphene_sphere_t @s.
394 	 *
395 	 * See also: graphene_ray_intersect_sphere()
396 	 *
397 	 * Params:
398 	 *     s = a #graphene_sphere_t
399 	 *
400 	 * Returns: `true` if the ray intersects the sphere
401 	 *
402 	 * Since: 1.10
403 	 */
404 	public bool intersectsSphere(Sphere s)
405 	{
406 		return graphene_ray_intersects_sphere(graphene_ray, (s is null) ? null : s.getSphereStruct()) != 0;
407 	}
408 
409 	/**
410 	 * Checks whether the given #graphene_ray_t @r intersects the
411 	 * given #graphene_triangle_t @b.
412 	 *
413 	 * See also: graphene_ray_intersect_triangle()
414 	 *
415 	 * Params:
416 	 *     t = a #graphene_triangle_t
417 	 *
418 	 * Returns: `true` if the ray intersects the triangle
419 	 *
420 	 * Since: 1.10
421 	 */
422 	public bool intersectsTriangle(Triangle t)
423 	{
424 		return graphene_ray_intersects_triangle(graphene_ray, (t is null) ? null : t.getTriangleStruct()) != 0;
425 	}
426 }