Revision df77c72c
Added by Leszek Koltunski over 9 years ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 36 | 36 |
<activity android:name=".quaternion.QuaternionActivity" /> |
| 37 | 37 |
<activity android:name=".matrix3d.Matrix3DActivity" /> |
| 38 | 38 |
<activity android:name=".vertex3d.Vertex3DActivity" /> |
| 39 |
<activity android:name=".fragment3d.Fragment3DActivity" /> |
|
| 39 | 40 |
<activity android:name=".plainmonalisa.PlainMonaLisaActivity" /> |
| 40 | 41 |
<activity android:name=".save.SaveActivity"/> |
| 41 | 42 |
</application> |
| src/main/java/org/distorted/examples/TableOfContents.java | ||
|---|---|---|
| 55 | 55 |
import org.distorted.examples.quaternion.QuaternionActivity; |
| 56 | 56 |
import org.distorted.examples.matrix3d.Matrix3DActivity; |
| 57 | 57 |
import org.distorted.examples.vertex3d.Vertex3DActivity; |
| 58 |
import org.distorted.examples.fragment3d.Fragment3DActivity; |
|
| 58 | 59 |
import org.distorted.examples.plainmonalisa.PlainMonaLisaActivity; |
| 59 | 60 |
import org.distorted.examples.save.SaveActivity; |
| 60 | 61 |
|
| ... | ... | |
| 268 | 269 |
activityMapping.put(i++, Vertex3DActivity.class); |
| 269 | 270 |
} |
| 270 | 271 |
|
| 272 |
{
|
|
| 273 |
final Map<String, Object> item = new HashMap<>(); |
|
| 274 |
item.put(ITEM_IMAGE, R.drawable.icon_example_fragment3d); |
|
| 275 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_fragment3d)); |
|
| 276 |
item.put(ITEM_SUBTITLE, getText(R.string.example_fragment3d_subtitle)); |
|
| 277 |
data.add(item); |
|
| 278 |
activityMapping.put(i++, Fragment3DActivity.class); |
|
| 279 |
} |
|
| 280 |
|
|
| 271 | 281 |
{
|
| 272 | 282 |
final Map<String, Object> item = new HashMap<>(); |
| 273 | 283 |
item.put(ITEM_IMAGE, R.drawable.icon_example_monalisa); |
| src/main/java/org/distorted/examples/fragment3d/Fragment3DActivity.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.fragment3d; |
|
| 21 |
|
|
| 22 |
import android.app.Activity; |
|
| 23 |
import android.opengl.GLSurfaceView; |
|
| 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.SeekBar; |
|
| 33 |
import android.widget.SeekBar.OnSeekBarChangeListener; |
|
| 34 |
import android.widget.Spinner; |
|
| 35 |
import android.widget.TableRow; |
|
| 36 |
import android.widget.TextView; |
|
| 37 |
|
|
| 38 |
import org.distorted.examples.R; |
|
| 39 |
import org.distorted.library.Distorted; |
|
| 40 |
import org.distorted.library.DistortedBitmap; |
|
| 41 |
import org.distorted.library.DistortedCubes; |
|
| 42 |
import org.distorted.library.DistortedObject; |
|
| 43 |
import org.distorted.library.EffectNames; |
|
| 44 |
|
|
| 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 46 |
|
|
| 47 |
public class Fragment3DActivity extends Activity |
|
| 48 |
implements OnSeekBarChangeListener, |
|
| 49 |
View.OnClickListener, |
|
| 50 |
AdapterView.OnItemSelectedListener |
|
| 51 |
{
|
|
| 52 |
private static final int COLOR_OFF = 0xffffe81f; |
|
| 53 |
private static final int COLOR_ON = 0xff0000ff; |
|
| 54 |
|
|
| 55 |
private boolean firstScreen; |
|
| 56 |
|
|
| 57 |
// fields needed for the first 'pick-a-shape' screen |
|
| 58 |
// |
|
| 59 |
private int mNumCols = 3; |
|
| 60 |
private int mNumRows = 3; |
|
| 61 |
private NumberPicker mColsPicker, mRowsPicker; |
|
| 62 |
private LinearLayout mLay; |
|
| 63 |
private boolean[] mShape; |
|
| 64 |
private DistortedObject mObject; |
|
| 65 |
private int mObjectType; |
|
| 66 |
private int mBitmap; |
|
| 67 |
|
|
| 68 |
// fields needed for the second 'apply fragment effects' screen |
|
| 69 |
// |
|
| 70 |
private SeekBar bar; |
|
| 71 |
private TextView textChroma, textAlpha, textBrightness, textSaturation, textCenter; |
|
| 72 |
private int chromaL, chromaR, chromaG, chromaB; |
|
| 73 |
private int alphaL; |
|
| 74 |
private int brightnessL; |
|
| 75 |
private int saturationL; |
|
| 76 |
private int centerX, centerY; |
|
| 77 |
|
|
| 78 |
private float fchromaL, fchromaR, fchromaG, fchromaB; |
|
| 79 |
private float falphaL; |
|
| 80 |
private float fbrightnessL; |
|
| 81 |
private float fsaturationL; |
|
| 82 |
private float fcenterX, fcenterY; |
|
| 83 |
private EffectNames[] effects = new EffectNames[4]; |
|
| 84 |
|
|
| 85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 86 |
|
|
| 87 |
@Override |
|
| 88 |
protected void onCreate(Bundle savedState) |
|
| 89 |
{
|
|
| 90 |
super.onCreate(savedState); |
|
| 91 |
|
|
| 92 |
setContentView(R.layout.objectpickerlayout); |
|
| 93 |
|
|
| 94 |
mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols); |
|
| 95 |
mRowsPicker = (NumberPicker)findViewById(R.id.objectpicker_rows); |
|
| 96 |
|
|
| 97 |
mColsPicker.setMaxValue(10); |
|
| 98 |
mColsPicker.setMinValue( 0); |
|
| 99 |
mRowsPicker.setMaxValue(10); |
|
| 100 |
mRowsPicker.setMinValue( 0); |
|
| 101 |
|
|
| 102 |
mColsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() |
|
| 103 |
{
|
|
| 104 |
@Override |
|
| 105 |
public void onValueChange(NumberPicker picker, int oldVal, int newVal) |
|
| 106 |
{
|
|
| 107 |
mNumCols = mColsPicker.getValue(); |
|
| 108 |
} |
|
| 109 |
}); |
|
| 110 |
|
|
| 111 |
mRowsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() |
|
| 112 |
{
|
|
| 113 |
@Override |
|
| 114 |
public void onValueChange(NumberPicker picker, int oldVal, int newVal) |
|
| 115 |
{
|
|
| 116 |
mNumRows = mRowsPicker.getValue(); |
|
| 117 |
} |
|
| 118 |
}); |
|
| 119 |
|
|
| 120 |
firstScreen = true; |
|
| 121 |
|
|
| 122 |
mObjectType = 0; |
|
| 123 |
|
|
| 124 |
Spinner typeSpinner = (Spinner)findViewById(R.id.objectpicker_spinnerType); |
|
| 125 |
typeSpinner.setOnItemSelectedListener(this); |
|
| 126 |
|
|
| 127 |
String[] objectType = new String[] {"DistortedCubes", "DistortedBitmap"};
|
|
| 128 |
|
|
| 129 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType); |
|
| 130 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 131 |
typeSpinner.setAdapter(adapterType); |
|
| 132 |
|
|
| 133 |
Spinner bitmapSpinner = (Spinner)findViewById(R.id.objectpicker_spinnerBitmap); |
|
| 134 |
bitmapSpinner.setOnItemSelectedListener(this); |
|
| 135 |
|
|
| 136 |
String[] objectBitmap = new String[] {"Girl", "Dog", "Cat", "Grid"};
|
|
| 137 |
|
|
| 138 |
ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap); |
|
| 139 |
adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 140 |
bitmapSpinner.setAdapter(adapterBitmap); |
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 144 |
|
|
| 145 |
private void setGrid() |
|
| 146 |
{
|
|
| 147 |
mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid); |
|
| 148 |
|
|
| 149 |
int width = mLay.getWidth(); |
|
| 150 |
int height= mLay.getHeight(); |
|
| 151 |
int w = mNumCols>0 ? (width / mNumCols) -10 : 0; |
|
| 152 |
int h = mNumRows>0 ? (height/ mNumRows) -10 : 0; |
|
| 153 |
int size= w<h ? w:h; |
|
| 154 |
int pad = size/20; |
|
| 155 |
|
|
| 156 |
mLay.removeAllViews(); |
|
| 157 |
|
|
| 158 |
mShape = new boolean[mNumRows*mNumCols]; |
|
| 159 |
|
|
| 160 |
TableRow.LayoutParams p = new android.widget.TableRow.LayoutParams(); |
|
| 161 |
|
|
| 162 |
p.rightMargin = pad; |
|
| 163 |
p.leftMargin = pad; |
|
| 164 |
p.topMargin = pad; |
|
| 165 |
p.bottomMargin = pad; |
|
| 166 |
p.height = size; |
|
| 167 |
p.width = size; |
|
| 168 |
|
|
| 169 |
for (int rows=0; rows<mNumRows; rows++) |
|
| 170 |
{
|
|
| 171 |
TableRow tr = new TableRow(this); |
|
| 172 |
tr.setGravity(Gravity.CENTER); |
|
| 173 |
|
|
| 174 |
for(int cols=0; cols<mNumCols; cols++) |
|
| 175 |
{
|
|
| 176 |
Button b = new Button(this); |
|
| 177 |
b.setOnClickListener(this); |
|
| 178 |
b.setId(rows*mNumCols+cols); |
|
| 179 |
b.setLayoutParams(p); |
|
| 180 |
b.setBackgroundColor(COLOR_ON); |
|
| 181 |
tr.addView(b, p); |
|
| 182 |
mShape[rows*mNumCols+cols] = true; |
|
| 183 |
} |
|
| 184 |
|
|
| 185 |
mLay.addView(tr); |
|
| 186 |
} |
|
| 187 |
} |
|
| 188 |
|
|
| 189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 190 |
|
|
| 191 |
public DistortedObject getObject() |
|
| 192 |
{
|
|
| 193 |
return mObject; |
|
| 194 |
} |
|
| 195 |
|
|
| 196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 197 |
|
|
| 198 |
public void onClick(View view) |
|
| 199 |
{
|
|
| 200 |
Button tmp = (Button)view; |
|
| 201 |
int id = tmp.getId(); |
|
| 202 |
mShape[id] = !mShape[id]; |
|
| 203 |
tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF); |
|
| 204 |
} |
|
| 205 |
|
|
| 206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 207 |
|
|
| 208 |
public int getBitmap() |
|
| 209 |
{
|
|
| 210 |
return mBitmap; |
|
| 211 |
} |
|
| 212 |
|
|
| 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 214 |
|
|
| 215 |
public void Continue(View v) |
|
| 216 |
{
|
|
| 217 |
if( mObjectType==1 ) |
|
| 218 |
{
|
|
| 219 |
firstScreen = false; |
|
| 220 |
mObject = new DistortedBitmap(100,100,mNumCols); |
|
| 221 |
setContentView(R.layout.fragment3dlayout); |
|
| 222 |
Default(null); |
|
| 223 |
} |
|
| 224 |
else |
|
| 225 |
{
|
|
| 226 |
View view = getLayoutInflater().inflate(R.layout.objectpicker2layout, null); |
|
| 227 |
|
|
| 228 |
setContentView(view); |
|
| 229 |
|
|
| 230 |
view.post(new Runnable() {
|
|
| 231 |
@Override |
|
| 232 |
public void run() {
|
|
| 233 |
setGrid(); |
|
| 234 |
} |
|
| 235 |
}); |
|
| 236 |
} |
|
| 237 |
} |
|
| 238 |
|
|
| 239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 240 |
|
|
| 241 |
public void Create(View v) |
|
| 242 |
{
|
|
| 243 |
firstScreen = false; |
|
| 244 |
|
|
| 245 |
String str = ""; |
|
| 246 |
|
|
| 247 |
for(int i=0; i<mNumRows*mNumCols; i++) |
|
| 248 |
str += mShape[i] ? "1" : "0"; |
|
| 249 |
|
|
| 250 |
mObject = new DistortedCubes(mNumCols, str, 10); |
|
| 251 |
|
|
| 252 |
setContentView(R.layout.fragment3dlayout); |
|
| 253 |
Default(null); |
|
| 254 |
} |
|
| 255 |
|
|
| 256 |
|
|
| 257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 258 |
|
|
| 259 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
| 260 |
{
|
|
| 261 |
switch(parent.getId()) |
|
| 262 |
{
|
|
| 263 |
case R.id.objectpicker_spinnerType : mObjectType = pos; break; |
|
| 264 |
case R.id.objectpicker_spinnerBitmap: switch(pos) |
|
| 265 |
{
|
|
| 266 |
case 0: mBitmap = R.raw.face; break; |
|
| 267 |
case 1: mBitmap = R.raw.dog; break; |
|
| 268 |
case 2: mBitmap = R.raw.cat; break; |
|
| 269 |
case 3: mBitmap = R.raw.grid; break; |
|
| 270 |
} |
|
| 271 |
break; |
|
| 272 |
} |
|
| 273 |
} |
|
| 274 |
|
|
| 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 276 |
|
|
| 277 |
public void onNothingSelected(AdapterView<?> parent) |
|
| 278 |
{
|
|
| 279 |
} |
|
| 280 |
|
|
| 281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 282 |
// 'second screen' methods |
|
| 283 |
|
|
| 284 |
public void Default(View view) |
|
| 285 |
{
|
|
| 286 |
effects[0] = EffectNames.CHROMA; |
|
| 287 |
effects[1] = EffectNames.ALPHA; |
|
| 288 |
effects[2] = EffectNames.BRIGHTNESS; |
|
| 289 |
effects[3] = EffectNames.SATURATION; |
|
| 290 |
|
|
| 291 |
chromaL = 0; |
|
| 292 |
chromaR = 0; |
|
| 293 |
chromaG = 0; |
|
| 294 |
chromaB = 0; |
|
| 295 |
|
|
| 296 |
alphaL = 0; |
|
| 297 |
brightnessL= 0; |
|
| 298 |
saturationL= 0; |
|
| 299 |
|
|
| 300 |
centerX = 50; |
|
| 301 |
centerY = 50; |
|
| 302 |
|
|
| 303 |
textCenter = (TextView)findViewById(R.id.fragment3dcenterText); |
|
| 304 |
computeCenter(); |
|
| 305 |
setCenterText(); |
|
| 306 |
|
|
| 307 |
setBar(R.id.fragment3dcenterX, centerX); |
|
| 308 |
setBar(R.id.fragment3dcenterY, centerY); |
|
| 309 |
|
|
| 310 |
addViews(); |
|
| 311 |
} |
|
| 312 |
|
|
| 313 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 314 |
|
|
| 315 |
private void addViews() |
|
| 316 |
{
|
|
| 317 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
|
| 318 |
|
|
| 319 |
layout.removeAllViews(); |
|
| 320 |
|
|
| 321 |
View chroma = getLayoutInflater().inflate(R.layout.fragment3dchroma , null); |
|
| 322 |
View alpha = getLayoutInflater().inflate(R.layout.fragment3dalpha , null); |
|
| 323 |
View brightness= getLayoutInflater().inflate(R.layout.fragment3dbrightness, null); |
|
| 324 |
View saturation= getLayoutInflater().inflate(R.layout.fragment3dsaturation, null); |
|
| 325 |
|
|
| 326 |
for( int i=effects.length-1 ; i>=0 ; i-- ) |
|
| 327 |
{
|
|
| 328 |
switch(effects[i]) |
|
| 329 |
{
|
|
| 330 |
case CHROMA : layout.addView(chroma , 0); break; |
|
| 331 |
case ALPHA : layout.addView(alpha , 0); break; |
|
| 332 |
case BRIGHTNESS : layout.addView(brightness, 0); break; |
|
| 333 |
case SATURATION : layout.addView(saturation, 0); break; |
|
| 334 |
} |
|
| 335 |
} |
|
| 336 |
|
|
| 337 |
textChroma = (TextView)findViewById(R.id.fragment3dchromaText); |
|
| 338 |
textAlpha = (TextView)findViewById(R.id.fragment3dalphaText); |
|
| 339 |
textBrightness= (TextView)findViewById(R.id.fragment3dbrightnessText); |
|
| 340 |
textSaturation= (TextView)findViewById(R.id.fragment3dsaturationText); |
|
| 341 |
|
|
| 342 |
setChromaText(); |
|
| 343 |
setAlphaText(); |
|
| 344 |
setBrightnessText(); |
|
| 345 |
setSaturationText(); |
|
| 346 |
|
|
| 347 |
setBar(R.id.fragment3dchromaBar1, chromaL); |
|
| 348 |
setBar(R.id.fragment3dchromaBar2, chromaR); |
|
| 349 |
setBar(R.id.fragment3dchromaBar3, chromaG); |
|
| 350 |
setBar(R.id.fragment3dchromaBar4, chromaB); |
|
| 351 |
|
|
| 352 |
setBar(R.id.fragment3dalphaBar1 , alphaL); |
|
| 353 |
setBar(R.id.fragment3dbrightnessBar1, brightnessL); |
|
| 354 |
setBar(R.id.fragment3dsaturationBar1, saturationL); |
|
| 355 |
|
|
| 356 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
| 357 |
view.getRenderer().setOrder(effects); |
|
| 358 |
} |
|
| 359 |
|
|
| 360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 361 |
|
|
| 362 |
private void moveUp(EffectNames name) |
|
| 363 |
{
|
|
| 364 |
int len = effects.length-1; |
|
| 365 |
int index = -1; |
|
| 366 |
|
|
| 367 |
for(int i=0; i<=len; i++) |
|
| 368 |
{
|
|
| 369 |
if( effects[i]==name ) |
|
| 370 |
{
|
|
| 371 |
index=i; |
|
| 372 |
break; |
|
| 373 |
} |
|
| 374 |
} |
|
| 375 |
|
|
| 376 |
if( index==0 ) |
|
| 377 |
{
|
|
| 378 |
for(int i=0; i<len; i++) |
|
| 379 |
effects[i] = effects[i+1]; |
|
| 380 |
|
|
| 381 |
effects[len] = name; |
|
| 382 |
} |
|
| 383 |
else if( index>0 ) |
|
| 384 |
{
|
|
| 385 |
effects[index] = effects[index-1]; |
|
| 386 |
effects[index-1] = name; |
|
| 387 |
} |
|
| 388 |
|
|
| 389 |
addViews(); |
|
| 390 |
} |
|
| 391 |
|
|
| 392 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 393 |
|
|
| 394 |
public void ButtonChroma(View v) |
|
| 395 |
{
|
|
| 396 |
moveUp(EffectNames.CHROMA); |
|
| 397 |
} |
|
| 398 |
|
|
| 399 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 400 |
|
|
| 401 |
public void ButtonAlpha(View v) |
|
| 402 |
{
|
|
| 403 |
moveUp(EffectNames.ALPHA); |
|
| 404 |
} |
|
| 405 |
|
|
| 406 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 407 |
|
|
| 408 |
public void ButtonBrightness(View v) |
|
| 409 |
{
|
|
| 410 |
moveUp(EffectNames.BRIGHTNESS); |
|
| 411 |
} |
|
| 412 |
|
|
| 413 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 414 |
|
|
| 415 |
public void ButtonSaturation(View v) |
|
| 416 |
{
|
|
| 417 |
moveUp(EffectNames.SATURATION); |
|
| 418 |
} |
|
| 419 |
|
|
| 420 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 421 |
|
|
| 422 |
private void setBar(int id, int value) |
|
| 423 |
{
|
|
| 424 |
bar = (SeekBar)findViewById(id); |
|
| 425 |
bar.setOnSeekBarChangeListener(this); |
|
| 426 |
bar.setProgress(value); |
|
| 427 |
} |
|
| 428 |
|
|
| 429 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 430 |
|
|
| 431 |
private void computeChroma() |
|
| 432 |
{
|
|
| 433 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
| 434 |
Fragment3DRenderer renderer = view.getRenderer(); |
|
| 435 |
|
|
| 436 |
fchromaL = chromaL/100.0f; |
|
| 437 |
fchromaR = chromaR*255/100.0f; |
|
| 438 |
fchromaG = chromaG*255/100.0f; |
|
| 439 |
fchromaB = chromaB*255/100.0f; |
|
| 440 |
|
|
| 441 |
renderer.setChroma( fchromaL, fchromaR, fchromaG, fchromaB ); |
|
| 442 |
} |
|
| 443 |
|
|
| 444 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 445 |
|
|
| 446 |
private void setChromaText() |
|
| 447 |
{
|
|
| 448 |
fchromaL = ((int)(100*fchromaL))/100.0f; |
|
| 449 |
fchromaR = (float)((int)fchromaR); |
|
| 450 |
fchromaG = (float)((int)fchromaG); |
|
| 451 |
fchromaB = (float)((int)fchromaB); |
|
| 452 |
|
|
| 453 |
textChroma.setText("chroma("+fchromaL+"( "+fchromaR+" , "+fchromaG+" , "+fchromaB+" )");
|
|
| 454 |
} |
|
| 455 |
|
|
| 456 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 457 |
|
|
| 458 |
private void computeAlpha() |
|
| 459 |
{
|
|
| 460 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
| 461 |
|
|
| 462 |
falphaL = alphaL/100.0f; |
|
| 463 |
|
|
| 464 |
view.getRenderer().setAlpha(falphaL); |
|
| 465 |
} |
|
| 466 |
|
|
| 467 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 468 |
|
|
| 469 |
private void setAlphaText() |
|
| 470 |
{
|
|
| 471 |
falphaL = ((int)(100*falphaL))/100.0f; |
|
| 472 |
|
|
| 473 |
textAlpha.setText("alpha("+falphaL+")");
|
|
| 474 |
} |
|
| 475 |
|
|
| 476 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 477 |
|
|
| 478 |
private void computeBrightness() |
|
| 479 |
{
|
|
| 480 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
| 481 |
|
|
| 482 |
fbrightnessL = brightnessL/100.0f; |
|
| 483 |
|
|
| 484 |
view.getRenderer().setBrightness( fbrightnessL ); |
|
| 485 |
} |
|
| 486 |
|
|
| 487 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 488 |
|
|
| 489 |
private void setBrightnessText() |
|
| 490 |
{
|
|
| 491 |
fbrightnessL = ((int)(100*fbrightnessL))/100.0f; |
|
| 492 |
|
|
| 493 |
textBrightness.setText("brightness("+fbrightnessL+")");
|
|
| 494 |
} |
|
| 495 |
|
|
| 496 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 497 |
|
|
| 498 |
private void computeSaturation() |
|
| 499 |
{
|
|
| 500 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
| 501 |
|
|
| 502 |
fsaturationL = saturationL/100.0f; |
|
| 503 |
|
|
| 504 |
view.getRenderer().setSaturation( fsaturationL ); |
|
| 505 |
} |
|
| 506 |
|
|
| 507 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 508 |
|
|
| 509 |
private void setSaturationText() |
|
| 510 |
{
|
|
| 511 |
fsaturationL = ((int)(100*fsaturationL))/100.0f; |
|
| 512 |
|
|
| 513 |
textSaturation.setText("saturation("+fsaturationL+")");
|
|
| 514 |
} |
|
| 515 |
|
|
| 516 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 517 |
|
|
| 518 |
private void computeCenter() |
|
| 519 |
{
|
|
| 520 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
| 521 |
|
|
| 522 |
fcenterX = centerX; |
|
| 523 |
fcenterY = centerY; |
|
| 524 |
|
|
| 525 |
view.getRenderer().setCenter( fcenterX, fcenterY ); |
|
| 526 |
} |
|
| 527 |
|
|
| 528 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 529 |
|
|
| 530 |
private void setCenterText() |
|
| 531 |
{
|
|
| 532 |
fcenterX = ((int)(100*fcenterX))/100.0f; |
|
| 533 |
fcenterY = ((int)(100*fcenterY))/100.0f; |
|
| 534 |
|
|
| 535 |
textCenter.setText("center("+fcenterX+","+fcenterY+")");
|
|
| 536 |
} |
|
| 537 |
|
|
| 538 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 539 |
|
|
| 540 |
public float getCenterX() |
|
| 541 |
{
|
|
| 542 |
return fcenterX; |
|
| 543 |
} |
|
| 544 |
|
|
| 545 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 546 |
|
|
| 547 |
public float getCenterY() |
|
| 548 |
{
|
|
| 549 |
return fcenterY; |
|
| 550 |
} |
|
| 551 |
|
|
| 552 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 553 |
// Overrides |
|
| 554 |
|
|
| 555 |
@Override |
|
| 556 |
protected void onPause() |
|
| 557 |
{
|
|
| 558 |
GLSurfaceView mView = (GLSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
| 559 |
if( mView!=null ) mView.onPause(); |
|
| 560 |
super.onPause(); |
|
| 561 |
} |
|
| 562 |
|
|
| 563 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 564 |
|
|
| 565 |
@Override |
|
| 566 |
protected void onResume() |
|
| 567 |
{
|
|
| 568 |
super.onResume(); |
|
| 569 |
GLSurfaceView mView = (GLSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
| 570 |
if( mView!=null ) mView.onResume(); |
|
| 571 |
} |
|
| 572 |
|
|
| 573 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 574 |
|
|
| 575 |
@Override |
|
| 576 |
public void onWindowFocusChanged(boolean hasFocus) |
|
| 577 |
{
|
|
| 578 |
super.onWindowFocusChanged(hasFocus); |
|
| 579 |
|
|
| 580 |
if( firstScreen ) |
|
| 581 |
{
|
|
| 582 |
mColsPicker.setValue(mNumCols); |
|
| 583 |
mRowsPicker.setValue(mNumRows); |
|
| 584 |
} |
|
| 585 |
} |
|
| 586 |
|
|
| 587 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 588 |
|
|
| 589 |
@Override |
|
| 590 |
protected void onDestroy() |
|
| 591 |
{
|
|
| 592 |
Distorted.onDestroy(); |
|
| 593 |
super.onDestroy(); |
|
| 594 |
} |
|
| 595 |
|
|
| 596 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 597 |
|
|
| 598 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
| 599 |
{
|
|
| 600 |
switch (bar.getId()) |
|
| 601 |
{
|
|
| 602 |
case R.id.fragment3dcenterX : centerX = progress; computeCenter() ; setCenterText() ; break; |
|
| 603 |
case R.id.fragment3dcenterY : centerY = progress; computeCenter() ; setCenterText() ; break; |
|
| 604 |
case R.id.fragment3dchromaBar1 : chromaL = progress; computeChroma() ; setChromaText() ; break; |
|
| 605 |
case R.id.fragment3dchromaBar2 : chromaR = progress; computeChroma() ; setChromaText() ; break; |
|
| 606 |
case R.id.fragment3dchromaBar3 : chromaG = progress; computeChroma() ; setChromaText() ; break; |
|
| 607 |
case R.id.fragment3dchromaBar4 : chromaB = progress; computeChroma() ; setChromaText() ; break; |
|
| 608 |
case R.id.fragment3dalphaBar1 : alphaL = progress; computeAlpha() ; setAlphaText() ; break; |
|
| 609 |
case R.id.fragment3dbrightnessBar1: brightnessL= progress; computeBrightness(); setBrightnessText(); break; |
|
| 610 |
case R.id.fragment3dsaturationBar1: saturationL= progress; computeSaturation(); setSaturationText(); break; |
|
| 611 |
} |
|
| 612 |
} |
|
| 613 |
|
|
| 614 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 615 |
|
|
| 616 |
public void onStartTrackingTouch(SeekBar bar) { }
|
|
| 617 |
|
|
| 618 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 619 |
|
|
| 620 |
public void onStopTrackingTouch(SeekBar bar) { }
|
|
| 621 |
} |
|
| src/main/java/org/distorted/examples/fragment3d/Fragment3DRenderer.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.fragment3d; |
|
| 21 |
|
|
| 22 |
import android.graphics.Bitmap; |
|
| 23 |
import android.graphics.BitmapFactory; |
|
| 24 |
import android.opengl.GLES20; |
|
| 25 |
import android.opengl.GLSurfaceView; |
|
| 26 |
|
|
| 27 |
import org.distorted.examples.R; |
|
| 28 |
import org.distorted.library.Distorted; |
|
| 29 |
import org.distorted.library.DistortedBitmap; |
|
| 30 |
import org.distorted.library.DistortedCubes; |
|
| 31 |
import org.distorted.library.DistortedObject; |
|
| 32 |
import org.distorted.library.EffectNames; |
|
| 33 |
import org.distorted.library.EffectTypes; |
|
| 34 |
import org.distorted.library.type.Dynamic1D; |
|
| 35 |
import org.distorted.library.type.Dynamic2D; |
|
| 36 |
import org.distorted.library.type.Dynamic3D; |
|
| 37 |
import org.distorted.library.type.DynamicQuat; |
|
| 38 |
import org.distorted.library.type.Static1D; |
|
| 39 |
import org.distorted.library.type.Static2D; |
|
| 40 |
import org.distorted.library.type.Static3D; |
|
| 41 |
import org.distorted.library.type.Static4D; |
|
| 42 |
|
|
| 43 |
import java.io.IOException; |
|
| 44 |
import java.io.InputStream; |
|
| 45 |
|
|
| 46 |
import javax.microedition.khronos.egl.EGLConfig; |
|
| 47 |
import javax.microedition.khronos.opengles.GL10; |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
class Fragment3DRenderer implements GLSurfaceView.Renderer |
|
| 52 |
{
|
|
| 53 |
private static final int SIZE = 100; |
|
| 54 |
|
|
| 55 |
private GLSurfaceView mView; |
|
| 56 |
private DistortedObject mObject; |
|
| 57 |
private DistortedBitmap mCenter; |
|
| 58 |
private float mFactorCen, mFactorObj; |
|
| 59 |
|
|
| 60 |
private int mObjWidth, mObjHeight; |
|
| 61 |
|
|
| 62 |
private DynamicQuat mQuatInt1, mQuatInt2; |
|
| 63 |
|
|
| 64 |
private EffectNames[] order; |
|
| 65 |
|
|
| 66 |
private Dynamic2D mCenterInter; |
|
| 67 |
private Dynamic3D mChromaInter, mMoveInter; |
|
| 68 |
private Dynamic1D mChromaLevelInter, mAlphaInter, mBrightnessInter, mSaturationInter; |
|
| 69 |
|
|
| 70 |
private Static2D mCenterPoint; |
|
| 71 |
private Static3D mChromaPoint, mMovePoint; |
|
| 72 |
private Static1D mChromaLevel, mAlphaPoint, mBrightnessPoint, mSaturationPoint; |
|
| 73 |
|
|
| 74 |
Static4D mQuat1, mQuat2; |
|
| 75 |
int mScreenMin; |
|
| 76 |
|
|
| 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 78 |
|
|
| 79 |
public void setChroma(float level, float r, float g, float b) |
|
| 80 |
{
|
|
| 81 |
mChromaLevel.set(level); |
|
| 82 |
mChromaPoint.set(r, g, b); |
|
| 83 |
} |
|
| 84 |
|
|
| 85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 86 |
|
|
| 87 |
public void setAlpha(float level) |
|
| 88 |
{
|
|
| 89 |
mAlphaPoint.set(level); |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 93 |
|
|
| 94 |
public void setBrightness(float level) |
|
| 95 |
{
|
|
| 96 |
mBrightnessPoint.set(level); |
|
| 97 |
} |
|
| 98 |
|
|
| 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 100 |
|
|
| 101 |
public void setSaturation(float level) |
|
| 102 |
{
|
|
| 103 |
mSaturationPoint.set(level); |
|
| 104 |
} |
|
| 105 |
|
|
| 106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 107 |
|
|
| 108 |
public void setCenter(float x, float y) |
|
| 109 |
{
|
|
| 110 |
x = (0.012f*x-0.1f)*mObjWidth; |
|
| 111 |
y = (0.012f*y-0.1f)*mObjHeight; |
|
| 112 |
|
|
| 113 |
mCenterPoint.set(x,y); |
|
| 114 |
mMovePoint.set(mFactorObj*x,mFactorObj*y,0); |
|
| 115 |
} |
|
| 116 |
|
|
| 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 118 |
|
|
| 119 |
public void setOrder(EffectNames[] effects) |
|
| 120 |
{
|
|
| 121 |
order = effects; |
|
| 122 |
setFragmentEffects(); |
|
| 123 |
} |
|
| 124 |
|
|
| 125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 126 |
|
|
| 127 |
private void setFragmentEffects() |
|
| 128 |
{
|
|
| 129 |
mObject.abortEffects(EffectTypes.FRAGMENT); |
|
| 130 |
|
|
| 131 |
for( int i=0; i<=order.length-1 ; i++ ) |
|
| 132 |
{
|
|
| 133 |
switch(order[i]) |
|
| 134 |
{
|
|
| 135 |
case CHROMA : mObject.chroma ( mChromaLevelInter , mChromaInter) ; break; |
|
| 136 |
case ALPHA : mObject.alpha ( mAlphaInter ) ; break; |
|
| 137 |
case BRIGHTNESS: mObject.brightness( mBrightnessInter ) ; break; |
|
| 138 |
case SATURATION: mObject.saturation( mSaturationInter ) ; break; |
|
| 139 |
} |
|
| 140 |
} |
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 144 |
|
|
| 145 |
public Fragment3DRenderer(GLSurfaceView v) |
|
| 146 |
{
|
|
| 147 |
mView = v; |
|
| 148 |
|
|
| 149 |
mObject = ((Fragment3DActivity)v.getContext()).getObject(); |
|
| 150 |
mCenter = new DistortedBitmap(SIZE, SIZE, 1); |
|
| 151 |
|
|
| 152 |
mObjWidth = mObject.getWidth(); |
|
| 153 |
mObjHeight= mObject.getHeight(); |
|
| 154 |
|
|
| 155 |
mCenterPoint = new Static2D(0,0); |
|
| 156 |
mMovePoint = new Static3D(0,0,0); |
|
| 157 |
mChromaPoint = new Static3D(0,0,0); |
|
| 158 |
mChromaLevel = new Static1D(0); |
|
| 159 |
mAlphaPoint = new Static1D(1); |
|
| 160 |
mBrightnessPoint= new Static1D(1); |
|
| 161 |
mSaturationPoint= new Static1D(0.5f); |
|
| 162 |
|
|
| 163 |
mCenterInter = new Dynamic2D(); |
|
| 164 |
mMoveInter = new Dynamic3D(); |
|
| 165 |
mChromaInter = new Dynamic3D(); |
|
| 166 |
mChromaLevelInter= new Dynamic1D(); |
|
| 167 |
mAlphaInter = new Dynamic1D(); |
|
| 168 |
mBrightnessInter = new Dynamic1D(); |
|
| 169 |
mSaturationInter = new Dynamic1D(); |
|
| 170 |
|
|
| 171 |
mCenterInter.add(mCenterPoint); |
|
| 172 |
mMoveInter.add(mMovePoint); |
|
| 173 |
mChromaInter.add(mChromaPoint); |
|
| 174 |
mChromaLevelInter.add(mChromaLevel); |
|
| 175 |
mAlphaInter.add(mAlphaPoint); |
|
| 176 |
mBrightnessInter.add(mBrightnessPoint); |
|
| 177 |
mSaturationInter.add(mSaturationPoint); |
|
| 178 |
|
|
| 179 |
mQuat1 = new Static4D(0,0,0,1); // unity |
|
| 180 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
|
| 181 |
|
|
| 182 |
mQuatInt1 = new DynamicQuat(0,0.5f); |
|
| 183 |
mQuatInt2 = new DynamicQuat(0,0.5f); |
|
| 184 |
|
|
| 185 |
mQuatInt1.add(mQuat1); |
|
| 186 |
mQuatInt2.add(mQuat2); |
|
| 187 |
} |
|
| 188 |
|
|
| 189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 190 |
|
|
| 191 |
public void onDrawFrame(GL10 glUnused) |
|
| 192 |
{
|
|
| 193 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
| 194 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
|
| 195 |
|
|
| 196 |
long time = System.currentTimeMillis(); |
|
| 197 |
|
|
| 198 |
mObject.draw(time); |
|
| 199 |
mCenter.draw(time); |
|
| 200 |
} |
|
| 201 |
|
|
| 202 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 203 |
|
|
| 204 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 205 |
{
|
|
| 206 |
mScreenMin = width<height ? width:height; |
|
| 207 |
|
|
| 208 |
mObject.abortEffects(EffectTypes.MATRIX); |
|
| 209 |
mCenter.abortEffects(EffectTypes.MATRIX); |
|
| 210 |
|
|
| 211 |
int centerSize = mCenter.getWidth(); |
|
| 212 |
|
|
| 213 |
if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object |
|
| 214 |
{
|
|
| 215 |
mFactorObj = (0.70f*height)/mObjHeight; |
|
| 216 |
mFactorCen = (0.15f*height)/centerSize; |
|
| 217 |
} |
|
| 218 |
else |
|
| 219 |
{
|
|
| 220 |
mFactorObj = (0.70f*width)/mObjWidth; |
|
| 221 |
mFactorCen = (0.15f*width)/centerSize; |
|
| 222 |
} |
|
| 223 |
|
|
| 224 |
Fragment3DActivity act = (Fragment3DActivity)mView.getContext(); |
|
| 225 |
float cX = act.getCenterX(); |
|
| 226 |
float cY = act.getCenterY(); |
|
| 227 |
|
|
| 228 |
cX = (0.012f*cX-0.1f)*mObjWidth; |
|
| 229 |
cY = (0.012f*cY-0.1f)*mObjHeight; |
|
| 230 |
|
|
| 231 |
mMovePoint.set(cX*mFactorObj,cY*mFactorObj,0); |
|
| 232 |
|
|
| 233 |
Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0); |
|
| 234 |
|
|
| 235 |
mObject.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) ); |
|
| 236 |
mObject.scale(mFactorObj); |
|
| 237 |
mObject.quaternion(mQuatInt1, rotateObj); |
|
| 238 |
mObject.quaternion(mQuatInt2, rotateObj); |
|
| 239 |
|
|
| 240 |
Static3D rotateCen = new Static3D(width/2,height/2, 0); |
|
| 241 |
|
|
| 242 |
mCenter.quaternion(mQuatInt1, rotateCen); |
|
| 243 |
mCenter.quaternion(mQuatInt2, rotateCen); |
|
| 244 |
mCenter.move( new Static3D( (width -mFactorCen*centerSize-mFactorObj*mObjWidth )/2 , |
|
| 245 |
(height-mFactorCen*centerSize-mFactorObj*mObjHeight)/2 , 10) ); |
|
| 246 |
mCenter.move(mMoveInter); |
|
| 247 |
mCenter.scale(mFactorCen); |
|
| 248 |
|
|
| 249 |
setFragmentEffects(); |
|
| 250 |
|
|
| 251 |
Distorted.onSurfaceChanged(width, height); |
|
| 252 |
} |
|
| 253 |
|
|
| 254 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 255 |
|
|
| 256 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 257 |
{
|
|
| 258 |
Fragment3DActivity act = (Fragment3DActivity)mView.getContext(); |
|
| 259 |
|
|
| 260 |
InputStream is1 = act.getResources().openRawResource(act.getBitmap()); |
|
| 261 |
InputStream is2 = act.getResources().openRawResource(R.raw.center); |
|
| 262 |
|
|
| 263 |
Bitmap bitmap1,bitmap2; |
|
| 264 |
|
|
| 265 |
try |
|
| 266 |
{
|
|
| 267 |
bitmap1 = BitmapFactory.decodeStream(is1); |
|
| 268 |
bitmap2 = BitmapFactory.decodeStream(is2); |
|
| 269 |
} |
|
| 270 |
finally |
|
| 271 |
{
|
|
| 272 |
try |
|
| 273 |
{
|
|
| 274 |
is1.close(); |
|
| 275 |
is2.close(); |
|
| 276 |
} |
|
| 277 |
catch(IOException e) { }
|
|
| 278 |
} |
|
| 279 |
|
|
| 280 |
mObject.setBitmap(bitmap1); |
|
| 281 |
mCenter.setBitmap(bitmap2); |
|
| 282 |
|
|
| 283 |
try |
|
| 284 |
{
|
|
| 285 |
Distorted.onSurfaceCreated(mView.getContext()); |
|
| 286 |
} |
|
| 287 |
catch(Exception ex) |
|
| 288 |
{
|
|
| 289 |
android.util.Log.e("Fragment3D", ex.getMessage() );
|
|
| 290 |
} |
|
| 291 |
} |
|
| 292 |
} |
|
| src/main/java/org/distorted/examples/fragment3d/Fragment3DSurfaceView.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.fragment3d; |
|
| 21 |
|
|
| 22 |
import android.content.Context; |
|
| 23 |
import android.opengl.GLSurfaceView; |
|
| 24 |
import android.os.Build; |
|
| 25 |
import android.util.AttributeSet; |
|
| 26 |
import android.view.MotionEvent; |
|
| 27 |
|
|
| 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 29 |
|
|
| 30 |
class Fragment3DSurfaceView extends GLSurfaceView |
|
| 31 |
{
|
|
| 32 |
private int mX, mY; |
|
| 33 |
private Fragment3DRenderer mRenderer; |
|
| 34 |
|
|
| 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 36 |
|
|
| 37 |
public Fragment3DSurfaceView(Context c, AttributeSet attrs) |
|
| 38 |
{
|
|
| 39 |
super(c, attrs); |
|
| 40 |
|
|
| 41 |
if(!isInEditMode()) |
|
| 42 |
{
|
|
| 43 |
setEGLContextClientVersion(2); |
|
| 44 |
|
|
| 45 |
if( Build.FINGERPRINT.startsWith("generic") )
|
|
| 46 |
{
|
|
| 47 |
setEGLConfigChooser(8, 8, 8, 8, 16, 0); |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
mRenderer = new Fragment3DRenderer(this); |
|
| 51 |
|
|
| 52 |
setRenderer(mRenderer); |
|
| 53 |
} |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 58 |
public Fragment3DRenderer getRenderer() |
|
| 59 |
{
|
|
| 60 |
return mRenderer; |
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 64 |
|
|
| 65 |
@Override |
|
| 66 |
public boolean onTouchEvent(MotionEvent event) |
|
| 67 |
{
|
|
| 68 |
int action = event.getAction(); |
|
| 69 |
int x = (int)event.getX(); |
|
| 70 |
int y = (int)event.getY(); |
|
| 71 |
|
|
| 72 |
switch(action) |
|
| 73 |
{
|
|
| 74 |
case MotionEvent.ACTION_DOWN: mX = x; |
|
| 75 |
mY = y; |
|
| 76 |
break; |
|
| 77 |
|
|
| 78 |
case MotionEvent.ACTION_MOVE: if( mX>=0 && mY>= 0 ) |
|
| 79 |
{
|
|
| 80 |
float px = mY-y; |
|
| 81 |
float py = mX-x; |
|
| 82 |
float pz = 0; |
|
| 83 |
float plen = (float)Math.sqrt(px*px + py*py + pz*pz); |
|
| 84 |
|
|
| 85 |
if( plen>0 ) |
|
| 86 |
{
|
|
| 87 |
px /= plen; |
|
| 88 |
py /= plen; |
|
| 89 |
pz /= plen; |
|
| 90 |
|
|
| 91 |
float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin); |
|
| 92 |
float sinA = (float)Math.sqrt(1-cosA*cosA); |
|
| 93 |
|
|
| 94 |
mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA); |
|
| 95 |
} |
|
| 96 |
} |
|
| 97 |
break; |
|
| 98 |
|
|
| 99 |
case MotionEvent.ACTION_UP : mX = -1; |
|
| 100 |
mY = -1; |
|
| 101 |
|
|
| 102 |
float qx = mRenderer.mQuat1.getX(); |
|
| 103 |
float qy = mRenderer.mQuat1.getY(); |
|
| 104 |
float qz = mRenderer.mQuat1.getZ(); |
|
| 105 |
float qw = mRenderer.mQuat1.getW(); |
|
| 106 |
|
|
| 107 |
float rx = mRenderer.mQuat2.getX(); |
|
| 108 |
float ry = mRenderer.mQuat2.getY(); |
|
| 109 |
float rz = mRenderer.mQuat2.getZ(); |
|
| 110 |
float rw = mRenderer.mQuat2.getW(); |
|
| 111 |
|
|
| 112 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
| 113 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
| 114 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
| 115 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
| 116 |
|
|
| 117 |
mRenderer.mQuat1.set(0f, 0f, 0f, 1f); |
|
| 118 |
mRenderer.mQuat2.set(tx, ty, tz, tw); |
|
| 119 |
|
|
| 120 |
break; |
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
return true; |
|
| 124 |
} |
|
| 125 |
} |
|
| 126 |
|
|
| src/main/res/layout/fragment3dalpha.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
|
|
| 3 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 4 |
android:id="@+id/fragment3dRowAlpha" |
|
| 5 |
android:layout_width="match_parent" |
|
| 6 |
android:layout_height="wrap_content" |
|
| 7 |
android:orientation="horizontal"> |
|
| 8 |
|
|
| 9 |
<LinearLayout |
|
| 10 |
android:layout_width="0dp" |
|
| 11 |
android:layout_height="wrap_content" |
|
| 12 |
android:layout_weight="0.8" |
|
| 13 |
android:orientation="vertical" > |
|
| 14 |
|
|
| 15 |
<TextView |
|
| 16 |
android:id="@+id/fragment3dalphaText" |
|
| 17 |
android:layout_width="wrap_content" |
|
| 18 |
android:layout_height="wrap_content" |
|
| 19 |
android:layout_marginEnd="5dp" |
|
| 20 |
android:layout_marginStart="5dp" |
|
| 21 |
android:layout_marginTop="3dp" |
|
| 22 |
/> |
|
| 23 |
|
|
| 24 |
<SeekBar |
|
| 25 |
android:id="@+id/fragment3dalphaBar1" |
|
| 26 |
android:layout_width="fill_parent" |
|
| 27 |
android:layout_height="wrap_content" |
|
| 28 |
android:layout_marginEnd="5dp" |
|
| 29 |
android:layout_marginLeft="5dp" |
|
| 30 |
android:layout_marginRight="5dp" /> |
|
| 31 |
|
|
| 32 |
</LinearLayout> |
|
| 33 |
|
|
| 34 |
<Button |
|
| 35 |
android:id="@+id/fragment3dUpAlpha" |
|
| 36 |
android:layout_width="60dp" |
|
| 37 |
android:layout_height="fill_parent" |
|
| 38 |
android:onClick="ButtonAlpha" |
|
| 39 |
android:text="@string/Up" /> |
|
| 40 |
|
|
| 41 |
</LinearLayout> |
|
| src/main/res/layout/fragment3dbrightness.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
|
|
| 3 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 4 |
android:id="@+id/fragment3dRowBrightness" |
|
| 5 |
android:orientation="horizontal" |
|
| 6 |
android:layout_width="match_parent" |
|
| 7 |
android:layout_height="wrap_content" > |
|
| 8 |
|
|
| 9 |
<LinearLayout |
|
| 10 |
android:layout_width="0dp" |
|
| 11 |
android:layout_height="match_parent" |
|
| 12 |
android:layout_weight="0.70" |
|
| 13 |
android:orientation="vertical" > |
|
| 14 |
|
|
| 15 |
<TextView |
|
| 16 |
android:id="@+id/fragment3dbrightnessText" |
|
| 17 |
android:layout_width="wrap_content" |
|
| 18 |
android:layout_height="wrap_content" |
|
| 19 |
android:layout_marginEnd="5dp" |
|
| 20 |
android:layout_marginStart="5dp" |
|
| 21 |
android:layout_marginTop="3dp" |
|
| 22 |
/> |
|
| 23 |
|
|
| 24 |
<SeekBar |
|
| 25 |
android:id="@+id/fragment3dbrightnessBar1" |
|
| 26 |
android:layout_width="fill_parent" |
|
| 27 |
android:layout_height="wrap_content" |
|
| 28 |
android:layout_gravity="end" |
|
| 29 |
android:layout_marginEnd="5dp" |
|
| 30 |
android:layout_marginLeft="5dp" |
|
| 31 |
android:layout_marginRight="5dp" /> |
|
| 32 |
|
|
| 33 |
</LinearLayout> |
|
| 34 |
|
|
| 35 |
<Button |
|
| 36 |
android:id="@+id/fragment3dUpBrightness" |
|
| 37 |
android:layout_width="60dp" |
|
| 38 |
android:layout_height="fill_parent" |
|
| 39 |
android:onClick="ButtonBrightness" |
|
| 40 |
android:text="@string/Up" /> |
|
| 41 |
|
|
| 42 |
</LinearLayout> |
|
| 43 |
|
|
| src/main/res/layout/fragment3dchroma.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
android:id="@+id/fragment3dRowChroma" |
|
| 4 |
android:orientation="horizontal" |
|
| 5 |
android:layout_width="match_parent" |
|
| 6 |
android:layout_height="wrap_content" > |
|
| 7 |
|
|
| 8 |
<LinearLayout |
|
| 9 |
android:layout_width="0dp" |
|
| 10 |
android:layout_height="match_parent" |
|
| 11 |
android:layout_weight="0.70" |
|
| 12 |
android:orientation="vertical" > |
|
| 13 |
|
|
| 14 |
<TextView |
|
| 15 |
android:id="@+id/fragment3dchromaText" |
|
| 16 |
android:layout_width="wrap_content" |
|
| 17 |
android:layout_height="wrap_content" |
|
| 18 |
android:layout_marginEnd="5dp" |
|
| 19 |
android:layout_marginStart="5dp" |
|
| 20 |
android:layout_marginTop="3dp" |
|
| 21 |
/> |
|
| 22 |
|
|
| 23 |
<SeekBar |
|
| 24 |
android:id="@+id/fragment3dchromaBar1" |
|
| 25 |
android:layout_width="fill_parent" |
|
| 26 |
android:layout_height="wrap_content" |
|
| 27 |
android:layout_gravity="end" |
|
| 28 |
android:layout_marginEnd="5dp" |
|
| 29 |
android:layout_marginLeft="5dp" |
|
| 30 |
android:layout_marginRight="5dp" /> |
|
| 31 |
|
|
| 32 |
<LinearLayout |
|
| 33 |
android:orientation="horizontal" |
|
| 34 |
android:layout_width="match_parent" |
|
| 35 |
android:layout_height="match_parent"> |
|
| 36 |
|
|
| 37 |
<SeekBar |
|
| 38 |
android:id="@+id/fragment3dchromaBar2" |
|
| 39 |
android:layout_width="fill_parent" |
|
| 40 |
android:layout_height="wrap_content" |
|
| 41 |
android:layout_marginLeft="5dp" |
|
| 42 |
android:layout_marginRight="5dp" |
|
| 43 |
android:layout_weight="0.33"/> |
|
| 44 |
|
|
| 45 |
<SeekBar |
|
| 46 |
android:id="@+id/fragment3dchromaBar3" |
|
| 47 |
android:layout_width="fill_parent" |
|
| 48 |
android:layout_height="wrap_content" |
|
| 49 |
android:layout_marginEnd="5dp" |
|
| 50 |
android:layout_marginLeft="5dp" |
|
| 51 |
android:layout_marginRight="5dp" |
|
| 52 |
android:layout_weight="0.33"/> |
|
| 53 |
|
|
| 54 |
<SeekBar |
|
| 55 |
android:id="@+id/fragment3dchromaBar4" |
|
| 56 |
android:layout_width="fill_parent" |
|
| 57 |
android:layout_height="wrap_content" |
|
| 58 |
android:layout_marginRight="5dp" |
|
| 59 |
android:layout_marginLeft="5dp" |
|
| 60 |
android:layout_weight="0.33"/> |
|
| 61 |
</LinearLayout> |
|
| 62 |
|
|
| 63 |
</LinearLayout> |
|
| 64 |
|
|
| 65 |
<Button |
|
| 66 |
android:id="@+id/fragment3dUpChroma" |
|
| 67 |
android:layout_width="60dp" |
|
| 68 |
android:layout_height="fill_parent" |
|
| 69 |
android:onClick="ButtonChroma" |
|
| 70 |
android:text="@string/Up" /> |
|
| 71 |
|
|
| 72 |
</LinearLayout> |
|
| src/main/res/layout/fragment3dlayout.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
android:layout_width="fill_parent" |
|
| 4 |
android:layout_height="fill_parent" |
|
| 5 |
android:orientation="vertical" > |
|
| 6 |
|
|
| 7 |
<org.distorted.examples.fragment3d.Fragment3DSurfaceView |
|
| 8 |
android:id="@+id/fragment3dSurfaceView" |
|
| 9 |
android:layout_width="fill_parent" |
|
| 10 |
android:layout_height="0dp" |
|
| 11 |
android:layout_weight="1" /> |
|
| 12 |
|
|
| 13 |
<LinearLayout |
|
| 14 |
android:orientation="horizontal" |
|
| 15 |
android:layout_width="match_parent" |
|
| 16 |
android:layout_height="wrap_content" |
|
| 17 |
android:layout_marginBottom="5dp" |
|
| 18 |
android:background="@android:color/holo_green_dark"> |
|
| 19 |
|
|
| 20 |
<LinearLayout |
|
| 21 |
android:orientation="vertical" |
|
| 22 |
android:layout_width="0dp" |
|
| 23 |
android:layout_height="match_parent" |
|
| 24 |
android:layout_weight="0.8"> |
|
| 25 |
|
|
| 26 |
<TextView |
|
| 27 |
android:id="@+id/fragment3dcenterText" |
|
| 28 |
android:layout_width="wrap_content" |
|
| 29 |
android:layout_height="wrap_content" |
|
| 30 |
android:layout_marginEnd="5dp" |
|
| 31 |
android:layout_marginStart="5dp" |
|
| 32 |
android:layout_marginTop="3dp" |
|
| 33 |
/> |
|
| 34 |
|
|
| 35 |
<LinearLayout |
|
| 36 |
android:orientation="horizontal" |
|
| 37 |
android:layout_width="match_parent" |
|
| 38 |
android:layout_height="match_parent" |
|
| 39 |
> |
|
| 40 |
|
|
| 41 |
<SeekBar |
|
| 42 |
android:layout_width="fill_parent" |
|
| 43 |
android:layout_height="wrap_content" |
|
| 44 |
android:id="@+id/fragment3dcenterX" |
|
| 45 |
android:layout_weight="0.5" |
|
| 46 |
android:paddingLeft="5dp" |
|
| 47 |
android:paddingRight="3dp"/> |
|
| 48 |
|
|
| 49 |
<SeekBar |
|
| 50 |
android:layout_width="fill_parent" |
|
| 51 |
android:layout_height="wrap_content" |
|
| 52 |
android:id="@+id/fragment3dcenterY" |
|
| 53 |
android:layout_weight="0.5" |
|
| 54 |
android:paddingLeft="3dp" |
|
| 55 |
android:paddingRight="5dp"/> |
|
| 56 |
</LinearLayout> |
|
| 57 |
|
|
| 58 |
</LinearLayout> |
|
| 59 |
|
|
| 60 |
<Button |
|
| 61 |
android:id="@+id/buttonDefault" |
|
| 62 |
android:layout_width="60dp" |
|
| 63 |
android:layout_height="wrap_content" |
|
| 64 |
android:onClick="Default" |
|
| 65 |
android:text="@string/reset" |
|
| 66 |
android:layout_gravity="right" |
|
| 67 |
android:layout_marginTop="3dp"/> |
|
| 68 |
</LinearLayout> |
|
| 69 |
|
|
| 70 |
<ScrollView |
|
| 71 |
android:id="@+id/fragment3dscrollView" |
|
| 72 |
android:layout_width="match_parent" |
|
| 73 |
android:layout_height="0dp" |
|
| 74 |
android:layout_weight="0.82" > |
|
| 75 |
|
|
| 76 |
<LinearLayout |
|
| 77 |
android:id="@+id/fragment3dlayout" |
|
| 78 |
android:layout_width="match_parent" |
|
| 79 |
android:layout_height="wrap_content" |
|
| 80 |
android:orientation="vertical" > |
|
| 81 |
</LinearLayout> |
|
| 82 |
|
|
| 83 |
</ScrollView> |
|
| 84 |
|
|
| 85 |
</LinearLayout> |
|
| src/main/res/layout/fragment3dsaturation.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
android:id="@+id/fragment3dRowSaturation" |
|
| 4 |
android:orientation="horizontal" |
|
| 5 |
android:layout_width="match_parent" |
|
| 6 |
android:layout_height="wrap_content" > |
|
| 7 |
|
|
| 8 |
<LinearLayout |
|
| 9 |
android:layout_width="0dp" |
|
| 10 |
android:layout_height="match_parent" |
|
| 11 |
android:layout_weight="0.70" |
|
| 12 |
android:orientation="vertical" > |
|
| 13 |
|
|
| 14 |
<TextView |
|
| 15 |
android:id="@+id/fragment3dsaturationText" |
|
| 16 |
android:layout_width="wrap_content" |
|
| 17 |
android:layout_height="wrap_content" |
|
| 18 |
android:layout_marginEnd="5dp" |
|
| 19 |
android:layout_marginStart="5dp" |
|
| 20 |
android:layout_marginTop="3dp" |
|
| 21 |
/> |
|
| 22 |
|
|
| 23 |
<SeekBar |
|
| 24 |
android:id="@+id/fragment3dsaturationBar1" |
|
| 25 |
android:layout_width="fill_parent" |
|
| 26 |
android:layout_height="wrap_content" |
|
| 27 |
android:layout_gravity="end" |
|
| 28 |
android:layout_marginEnd="5dp" |
|
| 29 |
android:layout_marginLeft="5dp" |
|
| 30 |
android:layout_marginRight="5dp" /> |
|
| 31 |
|
|
| 32 |
</LinearLayout> |
|
| 33 |
|
|
| 34 |
<Button |
|
| 35 |
android:id="@+id/fragment3dUpSaturation" |
|
| 36 |
android:layout_width="60dp" |
|
| 37 |
android:layout_height="fill_parent" |
|
| 38 |
android:onClick="ButtonSaturation" |
|
| 39 |
android:text="@string/Up" /> |
|
| 40 |
|
|
| 41 |
</LinearLayout> |
|
| src/main/res/values/strings.xml | ||
|---|---|---|
| 90 | 90 |
<string name="example_matrix3d_subtitle">Test results of Matrix effects on a 3D object.</string> |
| 91 | 91 |
<string name="example_vertex3d">3D Vertex Effects</string> |
| 92 | 92 |
<string name="example_vertex3d_subtitle">Test results of Vertex effects on a 3D object.</string> |
| 93 |
<string name="example_fragment3d">3D Fragment Effects</string> |
|
| 94 |
<string name="example_fragment3d_subtitle">Test results of Fragment effects on a 3D object.</string> |
|
| 93 | 95 |
<string name="example_plainmonalisa">PlainMonaLisa</string> |
| 94 | 96 |
<string name="example_plainmonalisa_subtitle">MonaLisa rendered on a plain SurfaceView</string> |
| 95 | 97 |
<string name="example_save">Save to PNG</string> |
Also available in: Unified diff
New Fragment3D app.