1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 uniform float cubeAngle;
26 gl_TexCoord[0].xy = gl_Vertex.xy;
27 vec4 vertex = gl_Vertex.xyzw;
28 float radian = radians(cubeAngle*0.5);
29 // height of the triangle compound of one side of the cube and the two bisecting lines
30 float midpoint = width*0.5*tan(radian);
31 // radius of the circle
32 float radius = (width*0.5)/cos(radian);
34 // the calculation does the following:
35 // At every x position we move on to the circle und create a new circular segment
36 // The distance between the new chord and the desktop (z=0) is the wanted z value
37 // The length of the new chord is 2*distance(x,middle of desktop(width*0.5))
38 // Now we calculate the angle between chord and radius as acos(distance/radius)
39 // With this angle we can can calculate the height of the new triangle (radius-distance*2-radius)
40 // The height is the opposite leg of the triangle compound of distance-*height*-radius
41 // New height minus old height (midpoint) is the looked for z-value
43 // distance from midpoint of desktop to x coord
44 float distance = width*0.5 - (vertex.x+xCoord);
45 if( (vertex.x+xCoord) > width*0.5 )
47 distance = (vertex.x+xCoord) - width*0.5;
49 float angle = acos( distance/radius );
51 // if distance == 0 -> angle=90 -> tan(90) singularity
53 h = tan( angle ) * distance;
54 vertex.z = h - midpoint;
55 gl_Position = gl_ModelViewProjectionMatrix * vertex;