Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectNames.java @ 476bbc81

1
package org.distorted.library;
2

    
3
///////////////////////////////////////////////////////////////////////////////////////////////////
4
/**
5
 * Names of Effects one can apply to DistortedObjects.
6
 */
7
public enum EffectNames
8
  {
9
  // EFFECT NAME /////// EFFECT TYPE ////////////// UNITY /////////////////////////
10
   
11
  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           ),
12
  QUATERNION       ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),      // quaternion is a unity iff its axis (x,y,z) is (0,0,0)
13
  MOVE             ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
14
  SCALE            ( EffectTypes.MATRIX  ,   new float[] {1.0f,1.0f,1.0f} ),
15
  SHEAR            ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
16
  // add new Matrix effects here...
17
  
18
  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),      // keep this the first VERT effect (reason: getType)
19
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      ),
20
  SINK             ( EffectTypes.VERTEX  ,   new float[] {1.0f}           ),
21
  SWIRL            ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
22
  WAVE             ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
23
  // add new Vertex Effects here...
24
  
25
  MACROBLOCK       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),      // keep this the first FRAG effect (reason: getType)
26
  ALPHA            ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
27
  SMOOTH_ALPHA     ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
28
  CHROMA           ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
29
  SMOOTH_CHROMA    ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
30
  BRIGHTNESS       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
31
  SMOOTH_BRIGHTNESS( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
32
  SATURATION       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
33
  SMOOTH_SATURATION( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
34
  CONTRAST         ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
35
  SMOOTH_CONTRAST  ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
36
  HUE              ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
37
  SMOOTH_HUE       ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
38
  // add new Fragment effects here...
39

    
40
  SAVE_PNG         ( EffectTypes.OTHER   ,   null                         ),      // OTHER Effects don't have Unities.
41
  SAVE_MP4         ( EffectTypes.OTHER   ,   null                         );      //
42
  // add new Other effects here...
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
  
46
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
47
  
48
  private EffectTypes type;
49
  private float[] unity;
50
  
51
  static private float[] unities;
52
  static private int[] dimensions;
53
  
54
  static
55
    {
56
    int len = values().length;
57
    int i=0;
58
    
59
    dimensions = new int[len];
60
    unities    = new float[MAXDIM*len];
61
    
62
    for(EffectNames name: EffectNames.values())
63
      {
64
      dimensions[i] = (name.unity==null ? 0 : name.unity.length);
65
      
66
      switch(dimensions[i])
67
        {
68
        case 4: unities[MAXDIM*i+3] = name.unity[3];
69
        case 3: unities[MAXDIM*i+2] = name.unity[2];
70
        case 2: unities[MAXDIM*i+1] = name.unity[1];
71
        case 1: unities[MAXDIM*i+0] = name.unity[0];
72
        case 0: break;
73
        }
74
      
75
      i++;  
76
      }
77
    }
78
  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80
  
81
  EffectNames(EffectTypes type, float[] unity)
82
    {
83
    this.type = type;  
84
    this.unity= unity;
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
// yes, I know we could have used values(i) but that allocates a new copy each time!
89

    
90
  static EffectTypes getType(int ordinal)
91
    {
92
    if( ordinal<DISTORT.ordinal()     ) return EffectTypes.MATRIX;
93
    if( ordinal<MACROBLOCK.ordinal()  ) return EffectTypes.VERTEX;
94
    if( ordinal<SAVE_PNG.ordinal()    ) return EffectTypes.FRAGMENT;
95

    
96
    return EffectTypes.OTHER;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  static void fillWithUnities(int ordinal, float[] buffer, int index)
102
    {
103
    switch(dimensions[ordinal])
104
      {
105
      case 0: break;
106
      case 1: buffer[index+0]=unities[MAXDIM*ordinal+0];
107
              break;
108
      case 2: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
109
              buffer[index+1]=unities[MAXDIM*ordinal+1];
110
              break;
111
      case 3: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
112
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
113
              buffer[index+2]=unities[MAXDIM*ordinal+2];
114
              break;
115
      case 4: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
116
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
117
              buffer[index+2]=unities[MAXDIM*ordinal+2];
118
              buffer[index+3]=unities[MAXDIM*ordinal+3];
119
              break;
120
      }  
121
    }
122
  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
  
125
  static boolean isUnity(int ordinal, float[] buffer, int index)
126
    {
127
    switch(dimensions[ordinal])
128
      {
129
      case 0: return true;
130
      case 1: return buffer[index+0]==unities[MAXDIM*ordinal+0];
131
      case 2: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
132
                     buffer[index+1]==unities[MAXDIM*ordinal+1];
133
      case 3: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
134
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
135
                     buffer[index+2]==unities[MAXDIM*ordinal+2];
136
      case 4: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
137
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
138
                     buffer[index+2]==unities[MAXDIM*ordinal+2] &&
139
                     buffer[index+3]==unities[MAXDIM*ordinal+3];
140
      }
141
   
142
    return false;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
// PUBLIC API
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148
/**
149
 * Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will
150
 * return EffectTypes.MATRIX.
151
 * @return type of the effect.
152
 */
153
  public EffectTypes getType()
154
    {
155
    return type;
156
    }
157
  }
(11-11/30)