GLKVector4 Reference

Framework
GLKit/GLKMath.h
Declared in
GLKMathTypes.h
GLKVector4.h

Overview

The GLKVector4 type defines a 4-component floating-point vector as well as many mathematical operations commonly used to manipulate vectors. Graphics programming uses vectors extensively to represent positions, normals, colors and other data structures.

The functions that manipulate GLKVector4 structures treat the inputs as immutable, instead returning a new vector that represent the results of the operation.

Functions by Task

Creating Vectors

Retrieving Information About a Vector

Mathematical Operations Performed on Vectors

Comparison Operations

Functions

GLKVector4Add

Returns the sum of two vectors.

GLKVector4 GLKVector4Add (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The first vector.

vectorRight

The second vector.

Return Value

A new vector whose components each represent the sum of the two components found in the same positions of the two source vectors.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4AddScalar

Returns a new vector created by adding a scalar value to each component of a vector.

GLKVector4 GLKVector4AddScalar (
   GLKVector4 vector,
   float value
);
Parameters
vector

A vector.

value

A scalar value.

Return Value

A new vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4AllEqualToScalar

Returns a Boolean value that states whether all the components of the source vector are equal to a scalar value.

bool GLKVector4AllEqualToScalar (
   GLKVector4 vector,
   float value
);
Parameters
vector

A vector.

value

A scalar.

Return Value

YES if all of the vector’s components are equal to value, NO otherwise.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4AllEqualToVector4

Returns a Boolean value that indicates whether each component of the first vector is equal to the corresponding component of a second vector.

bool GLKVector4AllEqualToVector4 (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The first vector.

vectorRight

The second vector.

Return Value

YES if all of the vectors’ components are equal , NO otherwise.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4AllGreaterThanOrEqualToScalar

Returns a Boolean value that states whether all the components of the source vector are greater than or equal to a scalar value.

bool GLKVector4AllGreaterThanOrEqualToScalar (
   GLKVector4 vector,
   float value
);
Parameters
vector

A vector.

value

A scalar.

Return Value

YES if all of the vector’s components are greater than or equal to the scalar value, NO otherwise.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4AllGreaterThanOrEqualToVector4

Returns a Boolean value that indicates whether each component of the first vector is greater than or equal to the corresponding component of a second vector.

bool GLKVector4AllGreaterThanOrEqualToVector4 (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The first vector.

vectorRight

The second vector.

Return Value

YES if each component in the first vector is greater than or equal to the corresponding component of the second vector, NO otherwise.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4AllGreaterThanScalar

Returns a Boolean value that states whether all the components of the source vector are greater than a scalar value.

bool GLKVector4AllGreaterThanScalar (
   GLKVector4 vector,
   float value
);
Parameters
vector

A vector.

value

A scalar.

Return Value

YES if all of the vector’s components are greater than the scalar value, NO otherwise.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4AllGreaterThanVector4

Returns a Boolean value that indicates whether each component of the first vector is greater than the corresponding component of a second vector.

bool GLKVector4AllGreaterThanVector4 (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The first vector.

vectorRight

The second vector.

Return Value

YES if each component in the first vector is greater than the corresponding component of the second vector, NO otherwise.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4CrossProduct

Returns the cross product of two vectors.

GLKVector4 GLKVector4CrossProduct (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The first vector.

vectorRight

The second vector.

Return Value

A new vector.

Discussion

The calculation is performed by taking the [x,y,z] components of the two source vectors and computing the cross product of those two vectors. The w component of the result vector is 0.0.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Distance

Returns the distance between two points.

float GLKVector4Distance (
   GLKVector4 vectorStart,
   GLKVector4 vectorEnd
);
Parameters
vectorStart

A vector providing the coordinates of the starting point.

vectorEnd

A vector providing the coordinates of the ending point.

Return Value

The distance between the two points.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Divide

Returns a new vector created by dividing one vector by another.

GLKVector4 GLKVector4Divide (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The first vector.

vectorRight

The dividend.

Return Value

A new vector whose components are each calculated by dividing the component found in same position of the first vector by the component found in the same position of the second vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4DivideScalar

Returns a new vector created by dividing each component of a vector by a scalar value.

GLKVector4 GLKVector4DivideScalar (
   GLKVector4 vector,
   float value
);
Parameters
vector

A vector.

value

A scalar value.

Return Value

A new vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4DotProduct

Returns the dot product of two vectors.

float GLKVector4DotProduct (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The first vector.

vectorRight

The second vector.

Return Value

The dot product of the two vectors.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Length

Returns the length of a vector.

float GLKVector4Length (
   GLKVector4 vector
);
Parameters
vector

A vector.

Return Value

The length of the vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Lerp

Returns a new vector created by linearly interpreting between two vectors.

GLKVector4 GLKVector4Lerp (
   GLKVector4 vectorStart,
   GLKVector4 vectorEnd,
   float t
);
Parameters
vectorStart

The starting vector.

vectorEnd

The ending vector.

t

An interpolation constant.

Return Value

A new vector.

Discussion

The value of t should typically be between 0.0 and 1.0. A value of 0.0 returns the starting vector and a value of 1.0 returns the ending vector. Any other value of t results in a linear interpolation between the two points.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Make

Returns a new four-component vector created from individual component values.

GLKVector4 GLKVector4Make (
   float x,
   float y,
   float z,
   float w
);
Parameters
x

The first component.

y

The second component.

z

The third component.

w

The fourth component.

Return Value

An initialized vector.

Availability
  • Available in OS X v10.8 and later.
Related Sample Code
Declared In
GLKVector4.h

GLKVector4MakeWithArray

Returns a new four-component vector created from an array of components.

GLKVector4 GLKVector4MakeWithArray (
   float values[4]
);
Parameters
values

The array containing the component values.

Return Value

The array

Discussion

An initialized vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4MakeWithVector3

Returns a new four-component vector created by combining a three-component vector with a scalar value.

GLKVector4 GLKVector4MakeWithVector3 (
   GLKVector3 vector,
   float w
);
Parameters
vector

A vector.

w

The fourth component.

Return Value

A new vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Maximum

Returns a new vector whose component value at each position is the largest component value at the same position in the source vectors.

GLKVector4 GLKVector4Maximum (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The first vector.

vectorRight

The second vector.

Return Value

A new vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Minimum

Returns a new vector whose component value at each position is the smallest component value at the same position in the source vectors.

GLKVector4 GLKVector4Minimum (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The first vector.

vectorRight

The second vector.

Return Value

A new vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Multiply

Returns the product of two vectors.

GLKVector4 GLKVector4Multiply (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The first vector.

vectorRight

The second vector.

Return Value

A new vector whose components each represent the product of the components found in the same positions of the two source vectors.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4MultiplyScalar

Returns a new vector created by multiplying each component of a vector by a scalar value.

GLKVector4 GLKVector4MultiplyScalar (
   GLKVector4 vector,
   float value
);
Parameters
vector

A vector.

value

A scalar value.

Return Value

A new vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Negate

Returns a new vector created by negating the component values of another vector.

GLKVector4 GLKVector4Negate (
   GLKVector4 vector
);
Parameters
vector

A vector.

Return Value

A new vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Normalize

Returns a new vector created by normalizing an input vector to a length of 1.0.

GLKVector4 GLKVector4Normalize (
   GLKVector4 vector
);
Parameters
vector

A vector.

Return Value

A new vector.

Discussion

The resulting vector points in the same direction as the input vector, but has a length of 1.0.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Project

Returns a new vector created by projecting a vector onto another vector.

GLKVector4 GLKVector4Project (
   GLKVector4 vectorToProject,
   GLKVector4 projectionVector
);
Parameters
vectorToProject

The vector being projected.

projectionVector

The projection vector.

Return Value

A new vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4Subtract

Returns the difference between two vectors.

GLKVector4 GLKVector4Subtract (
   GLKVector4 vectorLeft,
   GLKVector4 vectorRight
);
Parameters
vectorLeft

The starting vector.

vectorRight

The vector to subtract.

Return Value

A new vector whose components each represent the difference between the components found in the same positions of the two source vectors.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

GLKVector4SubtractScalar

Returns a new vector created by subtracting a scalar value from each component of a vector.

GLKVector4 GLKVector4SubtractScalar (
   GLKVector4 vector,
   float value
);
Parameters
vector

A vector.

value

A scalar value.

Return Value

A new vector.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKVector4.h

Data Types

GLKVector4

A representation of a 4-component vector.

union _GLKVector4
   {
   struct { float x, y, z, w; };
   struct { float r, g, b, a; };
   struct { float s, t, p, q; };
      float v[4];
}
typedef union _GLKVector4 GLKVector4;
Fields
x

The first component in the vector. Typically used when the vector refers to a position or a normal.

y

The second component in the vector. Typically used when the vector refers to a position or a normal.

z

The third component in the vector. Typically used when the vector refers to a position or a normal.

w

The fourth component in the vector. Typically used when the vector refers to a position.

r

The first component in the vector. Typically used when the vector refers to a color value.

g

The second component in the vector. Typically used when the vector refers to a color value.

b

The third component in the vector. Typically used when the vector refers to a color value.

a

The fourth component in the vector. Typically used when the vector refers to a color value.

s

The first component in the vector. Typically used when the vector refers to texture coordinates.

t

The second component in the vector. Typically used when the vector refers to texture coordinates.

p

The third component in the vector. Typically used when the vector refers to texture coordinates.

q

The fourth component in the vector. Typically used when the vector refers to texture coordinates.

v

The elements of the vector expressed as an array.

Availability
  • Available in OS X v10.8 and later.
Declared In
GLKMathTypes.h