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.Quaternion;
26 
27 private import glib.ConstructionException;
28 private import glib.MemorySlice;
29 private import gobject.ObjectG;
30 private import graphene.Euler;
31 private import graphene.Matrix;
32 private import graphene.Vec3;
33 private import graphene.Vec4;
34 private import graphene.c.functions;
35 public  import graphene.c.types;
36 private import gtkd.Loader;
37 
38 
39 /**
40  * A quaternion.
41  * 
42  * The contents of the #graphene_quaternion_t structure are private
43  * and should never be accessed directly.
44  *
45  * Since: 1.0
46  */
47 public class Quaternion
48 {
49 	/** the main Gtk struct */
50 	protected graphene_quaternion_t* graphene_quaternion;
51 	protected bool ownedRef;
52 
53 	/** Get the main Gtk struct */
54 	public graphene_quaternion_t* getQuaternionStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return graphene_quaternion;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected void* getStruct()
63 	{
64 		return cast(void*)graphene_quaternion;
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (graphene_quaternion_t* graphene_quaternion, bool ownedRef = false)
71 	{
72 		this.graphene_quaternion = graphene_quaternion;
73 		this.ownedRef = ownedRef;
74 	}
75 
76 	~this ()
77 	{
78 		if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef )
79 			graphene_quaternion_free(graphene_quaternion);
80 	}
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return graphene_quaternion_get_type();
87 	}
88 
89 	/**
90 	 * Allocates a new #graphene_quaternion_t.
91 	 *
92 	 * The contents of the returned value are undefined.
93 	 *
94 	 * Returns: the newly allocated #graphene_quaternion_t
95 	 *
96 	 * Since: 1.0
97 	 *
98 	 * Throws: ConstructionException GTK+ fails to create the object.
99 	 */
100 	public this()
101 	{
102 		auto __p = graphene_quaternion_alloc();
103 
104 		if(__p is null)
105 		{
106 			throw new ConstructionException("null returned by alloc");
107 		}
108 
109 		this(cast(graphene_quaternion_t*) __p);
110 	}
111 
112 	/**
113 	 * Adds two #graphene_quaternion_t @a and @b.
114 	 *
115 	 * Params:
116 	 *     b = a #graphene_quaternion_t
117 	 *     res = the result of the operation
118 	 *
119 	 * Since: 1.10
120 	 */
121 	public void add(Quaternion b, out Quaternion res)
122 	{
123 		graphene_quaternion_t* outres = sliceNew!graphene_quaternion_t();
124 
125 		graphene_quaternion_add(graphene_quaternion, (b is null) ? null : b.getQuaternionStruct(), outres);
126 
127 		res = ObjectG.getDObject!(Quaternion)(outres, true);
128 	}
129 
130 	/**
131 	 * Computes the dot product of two #graphene_quaternion_t.
132 	 *
133 	 * Params:
134 	 *     b = a #graphene_quaternion_t
135 	 *
136 	 * Returns: the value of the dot products
137 	 *
138 	 * Since: 1.0
139 	 */
140 	public float dot(Quaternion b)
141 	{
142 		return graphene_quaternion_dot(graphene_quaternion, (b is null) ? null : b.getQuaternionStruct());
143 	}
144 
145 	/**
146 	 * Checks whether the given quaternions are equal.
147 	 *
148 	 * Params:
149 	 *     b = a #graphene_quaternion_t
150 	 *
151 	 * Returns: `true` if the quaternions are equal
152 	 *
153 	 * Since: 1.0
154 	 */
155 	public bool equal(Quaternion b)
156 	{
157 		return graphene_quaternion_equal(graphene_quaternion, (b is null) ? null : b.getQuaternionStruct()) != 0;
158 	}
159 
160 	/**
161 	 * Releases the resources allocated by graphene_quaternion_alloc().
162 	 *
163 	 * Since: 1.0
164 	 */
165 	public void free()
166 	{
167 		graphene_quaternion_free(graphene_quaternion);
168 		ownedRef = false;
169 	}
170 
171 	/**
172 	 * Initializes a #graphene_quaternion_t using the given four values.
173 	 *
174 	 * Params:
175 	 *     x = the first component of the quaternion
176 	 *     y = the second component of the quaternion
177 	 *     z = the third component of the quaternion
178 	 *     w = the fourth component of the quaternion
179 	 *
180 	 * Returns: the initialized quaternion
181 	 *
182 	 * Since: 1.0
183 	 */
184 	public Quaternion init(float x, float y, float z, float w)
185 	{
186 		auto __p = graphene_quaternion_init(graphene_quaternion, x, y, z, w);
187 
188 		if(__p is null)
189 		{
190 			return null;
191 		}
192 
193 		return ObjectG.getDObject!(Quaternion)(cast(graphene_quaternion_t*) __p);
194 	}
195 
196 	/**
197 	 * Initializes a #graphene_quaternion_t using an @angle on a
198 	 * specific @axis.
199 	 *
200 	 * Params:
201 	 *     angle = the rotation on a given axis, in degrees
202 	 *     axis = the axis of rotation, expressed as a vector
203 	 *
204 	 * Returns: the initialized quaternion
205 	 *
206 	 * Since: 1.0
207 	 */
208 	public Quaternion initFromAngleVec3(float angle, Vec3 axis)
209 	{
210 		auto __p = graphene_quaternion_init_from_angle_vec3(graphene_quaternion, angle, (axis is null) ? null : axis.getVec3Struct());
211 
212 		if(__p is null)
213 		{
214 			return null;
215 		}
216 
217 		return ObjectG.getDObject!(Quaternion)(cast(graphene_quaternion_t*) __p);
218 	}
219 
220 	/**
221 	 * Initializes a #graphene_quaternion_t using the values of
222 	 * the [Euler angles](http://en.wikipedia.org/wiki/Euler_angles)
223 	 * on each axis.
224 	 *
225 	 * See also: graphene_quaternion_init_from_euler()
226 	 *
227 	 * Params:
228 	 *     degX = rotation angle on the X axis (yaw), in degrees
229 	 *     degY = rotation angle on the Y axis (pitch), in degrees
230 	 *     degZ = rotation angle on the Z axis (roll), in degrees
231 	 *
232 	 * Returns: the initialized quaternion
233 	 *
234 	 * Since: 1.0
235 	 */
236 	public Quaternion initFromAngles(float degX, float degY, float degZ)
237 	{
238 		auto __p = graphene_quaternion_init_from_angles(graphene_quaternion, degX, degY, degZ);
239 
240 		if(__p is null)
241 		{
242 			return null;
243 		}
244 
245 		return ObjectG.getDObject!(Quaternion)(cast(graphene_quaternion_t*) __p);
246 	}
247 
248 	/**
249 	 * Initializes a #graphene_quaternion_t using the given #graphene_euler_t.
250 	 *
251 	 * Params:
252 	 *     e = a #graphene_euler_t
253 	 *
254 	 * Returns: the initialized #graphene_quaternion_t
255 	 *
256 	 * Since: 1.2
257 	 */
258 	public Quaternion initFromEuler(Euler e)
259 	{
260 		auto __p = graphene_quaternion_init_from_euler(graphene_quaternion, (e is null) ? null : e.getEulerStruct());
261 
262 		if(__p is null)
263 		{
264 			return null;
265 		}
266 
267 		return ObjectG.getDObject!(Quaternion)(cast(graphene_quaternion_t*) __p);
268 	}
269 
270 	/**
271 	 * Initializes a #graphene_quaternion_t using the rotation components
272 	 * of a transformation matrix.
273 	 *
274 	 * Params:
275 	 *     m = a #graphene_matrix_t
276 	 *
277 	 * Returns: the initialized quaternion
278 	 *
279 	 * Since: 1.0
280 	 */
281 	public Quaternion initFromMatrix(Matrix m)
282 	{
283 		auto __p = graphene_quaternion_init_from_matrix(graphene_quaternion, (m is null) ? null : m.getMatrixStruct());
284 
285 		if(__p is null)
286 		{
287 			return null;
288 		}
289 
290 		return ObjectG.getDObject!(Quaternion)(cast(graphene_quaternion_t*) __p);
291 	}
292 
293 	/**
294 	 * Initializes a #graphene_quaternion_t with the values from @src.
295 	 *
296 	 * Params:
297 	 *     src = a #graphene_quaternion_t
298 	 *
299 	 * Returns: the initialized quaternion
300 	 *
301 	 * Since: 1.0
302 	 */
303 	public Quaternion initFromQuaternion(Quaternion src)
304 	{
305 		auto __p = graphene_quaternion_init_from_quaternion(graphene_quaternion, (src is null) ? null : src.getQuaternionStruct());
306 
307 		if(__p is null)
308 		{
309 			return null;
310 		}
311 
312 		return ObjectG.getDObject!(Quaternion)(cast(graphene_quaternion_t*) __p);
313 	}
314 
315 	/**
316 	 * Initializes a #graphene_quaternion_t using the values of
317 	 * the [Euler angles](http://en.wikipedia.org/wiki/Euler_angles)
318 	 * on each axis.
319 	 *
320 	 * See also: graphene_quaternion_init_from_euler()
321 	 *
322 	 * Params:
323 	 *     radX = rotation angle on the X axis (yaw), in radians
324 	 *     radY = rotation angle on the Y axis (pitch), in radians
325 	 *     radZ = rotation angle on the Z axis (roll), in radians
326 	 *
327 	 * Returns: the initialized quaternion
328 	 *
329 	 * Since: 1.0
330 	 */
331 	public Quaternion initFromRadians(float radX, float radY, float radZ)
332 	{
333 		auto __p = graphene_quaternion_init_from_radians(graphene_quaternion, radX, radY, radZ);
334 
335 		if(__p is null)
336 		{
337 			return null;
338 		}
339 
340 		return ObjectG.getDObject!(Quaternion)(cast(graphene_quaternion_t*) __p);
341 	}
342 
343 	/**
344 	 * Initializes a #graphene_quaternion_t with the values from @src.
345 	 *
346 	 * Params:
347 	 *     src = a #graphene_vec4_t
348 	 *
349 	 * Returns: the initialized quaternion
350 	 *
351 	 * Since: 1.0
352 	 */
353 	public Quaternion initFromVec4(Vec4 src)
354 	{
355 		auto __p = graphene_quaternion_init_from_vec4(graphene_quaternion, (src is null) ? null : src.getVec4Struct());
356 
357 		if(__p is null)
358 		{
359 			return null;
360 		}
361 
362 		return ObjectG.getDObject!(Quaternion)(cast(graphene_quaternion_t*) __p);
363 	}
364 
365 	/**
366 	 * Initializes a #graphene_quaternion_t using the identity
367 	 * transformation.
368 	 *
369 	 * Returns: the initialized quaternion
370 	 *
371 	 * Since: 1.0
372 	 */
373 	public Quaternion initIdentity()
374 	{
375 		auto __p = graphene_quaternion_init_identity(graphene_quaternion);
376 
377 		if(__p is null)
378 		{
379 			return null;
380 		}
381 
382 		return ObjectG.getDObject!(Quaternion)(cast(graphene_quaternion_t*) __p);
383 	}
384 
385 	/**
386 	 * Inverts a #graphene_quaternion_t, and returns the conjugate
387 	 * quaternion of @q.
388 	 *
389 	 * Params:
390 	 *     res = return location for the inverted
391 	 *         quaternion
392 	 *
393 	 * Since: 1.0
394 	 */
395 	public void invert(out Quaternion res)
396 	{
397 		graphene_quaternion_t* outres = sliceNew!graphene_quaternion_t();
398 
399 		graphene_quaternion_invert(graphene_quaternion, outres);
400 
401 		res = ObjectG.getDObject!(Quaternion)(outres, true);
402 	}
403 
404 	/**
405 	 * Multiplies two #graphene_quaternion_t @a and @b.
406 	 *
407 	 * Params:
408 	 *     b = a #graphene_quaternion_t
409 	 *     res = the result of the operation
410 	 *
411 	 * Since: 1.10
412 	 */
413 	public void multiply(Quaternion b, out Quaternion res)
414 	{
415 		graphene_quaternion_t* outres = sliceNew!graphene_quaternion_t();
416 
417 		graphene_quaternion_multiply(graphene_quaternion, (b is null) ? null : b.getQuaternionStruct(), outres);
418 
419 		res = ObjectG.getDObject!(Quaternion)(outres, true);
420 	}
421 
422 	/**
423 	 * Normalizes a #graphene_quaternion_t.
424 	 *
425 	 * Params:
426 	 *     res = return location for the normalized
427 	 *         quaternion
428 	 *
429 	 * Since: 1.0
430 	 */
431 	public void normalize(out Quaternion res)
432 	{
433 		graphene_quaternion_t* outres = sliceNew!graphene_quaternion_t();
434 
435 		graphene_quaternion_normalize(graphene_quaternion, outres);
436 
437 		res = ObjectG.getDObject!(Quaternion)(outres, true);
438 	}
439 
440 	/**
441 	 * Scales all the elements of a #graphene_quaternion_t @q using
442 	 * the given scalar factor.
443 	 *
444 	 * Params:
445 	 *     factor = a scaling factor
446 	 *     res = the result of the operation
447 	 *
448 	 * Since: 1.10
449 	 */
450 	public void scale(float factor, out Quaternion res)
451 	{
452 		graphene_quaternion_t* outres = sliceNew!graphene_quaternion_t();
453 
454 		graphene_quaternion_scale(graphene_quaternion, factor, outres);
455 
456 		res = ObjectG.getDObject!(Quaternion)(outres, true);
457 	}
458 
459 	/**
460 	 * Interpolates between the two given quaternions using a spherical
461 	 * linear interpolation, or [SLERP](http://en.wikipedia.org/wiki/Slerp),
462 	 * using the given interpolation @factor.
463 	 *
464 	 * Params:
465 	 *     b = a #graphene_quaternion_t
466 	 *     factor = the linear interpolation factor
467 	 *     res = return location for the interpolated
468 	 *         quaternion
469 	 *
470 	 * Since: 1.0
471 	 */
472 	public void slerp(Quaternion b, float factor, out Quaternion res)
473 	{
474 		graphene_quaternion_t* outres = sliceNew!graphene_quaternion_t();
475 
476 		graphene_quaternion_slerp(graphene_quaternion, (b is null) ? null : b.getQuaternionStruct(), factor, outres);
477 
478 		res = ObjectG.getDObject!(Quaternion)(outres, true);
479 	}
480 
481 	/**
482 	 * Converts a quaternion into an @angle, @axis pair.
483 	 *
484 	 * Params:
485 	 *     angle = return location for the angle, in degrees
486 	 *     axis = return location for the rotation axis
487 	 *
488 	 * Since: 1.0
489 	 */
490 	public void toAngleVec3(out float angle, out Vec3 axis)
491 	{
492 		graphene_vec3_t* outaxis = sliceNew!graphene_vec3_t();
493 
494 		graphene_quaternion_to_angle_vec3(graphene_quaternion, &angle, outaxis);
495 
496 		axis = ObjectG.getDObject!(Vec3)(outaxis, true);
497 	}
498 
499 	/**
500 	 * Converts a #graphene_quaternion_t to its corresponding rotations
501 	 * on the [Euler angles](http://en.wikipedia.org/wiki/Euler_angles)
502 	 * on each axis.
503 	 *
504 	 * Params:
505 	 *     degX = return location for the rotation angle on
506 	 *         the X axis (yaw), in degrees
507 	 *     degY = return location for the rotation angle on
508 	 *         the Y axis (pitch), in degrees
509 	 *     degZ = return location for the rotation angle on
510 	 *         the Z axis (roll), in degrees
511 	 *
512 	 * Since: 1.2
513 	 */
514 	public void toAngles(out float degX, out float degY, out float degZ)
515 	{
516 		graphene_quaternion_to_angles(graphene_quaternion, &degX, &degY, &degZ);
517 	}
518 
519 	/**
520 	 * Converts a quaternion into a transformation matrix expressing
521 	 * the rotation defined by the #graphene_quaternion_t.
522 	 *
523 	 * Params:
524 	 *     m = a #graphene_matrix_t
525 	 *
526 	 * Since: 1.0
527 	 */
528 	public void toMatrix(out Matrix m)
529 	{
530 		graphene_matrix_t* outm = sliceNew!graphene_matrix_t();
531 
532 		graphene_quaternion_to_matrix(graphene_quaternion, outm);
533 
534 		m = ObjectG.getDObject!(Matrix)(outm, true);
535 	}
536 
537 	/**
538 	 * Converts a #graphene_quaternion_t to its corresponding rotations
539 	 * on the [Euler angles](http://en.wikipedia.org/wiki/Euler_angles)
540 	 * on each axis.
541 	 *
542 	 * Params:
543 	 *     radX = return location for the rotation angle on
544 	 *         the X axis (yaw), in radians
545 	 *     radY = return location for the rotation angle on
546 	 *         the Y axis (pitch), in radians
547 	 *     radZ = return location for the rotation angle on
548 	 *         the Z axis (roll), in radians
549 	 *
550 	 * Since: 1.2
551 	 */
552 	public void toRadians(out float radX, out float radY, out float radZ)
553 	{
554 		graphene_quaternion_to_radians(graphene_quaternion, &radX, &radY, &radZ);
555 	}
556 
557 	/**
558 	 * Copies the components of a #graphene_quaternion_t into a
559 	 * #graphene_vec4_t.
560 	 *
561 	 * Params:
562 	 *     res = return location for a
563 	 *         #graphene_vec4_t
564 	 *
565 	 * Since: 1.0
566 	 */
567 	public void toVec4(out Vec4 res)
568 	{
569 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
570 
571 		graphene_quaternion_to_vec4(graphene_quaternion, outres);
572 
573 		res = ObjectG.getDObject!(Vec4)(outres, true);
574 	}
575 }