Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / MatrixEffect.java @ 310e14fb

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 MOVE       = 0;
31
  public static final int SCALE      = 1;
32
  public static final int ROTATE     = 2;
33
  public static final int QUATERNION = 3;
34
  public static final int SHEAR      = 4;
35
  public static final int NUM_EFFECTS= 5;
36

    
37
  static final int MAX = 5;
38
  private static final int MAX_UNITY_DIM = 3;
39

    
40
  Dynamic mDynamic0,mDynamic1;
41
  Static  mStatic0 , mStatic1;
42
  Data3D mCenter;
43

    
44
  private final static float[] mUnity= new float[MAX_UNITY_DIM*NUM_EFFECTS];
45
  private final static int[]   mUnityDim = new int[NUM_EFFECTS];
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  public MatrixEffect(int name, float[] unity, int dimension, boolean center, boolean region)
50
    {
51
    super(MATRIX,name,dimension,center,region);
52

    
53
    for(int i=0; i<unity.length; i++)
54
      {
55
      mUnity[name*MAX_UNITY_DIM+i] = unity[i];
56
      }
57

    
58
    mUnityDim[name] = unity.length;
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  public static boolean isUnity(int name, float[] buffer, int index)
64
    {
65
    switch(mUnityDim[name])
66
      {
67
      case 0: return true;
68
      case 1: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ];
69
      case 2: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
70
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1];
71
      case 3: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
72
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
73
                     buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2];
74
      case 4: 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
                     buffer[index+3]==mUnity[MAX_UNITY_DIM*name+3];
78
      }
79

    
80
    return false;
81
    }
82
  }
(14-14/29)