Project

General

Profile

« Previous | Next » 

Revision fa9b6494

Added by Leszek Koltunski almost 7 years ago

Convert the first few Apps to the new Effect API.

View differences:

src/main/java/org/distorted/examples/catanddog/CatAndDogRenderer.java
26 26
import javax.microedition.khronos.opengles.GL10;
27 27

  
28 28
import org.distorted.examples.R;
29
import org.distorted.library.effect.EffectName;
30
import org.distorted.library.effect.FragmentEffectAlpha;
31
import org.distorted.library.effect.FragmentEffectChroma;
32
import org.distorted.library.effect.MatrixEffectMove;
33
import org.distorted.library.effect.MatrixEffectRotate;
34
import org.distorted.library.effect.MatrixEffectScale;
29 35
import org.distorted.library.main.Distorted;
30 36
import org.distorted.library.main.DistortedEffects;
31 37
import org.distorted.library.main.DistortedScreen;
32 38
import org.distorted.library.main.DistortedTexture;
33
import org.distorted.library.EffectNames;
34 39
import org.distorted.library.main.MeshFlat;
35
import org.distorted.library.EffectTypes;
36 40
import org.distorted.library.type.Dynamic1D;
37 41
import org.distorted.library.type.Dynamic3D;
38 42
import org.distorted.library.type.Static1D;
......
47 51

  
48 52
class CatAndDogRenderer implements GLSurfaceView.Renderer
49 53
{
54
    private static final int DURATION = 10000;  // 10 seconds
55

  
50 56
    private GLSurfaceView mView;
51 57
    private DistortedEffects mEffects;
52 58
    private MeshFlat mMesh;
53 59
    private DistortedTexture mTexture;
54 60
    private DistortedScreen mScreen;
55
    private int bmpHeight, bmpWidth;
61
    private int mObjHeight, mObjWidth;
62
    private Static3D mMove, mRotate;
56 63

  
57 64
///////////////////////////////////////////////////////////////////////////////////////////////////
58 65

  
......
63 70
      mMesh = new MeshFlat(1,1);  // no vertex effects, grid can be a (1x1) quad.
64 71
      mEffects = new DistortedEffects();
65 72

  
73
      Dynamic3D move   = new Dynamic3D(DURATION,0.0f);
74
      mRotate = new Static3D(0,0,0);
75
      mMove   = new Static3D(0,0,0);
76
      Static3D move2  = new Static3D(0,0,0);
77

  
78
      move.add(mMove);
79
      move.add(move2);
80

  
66 81
      Static4D chromaRegion= new Static4D( 530, 200,100,100);
67 82
      Static4D alphaRegion = new Static4D( 230, 200,100,100);
68 83

  
69 84
      Dynamic1D chromaDyn = new Dynamic1D(3000,0.0f);
70 85
      chromaDyn.add(new Static1D(1));
71 86
      chromaDyn.add(new Static1D(0));
72

  
73
      mEffects.chroma(chromaDyn, new Static3D(1,0,0), chromaRegion ,true);
74

  
75 87
      Dynamic1D alphaDyn = new Dynamic1D(3000,0.0f);
76 88
      alphaDyn.add(new Static1D(1));
77 89
      alphaDyn.add(new Static1D(0));
90
      Dynamic3D diScale = new Dynamic3D(DURATION,0.0f);
91
      diScale.add(new Static3D(1,1,1));
92
      diScale.add(new Static3D(0.33f,0.33f,1));
93
      Dynamic1D diRotate = new Dynamic1D(DURATION,0.0f);
94
      diRotate.add(new Static1D(  0));
95
      diRotate.add(new Static1D(360));
78 96

  
79
      mEffects.alpha( alphaDyn, alphaRegion, false );
97
      mEffects.apply( new FragmentEffectChroma( chromaDyn, new Static3D(1,0,0), chromaRegion ,true) );
98
      mEffects.apply( new FragmentEffectAlpha(alphaDyn, alphaRegion, false) );
99
      mEffects.apply( new MatrixEffectMove(mMove));
100
      mEffects.apply( new MatrixEffectScale(diScale));
101
      mEffects.apply( new MatrixEffectRotate( diRotate, new Static3D(0,0,1), mRotate) );
80 102

  
81 103
      mScreen = new DistortedScreen(mView);
82 104
      }
83 105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

  
108
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
109
      {
110
      mMove.set(width-mObjWidth,height-mObjHeight,0);
111
      mRotate.set(mObjWidth/2,mObjHeight/2,0);
112
      mScreen.resize(width, height);
113
      }
84 114
///////////////////////////////////////////////////////////////////////////////////////////////////
85 115
   
86 116
    public void onDrawFrame(GL10 glUnused) 
......
108 138
        catch(IOException e) { }
109 139
        }  
110 140
      
111
      bmpHeight = bitmap.getHeight();
112
      bmpWidth  = bitmap.getWidth();
141
      mObjHeight = bitmap.getHeight();
142
      mObjWidth  = bitmap.getWidth();
113 143

  
114
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
144
      if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
115 145
      mTexture.setTexture(bitmap);
116 146

  
117 147
      mScreen.detachAll();
118 148
      mScreen.attach(mTexture,mEffects,mMesh);
119 149

  
120
      DistortedEffects.enableEffect(EffectNames.SMOOTH_CHROMA);
121
      DistortedEffects.enableEffect(EffectNames.ALPHA);
150
      DistortedEffects.enableEffect(EffectName.SMOOTH_CHROMA);
151
      DistortedEffects.enableEffect(EffectName.ALPHA);
122 152

  
123 153
      try
124 154
        {
......
129 159
        android.util.Log.e("Renderer", ex.getMessage() );
130 160
        }
131 161
      }
132
    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
    
135
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
136
      {
137
      int duration = 10000;   // 10 seconds
138
      
139
      Dynamic3D diMove = new Dynamic3D(duration,0.0f);
140
      diMove.add(new Static3D(width-bmpWidth,height-bmpHeight,0));
141
      diMove.add(new Static3D(0,0,0));
142
      
143
      Dynamic3D diScale = new Dynamic3D(duration,0.0f);
144
      diScale.add(new Static3D(1,1,1));
145
      diScale.add(new Static3D(0.33f,0.33f,1));
146
      
147
      Dynamic1D diRotate = new Dynamic1D(duration,0.0f);
148
      diRotate.add(new Static1D(  0));
149
      diRotate.add(new Static1D(360));
150
      
151
      mEffects.abortEffects(EffectTypes.MATRIX);
152

  
153
      mEffects.move(diMove);
154
      mEffects.scale(diScale);
155
      mEffects.rotate( diRotate, new Static3D(0,0,1), new Static3D(bmpWidth/2,bmpHeight/2,0) );
156

  
157
      mScreen.resize(width, height);
158
      }
159 162
}

Also available in: Unified diff