Revision 9814e53c
Added by Leszek Koltunski almost 7 years ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 52 | 52 |
<activity android:name=".glow.GlowActivity"/> |
| 53 | 53 |
<activity android:name=".movingglow.MovingGlowActivity"/> |
| 54 | 54 |
<activity android:name=".earth.EarthActivity"/> |
| 55 |
<activity android:name=".earth.EarthActivity2"/>
|
|
| 55 |
<activity android:name=".earth.EarthActivity"/> |
|
| 56 | 56 |
</application> |
| 57 | 57 |
</manifest> |
| src/main/java/org/distorted/examples/earth/EarthActivity.java | ||
|---|---|---|
| 20 | 20 |
package org.distorted.examples.earth; |
| 21 | 21 |
|
| 22 | 22 |
import android.app.Activity; |
| 23 |
import android.content.Intent;
|
|
| 23 |
import android.opengl.GLSurfaceView;
|
|
| 24 | 24 |
import android.os.Bundle; |
| 25 |
import android.view.Gravity; |
|
| 26 |
import android.view.View; |
|
| 27 |
import android.widget.AdapterView; |
|
| 28 |
import android.widget.ArrayAdapter; |
|
| 29 |
import android.widget.Button; |
|
| 30 |
import android.widget.LinearLayout; |
|
| 31 |
import android.widget.NumberPicker; |
|
| 32 |
import android.widget.Spinner; |
|
| 33 |
import android.widget.TableRow; |
|
| 25 |
import android.widget.SeekBar; |
|
| 34 | 26 |
|
| 35 | 27 |
import org.distorted.examples.R; |
| 28 |
import org.distorted.library.main.Distorted; |
|
| 29 |
import org.distorted.library.main.DistortedTexture; |
|
| 30 |
import org.distorted.library.mesh.MeshBase; |
|
| 31 |
import org.distorted.library.mesh.MeshSphere; |
|
| 36 | 32 |
|
| 37 | 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 38 | 34 |
|
| 39 |
public class EarthActivity extends Activity |
|
| 40 |
implements View.OnClickListener, AdapterView.OnItemSelectedListener |
|
| 41 |
{
|
|
| 42 |
private static final int COLOR_OFF = 0xffffe81f; |
|
| 43 |
private static final int COLOR_ON = 0xff0000ff; |
|
| 44 |
private static final int COLOR_INAC= 0xff999999; |
|
| 35 |
public class EarthActivity extends Activity implements SeekBar.OnSeekBarChangeListener |
|
| 36 |
{
|
|
| 37 |
private static final int SIZE = 100; |
|
| 38 |
private static final int LEVEL= 32; |
|
| 45 | 39 |
|
| 46 |
private int mNumCols = 1; |
|
| 47 |
private int mNumRows = 1; |
|
| 48 |
private int mNumSlic = 1; |
|
| 49 |
private boolean mGridInitialized; |
|
| 50 |
private NumberPicker mColsPicker, mRowsPicker, mSlicPicker; |
|
| 51 |
private boolean[] mShape; |
|
| 52 |
private int mObjectType; |
|
| 53 |
private int mBitmapID; |
|
| 54 |
private LinearLayout mLay; |
|
| 40 |
private DistortedTexture mTexture; |
|
| 41 |
private MeshBase mMesh; |
|
| 55 | 42 |
|
| 56 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 57 |
|
|
| 58 |
@Override |
|
| 59 |
protected void onCreate(Bundle savedState) |
|
| 60 |
{
|
|
| 61 |
super.onCreate(savedState); |
|
| 62 |
|
|
| 63 |
setContentView(R.layout.objectpickerlayout); |
|
| 64 |
|
|
| 65 |
mLay = findViewById(R.id.objectpicker_buttongrid); |
|
| 66 |
|
|
| 67 |
mColsPicker = findViewById(R.id.objectpicker_cols); |
|
| 68 |
mRowsPicker = findViewById(R.id.objectpicker_rows); |
|
| 69 |
mSlicPicker = findViewById(R.id.objectpicker_slices); |
|
| 70 |
|
|
| 71 |
mColsPicker.setMaxValue(40); |
|
| 72 |
mColsPicker.setMinValue( 1); |
|
| 73 |
mRowsPicker.setMaxValue(40); |
|
| 74 |
mRowsPicker.setMinValue( 1); |
|
| 75 |
mSlicPicker.setMaxValue(40); |
|
| 76 |
mSlicPicker.setMinValue( 0); |
|
| 77 |
|
|
| 78 |
mColsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() |
|
| 79 |
{
|
|
| 80 |
@Override |
|
| 81 |
public void onValueChange(NumberPicker picker, int oldVal, int newVal) |
|
| 82 |
{
|
|
| 83 |
setGrid(); |
|
| 84 |
} |
|
| 85 |
}); |
|
| 86 |
|
|
| 87 |
mRowsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() |
|
| 88 |
{
|
|
| 89 |
@Override |
|
| 90 |
public void onValueChange(NumberPicker picker, int oldVal, int newVal) |
|
| 91 |
{
|
|
| 92 |
setGrid(); |
|
| 93 |
} |
|
| 94 |
}); |
|
| 95 |
|
|
| 96 |
mSlicPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() |
|
| 97 |
{
|
|
| 98 |
@Override |
|
| 99 |
public void onValueChange(NumberPicker picker, int oldVal, int newVal) |
|
| 100 |
{
|
|
| 101 |
mNumSlic = mSlicPicker.getValue(); |
|
| 102 |
} |
|
| 103 |
}); |
|
| 104 |
|
|
| 105 |
mObjectType = 0; |
|
| 106 |
mGridInitialized = false; |
|
| 107 |
|
|
| 108 |
Spinner typeSpinner = findViewById(R.id.objectpicker_spinnerType); |
|
| 109 |
typeSpinner.setOnItemSelectedListener(this); |
|
| 110 |
|
|
| 111 |
String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat", "Mesh: Sphere", "Mesh: Quad"};
|
|
| 112 |
|
|
| 113 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType); |
|
| 114 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 115 |
typeSpinner.setAdapter(adapterType); |
|
| 116 |
|
|
| 117 |
Spinner bitmapSpinner = findViewById(R.id.objectpicker_spinnerBitmap); |
|
| 118 |
bitmapSpinner.setOnItemSelectedListener(this); |
|
| 119 |
|
|
| 120 |
String[] objectBitmap = new String[] { "Texture: Grid", "Texture: Girl", "Texture: Dog", "Texture: Cat",
|
|
| 121 |
"Texture: Squares", "Texture: Bean", "Texture: Lisa", "Texture: World" }; |
|
| 122 |
|
|
| 123 |
ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap); |
|
| 124 |
adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 125 |
bitmapSpinner.setAdapter(adapterBitmap); |
|
| 126 |
} |
|
| 127 |
|
|
| 128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 129 |
|
|
| 130 |
private void setGrid() |
|
| 131 |
{
|
|
| 132 |
mGridInitialized = true; |
|
| 133 |
|
|
| 134 |
mNumCols = mColsPicker.getValue(); |
|
| 135 |
mNumRows = mRowsPicker.getValue(); |
|
| 136 |
|
|
| 137 |
int width = mLay.getWidth(); |
|
| 138 |
int height= mLay.getHeight(); |
|
| 139 |
int w = mNumCols>0 ? (int)( 0.9f*width / mNumCols) : 0; |
|
| 140 |
int h = mNumRows>0 ? (int)( 0.9f*height/ mNumRows) : 0; |
|
| 141 |
int size= w<h ? w:h; |
|
| 142 |
int pad = size<20 ? 1 : size/20; |
|
| 143 |
|
|
| 144 |
mLay.removeAllViews(); |
|
| 145 |
|
|
| 146 |
mShape = new boolean[mNumRows*mNumCols]; |
|
| 147 |
|
|
| 148 |
TableRow.LayoutParams p = new TableRow.LayoutParams(); |
|
| 149 |
|
|
| 150 |
p.rightMargin = pad; |
|
| 151 |
p.leftMargin = pad; |
|
| 152 |
p.topMargin = pad; |
|
| 153 |
p.bottomMargin = pad; |
|
| 154 |
p.height = size; |
|
| 155 |
p.width = size; |
|
| 156 |
|
|
| 157 |
for (int rows=0; rows<mNumRows; rows++) |
|
| 44 |
|
|
| 45 |
@Override |
|
| 46 |
protected void onPause() |
|
| 158 | 47 |
{
|
| 159 |
TableRow tr = new TableRow(this); |
|
| 160 |
tr.setGravity(Gravity.CENTER); |
|
| 161 |
|
|
| 162 |
for(int cols=0; cols<mNumCols; cols++) |
|
| 163 |
{
|
|
| 164 |
Button b = new Button(this); |
|
| 165 |
b.setOnClickListener(this); |
|
| 166 |
b.setId(rows*mNumCols+cols); |
|
| 167 |
b.setLayoutParams(p); |
|
| 168 |
b.setBackgroundColor(mObjectType==0 ? COLOR_ON:COLOR_INAC); |
|
| 169 |
tr.addView(b, p); |
|
| 170 |
mShape[rows*mNumCols+cols] = true; |
|
| 171 |
} |
|
| 48 |
GLSurfaceView mView = this.findViewById(R.id.earthSurfaceView); |
|
| 49 |
if( mView!=null ) mView.onPause(); |
|
| 172 | 50 |
|
| 173 |
mLay.addView(tr); |
|
| 51 |
Distorted.onPause(); |
|
| 52 |
super.onPause(); |
|
| 174 | 53 |
} |
| 175 |
} |
|
| 176 | 54 |
|
| 177 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 178 |
|
|
| 179 |
public void onClick(View view) |
|
| 180 |
{
|
|
| 181 |
if( mObjectType==0 ) // cubes |
|
| 56 |
|
|
| 57 |
@Override |
|
| 58 |
protected void onResume() |
|
| 182 | 59 |
{
|
| 183 |
Button tmp = (Button)view;
|
|
| 184 |
int id = tmp.getId(); |
|
| 185 |
mShape[id] = !mShape[id];
|
|
| 186 |
tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
|
|
| 60 |
super.onResume();
|
|
| 61 |
|
|
| 62 |
GLSurfaceView mView = this.findViewById(R.id.earthSurfaceView);
|
|
| 63 |
if( mView!=null ) mView.onResume();
|
|
| 187 | 64 |
} |
| 188 |
} |
|
| 189 |
|
|
| 65 |
|
|
| 190 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 191 |
|
|
| 192 |
private void uncheckAll() |
|
| 193 |
{
|
|
| 194 |
TableRow tr; |
|
| 195 |
Button butt; |
|
| 196 |
|
|
| 197 |
for (int row=0; row<mNumRows; row++) |
|
| 67 |
|
|
| 68 |
@Override |
|
| 69 |
protected void onDestroy() |
|
| 198 | 70 |
{
|
| 199 |
tr = (TableRow)mLay.getChildAt(row); |
|
| 200 |
|
|
| 201 |
for(int col=0; col<mNumCols; col++) |
|
| 202 |
{
|
|
| 203 |
butt = (Button)tr.getVirtualChildAt(col); |
|
| 204 |
butt.setBackgroundColor(mObjectType==0 ? COLOR_ON : COLOR_INAC); |
|
| 205 |
mShape[row*mNumCols+col] = true; |
|
| 206 |
} |
|
| 71 |
Distorted.onDestroy(); |
|
| 72 |
super.onDestroy(); |
|
| 207 | 73 |
} |
| 208 |
} |
|
| 209 |
|
|
| 74 |
|
|
| 210 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 211 | 76 |
|
| 212 |
public void Create(View v) |
|
| 213 |
{
|
|
| 214 |
Intent mainInt = new Intent( getApplicationContext(), EarthActivity2.class); |
|
| 215 |
Bundle b = new Bundle(); |
|
| 216 |
|
|
| 217 |
int rows=0, cols=0; |
|
| 218 |
|
|
| 219 |
switch(mObjectType) |
|
| 77 |
@Override |
|
| 78 |
protected void onCreate(Bundle savedState) |
|
| 220 | 79 |
{
|
| 221 |
case 0: |
|
| 222 |
case 1: rows = mNumRows; |
|
| 223 |
cols = mNumCols; |
|
| 224 |
break; |
|
| 225 |
case 2: rows = mNumRows; // always make the sphere equal in X and Y |
|
| 226 |
cols = mNumRows; // |
|
| 227 |
break; |
|
| 228 |
case 3: rows = 1; // a quad is always 1x1 |
|
| 229 |
cols = 1; |
|
| 230 |
break; |
|
| 231 |
} |
|
| 232 |
|
|
| 233 |
b.putInt("type", mObjectType);
|
|
| 234 |
b.putInt("cols", cols);
|
|
| 235 |
b.putInt("rows", rows);
|
|
| 236 |
b.putInt("slices", mNumSlic);
|
|
| 237 |
b.putInt("bitmap", mBitmapID);
|
|
| 80 |
super.onCreate(savedState); |
|
| 238 | 81 |
|
| 239 |
if( mObjectType==0 ) // cubes |
|
| 240 |
{
|
|
| 241 |
String str = ""; |
|
| 82 |
mMesh = new MeshSphere(LEVEL); |
|
| 83 |
mTexture= new DistortedTexture(SIZE,SIZE); |
|
| 242 | 84 |
|
| 243 |
for(int i=0; i<mNumRows*mNumCols; i++) |
|
| 244 |
str += mShape[i] ? "1" : "0"; |
|
| 85 |
setContentView(R.layout.earthlayout); |
|
| 245 | 86 |
|
| 246 |
b.putString("string", str);
|
|
| 247 |
} |
|
| 248 |
else |
|
| 249 |
{
|
|
| 250 |
b.putString("string", "");
|
|
| 87 |
SeekBar levelBar = findViewById(R.id.earthInflateLevel); |
|
| 88 |
levelBar.setOnSeekBarChangeListener(this); |
|
| 89 |
levelBar.setProgress(50); |
|
| 251 | 90 |
} |
| 252 | 91 |
|
| 253 |
mainInt.putExtras(b); |
|
| 254 |
startActivity(mainInt); |
|
| 255 |
} |
|
| 256 |
|
|
| 257 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 258 | 93 |
|
| 259 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
| 260 |
{
|
|
| 261 |
switch(parent.getId()) |
|
| 94 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
| 262 | 95 |
{
|
| 263 |
case R.id.objectpicker_spinnerType : if( mObjectType!=pos ) |
|
| 264 |
{
|
|
| 265 |
mObjectType = pos; |
|
| 266 |
uncheckAll(); |
|
| 267 |
|
|
| 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 |
} |
|
| 287 |
} |
|
| 288 |
break; |
|
| 289 |
case R.id.objectpicker_spinnerBitmap: switch(pos) |
|
| 290 |
{
|
|
| 291 |
case 0: mBitmapID = -1 ; break; |
|
| 292 |
case 1: mBitmapID = R.raw.face ; break; |
|
| 293 |
case 2: mBitmapID = R.raw.dog ; break; |
|
| 294 |
case 3: mBitmapID = R.raw.cat ; break; |
|
| 295 |
case 4: mBitmapID = R.raw.grid ; break; |
|
| 296 |
case 5: mBitmapID = R.raw.bean ; break; |
|
| 297 |
case 6: mBitmapID = R.raw.monalisa; break; |
|
| 298 |
case 7: mBitmapID = R.raw.world ; break; |
|
| 299 |
} |
|
| 300 |
break; |
|
| 96 |
switch (bar.getId()) |
|
| 97 |
{
|
|
| 98 |
case R.id.earthInflateLevel: EarthSurfaceView view = this.findViewById(R.id.earthSurfaceView); |
|
| 99 |
view.getRenderer().setLevel(progress); |
|
| 100 |
break; |
|
| 101 |
} |
|
| 301 | 102 |
} |
| 302 |
} |
|
| 303 | 103 |
|
| 304 | 104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 305 | 105 |
|
| 306 |
public void onNothingSelected(AdapterView<?> parent) |
|
| 307 |
{
|
|
| 308 |
} |
|
| 106 |
public void onStartTrackingTouch(SeekBar bar) { }
|
|
| 309 | 107 |
|
| 310 | 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 311 |
// Overrides |
|
| 109 |
|
|
| 110 |
public void onStopTrackingTouch(SeekBar bar) { }
|
|
| 111 |
|
|
| 312 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 313 | 113 |
|
| 314 |
@Override
|
|
| 315 |
public void onWindowFocusChanged(boolean hasFocus)
|
|
| 316 |
{
|
|
| 317 |
super.onWindowFocusChanged(hasFocus);
|
|
| 114 |
public DistortedTexture getTexture()
|
|
| 115 |
{
|
|
| 116 |
return mTexture;
|
|
| 117 |
}
|
|
| 318 | 118 |
|
| 319 |
mColsPicker.setValue(mNumCols); |
|
| 320 |
mRowsPicker.setValue(mNumRows); |
|
| 321 |
mSlicPicker.setValue(mNumSlic); |
|
| 119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 322 | 120 |
|
| 323 |
if( !mGridInitialized ) setGrid(); |
|
| 324 |
} |
|
| 325 |
} |
|
| 121 |
public MeshBase getMesh() |
|
| 122 |
{
|
|
| 123 |
return mMesh; |
|
| 124 |
} |
|
| 125 |
} |
|
| src/main/java/org/distorted/examples/earth/EarthActivity2.java | ||
|---|---|---|
| 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.earth; |
|
| 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.widget.SeekBar; |
|
| 30 |
import android.widget.TextView; |
|
| 31 |
|
|
| 32 |
import org.distorted.examples.R; |
|
| 33 |
import org.distorted.library.main.Distorted; |
|
| 34 |
import org.distorted.library.main.DistortedTexture; |
|
| 35 |
import org.distorted.library.mesh.MeshBase; |
|
| 36 |
import org.distorted.library.mesh.MeshCubes; |
|
| 37 |
import org.distorted.library.mesh.MeshFlat; |
|
| 38 |
import org.distorted.library.mesh.MeshQuad; |
|
| 39 |
import org.distorted.library.mesh.MeshSphere; |
|
| 40 |
|
|
| 41 |
import java.io.IOException; |
|
| 42 |
import java.io.InputStream; |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 46 |
public class EarthActivity2 extends Activity implements SeekBar.OnSeekBarChangeListener |
|
| 47 |
{
|
|
| 48 |
private DistortedTexture mTexture; |
|
| 49 |
private MeshBase mMesh; |
|
| 50 |
private TextView mTextLevel; |
|
| 51 |
private int mBitmapID; |
|
| 52 |
private Bitmap mBitmap; |
|
| 53 |
private int mNumCols; |
|
| 54 |
private int mNumRows; |
|
| 55 |
private int mNumSlic; |
|
| 56 |
|
|
| 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 58 |
|
|
| 59 |
@Override |
|
| 60 |
protected void onPause() |
|
| 61 |
{
|
|
| 62 |
GLSurfaceView mView = this.findViewById(R.id.earthSurfaceView); |
|
| 63 |
if( mView!=null ) mView.onPause(); |
|
| 64 |
|
|
| 65 |
Distorted.onPause(); |
|
| 66 |
super.onPause(); |
|
| 67 |
} |
|
| 68 |
|
|
| 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 70 |
|
|
| 71 |
@Override |
|
| 72 |
protected void onResume() |
|
| 73 |
{
|
|
| 74 |
super.onResume(); |
|
| 75 |
|
|
| 76 |
GLSurfaceView mView = this.findViewById(R.id.earthSurfaceView); |
|
| 77 |
if( mView!=null ) mView.onResume(); |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
|
|
| 82 |
@Override |
|
| 83 |
protected void onDestroy() |
|
| 84 |
{
|
|
| 85 |
Distorted.onDestroy(); |
|
| 86 |
super.onDestroy(); |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 90 |
|
|
| 91 |
@Override |
|
| 92 |
protected void onCreate(Bundle savedState) |
|
| 93 |
{
|
|
| 94 |
super.onCreate(savedState); |
|
| 95 |
|
|
| 96 |
Bundle b = getIntent().getExtras(); |
|
| 97 |
|
|
| 98 |
String str = b.getString("string");
|
|
| 99 |
int objectType = b.getInt("type");
|
|
| 100 |
mNumCols = b.getInt("cols");
|
|
| 101 |
mNumRows = b.getInt("rows");
|
|
| 102 |
mNumSlic = b.getInt("slices");
|
|
| 103 |
mBitmapID = b.getInt("bitmap");
|
|
| 104 |
|
|
| 105 |
switch(objectType) |
|
| 106 |
{
|
|
| 107 |
case 0: mMesh = new MeshCubes(mNumCols, str, mNumSlic); |
|
| 108 |
break; |
|
| 109 |
case 1: mMesh = new MeshFlat(mNumCols,mNumRows); |
|
| 110 |
break; |
|
| 111 |
case 2: mMesh = new MeshSphere(mNumRows); |
|
| 112 |
break; |
|
| 113 |
case 3: mMesh = new MeshQuad(); |
|
| 114 |
break; |
|
| 115 |
} |
|
| 116 |
|
|
| 117 |
mTexture= new DistortedTexture(mNumCols,mNumRows); |
|
| 118 |
|
|
| 119 |
setContentView(R.layout.earthlayout); |
|
| 120 |
|
|
| 121 |
mTextLevel = findViewById(R.id.earthInflateText); |
|
| 122 |
SeekBar levelBar = findViewById(R.id.earthInflateLevel); |
|
| 123 |
levelBar.setOnSeekBarChangeListener(this); |
|
| 124 |
levelBar.setProgress(50); |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
|
|
| 129 |
public Bitmap getBitmap() |
|
| 130 |
{
|
|
| 131 |
if( mBitmap==null ) |
|
| 132 |
{
|
|
| 133 |
if( mBitmapID!=-1) |
|
| 134 |
{
|
|
| 135 |
InputStream is = getResources().openRawResource(mBitmapID); |
|
| 136 |
|
|
| 137 |
try |
|
| 138 |
{
|
|
| 139 |
mBitmap = BitmapFactory.decodeStream(is); |
|
| 140 |
} |
|
| 141 |
finally |
|
| 142 |
{
|
|
| 143 |
try |
|
| 144 |
{
|
|
| 145 |
is.close(); |
|
| 146 |
} |
|
| 147 |
catch(IOException e) { }
|
|
| 148 |
} |
|
| 149 |
} |
|
| 150 |
else |
|
| 151 |
{
|
|
| 152 |
final int W = 64*mNumCols; |
|
| 153 |
final int H = 64*mNumRows; |
|
| 154 |
|
|
| 155 |
Paint paint = new Paint(); |
|
| 156 |
mBitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888); |
|
| 157 |
Canvas canvas = new Canvas(mBitmap); |
|
| 158 |
|
|
| 159 |
paint.setAntiAlias(true); |
|
| 160 |
paint.setTextAlign(Paint.Align.CENTER); |
|
| 161 |
paint.setColor(0xff008800); |
|
| 162 |
paint.setStyle(Paint.Style.FILL); |
|
| 163 |
canvas.drawRect(0, 0, W, H, paint); |
|
| 164 |
paint.setColor(0xffffffff); |
|
| 165 |
|
|
| 166 |
for(int i=0; i<=mNumCols ; i++ ) canvas.drawRect(W*i/mNumCols-1, 0, W*i/mNumCols + 1, H, paint); |
|
| 167 |
for(int i=0; i<=mNumRows ; i++ ) canvas.drawRect( 0, H*i/mNumRows-1, W, H*i/mNumRows+1, paint); |
|
| 168 |
} |
|
| 169 |
} |
|
| 170 |
|
|
| 171 |
return mBitmap; |
|
| 172 |
} |
|
| 173 |
|
|
| 174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 175 |
|
|
| 176 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
| 177 |
{
|
|
| 178 |
switch (bar.getId()) |
|
| 179 |
{
|
|
| 180 |
case R.id.earthInflateLevel: EarthSurfaceView view = this.findViewById(R.id.earthSurfaceView); |
|
| 181 |
float level = view.getRenderer().setLevel(progress); |
|
| 182 |
mTextLevel.setText(getString(R.string.inflate_placeholder, level)); |
|
| 183 |
break; |
|
| 184 |
} |
|
| 185 |
} |
|
| 186 |
|
|
| 187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 188 |
|
|
| 189 |
public void onStartTrackingTouch(SeekBar bar) { }
|
|
| 190 |
|
|
| 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 192 |
|
|
| 193 |
public void onStopTrackingTouch(SeekBar bar) { }
|
|
| 194 |
|
|
| 195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 196 |
|
|
| 197 |
public DistortedTexture getTexture() |
|
| 198 |
{
|
|
| 199 |
return mTexture; |
|
| 200 |
} |
|
| 201 |
|
|
| 202 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 203 |
|
|
| 204 |
public MeshBase getMesh() |
|
| 205 |
{
|
|
| 206 |
return mMesh; |
|
| 207 |
} |
|
| 208 |
} |
|
| src/main/java/org/distorted/examples/earth/EarthRenderer.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.examples.earth; |
| 21 | 21 |
|
| 22 |
import android.graphics.Bitmap; |
|
| 23 |
import android.graphics.BitmapFactory; |
|
| 22 | 24 |
import android.opengl.GLSurfaceView; |
| 23 | 25 |
|
| 26 |
import org.distorted.examples.R; |
|
| 24 | 27 |
import org.distorted.library.effect.MatrixEffectMove; |
| 25 | 28 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
| 26 | 29 |
import org.distorted.library.effect.MatrixEffectScale; |
| ... | ... | |
| 33 | 36 |
import org.distorted.library.type.Static3D; |
| 34 | 37 |
import org.distorted.library.type.Static4D; |
| 35 | 38 |
|
| 39 |
import java.io.IOException; |
|
| 40 |
import java.io.InputStream; |
|
| 41 |
|
|
| 36 | 42 |
import javax.microedition.khronos.egl.EGLConfig; |
| 37 | 43 |
import javax.microedition.khronos.opengles.GL10; |
| 38 | 44 |
|
| ... | ... | |
| 64 | 70 |
mScale= new Static3D(1,1,1); |
| 65 | 71 |
mCenter=new Static3D(0,0,0); |
| 66 | 72 |
|
| 67 |
EarthActivity2 act = (EarthActivity2)v.getContext();
|
|
| 73 |
EarthActivity act = (EarthActivity)v.getContext();
|
|
| 68 | 74 |
|
| 69 | 75 |
mTexture = act.getTexture(); |
| 70 | 76 |
mMesh = act.getMesh(); |
| ... | ... | |
| 89 | 95 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, mCenter) ); |
| 90 | 96 |
|
| 91 | 97 |
mScreen = new DistortedScreen(); |
| 92 |
mScreen.glClearColor(1.0f,1.0f,1.0f,0.0f); |
|
| 93 | 98 |
mScreen.setProjection(FOV, NEAR); |
| 94 | 99 |
} |
| 95 | 100 |
|
| ... | ... | |
| 116 | 121 |
|
| 117 | 122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 118 | 123 |
|
| 119 |
float setLevel(int level)
|
|
| 124 |
void setLevel(int level)
|
|
| 120 | 125 |
{
|
| 121 | 126 |
float inflateLevel = (level-50)/50.0f; |
| 122 | 127 |
mMesh.setInflate(inflateLevel); |
| 123 |
|
|
| 124 |
return inflateLevel; |
|
| 125 | 128 |
} |
| 126 | 129 |
|
| 127 | 130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 128 | 131 |
|
| 129 | 132 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
| 130 | 133 |
{
|
| 131 |
EarthActivity2 act = (EarthActivity2)mView.getContext(); |
|
| 134 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.world); |
|
| 135 |
Bitmap bitmap; |
|
| 136 |
|
|
| 137 |
try |
|
| 138 |
{
|
|
| 139 |
bitmap = BitmapFactory.decodeStream(is); |
|
| 140 |
} |
|
| 141 |
finally |
|
| 142 |
{
|
|
| 143 |
try |
|
| 144 |
{
|
|
| 145 |
is.close(); |
|
| 146 |
} |
|
| 147 |
catch(IOException e) { }
|
|
| 148 |
} |
|
| 132 | 149 |
|
| 133 |
mTexture.setTexture( act.getBitmap() );
|
|
| 150 |
mTexture.setTexture(bitmap);
|
|
| 134 | 151 |
|
| 135 | 152 |
mScreen.detachAll(); |
| 136 | 153 |
mScreen.attach(mTexture,mEffects,mMesh); |
| src/main/res/layout/earthlayout.xml | ||
|---|---|---|
| 19 | 19 |
android:orientation="horizontal" |
| 20 | 20 |
android:background="@color/blue"> |
| 21 | 21 |
|
| 22 |
<TextView |
|
| 23 |
android:id="@+id/earthInflateText" |
|
| 24 |
android:layout_width="0dp" |
|
| 25 |
android:layout_height="wrap_content" |
|
| 26 |
android:layout_weight="0.3" |
|
| 27 |
android:paddingLeft="10dp" |
|
| 28 |
android:text="@string/inflate" /> |
|
| 29 |
|
|
| 30 | 22 |
<SeekBar |
| 31 | 23 |
android:id="@+id/earthInflateLevel" |
| 32 |
android:layout_weight="0.7" |
|
| 33 |
android:layout_width="0dp" |
|
| 24 |
android:layout_width="fill_parent" |
|
| 34 | 25 |
android:layout_height="50dp" |
| 35 | 26 |
android:paddingLeft="10dp" |
| 36 | 27 |
android:paddingRight="10dp" /> |
Also available in: Unified diff
Progress with the 'Earth' app.