1
0
Fork 0
mutter-performance-source/cogl/cogl-euler.c

199 lines
5.9 KiB
C
Raw Normal View History

/*
* Cogl
*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-22 01:28:54 +00:00
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2010 Intel Corporation.
*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-22 01:28:54 +00:00
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-22 01:28:54 +00:00
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-22 01:28:54 +00:00
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Authors:
* Robert Bragg <robert@linux.intel.com>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <cogl-util.h>
#include <cogl-euler.h>
#include <cogl-matrix.h>
#include "cogl-gtype-private.h"
#include <math.h>
#include <string.h>
COGL_GTYPE_DEFINE_BOXED (Euler, euler,
cogl_euler_copy,
cogl_euler_free);
void
cogl_euler_init (CoglEuler *euler,
float heading,
float pitch,
float roll)
{
euler->heading = heading;
euler->pitch = pitch;
euler->roll = roll;
}
void
cogl_euler_init_from_matrix (CoglEuler *euler,
const CoglMatrix *matrix)
{
/*
* Extracting a canonical Euler angle from a matrix:
* (where it is assumed the matrix contains no scaling, mirroring or
* skewing)
*
* A Euler angle is a combination of three rotations around mutually
* perpendicular axis. For this algorithm they are:
*
* Heading: A rotation about the Y axis by an angle H:
* | cosH 0 sinH|
* | 0 1 0|
* |-sinH 0 cosH|
*
* Pitch: A rotation around the X axis by an angle P:
* |1 0 0|
* |0 cosP -sinP|
* |0 sinP cosP|
*
* Roll: A rotation about the Z axis by an angle R:
* |cosR -sinR 0|
* |sinR cosR 0|
* | 0 0 1|
*
* When multiplied as matrices this gives:
* | cosHcosR+sinHsinPsinR sinRcosP -sinHcosR+cosHsinPsinR|
* M = |-cosHsinR+sinHsinPcosR cosRcosP sinRsinH+cosHsinPcosB|
* | sinHcosP -sinP cosHcosP |
*
* Given that there are an infinite number of ways to represent
* a given orientation, the "canonical" Euler angle is any such that:
* -180 < H < 180,
* -180 < R < 180 and
* -90 < P < 90
*
* M[3][2] = -sinP lets us immediately solve for P = asin(-M[3][2])
* (Note: asin has a range of +-90)
* This gives cosP
* This means we can use M[3][1] to calculate sinH:
* sinH = M[3][1]/cosP
* And use M[3][3] to calculate cosH:
* cosH = M[3][3]/cosP
* This lets us calculate H = atan2(sinH,cosH), but we optimise this:
* 1st note: atan2(x, y) does: atan(x/y) and uses the sign of x and y to
* determine the quadrant of the final angle.
* 2nd note: we know cosP is > 0 (ignoring cosP == 0)
* Therefore H = atan2((M[3][1]/cosP) / (M[3][3]/cosP)) can be simplified
* by skipping the division by cosP since it won't change the x/y ratio
* nor will it change their sign. This gives:
* H = atan2(M[3][1], M[3][3])
* R is computed in the same way as H from M[1][2] and M[2][2] so:
* R = atan2(M[1][2], M[2][2])
* Note: If cosP were == 0 then H and R could not be calculated as above
* because all the necessary matrix values would == 0. In other words we are
* pitched vertically and so H and R would now effectively rotate around the
* same axis - known as "Gimbal lock". In this situation we will set all the
* rotation on H and set R = 0.
* So with P = R = 0 we have cosP = 0, sinR = 0 and cosR = 1
* We can substitute those into the above equation for M giving:
* | cosH 0 -sinH|
* |sinHsinP 0 cosHsinP|
* | 0 -sinP 0|
* And calculate H as atan2 (-M[3][2], M[1][1])
*/
float sinP;
float H; /* heading */
float P; /* pitch */
float R; /* roll */
/* NB: CoglMatrix provides struct members named according to the
* [row][column] indexed. So matrix->zx is row 3 column 1. */
sinP = -matrix->zy;
/* Determine the Pitch, avoiding domain errors with asin () which
* might occur due to previous imprecision in manipulating the
* matrix. */
if (sinP <= -1.0f)
P = -G_PI_2;
else if (sinP >= 1.0f)
P = G_PI_2;
else
P = asinf (sinP);
/* If P is too close to 0 then we have hit Gimbal lock */
if (sinP > 0.999f)
{
H = atan2f (-matrix->zy, matrix->xx);
R = 0;
}
else
{
H = atan2f (matrix->zx, matrix->zz);
R = atan2f (matrix->xy, matrix->yy);
}
euler->heading = H;
euler->pitch = P;
euler->roll = R;
}
CoglBool
cogl_euler_equal (const void *v1, const void *v2)
{
const CoglEuler *a = v1;
const CoglEuler *b = v2;
_COGL_RETURN_VAL_IF_FAIL (v1 != NULL, FALSE);
_COGL_RETURN_VAL_IF_FAIL (v2 != NULL, FALSE);
if (v1 == v2)
return TRUE;
return (a->heading == b->heading &&
a->pitch == b->pitch &&
a->roll == b->roll);
}
CoglEuler *
cogl_euler_copy (const CoglEuler *src)
{
if (G_LIKELY (src))
{
CoglEuler *new = g_slice_new (CoglEuler);
memcpy (new, src, sizeof (float) * 3);
return new;
}
else
return NULL;
}
void
cogl_euler_free (CoglEuler *euler)
{
g_slice_free (CoglEuler, euler);
}