Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / MatrixEffectScale.java @ 8c57d77b

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2017 Leszek Koltunski  leszek@koltunski.pl                                          //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// This library is free software; you can redistribute it and/or                                 //
7
// modify it under the terms of the GNU Lesser General Public                                    //
8
// License as published by the Free Software Foundation; either                                  //
9
// version 2.1 of the License, or (at your option) any later version.                            //
10
//                                                                                               //
11
// This library 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 GNU                             //
14
// Lesser General Public License for more details.                                               //
15
//                                                                                               //
16
// You should have received a copy of the GNU Lesser General Public                              //
17
// License along with this library; if not, write to the Free Software                           //
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

    
21
package org.distorted.library.effect;
22

    
23
import android.opengl.Matrix;
24

    
25
import org.distorted.library.type.Data3D;
26
import org.distorted.library.type.Static3D;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29
/**
30
 * Scale the Mesh by 3D scale factors.
31
 */
32
public class MatrixEffectScale extends MatrixEffect
33
  {
34
  private final Data3D mScale;
35

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

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
/**
49
 * Only for use by the library itself.
50
 * <p>
51
 * Here and in Shear we have the whole reason why there are two separate 'P' and 'V' (Point and
52
 * Vector) matrices - Scale and Shear have to manipulate Points and Normal Vectors differently.
53
 *
54
 * Points get multiplied by (sx,sy,sz) - and vectors by (1/sx,1/sy,1/sz) (think about it!) - or
55
 * better by sx*sy*sz*(1/sx,1/sy,1/sz) to avoid dividing my zero (vectors are normalized after)
56
 *
57
 * @y.exclude
58
 */
59
  public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index)
60
    {
61
    float sx = uniforms[NUM_FLOAT_UNIFORMS*index  ];
62
    float sy = uniforms[NUM_FLOAT_UNIFORMS*index+1];
63
    float sz = uniforms[NUM_FLOAT_UNIFORMS*index+2];
64

    
65
    Matrix.scaleM(matrixP, 0, sx, sy, sz);
66
    Matrix.scaleM(matrixV, 0, sy*sz, sx*sz, sx*sy);
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
// PUBLIC API
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
/**
73
 * Scale the Mesh by 3D scale factors.
74
 *
75
 * @param scale current x- , y- and z- scale factors.
76
 */
77
  public MatrixEffectScale(Data3D scale)
78
    {
79
    super(EffectName.SCALE);
80
    mScale = scale;
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84
/**
85
 * Scale the Mesh by 3D scale factors.
86
 *
87
 * @param scale Common x,y, and z scale factor.
88
 */
89
  public MatrixEffectScale(float scale)
90
    {
91
    super(EffectName.SCALE);
92
    mScale = new Static3D(scale,scale,scale);
93
    }
94
  }
(15-15/34)