Revision d79a56d3
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/examples/bean/BeanRenderer.java | ||
|---|---|---|
| 102 | 102 |
|
| 103 | 103 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 104 | 104 |
{
|
| 105 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 106 |
|
|
| 107 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
| 108 |
{
|
|
| 109 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 110 |
float factor = (float)height/bmpHeight; |
|
| 105 |
float qx = (float)width /bmpWidth; |
|
| 106 |
float qy = (float)height/bmpHeight; |
|
| 111 | 107 |
|
| 112 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
| 113 |
mEffects.scale(factor); |
|
| 114 |
} |
|
| 115 |
else |
|
| 116 |
{
|
|
| 117 |
int h = (width*bmpHeight)/bmpWidth; |
|
| 118 |
float factor = (float)width/bmpWidth; |
|
| 119 |
|
|
| 120 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
| 121 |
mEffects.scale(factor); |
|
| 122 |
} |
|
| 108 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 109 |
mEffects.scale( qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) ); |
|
| 123 | 110 |
|
| 124 | 111 |
mScreen.resize(width, height); |
| 125 | 112 |
} |
| src/main/java/org/distorted/examples/catanddog/CatAndDogRenderer.java | ||
|---|---|---|
| 134 | 134 |
|
| 135 | 135 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 136 | 136 |
{
|
| 137 |
int duration = 10000; // 10 seconds |
|
| 138 |
|
|
| 137 |
// 1 cycle = 10000 ms = 10 seconds long |
|
| 138 |
int duration = 10000; |
|
| 139 |
|
|
| 140 |
// First abort all effect we might have had before |
|
| 141 |
// (we will if we got here from a brief stay in the background) |
|
| 142 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 143 |
|
|
| 144 |
// Now start applying the effects. Matrix effects are, like the name suggests, multiplications |
|
| 145 |
// of the Mesh by certain Projective Transformation Matrix. As such, those are - confusingly - |
|
| 146 |
// applied in exactly the opposite order than given, i.e. here the last SCALE would be the |
|
| 147 |
// first effect applied to each vertex of our Mesh, followed by a ROTATION, and only then by |
|
| 148 |
// the MOVE ! |
|
| 149 |
|
|
| 150 |
// MOVES ///////// |
|
| 151 |
// Now, after the SCALE and ROTATE, the center of our Mesh is still exactly at the center of |
|
| 152 |
// the Screen. Thus we move the Mesh back and forth between (0.5,0.5,0) and (-0.5,-0.5,0) , |
|
| 153 |
// i.e. between the lower right and upper left corners of the screen. |
|
| 139 | 154 |
Dynamic3D diMove = new Dynamic3D(duration,0.0f); |
| 140 |
diMove.add(new Static3D(width-bmpWidth,height-bmpHeight,0)); |
|
| 141 |
diMove.add(new Static3D(0,0,0)); |
|
| 142 |
|
|
| 143 |
Dynamic3D diScale = new Dynamic3D(duration,0.0f); |
|
| 144 |
diScale.add(new Static3D(1,1,1)); |
|
| 145 |
diScale.add(new Static3D(0.33f,0.33f,1)); |
|
| 146 |
|
|
| 155 |
Static3D lowerRight = new Static3D( +0.5f, +0.5f, 0); |
|
| 156 |
Static3D upperLeft = new Static3D( -0.5f, -0.5f, 0); |
|
| 157 |
diMove.add(lowerRight); |
|
| 158 |
diMove.add(upperLeft); |
|
| 159 |
mEffects.move(diMove); |
|
| 160 |
|
|
| 161 |
// ROTATION ////// |
|
| 162 |
// Now, after the SCALE, our Texture is positioned at the center of the screen - coords (0,0,0). |
|
| 163 |
// Rotate the whole Mesh around this point, along the (0,0,1) axis (i.e. vector perpendicular to |
|
| 164 |
// the surface of the screen) starting from 0 degrees to 360 and back. |
|
| 147 | 165 |
Dynamic1D diRotate = new Dynamic1D(duration,0.0f); |
| 148 | 166 |
diRotate.add(new Static1D( 0)); |
| 149 | 167 |
diRotate.add(new Static1D(360)); |
| 150 |
|
|
| 151 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 152 |
|
|
| 153 |
mEffects.move(diMove); |
|
| 168 |
Static3D axis = new Static3D(0,0,1); |
|
| 169 |
Static3D center = new Static3D(0,0,0); |
|
| 170 |
mEffects.rotate( diRotate, axis, center ); |
|
| 171 |
|
|
| 172 |
// SCALING /////// |
|
| 173 |
// Before we apply any effects, at the very start, out Mesh skinned by the 'Cat and Dog' texture |
|
| 174 |
// fills up the whole Screen. First we need to scale it down so that the resolution of the |
|
| 175 |
// original 'Cat and Dog' bitmap are preserved, (qx/qy part) and also apply a Dynamic switching |
|
| 176 |
// the size from 80% of the Screen to 20% and back. |
|
| 177 |
Dynamic3D diScale = new Dynamic3D(duration,0.0f); |
|
| 178 |
float qx = (float)width /bmpWidth; |
|
| 179 |
float qy = (float)height/bmpHeight; |
|
| 180 |
float start_scale = 0.8f; |
|
| 181 |
float end_scale = 0.2f; |
|
| 182 |
diScale.add(qx<qy ? (new Static3D( start_scale,start_scale*qx/qy,1)) : (new Static3D(start_scale*qy/qx,start_scale,1))); |
|
| 183 |
diScale.add(qx<qy ? (new Static3D( end_scale ,end_scale *qx/qy,1)) : (new Static3D(end_scale *qy/qx,end_scale ,1))); |
|
| 154 | 184 |
mEffects.scale(diScale); |
| 155 |
mEffects.rotate( diRotate, new Static3D(0,0,1), new Static3D(bmpWidth/2,bmpHeight/2,0) ); |
|
| 156 | 185 |
|
| 186 |
// Finally, tell the Screen itself the underlying OpenGL surface has changed dimensions. |
|
| 157 | 187 |
mScreen.resize(width, height); |
| 158 | 188 |
} |
| 159 | 189 |
} |
| src/main/java/org/distorted/examples/check/CheckRenderer.java | ||
|---|---|---|
| 88 | 88 |
|
| 89 | 89 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 90 | 90 |
{
|
| 91 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 92 |
|
|
| 93 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
| 94 |
{
|
|
| 95 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 96 |
float factor = (float)height/bmpHeight; |
|
| 97 |
|
|
| 98 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
| 99 |
mEffects.scale(factor); |
|
| 100 |
} |
|
| 101 |
else |
|
| 102 |
{
|
|
| 103 |
int h = (width*bmpHeight)/bmpWidth; |
|
| 104 |
float factor = (float)width/bmpWidth; |
|
| 91 |
float qx = (float)width /bmpWidth; |
|
| 92 |
float qy = (float)height/bmpHeight; |
|
| 105 | 93 |
|
| 106 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
| 107 |
mEffects.scale(factor); |
|
| 108 |
} |
|
| 94 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 95 |
mEffects.scale( qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) ); |
|
| 109 | 96 |
|
| 110 | 97 |
mScreen.resize(width, height); |
| 111 | 98 |
} |
| src/main/java/org/distorted/examples/deform/DeformRenderer.java | ||
|---|---|---|
| 100 | 100 |
fpsTexture.setTexture(fpsBitmap); |
| 101 | 101 |
fpsCanvas = new Canvas(fpsBitmap); |
| 102 | 102 |
fpsEffects = new DistortedEffects(); |
| 103 |
fpsEffects.move( new Static3D(5,5,0) ); |
|
| 104 | 103 |
|
| 105 | 104 |
mPaint = new Paint(); |
| 106 | 105 |
mPaint.setAntiAlias(true); |
| ... | ... | |
| 108 | 107 |
mPaint.setTextSize(0.7f*fpsH); |
| 109 | 108 |
|
| 110 | 109 |
stretchEffects = new DistortedEffects(); |
| 110 |
stretchEffects.scale(0.5f); |
|
| 111 | 111 |
|
| 112 | 112 |
mRegion = new Static4D(0,0,0,0); |
| 113 | 113 |
|
| ... | ... | |
| 205 | 205 |
scrHeight = height; |
| 206 | 206 |
scrWidth = width; |
| 207 | 207 |
|
| 208 |
fpsEffects.abortAllEffects(); |
|
| 209 |
fpsEffects.move( new Static3D( -0.5f + (fpsW/2 + 5.0f)/width, -0.5f + (fpsH/2 + 5.0f)/height,0.0f) ); |
|
| 210 |
fpsEffects.scale( new Static3D( (float)fpsW/width, (float)fpsH/height, 1.0f) ); |
|
| 211 |
|
|
| 208 | 212 |
mRegion.set3(mRadius*scrWidth); |
| 209 | 213 |
|
| 210 | 214 |
Canvas stretchCanvas; |
| ... | ... | |
| 231 | 235 |
if( stretchTexture==null ) stretchTexture = new DistortedTexture(w,h); |
| 232 | 236 |
stretchTexture.setTexture(stretchBitmap); |
| 233 | 237 |
|
| 234 |
stretchEffects.abortAllEffects(); |
|
| 235 |
stretchEffects.move( new Static3D(scrWidth/4,scrHeight/4,0) ); |
|
| 236 |
|
|
| 237 | 238 |
mScreen.detachAll(); |
| 238 | 239 |
mScreen.attach(stretchTexture,stretchEffects,stretchMesh); |
| 239 | 240 |
mScreen.attach(fpsTexture,fpsEffects,fpsMesh); |
| ... | ... | |
| 269 | 270 |
if( xt>scrWidth/2 ) xt=scrWidth/2; |
| 270 | 271 |
if( yt<0 ) yt=0; |
| 271 | 272 |
if( yt>scrHeight/2 ) yt=scrHeight/2; |
| 272 |
|
|
| 273 |
touchPoint.set(xt,yt,0); |
|
| 274 | 273 |
|
| 275 | 274 |
switch(mMode) |
| 276 | 275 |
{
|
| 277 | 276 |
case DISTORT: vDistort[0].set(0,0,0); |
| 277 |
touchPoint.set(xt,yt,0); |
|
| 278 | 278 |
mLastEffect = stretchEffects.distort( mMovingDistortDynamic, touchPoint, mRegion); |
| 279 | 279 |
break; |
| 280 | 280 |
case DEFORM : vDeform[0].set(0,0,0); |
| 281 |
touchPoint.set(xt,yt,0); |
|
| 281 | 282 |
mLastEffect = stretchEffects.deform( mMovingDeformDynamic, touchPoint, mRegion); |
| 282 | 283 |
break; |
| 283 | 284 |
case SHEAR : vShear[0].set(0,0,0); |
| 285 |
touchPoint.set( (float)xt/scrWidth, (float)yt/scrHeight,0); |
|
| 284 | 286 |
mLastEffect = stretchEffects.shear(mMovingShearDynamic, touchPoint); |
| 285 | 287 |
break; |
| 286 | 288 |
} |
| src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java | ||
|---|---|---|
| 105 | 105 |
|
| 106 | 106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 107 | 107 |
|
| 108 |
public void onDrawFrame(GL10 glUnused)
|
|
| 108 |
public void onDrawFrame(GL10 glUnused)
|
|
| 109 | 109 |
{
|
| 110 | 110 |
mScreen.render( System.currentTimeMillis() ); |
| 111 | 111 |
} |
| 112 | 112 |
|
| 113 | 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 114 | 114 |
|
| 115 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
| 116 |
{
|
|
| 117 |
for(int i=NUM-1; i>=0; i--)
|
|
| 118 |
{
|
|
| 119 |
mEffects[i].abortEffects(EffectTypes.MATRIX);
|
|
| 120 |
}
|
|
| 115 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
| 116 |
{
|
|
| 117 |
for(int i=NUM-1; i>=0; i--)
|
|
| 118 |
{
|
|
| 119 |
mEffects[i].abortEffects(EffectTypes.MATRIX); |
|
| 120 |
} |
|
| 121 | 121 |
|
| 122 |
if( (float)bmpHeight/(NUM*bmpWidth) > (float)height/width ) |
|
| 123 |
{
|
|
| 124 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 125 |
float factor = (float)height/bmpHeight; |
|
| 126 |
|
|
| 127 |
for(int i=NUM-1; i>=0; i--) |
|
| 128 |
{
|
|
| 129 |
mEffects[i].move( new Static3D((width-NUM*w)/2 +i*w ,0,0) ); |
|
| 130 |
mEffects[i].scale(factor); |
|
| 131 |
} |
|
| 132 |
} |
|
| 133 |
else |
|
| 134 |
{
|
|
| 135 |
int w = width/NUM; |
|
| 136 |
int h = (width*bmpHeight)/(bmpWidth*NUM); |
|
| 137 |
float factor = (float)width/(bmpWidth*NUM); |
|
| 138 |
|
|
| 139 |
for(int i=NUM-1; i>=0; i--) |
|
| 140 |
{
|
|
| 141 |
mEffects[i].move( new Static3D(i*w,(height-h)/2,0) ); |
|
| 142 |
mEffects[i].scale(factor); |
|
| 143 |
} |
|
| 144 |
} |
|
| 122 |
float qx = (float)width /bmpWidth; |
|
| 123 |
float qy = (float)height/bmpHeight; |
|
| 124 |
|
|
| 125 |
if( qx > NUM*qy ) // screen more 'horizontal' than NUM bitmaps next to each other |
|
| 126 |
{
|
|
| 127 |
for(int i=0; i<NUM; i++) |
|
| 128 |
{
|
|
| 129 |
mEffects[i].move( new Static3D( qy*((0.5f+i)/NUM-0.5f), 0, 0) ); |
|
| 130 |
mEffects[i].scale( new Static3D( qy/qx, 1, 1) ); |
|
| 131 |
} |
|
| 132 |
} |
|
| 133 |
else |
|
| 134 |
{
|
|
| 135 |
for(int i=0; i<NUM; i++) |
|
| 136 |
{
|
|
| 137 |
mEffects[i].move( new Static3D( (0.5f+i)/NUM-0.5f, 0, 0) ); |
|
| 138 |
mEffects[i].scale( new Static3D( 1.0f/NUM, (qx/qy)/NUM, 1) ); |
|
| 139 |
} |
|
| 140 |
} |
|
| 145 | 141 |
|
| 146 |
mScreen.resize(width, height);
|
|
| 147 |
}
|
|
| 142 |
mScreen.resize(width, height); |
|
| 143 |
} |
|
| 148 | 144 |
|
| 149 | 145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 150 | 146 |
|
| 151 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
| 152 |
{
|
|
| 153 |
Bitmap bitmap0= readBitmap(R.raw.dog);
|
|
| 154 |
Bitmap bitmap1= readBitmap(R.raw.face);
|
|
| 155 |
Bitmap bitmap2= readBitmap(R.raw.cat);
|
|
| 147 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
| 148 |
{
|
|
| 149 |
Bitmap bitmap0= readBitmap(R.raw.dog); |
|
| 150 |
Bitmap bitmap1= readBitmap(R.raw.face); |
|
| 151 |
Bitmap bitmap2= readBitmap(R.raw.cat); |
|
| 156 | 152 |
|
| 157 |
bmpHeight = bitmap0.getHeight();
|
|
| 158 |
bmpWidth = bitmap0.getWidth();
|
|
| 153 |
bmpHeight = bitmap0.getHeight(); |
|
| 154 |
bmpWidth = bitmap0.getWidth(); |
|
| 159 | 155 |
|
| 160 |
if( mTexture==null )
|
|
| 161 |
{
|
|
| 162 |
mTexture = new DistortedTexture[NUM];
|
|
| 156 |
if( mTexture==null ) |
|
| 157 |
{
|
|
| 158 |
mTexture = new DistortedTexture[NUM]; |
|
| 163 | 159 |
|
| 164 |
for(int i=0; i<NUM; i++)
|
|
| 165 |
mTexture[i] = new DistortedTexture(bmpWidth,bmpHeight);
|
|
| 166 |
}
|
|
| 160 |
for(int i=0; i<NUM; i++) |
|
| 161 |
mTexture[i] = new DistortedTexture(bmpWidth,bmpHeight); |
|
| 162 |
} |
|
| 167 | 163 |
|
| 168 |
mTexture[0].setTexture(bitmap0);
|
|
| 169 |
mTexture[1].setTexture(bitmap1);
|
|
| 170 |
mTexture[2].setTexture(bitmap2);
|
|
| 164 |
mTexture[0].setTexture(bitmap0); |
|
| 165 |
mTexture[1].setTexture(bitmap1); |
|
| 166 |
mTexture[2].setTexture(bitmap2); |
|
| 171 | 167 |
|
| 172 |
MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
|
|
| 168 |
MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth); |
|
| 173 | 169 |
|
| 174 |
mScreen.detachAll();
|
|
| 175 |
for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture[i], mEffects[i], mesh);
|
|
| 170 |
mScreen.detachAll(); |
|
| 171 |
for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture[i], mEffects[i], mesh); |
|
| 176 | 172 |
|
| 177 |
DistortedEffects.enableEffect(EffectNames.SINK);
|
|
| 178 |
DistortedEffects.enableEffect(EffectNames.DISTORT);
|
|
| 173 |
DistortedEffects.enableEffect(EffectNames.SINK); |
|
| 174 |
DistortedEffects.enableEffect(EffectNames.DISTORT); |
|
| 179 | 175 |
|
| 180 |
try
|
|
| 181 |
{
|
|
| 182 |
Distorted.onCreate(mView.getContext());
|
|
| 183 |
}
|
|
| 184 |
catch(Exception ex)
|
|
| 185 |
{
|
|
| 186 |
android.util.Log.e("Renderer", ex.getMessage() );
|
|
| 187 |
}
|
|
| 188 |
}
|
|
| 176 |
try |
|
| 177 |
{
|
|
| 178 |
Distorted.onCreate(mView.getContext()); |
|
| 179 |
} |
|
| 180 |
catch(Exception ex) |
|
| 181 |
{
|
|
| 182 |
android.util.Log.e("Renderer", ex.getMessage() );
|
|
| 183 |
} |
|
| 184 |
} |
|
| 189 | 185 |
} |
| src/main/java/org/distorted/examples/differenteffects/DifferentEffectsRenderer.java | ||
|---|---|---|
| 111 | 111 |
{
|
| 112 | 112 |
mEffects[i].abortEffects(EffectTypes.MATRIX); |
| 113 | 113 |
} |
| 114 |
|
|
| 115 |
if( (float)bmpHeight/(NUM*bmpWidth) > (float)height/width ) |
|
| 116 |
{
|
|
| 117 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 118 |
float factor = (float)height/bmpHeight; |
|
| 119 | 114 |
|
| 120 |
for(int i=NUM-1; i>=0; i--) |
|
| 115 |
float qx = (float)width /bmpWidth; |
|
| 116 |
float qy = (float)height/bmpHeight; |
|
| 117 |
|
|
| 118 |
if( qx > NUM*qy ) // screen more 'horizontal' than NUM bitmaps next to each other |
|
| 119 |
{
|
|
| 120 |
for(int i=0; i<NUM; i++) |
|
| 121 | 121 |
{
|
| 122 |
mEffects[i].move( new Static3D((width-NUM*w)/2 +i*w , 0, 0) );
|
|
| 123 |
mEffects[i].scale(factor);
|
|
| 122 |
mEffects[i].move( new Static3D( qy*((0.5f+i)/NUM-0.5f), 0, 0) );
|
|
| 123 |
mEffects[i].scale( new Static3D( qy/qx, 1, 1) );
|
|
| 124 | 124 |
} |
| 125 | 125 |
} |
| 126 | 126 |
else |
| 127 | 127 |
{
|
| 128 |
int w = width/NUM; |
|
| 129 |
int h = (width*bmpHeight)/(bmpWidth*NUM); |
|
| 130 |
float factor = (float)width/(bmpWidth*NUM); |
|
| 131 |
|
|
| 132 |
for(int i=NUM-1; i>=0; i--) |
|
| 128 |
for(int i=0; i<NUM; i++) |
|
| 133 | 129 |
{
|
| 134 |
mEffects[i].move( new Static3D(i*w, (height-h)/2, 0) );
|
|
| 135 |
mEffects[i].scale(factor);
|
|
| 130 |
mEffects[i].move( new Static3D( (0.5f+i)/NUM-0.5f, 0, 0) );
|
|
| 131 |
mEffects[i].scale( new Static3D( 1.0f/NUM, (qx/qy)/NUM, 1) );
|
|
| 136 | 132 |
} |
| 137 | 133 |
} |
| 138 | 134 |
|
| src/main/java/org/distorted/examples/effectqueue/EffectQueueRenderer.java | ||
|---|---|---|
| 34 | 34 |
import org.distorted.library.DistortedTexture; |
| 35 | 35 |
import org.distorted.library.Distorted; |
| 36 | 36 |
import org.distorted.library.EffectNames; |
| 37 |
import org.distorted.library.EffectTypes; |
|
| 38 | 37 |
import org.distorted.library.message.EffectListener; |
| 39 | 38 |
import org.distorted.library.message.EffectMessage; |
| 40 |
import org.distorted.library.type.Static3D; |
|
| 41 | 39 |
|
| 42 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 43 | 41 |
|
| ... | ... | |
| 127 | 125 |
|
| 128 | 126 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 129 | 127 |
{
|
| 130 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 131 |
mEffects.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) ); |
|
| 132 | 128 |
mScreen.resize(width,height); |
| 133 | 129 |
mView.setScreenSize(width,height); |
| 134 | 130 |
} |
| src/main/java/org/distorted/examples/fbo/FBORenderer.java | ||
|---|---|---|
| 103 | 103 |
|
| 104 | 104 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 105 | 105 |
{
|
| 106 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 107 |
|
|
| 108 |
if( (float)lisaHeight/lisaWidth > (float)height/width ) |
|
| 109 |
{
|
|
| 110 |
int w = (height*lisaWidth)/lisaHeight; |
|
| 111 |
float factor = (float)height/lisaHeight; |
|
| 112 |
|
|
| 113 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
| 114 |
mEffects.scale(factor); |
|
| 115 |
} |
|
| 116 |
else |
|
| 117 |
{
|
|
| 118 |
int h = (width*lisaHeight)/lisaWidth; |
|
| 119 |
float factor = (float)width/lisaWidth; |
|
| 106 |
float qx = (float)width /lisaWidth; |
|
| 107 |
float qy = (float)height/lisaHeight; |
|
| 120 | 108 |
|
| 121 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
| 122 |
mEffects.scale(factor); |
|
| 123 |
} |
|
| 109 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 110 |
mEffects.scale( qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) ); |
|
| 124 | 111 |
|
| 125 | 112 |
mScreen.resize(width, height); |
| 126 | 113 |
} |
| ... | ... | |
| 164 | 151 |
mGridTexture.setTexture(bitmap2); |
| 165 | 152 |
DistortedEffects gridEffects = new DistortedEffects(); |
| 166 | 153 |
|
| 167 |
mEffects.abortAllEffects(); |
|
| 168 |
|
|
| 169 | 154 |
mRoot = new DistortedNode(mLisaTexture, mEffects,new MeshFlat(1,1)); |
| 170 | 155 |
mRoot.attach(mGridTexture,gridEffects,new MeshCubes(10,10,false)); |
| 171 | 156 |
|
| ... | ... | |
| 174 | 159 |
mScreen.detachAll(); |
| 175 | 160 |
mScreen.attach(mRoot); |
| 176 | 161 |
|
| 177 |
float factor = lisaWidth/(2.0f*gridWidth); |
|
| 178 |
|
|
| 179 |
gridEffects.move( new Static3D( (lisaWidth-factor*gridWidth)/2,(lisaHeight-factor*gridHeight)/2,0) ); |
|
| 180 |
gridEffects.scale(factor); |
|
| 162 |
gridEffects.scale(0.5f); |
|
| 181 | 163 |
|
| 182 | 164 |
Dynamic1D rotDyn = new Dynamic1D(12000,0.0f); |
| 183 | 165 |
rotDyn.add(new Static1D( 0)); |
| 184 | 166 |
rotDyn.add(new Static1D(360)); |
| 185 | 167 |
rotDyn.setMode(Dynamic.MODE_JUMP); |
| 186 | 168 |
|
| 187 |
gridEffects.rotate(rotDyn, new Static3D(1,0,0), new Static3D(gridWidth/2,gridHeight/2,gridHeight/10) );
|
|
| 169 |
gridEffects.rotate(rotDyn, new Static3D(1,0,0), new Static3D(0,0,1.0f/10) );
|
|
| 188 | 170 |
|
| 189 | 171 |
Dynamic1D sinkDyn = new Dynamic1D(3000,0.0f); |
| 190 | 172 |
sinkDyn.add(new Static1D(1.0f)); |
| src/main/java/org/distorted/examples/girl/GirlRenderer.java | ||
|---|---|---|
| 159 | 159 |
|
| 160 | 160 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 161 | 161 |
{
|
| 162 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 163 |
|
|
| 164 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
| 165 |
{
|
|
| 166 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 167 |
float factor = (float)height/bmpHeight; |
|
| 168 |
|
|
| 169 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
| 170 |
mEffects.scale(factor); |
|
| 171 |
} |
|
| 172 |
else |
|
| 173 |
{
|
|
| 174 |
int h = (width*bmpHeight)/bmpWidth; |
|
| 175 |
float factor = (float)width/bmpWidth; |
|
| 162 |
float qx = (float)width /bmpWidth; |
|
| 163 |
float qy = (float)height/bmpHeight; |
|
| 176 | 164 |
|
| 177 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
| 178 |
mEffects.scale(factor); |
|
| 179 |
} |
|
| 165 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 166 |
mEffects.scale( qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) ); |
|
| 180 | 167 |
|
| 181 | 168 |
mScreen.resize(width, height); |
| 182 | 169 |
} |
| src/main/java/org/distorted/examples/listener/ListenerRenderer.java | ||
|---|---|---|
| 110 | 110 |
|
| 111 | 111 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 112 | 112 |
{
|
| 113 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 114 |
|
|
| 115 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
| 116 |
{
|
|
| 117 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 118 |
float factor = (float)height/bmpHeight; |
|
| 113 |
float qx = (float)width /bmpWidth; |
|
| 114 |
float qy = (float)height/bmpHeight; |
|
| 119 | 115 |
|
| 120 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
| 121 |
mEffects.scale(factor); |
|
| 122 |
} |
|
| 123 |
else |
|
| 124 |
{
|
|
| 125 |
int h = (width*bmpHeight)/bmpWidth; |
|
| 126 |
float factor = (float)width/bmpWidth; |
|
| 127 |
|
|
| 128 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
| 129 |
mEffects.scale(factor); |
|
| 130 |
} |
|
| 116 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 117 |
mEffects.scale( qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) ); |
|
| 131 | 118 |
|
| 132 | 119 |
mScreen.resize(width, height); |
| 133 | 120 |
} |
| src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java | ||
|---|---|---|
| 86 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 87 | 87 |
|
| 88 | 88 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 89 |
{
|
|
| 90 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 89 |
{
|
|
| 90 |
float qx = (float)width /bmpWidth; |
|
| 91 |
float qy = (float)height/bmpHeight; |
|
| 91 | 92 |
|
| 92 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
| 93 |
{
|
|
| 94 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 95 |
float factor = (float)height/bmpHeight; |
|
| 96 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
| 97 |
mEffects.scale(factor); |
|
| 98 |
} |
|
| 99 |
else |
|
| 100 |
{
|
|
| 101 |
int h = (width*bmpHeight)/bmpWidth; |
|
| 102 |
float factor = (float)width/bmpWidth; |
|
| 103 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
| 104 |
mEffects.scale(factor); |
|
| 105 |
} |
|
| 93 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 94 |
mEffects.scale( qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) ); |
|
| 106 | 95 |
|
| 107 | 96 |
mScreen.resize(width, height); |
| 108 | 97 |
} |
| src/main/java/org/distorted/examples/sink/SinkRenderer.java | ||
|---|---|---|
| 78 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 79 | 79 |
|
| 80 | 80 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 81 |
{
|
|
| 82 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 83 |
|
|
| 84 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
| 85 |
{
|
|
| 86 |
int w = (height*bmpWidth)/bmpHeight; |
|
| 87 |
float factor = (float)height/bmpHeight; |
|
| 81 |
{
|
|
| 82 |
float qx = (float)width /bmpWidth; |
|
| 83 |
float qy = (float)height/bmpHeight; |
|
| 88 | 84 |
|
| 89 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
| 90 |
mEffects.scale( factor ); |
|
| 91 |
} |
|
| 92 |
else |
|
| 93 |
{
|
|
| 94 |
int h = (width*bmpHeight)/bmpWidth; |
|
| 95 |
float factor = (float)width/bmpWidth; |
|
| 85 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
| 86 |
mEffects.scale( qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) ); |
|
| 96 | 87 |
|
| 97 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
| 98 |
mEffects.scale( factor ); |
|
| 99 |
} |
|
| 100 |
|
|
| 101 | 88 |
mScreen.resize(width, height); |
| 102 | 89 |
} |
| 103 | 90 |
|
| src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java | ||
|---|---|---|
| 207 | 207 |
if( mCrawlBackgroundTexture!=null ) mCrawlBackgroundTexture.markForDeletion(); |
| 208 | 208 |
mCrawlBackgroundTexture = new DistortedTexture(w,(int)(h*Math.sin(angleA)/Math.sin(angleB))); |
| 209 | 209 |
|
| 210 |
int randomA, randomX, randomY, randomTime; |
|
| 211 |
float randomS, randomAlpha1, randomAlpha2; |
|
| 212 |
|
|
| 213 |
Static3D center = new Static3D(0,0,0); |
|
| 214 |
Static3D axis = new Static3D(0,0,1); |
|
| 210 |
int randomTime; |
|
| 211 |
float randomX, randomY, randomS, randomAlpha1, randomAlpha2; |
|
| 212 |
|
|
| 213 |
float starScaleX = (float)mStarTexture.getWidth()/w; |
|
| 214 |
float starScaleY = (float)mStarTexture.getHeight()/h; |
|
| 215 |
|
|
| 215 | 216 |
Static1D alphaNoise = new Static1D(0.4f); |
| 216 | 217 |
|
| 217 | 218 |
for(int i=0; i<NUM_STARS; i++) |
| 218 | 219 |
{
|
| 219 |
randomX = mRnd.nextInt(w);
|
|
| 220 |
randomY = mRnd.nextInt(h);
|
|
| 220 |
randomX = mRnd.nextFloat() -0.5f;
|
|
| 221 |
randomY = mRnd.nextFloat() -0.5f;
|
|
| 221 | 222 |
randomS = 0.2f+ 0.8f*mRnd.nextFloat(); |
| 222 |
randomA = (int)(180*mRnd.nextFloat()); |
|
| 223 | 223 |
randomAlpha1 = 0.2f + 0.8f*mRnd.nextFloat(); |
| 224 | 224 |
randomAlpha2 = 0.8f + 0.2f*mRnd.nextFloat(); |
| 225 | 225 |
randomTime = 500+mRnd.nextInt(2000); |
| 226 | 226 |
|
| 227 | 227 |
mStarEffects[i].move( new Static3D(randomX,randomY,0) ); |
| 228 |
mStarEffects[i].scale(randomS); |
|
| 229 |
mStarEffects[i].rotate( new Static1D(randomA), axis, center ); |
|
| 230 |
|
|
| 228 |
mStarEffects[i].scale( new Static3D(randomS*starScaleX, randomS*starScaleY, 1) ); |
|
| 229 |
|
|
| 231 | 230 |
Dynamic1D di = new Dynamic1D(randomTime,0.0f); |
| 232 | 231 |
di.setNoise(alphaNoise); |
| 233 | 232 |
di.add(new Static1D(randomAlpha1)); |
| ... | ... | |
| 237 | 236 |
|
| 238 | 237 |
mScreen.attach(mStarTexture, mStarEffects[i], mQuad); |
| 239 | 238 |
} |
| 240 |
|
|
| 241 |
float scale = (0.5f*w/mGFFATexture.getWidth()); |
|
| 242 |
|
|
| 239 |
|
|
| 240 |
float qx = (float)mGFFATexture.getWidth()/w; |
|
| 241 |
float qy = (float)mGFFATexture.getHeight()/h; |
|
| 242 |
|
|
| 243 | 243 |
Dynamic1D di = new Dynamic1D(6000,0.5f); |
| 244 | 244 |
di.add(new Static1D(1.0f)); |
| 245 | 245 |
di.add(new Static1D(1.0f)); |
| 246 | 246 |
di.add(new Static1D(0.0f)); |
| 247 | 247 |
|
| 248 |
mGFFAEffects.move( new Static3D(w/5,h/3,0) );
|
|
| 249 |
mGFFAEffects.scale( new Static3D(scale,scale,scale) );
|
|
| 248 |
mGFFAEffects.move( new Static3D(qx/2-0.3f,qy/2-0.16f,0) );
|
|
| 249 |
mGFFAEffects.scale( new Static3D(qx,qy,1) );
|
|
| 250 | 250 |
mGFFAEffects.alpha(di); |
| 251 | 251 |
|
| 252 | 252 |
mScreen.attach(mGFFATexture, mGFFAEffects, mQuad); |
| ... | ... | |
| 380 | 380 |
mScreen.detach(mGFFAEffects); |
| 381 | 381 |
mGFFATexture.markForDeletion(); |
| 382 | 382 |
|
| 383 |
int screenW=mScreen.getWidth(); |
|
| 384 |
int screenH=mScreen.getHeight(); |
|
| 385 |
|
|
| 386 |
int logoW = mLogoTexture.getWidth(); |
|
| 387 |
int logoH = mLogoTexture.getHeight(); |
|
| 388 |
|
|
| 389 |
int initSize= (int)(3.0f*screenW/logoW); |
|
| 390 |
int finaSize= (int)(0.1f*screenW/logoW); |
|
| 383 |
float qx= (float)mScreen.getWidth() /mLogoTexture.getWidth() ; |
|
| 384 |
float qy= (float)mScreen.getHeight()/mLogoTexture.getHeight(); |
|
| 385 |
|
|
| 386 |
float initSize= 3.0f; |
|
| 387 |
float finaSize= 0.1f; |
|
| 391 | 388 |
|
| 392 | 389 |
Dynamic3D di = new Dynamic3D(10000,0.5f); |
| 393 |
di.add(new Static3D(initSize,initSize,1));
|
|
| 394 |
di.add(new Static3D(finaSize,finaSize,1));
|
|
| 390 |
di.add(qx<qy ? (new Static3D(initSize,initSize*qx/qy,1)) : (new Static3D(initSize*qy/qx,initSize,1)));
|
|
| 391 |
di.add(qx<qy ? (new Static3D(finaSize,finaSize*qx/qy,1)) : (new Static3D(finaSize*qy/qx,finaSize,1)));
|
|
| 395 | 392 |
|
| 396 |
mLogoEffects.move( new Static3D(screenW/2,screenH/2,0) ); |
|
| 397 | 393 |
mLogoEffects.scale(di); |
| 398 |
mLogoEffects.move( new Static3D(-logoW/2,-logoH/2,0) ); |
|
| 399 |
|
|
| 394 |
|
|
| 400 | 395 |
mScreen.attach(mLogoTexture, mLogoEffects,mQuad); |
| 401 | 396 |
mLogoEffects.registerForMessages(this); |
| 402 | 397 |
} |
| ... | ... | |
| 412 | 407 |
int backH = mCrawlBackgroundTexture.getHeight(); |
| 413 | 408 |
float scale= (float)screenW/crawlW; |
| 414 | 409 |
|
| 415 |
mCrawlBackgroundEffects.move( new Static3D(0,screenH-backH,0) ); |
|
| 416 |
mCrawlBackgroundEffects.rotate( new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(screenW/2,backH,0) ); |
|
| 410 |
//mCrawlBackgroundEffects.move( new Static3D(0,screenH-backH,0) ); |
|
| 411 |
mCrawlBackgroundEffects.rotate( new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(0.5f,1.0f,0.0f) ); |
|
| 412 |
mCrawlBackgroundEffects.scale( new Static3D(1.0f, (float)backH/screenH,1.0f) ); |
|
| 417 | 413 |
|
| 418 | 414 |
final int transpDist = 5; |
| 419 | 415 |
Static4D region = new Static4D(screenW/2,(1-transpDist)*backH,transpDist*backH,transpDist*backH); |
| 420 |
mCrawlBackgroundEffects.alpha(new Static1D(1-transpDist*0.6f), region, true); |
|
| 416 |
//mCrawlBackgroundEffects.alpha(new Static1D(1-transpDist*0.6f), region, true);
|
|
| 421 | 417 |
|
| 422 | 418 |
Dynamic3D di = new Dynamic3D(70000,0.5f); |
| 423 | 419 |
di.add(new Static3D(screenW/2,+backH , 0)); |
| 424 | 420 |
di.add(new Static3D(screenW/2,-scale*crawlH, 0)); |
| 425 | 421 |
|
| 426 |
mCrawlEffects.move(di); |
|
| 427 |
mCrawlEffects.scale( new Static3D(scale,scale,scale) ); |
|
| 428 |
mCrawlEffects.move( new Static3D(-crawlW/2,0,0) ); |
|
| 422 |
//mCrawlEffects.move(di);
|
|
| 423 |
//mCrawlEffects.scale( new Static3D(scale,scale,scale) );
|
|
| 424 |
//mCrawlEffects.move( new Static3D(-crawlW/2,0,0) );
|
|
| 429 | 425 |
|
| 430 | 426 |
mBackground = mScreen.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects,mQuad); |
| 431 | 427 |
mBackground.attach(mCrawlTexture, mCrawlEffects,mQuad); |
Also available in: Unified diff
Major refactoring: convert the Matrix Effects to be independent of the resolution of the surface we render to.
Re-write the first 15 apps to work with this.