Revision 16b336db
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/examples/meshfile/MeshFileActivity.java | ||
---|---|---|
25 | 25 |
import android.view.View; |
26 | 26 |
import android.widget.AdapterView; |
27 | 27 |
import android.widget.ArrayAdapter; |
28 |
import android.widget.SeekBar; |
|
28 | 29 |
import android.widget.Spinner; |
29 | 30 |
import android.widget.TextView; |
30 | 31 |
|
... | ... | |
33 | 34 |
|
34 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
35 | 36 |
|
36 |
public class MeshFileActivity extends Activity implements AdapterView.OnItemSelectedListener |
|
37 |
public class MeshFileActivity extends Activity implements AdapterView.OnItemSelectedListener, SeekBar.OnSeekBarChangeListener
|
|
37 | 38 |
{ |
38 | 39 |
private int mResource; |
39 | 40 |
private String[] mNames = new String[] { "deferredjob", |
... | ... | |
62 | 63 |
ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, mNames); |
63 | 64 |
adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
64 | 65 |
meshSpinner.setAdapter(adapterBitmap); |
66 |
|
|
67 |
SeekBar barB = findViewById(R.id.meshfileScale); |
|
68 |
barB.setOnSeekBarChangeListener(this); |
|
69 |
barB.setProgress(50); |
|
65 | 70 |
} |
66 | 71 |
|
67 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
145 | 150 |
public void onNothingSelected(AdapterView<?> parent) |
146 | 151 |
{ |
147 | 152 |
} |
153 |
|
|
154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
155 |
|
|
156 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
157 |
{ |
|
158 |
if( bar.getId() == R.id.meshfileScale ) |
|
159 |
{ |
|
160 |
MeshFileSurfaceView view = findViewById(R.id.meshfileSurfaceView); |
|
161 |
view.getRenderer().setScale(progress); |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
166 |
|
|
167 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
168 |
|
|
169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
170 |
|
|
171 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
172 |
|
|
148 | 173 |
} |
src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java | ||
---|---|---|
50 | 50 |
|
51 | 51 |
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener |
52 | 52 |
{ |
53 |
private final float DEFAULT_SCALE = 0.3f; |
|
54 |
|
|
53 | 55 |
private GLSurfaceView mView; |
54 | 56 |
private DistortedTexture mTexture; |
55 | 57 |
private DistortedScreen mScreen; |
... | ... | |
58 | 60 |
private long mTime; |
59 | 61 |
private int mBytes; |
60 | 62 |
private int mVertices; |
63 |
private float mCurrentScale; |
|
61 | 64 |
|
62 | 65 |
Static4D mQuat1, mQuat2; |
63 | 66 |
int mScreenMin; |
... | ... | |
71 | 74 |
mScale= new Static3D(1,1,1); |
72 | 75 |
Static3D center=new Static3D(0,0,0); |
73 | 76 |
|
77 |
mCurrentScale = DEFAULT_SCALE; |
|
78 |
|
|
74 | 79 |
mQuat1 = new Static4D(0,0,0,1); |
75 | 80 |
mQuat2 = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f); |
76 | 81 |
|
... | ... | |
100 | 105 |
|
101 | 106 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
102 | 107 |
{ |
103 |
final float SCALE = 0.3f; |
|
104 | 108 |
mScreenMin = Math.min(width, height); |
105 |
float factor = SCALE*mScreenMin;
|
|
109 |
float factor = mCurrentScale*mScreenMin;
|
|
106 | 110 |
mScale.set(factor,factor,factor); |
107 | 111 |
mScreen.resize(width, height); |
108 | 112 |
} |
... | ... | |
123 | 127 |
android.util.Log.e("MeshFile", ex.getMessage() ); |
124 | 128 |
} |
125 | 129 |
|
130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
131 |
// 0 ---> 0 |
|
132 |
// 50 ---> DEFAULT_SCALE |
|
133 |
// 100 ---> 4*DEFAULT_SCALE |
|
134 |
|
|
135 |
void setScale(int scale) |
|
136 |
{ |
|
137 |
if( scale<= 50 ) |
|
138 |
{ |
|
139 |
mCurrentScale = DEFAULT_SCALE * scale / 50.0f; |
|
140 |
} |
|
141 |
else |
|
142 |
{ |
|
143 |
mCurrentScale = DEFAULT_SCALE * ( 3*(scale/50.0f) - 2.0f); |
|
144 |
} |
|
145 |
|
|
146 |
float factor = mCurrentScale*mScreenMin; |
|
147 |
mScale.set(factor,factor,factor); |
|
148 |
} |
|
149 |
|
|
126 | 150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
127 | 151 |
|
128 | 152 |
void open(int resourceID) |
src/main/res/layout/meshfilelayout.xml | ||
---|---|---|
19 | 19 |
android:layout_width="0dp" |
20 | 20 |
android:layout_height="wrap_content" |
21 | 21 |
android:layout_weight="0.5" |
22 |
android:id="@+id/meshfileSpinner" |
|
23 |
/> |
|
22 |
android:id="@+id/meshfileSpinner"/> |
|
24 | 23 |
|
25 | 24 |
<Button |
26 | 25 |
android:id="@+id/meshfileButton" |
... | ... | |
34 | 33 |
|
35 | 34 |
</LinearLayout> |
36 | 35 |
|
36 |
<SeekBar |
|
37 |
android:id="@+id/meshfileScale" |
|
38 |
android:layout_width="match_parent" |
|
39 |
android:layout_height="wrap_content" |
|
40 |
android:paddingLeft="20dp" |
|
41 |
android:paddingRight="20dp" /> |
|
42 |
|
|
37 | 43 |
<LinearLayout |
38 | 44 |
android:orientation="horizontal" |
39 | 45 |
android:layout_width="match_parent" |
Also available in: Unified diff
Add a 'Scale' seekBar to the MeshFile app.