Replace CoglEuler by graphene_euler_t

As the first step into removing Cogl types that are covered by
Graphene, remove CoglEuler and replace it by graphene_euler_t.

This is a mostly straightforward replacement, except that the
naming conventions changed a bit. Cogl uses "heading" for the
Y axis, "pitch" for the X axis, and "roll" for the Z axis, and
graphene uses the axis themselves. That means the 1st and 2nd
arguments need to be swapped.

Also adapt the matrix stack to store a graphene_euler_t in the
rotation node -- that simplifies the code a bit as well.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/458
This commit is contained in:
Georges Basile Stavracas Neto 2019-02-16 09:41:43 -02:00
parent b1255bddcd
commit 4a4a423182
No known key found for this signature in database
GPG Key ID: 886C17EE170D1385
18 changed files with 61 additions and 543 deletions

View File

@ -1,196 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2010 Intel Corporation.
*
* 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:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 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>
*/
#include "cogl-config.h"
#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;
}
gboolean
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);
}

View File

@ -1,265 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2010 Intel Corporation.
*
* 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:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 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>
*/
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
#error "Only <cogl/cogl.h> can be included directly."
#endif
#ifndef __COGL_EULER_H
#define __COGL_EULER_H
#include <cogl/cogl-types.h>
#include <glib-object.h>
G_BEGIN_DECLS
/**
* SECTION:cogl-euler
* @short_description: Functions for initializing and manipulating
* euler angles.
*
* Euler angles are a simple representation of a 3 dimensional
* rotation; comprised of 3 ordered heading, pitch and roll rotations.
* An important thing to understand is that the axis of rotation
* belong to the object being rotated and so they also rotate as each
* of the heading, pitch and roll rotations are applied.
*
* One way to consider euler angles is to imagine controlling an
* aeroplane, where you first choose a heading (Such as flying south
* east), then you set the pitch (such as 30 degrees to take off) and
* then you might set a roll, by dipping the left, wing as you prepare
* to turn.
*
* They have some advantages and limitations that it helps to be
* aware of:
*
* Advantages:
* <itemizedlist>
* <listitem>
* Easy to understand and use, compared to quaternions and matrices,
* so may be a good choice for a user interface.
* </listitem>
* <listitem>
* Efficient storage, needing only 3 components any rotation can be
* represented.
* <note>Actually the #CoglEuler type isn't optimized for size because
* we may cache the equivalent #CoglQuaternion along with a euler
* rotation, but it would be trivial for an application to track the
* components of euler rotations in a packed float array if optimizing
* for size was important. The values could be passed to Cogl only when
* manipulation is necessary.</note>
* </listitem>
* </itemizedlist>
*
* Disadvantages:
* <itemizedlist>
* <listitem>
* Aliasing: it's possible to represent some rotations with multiple
* different heading, pitch and roll rotations.
* </listitem>
* <listitem>
* They can suffer from a problem called Gimbal Lock. A good
* explanation of this can be seen on wikipedia here:
* http://en.wikipedia.org/wiki/Gimbal_lock but basically two
* of the axis of rotation may become aligned and so you loose a
* degree of freedom. For example a pitch of +-90° would mean that
* heading and bank rotate around the same axis.
* </listitem>
* <listitem>
* If you use euler angles to orient something in 3D space and try to
* transition between orientations by interpolating the component
* angles you probably wont get the transitions you expect as they may
* not follow the shortest path between the two orientations.
* </listitem>
* <listitem>
* There's no standard to what order the component axis rotations are
* applied. The most common convention seems to be what we do in Cogl
* with heading (y-axis), pitch (x-axis) and then roll (z-axis), but
* other software might apply x-axis, y-axis then z-axis or any other
* order so you need to consider this if you are accepting euler
* rotations from some other software. Other software may also use
* slightly different aeronautical terms, such as "yaw" instead of
* "heading" or "bank" instead of "roll".
* </listitem>
* </itemizedlist>
*
* To minimize the aliasing issue we may refer to "Canonical Euler"
* angles where heading and roll are restricted to +- 180° and pitch is
* restricted to +- 90°. If pitch is +- 90° bank is set to 0°.
*
* Quaternions don't suffer from Gimbal Lock and they can be nicely
* interpolated between, their disadvantage is that they don't have an
* intuitive representation.
*
* A common practice is to accept angles in the intuitive Euler form
* and convert them to quaternions internally to avoid Gimbal Lock and
* handle interpolations. See cogl_quaternion_init_from_euler().
*/
/**
* CoglEuler:
* @heading: Angle to rotate around an object's y axis
* @pitch: Angle to rotate around an object's x axis
* @roll: Angle to rotate around an object's z axis
*
* Represents an ordered rotation first of @heading degrees around an
* object's y axis, then @pitch degrees around an object's x axis and
* finally @roll degrees around an object's z axis.
*
* <note>It's important to understand the that axis are associated
* with the object being rotated, so the axis also rotate in sequence
* with the rotations being applied.</note>
*
* The members of a #CoglEuler can be initialized, for example, with
* cogl_euler_init() and cogl_euler_init_from_quaternion ().
*
* You may also want to look at cogl_quaternion_init_from_euler() if
* you want to do interpolation between 3d rotations.
*
* Since: 2.0
*/
struct _CoglEuler
{
/*< public > */
float heading;
float pitch;
float roll;
/*< private > */
/* May cached a quaternion here in the future */
float padding0;
float padding1;
float padding2;
float padding3;
float padding4;
};
COGL_STRUCT_SIZE_ASSERT (CoglEuler, 32);
/**
* cogl_euler_get_gtype:
*
* Returns: a #GType that can be used with the GLib type system.
*/
GType cogl_euler_get_gtype (void);
/**
* cogl_euler_init:
* @euler: The #CoglEuler angle to initialize
* @heading: Angle to rotate around an object's y axis
* @pitch: Angle to rotate around an object's x axis
* @roll: Angle to rotate around an object's z axis
*
* Initializes @euler to represent a rotation of @x_angle degrees
* around the x axis, then @y_angle degrees around the y_axis and
* @z_angle degrees around the z axis.
*
* Since: 2.0
*/
void
cogl_euler_init (CoglEuler *euler,
float heading,
float pitch,
float roll);
/**
* cogl_euler_init_from_matrix:
* @euler: The #CoglEuler angle to initialize
* @matrix: A #CoglMatrix containing a rotation, but no scaling,
* mirroring or skewing.
*
* Extracts a euler rotation from the given @matrix and
* initializses @euler with the component x, y and z rotation angles.
*/
void
cogl_euler_init_from_matrix (CoglEuler *euler,
const CoglMatrix *matrix);
/**
* cogl_euler_init_from_quaternion:
* @euler: The #CoglEuler angle to initialize
* @quaternion: A #CoglEuler with the rotation to initialize with
*
* Initializes a @euler rotation with the equivalent rotation
* represented by the given @quaternion.
*/
void
cogl_euler_init_from_quaternion (CoglEuler *euler,
const CoglQuaternion *quaternion);
/**
* cogl_euler_equal:
* @v1: The first euler angle to compare
* @v2: The second euler angle to compare
*
* Compares the two given euler angles @v1 and @v1 and it they are
* equal returns %TRUE else %FALSE.
*
* <note>This function only checks that all three components rotations
* are numerically equal, it does not consider that some rotations
* can be represented with different component rotations</note>
*
* Returns: %TRUE if @v1 and @v2 are equal else %FALSE.
* Since: 2.0
*/
gboolean
cogl_euler_equal (const void *v1, const void *v2);
/**
* cogl_euler_copy:
* @src: A #CoglEuler to copy
*
* Allocates a new #CoglEuler and initilizes it with the component
* angles of @src. The newly allocated euler should be freed using
* cogl_euler_free().
*
* Returns: A newly allocated #CoglEuler
* Since: 2.0
*/
CoglEuler *
cogl_euler_copy (const CoglEuler *src);
/**
* cogl_euler_free:
* @euler: A #CoglEuler allocated via cogl_euler_copy()
*
* Frees a #CoglEuler that was previously allocated using
* cogl_euler_copy().
*
* Since: 2.0
*/
void
cogl_euler_free (CoglEuler *euler);
G_END_DECLS
#endif /* __COGL_EULER_H */

View File

@ -1616,7 +1616,7 @@ cogl_framebuffer_rotate_quaternion (CoglFramebuffer *framebuffer,
void void
cogl_framebuffer_rotate_euler (CoglFramebuffer *framebuffer, cogl_framebuffer_rotate_euler (CoglFramebuffer *framebuffer,
const CoglEuler *euler) const graphene_euler_t *euler)
{ {
CoglMatrixStack *modelview_stack = CoglMatrixStack *modelview_stack =
_cogl_framebuffer_get_modelview_stack (framebuffer); _cogl_framebuffer_get_modelview_stack (framebuffer);

View File

@ -52,10 +52,11 @@ typedef struct _CoglFramebuffer CoglFramebuffer;
#include <cogl/cogl-indices.h> #include <cogl/cogl-indices.h>
#include <cogl/cogl-bitmap.h> #include <cogl/cogl-bitmap.h>
#include <cogl/cogl-quaternion.h> #include <cogl/cogl-quaternion.h>
#include <cogl/cogl-euler.h>
#include <cogl/cogl-texture.h> #include <cogl/cogl-texture.h>
#include <glib-object.h> #include <glib-object.h>
#include <graphene.h>
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
@ -379,7 +380,7 @@ cogl_framebuffer_rotate_quaternion (CoglFramebuffer *framebuffer,
/** /**
* cogl_framebuffer_rotate_euler: * cogl_framebuffer_rotate_euler:
* @framebuffer: A #CoglFramebuffer pointer * @framebuffer: A #CoglFramebuffer pointer
* @euler: A #CoglEuler * @euler: A #graphene_euler_t
* *
* Multiplies the current model-view matrix by one that rotates * Multiplies the current model-view matrix by one that rotates
* according to the rotation described by @euler. * according to the rotation described by @euler.
@ -389,7 +390,7 @@ cogl_framebuffer_rotate_quaternion (CoglFramebuffer *framebuffer,
*/ */
void void
cogl_framebuffer_rotate_euler (CoglFramebuffer *framebuffer, cogl_framebuffer_rotate_euler (CoglFramebuffer *framebuffer,
const CoglEuler *euler); const graphene_euler_t *euler);
/** /**
* cogl_framebuffer_transform: * cogl_framebuffer_transform:

View File

@ -90,11 +90,7 @@ typedef struct _CoglMatrixEntryRotateEuler
{ {
CoglMatrixEntry _parent_data; CoglMatrixEntry _parent_data;
/* This doesn't store an actual CoglEuler in order to avoid the graphene_euler_t euler;
* padding */
float heading;
float pitch;
float roll;
} CoglMatrixEntryRotateEuler; } CoglMatrixEntryRotateEuler;
typedef struct _CoglMatrixEntryRotateQuaternion typedef struct _CoglMatrixEntryRotateQuaternion

View File

@ -196,17 +196,14 @@ cogl_matrix_stack_rotate_quaternion (CoglMatrixStack *stack,
} }
void void
cogl_matrix_stack_rotate_euler (CoglMatrixStack *stack, cogl_matrix_stack_rotate_euler (CoglMatrixStack *stack,
const CoglEuler *euler) const graphene_euler_t *euler)
{ {
CoglMatrixEntryRotateEuler *entry; CoglMatrixEntryRotateEuler *entry;
entry = _cogl_matrix_stack_push_operation (stack, entry = _cogl_matrix_stack_push_operation (stack,
COGL_MATRIX_OP_ROTATE_EULER); COGL_MATRIX_OP_ROTATE_EULER);
graphene_euler_init_from_euler (&entry->euler, euler);
entry->heading = euler->heading;
entry->pitch = euler->pitch;
entry->roll = euler->roll;
} }
void void
@ -580,13 +577,8 @@ initialized:
{ {
CoglMatrixEntryRotateEuler *rotate = CoglMatrixEntryRotateEuler *rotate =
(CoglMatrixEntryRotateEuler *)children[i]; (CoglMatrixEntryRotateEuler *)children[i];
CoglEuler euler;
cogl_euler_init (&euler,
rotate->heading,
rotate->pitch,
rotate->roll);
cogl_matrix_rotate_euler (matrix, cogl_matrix_rotate_euler (matrix,
&euler); &rotate->euler);
continue; continue;
} }
case COGL_MATRIX_OP_ROTATE_QUATERNION: case COGL_MATRIX_OP_ROTATE_QUATERNION:
@ -1008,9 +1000,7 @@ cogl_matrix_entry_equal (CoglMatrixEntry *entry0,
CoglMatrixEntryRotateEuler *rotate1 = CoglMatrixEntryRotateEuler *rotate1 =
(CoglMatrixEntryRotateEuler *)entry1; (CoglMatrixEntryRotateEuler *)entry1;
if (rotate0->heading != rotate1->heading || if (!graphene_euler_equal (&rotate0->euler, &rotate1->euler))
rotate0->pitch != rotate1->pitch ||
rotate0->roll != rotate1->roll)
return FALSE; return FALSE;
} }
break; break;
@ -1118,9 +1108,9 @@ cogl_debug_matrix_entry_print (CoglMatrixEntry *entry)
CoglMatrixEntryRotateEuler *rotate = CoglMatrixEntryRotateEuler *rotate =
(CoglMatrixEntryRotateEuler *)entry; (CoglMatrixEntryRotateEuler *)entry;
g_print (" ROTATE EULER heading=%f pitch=%f roll=%f\n", g_print (" ROTATE EULER heading=%f pitch=%f roll=%f\n",
rotate->heading, graphene_euler_get_y (&rotate->euler),
rotate->pitch, graphene_euler_get_x (&rotate->euler),
rotate->roll); graphene_euler_get_z (&rotate->euler));
continue; continue;
} }
case COGL_MATRIX_OP_SCALE: case COGL_MATRIX_OP_SCALE:

View File

@ -42,6 +42,7 @@
#include "cogl-matrix.h" #include "cogl-matrix.h"
#include "cogl-context.h" #include "cogl-context.h"
#include <graphene.h>
/** /**
* SECTION:cogl-matrix-stack * SECTION:cogl-matrix-stack
@ -321,14 +322,14 @@ cogl_matrix_stack_rotate_quaternion (CoglMatrixStack *stack,
/** /**
* cogl_matrix_stack_rotate_euler: * cogl_matrix_stack_rotate_euler:
* @stack: A #CoglMatrixStack * @stack: A #CoglMatrixStack
* @euler: A #CoglEuler * @euler: A #graphene_euler_t
* *
* Multiplies the current matrix by one that rotates according to the * Multiplies the current matrix by one that rotates according to the
* rotation described by @euler. * rotation described by @euler.
*/ */
void void
cogl_matrix_stack_rotate_euler (CoglMatrixStack *stack, cogl_matrix_stack_rotate_euler (CoglMatrixStack *stack,
const CoglEuler *euler); const graphene_euler_t *euler);
/** /**
* cogl_matrix_stack_multiply: * cogl_matrix_stack_multiply:

View File

@ -1370,7 +1370,7 @@ cogl_matrix_rotate_quaternion (CoglMatrix *matrix,
void void
cogl_matrix_rotate_euler (CoglMatrix *matrix, cogl_matrix_rotate_euler (CoglMatrix *matrix,
const CoglEuler *euler) const graphene_euler_t *euler)
{ {
CoglMatrix rotation_transform; CoglMatrix rotation_transform;
@ -1779,12 +1779,12 @@ cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
void void
cogl_matrix_init_from_euler (CoglMatrix *matrix, cogl_matrix_init_from_euler (CoglMatrix *matrix,
const CoglEuler *euler) const graphene_euler_t *euler)
{ {
/* Convert angles to radians */ /* Convert angles to radians */
float heading_rad = euler->heading / 180.0f * G_PI; float heading_rad = graphene_euler_get_y (euler) / 180.0f * G_PI;
float pitch_rad = euler->pitch / 180.0f * G_PI; float pitch_rad = graphene_euler_get_x (euler) / 180.0f * G_PI;
float roll_rad = euler->roll / 180.0f * G_PI; float roll_rad = graphene_euler_get_z (euler) / 180.0f * G_PI;
/* Pre-calculate the sin and cos */ /* Pre-calculate the sin and cos */
float sin_heading = sinf (heading_rad); float sin_heading = sinf (heading_rad);
float cos_heading = cosf (heading_rad); float cos_heading = cosf (heading_rad);

View File

@ -44,6 +44,8 @@
#include <cogl/cogl-quaternion.h> #include <cogl/cogl-quaternion.h>
#include <glib-object.h> #include <glib-object.h>
#include <graphene.h>
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
@ -216,13 +218,13 @@ cogl_matrix_rotate_quaternion (CoglMatrix *matrix,
* @euler: A euler describing a rotation * @euler: A euler describing a rotation
* *
* Multiplies @matrix with a rotation transformation described by the * Multiplies @matrix with a rotation transformation described by the
* given #CoglEuler. * given #graphene_euler_t.
* *
* Since: 2.0 * Since: 2.0
*/ */
void void
cogl_matrix_rotate_euler (CoglMatrix *matrix, cogl_matrix_rotate_euler (CoglMatrix *matrix,
const CoglEuler *euler); const graphene_euler_t *euler);
/** /**
* cogl_matrix_translate: * cogl_matrix_translate:
@ -529,13 +531,13 @@ cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
/** /**
* cogl_matrix_init_from_euler: * cogl_matrix_init_from_euler:
* @matrix: A 4x4 transformation matrix * @matrix: A 4x4 transformation matrix
* @euler: A #CoglEuler * @euler: A #graphene_euler_t
* *
* Initializes @matrix from a #CoglEuler rotation. * Initializes @matrix from a #graphene_euler_t rotation.
*/ */
void void
cogl_matrix_init_from_euler (CoglMatrix *matrix, cogl_matrix_init_from_euler (CoglMatrix *matrix,
const CoglEuler *euler); const graphene_euler_t *euler);
/** /**
* cogl_matrix_equal: * cogl_matrix_equal:

View File

@ -46,7 +46,6 @@
#include <cogl-quaternion-private.h> #include <cogl-quaternion-private.h>
#include <cogl-matrix.h> #include <cogl-matrix.h>
#include <cogl-vector.h> #include <cogl-vector.h>
#include <cogl-euler.h>
#include "cogl-gtype-private.h" #include "cogl-gtype-private.h"
#include <string.h> #include <string.h>
@ -200,24 +199,24 @@ cogl_quaternion_init_from_z_rotation (CoglQuaternion *quaternion,
void void
cogl_quaternion_init_from_euler (CoglQuaternion *quaternion, cogl_quaternion_init_from_euler (CoglQuaternion *quaternion,
const CoglEuler *euler) const graphene_euler_t *euler)
{ {
/* NB: We are using quaternions to represent an axis (a), angle (𝜃) pair /* NB: We are using quaternions to represent an axis (a), angle (𝜃) pair
* in this form: * in this form:
* [w=cos(𝜃/2) ( x=sin(𝜃/2)*a.x, y=sin(𝜃/2)*a.y, z=sin(𝜃/2)*a.x )] * [w=cos(𝜃/2) ( x=sin(𝜃/2)*a.x, y=sin(𝜃/2)*a.y, z=sin(𝜃/2)*a.x )]
*/ */
float sin_heading = float sin_heading =
sinf (euler->heading * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f); sinf (graphene_euler_get_y (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
float sin_pitch = float sin_pitch =
sinf (euler->pitch * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f); sinf (graphene_euler_get_x (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
float sin_roll = float sin_roll =
sinf (euler->roll * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f); sinf (graphene_euler_get_z (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
float cos_heading = float cos_heading =
cosf (euler->heading * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f); cosf (graphene_euler_get_y (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
float cos_pitch = float cos_pitch =
cosf (euler->pitch * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f); cosf (graphene_euler_get_x (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
float cos_roll = float cos_roll =
cosf (euler->roll * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f); cosf (graphene_euler_get_z (euler) * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f);
quaternion->w = quaternion->w =
cos_heading * cos_pitch * cos_roll + cos_heading * cos_pitch * cos_roll +

View File

@ -36,6 +36,8 @@
#ifndef __COGL_QUATERNION_H__ #ifndef __COGL_QUATERNION_H__
#define __COGL_QUATERNION_H__ #define __COGL_QUATERNION_H__
#include <graphene.h>
#include <cogl/cogl-types.h> #include <cogl/cogl-types.h>
#include <cogl/cogl-vector.h> #include <cogl/cogl-vector.h>
@ -57,7 +59,6 @@ G_BEGIN_DECLS
* . * .
*/ */
#include <cogl/cogl-vector.h> #include <cogl/cogl-vector.h>
#include <cogl/cogl-euler.h>
#include <glib-object.h> #include <glib-object.h>
@ -269,13 +270,13 @@ cogl_quaternion_init_from_z_rotation (CoglQuaternion *quaternion,
/** /**
* cogl_quaternion_init_from_euler: * cogl_quaternion_init_from_euler:
* @quaternion: A #CoglQuaternion * @quaternion: A #CoglQuaternion
* @euler: A #CoglEuler with which to initialize the quaternion * @euler: A #graphene_euler_t with which to initialize the quaternion
* *
* Since: 2.0 * Since: 2.0
*/ */
void void
cogl_quaternion_init_from_euler (CoglQuaternion *quaternion, cogl_quaternion_init_from_euler (CoglQuaternion *quaternion,
const CoglEuler *euler); const graphene_euler_t *euler);
/** /**
* cogl_quaternion_init_from_quaternion: * cogl_quaternion_init_from_quaternion:

View File

@ -114,17 +114,13 @@ void
cogl_handle_unref (CoglHandle handle); cogl_handle_unref (CoglHandle handle);
/* We forward declare this in cogl-types to avoid circular dependencies /* We forward declare this in cogl-types to avoid circular dependencies
* between cogl-matrix.h, cogl-euler.h and cogl-quaterion.h */ * between cogl-matrix.h and cogl-quaterion.h */
typedef struct _CoglMatrix CoglMatrix; typedef struct _CoglMatrix CoglMatrix;
/* Same as above we forward declared CoglQuaternion to avoid /* Same as above we forward declared CoglQuaternion to avoid
* circular dependencies. */ * circular dependencies. */
typedef struct _CoglQuaternion CoglQuaternion; typedef struct _CoglQuaternion CoglQuaternion;
/* Same as above we forward declared CoglEuler to avoid
* circular dependencies. */
typedef struct _CoglEuler CoglEuler;
/** /**
* CoglAngle: * CoglAngle:
* *

View File

@ -42,6 +42,8 @@
#define __COGL_MUST_UNDEF_COGL_H_INSIDE__ #define __COGL_MUST_UNDEF_COGL_H_INSIDE__
#endif #endif
#include <graphene.h>
/* We currently keep gtype integration delimited in case we eventually /* We currently keep gtype integration delimited in case we eventually
* want to split it out into a separate utility library when Cogl * want to split it out into a separate utility library when Cogl
* becomes a standalone project. (like cairo-gobject.so) * becomes a standalone project. (like cairo-gobject.so)
@ -101,7 +103,6 @@
#include <cogl/cogl-buffer.h> #include <cogl/cogl-buffer.h>
#include <cogl/cogl-pixel-buffer.h> #include <cogl/cogl-pixel-buffer.h>
#include <cogl/cogl-vector.h> #include <cogl/cogl-vector.h>
#include <cogl/cogl-euler.h>
#include <cogl/cogl-quaternion.h> #include <cogl/cogl-quaternion.h>
#include <cogl/cogl-texture-2d.h> #include <cogl/cogl-texture-2d.h>
#include <cogl/cogl-texture-2d-gl.h> #include <cogl/cogl-texture-2d-gl.h>

View File

@ -203,19 +203,6 @@ cogl_error_copy
cogl_error_free cogl_error_free
cogl_error_matches cogl_error_matches
cogl_euler_copy
cogl_euler_equal
cogl_euler_free
#ifdef COGL_HAS_GTYPE_SUPPORT
cogl_euler_get_gtype
#endif
cogl_euler_init
cogl_euler_init_from_matrix
#if 0
/* not yet implemented */
cogl_euler_init_from_quaternion
#endif
cogl_features_available cogl_features_available
cogl_feature_flags_get_type cogl_feature_flags_get_type
cogl_fence_closure_get_user_data cogl_fence_closure_get_user_data

View File

@ -114,7 +114,6 @@ cogl_nonintrospected_headers = [
'cogl-primitive.h', 'cogl-primitive.h',
'cogl-frame-info.h', 'cogl-frame-info.h',
'cogl-vector.h', 'cogl-vector.h',
'cogl-euler.h',
'cogl-output.h', 'cogl-output.h',
'cogl-quaternion.h', 'cogl-quaternion.h',
'cogl-matrix-stack.h', 'cogl-matrix-stack.h',
@ -270,7 +269,6 @@ cogl_sources = [
'cogl-primitive.c', 'cogl-primitive.c',
'cogl-matrix.c', 'cogl-matrix.c',
'cogl-vector.c', 'cogl-vector.c',
'cogl-euler.c',
'cogl-quaternion-private.h', 'cogl-quaternion-private.h',
'cogl-quaternion.c', 'cogl-quaternion.c',
'cogl-matrix-private.h', 'cogl-matrix-private.h',

View File

@ -24,13 +24,13 @@ cogl_mutter_config_h = configure_file(
cogl_pkg_deps = [ cogl_pkg_deps = [
glib_dep, glib_dep,
gobject_dep, gobject_dep,
graphene_dep,
] ]
cogl_pkg_private_deps = [ cogl_pkg_private_deps = [
cairo_dep, cairo_dep,
gmodule_no_export_dep, gmodule_no_export_dep,
gdk_pixbuf_dep, gdk_pixbuf_dep,
graphene_dep,
#uprof_dep, #uprof_dep,
] ]

View File

@ -38,7 +38,7 @@
void void
test_euler_quaternion (void) test_euler_quaternion (void)
{ {
CoglEuler euler; graphene_euler_t euler;
CoglQuaternion quaternion; CoglQuaternion quaternion;
CoglMatrix matrix_a, matrix_b; CoglMatrix matrix_a, matrix_b;
@ -49,7 +49,7 @@ test_euler_quaternion (void)
cogl_matrix_rotate (&matrix_a, 50.0f, 0.0f, 0.0f, 1.0f); cogl_matrix_rotate (&matrix_a, 50.0f, 0.0f, 0.0f, 1.0f);
/* And try the same rotation with a euler */ /* And try the same rotation with a euler */
cogl_euler_init (&euler, -30, 40, 50); graphene_euler_init_with_order (&euler, 40, -30, 50, GRAPHENE_EULER_ORDER_YXZ);
cogl_matrix_init_from_euler (&matrix_b, &euler); cogl_matrix_init_from_euler (&matrix_b, &euler);
/* Verify that the matrices are approximately the same */ /* Verify that the matrices are approximately the same */

View File

@ -341,32 +341,39 @@ get_base_pipeline (MetaShapedTexture *stex,
if (stex->transform != META_MONITOR_TRANSFORM_NORMAL) if (stex->transform != META_MONITOR_TRANSFORM_NORMAL)
{ {
graphene_euler_t euler;
CoglMatrix matrix; CoglMatrix matrix;
CoglEuler euler;
cogl_matrix_init_translation (&matrix, 0.5, 0.5, 0.0); cogl_matrix_init_translation (&matrix, 0.5, 0.5, 0.0);
switch (stex->transform) switch (stex->transform)
{ {
case META_MONITOR_TRANSFORM_90: case META_MONITOR_TRANSFORM_90:
cogl_euler_init (&euler, 0.0, 0.0, 90.0); graphene_euler_init_with_order (&euler, 0.0, 0.0, 90.0,
GRAPHENE_EULER_ORDER_YXZ);
break; break;
case META_MONITOR_TRANSFORM_180: case META_MONITOR_TRANSFORM_180:
cogl_euler_init (&euler, 0.0, 0.0, 180.0); graphene_euler_init_with_order (&euler, 0.0, 0.0, 180.0,
GRAPHENE_EULER_ORDER_YXZ);
break; break;
case META_MONITOR_TRANSFORM_270: case META_MONITOR_TRANSFORM_270:
cogl_euler_init (&euler, 0.0, 0.0, 270.0); graphene_euler_init_with_order (&euler, 0.0, 0.0, 270.0,
GRAPHENE_EULER_ORDER_YXZ);
break; break;
case META_MONITOR_TRANSFORM_FLIPPED: case META_MONITOR_TRANSFORM_FLIPPED:
cogl_euler_init (&euler, 180.0, 0.0, 0.0); graphene_euler_init_with_order (&euler, 0.0, 180.0, 0.0,
GRAPHENE_EULER_ORDER_YXZ);
break; break;
case META_MONITOR_TRANSFORM_FLIPPED_90: case META_MONITOR_TRANSFORM_FLIPPED_90:
cogl_euler_init (&euler, 0.0, 180.0, 90.0); graphene_euler_init_with_order (&euler, 180.0, 0.0, 90.0,
GRAPHENE_EULER_ORDER_YXZ);
break; break;
case META_MONITOR_TRANSFORM_FLIPPED_180: case META_MONITOR_TRANSFORM_FLIPPED_180:
cogl_euler_init (&euler, 180.0, 0.0, 180.0); graphene_euler_init_with_order (&euler, 0.0, 180.0, 180.0,
GRAPHENE_EULER_ORDER_YXZ);
break; break;
case META_MONITOR_TRANSFORM_FLIPPED_270: case META_MONITOR_TRANSFORM_FLIPPED_270:
cogl_euler_init (&euler, 0.0, 180.0, 270.0); graphene_euler_init_with_order (&euler, 180.0, 0.0, 270.0,
GRAPHENE_EULER_ORDER_YXZ);
break; break;
case META_MONITOR_TRANSFORM_NORMAL: case META_MONITOR_TRANSFORM_NORMAL:
g_assert_not_reached (); g_assert_not_reached ();