Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / MatrixEffectShear.java @ 8e28b6ff

1 2014665f leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2017 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// 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
// Distorted is distributed in the hope that it will be useful,                                  //
12
// 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
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
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
28
public class MatrixEffectShear extends MatrixEffect
29
  {
30 0dd98279 Leszek Koltunski
  private Data3D mShear, mCenter;
31
32 2014665f leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
33 6bb59aad Leszek Koltunski
/**
34
 * Shears the Object.
35
 *
36
 * @param shear   The 3-tuple of shear factors. The first controls level
37
 *                of shearing in the X-axis, second - Y-axis and the third -
38
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
39
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
40
 * @param center  Center of shearing, i.e. the point which stays unmoved.
41
 */
42 6d62a900 Leszek Koltunski
  public MatrixEffectShear(Data3D shear, Data3D center)
43 2014665f leszek
    {
44 9d0d8530 leszek
    super(EffectName.SHEAR);
45 0dd98279 Leszek Koltunski
    mShear = shear;
46
    mCenter = center;
47 15aa7d94 Leszek Koltunski
    }
48
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
51
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
52
    {
53 0dd98279 Leszek Koltunski
    mCenter.get(uniforms,index+4,currentDuration,step);
54
    return mShear.get(uniforms,index,currentDuration,step);
55 2014665f leszek
    }
56 227b03bd Leszek Koltunski
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
59
  public void apply(float[] matrix, float[] uniforms, int index)
60
    {
61
    float sx = uniforms[NUM_UNIFORMS*index  ];
62
    float sy = uniforms[NUM_UNIFORMS*index+1];
63
    float sz = uniforms[NUM_UNIFORMS*index+2];
64
65
    float x  = uniforms[NUM_UNIFORMS*index+4];
66
    float y  = uniforms[NUM_UNIFORMS*index+5];
67
    float z  = uniforms[NUM_UNIFORMS*index+6];
68
69
    Matrix.translateM(matrix, 0, x,-y, z);
70
71
    matrix[4] += sx*matrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear.
72
    matrix[5] += sx*matrix[1]; //                        0 1 0 0
73
    matrix[6] += sx*matrix[2]; //                        0 0 1 0
74
    matrix[7] += sx*matrix[3]; //                        0 0 0 1
75
76
    matrix[0] += sy*matrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear.
77
    matrix[1] += sy*matrix[5]; //                        y 1 0 0
78
    matrix[2] += sy*matrix[6]; //                        0 0 1 0
79
    matrix[3] += sy*matrix[7]; //                        0 0 0 1
80
81
    matrix[4] += sz*matrix[8]; // Multiply viewMatrix by 1 0 0 0 , i.e. Z-shear.
82
    matrix[5] += sz*matrix[9]; //                        0 1 0 0
83
    matrix[6] += sz*matrix[10];//                        0 z 1 0
84
    matrix[7] += sz*matrix[11];//                        0 0 0 1
85
86
    Matrix.translateM(matrix, 0,-x, y, -z);
87
    }
88 2014665f leszek
  }