Project

General

Profile

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

examples / src / main / java / org / distorted / examples / girl / GirlRenderer.java @ 5055b5d4

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 334c13fa Leszek Koltunski
    private Static3D pLeft, pRight, pHips;
52 7589635e Leszek Koltunski
    private Static4D Region, sinkRegion, HipsRegion;
53 abc3054d Leszek Koltunski
    private Dynamic3D diL, diR;
54
    private Dynamic1D diHips, diSink;
55
    private Static3D v0,v1,v2,v3;
56
    private Static1D dBegin, dMiddle, dEnd, s0;
57 427ab7bf Leszek Koltunski
    private int bmpHeight, bmpWidth;
58 abc3054d Leszek Koltunski
    private int boobsSwing;
59
    private int hipsSwirl;
60
    private float boobsSink;
61 427ab7bf Leszek Koltunski
    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
64 abc3054d Leszek Koltunski
   GirlRenderer(GLSurfaceView v)
65 427ab7bf Leszek Koltunski
      {
66
      mView = v;
67
      
68
      boobsSwing = 0;
69
      hipsSwirl  = 0;
70
      boobsSink  = 1.0f;
71
      
72 334c13fa Leszek Koltunski
      pLeft = new Static3D(132, 264, 0);
73
      pRight= new Static3D(247, 264, 0);
74 427ab7bf Leszek Koltunski
      
75 f988589e Leszek Koltunski
      // Size
76 7589635e Leszek Koltunski
      sinkRegion = new Static4D(0,0,60,60);
77 427ab7bf Leszek Koltunski
      
78 7589635e Leszek Koltunski
      s0 = new Static1D(boobsSink);
79 427ab7bf Leszek Koltunski
      
80 f988589e Leszek Koltunski
      diSink = new Dynamic1D(0,0.5f);
81 427ab7bf Leszek Koltunski
      diSink.add(s0);
82
      
83 f988589e Leszek Koltunski
      // Upper Movement
84 7589635e Leszek Koltunski
      Region = new Static4D(0,0,45,45);
85 427ab7bf Leszek Koltunski
      
86 f988589e Leszek Koltunski
      diL = new Dynamic3D(1000,0.0f);
87
      diR = new Dynamic3D(1000,0.0f);
88
89 7589635e Leszek Koltunski
      v0 = new Static3D( 0,-boobsSwing, 0);
90
      v1 = new Static3D( boobsSwing, 0, 0);
91
      v2 = new Static3D( 0, boobsSwing, 0);
92
      v3 = new Static3D(-boobsSwing, 0, 0);
93 427ab7bf Leszek Koltunski
      
94
      diL.add(v0);
95
      diL.add(v1);
96
      diL.add(v2);
97
      diL.add(v3);
98
      
99
      diR.add(v0);
100
      diR.add(v3);
101
      diR.add(v2);
102
      diR.add(v1);
103
      
104 f988589e Leszek Koltunski
      // Lower Movement
105 334c13fa Leszek Koltunski
      pHips = new Static3D(216,505,0);
106 7589635e Leszek Koltunski
      HipsRegion = new Static4D(0,0,120,120);
107 f969f51d Leszek Koltunski
      diHips = new Dynamic1D(1500,0.0f);
108 427ab7bf Leszek Koltunski
      
109 f969f51d Leszek Koltunski
      dBegin = new Static1D(-hipsSwirl);
110
      dMiddle= new Static1D(0);
111
      dEnd   = new Static1D(+hipsSwirl);
112 427ab7bf Leszek Koltunski
      
113 f969f51d Leszek Koltunski
      diHips.add(dBegin);
114
      diHips.add(dMiddle);
115
      diHips.add(dEnd);
116
      diHips.add(dEnd);
117
      diHips.add(dMiddle);
118
      diHips.add(dBegin);
119 427ab7bf Leszek Koltunski
      }
120
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
123 abc3054d Leszek Koltunski
   void setHips(int s)
124 427ab7bf Leszek Koltunski
     {      
125
     hipsSwirl = s;
126 f969f51d Leszek Koltunski
     dBegin.set(-hipsSwirl);
127
     dEnd.set(+hipsSwirl);
128 427ab7bf Leszek Koltunski
     }
129
   
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
132 abc3054d Leszek Koltunski
   void setSize(float s)
133 427ab7bf Leszek Koltunski
     {
134
     boobsSink = s;
135
     s0.set(boobsSink);
136
     }
137
   
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
140 abc3054d Leszek Koltunski
   void setSwing(int s)
141 427ab7bf Leszek Koltunski
     {
142
     boobsSwing = s; 
143
     
144
     v0.set( 0,-boobsSwing, 0);
145
     v1.set( boobsSwing, 0, 0);
146
     v2.set( 0, boobsSwing, 0);
147
     v3.set(-boobsSwing, 0, 0);
148
     }
149
   
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
   
152
   public void onDrawFrame(GL10 glUnused) 
153
      {
154
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
155
      mGirl.draw(System.currentTimeMillis());
156
      }
157
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
    
160
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
161
      { 
162 a8c3ada7 Leszek Koltunski
      mGirl.abortEffects(EffectTypes.MATRIX);
163 427ab7bf Leszek Koltunski
      
164 5055b5d4 Leszek Koltunski
      if( (float)bmpHeight/bmpWidth > (float)height/width )
165 427ab7bf Leszek Koltunski
        {
166
        int w = (height*bmpWidth)/bmpHeight;
167 7589635e Leszek Koltunski
        float factor = (float)height/bmpHeight;
168
169
        mGirl.move( new Static3D((width-w)/2,0,0) );
170 f988589e Leszek Koltunski
        mGirl.scale(factor);
171 427ab7bf Leszek Koltunski
        }
172
      else
173
        {
174
        int h = (width*bmpHeight)/bmpWidth;
175 7589635e Leszek Koltunski
        float factor = (float)width/bmpWidth;
176
177
        mGirl.move( new Static3D(0,(height-h)/2,0) );
178 f988589e Leszek Koltunski
        mGirl.scale(factor);
179 427ab7bf Leszek Koltunski
        }
180
      
181
      Distorted.onSurfaceChanged(width, height); 
182
      }
183
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185
    
186
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
187 e7a4ef16 Leszek Koltunski
      {
188
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
189
190 427ab7bf Leszek Koltunski
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
191
      Bitmap bitmap;
192
        
193
      try 
194
        {
195
        bitmap = BitmapFactory.decodeStream(is);
196
        } 
197
      finally 
198
        {
199
        try 
200
          {
201
          is.close();
202
          } 
203
        catch(IOException e) { }
204
        }  
205
      
206
      bmpHeight = bitmap.getHeight();
207
      bmpWidth  = bitmap.getWidth();
208
      
209
      mGirl = new DistortedBitmap(bitmap, 30);
210
211 b5cc7760 Leszek Koltunski
      mGirl.sink( diSink, pLeft, sinkRegion );
212
      mGirl.sink( diSink, pRight,sinkRegion );
213 427ab7bf Leszek Koltunski
214 b5cc7760 Leszek Koltunski
      mGirl.distort(diL, pLeft , Region);
215
      mGirl.distort(diR, pRight, Region);
216 427ab7bf Leszek Koltunski
         
217 b5cc7760 Leszek Koltunski
      mGirl.swirl(diHips, pHips, HipsRegion );
218 427ab7bf Leszek Koltunski
      
219
      try
220
        {
221 ed1c0b33 Leszek Koltunski
        Distorted.onSurfaceCreated(mView.getContext());
222 427ab7bf Leszek Koltunski
        }
223
      catch(Exception ex)
224
        {
225
        android.util.Log.e("Renderer", ex.getMessage() );
226
        }
227
      }
228
}