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.predeform;
|
21
|
|
22
|
import android.app.Activity;
|
23
|
import android.graphics.Bitmap;
|
24
|
import android.graphics.BitmapFactory;
|
25
|
import android.graphics.Canvas;
|
26
|
import android.graphics.Paint;
|
27
|
import android.opengl.GLSurfaceView;
|
28
|
import android.os.Bundle;
|
29
|
import android.view.View;
|
30
|
import android.widget.CheckBox;
|
31
|
import android.widget.SeekBar;
|
32
|
import android.widget.TextView;
|
33
|
|
34
|
import org.distorted.examples.R;
|
35
|
import org.distorted.library.main.DistortedLibrary;
|
36
|
import org.distorted.library.main.DistortedTexture;
|
37
|
import org.distorted.library.mesh.MeshBase;
|
38
|
|
39
|
import java.io.IOException;
|
40
|
import java.io.InputStream;
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
|
44
|
public class PredeformActivity2 extends Activity implements SeekBar.OnSeekBarChangeListener
|
45
|
{
|
46
|
private Bitmap mBitmap;
|
47
|
private TextView mTextLevel;
|
48
|
private DistortedTexture mTexture;
|
49
|
private MeshBase mMesh;
|
50
|
private int mNumRows, mNumCols, mNumSlic;
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
@Override
|
55
|
protected void onCreate(Bundle savedState)
|
56
|
{
|
57
|
super.onCreate(savedState);
|
58
|
DistortedLibrary.onCreate();
|
59
|
Bundle b = getIntent().getExtras();
|
60
|
|
61
|
int objectType = b.getInt("type");
|
62
|
int bitmapID = b.getInt("bitmap");
|
63
|
mNumCols = b.getInt("cols");
|
64
|
mNumRows = b.getInt("rows");
|
65
|
mNumSlic = b.getInt("slices");
|
66
|
|
67
|
StringBuilder strBuilder = new StringBuilder();
|
68
|
for(int i=0; i<mNumCols*mNumRows; i++) strBuilder.append('1');
|
69
|
|
70
|
int maxsize = mNumCols > mNumRows ? (Math.max(mNumCols, mNumSlic)) : (Math.max(mNumRows, mNumSlic));
|
71
|
createBitmap(maxsize,bitmapID);
|
72
|
mMesh = PredeformMeshList.createMesh(objectType, mNumCols, mNumRows, mNumSlic, bitmapID, strBuilder.toString() );
|
73
|
|
74
|
mTexture = new DistortedTexture();
|
75
|
|
76
|
setContentView(R.layout.predeformlayout);
|
77
|
mTextLevel = findViewById(R.id.predeformInflateText);
|
78
|
|
79
|
SeekBar inflateBar = findViewById(R.id.predeformInflateLevel);
|
80
|
inflateBar.setOnSeekBarChangeListener(this);
|
81
|
inflateBar.setProgress(50);
|
82
|
}
|
83
|
|
84
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85
|
|
86
|
@Override
|
87
|
protected void onPause()
|
88
|
{
|
89
|
super.onPause();
|
90
|
GLSurfaceView view = findViewById(R.id.predeformSurfaceView);
|
91
|
view.onPause();
|
92
|
DistortedLibrary.onPause();
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
|
97
|
@Override
|
98
|
protected void onResume()
|
99
|
{
|
100
|
super.onResume();
|
101
|
GLSurfaceView view = findViewById(R.id.predeformSurfaceView);
|
102
|
view.onResume();
|
103
|
}
|
104
|
|
105
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106
|
|
107
|
@Override
|
108
|
protected void onDestroy()
|
109
|
{
|
110
|
DistortedLibrary.onDestroy();
|
111
|
super.onDestroy();
|
112
|
}
|
113
|
|
114
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115
|
|
116
|
public void showNormal(View view)
|
117
|
{
|
118
|
CheckBox box = (CheckBox)view;
|
119
|
boolean show = box.isChecked();
|
120
|
|
121
|
PredeformSurfaceView v = findViewById(R.id.predeformSurfaceView);
|
122
|
PredeformRenderer renderer = v.getRenderer();
|
123
|
|
124
|
renderer.showNormal(show);
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
private void createBitmap(int size, int bitmapID)
|
130
|
{
|
131
|
if( bitmapID!=-1)
|
132
|
{
|
133
|
try (InputStream is = getResources().openRawResource(bitmapID))
|
134
|
{
|
135
|
mBitmap = BitmapFactory.decodeStream(is);
|
136
|
}
|
137
|
catch( IOException ex ) { android.util.Log.e("act", "failed to open resource "+bitmapID); }
|
138
|
}
|
139
|
else
|
140
|
{
|
141
|
final int T = 64;
|
142
|
final int S = T*size;
|
143
|
|
144
|
Paint paint = new Paint();
|
145
|
mBitmap = Bitmap.createBitmap(S,S, Bitmap.Config.ARGB_8888);
|
146
|
Canvas canvas = new Canvas(mBitmap);
|
147
|
|
148
|
paint.setAntiAlias(true);
|
149
|
paint.setTextAlign(Paint.Align.CENTER);
|
150
|
paint.setColor(0xff008800);
|
151
|
paint.setStyle(Paint.Style.FILL);
|
152
|
canvas.drawRect(0, 0, S, S, paint);
|
153
|
paint.setColor(0xffffffff);
|
154
|
|
155
|
for(int i=0; i<=size ; i++ )
|
156
|
{
|
157
|
canvas.drawRect( T*i-1, 0, T*i+1, S, paint);
|
158
|
canvas.drawRect( 0, T*i-1, S, T*i+1, paint);
|
159
|
}
|
160
|
}
|
161
|
}
|
162
|
|
163
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164
|
|
165
|
int getRows()
|
166
|
{
|
167
|
return mNumRows;
|
168
|
}
|
169
|
|
170
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171
|
|
172
|
int getCols()
|
173
|
{
|
174
|
return mNumCols;
|
175
|
}
|
176
|
|
177
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
178
|
|
179
|
int getSlic()
|
180
|
{
|
181
|
return mNumSlic;
|
182
|
}
|
183
|
|
184
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185
|
|
186
|
public Bitmap getBitmap()
|
187
|
{
|
188
|
return mBitmap;
|
189
|
}
|
190
|
|
191
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192
|
|
193
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
194
|
{
|
195
|
if(bar.getId() == R.id.predeformInflateLevel)
|
196
|
{
|
197
|
PredeformSurfaceView v2 = findViewById(R.id.predeformSurfaceView);
|
198
|
float level = v2.getRenderer().setLevel(progress);
|
199
|
mTextLevel.setText(getString(R.string.inflate_placeholder, level));
|
200
|
}
|
201
|
}
|
202
|
|
203
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
204
|
|
205
|
public void onStartTrackingTouch(SeekBar bar) { }
|
206
|
|
207
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208
|
|
209
|
public void onStopTrackingTouch(SeekBar bar) { }
|
210
|
|
211
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
212
|
|
213
|
public DistortedTexture getTexture()
|
214
|
{
|
215
|
return mTexture;
|
216
|
}
|
217
|
|
218
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
219
|
|
220
|
public MeshBase getMesh()
|
221
|
{
|
222
|
return mMesh;
|
223
|
}
|
224
|
}
|