Project

General

Profile

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

examples / src / main / java / org / distorted / examples / girl / GirlRenderer.java @ 89a0d841

1

    
2
package org.distorted.examples.girl;
3

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

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

    
10
import org.distorted.examples.R;
11

    
12
import org.distorted.library.Distorted;
13
import org.distorted.library.DistortedBitmap;
14
import org.distorted.library.Float1D;
15
import org.distorted.library.Float2D;
16
import org.distorted.library.Float3D;
17
import org.distorted.library.Float4D;
18
import org.distorted.library.Interpolator3D;
19
import org.distorted.library.Interpolator1D;
20

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

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

    
28
class GirlRenderer implements GLSurfaceView.Renderer 
29
{
30
    private GLSurfaceView mView;
31
    private DistortedBitmap mGirl;
32
    private Float2D pLeft, pRight, pHips;
33
    private Float4D Region, sinkRegion, HipsRegion;
34
    private static Interpolator3D diL, diR;
35
    private static Interpolator1D diHips, diSink;
36
    private static Float3D v0,v1,v2,v3;
37
    private static Float1D d0, d1, s0;
38
    
39
    private int bmpHeight, bmpWidth;
40
    
41
    private static int boobsSwing;
42
    private static int hipsSwirl;
43
    private static float boobsSink;
44
    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
   public GirlRenderer(GLSurfaceView v) 
48
      {
49
      mView = v;
50
      
51
      boobsSwing = 0;
52
      hipsSwirl  = 0;
53
      boobsSink  = 1.0f;
54
      
55
      pLeft = new Float2D(132, 264);
56
      pRight= new Float2D(247, 264);
57
      
58
      // Make the boobs bigger
59
      sinkRegion = new Float4D(0,0,60,60);
60
      
61
      s0 = new Float1D(boobsSink);
62
      
63
      diSink = new Interpolator1D(); 
64
      diSink.setCount(0.5f);
65
      diSink.setDuration(0);
66
      diSink.add(s0);
67
      
68
      // Boobs Movement
69
      Region = new Float4D(0,0,45,45);
70
      
71
      diL = new Interpolator3D();
72
      diR = new Interpolator3D();
73
      
74
      diL.setCount(0.0f);
75
      diR.setCount(0.0f);
76
      diL.setDuration(1000);
77
      diR.setDuration(1000);
78
      
79
      v0 = new Float3D( 0,-boobsSwing, 0);
80
      v1 = new Float3D( boobsSwing, 0, 0);
81
      v2 = new Float3D( 0, boobsSwing, 0);
82
      v3 = new Float3D(-boobsSwing, 0, 0);
83
      
84
      diL.add(v0);
85
      diL.add(v1);
86
      diL.add(v2);
87
      diL.add(v3);
88
      
89
      diR.add(v0);
90
      diR.add(v3);
91
      diR.add(v2);
92
      diR.add(v1);
93
      
94
      // Movement of the hips
95
      pHips = new Float2D(216,505);
96
      HipsRegion = new Float4D(0,0,120,120);
97
      diHips = new Interpolator1D();
98
      
99
      d0 = new Float1D(-hipsSwirl);
100
      d1 = new Float1D(+hipsSwirl);
101
      
102
      diHips.add(d0);
103
      diHips.add(d1);
104
      diHips.setDuration(1000);
105
      diHips.setCount(0.0f);
106
      }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

    
110
   public static void setHips(int s)
111
     {      
112
     hipsSwirl = s;
113
     d0.set(-hipsSwirl);
114
     d1.set(+hipsSwirl);
115
     }
116
   
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
   public static void setSize(float s)
120
     {
121
     boobsSink = s;
122
     s0.set(boobsSink);
123
     }
124
   
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
   public static void setSwing(int s)
128
     {
129
     boobsSwing = s; 
130
     
131
     v0.set( 0,-boobsSwing, 0);
132
     v1.set( boobsSwing, 0, 0);
133
     v2.set( 0, boobsSwing, 0);
134
     v3.set(-boobsSwing, 0, 0);
135
     }
136
   
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
   
139
   public void onDrawFrame(GL10 glUnused) 
140
      {
141
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
142
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
143
      
144
      mGirl.draw(System.currentTimeMillis());
145
      }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148
    
149
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
150
      { 
151
      mGirl.abortAllEffects(Distorted.TYPE_PRE);
152
      
153
      if( bmpHeight/bmpWidth > height/width )
154
        {
155
        int w = (height*bmpWidth)/bmpHeight;
156
        mGirl.move((width-w)/2 ,0, 0);
157
        mGirl.scale((float)height/bmpHeight);
158
        }
159
      else
160
        {
161
        int h = (width*bmpHeight)/bmpWidth;
162
        mGirl.move(0 ,(height-h)/2, 0);
163
        mGirl.scale((float)width/bmpWidth);
164
        }
165
      
166
      Distorted.onSurfaceChanged(width, height); 
167
      }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170
    
171
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
172
      {    
173
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
174
      Bitmap bitmap;
175
        
176
      try 
177
        {
178
        bitmap = BitmapFactory.decodeStream(is);
179
        } 
180
      finally 
181
        {
182
        try 
183
          {
184
          is.close();
185
          } 
186
        catch(IOException e) { }
187
        }  
188
      
189
      bmpHeight = bitmap.getHeight();
190
      bmpWidth  = bitmap.getWidth();
191
      
192
      mGirl = new DistortedBitmap(bitmap, 30);
193

    
194
      mGirl.sink( diSink, sinkRegion, pLeft );
195
      mGirl.sink( diSink, sinkRegion, pRight);
196

    
197
      mGirl.distort(diL, Region, pLeft );
198
      mGirl.distort(diR, Region, pRight);
199
         
200
      mGirl.swirl(diHips, HipsRegion, pHips);
201
      
202
      try
203
        {
204
        Distorted.onSurfaceCreated(mView.getContext());
205
        }
206
      catch(Exception ex)
207
        {
208
        android.util.Log.e("Renderer", ex.getMessage() );
209
        }
210
      }
211
}
(2-2/3)