Project

General

Profile

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

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

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 Static3D pLeft, pRight, pHips;
52
    private Static4D Region, sinkRegion, HipsRegion;
53
    private Dynamic3D diL, diR;
54
    private Dynamic1D diHips, diSink;
55
    private Static3D v0,v1,v2,v3;
56
    private Static1D dBegin, dMiddle, dEnd, s0;
57
    private int bmpHeight, bmpWidth;
58
    private int boobsSwing;
59
    private int hipsSwirl;
60
    private float boobsSink;
61
    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
   GirlRenderer(GLSurfaceView v)
65
      {
66
      mView = v;
67
      
68
      boobsSwing = 0;
69
      hipsSwirl  = 0;
70
      boobsSink  = 1.0f;
71
      
72
      pLeft = new Static3D(132, 264, 0);
73
      pRight= new Static3D(247, 264, 0);
74
      
75
      // Size
76
      sinkRegion = new Static4D(0,0,60,60);
77
      
78
      s0 = new Static1D(boobsSink);
79
      
80
      diSink = new Dynamic1D(0,0.5f);
81
      diSink.add(s0);
82
      
83
      // Upper Movement
84
      Region = new Static4D(0,0,45,45);
85
      
86
      diL = new Dynamic3D(1000,0.0f);
87
      diR = new Dynamic3D(1000,0.0f);
88

    
89
      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
      
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
      // Lower Movement
105
      pHips = new Static3D(216,505,0);
106
      HipsRegion = new Static4D(0,0,120,120);
107
      diHips = new Dynamic1D(1500,0.0f);
108
      
109
      dBegin = new Static1D(-hipsSwirl);
110
      dMiddle= new Static1D(0);
111
      dEnd   = new Static1D(+hipsSwirl);
112
      
113
      diHips.add(dBegin);
114
      diHips.add(dMiddle);
115
      diHips.add(dEnd);
116
      diHips.add(dEnd);
117
      diHips.add(dMiddle);
118
      diHips.add(dBegin);
119
      }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

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

    
132
   void setSize(float s)
133
     {
134
     boobsSink = s;
135
     s0.set(boobsSink);
136
     }
137
   
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
   void setSwing(int s)
141
     {
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
      mGirl.abortEffects(EffectTypes.MATRIX);
163
      
164
      if( (float)bmpHeight/bmpWidth > (float)height/width )
165
        {
166
        int w = (height*bmpWidth)/bmpHeight;
167
        float factor = (float)height/bmpHeight;
168

    
169
        mGirl.move( new Static3D((width-w)/2,0,0) );
170
        mGirl.scale(factor);
171
        }
172
      else
173
        {
174
        int h = (width*bmpHeight)/bmpWidth;
175
        float factor = (float)width/bmpWidth;
176

    
177
        mGirl.move( new Static3D(0,(height-h)/2,0) );
178
        mGirl.scale(factor);
179
        }
180
      
181
      Distorted.onSurfaceChanged(width, height); 
182
      }
183

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185
    
186
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
187
      {
188
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
189

    
190
      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
      mGirl.sink( diSink, pLeft, sinkRegion );
212
      mGirl.sink( diSink, pRight,sinkRegion );
213

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