mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 16:10:41 -05:00
Remove CoglVector3 type and use float * instead
It proved to be inconvenient that we had a special CoglVector3 typedef for vectors instead of just accepting pointers to float arrays because you'd so often end up having to make awkward casts from another vector type into a CoglVector3 and then cast back again. We're hoping that taking float pointers instead will lead to less unnecessary casting.
This commit is contained in:
parent
2b351af46a
commit
e163f1ca1a
@ -2085,41 +2085,41 @@ cogl_matrix_look_at (CoglMatrix *matrix,
|
|||||||
float world_up_z)
|
float world_up_z)
|
||||||
{
|
{
|
||||||
CoglMatrix tmp;
|
CoglMatrix tmp;
|
||||||
CoglVector3 forward;
|
float forward[3];
|
||||||
CoglVector3 side;
|
float side[3];
|
||||||
CoglVector3 up;
|
float up[3];
|
||||||
|
|
||||||
/* Get a unit viewing direction vector */
|
/* Get a unit viewing direction vector */
|
||||||
cogl_vector3_init (&forward,
|
cogl_vector3_init (forward,
|
||||||
object_x - eye_position_x,
|
object_x - eye_position_x,
|
||||||
object_y - eye_position_y,
|
object_y - eye_position_y,
|
||||||
object_z - eye_position_z);
|
object_z - eye_position_z);
|
||||||
cogl_vector3_normalize (&forward);
|
cogl_vector3_normalize (forward);
|
||||||
|
|
||||||
cogl_vector3_init (&up, world_up_x, world_up_y, world_up_z);
|
cogl_vector3_init (up, world_up_x, world_up_y, world_up_z);
|
||||||
|
|
||||||
/* Take the sideways direction as being perpendicular to the viewing
|
/* Take the sideways direction as being perpendicular to the viewing
|
||||||
* direction and the word up vector. */
|
* direction and the word up vector. */
|
||||||
cogl_vector3_cross_product (&side, &forward, &up);
|
cogl_vector3_cross_product (side, forward, up);
|
||||||
cogl_vector3_normalize (&side);
|
cogl_vector3_normalize (side);
|
||||||
|
|
||||||
/* Now we have unit sideways and forward-direction vectors calculate
|
/* Now we have unit sideways and forward-direction vectors calculate
|
||||||
* a new mutually perpendicular up vector. */
|
* a new mutually perpendicular up vector. */
|
||||||
cogl_vector3_cross_product (&up, &side, &forward);
|
cogl_vector3_cross_product (up, side, forward);
|
||||||
|
|
||||||
tmp.xx = side.x;
|
tmp.xx = side[0];
|
||||||
tmp.yx = side.y;
|
tmp.yx = side[1];
|
||||||
tmp.zx = side.z;
|
tmp.zx = side[2];
|
||||||
tmp.wx = 0;
|
tmp.wx = 0;
|
||||||
|
|
||||||
tmp.xy = up.x;
|
tmp.xy = up[0];
|
||||||
tmp.yy = up.y;
|
tmp.yy = up[1];
|
||||||
tmp.zy = up.z;
|
tmp.zy = up[2];
|
||||||
tmp.wy = 0;
|
tmp.wy = 0;
|
||||||
|
|
||||||
tmp.xz = -forward.x;
|
tmp.xz = -forward[0];
|
||||||
tmp.yz = -forward.y;
|
tmp.yz = -forward[1];
|
||||||
tmp.zz = -forward.z;
|
tmp.zz = -forward[2];
|
||||||
tmp.wz = 0;
|
tmp.wz = 0;
|
||||||
|
|
||||||
tmp.xw = 0;
|
tmp.xw = 0;
|
||||||
|
@ -74,36 +74,38 @@ cogl_quaternion_init (CoglQuaternion *quaternion,
|
|||||||
float y,
|
float y,
|
||||||
float z)
|
float z)
|
||||||
{
|
{
|
||||||
CoglVector3 axis = { x, y, z};
|
float axis[3] = { x, y, z};
|
||||||
cogl_quaternion_init_from_angle_vector (quaternion, angle, &axis);
|
cogl_quaternion_init_from_angle_vector (quaternion, angle, axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_quaternion_init_from_angle_vector (CoglQuaternion *quaternion,
|
cogl_quaternion_init_from_angle_vector (CoglQuaternion *quaternion,
|
||||||
float angle,
|
float angle,
|
||||||
const CoglVector3 *axis_in)
|
const float *axis3f_in)
|
||||||
{
|
{
|
||||||
/* 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 )]
|
||||||
*/
|
*/
|
||||||
CoglVector3 axis;
|
float axis[3];
|
||||||
float half_angle;
|
float half_angle;
|
||||||
float sin_half_angle;
|
float sin_half_angle;
|
||||||
|
|
||||||
/* XXX: Should we make cogl_vector3_normalize have separate in and
|
/* XXX: Should we make cogl_vector3_normalize have separate in and
|
||||||
* out args? */
|
* out args? */
|
||||||
axis = *axis_in;
|
axis[0] = axis3f_in[0];
|
||||||
cogl_vector3_normalize (&axis);
|
axis[1] = axis3f_in[1];
|
||||||
|
axis[2] = axis3f_in[2];
|
||||||
|
cogl_vector3_normalize (axis);
|
||||||
|
|
||||||
half_angle = angle * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f;
|
half_angle = angle * _COGL_QUATERNION_DEGREES_TO_RADIANS * 0.5f;
|
||||||
sin_half_angle = sinf (half_angle);
|
sin_half_angle = sinf (half_angle);
|
||||||
|
|
||||||
quaternion->w = cosf (half_angle);
|
quaternion->w = cosf (half_angle);
|
||||||
|
|
||||||
quaternion->x = axis.x * sin_half_angle;
|
quaternion->x = axis[0] * sin_half_angle;
|
||||||
quaternion->y = axis.y * sin_half_angle;
|
quaternion->y = axis[1] * sin_half_angle;
|
||||||
quaternion->z = axis.z * sin_half_angle;
|
quaternion->z = axis[2] * sin_half_angle;
|
||||||
|
|
||||||
cogl_quaternion_normalize (quaternion);
|
cogl_quaternion_normalize (quaternion);
|
||||||
}
|
}
|
||||||
@ -365,7 +367,7 @@ cogl_quaternion_get_rotation_angle (const CoglQuaternion *quaternion)
|
|||||||
|
|
||||||
void
|
void
|
||||||
cogl_quaternion_get_rotation_axis (const CoglQuaternion *quaternion,
|
cogl_quaternion_get_rotation_axis (const CoglQuaternion *quaternion,
|
||||||
CoglVector3 *vector)
|
float *vector3)
|
||||||
{
|
{
|
||||||
float sin_half_angle_sqr;
|
float sin_half_angle_sqr;
|
||||||
float one_over_sin_angle_over_2;
|
float one_over_sin_angle_over_2;
|
||||||
@ -383,18 +385,18 @@ cogl_quaternion_get_rotation_axis (const CoglQuaternion *quaternion,
|
|||||||
{
|
{
|
||||||
/* Either an identity quaternion or numerical imprecision.
|
/* Either an identity quaternion or numerical imprecision.
|
||||||
* Either way we return an arbitrary vector. */
|
* Either way we return an arbitrary vector. */
|
||||||
vector->x = 1;
|
vector3[0] = 1;
|
||||||
vector->y = 0;
|
vector3[1] = 0;
|
||||||
vector->z = 0;
|
vector3[2] = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate 1 / sin(𝜃/2) */
|
/* Calculate 1 / sin(𝜃/2) */
|
||||||
one_over_sin_angle_over_2 = 1.0f / sqrtf (sin_half_angle_sqr);
|
one_over_sin_angle_over_2 = 1.0f / sqrtf (sin_half_angle_sqr);
|
||||||
|
|
||||||
vector->x = quaternion->x * one_over_sin_angle_over_2;
|
vector3[0] = quaternion->x * one_over_sin_angle_over_2;
|
||||||
vector->y = quaternion->y * one_over_sin_angle_over_2;
|
vector3[1] = quaternion->y * one_over_sin_angle_over_2;
|
||||||
vector->z = quaternion->z * one_over_sin_angle_over_2;
|
vector3[2] = quaternion->z * one_over_sin_angle_over_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -164,7 +164,7 @@ cogl_quaternion_init (CoglQuaternion *quaternion,
|
|||||||
/**
|
/**
|
||||||
* cogl_quaternion_init_from_angle_vector:
|
* cogl_quaternion_init_from_angle_vector:
|
||||||
* @quaternion: An uninitialized #CoglQuaternion
|
* @quaternion: An uninitialized #CoglQuaternion
|
||||||
* @axis: your axis vector about which you want to rotate.
|
* @axis: your 3 component axis vector about which you want to rotate.
|
||||||
*
|
*
|
||||||
* Initializes a quaternion that rotates @angle degrees around the
|
* Initializes a quaternion that rotates @angle degrees around the
|
||||||
* given @axis vector. The axis vector does not need to be
|
* given @axis vector. The axis vector does not need to be
|
||||||
@ -178,7 +178,7 @@ cogl_quaternion_init (CoglQuaternion *quaternion,
|
|||||||
void
|
void
|
||||||
cogl_quaternion_init_from_angle_vector (CoglQuaternion *quaternion,
|
cogl_quaternion_init_from_angle_vector (CoglQuaternion *quaternion,
|
||||||
float angle,
|
float angle,
|
||||||
const CoglVector3 *axis);
|
const float *axis3f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_quaternion_init_identity:
|
* cogl_quaternion_init_identity:
|
||||||
@ -316,7 +316,7 @@ cogl_quaternion_get_rotation_angle (const CoglQuaternion *quaternion);
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_quaternion_get_rotation_axis (const CoglQuaternion *quaternion,
|
cogl_quaternion_get_rotation_axis (const CoglQuaternion *quaternion,
|
||||||
CoglVector3 *vector);
|
float *vector3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_quaternion_normalize:
|
* cogl_quaternion_normalize:
|
||||||
|
@ -32,25 +32,30 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define X 0
|
||||||
|
#define Y 1
|
||||||
|
#define Z 2
|
||||||
|
#define W 3
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector3_init (CoglVector3 *vector, float x, float y, float z)
|
cogl_vector3_init (float *vector, float x, float y, float z)
|
||||||
{
|
{
|
||||||
vector->x = x;
|
vector[X] = x;
|
||||||
vector->y = y;
|
vector[Y] = y;
|
||||||
vector->z = z;
|
vector[Z] = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector3_init_zero (CoglVector3 *vector)
|
cogl_vector3_init_zero (float *vector)
|
||||||
{
|
{
|
||||||
memset (vector, 0, sizeof (CoglVector3));
|
memset (vector, 0, sizeof (float) * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
cogl_vector3_equal (gconstpointer v1, gconstpointer v2)
|
cogl_vector3_equal (gconstpointer v1, gconstpointer v2)
|
||||||
{
|
{
|
||||||
CoglVector3 *vector0 = (CoglVector3 *)v1;
|
float *vector0 = (float *)v1;
|
||||||
CoglVector3 *vector1 = (CoglVector3 *)v2;
|
float *vector1 = (float *)v2;
|
||||||
|
|
||||||
_COGL_RETURN_VAL_IF_FAIL (v1 != NULL, FALSE);
|
_COGL_RETURN_VAL_IF_FAIL (v1 != NULL, FALSE);
|
||||||
_COGL_RETURN_VAL_IF_FAIL (v2 != NULL, FALSE);
|
_COGL_RETURN_VAL_IF_FAIL (v2 != NULL, FALSE);
|
||||||
@ -59,160 +64,162 @@ cogl_vector3_equal (gconstpointer v1, gconstpointer v2)
|
|||||||
* for comparing the components so we just use == that will at least
|
* for comparing the components so we just use == that will at least
|
||||||
* consider -0 and 0 to be equal. */
|
* consider -0 and 0 to be equal. */
|
||||||
return
|
return
|
||||||
vector0->x == vector1->x &&
|
vector0[X] == vector1[X] &&
|
||||||
vector0->y == vector1->y &&
|
vector0[Y] == vector1[Y] &&
|
||||||
vector0->z == vector1->z;
|
vector0[Z] == vector1[Z];
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
cogl_vector3_equal_with_epsilon (const CoglVector3 *vector0,
|
cogl_vector3_equal_with_epsilon (const float *vector0,
|
||||||
const CoglVector3 *vector1,
|
const float *vector1,
|
||||||
float epsilon)
|
float epsilon)
|
||||||
{
|
{
|
||||||
_COGL_RETURN_VAL_IF_FAIL (vector0 != NULL, FALSE);
|
_COGL_RETURN_VAL_IF_FAIL (vector0 != NULL, FALSE);
|
||||||
_COGL_RETURN_VAL_IF_FAIL (vector1 != NULL, FALSE);
|
_COGL_RETURN_VAL_IF_FAIL (vector1 != NULL, FALSE);
|
||||||
|
|
||||||
if (fabsf (vector0->x - vector1->x) < epsilon &&
|
if (fabsf (vector0[X] - vector1[X]) < epsilon &&
|
||||||
fabsf (vector0->y - vector1->y) < epsilon &&
|
fabsf (vector0[Y] - vector1[Y]) < epsilon &&
|
||||||
fabsf (vector0->z - vector1->z) < epsilon)
|
fabsf (vector0[Z] - vector1[Z]) < epsilon)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoglVector3 *
|
float *
|
||||||
cogl_vector3_copy (const CoglVector3 *vector)
|
cogl_vector3_copy (const float *vector)
|
||||||
{
|
{
|
||||||
if (vector)
|
if (vector)
|
||||||
return g_slice_dup (CoglVector3, vector);
|
return g_slice_copy (sizeof (float) * 3, vector);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector3_free (CoglVector3 *vector)
|
cogl_vector3_free (float *vector)
|
||||||
{
|
{
|
||||||
g_slice_free (CoglVector3, vector);
|
g_slice_free1 (sizeof (float) * 3, vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector3_invert (CoglVector3 *vector)
|
cogl_vector3_invert (float *vector)
|
||||||
{
|
{
|
||||||
vector->x = -vector->x;
|
vector[X] = -vector[X];
|
||||||
vector->y = -vector->y;
|
vector[Y] = -vector[Y];
|
||||||
vector->z = -vector->z;
|
vector[Z] = -vector[Z];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector3_add (CoglVector3 *result,
|
cogl_vector3_add (float *result,
|
||||||
const CoglVector3 *a,
|
const float *a,
|
||||||
const CoglVector3 *b)
|
const float *b)
|
||||||
{
|
{
|
||||||
result->x = a->x + b->x;
|
result[X] = a[X] + b[X];
|
||||||
result->y = a->y + b->y;
|
result[Y] = a[Y] + b[Y];
|
||||||
result->z = a->z + b->z;
|
result[Z] = a[Z] + b[Z];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector3_subtract (CoglVector3 *result,
|
cogl_vector3_subtract (float *result,
|
||||||
const CoglVector3 *a,
|
const float *a,
|
||||||
const CoglVector3 *b)
|
const float *b)
|
||||||
{
|
{
|
||||||
result->x = a->x - b->x;
|
result[X] = a[X] - b[X];
|
||||||
result->y = a->y - b->y;
|
result[Y] = a[Y] - b[Y];
|
||||||
result->z = a->z - b->z;
|
result[Z] = a[Z] - b[Z];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector3_multiply_scalar (CoglVector3 *vector,
|
cogl_vector3_multiply_scalar (float *vector,
|
||||||
float scalar)
|
float scalar)
|
||||||
{
|
{
|
||||||
vector->x *= scalar;
|
vector[X] *= scalar;
|
||||||
vector->y *= scalar;
|
vector[Y] *= scalar;
|
||||||
vector->z *= scalar;
|
vector[Z] *= scalar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector3_divide_scalar (CoglVector3 *vector,
|
cogl_vector3_divide_scalar (float *vector,
|
||||||
float scalar)
|
float scalar)
|
||||||
{
|
{
|
||||||
float one_over_scalar = 1.0f / scalar;
|
float one_over_scalar = 1.0f / scalar;
|
||||||
vector->x *= one_over_scalar;
|
vector[X] *= one_over_scalar;
|
||||||
vector->y *= one_over_scalar;
|
vector[Y] *= one_over_scalar;
|
||||||
vector->z *= one_over_scalar;
|
vector[Z] *= one_over_scalar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector3_normalize (CoglVector3 *vector)
|
cogl_vector3_normalize (float *vector)
|
||||||
{
|
{
|
||||||
float mag_squared =
|
float mag_squared =
|
||||||
vector->x * vector->x +
|
vector[X] * vector[X] +
|
||||||
vector->y * vector->y +
|
vector[Y] * vector[Y] +
|
||||||
vector->z * vector->z;
|
vector[Z] * vector[Z];
|
||||||
|
|
||||||
if (mag_squared > 0.0f)
|
if (mag_squared > 0.0f)
|
||||||
{
|
{
|
||||||
float one_over_mag = 1.0f / sqrtf (mag_squared);
|
float one_over_mag = 1.0f / sqrtf (mag_squared);
|
||||||
vector->x *= one_over_mag;
|
vector[X] *= one_over_mag;
|
||||||
vector->y *= one_over_mag;
|
vector[Y] *= one_over_mag;
|
||||||
vector->z *= one_over_mag;
|
vector[Z] *= one_over_mag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
cogl_vector3_magnitude (const CoglVector3 *vector)
|
cogl_vector3_magnitude (const float *vector)
|
||||||
{
|
{
|
||||||
return sqrtf (vector->x * vector->x +
|
return sqrtf (vector[X] * vector[X] +
|
||||||
vector->y * vector->y +
|
vector[Y] * vector[Y] +
|
||||||
vector->z * vector->z);
|
vector[Z] * vector[Z]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector3_cross_product (CoglVector3 *result,
|
cogl_vector3_cross_product (float *result,
|
||||||
const CoglVector3 *a,
|
const float *a,
|
||||||
const CoglVector3 *b)
|
const float *b)
|
||||||
{
|
{
|
||||||
CoglVector3 tmp;
|
float tmp[3];
|
||||||
|
|
||||||
tmp.x = a->y * b->z - a->z * b->y;
|
tmp[X] = a[Y] * b[Z] - a[Z] * b[Y];
|
||||||
tmp.y = a->z * b->x - a->x * b->z;
|
tmp[Y] = a[Z] * b[X] - a[X] * b[Z];
|
||||||
tmp.z = a->x * b->y - a->y * b->x;
|
tmp[Z] = a[X] * b[Y] - a[Y] * b[X];
|
||||||
*result = tmp;
|
result[X] = tmp[X];
|
||||||
|
result[Y] = tmp[Y];
|
||||||
|
result[Z] = tmp[Z];
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
cogl_vector3_dot_product (const CoglVector3 *a, const CoglVector3 *b)
|
cogl_vector3_dot_product (const float *a, const float *b)
|
||||||
{
|
{
|
||||||
return a->x * b->x + a->y * b->y + a->z * b->z;
|
return a[X] * b[X] + a[Y] * b[Y] + a[Z] * b[Z];
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
cogl_vector3_distance (const CoglVector3 *a, const CoglVector3 *b)
|
cogl_vector3_distance (const float *a, const float *b)
|
||||||
{
|
{
|
||||||
float dx = b->x - a->x;
|
float dx = b[X] - a[X];
|
||||||
float dy = b->y - a->y;
|
float dy = b[Y] - a[Y];
|
||||||
float dz = b->z - a->z;
|
float dz = b[Z] - a[Z];
|
||||||
|
|
||||||
return sqrtf (dx * dx + dy * dy + dz * dz);
|
return sqrtf (dx * dx + dy * dy + dz * dz);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
void
|
void
|
||||||
cogl_vector4_init (CoglVector4 *vector, float x, float y, float z)
|
cogl_vector4_init (float *vector, float x, float y, float z)
|
||||||
{
|
{
|
||||||
vector->x = x;
|
vector[X] = x;
|
||||||
vector->y = y;
|
vector[Y] = y;
|
||||||
vector->z = z;
|
vector[Z] = z;
|
||||||
vector->w = w;
|
vector[W] = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector4_init_zero (CoglVector4 *vector)
|
cogl_vector4_init_zero (float *vector)
|
||||||
{
|
{
|
||||||
memset (vector, 0, sizeof (CoglVector4));
|
memset (vector, 0, sizeof (CoglVector4));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector4_init_from_vector4 (CoglVector4 *vector, CoglVector4 *src)
|
cogl_vector4_init_from_vector4 (float *vector, float *src)
|
||||||
{
|
{
|
||||||
*vector4 = *src;
|
*vector4 = *src;
|
||||||
}
|
}
|
||||||
@ -226,8 +233,8 @@ cogl_vector4_equal (gconstpointer *v0, gconstpointer *v1)
|
|||||||
return memcmp (v1, v2, sizeof (float) * 4) == 0 ? TRUE : FALSE;
|
return memcmp (v1, v2, sizeof (float) * 4) == 0 ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoglVector4 *
|
float *
|
||||||
cogl_vector4_copy (CoglVector4 *vector)
|
cogl_vector4_copy (float *vector)
|
||||||
{
|
{
|
||||||
if (vector)
|
if (vector)
|
||||||
return g_slice_dup (CoglVector4, vector);
|
return g_slice_dup (CoglVector4, vector);
|
||||||
@ -235,13 +242,13 @@ cogl_vector4_copy (CoglVector4 *vector)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector4_free (CoglVector4 *vector)
|
cogl_vector4_free (float *vector)
|
||||||
{
|
{
|
||||||
g_slice_free (CoglVector4, vector);
|
g_slice_free (CoglVector4, vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector4_invert (CoglVector4 *vector)
|
cogl_vector4_invert (float *vector)
|
||||||
{
|
{
|
||||||
vector.x = -vector.x;
|
vector.x = -vector.x;
|
||||||
vector.y = -vector.y;
|
vector.y = -vector.y;
|
||||||
@ -250,9 +257,9 @@ cogl_vector4_invert (CoglVector4 *vector)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector4_add (CoglVector4 *result,
|
cogl_vector4_add (float *result,
|
||||||
CoglVector4 *a,
|
float *a,
|
||||||
CoglVector4 *b)
|
float *b)
|
||||||
{
|
{
|
||||||
result.x = a.x + b.x;
|
result.x = a.x + b.x;
|
||||||
result.y = a.y + b.y;
|
result.y = a.y + b.y;
|
||||||
@ -261,9 +268,9 @@ cogl_vector4_add (CoglVector4 *result,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector4_subtract (CoglVector4 *result,
|
cogl_vector4_subtract (float *result,
|
||||||
CoglVector4 *a,
|
float *a,
|
||||||
CoglVector4 *b)
|
float *b)
|
||||||
{
|
{
|
||||||
result.x = a.x - b.x;
|
result.x = a.x - b.x;
|
||||||
result.y = a.y - b.y;
|
result.y = a.y - b.y;
|
||||||
@ -272,7 +279,7 @@ cogl_vector4_subtract (CoglVector4 *result,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_vector4_divide (CoglVector4 *vector,
|
cogl_vector4_divide (float *vector,
|
||||||
float scalar)
|
float scalar)
|
||||||
{
|
{
|
||||||
float one_over_scalar = 1.0f / scalar;
|
float one_over_scalar = 1.0f / scalar;
|
||||||
|
@ -44,50 +44,9 @@ G_BEGIN_DECLS
|
|||||||
* component float vectors.
|
* component float vectors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* All of the cogl-vector API is currently experimental so we
|
|
||||||
* suffix the actual symbols with _EXP so if somone is monitoring for
|
|
||||||
* ABI changes it will hopefully be clearer to them what's going on if
|
|
||||||
* any of the symbols dissapear at a later date.
|
|
||||||
*/
|
|
||||||
#define cogl_vector3_init cogl_vector3_init_EXP
|
|
||||||
#define cogl_vector3_init_zero cogl_vector3_init_zero_EXP
|
|
||||||
#define cogl_vector3_equal cogl_vector3_equal_EXP
|
|
||||||
#define cogl_vector3_equal_with_epsilon cogl_vector3_equal_with_epsilon_EXP
|
|
||||||
#define cogl_vector3_copy cogl_vector3_copy_EXP
|
|
||||||
#define cogl_vector3_free cogl_vector3_free_EXP
|
|
||||||
#define cogl_vector3_invert cogl_vector3_invert_EXP
|
|
||||||
#define cogl_vector3_add cogl_vector3_add_EXP
|
|
||||||
#define cogl_vector3_subtract cogl_vector3_subtract_EXP
|
|
||||||
#define cogl_vector3_multiply_scalar cogl_vector3_multiply_scalar_EXP
|
|
||||||
#define cogl_vector3_divide_scalar cogl_vector3_divide_scalar_EXP
|
|
||||||
#define cogl_vector3_normalize cogl_vector3_normalize_EXP
|
|
||||||
#define cogl_vector3_magnitude cogl_vector3_magnitude_EXP
|
|
||||||
#define cogl_vector3_cross_product cogl_vector3_cross_product_EXP
|
|
||||||
#define cogl_vector3_dot_product cogl_vector3_dot_product_EXP
|
|
||||||
#define cogl_vector3_distance cogl_vector3_distance_EXP
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
/* FIXME: add sse alignment constraint? */
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
float z;
|
|
||||||
} CoglVector3;
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
/* FIXME: add sse alignment constraint? */
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
float z;
|
|
||||||
float w;
|
|
||||||
} CoglVector4;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_init:
|
* cogl_vector3_init:
|
||||||
* @vector: The CoglVector3 you want to initialize
|
* @vector: The 3 component vector you want to initialize
|
||||||
* @x: The x component
|
* @x: The x component
|
||||||
* @y: The y component
|
* @y: The y component
|
||||||
* @z: The z component
|
* @z: The z component
|
||||||
@ -100,11 +59,11 @@ typedef struct
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_vector3_init (CoglVector3 *vector, float x, float y, float z);
|
cogl_vector3_init (float *vector, float x, float y, float z);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_init_zero:
|
* cogl_vector3_init_zero:
|
||||||
* @vector: The CoglVector3 you want to initialize
|
* @vector: The 3 component vector you want to initialize
|
||||||
*
|
*
|
||||||
* Initializes a 3 component, single precision float vector with zero
|
* Initializes a 3 component, single precision float vector with zero
|
||||||
* for each component.
|
* for each component.
|
||||||
@ -113,12 +72,12 @@ cogl_vector3_init (CoglVector3 *vector, float x, float y, float z);
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_vector3_init_zero (CoglVector3 *vector);
|
cogl_vector3_init_zero (float *vector);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_equal:
|
* cogl_vector3_equal:
|
||||||
* @v1: The first CoglVector3 you want to compare
|
* @v1: The first 3 component vector you want to compare
|
||||||
* @v2: The second CoglVector3 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
|
* Compares the components of two vectors and returns TRUE if they are
|
||||||
* the same.
|
* the same.
|
||||||
@ -139,8 +98,8 @@ cogl_vector3_equal (gconstpointer v1, gconstpointer v2);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_equal_with_epsilon:
|
* cogl_vector3_equal_with_epsilon:
|
||||||
* @vector0: The first CoglVector3 you want to compare
|
* @vector0: The first 3 component vector you want to compare
|
||||||
* @vector1: The second CoglVector3 you want to compare
|
* @vector1: The second 3 component vector you want to compare
|
||||||
* @epsilon: The allowable difference between components to still be
|
* @epsilon: The allowable difference between components to still be
|
||||||
* considered equal
|
* considered equal
|
||||||
*
|
*
|
||||||
@ -159,43 +118,43 @@ cogl_vector3_equal (gconstpointer v1, gconstpointer v2);
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
cogl_vector3_equal_with_epsilon (const CoglVector3 *vector0,
|
cogl_vector3_equal_with_epsilon (const float *vector0,
|
||||||
const CoglVector3 *vector1,
|
const float *vector1,
|
||||||
float epsilon);
|
float epsilon);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_copy:
|
* cogl_vector3_copy:
|
||||||
* @vector: The CoglVector3 you want to copy
|
* @vector: The 3 component vector you want to copy
|
||||||
*
|
*
|
||||||
* Allocates a new #CoglVector3 structure on the heap initializing the
|
* Allocates a new 3 component float vector on the heap initializing
|
||||||
* components from the given @vector and returns a pointer to the newly
|
* the components from the given @vector and returns a pointer to the
|
||||||
* allocated vector. You should free the memory using
|
* newly allocated vector. You should free the memory using
|
||||||
* cogl_vector3_free()
|
* cogl_vector3_free()
|
||||||
*
|
*
|
||||||
* Returns: A newly allocated #CoglVector3.
|
* Returns: A newly allocated 3 component float vector
|
||||||
*
|
*
|
||||||
* Since: 1.4
|
* Since: 1.4
|
||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
CoglVector3 *
|
float *
|
||||||
cogl_vector3_copy (const CoglVector3 *vector);
|
cogl_vector3_copy (const float *vector);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_free:
|
* cogl_vector3_free:
|
||||||
* @vector: The CoglVector3 you want to free
|
* @vector: The 3 component you want to free
|
||||||
*
|
*
|
||||||
* Frees a #CoglVector3 that was previously allocated with
|
* Frees a 3 component vector that was previously allocated with
|
||||||
* cogl_vector_copy()
|
* cogl_vector_copy()
|
||||||
*
|
*
|
||||||
* Since: 1.4
|
* Since: 1.4
|
||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_vector3_free (CoglVector3 *vector);
|
cogl_vector3_free (float *vector);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_invert:
|
* cogl_vector3_invert:
|
||||||
* @vector: The CoglVector3 you want to manipulate
|
* @vector: The 3 component vector you want to manipulate
|
||||||
*
|
*
|
||||||
* Inverts/negates all the components of the given @vector.
|
* Inverts/negates all the components of the given @vector.
|
||||||
*
|
*
|
||||||
@ -203,7 +162,7 @@ cogl_vector3_free (CoglVector3 *vector);
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_vector3_invert (CoglVector3 *vector);
|
cogl_vector3_invert (float *vector);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_add:
|
* cogl_vector3_add:
|
||||||
@ -218,9 +177,9 @@ cogl_vector3_invert (CoglVector3 *vector);
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_vector3_add (CoglVector3 *result,
|
cogl_vector3_add (float *result,
|
||||||
const CoglVector3 *a,
|
const float *a,
|
||||||
const CoglVector3 *b);
|
const float *b);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_subtract:
|
* cogl_vector3_subtract:
|
||||||
@ -235,13 +194,13 @@ cogl_vector3_add (CoglVector3 *result,
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_vector3_subtract (CoglVector3 *result,
|
cogl_vector3_subtract (float *result,
|
||||||
const CoglVector3 *a,
|
const float *a,
|
||||||
const CoglVector3 *b);
|
const float *b);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_multiply_scalar:
|
* cogl_vector3_multiply_scalar:
|
||||||
* @vector: The CoglVector3 you want to manipulate
|
* @vector: The 3 component vector you want to manipulate
|
||||||
* @scalar: The scalar you want to multiply the vector components by
|
* @scalar: The scalar you want to multiply the vector components by
|
||||||
*
|
*
|
||||||
* Multiplies each of the @vector components by the given scalar.
|
* Multiplies each of the @vector components by the given scalar.
|
||||||
@ -250,12 +209,12 @@ cogl_vector3_subtract (CoglVector3 *result,
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_vector3_multiply_scalar (CoglVector3 *vector,
|
cogl_vector3_multiply_scalar (float *vector,
|
||||||
float scalar);
|
float scalar);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_divide_scalar:
|
* cogl_vector3_divide_scalar:
|
||||||
* @vector: The CoglVector3 you want to manipulate
|
* @vector: The 3 component vector you want to manipulate
|
||||||
* @scalar: The scalar you want to divide the vector components by
|
* @scalar: The scalar you want to divide the vector components by
|
||||||
*
|
*
|
||||||
* Divides each of the @vector components by the given scalar.
|
* Divides each of the @vector components by the given scalar.
|
||||||
@ -264,12 +223,12 @@ cogl_vector3_multiply_scalar (CoglVector3 *vector,
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_vector3_divide_scalar (CoglVector3 *vector,
|
cogl_vector3_divide_scalar (float *vector,
|
||||||
float scalar);
|
float scalar);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_normalize:
|
* cogl_vector3_normalize:
|
||||||
* @vector: The CoglVector3 you want to manipulate
|
* @vector: The 3 component vector you want to manipulate
|
||||||
*
|
*
|
||||||
* Updates the vector so it is a "unit vector" such that the
|
* Updates the vector so it is a "unit vector" such that the
|
||||||
* @vector<!-- -->s magnitude or length is equal to 1.
|
* @vector<!-- -->s magnitude or length is equal to 1.
|
||||||
@ -278,11 +237,11 @@ cogl_vector3_divide_scalar (CoglVector3 *vector,
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_vector3_normalize (CoglVector3 *vector);
|
cogl_vector3_normalize (float *vector);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_magnitude:
|
* cogl_vector3_magnitude:
|
||||||
* @vector: The CoglVector3 you want the magnitude for
|
* @vector: The 3 component vector you want the magnitude for
|
||||||
*
|
*
|
||||||
* Calculates the scalar magnitude or length of @vector.
|
* Calculates the scalar magnitude or length of @vector.
|
||||||
*
|
*
|
||||||
@ -292,13 +251,13 @@ cogl_vector3_normalize (CoglVector3 *vector);
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
float
|
float
|
||||||
cogl_vector3_magnitude (const CoglVector3 *vector);
|
cogl_vector3_magnitude (const float *vector);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_cross_product:
|
* cogl_vector3_cross_product:
|
||||||
* @result: Where you want the result written
|
* @result: Where you want the result written
|
||||||
* @u: Your first CoglVector3
|
* @u: Your first 3 component vector
|
||||||
* @v: Your second CoglVector3
|
* @v: Your second 3 component vector
|
||||||
*
|
*
|
||||||
* Calculates the cross product between the two vectors @u and @v.
|
* Calculates the cross product between the two vectors @u and @v.
|
||||||
*
|
*
|
||||||
@ -322,16 +281,16 @@ cogl_vector3_magnitude (const CoglVector3 *vector);
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cogl_vector3_cross_product (CoglVector3 *result,
|
cogl_vector3_cross_product (float *result,
|
||||||
const CoglVector3 *u,
|
const float *u,
|
||||||
const CoglVector3 *v);
|
const float *v);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_dot_product:
|
* cogl_vector3_dot_product:
|
||||||
* @a: Your first CoglVector3
|
* @a: Your first 3 component vector
|
||||||
* @b: Your second CoglVector3
|
* @b: Your second 3 component vector
|
||||||
*
|
*
|
||||||
* Calculates the dot product of the two #CoglVector3<!-- -->s. This
|
* Calculates the dot product of the two 3 component vectors. This
|
||||||
* can be used to determine the magnitude of one vector projected onto
|
* can be used to determine the magnitude of one vector projected onto
|
||||||
* another. (for example a surface normal)
|
* another. (for example a surface normal)
|
||||||
*
|
*
|
||||||
@ -365,7 +324,7 @@ cogl_vector3_cross_product (CoglVector3 *result,
|
|||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
float
|
float
|
||||||
cogl_vector3_dot_product (const CoglVector3 *a, const CoglVector3 *b);
|
cogl_vector3_dot_product (const float *a, const float *b);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_vector3_distance:
|
* cogl_vector3_distance:
|
||||||
@ -375,13 +334,14 @@ cogl_vector3_dot_product (const CoglVector3 *a, const CoglVector3 *b);
|
|||||||
* If you consider the two given vectors as (x,y,z) points instead
|
* If you consider the two given vectors as (x,y,z) points instead
|
||||||
* then this will compute the distance between those two points.
|
* then this will compute the distance between those two points.
|
||||||
*
|
*
|
||||||
* Returns: The distance between two points given as @CoglVector3<!-- -->s
|
* Returns: The distance between two points given as 3 component
|
||||||
|
* vectors.
|
||||||
*
|
*
|
||||||
* Since: 1.4
|
* Since: 1.4
|
||||||
* Stability: Unstable
|
* Stability: Unstable
|
||||||
*/
|
*/
|
||||||
float
|
float
|
||||||
cogl_vector3_distance (const CoglVector3 *a, const CoglVector3 *b);
|
cogl_vector3_distance (const float *a, const float *b);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user