Created
July 20, 2014 20:57
-
-
Save FlyingJester/1cae2df220f4625b624e to your computer and use it in GitHub Desktop.
Rotation causing divide-by-zero
This file contains hidden or 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
| #version 410\n\ | |
| \ | |
| uniform vec2 TS_Offset;\n\ | |
| uniform vec2 TS_RotationOffset;\n\ | |
| uniform float TS_RotationAngle;\n\ | |
| \ | |
| in vec2 TS_TextureUV;\n\ | |
| in vec4 TS_Position;\n\ | |
| in vec4 TS_Color;\n\ | |
| \ | |
| out vec4 color_v;\n\ | |
| out vec2 tex_v;\n\ | |
| \ | |
| uniform vec2 TS_ScreenSize;\n\ | |
| \ | |
| void main (void)\n\ | |
| {\n\ | |
| tex_v = TS_TextureUV;\n\ | |
| color_v = TS_Color;\n\ | |
| //Rotation: \n\ | |
| vec2 TS_Distance = (TS_Position.xy - TS_RotationOffset) + 0.001;\n\ | |
| float TS_ModAngle = atan(TS_Distance.y, TS_Distance.x) + TS_RotationAngle;\n\ | |
| float TS_Distance2 = sqrt( (TS_Distance.x*TS_Distance.x) * (TS_Distance.y*TS_Distance.y));\n\ | |
| vec2 TS_NewPos = (TS_RotationOffset + vec2( cos(TS_ModAngle), sin(TS_ModAngle) ) * TS_Distance2 )*2.0;\n\ | |
| gl_Position = (vec4(TS_Offset.x*2.0, TS_Offset.y*(-2.0), 0.0, 0.0) +(vec4(TS_NewPos.x - TS_ScreenSize.x, -TS_NewPos.y + (TS_ScreenSize.y), TS_Position.ba)))/vec4(TS_ScreenSize, 1.0, 1.0);\n\ | |
| }\ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment