Skip to content

Matrix4 Translate

Kion edited this page Sep 16, 2017 · 1 revision

mat4 translate

Description

Translates a given mat4 matrix by a vec3.

Arguments

  • mat4 m - the matrix to be translated
  • vec3 t - x, y, z vector 3 to translate by
  • mat4 dst - destination mat4

Source

void mat4_translate(mat4 m, vec3 t, mat4 dst) {

    mat4 tmp;
    mat4_identity(dst);

    tmp[M_00] = 1.0f;
    tmp[M_10] = 0.0f;
    tmp[M_20] = 0.0f;
    tmp[M_30] = 0.0f;

    tmp[M_01] = 0.0f;
    tmp[M_11] = 1.0f;
    tmp[M_21] = 0.0f;
    tmp[M_31] = 0.0f;

    tmp[M_02] = 0.0f;
    tmp[M_12] = 0.0f;
    tmp[M_22] = 1.0f;
    tmp[M_32] = 0.0f;

    tmp[M_03] = t[0];
    tmp[M_13] = t[1];
    tmp[M_23] = t[2];
    tmp[M_33] = 1.0f;

    mat4_multiply(m, tmp, dst);

}

DashGL

  • Home
  • Shaders
  • Vector2
  • Vector3
  • Vector4
  • Matrix4x4

Vector 3


Matrix 4x4

Clone this wiki locally