CGPdocs

vec4

4D vector of floats (homogeneous coordinates, RGBA).

alias of numarray_stack<float,4>module 02_numarraysource: numarray_stack4.hpp
vec2, vec3 and vec4 store their floats x, y, z, w side by side (indices 0 to 3); the same element has four spellings, and the common calls are norm, normalize, dot and cross.
vec2, vec3 and vec4 store their floats x, y, z, w side by side (indices 0 to 3); the same element has four spellings, and the common calls are norm, normalize, dot and cross. Tap to enlarge.

Fields and methods

Members of the struct numarray_stack<T,4>. Most of what you do with a CGP type goes through the free functions listed below.

Fields

T xFirst coordinate of the vector.
T ySecond coordinate of the vector.
T zThird coordinate of the vector.
T wFourth coordinate of the vector.

Methods

numarray_stack()Builds a vector of size 2, 3 or 4 with all coordinates value-initialized (zero for numbers).8 overloads src
numarray_stack(T const& x, T const& y, T const& z, T const& w)Builds a 4D vector from its coordinates x, y, z and w. src
numarray_stack(T const& x, T const& y, numarray_stack<T,2> const& zw)Builds a 4D vector from x, y and a 2D vector giving (z, w). src
numarray_stack(T const& x, numarray_stack<T,2> const& yz, T const& w)Builds a 4D vector from x, a 2D vector giving (y, z), and w. src
numarray_stack(T const& x, numarray_stack<T,3> const& yzw)Builds a 4D vector from x and a 3D vector giving (y, z, w). src
numarray_stack(numarray_stack<T,2> const& xy, T const& z, T const& w)Builds a 4D vector from a 2D vector giving (x, y), then z and w. src
numarray_stack(numarray_stack<T,2> const& xy, numarray_stack<T,2> const& zw)Builds a 4D vector from two 2D vectors giving (x, y) and (z, w). src
numarray_stack(numarray_stack<T,3> const& xyz, T const& w)Builds a 4D vector from a 3D vector giving (x, y, z) and w, e.g. vec4(p, 1.0f) for a homogeneous position. src
Number of components N, fixed at compile time. src
Sets the N components to the given value and returns the vector. src
Returns the element at index, bound-checked unless CGP_NO_DEBUG is defined. src
Returns a const reference to the element at the given index, with bound checking unless CGP_NO_DEBUG is defined. src
Returns a const reference to the element at the given index; bound-checked for sizes 2, 3 and 4 (vec2, vec3, vec4) unless CGP_NO_DEBUG is defined, but not checked for the other sizes N. src
Returns a const iterator to the first element (a plain pointer for sizes 2, 3 and 4). src
Returns a const iterator one past the last element (a plain pointer for sizes 2, 3 and 4). src
Returns a const iterator to the first element (a plain pointer for sizes 2, 3 and 4). src
Returns a const iterator one past the last element (a plain pointer for sizes 2, 3 and 4). src
Returns a const reference to the element at the given index, without bound checking. src
Returns a copy of the first three coordinates (x, y, z) as a vec3. src
Returns a copy of the coordinates (x, y) as a 2D vector (for vec3 and vec4). src
Returns a copy of the coordinates (y, z) as a 2D vector (for vec3 and vec4). src
Returns a copy of the coordinates (x, z) as a 2D vector (for vec3 and vec4). src

Functions taking a vec4

Construct 1

Documented on another page

Convert 2

type_str

generic2 overloads
template <typename T>
std::string type_str(numarray_stack<T,4> const&)
source

Type name as a string, e.g. "numarray_stack4<int>".

std::string type_str(vec4 const&)
source

Type name as a string: "vec4".

Access 2

template <typename T, int N, typename INDEX_TYPE>
void check_index_bounds(INDEX_TYPE index, numarray_stack<T,4> const& data)

Raises an error if the index is outside [0, 3]; no-op when CGP_NO_DEBUG is defined.

get

genericsource
template <int idx, typename T>
T const& get(numarray_stack<T,4> const& data)
T& get(numarray_stack<T,4>& data)

Component idx with the index checked at compile time (static_assert).

Other 1

Documented on another page

  • opengl_uniformSend a vec4 uniform to the shader; warns if the uniform is not found and expected is true.on opengl_shader_structure

Functions returning a vec4

Access 1

Documented on another page

  • getRow idx1 as a vector, with the index checked at compile time (static_assert).on matN

Operators

Show the 4 operators (+, -, *, ==, ...)

Documented on another page

  • operator*Apply the affine transform to a homogeneous vector, the translation being weighted by w: a direction (w=0) is not translated.on affine
  • operator*Apply the rigid transform to a homogeneous vector, the translation being weighted by w.on affine_rt
  • operator*Apply the transform to a homogeneous vector, the translation being weighted by w.on affine_rts
  • operator*Homogeneous vector whose xyz part is rotated, w being kept.on rotation_transform
CGP - Computer Graphics Programming.