Project

General

Profile

« Previous | Next » 

Revision 99a80c08

Added by Leszek Koltunski over 1 year ago

Minor.

View differences:

src/main/java/org/distorted/examples/flatblur2/FlatBlur2Renderer.java
19 19

  
20 20
package org.distorted.examples.flatblur2;
21 21

  
22
import android.content.res.Resources;
22 23
import android.opengl.GLSurfaceView;
23 24

  
25
import org.distorted.library.effect.EffectQuality;
26
import org.distorted.library.effect.EffectType;
27
import org.distorted.library.effect.MatrixEffectRotate;
28
import org.distorted.library.effect.MatrixEffectScale;
24 29
import org.distorted.library.effect.PostprocessEffectGlow;
25
import org.distorted.library.effect.VertexEffectScale;
26 30
import org.distorted.library.main.DistortedEffects;
27 31
import org.distorted.library.main.DistortedLibrary;
28 32
import org.distorted.library.main.DistortedNode;
29 33
import org.distorted.library.main.DistortedScreen;
30 34
import org.distorted.library.main.DistortedTexture;
35
import org.distorted.library.mesh.MeshCubes;
31 36
import org.distorted.library.mesh.MeshQuad;
37

  
38
import org.distorted.library.message.EffectListener;
39
import org.distorted.library.type.Dynamic2D;
40
import org.distorted.library.type.Dynamic4D;
41
import org.distorted.library.type.Static1D;
32 42
import org.distorted.library.type.Static2D;
43
import org.distorted.library.type.Static3D;
33 44
import org.distorted.library.type.Static4D;
34 45

  
35 46
import javax.microedition.khronos.egl.EGLConfig;
......
37 48

  
38 49
///////////////////////////////////////////////////////////////////////////////////////////////////
39 50

  
40
class FlatBlur2Renderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
51
class FlatBlur2Renderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener, ListenerOverlay, EffectListener
41 52
{
42 53
    private final GLSurfaceView mView;
43 54
    private final DistortedScreen mScreen;
44
    private final DistortedNode mNode;
55
    private Static3D mScale1, mScale2;
56
    private DistortedNode mNode;
45 57

  
46 58
///////////////////////////////////////////////////////////////////////////////////////////////////
47 59

  
......
49 61
      {
50 62
      mView = v;
51 63
      mScreen = new DistortedScreen();
52

  
53
      DistortedTexture texture1 = new DistortedTexture();
54
      texture1.setColorARGB(0xffff0000);
55
      MeshQuad mesh1 = new MeshQuad();
56
      DistortedEffects effects1 = new DistortedEffects();
57
      VertexEffectScale mainScale= new VertexEffectScale(200);
58
      effects1.apply(mainScale);
59
      mNode = new DistortedNode(texture1,effects1,mesh1);
60
      mScreen.attach(mNode);
61

  
62
      DistortedTexture texture2 = new DistortedTexture();
63
      texture2.setColorARGB(0xffff0000);
64
      MeshQuad mesh2 = new MeshQuad();
65
      DistortedEffects effects2 = new DistortedEffects();
66
      DistortedNode node2 = new DistortedNode(texture2,effects2,mesh2);
67
      mScreen.attach(node2);
68 64
      }
69 65

  
70 66
///////////////////////////////////////////////////////////////////////////////////////////////////
......
78 74

  
79 75
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
80 76
      {
77
      float s = width*0.05f;
78
      mScale1.set(width,width,0);
79
      mScale2.set(s,s,s);
81 80
      mScreen.resize(width,height);
82 81
      }
83 82

  
......
85 84
    
86 85
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
87 86
      {
88
      VertexEffectScale.enable();
89
      PostprocessEffectGlow.enable();
87
      DistortedTexture surface1 = new DistortedTexture();
88
      surface1.setColorARGB(0xffff0000);
89
      MeshQuad mesh1 = new MeshQuad();
90
      DistortedEffects effects1 = new DistortedEffects();
91

  
92
      mScale1 = new Static3D(1,1,1);
93
      MatrixEffectScale scale1 = new MatrixEffectScale(mScale1);
94
      effects1.apply(scale1);
95
      mNode = new DistortedNode(surface1,effects1,mesh1);
96
      mScreen.attach(mNode);
97

  
98
      DistortedTexture surface2 = new DistortedTexture();
99
      surface2.setColorARGB(0xff0000ff);
100
      MeshCubes mesh2 = new MeshCubes(2,2,2);
101
      DistortedEffects effects2 = new DistortedEffects();
102

  
103
      mScale2 = new Static3D(1,1,1);
104
      MatrixEffectScale scale2 = new MatrixEffectScale(mScale2);
105
      effects2.apply(scale2);
106
      Static1D angle = new Static1D(30);
107
      float SQ3 = (float)Math.sqrt(3);
108
      Static3D axis = new Static3D(SQ3/3,SQ3/3,SQ3/3);
109
      Static3D center = new Static3D(0,0,0);
110
      MatrixEffectRotate rot = new MatrixEffectRotate(angle,axis,center);
111
      effects2.apply(rot);
112
      DistortedNode node2 = new DistortedNode(surface2,effects2,mesh2);
113
      mNode.attach(node2);
114

  
115
      OverlayStars.enableEffects();
90 116
      DistortedLibrary.onSurfaceCreated( mView.getContext(), this);
91 117
      }
92 118

  
......
99 125

  
100 126
///////////////////////////////////////////////////////////////////////////////////////////////////
101 127

  
102
    public void crash()
128
    public void button1()
103 129
      {
104
      Static2D haloRadius = new Static2D(15,50);
105
      Static4D color      = new Static4D(1,1,1,1);
106
      PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
130
      OverlayStars stars = new OverlayStars();
131
      Resources res = mView.getResources();
132
      DataStars data  = new DataStars(10,5,res);
133
      stars.startOverlay(mScreen,this,data);
134
      }
135

  
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

  
138
    public void button2()
139
      {
140
      PostprocessEffectGlow glow = constructGlow();
107 141
      DistortedEffects effects = mNode.getEffects();
108 142
      effects.apply(glow);
109 143
      }
144

  
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

  
147
   private PostprocessEffectGlow constructGlow()
148
      {
149
      final int DUR_GLO = 3000;
150
      Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,0.5f);
151
      Static2D point20 = new Static2D( 0, 0);
152
      Static2D point21 = new Static2D(15,50);
153
      Dynamic4D color = new Dynamic4D(DUR_GLO, 0.5f);
154
      Static4D point40 = new Static4D(1,1,1,0.0f);
155
      Static4D point41 = new Static4D(1,1,1,0.8f);
156

  
157
      haloRadius.add(point20);
158
      haloRadius.add(point21);
159
      haloRadius.add(point20);
160
      color.add(point40);
161
      color.add(point41);
162
      color.add(point40);
163

  
164
      PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
165
      glow.setQuality(EffectQuality.MEDIUM);
166
      glow.notifyWhenFinished(this);
167
      return glow;
168
      }
169

  
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

  
172
    public void overlayFinished(long id)
173
      {
174

  
175
      }
176

  
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

  
179
    public void effectFinished(long id)
180
      {
181
      DistortedEffects effects = mNode.getEffects();
182
      effects.abortByType(EffectType.POSTPROCESS);
183
      }
110 184
}

Also available in: Unified diff