Project

General

Profile

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

examples / src / main / java / org / distorted / examples / girl / GirlRenderer.java @ 7589635e

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.examples.girl;
21

    
22
import java.io.IOException;
23
import java.io.InputStream;
24

    
25
import javax.microedition.khronos.egl.EGLConfig;
26
import javax.microedition.khronos.opengles.GL10;
27

    
28
import org.distorted.examples.R;
29

    
30
import org.distorted.library.Distorted;
31
import org.distorted.library.DistortedBitmap;
32
import org.distorted.library.EffectTypes;
33
import org.distorted.library.type.Dynamic1D;
34
import org.distorted.library.type.Dynamic3D;
35
import org.distorted.library.type.Static1D;
36
import org.distorted.library.type.Static2D;
37
import org.distorted.library.type.Static3D;
38
import org.distorted.library.type.Static4D;
39

    
40
import android.graphics.Bitmap;
41
import android.graphics.BitmapFactory;
42
import android.opengl.GLES20;
43
import android.opengl.GLSurfaceView;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
class GirlRenderer implements GLSurfaceView.Renderer 
48
{
49
    private GLSurfaceView mView;
50
    private DistortedBitmap mGirl;
51
    private Static2D pLeft, pRight, pHips;
52
    private Static4D Region, sinkRegion, HipsRegion;
53
    private static Dynamic3D diL, diR;
54
    private static Dynamic1D diHips, diSink;
55
    private static Static3D v0,v1,v2,v3;
56
    private static Static1D d0, d1, s0;
57
    
58
    private int bmpHeight, bmpWidth;
59
    
60
    private static int boobsSwing;
61
    private static int hipsSwirl;
62
    private static float boobsSink;
63
    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
   public GirlRenderer(GLSurfaceView v) 
67
      {
68
      mView = v;
69
      
70
      boobsSwing = 0;
71
      hipsSwirl  = 0;
72
      boobsSink  = 1.0f;
73
      
74
      pLeft = new Static2D(132, 264);
75
      pRight= new Static2D(247, 264);
76
      
77
      // Make the boobs bigger
78
      sinkRegion = new Static4D(0,0,60,60);
79
      
80
      s0 = new Static1D(boobsSink);
81
      
82
      diSink = new Dynamic1D();
83
      diSink.setCount(0.5f);
84
      diSink.setDuration(0);
85
      diSink.add(s0);
86
      
87
      // Boobs Movement
88
      Region = new Static4D(0,0,45,45);
89
      
90
      diL = new Dynamic3D();
91
      diR = new Dynamic3D();
92
      
93
      diL.setCount(0.0f);
94
      diR.setCount(0.0f);
95
      diL.setDuration(1000);
96
      diR.setDuration(1000);
97
      
98
      v0 = new Static3D( 0,-boobsSwing, 0);
99
      v1 = new Static3D( boobsSwing, 0, 0);
100
      v2 = new Static3D( 0, boobsSwing, 0);
101
      v3 = new Static3D(-boobsSwing, 0, 0);
102
      
103
      diL.add(v0);
104
      diL.add(v1);
105
      diL.add(v2);
106
      diL.add(v3);
107
      
108
      diR.add(v0);
109
      diR.add(v3);
110
      diR.add(v2);
111
      diR.add(v1);
112
      
113
      // Movement of the hips
114
      pHips = new Static2D(216,505);
115
      HipsRegion = new Static4D(0,0,120,120);
116
      diHips = new Dynamic1D();
117
      
118
      d0 = new Static1D(-hipsSwirl);
119
      d1 = new Static1D(+hipsSwirl);
120
      
121
      diHips.add(d0);
122
      diHips.add(d1);
123
      diHips.setDuration(1000);
124
      diHips.setCount(0.0f);
125
      }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
   public static void setHips(int s)
130
     {      
131
     hipsSwirl = s;
132
     d0.set(-hipsSwirl);
133
     d1.set(+hipsSwirl);
134
     }
135
   
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
   public static void setSize(float s)
139
     {
140
     boobsSink = s;
141
     s0.set(boobsSink);
142
     }
143
   
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
   public static void setSwing(int s)
147
     {
148
     boobsSwing = s; 
149
     
150
     v0.set( 0,-boobsSwing, 0);
151
     v1.set( boobsSwing, 0, 0);
152
     v2.set( 0, boobsSwing, 0);
153
     v3.set(-boobsSwing, 0, 0);
154
     }
155
   
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157
   
158
   public void onDrawFrame(GL10 glUnused) 
159
      {
160
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
161
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
162
      
163
      mGirl.draw(System.currentTimeMillis());
164
      }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
    
168
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
169
      { 
170
      mGirl.abortEffects(EffectTypes.MATRIX);
171
      
172
      if( bmpHeight/bmpWidth > height/width )
173
        {
174
        int w = (height*bmpWidth)/bmpHeight;
175
        float factor = (float)height/bmpHeight;
176

    
177
        mGirl.move( new Static3D((width-w)/2,0,0) );
178
        mGirl.scale( new Static3D(factor,factor,factor) );
179
        }
180
      else
181
        {
182
        int h = (width*bmpHeight)/bmpWidth;
183
        float factor = (float)width/bmpWidth;
184

    
185
        mGirl.move( new Static3D(0,(height-h)/2,0) );
186
        mGirl.scale( new Static3D(factor,factor,factor) );
187
        }
188
      
189
      Distorted.onSurfaceChanged(width, height); 
190
      }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193
    
194
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
195
      {    
196
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
197
      Bitmap bitmap;
198
        
199
      try 
200
        {
201
        bitmap = BitmapFactory.decodeStream(is);
202
        } 
203
      finally 
204
        {
205
        try 
206
          {
207
          is.close();
208
          } 
209
        catch(IOException e) { }
210
        }  
211
      
212
      bmpHeight = bitmap.getHeight();
213
      bmpWidth  = bitmap.getWidth();
214
      
215
      mGirl = new DistortedBitmap(bitmap, 30);
216

    
217
      mGirl.sink( diSink, sinkRegion, pLeft );
218
      mGirl.sink( diSink, sinkRegion, pRight);
219

    
220
      mGirl.distort(diL, Region, pLeft );
221
      mGirl.distort(diR, Region, pRight);
222
         
223
      mGirl.swirl(diHips, HipsRegion, pHips);
224
      
225
      try
226
        {
227
        Distorted.onSurfaceCreated(mView.getContext());
228
        }
229
      catch(Exception ex)
230
        {
231
        android.util.Log.e("Renderer", ex.getMessage() );
232
        }
233
      }
234
}
(2-2/3)