Skip to content

Instantly share code, notes, and snippets.

@mattatz
Last active July 28, 2022 05:31
Show Gist options
  • Save mattatz/76d59f96c9eebeb319819d0a504ecf25 to your computer and use it in GitHub Desktop.
Save mattatz/76d59f96c9eebeb319819d0a504ecf25 to your computer and use it in GitHub Desktop.

Revisions

  1. mattatz revised this gist Apr 28, 2016. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions LookAtMatrix.cginc
    Original file line number Diff line number Diff line change
    @@ -5,14 +5,11 @@ float4x4 look_at_matrix(float3 at, float3 eye, float3 up) {
    float3 zaxis = normalize(at - eye);
    float3 xaxis = normalize(cross(up, zaxis));
    float3 yaxis = cross(zaxis, xaxis);
    float dx = -dot(xaxis, eye);
    float dy = -dot(yaxis, eye);
    float dz = -dot(zaxis, eye);
    return float4x4(
    xaxis.x, yaxis.x, zaxis.x, 0,
    xaxis.y, yaxis.y, zaxis.y, 0,
    xaxis.z, yaxis.z, zaxis.z, 0,
    dx, dy, dz, 1
    0, 0, 0, 1
    );
    }

  2. mattatz created this gist Apr 28, 2016.
    19 changes: 19 additions & 0 deletions LookAtMatrix.cginc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #ifndef _LOOK_AT_MATRIX_
    #define _LOOK_AT_MATRIX_

    float4x4 look_at_matrix(float3 at, float3 eye, float3 up) {
    float3 zaxis = normalize(at - eye);
    float3 xaxis = normalize(cross(up, zaxis));
    float3 yaxis = cross(zaxis, xaxis);
    float dx = -dot(xaxis, eye);
    float dy = -dot(yaxis, eye);
    float dz = -dot(zaxis, eye);
    return float4x4(
    xaxis.x, yaxis.x, zaxis.x, 0,
    xaxis.y, yaxis.y, zaxis.y, 0,
    xaxis.z, yaxis.z, zaxis.z, 0,
    dx, dy, dz, 1
    );
    }

    #endif