4 * An object oriented GL/GLES Abstraction/Utility Layer
6 * Copyright (C) 2010 Intel Corporation.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 * Robert Bragg <robert@linux.intel.com>
27 #if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
28 #error "Only <cogl/cogl.h> can be included directly."
31 #ifndef __COGL_EULER_H
32 #define __COGL_EULER_H
34 #include <cogl/cogl-types.h>
42 * @short_description: Functions for initializing and manipulating
45 * Euler angles are a simple representation of a 3 dimensional
46 * rotation; comprised of 3 ordered heading, pitch and roll rotations.
47 * An important thing to understand is that the axis of rotation
48 * belong to the object being rotated and so they also rotate as each
49 * of the heading, pitch and roll rotations are applied.
51 * One way to consider euler angles is to imagine controlling an
52 * aeroplane, where you first choose a heading (Such as flying south
53 * east), then you set the pitch (such as 30 degrees to take off) and
54 * then you might set a roll, by dipping the left, wing as you prepare
57 * They have some advantages and limitations that it helps to be
63 * Easy to understand and use, compared to quaternions and matrices,
64 * so may be a good choice for a user interface.
67 * Efficient storage, needing only 3 components any rotation can be
69 * <note>Actually the #CoglEuler type isn't optimized for size because
70 * we may cache the equivalent #CoglQuaternion along with a euler
71 * rotation, but it would be trivial for an application to track the
72 * components of euler rotations in a packed float array if optimizing
73 * for size was important. The values could be passed to Cogl only when
74 * manipulation is necessary.</note>
81 * Aliasing: it's possible to represent some rotations with multiple
82 * different heading, pitch and roll rotations.
85 * They can suffer from a problem called Gimbal Lock. A good
86 * explanation of this can be seen on wikipedia here:
87 * http://en.wikipedia.org/wiki/Gimbal_lock but basically two
88 * of the axis of rotation may become aligned and so you loose a
89 * degree of freedom. For example a pitch of +-90° would mean that
90 * heading and bank rotate around the same axis.
93 * If you use euler angles to orient something in 3D space and try to
94 * transition between orientations by interpolating the component
95 * angles you probably wont get the transitions you expect as they may
96 * not follow the shortest path between the two orientations.
99 * There's no standard to what order the component axis rotations are
100 * applied. The most common convention seems to be what we do in Cogl
101 * with heading (y-axis), pitch (x-axis) and then roll (z-axis), but
102 * other software might apply x-axis, y-axis then z-axis or any other
103 * order so you need to consider this if you are accepting euler
104 * rotations from some other software. Other software may also use
105 * slightly different aeronautical terms, such as "yaw" instead of
106 * "heading" or "bank" instead of "roll".
110 * To minimize the aliasing issue we may refer to "Canonical Euler"
111 * angles where heading and roll are restricted to +- 180° and pitch is
112 * restricted to +- 90°. If pitch is +- 90° bank is set to 0°.
114 * Quaternions don't suffer from Gimbal Lock and they can be nicely
115 * interpolated between, their disadvantage is that they don't have an
116 * intuitive representation.
118 * A common practice is to accept angles in the intuitive Euler form
119 * and convert them to quaternions internally to avoid Gimbal Lock and
120 * handle interpolations. See cogl_quaternion_init_from_euler().
125 * @heading: Angle to rotate around an object's y axis
126 * @pitch: Angle to rotate around an object's x axis
127 * @roll: Angle to rotate around an object's z axis
129 * Represents an ordered rotation first of @heading degrees around an
130 * object's y axis, then @pitch degrees around an object's x axis and
131 * finally @roll degrees around an object's z axis.
133 * <note>It's important to understand the that axis are associated
134 * with the object being rotated, so the axis also rotate in sequence
135 * with the rotations being applied.</note>
137 * The members of a #CoglEuler can be initialized, for example, with
138 * cogl_euler_init() and cogl_euler_init_from_quaternion ().
140 * You may also want to look at cogl_quaternion_init_from_euler() if
141 * you want to do interpolation between 3d rotations.
153 /* May cached a quaternion here in the future */
160 COGL_STRUCT_SIZE_ASSERT (CoglEuler, 32);
164 * @euler: The #CoglEuler angle to initialize
165 * @heading: Angle to rotate around an object's y axis
166 * @pitch: Angle to rotate around an object's x axis
167 * @roll: Angle to rotate around an object's z axis
169 * Initializes @euler to represent a rotation of @x_angle degrees
170 * around the x axis, then @y_angle degrees around the y_axis and
171 * @z_angle degrees around the z axis.
176 cogl_euler_init (CoglEuler *euler,
182 * cogl_euler_init_from_matrix:
183 * @euler: The #CoglEuler angle to initialize
184 * @matrix: A #CoglMatrix containing a rotation, but no scaling,
185 * mirroring or skewing.
187 * Extracts a euler rotation from the given @matrix and
188 * initializses @euler with the component x, y and z rotation angles.
191 cogl_euler_init_from_matrix (CoglEuler *euler,
192 const CoglMatrix *matrix);
195 * cogl_euler_init_from_quaternion:
196 * @euler: The #CoglEuler angle to initialize
197 * @quaternion: A #CoglEuler with the rotation to initialize with
199 * Initializes a @euler rotation with the equivalent rotation
200 * represented by the given @quaternion.
203 cogl_euler_init_from_quaternion (CoglEuler *euler,
204 const CoglQuaternion *quaternion);
208 * @v1: The first euler angle to compare
209 * @v1: The second euler angle to compare
211 * Compares the two given euler angles @v1 and @v1 and it they are
212 * equal returns %TRUE else %FALSE.
214 * <note>This function only checks that all three components rotations
215 * are numerically equal, it does not consider that some rotations
216 * can be represented with different component rotations</note>
218 * Returns: %TRUE if @v1 and @v2 are equal else %FALSE.
222 cogl_euler_equal (gconstpointer v1, gconstpointer v2);
226 * @src: A #CoglEuler to copy
228 * Allocates a new #CoglEuler and initilizes it with the component
229 * angles of @src. The newly allocated euler should be freed using
232 * Returns: A newly allocated #CoglEuler
236 cogl_euler_copy (const CoglEuler *src);
240 * @euler: A #CoglEuler allocated via cogl_euler_copy()
242 * Frees a #CoglEuler that was previously allocated using
248 cogl_euler_free (CoglEuler *euler);
252 #endif /* __COGL_EULER_H */