Revision 51554e47
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.graphics.Bitmap; |
23 | 23 |
import android.graphics.BitmapFactory; |
24 |
import android.opengl.GLES30; |
|
25 | 24 |
import android.opengl.GLSurfaceView; |
26 | 25 |
|
27 | 26 |
import org.distorted.examples.R; |
... | ... | |
49 | 48 |
private DistortedTexture mTexture; |
50 | 49 |
private DistortedScreen mScreen; |
51 | 50 |
private AroundTheWorldEffectsManager mManager; |
52 |
private int mObjWidth, mObjHeight;
|
|
51 |
private int bmpWidth, bmpHeight;
|
|
53 | 52 |
|
54 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 54 |
|
... | ... | |
84 | 83 |
|
85 | 84 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
86 | 85 |
{ |
87 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
86 |
float qx = (float)width /bmpWidth; |
|
87 |
float qy = (float)height/bmpHeight; |
|
88 | 88 |
|
89 |
if( (float)mObjHeight/mObjWidth > (float)height/width ) |
|
90 |
{ |
|
91 |
int w = (height*mObjWidth)/mObjHeight; |
|
92 |
float factor = (float)height/mObjHeight; |
|
93 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
94 |
mEffects.scale(factor); |
|
95 |
} |
|
96 |
else |
|
97 |
{ |
|
98 |
int h = (width*mObjHeight)/mObjWidth; |
|
99 |
float factor = (float)width/mObjWidth; |
|
100 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
101 |
mEffects.scale(factor); |
|
102 |
} |
|
89 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
90 |
mEffects.scale( qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) ); |
|
103 | 91 |
|
104 | 92 |
mScreen.resize(width,height); |
105 | 93 |
} |
... | ... | |
124 | 112 |
catch(IOException e) { } |
125 | 113 |
} |
126 | 114 |
|
127 |
mObjWidth = bitmap.getWidth();
|
|
128 |
mObjHeight= bitmap.getHeight();
|
|
115 |
bmpWidth = bitmap.getWidth();
|
|
116 |
bmpHeight= bitmap.getHeight();
|
|
129 | 117 |
|
130 |
if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
|
|
118 |
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
|
|
131 | 119 |
mTexture.setTexture(bitmap); |
132 | 120 |
|
133 | 121 |
mScreen.detachAll(); |
134 |
mScreen.attach(mTexture, mEffects, new MeshFlat(30,30*mObjHeight/mObjWidth));
|
|
122 |
mScreen.attach(mTexture, mEffects, new MeshFlat(30,30*bmpHeight/bmpWidth));
|
|
135 | 123 |
|
136 | 124 |
DistortedEffects.enableEffect(EffectNames.DISTORT); |
137 | 125 |
DistortedEffects.enableEffect(EffectNames.SINK); |
Also available in: Unified diff
Convert a few more APPs to the new resolution-independent Matrix Effects.