Project

General

Profile

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

examples / src / main / java / org / distortedandroid / examples / macroblock / MacroblockRenderer.java @ 427ab7bf

1
package org.distortedandroid.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.distortedandroid.examples.R;
10
import org.distortedandroid.library.Distorted;
11
import org.distortedandroid.library.DistortedBitmap;
12
import org.distortedandroid.library.Interpolator1D;
13
import org.distortedandroid.library.Interpolator3D;
14
import org.distortedandroid.library.Float1D;
15
import org.distortedandroid.library.Float2D;
16
import org.distortedandroid.library.Float3D;
17
import org.distortedandroid.library.Float4D;
18

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

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

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

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

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

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

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