Project

General

Profile

« Previous | Next » 

Revision 6173632c

Added by Leszek Koltunski almost 7 years ago

Further progress with Apps: 21 (out of 30) compile now.

View differences:

src/main/java/org/distorted/examples/olimpic/OlimpicRenderer.java
27 27

  
28 28
import org.distorted.examples.R;
29 29

  
30
import org.distorted.library.effect.EffectName;
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;
30 35
import org.distorted.library.main.DistortedEffects;
31 36
import org.distorted.library.main.DistortedScreen;
32 37
import org.distorted.library.main.DistortedNode;
33
import org.distorted.library.EffectNames;
34
import org.distorted.library.EffectTypes;
35 38
import org.distorted.library.main.MeshFlat;
36 39
import org.distorted.library.type.Dynamic1D;
37 40
import org.distorted.library.type.Static3D;
......
58 61
   private MeshFlat mMesh;
59 62
   private int mScreenW, mScreenH;
60 63
   private int mPrevRendered, mCurrRendered;
64
   private Static3D mMove, mScale;
61 65

  
62 66
   private DistortedNode[] mCircleNode = new DistortedNode[NUM_CIRCLES];
63 67
   private DistortedEffects[] mEffects = new DistortedEffects[NUM_LEAVES];
......
114 118
      for(int j=0; j<NUM_LEAVES; j++)
115 119
        {
116 120
        mEffects[j] = new DistortedEffects();
117
        mEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
118
        mEffects[j].move(moveVector);
121
        mEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, center) );
122
        mEffects[j].apply(new MatrixEffectMove(moveVector));
119 123
        }
120 124

  
121 125
      for(int i=0; i<NUM_CIRCLES; i++)
122 126
        {
123 127
        effects = new DistortedEffects();
124
        effects.move( new Static3D(positions[2*i], positions[2*i+1], 0) );
125
        effects.rotate( rot, axis, center );
126
        effects.chroma( new Static1D(0.5f), new Static3D(colors[3*i],colors[3*i+1], colors[3*i+2]) );
128
        effects.apply( new MatrixEffectMove(new Static3D(positions[2*i], positions[2*i+1], 0)) );
129
        effects.apply( new MatrixEffectRotate(rot, axis, center) );
130
        effects.apply( new FragmentEffectChroma(new Static1D(0.5f), new Static3D(colors[3*i],colors[3*i+1], colors[3*i+2])) );
127 131

  
128 132
        mCircleNode[i] = new DistortedNode( surface, effects, mMesh);
129 133
        mRoot.attach(mCircleNode[i]);
......
133 137

  
134 138
      mScreen = new DistortedScreen(mView);
135 139
      mScreen.attach(mRoot);
140

  
141
      mMove = new Static3D(0,0,0);
142
      mScale= new Static3D(1,1,1);
143
      effects.apply(new MatrixEffectMove(mMove));
144
      effects.apply(new MatrixEffectScale(mScale));
136 145
      }
137 146

  
138 147
///////////////////////////////////////////////////////////////////////////////////////////////////
139 148
   
140
    public void onDrawFrame(GL10 glUnused) 
141
      {
142
      mCurrRendered = mScreen.render(System.currentTimeMillis());
149
   public void onDrawFrame(GL10 glUnused)
150
     {
151
     mCurrRendered = mScreen.render(System.currentTimeMillis());
143 152

  
144
      if( mCurrRendered!=mPrevRendered )
145
        {
146
        mPrevRendered = mCurrRendered;
153
     if( mCurrRendered!=mPrevRendered )
154
       {
155
       mPrevRendered = mCurrRendered;
147 156

  
148
        final OlimpicActivity act = (OlimpicActivity)mView.getContext();
157
       final OlimpicActivity act = (OlimpicActivity)mView.getContext();
149 158

  
150
        act.runOnUiThread(new Runnable()
159
       act.runOnUiThread(new Runnable()
151 160
          {
152 161
          public void run()
153 162
            {
154
            act.setText("rendered: "+mCurrRendered+" objects");
155
            }
163
           act.setText("rendered: "+mCurrRendered+" objects");
164
           }
156 165
          });
157
        }
158
      }
166
       }
167
     }
159 168

  
160 169
///////////////////////////////////////////////////////////////////////////////////////////////////
161 170
    
162
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
163
      {
164
      DistortedEffects effects = mRoot.getEffects();
165

  
166
      effects.abortEffects(EffectTypes.MATRIX);
167
      
168
      if( (float)mScreenH/mScreenW > (float)height/width )
169
        {
170
        int w = (height*mScreenW)/mScreenH;
171
        float factor = (float)height/mScreenH;
172

  
173
        effects.move( new Static3D((width-w)/2 ,0, 0) );
174
        effects.scale( factor );
175
        }
176
      else
177
        {
178
        int h = (width*mScreenH)/mScreenW;
179
        float factor = (float)width/mScreenW;
180

  
181
        effects.move( new Static3D(0,(height-h)/2,0) );
182
        effects.scale( factor );
183
        }
171
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
172
     {
173
     if( (float)mScreenH/mScreenW > (float)height/width )
174
       {
175
       int w = (height*mScreenW)/mScreenH;
176
       float factor = (float)height/mScreenH;
177
       mMove.set((width-w)/2 ,0, 0);
178
       mScale.set(factor,factor,factor);
179
       }
180
     else
181
       {
182
       int h = (width*mScreenH)/mScreenW;
183
       float factor = (float)width/mScreenW;
184
       mMove.set(0,(height-h)/2,0);
185
       mScale.set(factor,factor,factor);
186
       }
184 187
      
185
      mScreen.resize(width, height);
186
      }
188
     mScreen.resize(width, height);
189
     }
187 190

  
188 191
///////////////////////////////////////////////////////////////////////////////////////////////////
189 192
    
190
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
191
      {
192
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
193
      Bitmap leaf;
193
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
194
     {
195
     InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
196
     Bitmap leaf;
194 197
      
195
      try 
196
        {
197
        leaf = BitmapFactory.decodeStream(is);
198
        } 
199
      finally 
200
        {
201
        try 
202
          {
203
          is.close();
204
          } 
205
        catch(IOException e) { }
206
        }  
198
     try
199
       {
200
       leaf = BitmapFactory.decodeStream(is);
201
       }
202
     finally
203
       {
204
       try
205
         {
206
         is.close();
207
         }
208
       catch(IOException e) { }
209
       }
207 210
      
208
      mLeaf.setTexture(leaf);
211
     mLeaf.setTexture(leaf);
209 212

  
210
      DistortedEffects.enableEffect(EffectNames.CHROMA);
213
     DistortedEffects.enableEffect(EffectName.CHROMA);
211 214

  
212
      try
213
        {
214
        Distorted.onCreate(mView.getContext());
215
        }
216
      catch(Exception ex)
217
        {
218
        android.util.Log.e("Olympic", ex.getMessage() );
219
        }
220
      }
221
 
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
    
215
     try
216
       {
217
       Distorted.onCreate(mView.getContext());
218
       }
219
     catch(Exception ex)
220
       {
221
       android.util.Log.e("Olympic", ex.getMessage() );
222
       }
223
     }
224 224
}

Also available in: Unified diff