Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (39 sloc) 1.38 KB
#donotrun
// Standard matrices
// Return rotation matrix for rotating around vector v by angle
mat3 rotationMatrix3(vec3 v, float angle)
{
float c = cos(radians(angle));
float s = sin(radians(angle));
return mat3(c + (1.0 - c) * v.x * v.x, (1.0 - c) * v.x * v.y - s * v.z, (1.0 - c) * v.x * v.z + s * v.y,
(1.0 - c) * v.x * v.y + s * v.z, c + (1.0 - c) * v.y * v.y, (1.0 - c) * v.y * v.z - s * v.x,
(1.0 - c) * v.x * v.z - s * v.y, (1.0 - c) * v.y * v.z + s * v.x, c + (1.0 - c) * v.z * v.z
);
}
mat3 rotationMatrixXYZ(vec3 v) {
return rotationMatrix3(vec3(1.0,0.0,0.0), v.x)*
rotationMatrix3(vec3(0.0,1.0,0.0), v.y)*
rotationMatrix3(vec3(0.0,0.0,1.0), v.z);
}
// Return rotation matrix for rotating around vector v by angle
mat4 rotationMatrix(vec3 v, float angle)
{
float c = cos(radians(angle));
float s = sin(radians(angle));
return mat4(c + (1.0 - c) * v.x * v.x, (1.0 - c) * v.x * v.y - s * v.z, (1.0 - c) * v.x * v.z + s * v.y, 0.0,
(1.0 - c) * v.x * v.y + s * v.z, c + (1.0 - c) * v.y * v.y, (1.0 - c) * v.y * v.z - s * v.x, 0.0,
(1.0 - c) * v.x * v.z - s * v.y, (1.0 - c) * v.y * v.z + s * v.x, c + (1.0 - c) * v.z * v.z, 0.0,
0.0, 0.0, 0.0, 1.0);
}
mat4 translate(vec3 v) {
return mat4(1.0,0.0,0.0,0.0,
0.0,1.0,0.0,0.0,
0.0,0.0,1.0,0.0,
v.x,v.y,v.z,1.0);
}
mat4 scale4(float s) {
return mat4(s,0.0,0.0,0.0,
0.0,s,0.0,0.0,
0.0,0.0,s,0.0,
0.0,0.0,0.0,1.0);
}