iOS Developer Library

Developer

GLKit Framework Reference GLKVector2 Reference

Options
Deployment Target:

On This Page
Language:

GLKVector2 Reference

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

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

Functions

  • Returns a new two-component vector created from individual component values.

    Declaration

    Objective-C

    GLKVector2 GLKVector2Make ( float x, float y );

    Parameters

    x

    The first component.

    y

    The second component.

    Return Value

    An initialized vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2MakeWithArray ( float values[2] );

    Parameters

    values

    The array containing the component values.

    Return Value

    The array

    Discussion

    An initialized vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

  • Returns the length of a vector.

    Declaration

    Objective-C

    float GLKVector2Length ( GLKVector2 vector );

    Parameters

    vector

    A vector.

    Return Value

    The length of the vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

  • Returns the distance between two points.

    Declaration

    Objective-C

    float GLKVector2Distance ( GLKVector2 vectorStart, GLKVector2 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.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2Negate ( GLKVector2 vector );

    Parameters

    vector

    A vector.

    Return Value

    A new vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2Normalize ( GLKVector2 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.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2AddScalar ( GLKVector2 vector, float value );

    Parameters

    vector

    A vector.

    value

    A scalar value.

    Return Value

    A new vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2SubtractScalar ( GLKVector2 vector, float value );

    Parameters

    vector

    A vector.

    value

    A scalar value.

    Return Value

    A new vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2MultiplyScalar ( GLKVector2 vector, float value );

    Parameters

    vector

    A vector.

    value

    A scalar value.

    Return Value

    A new vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2DivideScalar ( GLKVector2 vector, float value );

    Parameters

    vector

    A vector.

    value

    A scalar value.

    Return Value

    A new vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

  • Returns the sum of two vectors.

    Declaration

    Objective-C

    GLKVector2 GLKVector2Add ( GLKVector2 vectorLeft, GLKVector2 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.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

  • Returns the difference between two vectors.

    Declaration

    Objective-C

    GLKVector2 GLKVector2Subtract ( GLKVector2 vectorLeft, GLKVector2 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.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

  • Returns a new vector created by multiplying one vector by another.

    Declaration

    Objective-C

    GLKVector2 GLKVector2Multiply ( GLKVector2 vectorLeft, GLKVector2 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.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2Divide ( GLKVector2 vectorLeft, GLKVector2 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.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

  • Returns the dot product of two vectors.

    Declaration

    Objective-C

    float GLKVector2DotProduct ( GLKVector2 vectorLeft, GLKVector2 vectorRight );

    Parameters

    vectorLeft

    The first vector.

    vectorRight

    The second vector.

    Return Value

    The dot product of the two vectors.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2Lerp ( GLKVector2 vectorStart, GLKVector2 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.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2Project ( GLKVector2 vectorToProject, GLKVector2 projectionVector );

    Parameters

    vectorToProject

    The vector being projected.

    projectionVector

    The projection vector.

    Return Value

    A new vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2Maximum ( GLKVector2 vectorLeft, GLKVector2 vectorRight );

    Parameters

    vectorLeft

    The first vector.

    vectorRight

    The second vector.

    Return Value

    A new vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    GLKVector2 GLKVector2Minimum ( GLKVector2 vectorLeft, GLKVector2 vectorRight );

    Parameters

    vectorLeft

    The first vector.

    vectorRight

    The second vector.

    Return Value

    A new vector.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    bool GLKVector2AllEqualToScalar ( GLKVector2 vector, float value );

    Parameters

    vector

    A vector.

    value

    A scalar.

    Return Value

    YEStrue if all of the vector’s components are equal to value, NOfalse otherwise.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    bool GLKVector2AllEqualToVector2 ( GLKVector2 vectorLeft, GLKVector2 vectorRight );

    Parameters

    vectorLeft

    The first vector.

    vectorRight

    The second vector.

    Return Value

    YEStrue if all of the vectors’ components are equal , NOfalse otherwise.

    Discussion

    The vectors are considered equal when the value for the component at each position in the two source vectors is equal.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    bool GLKVector2AllGreaterThanOrEqualToScalar ( GLKVector2 vector, float value );

    Parameters

    vector

    A vector.

    value

    A scalar.

    Return Value

    A Boolean value that states whether the vector components are all greater than or equal to the scalar value.

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

  • 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.

    Declaration

    Objective-C

    bool GLKVector2AllGreaterThanOrEqualToVector2 ( GLKVector2 vectorLeft, GLKVector2 vectorRight );

    Parameters

    vectorLeft

    The first vector.

    vectorRight

    The second vector.

    Return Value

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

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    bool GLKVector2AllGreaterThanScalar ( GLKVector2 vector, float value );

    Parameters

    vector

    A vector.

    value

    A scalar.

    Return Value

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

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Objective-C

    bool GLKVector2AllGreaterThanVector2 ( GLKVector2 vectorLeft, GLKVector2 vectorRight );

    Parameters

    vectorLeft

    The first vector.

    vectorRight

    The second vector.

    Return Value

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

    Import Statement

    Objective-C

    @import GLKit;

    Availability

    Available in iOS 5.0 and later.

Data Types

  • A representation of a 2-component vector.

    Declaration

    Objective-C

    union _GLKVector2 { struct { float x, y; }; struct { float s, t; }; float v[2]; }; typedef union _GLKVector2 GLKVector2;

    Fields

    x

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

    y

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

    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.

    v

    The elements of the vector expressed as an array.

    Availability

    Available in iOS 5.0 and later.