Revision 83e0ca5e
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/examples/generic/GenericActivity.java | ||
---|---|---|
108 | 108 |
Spinner typeSpinner = findViewById(R.id.objectpicker_spinnerType); |
109 | 109 |
typeSpinner.setOnItemSelectedListener(this); |
110 | 110 |
|
111 |
String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat", "Mesh: Sphere", "Mesh: Quad"}; |
|
111 |
String[] objectType = new String[GenericMeshList.LENGTH]; |
|
112 |
|
|
113 |
for(int mesh=0; mesh<GenericMeshList.LENGTH; mesh++) |
|
114 |
{ |
|
115 |
objectType[mesh] = "Mesh: "+GenericMeshList.getName(mesh); |
|
116 |
} |
|
112 | 117 |
|
113 | 118 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType); |
114 | 119 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
... | ... | |
214 | 219 |
Intent mainInt = new Intent( getApplicationContext(), GenericActivity2.class); |
215 | 220 |
Bundle b = new Bundle(); |
216 | 221 |
|
217 |
int rows=0, cols=0;
|
|
222 |
int rows,cols;
|
|
218 | 223 |
|
219 |
switch(mObjectType)
|
|
224 |
switch( GenericMeshList.getDimension(mObjectType) )
|
|
220 | 225 |
{ |
221 |
case 0: |
|
222 |
case 1: rows = mNumRows; |
|
223 |
cols = mNumCols; |
|
226 |
case 0: rows = 1; // a quad |
|
227 |
cols = 1; |
|
224 | 228 |
break; |
225 |
case 2: rows = mNumRows; // always make the sphere equal in X and Y
|
|
226 |
cols = mNumRows; //
|
|
229 |
case 1: rows = mNumRows; // Triangles, Sphere
|
|
230 |
cols = mNumRows; |
|
227 | 231 |
break; |
228 |
case 3: rows = 1; // a quad is always 1x1
|
|
229 |
cols = 1;
|
|
232 |
default:rows = mNumRows;
|
|
233 |
cols = mNumCols;
|
|
230 | 234 |
break; |
231 | 235 |
} |
232 | 236 |
|
... | ... | |
265 | 269 |
mObjectType = pos; |
266 | 270 |
uncheckAll(); |
267 | 271 |
|
268 |
switch(mObjectType) |
|
269 |
{ |
|
270 |
case 0: mColsPicker.setEnabled(true); |
|
271 |
mRowsPicker.setEnabled(true); |
|
272 |
mSlicPicker.setEnabled(true); |
|
273 |
break; |
|
274 |
case 1: mColsPicker.setEnabled(true); |
|
275 |
mRowsPicker.setEnabled(true); |
|
276 |
mSlicPicker.setEnabled(false); |
|
277 |
break; |
|
278 |
case 2: mColsPicker.setEnabled(false); |
|
279 |
mRowsPicker.setEnabled(true); |
|
280 |
mSlicPicker.setEnabled(false); |
|
281 |
break; |
|
282 |
case 3: mColsPicker.setEnabled(false); |
|
283 |
mRowsPicker.setEnabled(false); |
|
284 |
mSlicPicker.setEnabled(false); |
|
285 |
break; |
|
286 |
} |
|
272 |
int dim = GenericMeshList.getDimension(mObjectType); |
|
273 |
|
|
274 |
mRowsPicker.setEnabled(dim>=1); |
|
275 |
mColsPicker.setEnabled(dim>=2); |
|
276 |
mSlicPicker.setEnabled(dim>=3); |
|
287 | 277 |
} |
288 | 278 |
break; |
289 | 279 |
case R.id.objectpicker_spinnerBitmap: switch(pos) |
src/main/java/org/distorted/examples/generic/GenericActivity2.java | ||
---|---|---|
34 | 34 |
import org.distorted.library.main.DistortedLibrary; |
35 | 35 |
import org.distorted.library.main.DistortedEffects; |
36 | 36 |
import org.distorted.library.main.DistortedTexture; |
37 |
import org.distorted.library.mesh.MeshCubes; |
|
38 |
import org.distorted.library.mesh.MeshRectangles; |
|
39 | 37 |
import org.distorted.library.mesh.MeshBase; |
40 |
import org.distorted.library.mesh.MeshQuad; |
|
41 |
import org.distorted.library.mesh.MeshSphere; |
|
42 | 38 |
import org.distorted.library.type.Static3D; |
43 | 39 |
import org.distorted.library.type.Static4D; |
44 | 40 |
|
... | ... | |
80 | 76 |
mShowNormal = false; |
81 | 77 |
mUseOIT = false; |
82 | 78 |
|
83 |
mEffects= new DistortedEffects(); |
|
84 |
|
|
85 |
int maxsize = numCols > numRows ? (numCols>numSlic ? numCols:numSlic) : (numRows>numSlic ? numRows:numSlic) ; |
|
86 |
|
|
79 |
int maxsize = numCols > numRows ? (numCols>numSlic ? numCols:numSlic) : (numRows>numSlic ? numRows:numSlic); |
|
87 | 80 |
createBitmap(maxsize, bitmapID); |
88 |
|
|
89 |
switch(objectType) |
|
90 |
{ |
|
91 |
case 0: if( bitmapID!=-1 ) |
|
92 |
{ |
|
93 |
mMesh = new MeshCubes(numCols, str, numSlic); |
|
94 |
} |
|
95 |
else |
|
96 |
{ |
|
97 |
Static4D mapFB = new Static4D(0.0f,0.0f, (float)numCols/maxsize, (float)numRows/maxsize); |
|
98 |
Static4D mapLR = new Static4D(0.0f,0.0f, (float)numSlic/maxsize, (float)numRows/maxsize); |
|
99 |
Static4D mapTB = new Static4D(0.0f,0.0f, (float)numCols/maxsize, (float)numSlic/maxsize); |
|
100 |
|
|
101 |
mMesh = new MeshCubes(numCols, str, numSlic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB); |
|
102 |
} |
|
103 |
mMesh.setStretch(numCols,numRows,numSlic); |
|
104 |
break; |
|
105 |
case 1: mMesh = new MeshRectangles(numCols,numRows); |
|
106 |
mMesh.setStretch(numCols,numRows,0); |
|
107 |
break; |
|
108 |
case 2: mMesh = new MeshSphere(numRows); |
|
109 |
mMesh.setStretch(numRows,numRows,numRows); |
|
110 |
break; |
|
111 |
case 3: mMesh = new MeshQuad(); |
|
112 |
mMesh.setStretch(1,1,0); |
|
113 |
break; |
|
114 |
} |
|
81 |
mMesh = GenericMeshList.createMesh(objectType, numCols, numRows, numSlic, bitmapID, str); |
|
115 | 82 |
|
116 | 83 |
mMesh.setShowNormals(mShowNormal); |
117 | 84 |
mTexture= new DistortedTexture(); |
85 |
mEffects= new DistortedEffects(); |
|
118 | 86 |
|
119 | 87 |
final View view = getLayoutInflater().inflate(R.layout.genericlayout, null); |
120 | 88 |
|
src/main/java/org/distorted/examples/generic/GenericEffect.java | ||
---|---|---|
107 | 107 |
|
108 | 108 |
switch(mName) |
109 | 109 |
{ |
110 |
case ROTATE : effect = new MatrixEffectRotate (mDyn1, mDyn3, mCenterDyn); android.util.Log.e("eff", "adding rotate with center "+mCenterSta.get0());break;
|
|
110 |
case ROTATE : effect = new MatrixEffectRotate (mDyn1, mDyn3, mCenterDyn);break; |
|
111 | 111 |
case QUATERNION : effect = new MatrixEffectQuaternion (mDyn4, mCenterDyn); break; |
112 | 112 |
case MOVE : effect = new MatrixEffectMove (mDyn3) ; break; |
113 | 113 |
case SCALE : effect = new MatrixEffectScale (mDyn3) ; break; |
src/main/java/org/distorted/examples/generic/GenericMeshList.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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 org.distorted.library.mesh.MeshBase; |
|
23 |
import org.distorted.library.mesh.MeshCubes; |
|
24 |
import org.distorted.library.mesh.MeshQuad; |
|
25 |
import org.distorted.library.mesh.MeshRectangles; |
|
26 |
import org.distorted.library.mesh.MeshSphere; |
|
27 |
import org.distorted.library.mesh.MeshTriangles; |
|
28 |
import org.distorted.library.type.Static4D; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public enum GenericMeshList |
|
33 |
{ |
|
34 |
CUBES ( "Cubes" , 3 ), |
|
35 |
RECTANGLES ( "Rectangles" , 2 ), |
|
36 |
SPHERE ( "Sphere" , 1 ), |
|
37 |
QUAD ( "Quad" , 0 ), |
|
38 |
TRIANGLES ( "Triangles" , 1 ), |
|
39 |
; |
|
40 |
|
|
41 |
static final int LENGTH = values().length; |
|
42 |
private static final GenericMeshList[] meshes; |
|
43 |
private String mName; |
|
44 |
private int mDimension; |
|
45 |
|
|
46 |
static |
|
47 |
{ |
|
48 |
int i=0; |
|
49 |
meshes = new GenericMeshList[LENGTH]; |
|
50 |
|
|
51 |
for(GenericMeshList mesh: GenericMeshList.values()) |
|
52 |
{ |
|
53 |
meshes[i++] = mesh; |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
GenericMeshList(String name, int dim ) |
|
60 |
{ |
|
61 |
mName = name; |
|
62 |
mDimension = dim; |
|
63 |
} |
|
64 |
|
|
65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 |
|
|
67 |
static String getName(int ordinal) |
|
68 |
{ |
|
69 |
return meshes[ordinal].mName; |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
static int getDimension(int ordinal) |
|
75 |
{ |
|
76 |
return meshes[ordinal].mDimension; |
|
77 |
} |
|
78 |
|
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
|
|
81 |
static MeshBase createMesh(int ordinal, int cols, int rows, int slic, int bitmapID, String str) |
|
82 |
{ |
|
83 |
MeshBase mesh; |
|
84 |
|
|
85 |
int maxsize = cols > rows ? (cols>slic ? cols:slic) : (rows>slic ? rows:slic) ; |
|
86 |
|
|
87 |
switch( meshes[ordinal] ) |
|
88 |
{ |
|
89 |
case CUBES : if( bitmapID!=-1 ) |
|
90 |
{ |
|
91 |
mesh = new MeshCubes(cols, str, slic); |
|
92 |
} |
|
93 |
else |
|
94 |
{ |
|
95 |
Static4D mapFB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)rows/maxsize); |
|
96 |
Static4D mapLR = new Static4D(0.0f,0.0f, (float)slic/maxsize, (float)rows/maxsize); |
|
97 |
Static4D mapTB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)slic/maxsize); |
|
98 |
|
|
99 |
mesh = new MeshCubes(cols, str, slic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB); |
|
100 |
} |
|
101 |
mesh.setStretch(cols,rows,slic); |
|
102 |
break; |
|
103 |
case RECTANGLES: mesh = new MeshRectangles(cols,rows); |
|
104 |
mesh.setStretch(cols,rows,0); |
|
105 |
break; |
|
106 |
case SPHERE : mesh = new MeshSphere(rows); |
|
107 |
mesh.setStretch(rows,rows,rows); |
|
108 |
break; |
|
109 |
case QUAD : mesh = new MeshQuad(); |
|
110 |
mesh.setStretch(1,1,0); |
|
111 |
break; |
|
112 |
case TRIANGLES : mesh = new MeshTriangles(rows); |
|
113 |
mesh.setStretch(rows,rows,0); |
|
114 |
break; |
|
115 |
default: mesh = null; |
|
116 |
android.util.Log.e("Meshes", "Error: unimplemented Mesh!"); |
|
117 |
} |
|
118 |
|
|
119 |
return mesh; |
|
120 |
} |
|
121 |
} |
src/main/java/org/distorted/examples/inflate/InflateActivity.java | ||
---|---|---|
108 | 108 |
Spinner typeSpinner = findViewById(R.id.objectpicker_spinnerType); |
109 | 109 |
typeSpinner.setOnItemSelectedListener(this); |
110 | 110 |
|
111 |
String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat", "Mesh: Sphere", "Mesh: Quad"}; |
|
111 |
String[] objectType = new String[InflateMeshList.LENGTH]; |
|
112 |
|
|
113 |
for(int mesh=0; mesh<InflateMeshList.LENGTH; mesh++) |
|
114 |
{ |
|
115 |
objectType[mesh] = "Mesh: "+InflateMeshList.getName(mesh); |
|
116 |
} |
|
112 | 117 |
|
113 | 118 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType); |
114 | 119 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
... | ... | |
214 | 219 |
Intent mainInt = new Intent( getApplicationContext(), InflateActivity2.class); |
215 | 220 |
Bundle b = new Bundle(); |
216 | 221 |
|
217 |
int rows=0, cols=0;
|
|
222 |
int rows,cols;
|
|
218 | 223 |
|
219 |
switch(mObjectType)
|
|
224 |
switch( InflateMeshList.getDimension(mObjectType) )
|
|
220 | 225 |
{ |
221 |
case 0: |
|
222 |
case 1: rows = mNumRows; |
|
223 |
cols = mNumCols; |
|
226 |
case 0: rows = 1; // a quad |
|
227 |
cols = 1; |
|
224 | 228 |
break; |
225 |
case 2: rows = mNumRows; // always make the sphere equal in X and Y
|
|
226 |
cols = mNumRows; //
|
|
229 |
case 1: rows = mNumRows; // Triangles, Sphere
|
|
230 |
cols = mNumRows; |
|
227 | 231 |
break; |
228 |
case 3: rows = 1; // a quad is always 1x1
|
|
229 |
cols = 1;
|
|
232 |
default:rows = mNumRows;
|
|
233 |
cols = mNumCols;
|
|
230 | 234 |
break; |
231 | 235 |
} |
232 | 236 |
|
... | ... | |
265 | 269 |
mObjectType = pos; |
266 | 270 |
uncheckAll(); |
267 | 271 |
|
268 |
switch(mObjectType) |
|
269 |
{ |
|
270 |
case 0: mColsPicker.setEnabled(true); |
|
271 |
mRowsPicker.setEnabled(true); |
|
272 |
mSlicPicker.setEnabled(true); |
|
273 |
break; |
|
274 |
case 1: mColsPicker.setEnabled(true); |
|
275 |
mRowsPicker.setEnabled(true); |
|
276 |
mSlicPicker.setEnabled(false); |
|
277 |
break; |
|
278 |
case 2: mColsPicker.setEnabled(false); |
|
279 |
mRowsPicker.setEnabled(true); |
|
280 |
mSlicPicker.setEnabled(false); |
|
281 |
break; |
|
282 |
case 3: mColsPicker.setEnabled(false); |
|
283 |
mRowsPicker.setEnabled(false); |
|
284 |
mSlicPicker.setEnabled(false); |
|
285 |
break; |
|
286 |
} |
|
272 |
int dim = InflateMeshList.getDimension(mObjectType); |
|
273 |
|
|
274 |
mRowsPicker.setEnabled(dim>=1); |
|
275 |
mColsPicker.setEnabled(dim>=2); |
|
276 |
mSlicPicker.setEnabled(dim>=3); |
|
287 | 277 |
} |
288 | 278 |
break; |
289 | 279 |
case R.id.objectpicker_spinnerBitmap: switch(pos) |
src/main/java/org/distorted/examples/inflate/InflateActivity2.java | ||
---|---|---|
23 | 23 |
import org.distorted.examples.R; |
24 | 24 |
import org.distorted.library.main.DistortedTexture; |
25 | 25 |
import org.distorted.library.mesh.MeshBase; |
26 |
import org.distorted.library.mesh.MeshCubes; |
|
27 |
import org.distorted.library.mesh.MeshRectangles; |
|
28 |
import org.distorted.library.mesh.MeshQuad; |
|
29 |
import org.distorted.library.mesh.MeshSphere; |
|
30 |
import org.distorted.library.type.Static4D; |
|
31 | 26 |
|
32 | 27 |
import android.app.Activity; |
33 | 28 |
import android.graphics.Bitmap; |
... | ... | |
54 | 49 |
private TextView mTextLevel; |
55 | 50 |
private DistortedTexture mTexture; |
56 | 51 |
private MeshBase mMesh; |
57 |
private int mNumCols, mNumRows, mNumSlic; |
|
58 | 52 |
|
59 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
60 | 54 |
|
... | ... | |
100 | 94 |
String str = b.getString("string"); |
101 | 95 |
int objectType = b.getInt("type"); |
102 | 96 |
int bitmapID = b.getInt("bitmap"); |
103 |
mNumCols = b.getInt("cols"); |
|
104 |
mNumRows = b.getInt("rows"); |
|
105 |
mNumSlic = b.getInt("slices"); |
|
106 |
|
|
107 |
int maxsize = mNumCols > mNumRows ? (mNumCols>mNumSlic ? mNumCols:mNumSlic) : (mNumRows>mNumSlic ? mNumRows:mNumSlic) ; |
|
97 |
int numCols = b.getInt("cols"); |
|
98 |
int numRows = b.getInt("rows"); |
|
99 |
int numSlic = b.getInt("slices"); |
|
108 | 100 |
|
101 |
int maxsize = numCols > numRows ? (numCols>numSlic ? numCols:numSlic) : (numRows>numSlic ? numRows:numSlic); |
|
109 | 102 |
createBitmap(maxsize,bitmapID); |
110 |
|
|
111 |
switch(objectType) |
|
112 |
{ |
|
113 |
case 0: if( bitmapID!=-1 ) |
|
114 |
{ |
|
115 |
mMesh = new MeshCubes(mNumCols, str, mNumSlic); |
|
116 |
} |
|
117 |
else |
|
118 |
{ |
|
119 |
Static4D mapFB = new Static4D(0.0f,0.0f, (float)mNumCols/maxsize, (float)mNumRows/maxsize); |
|
120 |
Static4D mapLR = new Static4D(0.0f,0.0f, (float)mNumSlic/maxsize, (float)mNumRows/maxsize); |
|
121 |
Static4D mapTB = new Static4D(0.0f,0.0f, (float)mNumCols/maxsize, (float)mNumSlic/maxsize); |
|
122 |
|
|
123 |
mMesh = new MeshCubes(mNumCols, str, mNumSlic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB); |
|
124 |
} |
|
125 |
mMesh.setStretch(mNumCols,mNumRows,mNumSlic); |
|
126 |
break; |
|
127 |
case 1: mMesh = new MeshRectangles(mNumCols,mNumRows); |
|
128 |
mMesh.setStretch(mNumCols,mNumRows,0); |
|
129 |
break; |
|
130 |
case 2: mMesh = new MeshSphere(mNumRows); |
|
131 |
mMesh.setStretch(mNumRows,mNumRows,mNumRows); |
|
132 |
break; |
|
133 |
case 3: mMesh = new MeshQuad(); |
|
134 |
mMesh.setStretch(1,1,0); |
|
135 |
break; |
|
136 |
} |
|
137 |
|
|
103 |
mMesh = InflateMeshList.createMesh(objectType, numCols, numRows, numSlic, bitmapID, str); |
|
138 | 104 |
mTexture = new DistortedTexture(); |
139 | 105 |
|
140 | 106 |
setContentView(R.layout.inflatelayout); |
141 | 107 |
|
142 |
Spinner renderSpinner = findViewById(R.id.inflateSpinnerMode);
|
|
108 |
Spinner renderSpinner = findViewById(R.id.inflateSpinnerMode); |
|
143 | 109 |
renderSpinner.setOnItemSelectedListener(this); |
144 | 110 |
|
145 | 111 |
String[] objectBitmap = new String[] { "Render: Normal", "Render: OIT" }; |
... | ... | |
268 | 234 |
{ |
269 | 235 |
return mMesh; |
270 | 236 |
} |
271 |
|
|
272 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
273 |
|
|
274 |
public int getNumCols() |
|
275 |
{ |
|
276 |
return mNumCols; |
|
277 |
} |
|
278 |
|
|
279 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
280 |
|
|
281 |
public int getNumRows() |
|
282 |
{ |
|
283 |
return mNumRows; |
|
284 |
} |
|
285 |
|
|
286 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
287 |
|
|
288 |
public int getNumSlic() |
|
289 |
{ |
|
290 |
return mNumSlic; |
|
291 |
} |
|
292 | 237 |
} |
src/main/java/org/distorted/examples/inflate/InflateMeshList.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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.inflate; |
|
21 |
|
|
22 |
import org.distorted.library.mesh.MeshBase; |
|
23 |
import org.distorted.library.mesh.MeshCubes; |
|
24 |
import org.distorted.library.mesh.MeshQuad; |
|
25 |
import org.distorted.library.mesh.MeshRectangles; |
|
26 |
import org.distorted.library.mesh.MeshSphere; |
|
27 |
import org.distorted.library.mesh.MeshTriangles; |
|
28 |
import org.distorted.library.type.Static4D; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public enum InflateMeshList |
|
33 |
{ |
|
34 |
CUBES ( "Cubes" , 3 ), |
|
35 |
RECTANGLES ( "Rectangles" , 2 ), |
|
36 |
SPHERE ( "Sphere" , 1 ), |
|
37 |
QUAD ( "Quad" , 0 ), |
|
38 |
TRIANGLES ( "Triangles" , 1 ), |
|
39 |
; |
|
40 |
|
|
41 |
static final int LENGTH = values().length; |
|
42 |
private static final InflateMeshList[] meshes; |
|
43 |
private String mName; |
|
44 |
private int mDimension; |
|
45 |
|
|
46 |
static |
|
47 |
{ |
|
48 |
int i=0; |
|
49 |
meshes = new InflateMeshList[LENGTH]; |
|
50 |
|
|
51 |
for(InflateMeshList mesh: InflateMeshList.values()) |
|
52 |
{ |
|
53 |
meshes[i++] = mesh; |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
InflateMeshList(String name, int dim ) |
|
60 |
{ |
|
61 |
mName = name; |
|
62 |
mDimension = dim; |
|
63 |
} |
|
64 |
|
|
65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 |
|
|
67 |
static String getName(int ordinal) |
|
68 |
{ |
|
69 |
return meshes[ordinal].mName; |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
static int getDimension(int ordinal) |
|
75 |
{ |
|
76 |
return meshes[ordinal].mDimension; |
|
77 |
} |
|
78 |
|
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
|
|
81 |
static MeshBase createMesh(int ordinal, int cols, int rows, int slic, int bitmapID, String str) |
|
82 |
{ |
|
83 |
MeshBase mesh; |
|
84 |
|
|
85 |
int maxsize = cols > rows ? (cols>slic ? cols:slic) : (rows>slic ? rows:slic) ; |
|
86 |
|
|
87 |
switch( meshes[ordinal] ) |
|
88 |
{ |
|
89 |
case CUBES : if( bitmapID!=-1 ) |
|
90 |
{ |
|
91 |
mesh = new MeshCubes(cols, str, slic); |
|
92 |
} |
|
93 |
else |
|
94 |
{ |
|
95 |
Static4D mapFB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)rows/maxsize); |
|
96 |
Static4D mapLR = new Static4D(0.0f,0.0f, (float)slic/maxsize, (float)rows/maxsize); |
|
97 |
Static4D mapTB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)slic/maxsize); |
|
98 |
|
|
99 |
mesh = new MeshCubes(cols, str, slic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB); |
|
100 |
} |
|
101 |
mesh.setStretch(cols,rows,slic); |
|
102 |
break; |
|
103 |
case RECTANGLES: mesh = new MeshRectangles(cols,rows); |
|
104 |
mesh.setStretch(cols,rows,0); |
|
105 |
break; |
|
106 |
case SPHERE : mesh = new MeshSphere(rows); |
|
107 |
mesh.setStretch(rows,rows,rows); |
|
108 |
break; |
|
109 |
case QUAD : mesh = new MeshQuad(); |
|
110 |
mesh.setStretch(1,1,0); |
|
111 |
break; |
|
112 |
case TRIANGLES : mesh = new MeshTriangles(rows); |
|
113 |
mesh.setStretch(rows,rows,0); |
|
114 |
break; |
|
115 |
default: mesh = null; |
|
116 |
android.util.Log.e("Meshes", "Error: unimplemented Mesh!"); |
|
117 |
} |
|
118 |
|
|
119 |
return mesh; |
|
120 |
} |
|
121 |
} |
Also available in: Unified diff
New Mesh 'Triangles' and updated Inflate & Generic apps to test it.