Revision 6173632c
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/movingeffects/MovingEffectsRenderer.java | ||
---|---|---|
28 | 28 |
import android.graphics.Paint.Style; |
29 | 29 |
import android.opengl.GLSurfaceView; |
30 | 30 |
|
31 |
import org.distorted.library.effect.EffectName; |
|
31 | 32 |
import org.distorted.library.main.DistortedScreen; |
32 | 33 |
import org.distorted.library.main.DistortedTexture; |
33 | 34 |
import org.distorted.library.main.DistortedEffects; |
34 |
import org.distorted.library.EffectNames; |
|
35 | 35 |
import org.distorted.library.main.MeshFlat; |
36 | 36 |
import org.distorted.library.main.Distorted; |
37 | 37 |
|
... | ... | |
109 | 109 |
|
110 | 110 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
111 | 111 |
{ |
112 |
DistortedEffects.enableEffect(EffectNames.SWIRL);
|
|
113 |
DistortedEffects.enableEffect(EffectNames.SMOOTH_ALPHA);
|
|
114 |
DistortedEffects.enableEffect(EffectNames.SMOOTH_CHROMA);
|
|
115 |
DistortedEffects.enableEffect(EffectNames.DISTORT);
|
|
116 |
DistortedEffects.enableEffect(EffectNames.SINK);
|
|
112 |
DistortedEffects.enableEffect(EffectName.SWIRL); |
|
113 |
DistortedEffects.enableEffect(EffectName.SMOOTH_ALPHA); |
|
114 |
DistortedEffects.enableEffect(EffectName.SMOOTH_CHROMA); |
|
115 |
DistortedEffects.enableEffect(EffectName.DISTORT); |
|
116 |
DistortedEffects.enableEffect(EffectName.SINK); |
|
117 | 117 |
|
118 | 118 |
try |
119 | 119 |
{ |
src/main/java/org/distorted/examples/movingeffects/MovingEffectsSurfaceView.java | ||
---|---|---|
27 | 27 |
import android.view.MotionEvent; |
28 | 28 |
import android.util.AttributeSet; |
29 | 29 |
|
30 |
import org.distorted.library.effect.EffectType; |
|
31 |
import org.distorted.library.effect.FragmentEffectAlpha; |
|
32 |
import org.distorted.library.effect.FragmentEffectChroma; |
|
33 |
import org.distorted.library.effect.VertexEffectDistort; |
|
34 |
import org.distorted.library.effect.VertexEffectSink; |
|
35 |
import org.distorted.library.effect.VertexEffectSwirl; |
|
30 | 36 |
import org.distorted.library.main.DistortedEffects; |
31 |
import org.distorted.library.EffectTypes; |
|
32 | 37 |
import org.distorted.library.type.Dynamic3D; |
33 | 38 |
import org.distorted.library.type.Dynamic4D; |
34 | 39 |
import org.distorted.library.type.Static1D; |
... | ... | |
42 | 47 |
{ |
43 | 48 |
private static final int LOOP_TIME = 5000; |
44 | 49 |
private static final int NUM_POINTS= 100; |
45 |
|
|
50 |
|
|
46 | 51 |
public static final int EFFECT_POINTS=0; |
47 | 52 |
public static final int EFFECT_BUBBLE=1; |
48 | 53 |
public static final int EFFECT_SINK =2; |
... | ... | |
66 | 71 |
|
67 | 72 |
private MovingEffectsRenderer mRenderer; |
68 | 73 |
|
74 |
private VertexEffectDistort mEffectDistort; |
|
75 |
private VertexEffectSink mEffectSink; |
|
76 |
private VertexEffectSwirl mEffectSwirl; |
|
77 |
private FragmentEffectChroma mEffectChroma; |
|
78 |
private FragmentEffectAlpha mEffectAlpha; |
|
79 |
|
|
69 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
70 | 81 |
|
71 | 82 |
public MovingEffectsSurfaceView(Context context, AttributeSet attrs) |
... | ... | |
88 | 99 |
setFocusableInTouchMode(true); |
89 | 100 |
setRenderer(mRenderer); |
90 | 101 |
} |
102 |
|
|
103 |
mEffectDistort = new VertexEffectDistort(new Static3D(0,0,mMax/10) , di3D, dr); |
|
104 |
mEffectSink = new VertexEffectSink(new Static1D(10), di3D, dr); |
|
105 |
mEffectSwirl = new VertexEffectSwirl( new Static1D(30), di3D, dr); |
|
106 |
mEffectAlpha = new FragmentEffectAlpha(new Static1D(0.5f), mRegion, true); |
|
107 |
mEffectChroma = new FragmentEffectChroma(new Static1D(0.5f), new Static3D(1,0,0), mRegion, true); |
|
91 | 108 |
} |
92 | 109 |
|
93 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
119 | 136 |
synchronized(lock) |
120 | 137 |
{ |
121 | 138 |
DistortedEffects q = mRenderer.getEffects(); |
122 |
q.abortEffects(EffectTypes.VERTEX);
|
|
123 |
q.abortEffects(EffectTypes.FRAGMENT);
|
|
124 |
q.distort( new Static3D(0,0,mMax/10) , di3D, dr);
|
|
139 |
q.abortByType(EffectType.VERTEX);
|
|
140 |
q.abortByType(EffectType.FRAGMENT);
|
|
141 |
q.apply(mEffectDistort);
|
|
125 | 142 |
mCurrEffect = EFFECT_BUBBLE; |
126 | 143 |
} |
127 | 144 |
} |
... | ... | |
135 | 152 |
synchronized(lock) |
136 | 153 |
{ |
137 | 154 |
DistortedEffects q = mRenderer.getEffects(); |
138 |
q.abortEffects(EffectTypes.VERTEX);
|
|
139 |
q.abortEffects(EffectTypes.FRAGMENT);
|
|
140 |
q.sink(new Static1D(10), di3D, dr);
|
|
155 |
q.abortByType(EffectType.VERTEX);
|
|
156 |
q.abortByType(EffectType.FRAGMENT);
|
|
157 |
q.apply(mEffectSink);
|
|
141 | 158 |
mCurrEffect = EFFECT_SINK; |
142 | 159 |
} |
143 | 160 |
} |
... | ... | |
151 | 168 |
synchronized(lock) |
152 | 169 |
{ |
153 | 170 |
DistortedEffects q = mRenderer.getEffects(); |
154 |
q.abortEffects(EffectTypes.VERTEX);
|
|
155 |
q.abortEffects(EffectTypes.FRAGMENT);
|
|
156 |
q.chroma(new Static1D(0.5f), new Static3D(1,0,0), mRegion, true);
|
|
171 |
q.abortByType(EffectType.VERTEX);
|
|
172 |
q.abortByType(EffectType.FRAGMENT);
|
|
173 |
q.apply(mEffectChroma);
|
|
157 | 174 |
mCurrEffect = EFFECT_CHROMA; |
158 | 175 |
} |
159 | 176 |
} |
... | ... | |
167 | 184 |
synchronized(lock) |
168 | 185 |
{ |
169 | 186 |
DistortedEffects q = mRenderer.getEffects(); |
170 |
q.abortEffects(EffectTypes.VERTEX);
|
|
171 |
q.abortEffects(EffectTypes.FRAGMENT);
|
|
172 |
q.alpha(new Static1D(0.5f), mRegion, true);
|
|
187 |
q.abortByType(EffectType.VERTEX);
|
|
188 |
q.abortByType(EffectType.FRAGMENT);
|
|
189 |
q.apply(mEffectAlpha);
|
|
173 | 190 |
mCurrEffect = EFFECT_TRANS; |
174 | 191 |
} |
175 | 192 |
} |
... | ... | |
183 | 200 |
synchronized(lock) |
184 | 201 |
{ |
185 | 202 |
DistortedEffects q = mRenderer.getEffects(); |
186 |
q.abortEffects(EffectTypes.VERTEX);
|
|
187 |
q.abortEffects(EffectTypes.FRAGMENT);
|
|
188 |
q.swirl( new Static1D(30), di3D, dr);
|
|
203 |
q.abortByType(EffectType.VERTEX);
|
|
204 |
q.abortByType(EffectType.FRAGMENT);
|
|
205 |
q.apply(mEffectSwirl);
|
|
189 | 206 |
mCurrEffect = EFFECT_SWIRL; |
190 | 207 |
} |
191 | 208 |
} |
... | ... | |
197 | 214 |
synchronized(lock) |
198 | 215 |
{ |
199 | 216 |
DistortedEffects q = mRenderer.getEffects(); |
200 |
q.abortEffects(EffectTypes.VERTEX);
|
|
201 |
q.abortEffects(EffectTypes.FRAGMENT);
|
|
217 |
q.abortByType(EffectType.VERTEX);
|
|
218 |
q.abortByType(EffectType.FRAGMENT);
|
|
202 | 219 |
di3D.removeAll(); |
203 | 220 |
mRegion.removeAll(); |
204 | 221 |
mCurrEffect = EFFECT_POINTS; |
src/main/java/org/distorted/examples/olimpic/OlimpicRenderer.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
import org.distorted.examples.R; |
29 | 29 |
|
30 |
import org.distorted.library.effect.EffectName; |
|
31 |
import org.distorted.library.effect.FragmentEffectChroma; |
|
32 |
import org.distorted.library.effect.MatrixEffectMove; |
|
33 |
import org.distorted.library.effect.MatrixEffectRotate; |
|
34 |
import org.distorted.library.effect.MatrixEffectScale; |
|
30 | 35 |
import org.distorted.library.main.DistortedEffects; |
31 | 36 |
import org.distorted.library.main.DistortedScreen; |
32 | 37 |
import org.distorted.library.main.DistortedNode; |
33 |
import org.distorted.library.EffectNames; |
|
34 |
import org.distorted.library.EffectTypes; |
|
35 | 38 |
import org.distorted.library.main.MeshFlat; |
36 | 39 |
import org.distorted.library.type.Dynamic1D; |
37 | 40 |
import org.distorted.library.type.Static3D; |
... | ... | |
58 | 61 |
private MeshFlat mMesh; |
59 | 62 |
private int mScreenW, mScreenH; |
60 | 63 |
private int mPrevRendered, mCurrRendered; |
64 |
private Static3D mMove, mScale; |
|
61 | 65 |
|
62 | 66 |
private DistortedNode[] mCircleNode = new DistortedNode[NUM_CIRCLES]; |
63 | 67 |
private DistortedEffects[] mEffects = new DistortedEffects[NUM_LEAVES]; |
... | ... | |
114 | 118 |
for(int j=0; j<NUM_LEAVES; j++) |
115 | 119 |
{ |
116 | 120 |
mEffects[j] = new DistortedEffects(); |
117 |
mEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
|
|
118 |
mEffects[j].move(moveVector);
|
|
121 |
mEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, center) );
|
|
122 |
mEffects[j].apply(new MatrixEffectMove(moveVector));
|
|
119 | 123 |
} |
120 | 124 |
|
121 | 125 |
for(int i=0; i<NUM_CIRCLES; i++) |
122 | 126 |
{ |
123 | 127 |
effects = new DistortedEffects(); |
124 |
effects.move( new Static3D(positions[2*i], positions[2*i+1], 0) );
|
|
125 |
effects.rotate( rot, axis, center );
|
|
126 |
effects.chroma( new Static1D(0.5f), new Static3D(colors[3*i],colors[3*i+1], colors[3*i+2]) );
|
|
128 |
effects.apply( new MatrixEffectMove(new Static3D(positions[2*i], positions[2*i+1], 0)) );
|
|
129 |
effects.apply( new MatrixEffectRotate(rot, axis, center) );
|
|
130 |
effects.apply( new FragmentEffectChroma(new Static1D(0.5f), new Static3D(colors[3*i],colors[3*i+1], colors[3*i+2])) );
|
|
127 | 131 |
|
128 | 132 |
mCircleNode[i] = new DistortedNode( surface, effects, mMesh); |
129 | 133 |
mRoot.attach(mCircleNode[i]); |
... | ... | |
133 | 137 |
|
134 | 138 |
mScreen = new DistortedScreen(mView); |
135 | 139 |
mScreen.attach(mRoot); |
140 |
|
|
141 |
mMove = new Static3D(0,0,0); |
|
142 |
mScale= new Static3D(1,1,1); |
|
143 |
effects.apply(new MatrixEffectMove(mMove)); |
|
144 |
effects.apply(new MatrixEffectScale(mScale)); |
|
136 | 145 |
} |
137 | 146 |
|
138 | 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
139 | 148 |
|
140 |
public void onDrawFrame(GL10 glUnused)
|
|
141 |
{
|
|
142 |
mCurrRendered = mScreen.render(System.currentTimeMillis());
|
|
149 |
public void onDrawFrame(GL10 glUnused)
|
|
150 |
{ |
|
151 |
mCurrRendered = mScreen.render(System.currentTimeMillis()); |
|
143 | 152 |
|
144 |
if( mCurrRendered!=mPrevRendered )
|
|
145 |
{
|
|
146 |
mPrevRendered = mCurrRendered;
|
|
153 |
if( mCurrRendered!=mPrevRendered ) |
|
154 |
{ |
|
155 |
mPrevRendered = mCurrRendered; |
|
147 | 156 |
|
148 |
final OlimpicActivity act = (OlimpicActivity)mView.getContext();
|
|
157 |
final OlimpicActivity act = (OlimpicActivity)mView.getContext(); |
|
149 | 158 |
|
150 |
act.runOnUiThread(new Runnable()
|
|
159 |
act.runOnUiThread(new Runnable() |
|
151 | 160 |
{ |
152 | 161 |
public void run() |
153 | 162 |
{ |
154 |
act.setText("rendered: "+mCurrRendered+" objects");
|
|
155 |
}
|
|
163 |
act.setText("rendered: "+mCurrRendered+" objects"); |
|
164 |
} |
|
156 | 165 |
}); |
157 |
}
|
|
158 |
}
|
|
166 |
} |
|
167 |
} |
|
159 | 168 |
|
160 | 169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
161 | 170 |
|
162 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
163 |
{ |
|
164 |
DistortedEffects effects = mRoot.getEffects(); |
|
165 |
|
|
166 |
effects.abortEffects(EffectTypes.MATRIX); |
|
167 |
|
|
168 |
if( (float)mScreenH/mScreenW > (float)height/width ) |
|
169 |
{ |
|
170 |
int w = (height*mScreenW)/mScreenH; |
|
171 |
float factor = (float)height/mScreenH; |
|
172 |
|
|
173 |
effects.move( new Static3D((width-w)/2 ,0, 0) ); |
|
174 |
effects.scale( factor ); |
|
175 |
} |
|
176 |
else |
|
177 |
{ |
|
178 |
int h = (width*mScreenH)/mScreenW; |
|
179 |
float factor = (float)width/mScreenW; |
|
180 |
|
|
181 |
effects.move( new Static3D(0,(height-h)/2,0) ); |
|
182 |
effects.scale( factor ); |
|
183 |
} |
|
171 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
172 |
{ |
|
173 |
if( (float)mScreenH/mScreenW > (float)height/width ) |
|
174 |
{ |
|
175 |
int w = (height*mScreenW)/mScreenH; |
|
176 |
float factor = (float)height/mScreenH; |
|
177 |
mMove.set((width-w)/2 ,0, 0); |
|
178 |
mScale.set(factor,factor,factor); |
|
179 |
} |
|
180 |
else |
|
181 |
{ |
|
182 |
int h = (width*mScreenH)/mScreenW; |
|
183 |
float factor = (float)width/mScreenW; |
|
184 |
mMove.set(0,(height-h)/2,0); |
|
185 |
mScale.set(factor,factor,factor); |
|
186 |
} |
|
184 | 187 |
|
185 |
mScreen.resize(width, height);
|
|
186 |
}
|
|
188 |
mScreen.resize(width, height); |
|
189 |
} |
|
187 | 190 |
|
188 | 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
189 | 192 |
|
190 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
191 |
{
|
|
192 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
|
|
193 |
Bitmap leaf;
|
|
193 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
194 |
{ |
|
195 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf); |
|
196 |
Bitmap leaf; |
|
194 | 197 |
|
195 |
try
|
|
196 |
{
|
|
197 |
leaf = BitmapFactory.decodeStream(is);
|
|
198 |
}
|
|
199 |
finally
|
|
200 |
{
|
|
201 |
try
|
|
202 |
{
|
|
203 |
is.close();
|
|
204 |
}
|
|
205 |
catch(IOException e) { }
|
|
206 |
}
|
|
198 |
try
|
|
199 |
{ |
|
200 |
leaf = BitmapFactory.decodeStream(is); |
|
201 |
}
|
|
202 |
finally
|
|
203 |
{ |
|
204 |
try
|
|
205 |
{ |
|
206 |
is.close(); |
|
207 |
}
|
|
208 |
catch(IOException e) { } |
|
209 |
}
|
|
207 | 210 |
|
208 |
mLeaf.setTexture(leaf);
|
|
211 |
mLeaf.setTexture(leaf); |
|
209 | 212 |
|
210 |
DistortedEffects.enableEffect(EffectNames.CHROMA);
|
|
213 |
DistortedEffects.enableEffect(EffectName.CHROMA);
|
|
211 | 214 |
|
212 |
try |
|
213 |
{ |
|
214 |
Distorted.onCreate(mView.getContext()); |
|
215 |
} |
|
216 |
catch(Exception ex) |
|
217 |
{ |
|
218 |
android.util.Log.e("Olympic", ex.getMessage() ); |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
223 |
|
|
215 |
try |
|
216 |
{ |
|
217 |
Distorted.onCreate(mView.getContext()); |
|
218 |
} |
|
219 |
catch(Exception ex) |
|
220 |
{ |
|
221 |
android.util.Log.e("Olympic", ex.getMessage() ); |
|
222 |
} |
|
223 |
} |
|
224 | 224 |
} |
Also available in: Unified diff
Further progress with Apps: 21 (out of 30) compile now.