Project

General

Profile

Download (4.66 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / effect / MatrixEffectShear.java @ c1fa9e3c

1 2014665f leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2017 Leszek Koltunski                                                               //
3
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 2014665f leszek
//                                                                                               //
6 46b572b5 Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 2014665f leszek
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11 46b572b5 Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 2014665f leszek
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17 46b572b5 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 2014665f leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.library.effect;
21
22 227b03bd Leszek Koltunski
import android.opengl.Matrix;
23
24 6d62a900 Leszek Koltunski
import org.distorted.library.type.Data3D;
25
26 2014665f leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
27 faa3ff56 Leszek Koltunski
/**
28
 * Shear the Mesh.
29
 */
30 2014665f leszek
public class MatrixEffectShear extends MatrixEffect
31
  {
32 0dd98279 Leszek Koltunski
  private Data3D mShear, mCenter;
33
34 2014665f leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
35 6bb59aad Leszek Koltunski
/**
36 faa3ff56 Leszek Koltunski
 * Only for use by the library itself.
37 6bb59aad Leszek Koltunski
 *
38 faa3ff56 Leszek Koltunski
 * @y.exclude
39 6bb59aad Leszek Koltunski
 */
40 15aa7d94 Leszek Koltunski
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
41
    {
42 e979d285 Leszek Koltunski
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
43 0dd98279 Leszek Koltunski
    return mShear.get(uniforms,index,currentDuration,step);
44 2014665f leszek
    }
45 227b03bd Leszek Koltunski
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47 faa3ff56 Leszek Koltunski
/**
48
 * Only for use by the library itself.
49
 *
50
 * @y.exclude
51
 */
52 227b03bd Leszek Koltunski
  public void apply(float[] matrix, float[] uniforms, int index)
53
    {
54
    float sx = uniforms[NUM_UNIFORMS*index  ];
55
    float sy = uniforms[NUM_UNIFORMS*index+1];
56
    float sz = uniforms[NUM_UNIFORMS*index+2];
57
58 e979d285 Leszek Koltunski
    float x  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET  ];
59
    float y  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+1];
60
    float z  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+2];
61 227b03bd Leszek Koltunski
62 7bebb196 Leszek Koltunski
    Matrix.translateM(matrix, 0, x, y, z);
63 227b03bd Leszek Koltunski
64
    matrix[4] += sx*matrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear.
65
    matrix[5] += sx*matrix[1]; //                        0 1 0 0
66
    matrix[6] += sx*matrix[2]; //                        0 0 1 0
67
    matrix[7] += sx*matrix[3]; //                        0 0 0 1
68
69
    matrix[0] += sy*matrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear.
70
    matrix[1] += sy*matrix[5]; //                        y 1 0 0
71
    matrix[2] += sy*matrix[6]; //                        0 0 1 0
72
    matrix[3] += sy*matrix[7]; //                        0 0 0 1
73
74
    matrix[4] += sz*matrix[8]; // Multiply viewMatrix by 1 0 0 0 , i.e. Z-shear.
75
    matrix[5] += sz*matrix[9]; //                        0 1 0 0
76
    matrix[6] += sz*matrix[10];//                        0 z 1 0
77
    matrix[7] += sz*matrix[11];//                        0 0 0 1
78
79 7bebb196 Leszek Koltunski
    Matrix.translateM(matrix, 0,-x,-y,-z);
80 227b03bd Leszek Koltunski
    }
81 faa3ff56 Leszek Koltunski
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
// PUBLIC API
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
/**
86
 * Shear the Mesh.
87
 *
88
 * @param shear   The 3-tuple of shear factors. The first controls level
89
 *                of shearing in the X-axis, second - Y-axis and the third -
90 2fef9669 Leszek Koltunski
 *                Z-axis. Each is the tangent of the shear angle, i.e 0 -
91 faa3ff56 Leszek Koltunski
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
92
 * @param center  Center of shearing, i.e. the point which stays unmoved.
93
 */
94
  public MatrixEffectShear(Data3D shear, Data3D center)
95
    {
96
    super(EffectName.SHEAR);
97
    mShear = shear;
98
    mCenter = center;
99
    }
100 2014665f leszek
  }