## rotate4d (`lygia`/`math`/`rotate4d`)

returns a 4x4 rotation matrix

Use:

``````<mat4> rotate4d(<vec3> axis, <float> radians)
``````

Check it on Github

``````
#ifndef FNC_ROTATE4D
#define FNC_ROTATE4D
mat4 rotate4d(in vec3 a, const in float r) {
a = normalize(a);
float s = sin(r);
float c = cos(r);
float oc = 1.0 - c;
vec4 col1 = vec4(oc * a.x * a.x + c, oc * a.x * a.y + a.z * s, oc * a.z * a.x - a.y * s, 0.0);
vec4 col2 = vec4(oc * a.x * a.y - a.z * s, oc * a.y * a.y + c, oc * a.y * a.z + a.x * s, 0.0);
vec4 col3 = vec4(oc * a.z * a.x + a.y * s, oc * a.y * a.z - a.x * s, oc * a.z * a.z + c, 0.0);
vec4 col4 = vec4(0.0, 0.0, 0.0, 1.0);
return mat4(col1, col2, col3, col4);
}
#endif

``````

Use:

``````<float4x4> rotate4d(<float3> axis, <float> radians)
``````

Check it on Github

``````
#ifndef FNC_ROTATE4D
#define FNC_ROTATE4D
float4x4 rotate4d(in float3 axis, const in float radians) {
axis = normalize(axis);
float oc = 1.0 - c;
return float4x4(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);
}
#endif

``````

Check it on Github

``````
fn rotate4d(a: vec3f, r: f32) -> mat4x4<f32> {
let s = sin(r);
let c = cos(r);
let oc = 1.0 - c;
return mat4x4<f32>( oc * a.x * a.x + c,         oc * a.x * a.y - a.z * s,   oc * a.z * a.x + a.y * s,   0.0,
oc * a.x * a.y + a.z * s,   oc * a.y * a.y + c,         oc * a.y * a.z - a.x * s,   0.0,
oc * a.z * a.x - a.y * s,   oc * a.y * a.z + a.x * s,   oc * a.z * a.z + c,         0.0,
0.0,                        0.0,                        0.0,                        1.0);
}

``````