Project

General

Profile

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

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

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 427ab7bf Leszek Koltunski
20 5068fa06 Leszek Koltunski
package org.distorted.examples.girl;
21 427ab7bf Leszek Koltunski
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 5068fa06 Leszek Koltunski
import org.distorted.examples.R;
29 427ab7bf Leszek Koltunski
30 5068fa06 Leszek Koltunski
import org.distorted.library.Distorted;
31
import org.distorted.library.DistortedBitmap;
32 95593730 Leszek Koltunski
import org.distorted.library.EffectTypes;
33 7589635e Leszek Koltunski
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 427ab7bf Leszek Koltunski
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 7589635e Leszek Koltunski
    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 f969f51d Leszek Koltunski
    private static Static1D dBegin, dMiddle, dEnd, s0;
57 427ab7bf Leszek Koltunski
    
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 7589635e Leszek Koltunski
      pLeft = new Static2D(132, 264);
75
      pRight= new Static2D(247, 264);
76 427ab7bf Leszek Koltunski
      
77 f988589e Leszek Koltunski
      // Size
78 7589635e Leszek Koltunski
      sinkRegion = new Static4D(0,0,60,60);
79 427ab7bf Leszek Koltunski
      
80 7589635e Leszek Koltunski
      s0 = new Static1D(boobsSink);
81 427ab7bf Leszek Koltunski
      
82 f988589e Leszek Koltunski
      diSink = new Dynamic1D(0,0.5f);
83 427ab7bf Leszek Koltunski
      diSink.add(s0);
84
      
85 f988589e Leszek Koltunski
      // Upper Movement
86 7589635e Leszek Koltunski
      Region = new Static4D(0,0,45,45);
87 427ab7bf Leszek Koltunski
      
88 f988589e Leszek Koltunski
      diL = new Dynamic3D(1000,0.0f);
89
      diR = new Dynamic3D(1000,0.0f);
90
91 7589635e Leszek Koltunski
      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 427ab7bf Leszek Koltunski
      
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 f988589e Leszek Koltunski
      // Lower Movement
107 7589635e Leszek Koltunski
      pHips = new Static2D(216,505);
108
      HipsRegion = new Static4D(0,0,120,120);
109 f969f51d Leszek Koltunski
      diHips = new Dynamic1D(1500,0.0f);
110 427ab7bf Leszek Koltunski
      
111 f969f51d Leszek Koltunski
      dBegin = new Static1D(-hipsSwirl);
112
      dMiddle= new Static1D(0);
113
      dEnd   = new Static1D(+hipsSwirl);
114 427ab7bf Leszek Koltunski
      
115 f969f51d Leszek Koltunski
      diHips.add(dBegin);
116
      diHips.add(dMiddle);
117
      diHips.add(dEnd);
118
      diHips.add(dEnd);
119
      diHips.add(dMiddle);
120
      diHips.add(dBegin);
121 427ab7bf Leszek Koltunski
      }
122
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125
   public static void setHips(int s)
126
     {      
127
     hipsSwirl = s;
128 f969f51d Leszek Koltunski
     dBegin.set(-hipsSwirl);
129
     dEnd.set(+hipsSwirl);
130 427ab7bf Leszek Koltunski
     }
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 a8c3ada7 Leszek Koltunski
      mGirl.abortEffects(EffectTypes.MATRIX);
167 427ab7bf Leszek Koltunski
      
168
      if( bmpHeight/bmpWidth > height/width )
169
        {
170
        int w = (height*bmpWidth)/bmpHeight;
171 7589635e Leszek Koltunski
        float factor = (float)height/bmpHeight;
172
173
        mGirl.move( new Static3D((width-w)/2,0,0) );
174 f988589e Leszek Koltunski
        mGirl.scale(factor);
175 427ab7bf Leszek Koltunski
        }
176
      else
177
        {
178
        int h = (width*bmpHeight)/bmpWidth;
179 7589635e Leszek Koltunski
        float factor = (float)width/bmpWidth;
180
181
        mGirl.move( new Static3D(0,(height-h)/2,0) );
182 f988589e Leszek Koltunski
        mGirl.scale(factor);
183 427ab7bf Leszek Koltunski
        }
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 b5cc7760 Leszek Koltunski
      mGirl.sink( diSink, pLeft, sinkRegion );
214
      mGirl.sink( diSink, pRight,sinkRegion );
215 427ab7bf Leszek Koltunski
216 b5cc7760 Leszek Koltunski
      mGirl.distort(diL, pLeft , Region);
217
      mGirl.distort(diR, pRight, Region);
218 427ab7bf Leszek Koltunski
         
219 b5cc7760 Leszek Koltunski
      mGirl.swirl(diHips, pHips, HipsRegion );
220 427ab7bf Leszek Koltunski
      
221
      try
222
        {
223 ed1c0b33 Leszek Koltunski
        Distorted.onSurfaceCreated(mView.getContext());
224 427ab7bf Leszek Koltunski
        }
225
      catch(Exception ex)
226
        {
227
        android.util.Log.e("Renderer", ex.getMessage() );
228
        }
229
      }
230
}