Project

General

Profile

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

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

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
    private static Static1D d0, d1, 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 f988589e Leszek Koltunski
      diHips = new Dynamic1D(1000,0.0f);
110 427ab7bf Leszek Koltunski
      
111 7589635e Leszek Koltunski
      d0 = new Static1D(-hipsSwirl);
112
      d1 = new Static1D(+hipsSwirl);
113 427ab7bf Leszek Koltunski
      
114
      diHips.add(d0);
115
      diHips.add(d1);
116
      }
117
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119
120
   public static void setHips(int s)
121
     {      
122
     hipsSwirl = s;
123
     d0.set(-hipsSwirl);
124
     d1.set(+hipsSwirl);
125
     }
126
   
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
129
   public static void setSize(float s)
130
     {
131
     boobsSink = s;
132
     s0.set(boobsSink);
133
     }
134
   
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
137
   public static void setSwing(int s)
138
     {
139
     boobsSwing = s; 
140
     
141
     v0.set( 0,-boobsSwing, 0);
142
     v1.set( boobsSwing, 0, 0);
143
     v2.set( 0, boobsSwing, 0);
144
     v3.set(-boobsSwing, 0, 0);
145
     }
146
   
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148
   
149
   public void onDrawFrame(GL10 glUnused) 
150
      {
151
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
152
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
153
      
154
      mGirl.draw(System.currentTimeMillis());
155
      }
156
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
    
159
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
160
      { 
161 a8c3ada7 Leszek Koltunski
      mGirl.abortEffects(EffectTypes.MATRIX);
162 427ab7bf Leszek Koltunski
      
163
      if( bmpHeight/bmpWidth > height/width )
164
        {
165
        int w = (height*bmpWidth)/bmpHeight;
166 7589635e Leszek Koltunski
        float factor = (float)height/bmpHeight;
167
168
        mGirl.move( new Static3D((width-w)/2,0,0) );
169 f988589e Leszek Koltunski
        mGirl.scale(factor);
170 427ab7bf Leszek Koltunski
        }
171
      else
172
        {
173
        int h = (width*bmpHeight)/bmpWidth;
174 7589635e Leszek Koltunski
        float factor = (float)width/bmpWidth;
175
176
        mGirl.move( new Static3D(0,(height-h)/2,0) );
177 f988589e Leszek Koltunski
        mGirl.scale(factor);
178 427ab7bf Leszek Koltunski
        }
179
      
180
      Distorted.onSurfaceChanged(width, height); 
181
      }
182
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184
    
185
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
186
      {    
187
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
188
      Bitmap bitmap;
189
        
190
      try 
191
        {
192
        bitmap = BitmapFactory.decodeStream(is);
193
        } 
194
      finally 
195
        {
196
        try 
197
          {
198
          is.close();
199
          } 
200
        catch(IOException e) { }
201
        }  
202
      
203
      bmpHeight = bitmap.getHeight();
204
      bmpWidth  = bitmap.getWidth();
205
      
206
      mGirl = new DistortedBitmap(bitmap, 30);
207
208 b5cc7760 Leszek Koltunski
      mGirl.sink( diSink, pLeft, sinkRegion );
209
      mGirl.sink( diSink, pRight,sinkRegion );
210 427ab7bf Leszek Koltunski
211 b5cc7760 Leszek Koltunski
      mGirl.distort(diL, pLeft , Region);
212
      mGirl.distort(diR, pRight, Region);
213 427ab7bf Leszek Koltunski
         
214 b5cc7760 Leszek Koltunski
      mGirl.swirl(diHips, pHips, HipsRegion );
215 427ab7bf Leszek Koltunski
      
216
      try
217
        {
218 ed1c0b33 Leszek Koltunski
        Distorted.onSurfaceCreated(mView.getContext());
219 427ab7bf Leszek Koltunski
        }
220
      catch(Exception ex)
221
        {
222
        android.util.Log.e("Renderer", ex.getMessage() );
223
        }
224
      }
225
}