Created
September 17, 2011 01:12
-
-
Save rlane/1223480 to your computer and use it in GitHub Desktop.
GLSL matrix functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mat4 translate(vec3 d) | |
{ | |
return mat4(1, 0, 0, d.x, | |
0, 1, 0, d.y, | |
0, 0, 1, d.z, | |
0, 0, 0, 1); | |
} | |
mat4 scale(float c) | |
{ | |
return mat4(c, 0, 0, 0, | |
0, c, 0, 0, | |
0, 0, c, 0, | |
0, 0, 0, 1); | |
} | |
mat4 rotate2d(float a) | |
{ | |
return mat4(cos(a), -sin(a), 0, 0, | |
sin(a), cos(a), 0, 0, | |
0, 0, 1.0, 0, | |
0, 0, 0, 1.0); | |
} | |
mat4 ortho(float n, float f, float r, float l, float t, float b) | |
{ | |
return mat4(2.0/(r-l), 0, 0, -(r+l)/(r-l), | |
0, 2.0/(t-b), 0, -(t+b)/(t-b), | |
0, 0, -2.0/(f-n), -(f+n)/(f-n), | |
0, 0, 0, 1); | |
} | |
mat4 orthoX(vec2 pos, float aspect, float w) | |
{ | |
return ortho(-1.0, 1.0, w/2.0, -w/2.0, w*aspect/2.0, -w*aspect/2.0)*translate(vec3(pos,0)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment