LYGIA Shader Library

lookAt (lygia/v1.1.6/space/lookAt)

create a look up matrix

Use:

<mat3> lookAt(<vec3> forward, <vec3> up)
<mat3> lookAt(<vec3> target, <vec3> eye, <vec3> up)
<mat3> lookAt(<vec3> target, <vec3> eye, <float> rolle)

Check it on Github


#ifndef FNC_LOOKAT
#define FNC_LOOKAT

mat3 lookAt(vec3 forward, vec3 up) {
    vec3 xaxis = normalize(cross(forward, up));
    vec3 yaxis = up;
    vec3 zaxis = forward;
    return mat3(xaxis, yaxis, zaxis);
}

mat3 lookAt(vec3 target, vec3 eye, vec3 up) {
    vec3 zaxis = normalize(target - eye);
    vec3 xaxis = normalize(cross(zaxis, up));
    vec3 yaxis = cross(zaxis, xaxis);
    return mat3(xaxis, yaxis, zaxis);
}

mat3 lookAt(vec3 target, vec3 eye, float roll) {
    vec3 up = vec3(sin(roll), cos(roll), 0.0);
    vec3 zaxis = normalize(target - eye);
    vec3 xaxis = normalize(cross(zaxis, up));
    vec3 yaxis = normalize(cross(xaxis, zaxis));
    return mat3(xaxis, yaxis, zaxis);
}

mat3 lookAt(vec3 forward) {
    return lookAt(forward, vec3(0.0, 1.0, 0.0));
}

#endif

Use:

<float3x3> lookAt(<float3> forward, <float3> up)
<float3x3> lookAt(<float3> target, <float3> eye, <float3> up)
<float3x3> lookAt(<float3> target, <float3> eye, <float> rolle)

Check it on Github


#ifndef FNC_LOOKAT
#define FNC_LOOKAT

float3x3 lookAt(float3 forward, float3 up) {
    float3 xaxis = normalize(cross(forward, up));
    float3 yaxis = up;
    float3 zaxis = forward;
    return float3x3(xaxis, yaxis, zaxis);
}

float3x3 lookAt(float3 target, float3 eye, float3 up) {
    float3 zaxis = normalize(target - eye);
    float3 xaxis = normalize(cross(zaxis, up));
    float3 yaxis = cross(zaxis, xaxis);
    return float3x3(xaxis, yaxis, zaxis);
}

float3x3 lookAt(float3 target, float3 eye, float roll) {
    float3 up = float3(sin(roll), cos(roll), 0.0);
    float3 zaxis = normalize(target - eye);
    float3 xaxis = normalize(cross(zaxis, up));
    float3 yaxis = normalize(cross(xaxis, zaxis));
    return float3x3(xaxis, yaxis, zaxis);
}

#endif

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository