Skip to content

Instantly share code, notes, and snippets.

@akella
Created January 20, 2019 08:53
Show Gist options
  • Select an option

  • Save akella/30e24b703315ad70a0cd44d6fab8539d to your computer and use it in GitHub Desktop.

Select an option

Save akella/30e24b703315ad70a0cd44d6fab8539d to your computer and use it in GitHub Desktop.

Revisions

  1. akella created this gist Jan 20, 2019.
    17 changes: 17 additions & 0 deletions rotate.glsl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@

    mat4 rotationMatrix(vec3 axis, float angle) {
    axis = normalize(axis);
    float s = sin(angle);
    float c = cos(angle);
    float oc = 1.0 - c;

    return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
    oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
    oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
    0.0, 0.0, 0.0, 1.0);
    }

    vec3 rotate(vec3 v, vec3 axis, float angle) {
    mat4 m = rotationMatrix(axis, angle);
    return (m * vec4(v, 1.0)).xyz;
    }