Revision 51554e47
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/examples/olimpic/OlimpicRenderer.java | ||
---|---|---|
56 | 56 |
private DistortedTexture mLeaf; |
57 | 57 |
private DistortedScreen mScreen; |
58 | 58 |
private MeshFlat mMesh; |
59 |
private int mScreenW, mScreenH;
|
|
59 |
private int mRootW, mRootH;
|
|
60 | 60 |
private int mPrevRendered, mCurrRendered; |
61 | 61 |
|
62 | 62 |
private DistortedNode[] mCircleNode = new DistortedNode[NUM_CIRCLES]; |
... | ... | |
95 | 95 |
mMesh = new MeshFlat(1,1); |
96 | 96 |
DistortedEffects effects = new DistortedEffects(); |
97 | 97 |
|
98 |
mScreenW = 9*LEAF_SIZE;
|
|
99 |
mScreenH = 9*LEAF_SIZE;
|
|
100 |
mRoot = new DistortedNode(new DistortedTexture(mScreenW,mScreenH), effects, mMesh);
|
|
98 |
mRootW = 9*LEAF_SIZE;
|
|
99 |
mRootH = 9*LEAF_SIZE;
|
|
100 |
mRoot = new DistortedNode(new DistortedTexture(mRootW,mRootH), effects, mMesh);
|
|
101 | 101 |
|
102 | 102 |
Dynamic1D rot = new Dynamic1D(5000,0.0f); |
103 | 103 |
rot.setMode(Dynamic1D.MODE_JUMP); |
104 | 104 |
rot.add(new Static1D( 0)); |
105 | 105 |
rot.add(new Static1D(360)); |
106 | 106 |
|
107 |
int[] colors = new int[] {0,0,1, 0,0,0, 1,0,0, 1,1,0, 0,1,0}; // blue, black, red, yellow, green |
|
108 |
int[] positions = new int[] {0,2*LEAF_SIZE, 3*LEAF_SIZE,2*LEAF_SIZE, 6*LEAF_SIZE,2*LEAF_SIZE, 3*LEAF_SIZE/2,9*LEAF_SIZE/2, 9*LEAF_SIZE/2,9*LEAF_SIZE/2}; |
|
107 |
int[] colors = new int[] {0,0,1, 0,0,0, 1,0,0, 1,1,0, 0,1,0}; // blue, black, red, yellow, green |
|
108 |
float[] positions = new float[] { -0.333f, -0.12f, 0.0f,-0.12f, +0.333f,-0.12f, |
|
109 |
-0.166f,+0.166f, +0.166f,+0.166f }; |
|
109 | 110 |
|
110 |
Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0);
|
|
111 |
Static3D center = new Static3D(0,0,0);
|
|
111 | 112 |
Static3D axis = new Static3D(0,0,1); |
112 |
Static3D moveVector = new Static3D(0,LEAF_SIZE,0); |
|
113 |
Static3D move = new Static3D(-0.33f,0.0f,0.0f); |
|
114 |
Static3D scale = new Static3D(0.333f,0.333f,0.333f); |
|
113 | 115 |
|
114 | 116 |
for(int j=0; j<NUM_LEAVES; j++) |
115 | 117 |
{ |
116 | 118 |
mEffects[j] = new DistortedEffects(); |
117 |
mEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center ); |
|
118 |
mEffects[j].move(moveVector); |
|
119 |
mEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center); |
|
120 |
mEffects[j].move(move); |
|
121 |
mEffects[j].scale(scale); |
|
119 | 122 |
} |
120 | 123 |
|
121 | 124 |
for(int i=0; i<NUM_CIRCLES; i++) |
... | ... | |
123 | 126 |
effects = new DistortedEffects(); |
124 | 127 |
effects.move( new Static3D(positions[2*i], positions[2*i+1], 0) ); |
125 | 128 |
effects.rotate( rot, axis, center ); |
129 |
effects.scale( scale ); |
|
126 | 130 |
effects.chroma( 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); |
... | ... | |
137 | 141 |
|
138 | 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
139 | 143 |
|
140 |
public void onDrawFrame(GL10 glUnused)
|
|
141 |
{
|
|
142 |
mCurrRendered = mScreen.render(System.currentTimeMillis());
|
|
144 |
public void onDrawFrame(GL10 glUnused)
|
|
145 |
{ |
|
146 |
mCurrRendered = mScreen.render(System.currentTimeMillis()); |
|
143 | 147 |
|
144 |
if( mCurrRendered!=mPrevRendered )
|
|
145 |
{
|
|
146 |
mPrevRendered = mCurrRendered;
|
|
148 |
if( mCurrRendered!=mPrevRendered ) |
|
149 |
{ |
|
150 |
mPrevRendered = mCurrRendered; |
|
147 | 151 |
|
148 |
final OlimpicActivity act = (OlimpicActivity)mView.getContext();
|
|
152 |
final OlimpicActivity act = (OlimpicActivity)mView.getContext(); |
|
149 | 153 |
|
150 |
act.runOnUiThread(new Runnable()
|
|
154 |
act.runOnUiThread(new Runnable() |
|
151 | 155 |
{ |
152 | 156 |
public void run() |
153 | 157 |
{ |
154 |
act.setText("rendered: "+mCurrRendered+" objects");
|
|
155 |
}
|
|
158 |
act.setText("rendered: "+mCurrRendered+" objects"); |
|
159 |
} |
|
156 | 160 |
}); |
157 |
}
|
|
158 |
}
|
|
161 |
} |
|
162 |
} |
|
159 | 163 |
|
160 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
161 | 165 |
|
162 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
163 |
{
|
|
164 |
DistortedEffects effects = mRoot.getEffects();
|
|
166 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
167 |
{ |
|
168 |
DistortedEffects effects = mRoot.getEffects(); |
|
165 | 169 |
|
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; |
|
170 |
float qx = (float)width /mRootW; |
|
171 |
float qy = (float)height/mRootH; |
|
172 | 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; |
|
173 |
effects.abortEffects(EffectTypes.MATRIX); |
|
174 |
effects.scale( qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) ); |
|
180 | 175 |
|
181 |
effects.move( new Static3D(0,(height-h)/2,0) ); |
|
182 |
effects.scale( factor ); |
|
183 |
} |
|
184 |
|
|
185 |
mScreen.resize(width, height); |
|
186 |
} |
|
176 |
mScreen.resize(width, height); |
|
177 |
} |
|
187 | 178 |
|
188 | 179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
189 | 180 |
|
190 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
191 |
{
|
|
192 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
|
|
193 |
Bitmap leaf;
|
|
181 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
182 |
{ |
|
183 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf); |
|
184 |
Bitmap leaf; |
|
194 | 185 |
|
195 |
try
|
|
196 |
{
|
|
197 |
leaf = BitmapFactory.decodeStream(is);
|
|
198 |
}
|
|
199 |
finally
|
|
200 |
{
|
|
201 |
try
|
|
202 |
{
|
|
203 |
is.close();
|
|
204 |
}
|
|
205 |
catch(IOException e) { }
|
|
206 |
}
|
|
186 |
try
|
|
187 |
{ |
|
188 |
leaf = BitmapFactory.decodeStream(is); |
|
189 |
}
|
|
190 |
finally
|
|
191 |
{ |
|
192 |
try
|
|
193 |
{ |
|
194 |
is.close(); |
|
195 |
}
|
|
196 |
catch(IOException e) { } |
|
197 |
}
|
|
207 | 198 |
|
208 |
mLeaf.setTexture(leaf);
|
|
199 |
mLeaf.setTexture(leaf); |
|
209 | 200 |
|
210 |
DistortedEffects.enableEffect(EffectNames.CHROMA);
|
|
201 |
DistortedEffects.enableEffect(EffectNames.CHROMA); |
|
211 | 202 |
|
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 |
|
|
203 |
try |
|
204 |
{ |
|
205 |
Distorted.onCreate(mView.getContext()); |
|
206 |
} |
|
207 |
catch(Exception ex) |
|
208 |
{ |
|
209 |
android.util.Log.e("Olympic", ex.getMessage() ); |
|
210 |
} |
|
211 |
} |
|
224 | 212 |
} |
Also available in: Unified diff
Convert a few more APPs to the new resolution-independent Matrix Effects.