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.generic;
|
21
|
|
22
|
import android.graphics.Bitmap;
|
23
|
import android.graphics.BitmapFactory;
|
24
|
import android.graphics.Canvas;
|
25
|
import android.graphics.Paint;
|
26
|
import android.opengl.GLSurfaceView;
|
27
|
import android.os.Bundle;
|
28
|
import com.google.android.material.tabs.TabLayout;
|
29
|
import androidx.appcompat.app.AppCompatActivity;
|
30
|
import android.view.View;
|
31
|
import android.widget.CheckBox;
|
32
|
|
33
|
import org.distorted.examples.R;
|
34
|
import org.distorted.library.main.DistortedLibrary;
|
35
|
import org.distorted.library.main.DistortedEffects;
|
36
|
import org.distorted.library.main.DistortedTexture;
|
37
|
import org.distorted.library.mesh.MeshBase;
|
38
|
import org.distorted.library.type.Static3D;
|
39
|
import org.distorted.library.type.Static4D;
|
40
|
|
41
|
import java.io.IOException;
|
42
|
import java.io.InputStream;
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
public class GenericActivity2 extends AppCompatActivity
|
47
|
{
|
48
|
private DistortedTexture mTexture;
|
49
|
private MeshBase mMesh;
|
50
|
private Bitmap mBitmap;
|
51
|
private DistortedEffects mEffects;
|
52
|
private GenericViewPager mViewPager;
|
53
|
|
54
|
private boolean mShowCenter, mShowRegion, mShowNormal, mUseOIT;
|
55
|
private float mScaleX, mScaleY, mScaleZ;
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
|
59
|
@Override
|
60
|
protected void onCreate(Bundle savedState)
|
61
|
{
|
62
|
super.onCreate(savedState);
|
63
|
|
64
|
setTheme(R.style.CustomActivityThemeNoActionBar);
|
65
|
|
66
|
Bundle b = getIntent().getExtras();
|
67
|
|
68
|
int objectType = b.getInt("type");
|
69
|
int numCols = b.getInt("cols");
|
70
|
int numRows = b.getInt("rows");
|
71
|
int numSlic = b.getInt("slices");
|
72
|
int bitmapID = b.getInt("bitmap");
|
73
|
String str = b.getString("string");
|
74
|
|
75
|
mShowCenter = false;
|
76
|
mShowRegion = false;
|
77
|
mShowNormal = false;
|
78
|
mUseOIT = false;
|
79
|
|
80
|
mScaleX = numCols;
|
81
|
mScaleY = numRows;
|
82
|
mScaleZ = numSlic;
|
83
|
|
84
|
int maxsize = numCols > numRows ? (Math.max(numCols, numSlic)) : (Math.max(numRows, numSlic));
|
85
|
createBitmap(maxsize, bitmapID);
|
86
|
mMesh = GenericMeshList.createMesh(objectType, numCols, numRows, numSlic, bitmapID, str);
|
87
|
|
88
|
mMesh.setShowNormals(mShowNormal);
|
89
|
mTexture= new DistortedTexture();
|
90
|
mEffects= new DistortedEffects();
|
91
|
|
92
|
final View view = getLayoutInflater().inflate(R.layout.genericlayout, null);
|
93
|
|
94
|
setContentView(view);
|
95
|
|
96
|
mViewPager = new GenericViewPager(this,R.id.generic_viewpager);
|
97
|
TabLayout tabLayout = findViewById(R.id.generic_sliding_tabs);
|
98
|
tabLayout.setupWithViewPager(mViewPager.getPager());
|
99
|
}
|
100
|
|
101
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102
|
|
103
|
private void createBitmap(int size, int bitmapID)
|
104
|
{
|
105
|
if( bitmapID!=-1)
|
106
|
{
|
107
|
InputStream is = getResources().openRawResource(bitmapID);
|
108
|
|
109
|
try
|
110
|
{
|
111
|
mBitmap = BitmapFactory.decodeStream(is);
|
112
|
}
|
113
|
finally
|
114
|
{
|
115
|
try
|
116
|
{
|
117
|
is.close();
|
118
|
}
|
119
|
catch(IOException e) { }
|
120
|
}
|
121
|
}
|
122
|
else
|
123
|
{
|
124
|
final int T = 64;
|
125
|
final int S = T*size;
|
126
|
|
127
|
Paint paint = new Paint();
|
128
|
mBitmap = Bitmap.createBitmap(S,S, Bitmap.Config.ARGB_8888);
|
129
|
Canvas canvas = new Canvas(mBitmap);
|
130
|
|
131
|
paint.setAntiAlias(true);
|
132
|
paint.setTextAlign(Paint.Align.CENTER);
|
133
|
paint.setColor(0xff008800);
|
134
|
paint.setStyle(Paint.Style.FILL);
|
135
|
canvas.drawRect(0, 0, S, S, paint);
|
136
|
paint.setColor(0xffffffff);
|
137
|
|
138
|
for(int i=0; i<=size ; i++ )
|
139
|
{
|
140
|
canvas.drawRect( T*i-1, 0, T*i+1, S, paint);
|
141
|
canvas.drawRect( 0, T*i-1, S, T*i+1, paint);
|
142
|
}
|
143
|
}
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
public DistortedTexture getTexture()
|
149
|
{
|
150
|
return mTexture;
|
151
|
}
|
152
|
|
153
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
154
|
|
155
|
public MeshBase getMesh()
|
156
|
{
|
157
|
return mMesh;
|
158
|
}
|
159
|
|
160
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
161
|
|
162
|
public Bitmap getBitmap()
|
163
|
{
|
164
|
return mBitmap;
|
165
|
}
|
166
|
|
167
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168
|
|
169
|
public DistortedEffects getEffects()
|
170
|
{
|
171
|
return mEffects;
|
172
|
}
|
173
|
|
174
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175
|
|
176
|
public GenericViewPager getPager()
|
177
|
{
|
178
|
return mViewPager;
|
179
|
}
|
180
|
|
181
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182
|
|
183
|
public float getWidth()
|
184
|
{
|
185
|
return mScaleX;
|
186
|
}
|
187
|
|
188
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189
|
|
190
|
public float getHeight()
|
191
|
{
|
192
|
return mScaleY;
|
193
|
}
|
194
|
|
195
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
196
|
|
197
|
public float getDepth()
|
198
|
{
|
199
|
return mScaleZ;
|
200
|
}
|
201
|
|
202
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203
|
|
204
|
public int getScreenWidth()
|
205
|
{
|
206
|
GenericSurfaceView view = findViewById(R.id.genericSurfaceView);
|
207
|
GenericRenderer renderer = view.getRenderer();
|
208
|
return renderer.getWidth();
|
209
|
}
|
210
|
|
211
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
212
|
|
213
|
public float getScaleFactor()
|
214
|
{
|
215
|
GenericSurfaceView view = findViewById(R.id.genericSurfaceView);
|
216
|
GenericRenderer renderer = view.getRenderer();
|
217
|
return renderer.getScaleFactor();
|
218
|
}
|
219
|
|
220
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221
|
|
222
|
void setCenter(float x, float y, float z)
|
223
|
{
|
224
|
GenericSurfaceView view = findViewById(R.id.genericSurfaceView);
|
225
|
GenericRenderer renderer = view.getRenderer();
|
226
|
renderer.setCenter(x,y,z);
|
227
|
}
|
228
|
|
229
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
230
|
|
231
|
void setRegion(Static4D region)
|
232
|
{
|
233
|
GenericSurfaceView view = findViewById(R.id.genericSurfaceView);
|
234
|
GenericRenderer renderer = view.getRenderer();
|
235
|
renderer.setRegion( region.get0(), region.get1(), region.get2(), region.get3() );
|
236
|
}
|
237
|
|
238
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
239
|
|
240
|
public void showRegionAndCenter(View view)
|
241
|
{
|
242
|
CheckBox center = findViewById(R.id.genericCheckBoxCenter);
|
243
|
mShowCenter = center.isChecked();
|
244
|
CheckBox region = findViewById(R.id.genericCheckBoxRegion);
|
245
|
mShowRegion = region.isChecked();
|
246
|
|
247
|
GenericSurfaceView sv = findViewById(R.id.genericSurfaceView);
|
248
|
|
249
|
mViewPager.showRegionAndCenter(mShowRegion, mShowCenter, sv);
|
250
|
}
|
251
|
|
252
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
253
|
|
254
|
public void showNormal(View view)
|
255
|
{
|
256
|
CheckBox box = (CheckBox)view;
|
257
|
mShowNormal = box.isChecked();
|
258
|
|
259
|
if ( mMesh!=null )
|
260
|
{
|
261
|
mMesh.setShowNormals(mShowNormal);
|
262
|
}
|
263
|
}
|
264
|
|
265
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
266
|
|
267
|
public void triggerOIT(View view)
|
268
|
{
|
269
|
CheckBox box = (CheckBox)view;
|
270
|
mUseOIT = box.isChecked();
|
271
|
|
272
|
GenericSurfaceView sv = findViewById(R.id.genericSurfaceView);
|
273
|
sv.getRenderer().useOIT(mUseOIT);
|
274
|
}
|
275
|
|
276
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
277
|
// Overrides
|
278
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
279
|
|
280
|
@Override
|
281
|
protected void onPause()
|
282
|
{
|
283
|
GLSurfaceView mView = findViewById(R.id.genericSurfaceView);
|
284
|
if( mView!=null ) mView.onPause();
|
285
|
|
286
|
DistortedLibrary.onPause();
|
287
|
super.onPause();
|
288
|
}
|
289
|
|
290
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
291
|
|
292
|
@Override
|
293
|
protected void onResume()
|
294
|
{
|
295
|
super.onResume();
|
296
|
GLSurfaceView mView = findViewById(R.id.genericSurfaceView);
|
297
|
if( mView!=null ) mView.onResume();
|
298
|
}
|
299
|
|
300
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
301
|
|
302
|
@Override
|
303
|
protected void onDestroy()
|
304
|
{
|
305
|
DistortedLibrary.onDestroy();
|
306
|
super.onDestroy();
|
307
|
}
|
308
|
}
|