Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import android.opengl.Matrix;
23

    
24
import org.distorted.library.type.Data3D;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27
/**
28
 * Shear the Mesh.
29
 */
30
public class MatrixEffectShear extends MatrixEffect
31
  {
32
  private Data3D mShear, mCenter;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
/**
36
 * Only for use by the library itself.
37
 *
38
 * @y.exclude
39
 */
40
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
41
    {
42
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
43
    return mShear.get(uniforms,index,currentDuration,step);
44
    }
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
/**
48
 * Only for use by the library itself.
49
 *
50
 * @y.exclude
51
 */
52
  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
    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

    
62
    Matrix.translateM(matrix, 0, x, y, z);
63

    
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
    Matrix.translateM(matrix, 0,-x,-y,-z);
80
    }
81

    
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
 *                Z-axis. Each is the tangent of the shear angle, i.e 0 -
91
 *                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
  }
(16-16/31)