Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / MatrixEffect.java @ 15aa7d94

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 org.distorted.library.type.*;
23

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
// MATRIX EFFECTS.
26
// 7 Uniforms: 4 per-effect interpolated values + 3 dimensional center.
27

    
28
public abstract class MatrixEffect extends Effect
29
  {
30
  public static final int NUM_UNIFORMS = 7;
31

    
32
  public static final int MOVE       = 0;
33
  public static final int SCALE      = 1;
34
  public static final int ROTATE     = 2;
35
  public static final int QUATERNION = 3;
36
  public static final int SHEAR      = 4;
37
  public static final int NUM_EFFECTS= 5;
38

    
39
  static final int MAX = 5;
40
  private static final int MAX_UNITY_DIM = 3;
41

    
42
  Dynamic mDynamic0,mDynamic1;
43
  Static  mStatic0 , mStatic1;
44
  Dynamic3D mDynamicCenter;
45
  Static3D mStaticCenter;
46

    
47
  private final static float[] mUnity= new float[MAX_UNITY_DIM*NUM_EFFECTS];
48
  private final static int[]   mUnityDim = new int[NUM_EFFECTS];
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
  public MatrixEffect(int name, float[] unity, int dimension, boolean center, boolean region)
53
    {
54
    super(MATRIX,name,dimension,center,region);
55

    
56
    for(int i=0; i<unity.length; i++)
57
      {
58
      mUnity[name*MAX_UNITY_DIM+i] = unity[i];
59
      }
60

    
61
    mUnityDim[name] = unity.length;
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  public static boolean isUnity(int name, float[] buffer, int index)
67
    {
68
    switch(mUnityDim[name])
69
      {
70
      case 0: return true;
71
      case 1: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ];
72
      case 2: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
73
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1];
74
      case 3: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
75
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
76
                     buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2];
77
      case 4: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
78
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
79
                     buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2] &&
80
                     buffer[index+3]==mUnity[MAX_UNITY_DIM*name+3];
81
      }
82

    
83
    return false;
84
    }
85
  }
(8-8/23)