~linaro-graphics-wg/compiz-plugins-main/oneiric-gles2

« back to all changes in this revision

Viewing changes to animation/src/transform.cpp

  • Committer: Sam Spilsbury
  • Date: 2011-09-20 07:43:55 UTC
  • Revision ID: sam.spilsbury@canonical.com-20110920074355-puzdutejjwsu3ta2
Sync - Remove Plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Animation plugin for compiz
3
 
 *
4
 
 * transform.cpp
5
 
 *
6
 
 * Copyright : (C) 2006 Erkin Bahceci
7
 
 * E-mail    : erkinbah@gmail.com
8
 
 *
9
 
 * Based on Wobbly and Minimize plugins by
10
 
 *           : David Reveman
11
 
 * E-mail    : davidr@novell.com>
12
 
 *
13
 
 * Particle system added by : (C) 2006 Dennis Kasprzyk
14
 
 * E-mail                   : onestone@beryl-project.org
15
 
 *
16
 
 * Beam-Up added by : Florencio Guimaraes
17
 
 * E-mail           : florencio@nexcorp.com.br
18
 
 *
19
 
 * Hexagon tessellator added by : Mike Slegeir
20
 
 * E-mail                       : mikeslegeir@mail.utexas.edu>
21
 
 *
22
 
 * This program is free software; you can redistribute it and/or
23
 
 * modify it under the terms of the GNU General Public License
24
 
 * as published by the Free Software Foundation; either version 2
25
 
 * of the License, or (at your option) any later version.
26
 
 *
27
 
 * This program is distributed in the hope that it will be useful,
28
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 
 * GNU General Public License for more details.
31
 
 *
32
 
 * You should have received a copy of the GNU General Public License
33
 
 * along with this program; if not, write to the Free Software
34
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
35
 
 */
36
 
 
37
 
#include "private.h"
38
 
 
39
 
TransformAnim::TransformAnim (CompWindow *w,
40
 
                              WindowEvent curWindowEvent,
41
 
                              float duration,
42
 
                              const AnimEffect info,
43
 
                              const CompRect &icon) :
44
 
    Animation::Animation (w, curWindowEvent, duration, info, icon),
45
 
    mTransformStartProgress (0.0f),
46
 
    mTransformProgress (0.0f)
47
 
{
48
 
}
49
 
 
50
 
void
51
 
TransformAnim::init ()
52
 
{
53
 
    adjustDuration ();
54
 
}
55
 
 
56
 
void
57
 
TransformAnim::updateBB (CompOutput &output)
58
 
{
59
 
    GLMatrix wTransform;
60
 
 
61
 
    prepareTransform (output, wTransform, mTransform);
62
 
 
63
 
    CompRect outRect (mAWindow->savedRectsValid () ?
64
 
                      mAWindow->savedOutRect () :
65
 
                      mWindow->outputRect ());
66
 
    float corners[4*3] = {
67
 
        outRect.x (), outRect.y (), 0,
68
 
        outRect.x () + outRect.width (), outRect.y (), 0,
69
 
        outRect.x (), outRect.y () + outRect.height (), 0,
70
 
        outRect.x () + outRect.width (), outRect.y () + outRect.height (), 0
71
 
    };
72
 
    mAWindow->expandBBWithPoints3DTransform (output,
73
 
                                             wTransform,
74
 
                                             corners,
75
 
                                             0,
76
 
                                             4);
77
 
}
78
 
 
79
 
void
80
 
TransformAnim::step ()
81
 
{
82
 
    mTransform.reset ();
83
 
    applyTransform ();
84
 
}
85
 
 
86
 
void
87
 
TransformAnim::updateTransform (GLMatrix &wTransform)
88
 
{
89
 
    wTransform *= mTransform;
90
 
}
91
 
 
92
 
/// Scales z by 0 and does perspective distortion so that it
93
 
/// looks the same wherever on the screen.
94
 
void
95
 
TransformAnim::perspectiveDistortAndResetZ (GLMatrix &transform)
96
 
{
97
 
    float v = -1.0 / ::screen->width ();
98
 
    /*
99
 
      This does
100
 
      transform = M * transform, where M is
101
 
      1, 0, 0, 0,
102
 
      0, 1, 0, 0,
103
 
      0, 0, 0, v,
104
 
      0, 0, 0, 1
105
 
    */
106
 
 
107
 
    transform[8] = v * transform[12];
108
 
    transform[9] = v * transform[13];
109
 
    transform[10] = v * transform[14];
110
 
    transform[11] = v * transform[15];
111
 
}
112
 
 
113
 
void
114
 
TransformAnim::applyPerspectiveSkew (CompOutput &output,
115
 
                                     GLMatrix &transform,
116
 
                                     Point &center)
117
 
{
118
 
    GLfloat skewx = -(((center.x () - output.region ()->extents.x1) -
119
 
                       output.width () / 2) * 1.15);
120
 
    GLfloat skewy = -(((center.y () - output.region ()->extents.y1) -
121
 
                       output.height () / 2) * 1.15);
122
 
 
123
 
    /* transform = M * transform, where M is the skew matrix
124
 
        {1,0,0,0,
125
 
         0,1,0,0,
126
 
         skewx,skewy,1,0,
127
 
         0,0,0,1};
128
 
    */
129
 
 
130
 
    transform[8] = skewx * transform[0] + skewy * transform[4] + transform[8];
131
 
    transform[9] = skewx * transform[1] + skewy * transform[5] + transform[9];
132
 
    transform[10] = skewx * transform[2] + skewy * transform[6] + transform[10];
133
 
    transform[11] = skewx * transform[3] + skewy * transform[7] + transform[11];
134
 
}
135
 
 
136
 
Point
137
 
TransformAnim::getCenter ()
138
 
{
139
 
    CompRect inRect (mAWindow->savedRectsValid () ?
140
 
                     mAWindow->savedInRect () :
141
 
                     mWindow->borderRect ());
142
 
    Point center (inRect.x () + inRect.width () / 2,
143
 
                  inRect.y () + inRect.height () / 2);
144
 
    return center;
145
 
}
146