Project

General

Profile

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

examples / src / main / java / org / distorted / examples / girl / GirlRenderer.java @ 95593730

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.EffectTypes;
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
import org.distorted.library.Interpolator3D;
20
import org.distorted.library.Interpolator1D;
21

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

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

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

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

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

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

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

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

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

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

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

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