Project

General

Profile

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

examples / src / main / java / org / distorted / examples / macroblock / MacroblockRenderer.java @ a8c3ada7

1
package org.distorted.examples.macroblock;
2

    
3
import java.io.IOException;
4
import java.io.InputStream;
5

    
6
import javax.microedition.khronos.egl.EGLConfig;
7
import javax.microedition.khronos.opengles.GL10;
8

    
9
import org.distorted.examples.R;
10
import org.distorted.library.Distorted;
11
import org.distorted.library.DistortedBitmap;
12
import org.distorted.library.EffectTypes;
13
import org.distorted.library.Interpolator1D;
14
import org.distorted.library.Interpolator3D;
15
import org.distorted.library.Float1D;
16
import org.distorted.library.Float2D;
17
import org.distorted.library.Float3D;
18
import org.distorted.library.Float4D;
19

    
20
import android.graphics.Bitmap;
21
import android.graphics.BitmapFactory;
22
import android.opengl.GLES20;
23
import android.opengl.GLSurfaceView;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

    
27
class MacroblockRenderer implements GLSurfaceView.Renderer 
28
{
29
    private GLSurfaceView mView;
30
    private DistortedBitmap macroblock;
31
    private Float4D Region;
32
    private int bmpHeight, bmpWidth;
33
    private Float2D traP, macP;
34
    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
    public MacroblockRenderer(GLSurfaceView v) 
38
      {   
39
      mView = v;
40
      
41
      Region = new Float4D(0,0,100,100);
42
      macP   = new Float2D(530,200);
43
      traP   = new Float2D(230,200);
44
      }
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
   
48
    public void onDrawFrame(GL10 glUnused) 
49
      {
50
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
51
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
52
   
53
      macroblock.draw(System.currentTimeMillis());
54
      }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
    
58
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
59
      {  
60
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.cat_and_dog);
61
      Bitmap bitmap;
62
        
63
      try 
64
        {
65
        bitmap = BitmapFactory.decodeStream(is);
66
        } 
67
      finally 
68
        {
69
        try 
70
          {
71
          is.close();
72
          } 
73
        catch(IOException e) { }
74
        }  
75
      
76
      bmpHeight = bitmap.getHeight();
77
      bmpWidth  = bitmap.getWidth();
78
      
79
      macroblock = new DistortedBitmap(bitmap, 30);    
80
      macroblock.macroblock(  30, Region, macP, 3000, 0.0f);
81
      macroblock.alpha     (0.0f, Region, traP, 3000, 0.0f);
82
      
83
      try
84
        {
85
        Distorted.onSurfaceCreated(mView.getContext());
86
        }
87
      catch(Exception ex)
88
        {
89
        android.util.Log.e("Renderer", ex.getMessage() );
90
        }
91
      }
92
    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
    
95
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
96
      {
97
      int duration = 10000;   
98
      
99
      Interpolator3D diMove = new Interpolator3D();
100
      diMove.setCount(0.0f);
101
      diMove.setDuration(duration);
102
      diMove.add(new Float3D(width-bmpWidth,height-bmpHeight,0));
103
      diMove.add(new Float3D(0,0,0));
104
      
105
      Interpolator3D diScale = new Interpolator3D();
106
      diScale.setCount(0.0f);
107
      diScale.setDuration(duration);
108
      diScale.add(new Float3D(1,1,1));
109
      diScale.add(new Float3D(0.33f,0.33f,1));
110
      
111
      Interpolator1D diRotate = new Interpolator1D();
112
      diRotate.setCount(0.0f);
113
      diRotate.setDuration(duration);
114
      diRotate.add(new Float1D(  0));
115
      diRotate.add(new Float1D(360));
116
      
117
      macroblock.abortEffects(EffectTypes.MATRIX);
118

    
119
      macroblock.move(diMove);
120
      macroblock.scale(diScale);
121
      macroblock.rotate( new Float3D(bmpWidth/2,bmpHeight/2,0), diRotate, 0.0f, 0.0f, 1.0f);
122
      
123
      Distorted.onSurfaceChanged(width, height); 
124
      }
125
}
(2-2/3)