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.Vec3;
26 
27 private import glib.ConstructionException;
28 private import glib.MemorySlice;
29 private import gobject.ObjectG;
30 private import graphene.Vec2;
31 private import graphene.Vec4;
32 private import graphene.c.functions;
33 public  import graphene.c.types;
34 private import gtkd.Loader;
35 
36 
37 /**
38  * A structure capable of holding a vector with three dimensions: x, y, and z.
39  * 
40  * The contents of the #graphene_vec3_t structure are private and should
41  * never be accessed directly.
42  */
43 public class Vec3
44 {
45 	/** the main Gtk struct */
46 	protected graphene_vec3_t* graphene_vec3;
47 	protected bool ownedRef;
48 
49 	/** Get the main Gtk struct */
50 	public graphene_vec3_t* getVec3Struct(bool transferOwnership = false)
51 	{
52 		if (transferOwnership)
53 			ownedRef = false;
54 		return graphene_vec3;
55 	}
56 
57 	/** the main Gtk struct as a void* */
58 	protected void* getStruct()
59 	{
60 		return cast(void*)graphene_vec3;
61 	}
62 
63 	/**
64 	 * Sets our main struct and passes it to the parent class.
65 	 */
66 	public this (graphene_vec3_t* graphene_vec3, bool ownedRef = false)
67 	{
68 		this.graphene_vec3 = graphene_vec3;
69 		this.ownedRef = ownedRef;
70 	}
71 
72 	~this ()
73 	{
74 		if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef )
75 			graphene_vec3_free(graphene_vec3);
76 	}
77 
78 
79 	/** */
80 	public static GType getType()
81 	{
82 		return graphene_vec3_get_type();
83 	}
84 
85 	/**
86 	 * Allocates a new #graphene_vec3_t structure.
87 	 *
88 	 * The contents of the returned structure are undefined.
89 	 *
90 	 * Use graphene_vec3_init() to initialize the vector.
91 	 *
92 	 * Returns: the newly allocated #graphene_vec3_t
93 	 *     structure. Use graphene_vec3_free() to free the resources allocated
94 	 *     by this function.
95 	 *
96 	 * Since: 1.0
97 	 *
98 	 * Throws: ConstructionException GTK+ fails to create the object.
99 	 */
100 	public this()
101 	{
102 		auto __p = graphene_vec3_alloc();
103 
104 		if(__p is null)
105 		{
106 			throw new ConstructionException("null returned by alloc");
107 		}
108 
109 		this(cast(graphene_vec3_t*) __p);
110 	}
111 
112 	/**
113 	 * Adds each component of the two given vectors.
114 	 *
115 	 * Params:
116 	 *     b = a #graphene_vec3_t
117 	 *     res = return location for the resulting vector
118 	 *
119 	 * Since: 1.0
120 	 */
121 	public void add(Vec3 b, out Vec3 res)
122 	{
123 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
124 
125 		graphene_vec3_add(graphene_vec3, (b is null) ? null : b.getVec3Struct(), outres);
126 
127 		res = ObjectG.getDObject!(Vec3)(outres, true);
128 	}
129 
130 	/**
131 	 * Computes the cross product of the two given vectors.
132 	 *
133 	 * Params:
134 	 *     b = a #graphene_vec3_t
135 	 *     res = return location for the resulting vector
136 	 *
137 	 * Since: 1.0
138 	 */
139 	public void cross(Vec3 b, out Vec3 res)
140 	{
141 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
142 
143 		graphene_vec3_cross(graphene_vec3, (b is null) ? null : b.getVec3Struct(), outres);
144 
145 		res = ObjectG.getDObject!(Vec3)(outres, true);
146 	}
147 
148 	/**
149 	 * Divides each component of the first operand @a by the corresponding
150 	 * component of the second operand @b, and places the results into the
151 	 * vector @res.
152 	 *
153 	 * Params:
154 	 *     b = a #graphene_vec3_t
155 	 *     res = return location for the resulting vector
156 	 *
157 	 * Since: 1.0
158 	 */
159 	public void divide(Vec3 b, out Vec3 res)
160 	{
161 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
162 
163 		graphene_vec3_divide(graphene_vec3, (b is null) ? null : b.getVec3Struct(), outres);
164 
165 		res = ObjectG.getDObject!(Vec3)(outres, true);
166 	}
167 
168 	/**
169 	 * Computes the dot product of the two given vectors.
170 	 *
171 	 * Params:
172 	 *     b = a #graphene_vec3_t
173 	 *
174 	 * Returns: the value of the dot product
175 	 *
176 	 * Since: 1.0
177 	 */
178 	public float dot(Vec3 b)
179 	{
180 		return graphene_vec3_dot(graphene_vec3, (b is null) ? null : b.getVec3Struct());
181 	}
182 
183 	/**
184 	 * Checks whether the two given #graphene_vec3_t are equal.
185 	 *
186 	 * Params:
187 	 *     v2 = a #graphene_vec3_t
188 	 *
189 	 * Returns: `true` if the two vectors are equal, and false otherwise
190 	 *
191 	 * Since: 1.2
192 	 */
193 	public bool equal(Vec3 v2)
194 	{
195 		return graphene_vec3_equal(graphene_vec3, (v2 is null) ? null : v2.getVec3Struct()) != 0;
196 	}
197 
198 	/**
199 	 * Frees the resources allocated by @v
200 	 *
201 	 * Since: 1.0
202 	 */
203 	public void free()
204 	{
205 		graphene_vec3_free(graphene_vec3);
206 		ownedRef = false;
207 	}
208 
209 	/**
210 	 * Retrieves the first component of the given vector @v.
211 	 *
212 	 * Returns: the value of the first component of the vector
213 	 *
214 	 * Since: 1.0
215 	 */
216 	public float getX()
217 	{
218 		return graphene_vec3_get_x(graphene_vec3);
219 	}
220 
221 	/**
222 	 * Creates a #graphene_vec2_t that contains the first and second
223 	 * components of the given #graphene_vec3_t.
224 	 *
225 	 * Params:
226 	 *     res = return location for a #graphene_vec2_t
227 	 *
228 	 * Since: 1.0
229 	 */
230 	public void getXy(out Vec2 res)
231 	{
232 		graphene_vec2_t* outres = sliceNew!graphene_vec2_t();
233 
234 		graphene_vec3_get_xy(graphene_vec3, outres);
235 
236 		res = ObjectG.getDObject!(Vec2)(outres, true);
237 	}
238 
239 	/**
240 	 * Creates a #graphene_vec3_t that contains the first two components of
241 	 * the given #graphene_vec3_t, and the third component set to 0.
242 	 *
243 	 * Params:
244 	 *     res = return location for a #graphene_vec3_t
245 	 *
246 	 * Since: 1.0
247 	 */
248 	public void getXy0(out Vec3 res)
249 	{
250 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
251 
252 		graphene_vec3_get_xy0(graphene_vec3, outres);
253 
254 		res = ObjectG.getDObject!(Vec3)(outres, true);
255 	}
256 
257 	/**
258 	 * Converts a #graphene_vec3_t in a #graphene_vec4_t using 0.0
259 	 * as the value for the fourth component of the resulting vector.
260 	 *
261 	 * Params:
262 	 *     res = return location for the vector
263 	 *
264 	 * Since: 1.0
265 	 */
266 	public void getXyz0(out Vec4 res)
267 	{
268 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
269 
270 		graphene_vec3_get_xyz0(graphene_vec3, outres);
271 
272 		res = ObjectG.getDObject!(Vec4)(outres, true);
273 	}
274 
275 	/**
276 	 * Converts a #graphene_vec3_t in a #graphene_vec4_t using 1.0
277 	 * as the value for the fourth component of the resulting vector.
278 	 *
279 	 * Params:
280 	 *     res = return location for the vector
281 	 *
282 	 * Since: 1.0
283 	 */
284 	public void getXyz1(out Vec4 res)
285 	{
286 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
287 
288 		graphene_vec3_get_xyz1(graphene_vec3, outres);
289 
290 		res = ObjectG.getDObject!(Vec4)(outres, true);
291 	}
292 
293 	/**
294 	 * Converts a #graphene_vec3_t in a #graphene_vec4_t using @w as
295 	 * the value of the fourth component of the resulting vector.
296 	 *
297 	 * Params:
298 	 *     w = the value of the W component
299 	 *     res = return location for the vector
300 	 *
301 	 * Since: 1.0
302 	 */
303 	public void getXyzw(float w, out Vec4 res)
304 	{
305 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
306 
307 		graphene_vec3_get_xyzw(graphene_vec3, w, outres);
308 
309 		res = ObjectG.getDObject!(Vec4)(outres, true);
310 	}
311 
312 	/**
313 	 * Retrieves the second component of the given vector @v.
314 	 *
315 	 * Returns: the value of the second component of the vector
316 	 *
317 	 * Since: 1.0
318 	 */
319 	public float getY()
320 	{
321 		return graphene_vec3_get_y(graphene_vec3);
322 	}
323 
324 	/**
325 	 * Retrieves the third component of the given vector @v.
326 	 *
327 	 * Returns: the value of the third component of the vector
328 	 *
329 	 * Since: 1.0
330 	 */
331 	public float getZ()
332 	{
333 		return graphene_vec3_get_z(graphene_vec3);
334 	}
335 
336 	/**
337 	 * Initializes a #graphene_vec3_t using the given values.
338 	 *
339 	 * This function can be called multiple times.
340 	 *
341 	 * Params:
342 	 *     x = the X field of the vector
343 	 *     y = the Y field of the vector
344 	 *     z = the Z field of the vector
345 	 *
346 	 * Returns: a pointer to the initialized
347 	 *     vector
348 	 *
349 	 * Since: 1.0
350 	 */
351 	public Vec3 init(float x, float y, float z)
352 	{
353 		auto __p = graphene_vec3_init(graphene_vec3, x, y, z);
354 
355 		if(__p is null)
356 		{
357 			return null;
358 		}
359 
360 		return ObjectG.getDObject!(Vec3)(cast(graphene_vec3_t*) __p);
361 	}
362 
363 	/**
364 	 * Initializes a #graphene_vec3_t with the values from an array.
365 	 *
366 	 * Params:
367 	 *     src = an array of 3 floating point values
368 	 *
369 	 * Returns: the initialized vector
370 	 *
371 	 * Since: 1.0
372 	 */
373 	public Vec3 initFromFloat(float[3] src)
374 	{
375 		auto __p = graphene_vec3_init_from_float(graphene_vec3, src.ptr);
376 
377 		if(__p is null)
378 		{
379 			return null;
380 		}
381 
382 		return ObjectG.getDObject!(Vec3)(cast(graphene_vec3_t*) __p);
383 	}
384 
385 	/**
386 	 * Initializes a #graphene_vec3_t with the values of another
387 	 * #graphene_vec3_t.
388 	 *
389 	 * Params:
390 	 *     src = a #graphene_vec3_t
391 	 *
392 	 * Returns: the initialized vector
393 	 *
394 	 * Since: 1.0
395 	 */
396 	public Vec3 initFromVec3(Vec3 src)
397 	{
398 		auto __p = graphene_vec3_init_from_vec3(graphene_vec3, (src is null) ? null : src.getVec3Struct());
399 
400 		if(__p is null)
401 		{
402 			return null;
403 		}
404 
405 		return ObjectG.getDObject!(Vec3)(cast(graphene_vec3_t*) __p);
406 	}
407 
408 	/**
409 	 * Linearly interpolates @v1 and @v2 using the given @factor.
410 	 *
411 	 * Params:
412 	 *     v2 = a #graphene_vec3_t
413 	 *     factor = the interpolation factor
414 	 *     res = the interpolated vector
415 	 *
416 	 * Since: 1.10
417 	 */
418 	public void interpolate(Vec3 v2, double factor, out Vec3 res)
419 	{
420 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
421 
422 		graphene_vec3_interpolate(graphene_vec3, (v2 is null) ? null : v2.getVec3Struct(), factor, outres);
423 
424 		res = ObjectG.getDObject!(Vec3)(outres, true);
425 	}
426 
427 	/**
428 	 * Retrieves the length of the given vector @v.
429 	 *
430 	 * Returns: the value of the length of the vector
431 	 *
432 	 * Since: 1.0
433 	 */
434 	public float length()
435 	{
436 		return graphene_vec3_length(graphene_vec3);
437 	}
438 
439 	/**
440 	 * Compares each component of the two given vectors and creates a
441 	 * vector that contains the maximum values.
442 	 *
443 	 * Params:
444 	 *     b = a #graphene_vec3_t
445 	 *     res = return location for the result vector
446 	 *
447 	 * Since: 1.0
448 	 */
449 	public void max(Vec3 b, out Vec3 res)
450 	{
451 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
452 
453 		graphene_vec3_max(graphene_vec3, (b is null) ? null : b.getVec3Struct(), outres);
454 
455 		res = ObjectG.getDObject!(Vec3)(outres, true);
456 	}
457 
458 	/**
459 	 * Compares each component of the two given vectors and creates a
460 	 * vector that contains the minimum values.
461 	 *
462 	 * Params:
463 	 *     b = a #graphene_vec3_t
464 	 *     res = return location for the result vector
465 	 *
466 	 * Since: 1.0
467 	 */
468 	public void min(Vec3 b, out Vec3 res)
469 	{
470 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
471 
472 		graphene_vec3_min(graphene_vec3, (b is null) ? null : b.getVec3Struct(), outres);
473 
474 		res = ObjectG.getDObject!(Vec3)(outres, true);
475 	}
476 
477 	/**
478 	 * Multiplies each component of the two given vectors.
479 	 *
480 	 * Params:
481 	 *     b = a #graphene_vec3_t
482 	 *     res = return location for the resulting vector
483 	 *
484 	 * Since: 1.0
485 	 */
486 	public void multiply(Vec3 b, out Vec3 res)
487 	{
488 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
489 
490 		graphene_vec3_multiply(graphene_vec3, (b is null) ? null : b.getVec3Struct(), outres);
491 
492 		res = ObjectG.getDObject!(Vec3)(outres, true);
493 	}
494 
495 	/**
496 	 * Compares the two given #graphene_vec3_t vectors and checks
497 	 * whether their values are within the given @epsilon.
498 	 *
499 	 * Params:
500 	 *     v2 = a #graphene_vec3_t
501 	 *     epsilon = the threshold between the two vectors
502 	 *
503 	 * Returns: `true` if the two vectors are near each other
504 	 *
505 	 * Since: 1.2
506 	 */
507 	public bool near(Vec3 v2, float epsilon)
508 	{
509 		return graphene_vec3_near(graphene_vec3, (v2 is null) ? null : v2.getVec3Struct(), epsilon) != 0;
510 	}
511 
512 	/**
513 	 * Negates the given #graphene_vec3_t.
514 	 *
515 	 * Params:
516 	 *     res = return location for the result vector
517 	 *
518 	 * Since: 1.2
519 	 */
520 	public void negate(out Vec3 res)
521 	{
522 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
523 
524 		graphene_vec3_negate(graphene_vec3, outres);
525 
526 		res = ObjectG.getDObject!(Vec3)(outres, true);
527 	}
528 
529 	/**
530 	 * Normalizes the given #graphene_vec3_t.
531 	 *
532 	 * Params:
533 	 *     res = return location for the normalized vector
534 	 *
535 	 * Since: 1.0
536 	 */
537 	public void normalize(out Vec3 res)
538 	{
539 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
540 
541 		graphene_vec3_normalize(graphene_vec3, outres);
542 
543 		res = ObjectG.getDObject!(Vec3)(outres, true);
544 	}
545 
546 	/**
547 	 * Multiplies all components of the given vector with the given scalar @factor.
548 	 *
549 	 * Params:
550 	 *     factor = the scalar factor
551 	 *     res = return location for the result vector
552 	 *
553 	 * Since: 1.2
554 	 */
555 	public void scale(float factor, out Vec3 res)
556 	{
557 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
558 
559 		graphene_vec3_scale(graphene_vec3, factor, outres);
560 
561 		res = ObjectG.getDObject!(Vec3)(outres, true);
562 	}
563 
564 	/**
565 	 * Subtracts from each component of the first operand @a the
566 	 * corresponding component of the second operand @b and places
567 	 * each result into the components of @res.
568 	 *
569 	 * Params:
570 	 *     b = a #graphene_vec3_t
571 	 *     res = return location for the resulting vector
572 	 *
573 	 * Since: 1.0
574 	 */
575 	public void subtract(Vec3 b, out Vec3 res)
576 	{
577 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
578 
579 		graphene_vec3_subtract(graphene_vec3, (b is null) ? null : b.getVec3Struct(), outres);
580 
581 		res = ObjectG.getDObject!(Vec3)(outres, true);
582 	}
583 
584 	/**
585 	 * Copies the components of a #graphene_vec3_t into the given array.
586 	 *
587 	 * Params:
588 	 *     dest = return location for
589 	 *         an array of floating point values
590 	 *
591 	 * Since: 1.0
592 	 */
593 	public void toFloat(out float[3] dest)
594 	{
595 		float[3] outdest;
596 
597 		graphene_vec3_to_float(graphene_vec3, outdest.ptr);
598 
599 		dest = outdest[0 .. 3];
600 	}
601 
602 	/**
603 	 * Provides a constant pointer to a vector with three components,
604 	 * all sets to 1.
605 	 *
606 	 * Returns: a constant vector
607 	 *
608 	 * Since: 1.0
609 	 */
610 	public static Vec3 one()
611 	{
612 		auto __p = graphene_vec3_one();
613 
614 		if(__p is null)
615 		{
616 			return null;
617 		}
618 
619 		return ObjectG.getDObject!(Vec3)(cast(graphene_vec3_t*) __p);
620 	}
621 
622 	/**
623 	 * Provides a constant pointer to a vector with three components
624 	 * with values set to (1, 0, 0).
625 	 *
626 	 * Returns: a constant vector
627 	 *
628 	 * Since: 1.0
629 	 */
630 	public static Vec3 xAxis()
631 	{
632 		auto __p = graphene_vec3_x_axis();
633 
634 		if(__p is null)
635 		{
636 			return null;
637 		}
638 
639 		return ObjectG.getDObject!(Vec3)(cast(graphene_vec3_t*) __p);
640 	}
641 
642 	/**
643 	 * Provides a constant pointer to a vector with three components
644 	 * with values set to (0, 1, 0).
645 	 *
646 	 * Returns: a constant vector
647 	 *
648 	 * Since: 1.0
649 	 */
650 	public static Vec3 yAxis()
651 	{
652 		auto __p = graphene_vec3_y_axis();
653 
654 		if(__p is null)
655 		{
656 			return null;
657 		}
658 
659 		return ObjectG.getDObject!(Vec3)(cast(graphene_vec3_t*) __p);
660 	}
661 
662 	/**
663 	 * Provides a constant pointer to a vector with three components
664 	 * with values set to (0, 0, 1).
665 	 *
666 	 * Returns: a constant vector
667 	 *
668 	 * Since: 1.0
669 	 */
670 	public static Vec3 zAxis()
671 	{
672 		auto __p = graphene_vec3_z_axis();
673 
674 		if(__p is null)
675 		{
676 			return null;
677 		}
678 
679 		return ObjectG.getDObject!(Vec3)(cast(graphene_vec3_t*) __p);
680 	}
681 
682 	/**
683 	 * Provides a constant pointer to a vector with three components,
684 	 * all sets to 0.
685 	 *
686 	 * Returns: a constant vector
687 	 *
688 	 * Since: 1.0
689 	 */
690 	public static Vec3 zero()
691 	{
692 		auto __p = graphene_vec3_zero();
693 
694 		if(__p is null)
695 		{
696 			return null;
697 		}
698 
699 		return ObjectG.getDObject!(Vec3)(cast(graphene_vec3_t*) __p);
700 	}
701 }