Revision e3c87517
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/examples/inflate/InflateActivity.java | ||
---|---|---|
143 | 143 |
int height= mLay.getHeight(); |
144 | 144 |
int w = mNumCols>0 ? (int)( 0.9f*width / mNumCols) : 0; |
145 | 145 |
int h = mNumRows>0 ? (int)( 0.9f*height/ mNumRows) : 0; |
146 |
int size= w<h ? w:h;
|
|
146 |
int size= Math.min(w, h);
|
|
147 | 147 |
int pad = size<20 ? 1 : size/20; |
148 | 148 |
|
149 | 149 |
mLay.removeAllViews(); |
... | ... | |
219 | 219 |
Intent mainInt = new Intent( getApplicationContext(), InflateActivity2.class); |
220 | 220 |
Bundle b = new Bundle(); |
221 | 221 |
|
222 |
int rows,cols; |
|
223 |
|
|
224 |
switch( InflateMeshList.getDimension(mObjectType) ) |
|
225 |
{ |
|
226 |
case 0: rows = 1; // a quad |
|
227 |
cols = 1; |
|
228 |
break; |
|
229 |
case 1: rows = mNumRows; // Triangles, Sphere |
|
230 |
cols = mNumRows; |
|
231 |
break; |
|
232 |
default:rows = mNumRows; |
|
233 |
cols = mNumCols; |
|
234 |
break; |
|
235 |
} |
|
236 |
|
|
237 |
b.putInt("type", mObjectType); |
|
238 |
b.putInt("cols", cols); |
|
239 |
b.putInt("rows", rows); |
|
240 |
b.putInt("slices", mNumSlic); |
|
222 |
b.putInt("type" , mObjectType); |
|
223 |
b.putInt("cols" , InflateMeshList.getCols(mObjectType, mNumCols, mNumRows, mNumSlic) ); |
|
224 |
b.putInt("rows" , InflateMeshList.getRows(mObjectType, mNumCols, mNumRows, mNumSlic) ); |
|
225 |
b.putInt("slices", InflateMeshList.getSlic(mObjectType, mNumCols, mNumRows, mNumSlic) ); |
|
241 | 226 |
b.putInt("bitmap", mBitmapID); |
242 | 227 |
|
243 |
if( mObjectType==0 ) // cubes |
|
244 |
{ |
|
245 |
String str = ""; |
|
246 |
|
|
247 |
for(int i=0; i<mNumRows*mNumCols; i++) |
|
248 |
str += mShape[i] ? "1" : "0"; |
|
249 |
|
|
250 |
b.putString("string", str); |
|
251 |
} |
|
252 |
else |
|
253 |
{ |
|
254 |
b.putString("string", ""); |
|
255 |
} |
|
228 |
b.putString("string", InflateMeshList.getString(mObjectType, mNumCols, mNumRows, mShape)); |
|
256 | 229 |
|
257 | 230 |
mainInt.putExtras(b); |
258 | 231 |
startActivity(mainInt); |
src/main/java/org/distorted/examples/inflate/InflateActivity2.java | ||
---|---|---|
49 | 49 |
private TextView mTextLevel; |
50 | 50 |
private DistortedTexture mTexture; |
51 | 51 |
private MeshBase mMesh; |
52 |
private int mNumRows, mNumCols, mNumSlic; |
|
52 | 53 |
|
53 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 | 55 |
|
... | ... | |
94 | 95 |
String str = b.getString("string"); |
95 | 96 |
int objectType = b.getInt("type"); |
96 | 97 |
int bitmapID = b.getInt("bitmap"); |
97 |
int numCols = b.getInt("cols");
|
|
98 |
int numRows = b.getInt("rows");
|
|
99 |
int numSlic = b.getInt("slices");
|
|
98 |
mNumCols = b.getInt("cols");
|
|
99 |
mNumRows = b.getInt("rows");
|
|
100 |
mNumSlic = b.getInt("slices");
|
|
100 | 101 |
|
101 |
int maxsize = numCols > numRows ? (Math.max(numCols, numSlic)) : (Math.max(numRows, numSlic));
|
|
102 |
int maxsize = mNumCols > mNumRows ? (Math.max(mNumCols, mNumSlic)) : (Math.max(mNumRows, mNumSlic));
|
|
102 | 103 |
createBitmap(maxsize,bitmapID); |
103 |
mMesh = InflateMeshList.createMesh(objectType, numCols, numRows, numSlic, bitmapID, str); |
|
104 |
mMesh = InflateMeshList.createMesh(objectType, mNumCols, mNumRows, mNumSlic, bitmapID, str); |
|
105 |
|
|
104 | 106 |
mTexture = new DistortedTexture(); |
105 | 107 |
|
106 | 108 |
setContentView(R.layout.inflatelayout); |
... | ... | |
131 | 133 |
{ |
132 | 134 |
if( bitmapID!=-1) |
133 | 135 |
{ |
134 |
InputStream is = getResources().openRawResource(bitmapID); |
|
135 |
|
|
136 |
try |
|
136 |
try (InputStream is = getResources().openRawResource(bitmapID)) |
|
137 | 137 |
{ |
138 | 138 |
mBitmap = BitmapFactory.decodeStream(is); |
139 | 139 |
} |
140 |
finally |
|
141 |
{ |
|
142 |
try |
|
143 |
{ |
|
144 |
is.close(); |
|
145 |
} |
|
146 |
catch(IOException e) { } |
|
147 |
} |
|
140 |
catch( IOException ex ) { android.util.Log.e("act", "failed to open resource "+bitmapID); } |
|
148 | 141 |
} |
149 | 142 |
else |
150 | 143 |
{ |
... | ... | |
170 | 163 |
} |
171 | 164 |
} |
172 | 165 |
|
166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
167 |
|
|
168 |
int getRows() |
|
169 |
{ |
|
170 |
return mNumRows; |
|
171 |
} |
|
172 |
|
|
173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
174 |
|
|
175 |
int getCols() |
|
176 |
{ |
|
177 |
return mNumCols; |
|
178 |
} |
|
179 |
|
|
180 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
181 |
|
|
182 |
int getSlic() |
|
183 |
{ |
|
184 |
return mNumSlic; |
|
185 |
} |
|
186 |
|
|
173 | 187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
174 | 188 |
|
175 | 189 |
public Bitmap getBitmap() |
... | ... | |
184 | 198 |
InflateSurfaceView v = this.findViewById(R.id.inflateSurfaceView); |
185 | 199 |
InflateRenderer renderer = v.getRenderer(); |
186 | 200 |
|
187 |
switch(parent.getId())
|
|
201 |
if( parent.getId()==R.id.inflateSpinnerMode)
|
|
188 | 202 |
{ |
189 |
case R.id.inflateSpinnerMode: renderer.setRenderModeToOIT(pos==1); |
|
190 |
break; |
|
203 |
renderer.setRenderModeToOIT(pos==1); |
|
191 | 204 |
} |
192 | 205 |
} |
193 | 206 |
|
src/main/java/org/distorted/examples/inflate/InflateMeshList.java | ||
---|---|---|
74 | 74 |
return meshes[ordinal].mDimension; |
75 | 75 |
} |
76 | 76 |
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
|
79 |
static int getRows(int ordinal, int cols, int rows, int slic) |
|
80 |
{ |
|
81 |
switch(ordinal) |
|
82 |
{ |
|
83 |
case 0: return rows; // cubes |
|
84 |
case 1: return rows; // rectangles |
|
85 |
case 2: return rows; // sphere |
|
86 |
case 3: return 1; // quad |
|
87 |
case 4: return rows; // triangles |
|
88 |
} |
|
89 |
|
|
90 |
return 0; |
|
91 |
} |
|
92 |
|
|
93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
94 |
|
|
95 |
static int getCols(int ordinal, int cols, int rows, int slic) |
|
96 |
{ |
|
97 |
switch(ordinal) |
|
98 |
{ |
|
99 |
case 0: return cols; // cubes |
|
100 |
case 1: return cols; // rectangles |
|
101 |
case 2: return rows; // sphere |
|
102 |
case 3: return 1; // quad |
|
103 |
case 4: return rows; // triangles |
|
104 |
} |
|
105 |
|
|
106 |
return 0; |
|
107 |
} |
|
108 |
|
|
109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
110 |
|
|
111 |
static int getSlic(int ordinal, int cols, int rows, int slic) |
|
112 |
{ |
|
113 |
switch(ordinal) |
|
114 |
{ |
|
115 |
case 0: return slic; // cubes |
|
116 |
case 1: return rows; // rectangles |
|
117 |
case 2: return rows; // sphere |
|
118 |
case 3: return 1; // quad |
|
119 |
case 4: return rows; // triangles |
|
120 |
} |
|
121 |
|
|
122 |
return 0; |
|
123 |
} |
|
124 |
|
|
125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
126 |
|
|
127 |
static String getString(int ordinal, int cols, int rows, boolean[] shape) |
|
128 |
{ |
|
129 |
if( ordinal==0 ) |
|
130 |
{ |
|
131 |
String str = ""; |
|
132 |
|
|
133 |
for(int i=0; i<rows*cols; i++) |
|
134 |
str += shape[i] ? "1" : "0"; |
|
135 |
|
|
136 |
return str; |
|
137 |
} |
|
138 |
|
|
139 |
return ""; |
|
140 |
} |
|
141 |
|
|
77 | 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
78 | 143 |
|
79 | 144 |
static MeshBase createMesh(int ordinal, int cols, int rows, int slic, int bitmapID, String str) |
80 | 145 |
{ |
81 | 146 |
MeshBase mesh; |
82 | 147 |
|
83 |
int maxsize = cols > rows ? (cols>slic ? cols:slic) : (rows>slic ? rows:slic) ;
|
|
148 |
int maxsize = cols > rows ? (Math.max(cols, slic)) : (Math.max(rows, slic)) ;
|
|
84 | 149 |
|
85 | 150 |
switch( meshes[ordinal] ) |
86 | 151 |
{ |
... | ... | |
96 | 161 |
|
97 | 162 |
mesh = new MeshCubes(cols, str, slic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB); |
98 | 163 |
} |
99 |
mesh.setStretch(cols,rows,slic); |
|
100 | 164 |
break; |
101 | 165 |
case Rectangles: mesh = new MeshRectangles(cols,rows); |
102 |
mesh.setStretch(cols,rows,0); |
|
103 | 166 |
break; |
104 | 167 |
case Sphere : mesh = new MeshSphere(rows); |
105 |
mesh.setStretch(rows,rows,rows); |
|
106 | 168 |
break; |
107 | 169 |
case Quad : mesh = new MeshQuad(); |
108 |
mesh.setStretch(1,1,0); |
|
109 | 170 |
break; |
110 | 171 |
case Triangles : mesh = new MeshTriangles(rows); |
111 |
mesh.setStretch(rows,rows,0); |
|
112 | 172 |
break; |
113 | 173 |
default: mesh = null; |
114 | 174 |
android.util.Log.e("Meshes", "Error: unimplemented Mesh!"); |
src/main/java/org/distorted/examples/inflate/InflateRenderer.java | ||
---|---|---|
25 | 25 |
import org.distorted.library.effect.FragmentEffectAlpha; |
26 | 26 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
27 | 27 |
import org.distorted.library.effect.MatrixEffectScale; |
28 |
import org.distorted.library.effect.VertexEffectScale; |
|
28 | 29 |
import org.distorted.library.main.DistortedEffects; |
29 | 30 |
import org.distorted.library.main.DistortedLibrary; |
30 | 31 |
import org.distorted.library.main.DistortedScreen; |
... | ... | |
63 | 64 |
mView = v; |
64 | 65 |
|
65 | 66 |
mAlpha = new Static1D(1.0f); |
66 |
|
|
67 | 67 |
mScale= new Static3D(1,1,1); |
68 | 68 |
|
69 | 69 |
Static3D center=new Static3D(0,0,0); |
... | ... | |
73 | 73 |
mTexture = act.getTexture(); |
74 | 74 |
mMesh = act.getMesh(); |
75 | 75 |
|
76 |
mObjWidth = mMesh.getStretchX();
|
|
77 |
mObjHeight= mMesh.getStretchY();
|
|
78 |
mObjDepth = mMesh.getStretchZ();
|
|
76 |
mObjWidth = act.getCols();
|
|
77 |
mObjHeight= act.getRows();
|
|
78 |
mObjDepth = act.getSlic();
|
|
79 | 79 |
|
80 | 80 |
mQuat1 = new Static4D(0,0,0,1); // unity |
81 | 81 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
... | ... | |
87 | 87 |
quatInt2.add(mQuat2); |
88 | 88 |
|
89 | 89 |
mEffects = new DistortedEffects(); |
90 |
mEffects.apply( new VertexEffectScale(new Static3D(mObjWidth,mObjHeight,mObjDepth) ) ); |
|
90 | 91 |
mEffects.apply( new MatrixEffectScale(mScale)); |
91 | 92 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) ); |
92 | 93 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) ); |
... | ... | |
110 | 111 |
{ |
111 | 112 |
final float SCALE = 0.75f; |
112 | 113 |
|
113 |
mScreenMin = width<height ? width:height;
|
|
114 |
mScreenMin = Math.min(width, height);
|
|
114 | 115 |
float factor = ( width*mObjHeight > height*mObjWidth ) ? (SCALE*height)/mObjHeight : (SCALE*width)/mObjWidth; |
115 | 116 |
mScale.set(factor,factor,factor); |
116 | 117 |
mScreen.resize(width, height); |
... | ... | |
150 | 151 |
mScreen.detachAll(); |
151 | 152 |
mScreen.attach(mTexture,mEffects,mMesh); |
152 | 153 |
|
154 |
VertexEffectScale.enable(); |
|
153 | 155 |
FragmentEffectAlpha.enable(); |
154 | 156 |
|
155 | 157 |
try |
Also available in: Unified diff
Convert the first app, Inflate, to the new MeshBase.setStretch-less API ( use VertexEffectScale instead )