lygia
/space
/lookAt
)create a look at matrix. Right handed by default.
Use:
<mat3> lookAt(<vec3> forward, <vec3> up)
<mat3> lookAt(<vec3> eye, <vec3> target, <vec3> up)
<mat3> lookAt(<vec3> eye, <vec3> target, <float> roll)
<mat3> lookAt(<vec3> forward)
#ifndef FNC_LOOKAT
#define FNC_LOOKAT
mat3 lookAt(vec3 forward, vec3 up) {
vec3 zaxis = normalize(forward);
#if defined(LOOK_AT_RIGHT_HANDED)
vec3 xaxis = normalize(cross(zaxis, up));
vec3 yaxis = cross(xaxis, zaxis);
#else
vec3 xaxis = normalize(cross(up, zaxis));
vec3 yaxis = cross(zaxis, xaxis);
#endif
return mat3(xaxis, yaxis, zaxis);
}
mat3 lookAt(vec3 eye, vec3 target, vec3 up) {
vec3 forward = normalize(target - eye);
return lookAt(forward, up);
}
mat3 lookAt(vec3 eye, vec3 target, float roll) {
vec3 up = vec3(sin(roll), cos(roll), 0.0);
return lookAt(eye, target, up);
}
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> roll)
<float3x3> lookAt(<float3> forward)
#ifndef FNC_LOOKAT
#define FNC_LOOKAT
float3x3 lookAt(float3 forward, float3 up) {
float3 zaxis = normalize(forward);
#if defined (LOOK_AT_RIGHT_HANDED)
float3 xaxis = normalize(cross(zaxis, up));
float3 yaxis = cross(xaxis, zaxis);
#else
float3 xaxis = normalize(cross(up, zaxis));
float3 yaxis = cross(zaxis, xaxis);
#endif
float3x3 m;
m._m00_m10_m20 = xaxis;
m._m01_m11_m21 = yaxis;
m._m02_m12_m22 = zaxis;
return m;
}
float3x3 lookAt(float3 eye, float3 target, float3 up) {
float3 forward = normalize(target - eye);
return lookAt(forward, up);
}
float3x3 lookAt(float3 eye, float3 target, float roll) {
float3 up = float3(sin(roll), cos(roll), 0.0);
return lookAt(eye, target, up);
}
float3x3 lookAt(float3 forward) {
return lookAt(forward, float3(0.0, 1.0, 0.0));
}
#endif
Use:
<mat3> lookAt(<float3> forward, <float3> up)
<mat3> lookAt(<float3> eye, <float3> target, <float3> up)
<mat3> lookAt(<float3> eye, <float3> target, <float> rolle)
<mat3> lookAt(<float3> forward)
#ifndef FNC_LOOKAT
#define FNC_LOOKAT
mat3 lookAt(float3 forward, float3 up) {
float3 zaxis = normalize(forward);
#if defined(LOOK_AT_RIGHT_HANDED)
float3 xaxis = normalize(cross(zaxis, up));
float3 yaxis = cross(xaxis, zaxis);
#else
float3 xaxis = normalize(cross(up, zaxis));
float3 yaxis = cross(zaxis, xaxis);
#endif
return mat3(xaxis, yaxis, zaxis);
}
mat3 lookAt(float3 eye, float3 target, float3 up) {
float3 zaxis = normalize(target - eye);
float3 xaxis = normalize(cross(zaxis, up));
float3 yaxis = cross(zaxis, xaxis);
return mat3(xaxis, yaxis, zaxis);
}
mat3 lookAt(float3 eye, float3 target, 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 mat3(xaxis, yaxis, zaxis);
}
mat3 lookAt(float3 forward) {
return lookAt(forward, float3(0.0, 1.0, 0.0));
}
#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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository