Replace CoglVector* by graphene_vec*_t
This is an extremely straightforward and minimalistic port of CoglVector APIs to the corresponding Graphene APIs. Make ClutterPlane use graphene_vec3_t internally too, for the simplest purpose of keeping the patch focused. https://gitlab.gnome.org/GNOME/mutter/merge_requests/458
This commit is contained in:
parent
16875340cb
commit
ba0f17f5b1
@ -1097,24 +1097,18 @@ _clutter_paint_volume_cull (ClutterPaintVolume *pv,
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
const ClutterPlane *plane = &planes[i];
|
||||
int out = 0;
|
||||
for (j = 0; j < vertex_count; j++)
|
||||
{
|
||||
ClutterVertex p;
|
||||
float distance;
|
||||
graphene_vec3_t v;
|
||||
|
||||
/* XXX: for perspective projections this can be optimized
|
||||
* out because all the planes should pass through the origin
|
||||
* so (0,0,0) is a valid v0. */
|
||||
p.x = vertices[j].x - planes[i].v0[0];
|
||||
p.y = vertices[j].y - planes[i].v0[1];
|
||||
p.z = vertices[j].z - planes[i].v0[2];
|
||||
graphene_vec3_init (&v,
|
||||
vertices[j].x - graphene_vec3_get_x (&plane->v0),
|
||||
vertices[j].y - graphene_vec3_get_y (&plane->v0),
|
||||
vertices[j].z - graphene_vec3_get_z (&plane->v0));
|
||||
|
||||
distance = (planes[i].n[0] * p.x +
|
||||
planes[i].n[1] * p.y +
|
||||
planes[i].n[2] * p.z);
|
||||
|
||||
if (distance < 0)
|
||||
if (graphene_vec3_dot (&plane->n, &v) < 0)
|
||||
out++;
|
||||
}
|
||||
|
||||
|
@ -292,8 +292,8 @@ PangoDirection _clutter_pango_find_base_dir (const gchar *text,
|
||||
|
||||
typedef struct _ClutterPlane
|
||||
{
|
||||
float v0[3];
|
||||
float n[3];
|
||||
graphene_vec3_t v0;
|
||||
graphene_vec3_t n;
|
||||
} ClutterPlane;
|
||||
|
||||
typedef enum _ClutterCullResult
|
||||
|
@ -715,8 +715,9 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
|
||||
Vector4 *tmp_poly;
|
||||
ClutterPlane *plane;
|
||||
int i;
|
||||
float b[3];
|
||||
float c[3];
|
||||
Vector4 *poly;
|
||||
graphene_vec3_t b;
|
||||
graphene_vec3_t c;
|
||||
int count;
|
||||
|
||||
tmp_poly = g_alloca (sizeof (Vector4) * n_vertices * 2);
|
||||
@ -783,23 +784,37 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
plane = &planes[i];
|
||||
memcpy (plane->v0, tmp_poly + i, sizeof (float) * 3);
|
||||
memcpy (b, tmp_poly + n_vertices + i, sizeof (float) * 3);
|
||||
memcpy (c, tmp_poly + n_vertices + i + 1, sizeof (float) * 3);
|
||||
cogl_vector3_subtract (b, b, plane->v0);
|
||||
cogl_vector3_subtract (c, c, plane->v0);
|
||||
cogl_vector3_cross_product (plane->n, b, c);
|
||||
cogl_vector3_normalize (plane->n);
|
||||
|
||||
poly = &tmp_poly[i];
|
||||
graphene_vec3_init (&plane->v0, poly->x, poly->y, poly->z);
|
||||
|
||||
poly = &tmp_poly[n_vertices + i];
|
||||
graphene_vec3_init (&b, poly->x, poly->y, poly->z);
|
||||
|
||||
poly = &tmp_poly[n_vertices + i + 1];
|
||||
graphene_vec3_init (&c, poly->x, poly->y, poly->z);
|
||||
|
||||
graphene_vec3_subtract (&b, &plane->v0, &b);
|
||||
graphene_vec3_subtract (&c, &plane->v0, &c);
|
||||
graphene_vec3_cross (&b, &c, &plane->n);
|
||||
graphene_vec3_normalize (&plane->n, &plane->n);
|
||||
}
|
||||
|
||||
plane = &planes[n_vertices - 1];
|
||||
memcpy (plane->v0, tmp_poly + 0, sizeof (float) * 3);
|
||||
memcpy (b, tmp_poly + (2 * n_vertices - 1), sizeof (float) * 3);
|
||||
memcpy (c, tmp_poly + n_vertices, sizeof (float) * 3);
|
||||
cogl_vector3_subtract (b, b, plane->v0);
|
||||
cogl_vector3_subtract (c, c, plane->v0);
|
||||
cogl_vector3_cross_product (plane->n, b, c);
|
||||
cogl_vector3_normalize (plane->n);
|
||||
|
||||
poly = &tmp_poly[0];
|
||||
graphene_vec3_init (&plane->v0, poly->x, poly->y, poly->z);
|
||||
|
||||
poly = &tmp_poly[2 * n_vertices - 1];
|
||||
graphene_vec3_init (&b, poly->x, poly->y, poly->z);
|
||||
|
||||
poly = &tmp_poly[n_vertices];
|
||||
graphene_vec3_init (&c, poly->x, poly->y, poly->z);
|
||||
|
||||
graphene_vec3_subtract (&b, &plane->v0, &b);
|
||||
graphene_vec3_subtract (&c, &plane->v0, &c);
|
||||
graphene_vec3_cross (&b, &c, &plane->n);
|
||||
graphene_vec3_normalize (&plane->n, &plane->n);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -75,7 +75,6 @@
|
||||
#include <cogl-debug.h>
|
||||
#include <cogl-matrix.h>
|
||||
#include <cogl-matrix-private.h>
|
||||
#include <cogl-vector.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <math.h>
|
||||
@ -2184,41 +2183,41 @@ cogl_matrix_look_at (CoglMatrix *matrix,
|
||||
float world_up_z)
|
||||
{
|
||||
CoglMatrix tmp;
|
||||
float forward[3];
|
||||
float side[3];
|
||||
float up[3];
|
||||
graphene_vec3_t forward;
|
||||
graphene_vec3_t side;
|
||||
graphene_vec3_t up;
|
||||
|
||||
/* Get a unit viewing direction vector */
|
||||
cogl_vector3_init (forward,
|
||||
object_x - eye_position_x,
|
||||
object_y - eye_position_y,
|
||||
object_z - eye_position_z);
|
||||
cogl_vector3_normalize (forward);
|
||||
graphene_vec3_init (&forward,
|
||||
object_x - eye_position_x,
|
||||
object_y - eye_position_y,
|
||||
object_z - eye_position_z);
|
||||
graphene_vec3_normalize (&forward, &forward);
|
||||
|
||||
cogl_vector3_init (up, world_up_x, world_up_y, world_up_z);
|
||||
graphene_vec3_init (&up, world_up_x, world_up_y, world_up_z);
|
||||
|
||||
/* Take the sideways direction as being perpendicular to the viewing
|
||||
* direction and the word up vector. */
|
||||
cogl_vector3_cross_product (side, forward, up);
|
||||
cogl_vector3_normalize (side);
|
||||
graphene_vec3_cross (&forward, &up, &side);
|
||||
graphene_vec3_normalize (&side, &side);
|
||||
|
||||
/* Now we have unit sideways and forward-direction vectors calculate
|
||||
* a new mutually perpendicular up vector. */
|
||||
cogl_vector3_cross_product (up, side, forward);
|
||||
graphene_vec3_cross (&side, &forward, &up);
|
||||
|
||||
tmp.xx = side[0];
|
||||
tmp.yx = side[1];
|
||||
tmp.zx = side[2];
|
||||
tmp.xx = graphene_vec3_get_x (&side);
|
||||
tmp.yx = graphene_vec3_get_y (&side);
|
||||
tmp.zx = graphene_vec3_get_z (&side);
|
||||
tmp.wx = 0;
|
||||
|
||||
tmp.xy = up[0];
|
||||
tmp.yy = up[1];
|
||||
tmp.zy = up[2];
|
||||
tmp.xy = graphene_vec3_get_x (&up);
|
||||
tmp.yy = graphene_vec3_get_y (&up);
|
||||
tmp.zy = graphene_vec3_get_z (&up);
|
||||
tmp.wy = 0;
|
||||
|
||||
tmp.xz = -forward[0];
|
||||
tmp.yz = -forward[1];
|
||||
tmp.zz = -forward[2];
|
||||
tmp.xz = -graphene_vec3_get_x (&forward);
|
||||
tmp.yz = -graphene_vec3_get_y (&forward);
|
||||
tmp.zz = -graphene_vec3_get_z (&forward);
|
||||
tmp.wz = 0;
|
||||
|
||||
tmp.xw = 0;
|
||||
|
@ -1,298 +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-vector.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#define X 0
|
||||
#define Y 1
|
||||
#define Z 2
|
||||
#define W 3
|
||||
|
||||
void
|
||||
cogl_vector3_init (float *vector, float x, float y, float z)
|
||||
{
|
||||
vector[X] = x;
|
||||
vector[Y] = y;
|
||||
vector[Z] = z;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector3_init_zero (float *vector)
|
||||
{
|
||||
memset (vector, 0, sizeof (float) * 3);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_vector3_equal (const void *v1, const void *v2)
|
||||
{
|
||||
float *vector0 = (float *)v1;
|
||||
float *vector1 = (float *)v2;
|
||||
|
||||
g_return_val_if_fail (v1 != NULL, FALSE);
|
||||
g_return_val_if_fail (v2 != NULL, FALSE);
|
||||
|
||||
/* There's no point picking an arbitrary epsilon that's appropriate
|
||||
* for comparing the components so we just use == that will at least
|
||||
* consider -0 and 0 to be equal. */
|
||||
return
|
||||
vector0[X] == vector1[X] &&
|
||||
vector0[Y] == vector1[Y] &&
|
||||
vector0[Z] == vector1[Z];
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_vector3_equal_with_epsilon (const float *vector0,
|
||||
const float *vector1,
|
||||
float epsilon)
|
||||
{
|
||||
g_return_val_if_fail (vector0 != NULL, FALSE);
|
||||
g_return_val_if_fail (vector1 != NULL, FALSE);
|
||||
|
||||
if (fabsf (vector0[X] - vector1[X]) < epsilon &&
|
||||
fabsf (vector0[Y] - vector1[Y]) < epsilon &&
|
||||
fabsf (vector0[Z] - vector1[Z]) < epsilon)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
float *
|
||||
cogl_vector3_copy (const float *vector)
|
||||
{
|
||||
if (vector)
|
||||
return g_slice_copy (sizeof (float) * 3, vector);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector3_free (float *vector)
|
||||
{
|
||||
g_slice_free1 (sizeof (float) * 3, vector);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector3_invert (float *vector)
|
||||
{
|
||||
vector[X] = -vector[X];
|
||||
vector[Y] = -vector[Y];
|
||||
vector[Z] = -vector[Z];
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector3_add (float *result,
|
||||
const float *a,
|
||||
const float *b)
|
||||
{
|
||||
result[X] = a[X] + b[X];
|
||||
result[Y] = a[Y] + b[Y];
|
||||
result[Z] = a[Z] + b[Z];
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector3_subtract (float *result,
|
||||
const float *a,
|
||||
const float *b)
|
||||
{
|
||||
result[X] = a[X] - b[X];
|
||||
result[Y] = a[Y] - b[Y];
|
||||
result[Z] = a[Z] - b[Z];
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector3_multiply_scalar (float *vector,
|
||||
float scalar)
|
||||
{
|
||||
vector[X] *= scalar;
|
||||
vector[Y] *= scalar;
|
||||
vector[Z] *= scalar;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector3_divide_scalar (float *vector,
|
||||
float scalar)
|
||||
{
|
||||
float one_over_scalar = 1.0f / scalar;
|
||||
vector[X] *= one_over_scalar;
|
||||
vector[Y] *= one_over_scalar;
|
||||
vector[Z] *= one_over_scalar;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector3_normalize (float *vector)
|
||||
{
|
||||
float mag_squared =
|
||||
vector[X] * vector[X] +
|
||||
vector[Y] * vector[Y] +
|
||||
vector[Z] * vector[Z];
|
||||
|
||||
if (mag_squared > 0.0f)
|
||||
{
|
||||
float one_over_mag = 1.0f / sqrtf (mag_squared);
|
||||
vector[X] *= one_over_mag;
|
||||
vector[Y] *= one_over_mag;
|
||||
vector[Z] *= one_over_mag;
|
||||
}
|
||||
}
|
||||
|
||||
float
|
||||
cogl_vector3_magnitude (const float *vector)
|
||||
{
|
||||
return sqrtf (vector[X] * vector[X] +
|
||||
vector[Y] * vector[Y] +
|
||||
vector[Z] * vector[Z]);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector3_cross_product (float *result,
|
||||
const float *a,
|
||||
const float *b)
|
||||
{
|
||||
float tmp[3];
|
||||
|
||||
tmp[X] = a[Y] * b[Z] - a[Z] * b[Y];
|
||||
tmp[Y] = a[Z] * b[X] - a[X] * b[Z];
|
||||
tmp[Z] = a[X] * b[Y] - a[Y] * b[X];
|
||||
result[X] = tmp[X];
|
||||
result[Y] = tmp[Y];
|
||||
result[Z] = tmp[Z];
|
||||
}
|
||||
|
||||
float
|
||||
cogl_vector3_dot_product (const float *a, const float *b)
|
||||
{
|
||||
return a[X] * b[X] + a[Y] * b[Y] + a[Z] * b[Z];
|
||||
}
|
||||
|
||||
float
|
||||
cogl_vector3_distance (const float *a, const float *b)
|
||||
{
|
||||
float dx = b[X] - a[X];
|
||||
float dy = b[Y] - a[Y];
|
||||
float dz = b[Z] - a[Z];
|
||||
|
||||
return sqrtf (dx * dx + dy * dy + dz * dz);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void
|
||||
cogl_vector4_init (float *vector, float x, float y, float z)
|
||||
{
|
||||
vector[X] = x;
|
||||
vector[Y] = y;
|
||||
vector[Z] = z;
|
||||
vector[W] = w;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector4_init_zero (float *vector)
|
||||
{
|
||||
memset (vector, 0, sizeof (CoglVector4));
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector4_init_from_vector4 (float *vector, float *src)
|
||||
{
|
||||
*vector4 = *src;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_vector4_equal (const void *v0, const void *v1)
|
||||
{
|
||||
g_return_val_if_fail (v1 != NULL, FALSE);
|
||||
g_return_val_if_fail (v2 != NULL, FALSE);
|
||||
|
||||
return memcmp (v1, v2, sizeof (float) * 4) == 0 ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
float *
|
||||
cogl_vector4_copy (float *vector)
|
||||
{
|
||||
if (vector)
|
||||
return g_slice_dup (CoglVector4, vector);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector4_free (float *vector)
|
||||
{
|
||||
g_slice_free (CoglVector4, vector);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector4_invert (float *vector)
|
||||
{
|
||||
vector.x = -vector.x;
|
||||
vector.y = -vector.y;
|
||||
vector.z = -vector.z;
|
||||
vector.w = -vector.w;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector4_add (float *result,
|
||||
float *a,
|
||||
float *b)
|
||||
{
|
||||
result.x = a.x + b.x;
|
||||
result.y = a.y + b.y;
|
||||
result.z = a.z + b.z;
|
||||
result.w = a.w + b.w;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector4_subtract (float *result,
|
||||
float *a,
|
||||
float *b)
|
||||
{
|
||||
result.x = a.x - b.x;
|
||||
result.y = a.y - b.y;
|
||||
result.z = a.z - b.z;
|
||||
result.w = a.w - b.w;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vector4_divide (float *vector,
|
||||
float scalar)
|
||||
{
|
||||
float one_over_scalar = 1.0f / scalar;
|
||||
result.x *= one_over_scalar;
|
||||
result.y *= one_over_scalar;
|
||||
result.z *= one_over_scalar;
|
||||
result.w *= one_over_scalar;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,356 +0,0 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* A Low Level GPU Graphics and Utilities API
|
||||
*
|
||||
* Copyright (C) 2008,2009,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_VECTOR_H
|
||||
#define __COGL_VECTOR_H
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-vector
|
||||
* @short_description: Functions for handling single precision float
|
||||
* vectors.
|
||||
*
|
||||
* This exposes a utility API that can be used for basic manipulation of 3
|
||||
* component float vectors.
|
||||
*/
|
||||
|
||||
/**
|
||||
* cogl_vector3_init:
|
||||
* @vector: The 3 component vector you want to initialize
|
||||
* @x: The x component
|
||||
* @y: The y component
|
||||
* @z: The z component
|
||||
*
|
||||
* Initializes a 3 component, single precision float vector which can
|
||||
* then be manipulated with the cogl_vector convenience APIs. Vectors
|
||||
* can also be used in places where a "point" is often desired.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_vector3_init (float *vector, float x, float y, float z);
|
||||
|
||||
/**
|
||||
* cogl_vector3_init_zero:
|
||||
* @vector: The 3 component vector you want to initialize
|
||||
*
|
||||
* Initializes a 3 component, single precision float vector with zero
|
||||
* for each component.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_vector3_init_zero (float *vector);
|
||||
|
||||
/**
|
||||
* cogl_vector3_equal:
|
||||
* @v1: The first 3 component vector you want to compare
|
||||
* @v2: The second 3 component vector you want to compare
|
||||
*
|
||||
* Compares the components of two vectors and returns TRUE if they are
|
||||
* the same.
|
||||
*
|
||||
* The comparison of the components is done with the '==' operator
|
||||
* such that -0 is considered equal to 0, but otherwise there is no
|
||||
* fuzziness such as an epsilon to consider vectors that are
|
||||
* essentially identical except for some minor precision error
|
||||
* differences due to the way they have been manipulated.
|
||||
*
|
||||
* Returns: TRUE if the vectors are equal else FALSE.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
gboolean
|
||||
cogl_vector3_equal (const void *v1, const void *v2);
|
||||
|
||||
/**
|
||||
* cogl_vector3_equal_with_epsilon:
|
||||
* @vector0: The first 3 component vector you want to compare
|
||||
* @vector1: The second 3 component vector you want to compare
|
||||
* @epsilon: The allowable difference between components to still be
|
||||
* considered equal
|
||||
*
|
||||
* Compares the components of two vectors using the given epsilon and
|
||||
* returns TRUE if they are the same, using an internal epsilon for
|
||||
* comparing the floats.
|
||||
*
|
||||
* Each component is compared against the epsilon value in this way:
|
||||
* |[
|
||||
* if (fabsf (vector0->x - vector1->x) < epsilon)
|
||||
* ]|
|
||||
*
|
||||
* Returns: TRUE if the vectors are equal else FALSE.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
gboolean
|
||||
cogl_vector3_equal_with_epsilon (const float *vector0,
|
||||
const float *vector1,
|
||||
float epsilon);
|
||||
|
||||
/**
|
||||
* cogl_vector3_copy:
|
||||
* @vector: The 3 component vector you want to copy
|
||||
*
|
||||
* Allocates a new 3 component float vector on the heap initializing
|
||||
* the components from the given @vector and returns a pointer to the
|
||||
* newly allocated vector. You should free the memory using
|
||||
* cogl_vector3_free()
|
||||
*
|
||||
* Returns: A newly allocated 3 component float vector
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
float *
|
||||
cogl_vector3_copy (const float *vector);
|
||||
|
||||
/**
|
||||
* cogl_vector3_free:
|
||||
* @vector: The 3 component you want to free
|
||||
*
|
||||
* Frees a 3 component vector that was previously allocated with
|
||||
* cogl_vector3_copy()
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_vector3_free (float *vector);
|
||||
|
||||
/**
|
||||
* cogl_vector3_invert:
|
||||
* @vector: The 3 component vector you want to manipulate
|
||||
*
|
||||
* Inverts/negates all the components of the given @vector.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_vector3_invert (float *vector);
|
||||
|
||||
/**
|
||||
* cogl_vector3_add:
|
||||
* @result: Where you want the result written
|
||||
* @a: The first vector operand
|
||||
* @b: The second vector operand
|
||||
*
|
||||
* Adds each of the corresponding components in vectors @a and @b
|
||||
* storing the results in @result.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_vector3_add (float *result,
|
||||
const float *a,
|
||||
const float *b);
|
||||
|
||||
/**
|
||||
* cogl_vector3_subtract:
|
||||
* @result: Where you want the result written
|
||||
* @a: The first vector operand
|
||||
* @b: The second vector operand
|
||||
*
|
||||
* Subtracts each of the corresponding components in vector @b from
|
||||
* @a storing the results in @result.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_vector3_subtract (float *result,
|
||||
const float *a,
|
||||
const float *b);
|
||||
|
||||
/**
|
||||
* cogl_vector3_multiply_scalar:
|
||||
* @vector: The 3 component vector you want to manipulate
|
||||
* @scalar: The scalar you want to multiply the vector components by
|
||||
*
|
||||
* Multiplies each of the @vector components by the given scalar.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_vector3_multiply_scalar (float *vector,
|
||||
float scalar);
|
||||
|
||||
/**
|
||||
* cogl_vector3_divide_scalar:
|
||||
* @vector: The 3 component vector you want to manipulate
|
||||
* @scalar: The scalar you want to divide the vector components by
|
||||
*
|
||||
* Divides each of the @vector components by the given scalar.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_vector3_divide_scalar (float *vector,
|
||||
float scalar);
|
||||
|
||||
/**
|
||||
* cogl_vector3_normalize:
|
||||
* @vector: The 3 component vector you want to manipulate
|
||||
*
|
||||
* Updates the vector so it is a "unit vector" such that the
|
||||
* @vector<!-- -->s magnitude or length is equal to 1.
|
||||
*
|
||||
* <note>It's safe to use this function with the [0, 0, 0] vector, it will not
|
||||
* try to divide components by 0 (its norm) and will leave the vector
|
||||
* untouched.</note>
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_vector3_normalize (float *vector);
|
||||
|
||||
/**
|
||||
* cogl_vector3_magnitude:
|
||||
* @vector: The 3 component vector you want the magnitude for
|
||||
*
|
||||
* Calculates the scalar magnitude or length of @vector.
|
||||
*
|
||||
* Returns: The magnitude of @vector.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
float
|
||||
cogl_vector3_magnitude (const float *vector);
|
||||
|
||||
/**
|
||||
* cogl_vector3_cross_product:
|
||||
* @result: Where you want the result written
|
||||
* @u: Your first 3 component vector
|
||||
* @v: Your second 3 component vector
|
||||
*
|
||||
* Calculates the cross product between the two vectors @u and @v.
|
||||
*
|
||||
* The cross product is a vector perpendicular to both @u and @v. This
|
||||
* can be useful for calculating the normal of a polygon by creating
|
||||
* two vectors in its plane using the polygons vertices and taking
|
||||
* their cross product.
|
||||
*
|
||||
* If the two vectors are parallel then the cross product is 0.
|
||||
*
|
||||
* You can use a right hand rule to determine which direction the
|
||||
* perpendicular vector will point: If you place the two vectors tail,
|
||||
* to tail and imagine grabbing the perpendicular line that extends
|
||||
* through the common tail with your right hand such that you fingers
|
||||
* rotate in the direction from @u to @v then the resulting vector
|
||||
* points along your extended thumb.
|
||||
*
|
||||
* Returns: The cross product between two vectors @u and @v.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_vector3_cross_product (float *result,
|
||||
const float *u,
|
||||
const float *v);
|
||||
|
||||
/**
|
||||
* cogl_vector3_dot_product:
|
||||
* @a: Your first 3 component vector
|
||||
* @b: Your second 3 component vector
|
||||
*
|
||||
* Calculates the dot product of the two 3 component vectors. This
|
||||
* can be used to determine the magnitude of one vector projected onto
|
||||
* another. (for example a surface normal)
|
||||
*
|
||||
* For example if you have a polygon with a given normal vector and
|
||||
* some other point for which you want to calculate its distance from
|
||||
* the polygon, you can create a vector between one of the polygon
|
||||
* vertices and that point and use the dot product to calculate the
|
||||
* magnitude for that vector but projected onto the normal of the
|
||||
* polygon. This way you don't just get the distance from the point to
|
||||
* the edge of the polygon you get the distance from the point to the
|
||||
* nearest part of the polygon.
|
||||
*
|
||||
* <note>If you don't use a unit length normal in the above example
|
||||
* then you would then also have to divide the result by the magnitude
|
||||
* of the normal</note>
|
||||
*
|
||||
* The dot product is calculated as:
|
||||
* |[
|
||||
* (a->x * b->x + a->y * b->y + a->z * b->z)
|
||||
* ]|
|
||||
*
|
||||
* For reference, the dot product can also be calculated from the
|
||||
* angle between two vectors as:
|
||||
* |[
|
||||
* |a||b|cos𝜃
|
||||
* ]|
|
||||
*
|
||||
* Returns: The dot product of two vectors.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
float
|
||||
cogl_vector3_dot_product (const float *a, const float *b);
|
||||
|
||||
/**
|
||||
* cogl_vector3_distance:
|
||||
* @a: The first point
|
||||
* @b: The second point
|
||||
*
|
||||
* If you consider the two given vectors as (x,y,z) points instead
|
||||
* then this will compute the distance between those two points.
|
||||
*
|
||||
* Returns: The distance between two points given as 3 component
|
||||
* vectors.
|
||||
*
|
||||
* Since: 1.4
|
||||
* Stability: Unstable
|
||||
*/
|
||||
float
|
||||
cogl_vector3_distance (const float *a, const float *b);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_VECTOR_H */
|
||||
|
@ -101,7 +101,6 @@
|
||||
#include <cogl/cogl-context.h>
|
||||
#include <cogl/cogl-buffer.h>
|
||||
#include <cogl/cogl-pixel-buffer.h>
|
||||
#include <cogl/cogl-vector.h>
|
||||
#include <cogl/cogl-texture-2d.h>
|
||||
#include <cogl/cogl-texture-2d-gl.h>
|
||||
#include <cogl/cogl-texture-2d-sliced.h>
|
||||
|
@ -885,23 +885,6 @@ cogl_texture_2d_sliced_new_with_size
|
||||
cogl_transform
|
||||
cogl_translate
|
||||
|
||||
cogl_vector3_add
|
||||
cogl_vector3_copy
|
||||
cogl_vector3_cross_product
|
||||
cogl_vector3_distance
|
||||
cogl_vector3_divide_scalar
|
||||
cogl_vector3_dot_product
|
||||
cogl_vector3_equal
|
||||
cogl_vector3_equal_with_epsilon
|
||||
cogl_vector3_free
|
||||
cogl_vector3_init
|
||||
cogl_vector3_init_zero
|
||||
cogl_vector3_invert
|
||||
cogl_vector3_magnitude
|
||||
cogl_vector3_multiply_scalar
|
||||
cogl_vector3_normalize
|
||||
cogl_vector3_subtract
|
||||
|
||||
cogl_vertex_buffer_add
|
||||
cogl_vertex_buffer_delete
|
||||
cogl_vertex_buffer_disable
|
||||
|
@ -112,7 +112,6 @@ cogl_nonintrospected_headers = [
|
||||
'cogl-attribute.h',
|
||||
'cogl-primitive.h',
|
||||
'cogl-frame-info.h',
|
||||
'cogl-vector.h',
|
||||
'cogl-output.h',
|
||||
'cogl-matrix-stack.h',
|
||||
'cogl-poll.h',
|
||||
@ -264,7 +263,6 @@ cogl_sources = [
|
||||
'cogl-primitive-private.h',
|
||||
'cogl-primitive.c',
|
||||
'cogl-matrix.c',
|
||||
'cogl-vector.c',
|
||||
'cogl-matrix-private.h',
|
||||
'cogl-matrix-stack.c',
|
||||
'cogl-matrix-stack-private.h',
|
||||
|
Loading…
Reference in New Issue
Block a user