Revision c1f047b9
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/examples/predeform/PredeformActivity.java | ||
|---|---|---|
| 312 | 312 |
} |
| 313 | 313 |
|
| 314 | 314 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 315 |
// TODO
|
|
| 315 |
// only if we want to draw the center, ignore here
|
|
| 316 | 316 |
|
| 317 | 317 |
void setCenter(float x, float y, float z) |
| 318 | 318 |
{
|
| ... | ... | |
| 320 | 320 |
} |
| 321 | 321 |
|
| 322 | 322 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 323 |
// TODO
|
|
| 323 |
// only if we want to draw the region, ignore here
|
|
| 324 | 324 |
|
| 325 | 325 |
void setRegion(Static4D region) |
| 326 | 326 |
{
|
| src/main/java/org/distorted/examples/predeform/PredeformActivity2.java | ||
|---|---|---|
| 27 | 27 |
import android.opengl.GLSurfaceView; |
| 28 | 28 |
import android.os.Bundle; |
| 29 | 29 |
import android.view.View; |
| 30 |
import android.widget.AdapterView; |
|
| 31 |
import android.widget.ArrayAdapter; |
|
| 30 |
import android.widget.CheckBox; |
|
| 32 | 31 |
import android.widget.SeekBar; |
| 33 |
import android.widget.Spinner; |
|
| 34 | 32 |
import android.widget.TextView; |
| 35 | 33 |
|
| 36 | 34 |
import org.distorted.examples.R; |
| ... | ... | |
| 43 | 41 |
|
| 44 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 45 | 43 |
|
| 46 |
public class PredeformActivity2 extends Activity implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener
|
|
| 44 |
public class PredeformActivity2 extends Activity implements SeekBar.OnSeekBarChangeListener |
|
| 47 | 45 |
{
|
| 48 | 46 |
private Bitmap mBitmap; |
| 49 | 47 |
private TextView mTextLevel; |
| ... | ... | |
| 108 | 106 |
mTexture = new DistortedTexture(); |
| 109 | 107 |
|
| 110 | 108 |
setContentView(R.layout.predeformlayout); |
| 111 |
|
|
| 112 |
Spinner renderSpinner = findViewById(R.id.predeformSpinnerMode); |
|
| 113 |
renderSpinner.setOnItemSelectedListener(this); |
|
| 114 |
|
|
| 115 |
String[] objectBitmap = new String[] { "Render: Normal", "Render: OIT" };
|
|
| 116 |
|
|
| 117 |
ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap); |
|
| 118 |
adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 119 |
renderSpinner.setAdapter(adapterBitmap); |
|
| 120 |
|
|
| 109 |
; |
|
| 121 | 110 |
mTextLevel = findViewById(R.id.predeformInflateText); |
| 122 | 111 |
|
| 123 |
SeekBar transparencyBar = findViewById(R.id.predeformTransparency); |
|
| 124 |
transparencyBar.setOnSeekBarChangeListener(this); |
|
| 125 |
transparencyBar.setProgress(50); |
|
| 126 |
|
|
| 127 | 112 |
SeekBar inflateBar = findViewById(R.id.predeformInflateLevel); |
| 128 | 113 |
inflateBar.setOnSeekBarChangeListener(this); |
| 129 | 114 |
inflateBar.setProgress(50); |
| 130 | 115 |
} |
| 131 | 116 |
|
| 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 118 |
|
|
| 119 |
public void showNormal(View view) |
|
| 120 |
{
|
|
| 121 |
CheckBox box = (CheckBox)view; |
|
| 122 |
boolean showNormal = box.isChecked(); |
|
| 123 |
|
|
| 124 |
if ( mMesh!=null ) |
|
| 125 |
{
|
|
| 126 |
mMesh.setShowNormals(showNormal); |
|
| 127 |
} |
|
| 128 |
} |
|
| 129 |
|
|
| 132 | 130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 133 | 131 |
|
| 134 | 132 |
private void createBitmap(int size, int bitmapID) |
| ... | ... | |
| 193 | 191 |
return mBitmap; |
| 194 | 192 |
} |
| 195 | 193 |
|
| 196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 197 |
|
|
| 198 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
| 199 |
{
|
|
| 200 |
PredeformSurfaceView v = findViewById(R.id.predeformSurfaceView); |
|
| 201 |
PredeformRenderer renderer = v.getRenderer(); |
|
| 202 |
|
|
| 203 |
if( parent.getId()==R.id.predeformSpinnerMode) |
|
| 204 |
{
|
|
| 205 |
renderer.setRenderModeToOIT(pos==1); |
|
| 206 |
} |
|
| 207 |
} |
|
| 208 |
|
|
| 209 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 210 |
|
|
| 211 |
public void onNothingSelected(AdapterView<?> parent) |
|
| 212 |
{
|
|
| 213 |
} |
|
| 214 |
|
|
| 215 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 216 | 195 |
|
| 217 | 196 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
| 218 | 197 |
{
|
| 219 |
switch (bar.getId())
|
|
| 198 |
if(bar.getId() == R.id.predeformInflateLevel)
|
|
| 220 | 199 |
{
|
| 221 |
case R.id.predeformTransparency: PredeformSurfaceView v1 = findViewById(R.id.predeformSurfaceView); |
|
| 222 |
v1.getRenderer().setTransparency(progress); |
|
| 223 |
break; |
|
| 224 |
case R.id.predeformInflateLevel: PredeformSurfaceView v2 = findViewById(R.id.predeformSurfaceView); |
|
| 225 |
float level = v2.getRenderer().setLevel(progress); |
|
| 226 |
mTextLevel.setText(getString(R.string.inflate_placeholder, level)); |
|
| 227 |
break; |
|
| 200 |
PredeformSurfaceView v2 = findViewById(R.id.predeformSurfaceView); |
|
| 201 |
float level = v2.getRenderer().setLevel(progress); |
|
| 202 |
mTextLevel.setText(getString(R.string.inflate_placeholder, level)); |
|
| 228 | 203 |
} |
| 229 | 204 |
} |
| 230 | 205 |
|
| src/main/java/org/distorted/examples/predeform/PredeformRenderer.java | ||
|---|---|---|
| 31 | 31 |
import org.distorted.library.main.DistortedTexture; |
| 32 | 32 |
import org.distorted.library.mesh.MeshBase; |
| 33 | 33 |
import org.distorted.library.type.DynamicQuat; |
| 34 |
import org.distorted.library.type.Static1D; |
|
| 35 | 34 |
import org.distorted.library.type.Static3D; |
| 36 | 35 |
import org.distorted.library.type.Static4D; |
| 37 | 36 |
|
| ... | ... | |
| 52 | 51 |
private DistortedScreen mScreen; |
| 53 | 52 |
private float mObjWidth, mObjHeight, mObjDepth; |
| 54 | 53 |
private Static3D mScale; |
| 55 |
private Static1D mAlpha; |
|
| 56 | 54 |
|
| 57 | 55 |
Static4D mQuat1, mQuat2; |
| 58 | 56 |
int mScreenMin; |
| ... | ... | |
| 63 | 61 |
{
|
| 64 | 62 |
mView = v; |
| 65 | 63 |
|
| 66 |
mAlpha = new Static1D(1.0f); |
|
| 67 | 64 |
mScale= new Static3D(1,1,1); |
| 68 | 65 |
|
| 69 | 66 |
Static3D center=new Static3D(0,0,0); |
| ... | ... | |
| 91 | 88 |
mEffects.apply( new MatrixEffectScale(mScale)); |
| 92 | 89 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) ); |
| 93 | 90 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) ); |
| 94 |
mEffects.apply( new FragmentEffectAlpha(mAlpha)); |
|
| 95 | 91 |
|
| 96 | 92 |
mScreen = new DistortedScreen(); |
| 97 | 93 |
mScreen.glClearColor(1.0f,1.0f,1.0f,0.0f); |
| ... | ... | |
| 117 | 113 |
mScreen.resize(width, height); |
| 118 | 114 |
} |
| 119 | 115 |
|
| 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 121 |
|
|
| 122 |
void setRenderModeToOIT(boolean oit) |
|
| 123 |
{
|
|
| 124 |
mScreen.setOrderIndependentTransparency(oit); |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
|
|
| 129 |
void setTransparency(int level) |
|
| 130 |
{
|
|
| 131 |
mAlpha.set((float)level/100.0f); |
|
| 132 |
} |
|
| 133 |
|
|
| 134 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 135 | 117 |
|
| 136 | 118 |
float setLevel(int level) |
| src/main/res/layout/predeformlayout.xml | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
<TextView |
| 23 | 23 |
android:id="@+id/predeformInflateText" |
| 24 |
android:layout_width="0dp"
|
|
| 24 |
android:layout_width="wrap_content"
|
|
| 25 | 25 |
android:layout_height="wrap_content" |
| 26 |
android:layout_weight="0.3"
|
|
| 26 |
android:layout_weight="1"
|
|
| 27 | 27 |
android:paddingLeft="10dp" |
| 28 | 28 |
android:text="@string/inflate" /> |
| 29 | 29 |
|
| 30 | 30 |
<SeekBar |
| 31 | 31 |
android:id="@+id/predeformInflateLevel" |
| 32 |
android:layout_weight="0.7"
|
|
| 33 |
android:layout_width="0dp"
|
|
| 34 |
android:layout_height="50dp"
|
|
| 35 |
android:paddingLeft="10dp"
|
|
| 32 |
android:layout_width="wrap_content"
|
|
| 33 |
android:layout_height="wrap_content"
|
|
| 34 |
android:layout_weight="3"
|
|
| 35 |
android:paddingLeft="5dp"
|
|
| 36 | 36 |
android:paddingRight="5dp" /> |
| 37 | 37 |
|
| 38 |
</LinearLayout> |
|
| 39 |
|
|
| 40 |
<LinearLayout |
|
| 41 |
android:id="@+id/linearLayout3" |
|
| 42 |
android:layout_width="fill_parent" |
|
| 43 |
android:layout_height="wrap_content" |
|
| 44 |
android:gravity="center|fill_horizontal" |
|
| 45 |
android:orientation="horizontal" |
|
| 46 |
android:background="@color/blue"> |
|
| 47 |
|
|
| 48 |
<SeekBar |
|
| 49 |
android:id="@+id/predeformTransparency" |
|
| 50 |
android:layout_weight="0.50" |
|
| 51 |
android:layout_width="0dp" |
|
| 52 |
android:layout_height="50dp" |
|
| 53 |
android:paddingLeft="10dp" |
|
| 54 |
android:paddingRight="10dp" /> |
|
| 38 |
<CheckBox |
|
| 39 |
android:id="@+id/predeformNormal" |
|
| 40 |
android:layout_width="wrap_content" |
|
| 41 |
android:layout_height="wrap_content" |
|
| 42 |
android:layout_weight="1" |
|
| 43 |
android:checked="false" |
|
| 44 |
android:onClick="showNormal" |
|
| 45 |
android:text="@string/show_normal" |
|
| 46 |
android:textSize="12sp"/> |
|
| 55 | 47 |
|
| 56 |
<Spinner |
|
| 57 |
android:layout_width="0dp" |
|
| 58 |
android:layout_height="50dp" |
|
| 59 |
android:layout_weight="0.5" |
|
| 60 |
android:id="@+id/predeformSpinnerMode" |
|
| 61 |
/> |
|
| 62 | 48 |
</LinearLayout> |
| 63 |
|
|
| 64 | 49 |
</LinearLayout> |
Also available in: Unified diff
Progress with the Predeform app.