Project

General

Profile

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

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

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 dBegin, dMiddle, dEnd, 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
      // Size
78
      sinkRegion = new Static4D(0,0,60,60);
79
      
80
      s0 = new Static1D(boobsSink);
81
      
82
      diSink = new Dynamic1D(0,0.5f);
83
      diSink.add(s0);
84
      
85
      // Upper Movement
86
      Region = new Static4D(0,0,45,45);
87
      
88
      diL = new Dynamic3D(1000,0.0f);
89
      diR = new Dynamic3D(1000,0.0f);
90

    
91
      v0 = new Static3D( 0,-boobsSwing, 0);
92
      v1 = new Static3D( boobsSwing, 0, 0);
93
      v2 = new Static3D( 0, boobsSwing, 0);
94
      v3 = new Static3D(-boobsSwing, 0, 0);
95
      
96
      diL.add(v0);
97
      diL.add(v1);
98
      diL.add(v2);
99
      diL.add(v3);
100
      
101
      diR.add(v0);
102
      diR.add(v3);
103
      diR.add(v2);
104
      diR.add(v1);
105
      
106
      // Lower Movement
107
      pHips = new Static2D(216,505);
108
      HipsRegion = new Static4D(0,0,120,120);
109
      diHips = new Dynamic1D(1500,0.0f);
110
      
111
      dBegin = new Static1D(-hipsSwirl);
112
      dMiddle= new Static1D(0);
113
      dEnd   = new Static1D(+hipsSwirl);
114
      
115
      diHips.add(dBegin);
116
      diHips.add(dMiddle);
117
      diHips.add(dEnd);
118
      diHips.add(dEnd);
119
      diHips.add(dMiddle);
120
      diHips.add(dBegin);
121
      }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
   public static void setHips(int s)
126
     {      
127
     hipsSwirl = s;
128
     dBegin.set(-hipsSwirl);
129
     dEnd.set(+hipsSwirl);
130
     }
131
   
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
   public static void setSize(float s)
135
     {
136
     boobsSink = s;
137
     s0.set(boobsSink);
138
     }
139
   
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

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

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

    
173
        mGirl.move( new Static3D((width-w)/2,0,0) );
174
        mGirl.scale(factor);
175
        }
176
      else
177
        {
178
        int h = (width*bmpHeight)/bmpWidth;
179
        float factor = (float)width/bmpWidth;
180

    
181
        mGirl.move( new Static3D(0,(height-h)/2,0) );
182
        mGirl.scale(factor);
183
        }
184
      
185
      Distorted.onSurfaceChanged(width, height); 
186
      }
187

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

    
213
      mGirl.sink( diSink, pLeft, sinkRegion );
214
      mGirl.sink( diSink, pRight,sinkRegion );
215

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