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.Euler;
26 
27 private import glib.ConstructionException;
28 private import glib.MemorySlice;
29 private import gobject.ObjectG;
30 private import graphene.Matrix;
31 private import graphene.Quaternion;
32 private import graphene.Vec3;
33 private import graphene.c.functions;
34 public  import graphene.c.types;
35 private import gtkd.Loader;
36 
37 
38 /**
39  * Describe a rotation using Euler angles.
40  * 
41  * The contents of the #graphene_euler_t structure are private
42  * and should never be accessed directly.
43  *
44  * Since: 1.2
45  */
46 public class Euler
47 {
48 	/** the main Gtk struct */
49 	protected graphene_euler_t* graphene_euler;
50 	protected bool ownedRef;
51 
52 	/** Get the main Gtk struct */
53 	public graphene_euler_t* getEulerStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return graphene_euler;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected void* getStruct()
62 	{
63 		return cast(void*)graphene_euler;
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (graphene_euler_t* graphene_euler, bool ownedRef = false)
70 	{
71 		this.graphene_euler = graphene_euler;
72 		this.ownedRef = ownedRef;
73 	}
74 
75 	~this ()
76 	{
77 		if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef )
78 			graphene_euler_free(graphene_euler);
79 	}
80 
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return graphene_euler_get_type();
86 	}
87 
88 	/**
89 	 * Allocates a new #graphene_euler_t.
90 	 *
91 	 * The contents of the returned structure are undefined.
92 	 *
93 	 * Returns: the newly allocated #graphene_euler_t
94 	 *
95 	 * Since: 1.2
96 	 *
97 	 * Throws: ConstructionException GTK+ fails to create the object.
98 	 */
99 	public this()
100 	{
101 		auto __p = graphene_euler_alloc();
102 
103 		if(__p is null)
104 		{
105 			throw new ConstructionException("null returned by alloc");
106 		}
107 
108 		this(cast(graphene_euler_t*) __p);
109 	}
110 
111 	/**
112 	 * Checks if two #graphene_euler_t are equal.
113 	 *
114 	 * Params:
115 	 *     b = a #graphene_euler_t
116 	 *
117 	 * Returns: `true` if the two #graphene_euler_t are equal
118 	 *
119 	 * Since: 1.2
120 	 */
121 	public bool equal(Euler b)
122 	{
123 		return graphene_euler_equal(graphene_euler, (b is null) ? null : b.getEulerStruct()) != 0;
124 	}
125 
126 	/**
127 	 * Frees the resources allocated by graphene_euler_alloc().
128 	 *
129 	 * Since: 1.2
130 	 */
131 	public void free()
132 	{
133 		graphene_euler_free(graphene_euler);
134 		ownedRef = false;
135 	}
136 
137 	/**
138 	 * Retrieves the first component of the Euler angle vector,
139 	 * depending on the order of rotation.
140 	 *
141 	 * See also: graphene_euler_get_x()
142 	 *
143 	 * Returns: the first component of the Euler angle vector, in radians
144 	 *
145 	 * Since: 1.10
146 	 */
147 	public float getAlpha()
148 	{
149 		return graphene_euler_get_alpha(graphene_euler);
150 	}
151 
152 	/**
153 	 * Retrieves the second component of the Euler angle vector,
154 	 * depending on the order of rotation.
155 	 *
156 	 * See also: graphene_euler_get_y()
157 	 *
158 	 * Returns: the second component of the Euler angle vector, in radians
159 	 *
160 	 * Since: 1.10
161 	 */
162 	public float getBeta()
163 	{
164 		return graphene_euler_get_beta(graphene_euler);
165 	}
166 
167 	/**
168 	 * Retrieves the third component of the Euler angle vector,
169 	 * depending on the order of rotation.
170 	 *
171 	 * See also: graphene_euler_get_z()
172 	 *
173 	 * Returns: the third component of the Euler angle vector, in radians
174 	 *
175 	 * Since: 1.10
176 	 */
177 	public float getGamma()
178 	{
179 		return graphene_euler_get_gamma(graphene_euler);
180 	}
181 
182 	/**
183 	 * Retrieves the order used to apply the rotations described in the
184 	 * #graphene_euler_t structure, when converting to and from other
185 	 * structures, like #graphene_quaternion_t and #graphene_matrix_t.
186 	 *
187 	 * This function does not return the %GRAPHENE_EULER_ORDER_DEFAULT
188 	 * enumeration value; it will return the effective order of rotation
189 	 * instead.
190 	 *
191 	 * Returns: the order used to apply the rotations
192 	 *
193 	 * Since: 1.2
194 	 */
195 	public graphene_euler_order_t getOrder()
196 	{
197 		return graphene_euler_get_order(graphene_euler);
198 	}
199 
200 	/**
201 	 * Retrieves the rotation angle on the X axis, in degrees.
202 	 *
203 	 * Returns: the rotation angle
204 	 *
205 	 * Since: 1.2
206 	 */
207 	public float getX()
208 	{
209 		return graphene_euler_get_x(graphene_euler);
210 	}
211 
212 	/**
213 	 * Retrieves the rotation angle on the Y axis, in degrees.
214 	 *
215 	 * Returns: the rotation angle
216 	 *
217 	 * Since: 1.2
218 	 */
219 	public float getY()
220 	{
221 		return graphene_euler_get_y(graphene_euler);
222 	}
223 
224 	/**
225 	 * Retrieves the rotation angle on the Z axis, in degrees.
226 	 *
227 	 * Returns: the rotation angle
228 	 *
229 	 * Since: 1.2
230 	 */
231 	public float getZ()
232 	{
233 		return graphene_euler_get_z(graphene_euler);
234 	}
235 
236 	/**
237 	 * Initializes a #graphene_euler_t using the given angles.
238 	 *
239 	 * The order of the rotations is %GRAPHENE_EULER_ORDER_DEFAULT.
240 	 *
241 	 * Params:
242 	 *     x = rotation angle on the X axis, in degrees
243 	 *     y = rotation angle on the Y axis, in degrees
244 	 *     z = rotation angle on the Z axis, in degrees
245 	 *
246 	 * Returns: the initialized #graphene_euler_t
247 	 *
248 	 * Since: 1.2
249 	 */
250 	public Euler init(float x, float y, float z)
251 	{
252 		auto __p = graphene_euler_init(graphene_euler, x, y, z);
253 
254 		if(__p is null)
255 		{
256 			return null;
257 		}
258 
259 		return ObjectG.getDObject!(Euler)(cast(graphene_euler_t*) __p);
260 	}
261 
262 	/**
263 	 * Initializes a #graphene_euler_t using the angles and order of
264 	 * another #graphene_euler_t.
265 	 *
266 	 * If the #graphene_euler_t @src is %NULL, this function is equivalent
267 	 * to calling graphene_euler_init() with all angles set to 0.
268 	 *
269 	 * Params:
270 	 *     src = a #graphene_euler_t
271 	 *
272 	 * Returns: the initialized #graphene_euler_t
273 	 *
274 	 * Since: 1.2
275 	 */
276 	public Euler initFromEuler(Euler src)
277 	{
278 		auto __p = graphene_euler_init_from_euler(graphene_euler, (src is null) ? null : src.getEulerStruct());
279 
280 		if(__p is null)
281 		{
282 			return null;
283 		}
284 
285 		return ObjectG.getDObject!(Euler)(cast(graphene_euler_t*) __p);
286 	}
287 
288 	/**
289 	 * Initializes a #graphene_euler_t using the given rotation matrix.
290 	 *
291 	 * If the #graphene_matrix_t @m is %NULL, the #graphene_euler_t will
292 	 * be initialized with all angles set to 0.
293 	 *
294 	 * Params:
295 	 *     m = a rotation matrix
296 	 *     order = the order used to apply the rotations
297 	 *
298 	 * Returns: the initialized #graphene_euler_t
299 	 *
300 	 * Since: 1.2
301 	 */
302 	public Euler initFromMatrix(Matrix m, graphene_euler_order_t order)
303 	{
304 		auto __p = graphene_euler_init_from_matrix(graphene_euler, (m is null) ? null : m.getMatrixStruct(), order);
305 
306 		if(__p is null)
307 		{
308 			return null;
309 		}
310 
311 		return ObjectG.getDObject!(Euler)(cast(graphene_euler_t*) __p);
312 	}
313 
314 	/**
315 	 * Initializes a #graphene_euler_t using the given normalized quaternion.
316 	 *
317 	 * If the #graphene_quaternion_t @q is %NULL, the #graphene_euler_t will
318 	 * be initialized with all angles set to 0.
319 	 *
320 	 * Params:
321 	 *     q = a normalized #graphene_quaternion_t
322 	 *     order = the order used to apply the rotations
323 	 *
324 	 * Returns: the initialized #graphene_euler_t
325 	 *
326 	 * Since: 1.2
327 	 */
328 	public Euler initFromQuaternion(Quaternion q, graphene_euler_order_t order)
329 	{
330 		auto __p = graphene_euler_init_from_quaternion(graphene_euler, (q is null) ? null : q.getQuaternionStruct(), order);
331 
332 		if(__p is null)
333 		{
334 			return null;
335 		}
336 
337 		return ObjectG.getDObject!(Euler)(cast(graphene_euler_t*) __p);
338 	}
339 
340 	/**
341 	 * Initializes a #graphene_euler_t using the given angles
342 	 * and order of rotation.
343 	 *
344 	 * Params:
345 	 *     x = rotation angle on the X axis, in radians
346 	 *     y = rotation angle on the Y axis, in radians
347 	 *     z = rotation angle on the Z axis, in radians
348 	 *     order = order of rotations
349 	 *
350 	 * Returns: the initialized #graphene_euler_t
351 	 *
352 	 * Since: 1.10
353 	 */
354 	public Euler initFromRadians(float x, float y, float z, graphene_euler_order_t order)
355 	{
356 		auto __p = graphene_euler_init_from_radians(graphene_euler, x, y, z, order);
357 
358 		if(__p is null)
359 		{
360 			return null;
361 		}
362 
363 		return ObjectG.getDObject!(Euler)(cast(graphene_euler_t*) __p);
364 	}
365 
366 	/**
367 	 * Initializes a #graphene_euler_t using the angles contained in a
368 	 * #graphene_vec3_t.
369 	 *
370 	 * If the #graphene_vec3_t @v is %NULL, the #graphene_euler_t will be
371 	 * initialized with all angles set to 0.
372 	 *
373 	 * Params:
374 	 *     v = a #graphene_vec3_t containing the rotation
375 	 *         angles in degrees
376 	 *     order = the order used to apply the rotations
377 	 *
378 	 * Returns: the initialized #graphene_euler_t
379 	 *
380 	 * Since: 1.2
381 	 */
382 	public Euler initFromVec3(Vec3 v, graphene_euler_order_t order)
383 	{
384 		auto __p = graphene_euler_init_from_vec3(graphene_euler, (v is null) ? null : v.getVec3Struct(), order);
385 
386 		if(__p is null)
387 		{
388 			return null;
389 		}
390 
391 		return ObjectG.getDObject!(Euler)(cast(graphene_euler_t*) __p);
392 	}
393 
394 	/**
395 	 * Initializes a #graphene_euler_t with the given angles and @order.
396 	 *
397 	 * Params:
398 	 *     x = rotation angle on the X axis, in degrees
399 	 *     y = rotation angle on the Y axis, in degrees
400 	 *     z = rotation angle on the Z axis, in degrees
401 	 *     order = the order used to apply the rotations
402 	 *
403 	 * Returns: the initialized #graphene_euler_t
404 	 *
405 	 * Since: 1.2
406 	 */
407 	public Euler initWithOrder(float x, float y, float z, graphene_euler_order_t order)
408 	{
409 		auto __p = graphene_euler_init_with_order(graphene_euler, x, y, z, order);
410 
411 		if(__p is null)
412 		{
413 			return null;
414 		}
415 
416 		return ObjectG.getDObject!(Euler)(cast(graphene_euler_t*) __p);
417 	}
418 
419 	/**
420 	 * Reorders a #graphene_euler_t using @order.
421 	 *
422 	 * This function is equivalent to creating a #graphene_quaternion_t from the
423 	 * given #graphene_euler_t, and then converting the quaternion into another
424 	 * #graphene_euler_t.
425 	 *
426 	 * Params:
427 	 *     order = the new order
428 	 *     res = return location for the reordered
429 	 *         #graphene_euler_t
430 	 *
431 	 * Since: 1.2
432 	 */
433 	public void reorder(graphene_euler_order_t order, out Euler res)
434 	{
435 		graphene_euler_t* outres = sliceNew!graphene_euler_t();
436 
437 		graphene_euler_reorder(graphene_euler, order, outres);
438 
439 		res = ObjectG.getDObject!(Euler)(outres, true);
440 	}
441 
442 	/**
443 	 * Converts a #graphene_euler_t into a transformation matrix expressing
444 	 * the extrinsic composition of rotations described by the Euler angles.
445 	 *
446 	 * The rotations are applied over the reference frame axes in the order
447 	 * associated with the #graphene_euler_t; for instance, if the order
448 	 * used to initialize @e is %GRAPHENE_EULER_ORDER_XYZ:
449 	 *
450 	 * * the first rotation moves the body around the X axis with
451 	 * an angle φ
452 	 * * the second rotation moves the body around the Y axis with
453 	 * an angle of ϑ
454 	 * * the third rotation moves the body around the Z axis with
455 	 * an angle of ψ
456 	 *
457 	 * The rotation sign convention is right-handed, to preserve compatibility
458 	 * between Euler-based, quaternion-based, and angle-axis-based rotations.
459 	 *
460 	 * Params:
461 	 *     res = return location for a #graphene_matrix_t
462 	 *
463 	 * Since: 1.2
464 	 */
465 	public void toMatrix(out Matrix res)
466 	{
467 		graphene_matrix_t* outres = sliceNew!graphene_matrix_t();
468 
469 		graphene_euler_to_matrix(graphene_euler, outres);
470 
471 		res = ObjectG.getDObject!(Matrix)(outres, true);
472 	}
473 
474 	/**
475 	 * Converts a #graphene_euler_t into a #graphene_quaternion_t.
476 	 *
477 	 * Params:
478 	 *     res = return location for a #graphene_quaternion_t
479 	 *
480 	 * Since: 1.10
481 	 */
482 	public void toQuaternion(out Quaternion res)
483 	{
484 		graphene_quaternion_t* outres = sliceNew!graphene_quaternion_t();
485 
486 		graphene_euler_to_quaternion(graphene_euler, outres);
487 
488 		res = ObjectG.getDObject!(Quaternion)(outres, true);
489 	}
490 
491 	/**
492 	 * Retrieves the angles of a #graphene_euler_t and initializes a
493 	 * #graphene_vec3_t with them.
494 	 *
495 	 * Params:
496 	 *     res = return location for a #graphene_vec3_t
497 	 *
498 	 * Since: 1.2
499 	 */
500 	public void toVec3(out Vec3 res)
501 	{
502 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
503 
504 		graphene_euler_to_vec3(graphene_euler, outres);
505 
506 		res = ObjectG.getDObject!(Vec3)(outres, true);
507 	}
508 }