Project

General

Profile

« Previous | Next » 

Revision 3a91bfe1

Added by Leszek Koltunski almost 7 years ago

Progress with GLOW.

Serious bug sorting Surface's children into postprocessing Buckets detected.

View differences:

src/main/java/org/distorted/examples/glow/GlowRenderer.java
26 26
import org.distorted.examples.R;
27 27
import org.distorted.library.Distorted;
28 28
import org.distorted.library.DistortedEffects;
29
import org.distorted.library.DistortedEffectsPostprocess;
29 30
import org.distorted.library.DistortedNode;
30 31
import org.distorted.library.DistortedScreen;
31 32
import org.distorted.library.DistortedTexture;
......
33 34
import org.distorted.library.EffectTypes;
34 35
import org.distorted.library.MeshFlat;
35 36
import org.distorted.library.MeshObject;
37
import org.distorted.library.message.EffectListener;
38
import org.distorted.library.message.EffectMessage;
36 39
import org.distorted.library.type.Dynamic1D;
40
import org.distorted.library.type.Dynamic4D;
37 41
import org.distorted.library.type.Static1D;
38 42
import org.distorted.library.type.Static3D;
43
import org.distorted.library.type.Static4D;
39 44

  
40 45
import java.io.IOException;
41 46
import java.io.InputStream;
......
45 50

  
46 51
///////////////////////////////////////////////////////////////////////////////////////////////////
47 52

  
48
class GlowRenderer implements GLSurfaceView.Renderer
53
class GlowRenderer implements GLSurfaceView.Renderer,EffectListener
49 54
{
50 55
   private static final int[] colors  = new int[] {0,0,1,  0,0,0,  1,0,0,  1,1,0,  0,1,0,  1,1,1}; // blue, black, red, yellow, green, white
51 56
   private static final int LEAF_SIZE = 100;
......
55 60
   private DistortedNode mRoot;
56 61
   private DistortedTexture mLeaf;
57 62
   private DistortedScreen mScreen;
63
   private DistortedEffectsPostprocess[] mLeafGlow = new DistortedEffectsPostprocess[NUM_LEAVES];
58 64
   private int mRootW, mRootH;
65
   private int mGlowing;
59 66

  
60 67
///////////////////////////////////////////////////////////////////////////////////////////////////
61 68

  
......
80 87

  
81 88
      for(int j=0; j<NUM_LEAVES; j++)
82 89
        {
90
        mLeafGlow[j] = new DistortedEffectsPostprocess();
91
        mLeafGlow[j].registerForMessages(this);
92

  
83 93
        leafEffects[j] = new DistortedEffects();
84 94
        leafEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
85 95
        leafEffects[j].move(moveVector);
86 96
        leafEffects[j].chroma( chromaLevel, new Static3D(colors[3*j],colors[3*j+1], colors[3*j+2]) );
87

  
88
        mRoot.attach( mLeaf, leafEffects[j], mesh);
97
        DistortedNode node = new DistortedNode( mLeaf, leafEffects[j], mesh);
98
        node.setPostprocessEffects(mLeafGlow[j]);
99
        mRoot.attach(node);
89 100
        }
90 101

  
102
      makeGlow(0);
103

  
91 104
      mScreen = new DistortedScreen(mView);
92 105
      mScreen.attach(mRoot);
93 106
      }
94 107

  
95 108
///////////////////////////////////////////////////////////////////////////////////////////////////
96
   
97
    public void onDrawFrame(GL10 glUnused) 
98
      {
99
      mScreen.render(System.currentTimeMillis());
100
      }
109

  
110
   private void makeGlow(int leaf)
111
     {
112
     //android.util.Log.e("glow", "glowing: "+leaf);
113

  
114
     mGlowing = leaf;
115

  
116
     Dynamic1D radius = new Dynamic1D(5000,1.0f);
117
     Static1D startR  = new Static1D( 0);
118
     Static1D endR    = new Static1D(50);
119
     radius.add(startR);
120
     radius.add(endR);
121

  
122
     Dynamic4D color  = new Dynamic4D(5000,1.0f);
123
     Static4D startC  = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 0);
124
     Static4D endC    = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 1);
125
     color.add(startC);
126
     color.add(endC);
127

  
128
     mLeafGlow[leaf].glow( radius, color );
129
     }
101 130

  
102 131
///////////////////////////////////////////////////////////////////////////////////////////////////
103
    
104
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
105
      {
106
      float qw = (float)width /mRootW;
107
      float qh = (float)height/mRootH;
108
      float factor = 0.6f* (qw<qh ? qw:qh);
109
      int w = (int)(factor*mRootW);
110
      int h = (int)(factor*mRootH);
111

  
112
      Dynamic1D rot = new Dynamic1D(5000,0.0f);
113
      rot.setMode(Dynamic1D.MODE_JUMP);
114
      rot.add(new Static1D(  0));
115
      rot.add(new Static1D(360));
116

  
117
      Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0);
118
      Static3D axis   = new Static3D(0,0,1);
119

  
120
      DistortedEffects effects = mRoot.getEffects();
121
      effects.abortEffects(EffectTypes.MATRIX);
122
      effects.move( new Static3D((width-w)/2 ,(height-h)/2, 0) );
123
      effects.scale( factor );
124
      effects.rotate( rot, axis, center );
125

  
126
      mScreen.resize(width, height);
127
      }
132
// Glow finished. Make the next Leaf glow.
133

  
134
   public void effectMessage(final EffectMessage em, final long effectID, final EffectNames effectName, final long objectID)
135
     {
136
     switch(em)
137
       {
138
       case EFFECT_FINISHED: //android.util.Log.e("glow", "effectMessage FINISHED");
139
                             int glowing = mGlowing+1;
140
                             if( glowing>=NUM_LEAVES ) glowing = 0;
141
                             makeGlow(glowing);
142
                             break;
143
       default:              //android.util.Log.e("glow", "effectMessage REMOVED");
144
                             break;
145
       }
146
     }
128 147

  
129 148
///////////////////////////////////////////////////////////////////////////////////////////////////
130
    
131
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
132
      {
133
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
134
      Bitmap leaf;
135
      
136
      try 
137
        {
138
        leaf = BitmapFactory.decodeStream(is);
139
        } 
140
      finally 
141
        {
142
        try 
143
          {
144
          is.close();
145
          } 
146
        catch(IOException e) { }
147
        }  
148
      
149
      mLeaf.setTexture(leaf);
150 149

  
151
      DistortedEffects.enableEffect(EffectNames.CHROMA);
152
      DistortedEffects.enableEffect(EffectNames.GLOW);
150
   public void onDrawFrame(GL10 glUnused)
151
     {
152
     mScreen.render(System.currentTimeMillis());
153
     }
154

  
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156
    
157
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
158
     {
159
     float qw = (float)width /mRootW;
160
     float qh = (float)height/mRootH;
161
     float factor = 0.6f* (qw<qh ? qw:qh);
162
     int w = (int)(factor*mRootW);
163
     int h = (int)(factor*mRootH);
164

  
165
     Dynamic1D rot = new Dynamic1D(5000,0.0f);
166
     rot.setMode(Dynamic1D.MODE_JUMP);
167
     rot.add(new Static1D(  0));
168
     rot.add(new Static1D(360));
169

  
170
     Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0);
171
     Static3D axis   = new Static3D(0,0,1);
172

  
173
     DistortedEffects effects = mRoot.getEffects();
174
     effects.abortEffects(EffectTypes.MATRIX);
175
     effects.move( new Static3D((width-w)/2 ,(height-h)/2, 0) );
176
     effects.scale( factor );
177
     effects.rotate( rot, axis, center );
178

  
179
     mScreen.resize(width, height);
180
     }
153 181

  
154
      try
155
        {
156
        Distorted.onCreate(mView.getContext());
157
        }
158
      catch(Exception ex)
159
        {
160
        android.util.Log.e("Glow", ex.getMessage() );
161
        }
162
      }
163
 
164 182
///////////////////////////////////////////////////////////////////////////////////////////////////
165 183
    
184
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
185
     {
186
     InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
187
     Bitmap leaf;
188
      
189
     try
190
       {
191
       leaf = BitmapFactory.decodeStream(is);
192
       }
193
     finally
194
       {
195
       try
196
         {
197
         is.close();
198
         }
199
       catch(IOException e) { }
200
       }
201
      
202
     mLeaf.setTexture(leaf);
203

  
204
     DistortedEffects.enableEffect(EffectNames.CHROMA);
205
     DistortedEffects.enableEffect(EffectNames.GLOW);
206

  
207
     try
208
       {
209
       Distorted.onCreate(mView.getContext());
210
       }
211
     catch(Exception ex)
212
       {
213
       android.util.Log.e("Glow", ex.getMessage() );
214
       }
215
     }
166 216
}

Also available in: Unified diff