LYGIA Shader Library

rotate (lygia/v1.1.4/space/rotate)

rotate a 2D space by a radian radians

Dependencies:

Use:

rotate(<vec3|vec2> st, float radians [, vec2 center])

Check it on Github



#ifndef FNC_ROTATE
#define FNC_ROTATE
vec2 rotate(in vec2 st, in float radians, in vec2 center) {
    return rotate2d(radians) * (st - center) + center;
}

vec2 rotate(in vec2 st, in float radians) {
    #ifdef CENTER_2D
    return rotate(st, radians, CENTER_2D);
    #else
    return rotate(st, radians, vec2(.5));
    #endif
}

vec2 rotate(vec2 st, vec2 x_axis) {
    #ifdef CENTER_2D
    st -= CENTER_2D;
    #endif
    vec2 rta = vec2( dot(st, vec2(-x_axis.y, x_axis.x)), dot(st, x_axis) );
    #ifdef CENTER_2D
    rta += CENTER_2D;
    #endif
    return rta;
}

vec3 rotate(in vec3 xyz, in float radians, in vec3 axis, in vec3 center) {
    return (rotate4d(axis, radians) * vec4(xyz - center, 1.)).xyz + center;
}

vec3 rotate(in vec3 xyz, in float radians, in vec3 axis) {
    #ifdef CENTER_3D
    return rotate(xyz, radians, axis, CENTER_3D);
    #else
    return rotate(xyz, radians, axis, vec3(0.));
    #endif
}

vec4 rotate(in vec4 xyzw, in float radians, in vec3 axis, in vec4 center) {
    return rotate4d(axis, radians) * (xyzw - center) + center;
}

vec4 rotate(in vec4 xyzw, in float radians, in vec3 axis) {
    #ifdef CENTER_4D
    return rotate(xyzw, radians, axis, CENTER_4D);
    #else
    return rotate(xyzw, radians, axis, vec4(0.));
    #endif
}
#endif

Dependencies:

Use:

rotate(<float3|float2> st, float radians [, float2 center])

Check it on Github



#ifndef FNC_ROTATE
#define FNC_ROTATE
float2 rotate(in float2 st, in float radians, in float2 center) {
    return mul(rotate2d(radians), (st - center)) + center;
}

float2 rotate(in float2 st, in float radians) {
    #ifdef CENTER_2D
    return rotate(st, radians, CENTER_2D);
    #else
    return rotate(st, radians, float2(0.5, 0.5));
    #endif
}

float2 rotate(float2 st, float2 x_axis) {
    #ifdef CENTER_2D
    st -= CENTER_2D;
    #endif
    float2 rta = float2( dot(st, float2(-x_axis.y, x_axis.x)), dot(st, x_axis) );
    #ifdef CENTER_2D
    rta += CENTER_2D;
    #endif
    return rta;
}

float3 rotate(in float3 xyz, in float radians, in float3 axis, in float3 center) {
    return mul(rotate4d(axis, radians), float4(xyz - center, 1.)).xyz + center;
}

float3 rotate(in float3 xyz, in float radians, in float3 axis) {
    #ifdef CENTER_3D
    return rotate(xyz, radians, axis, CENTER_3D);
    #else
    return rotate(xyz, radians, axis, float3(0.0, 0.0, 0.0));
    #endif
}

float4 rotate(in float4 xyzw, in float radians, in float3 axis, in float4 center) {
    return mul(rotate4d(axis, radians), (xyzw - center)) + center;
}

float4 rotate(in float4 xyzw, in float radians, in float3 axis) {
    #ifdef CENTER_4D
    return rotate(xyzw, radians, axis, CENTER_4D);
    #else
    return rotate(xyzw, radians, axis, float4(0.0, 0.0, 0.0, 0.0));
    #endif
}
#endif

Dependencies:

Check it on Github


fn rotate(st: vec2<f32>, radians: f32) -> vec2<f32> {
    return rotate2d(radians) * (st - 0.5) + 0.5;
}

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