Revision 26c4e181
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java | ||
---|---|---|
51 | 51 |
private MeshRectangles mMesh; |
52 | 52 |
private DistortedScreen mScreen; |
53 | 53 |
private Static3D mScale; |
54 |
private Static3D mCenterLeft, mCenterRight; |
|
54 | 55 |
|
55 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 57 |
|
... | ... | |
60 | 61 |
|
61 | 62 |
// two points, centers of the Distort effect |
62 | 63 |
// the left and right tip of the mouth |
63 |
Static3D pLeft = new Static3D( 90, 108, 0); |
|
64 |
Static3D pRight = new Static3D(176, 111, 0); |
|
64 |
// (0,0,0) for now because we don't know the size of the bitmap yet. |
|
65 |
mCenterLeft = new Static3D(0,0,0); |
|
66 |
mCenterRight = new Static3D(0,0,0); |
|
65 | 67 |
|
66 | 68 |
// two regions defining the areas affected by the Distort effect |
67 | 69 |
Static4D rLeft = new Static4D(-10, 10, 0, 25); |
... | ... | |
83 | 85 |
dRight.add( new Static3D( 20, 10, 0) ); |
84 | 86 |
|
85 | 87 |
mEffects = new DistortedEffects(); |
86 |
mEffects.apply( new VertexEffectDistort(dLeft , pLeft , rLeft ) );
|
|
87 |
mEffects.apply( new VertexEffectDistort(dRight, pRight, rRight) );
|
|
88 |
mEffects.apply( new VertexEffectDistort(dLeft , mCenterLeft , rLeft ) );
|
|
89 |
mEffects.apply( new VertexEffectDistort(dRight, mCenterRight, rRight) );
|
|
88 | 90 |
|
89 | 91 |
mScale= new Static3D(1,1,1); |
90 | 92 |
mEffects.apply(new MatrixEffectScale(mScale)); |
... | ... | |
103 | 105 |
|
104 | 106 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
105 | 107 |
{ |
106 |
float horiRatio = (float)width / mTexture.getWidth();
|
|
107 |
float vertRatio = (float)height/ mTexture.getHeight();
|
|
108 |
float horiRatio = (float)width / mMesh.getStretchX();
|
|
109 |
float vertRatio = (float)height/ mMesh.getStretchY();
|
|
108 | 110 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
109 | 111 |
|
110 | 112 |
mScale.set( factor,factor,factor ); |
... | ... | |
134 | 136 |
int bmpHeight = bitmap.getHeight(); |
135 | 137 |
int bmpWidth = bitmap.getWidth(); |
136 | 138 |
|
139 |
// Now we know the size of the bitmap, we can set the centers of effects |
|
140 |
// to (90,108) from the lower-left corner (CenterLeft) and (176,111) from the corner. |
|
141 |
mCenterLeft .set( 90 - bmpWidth/2, 108 - bmpHeight/2, 0); |
|
142 |
mCenterRight.set(176 - bmpWidth/2, 111 - bmpHeight/2, 0); |
|
143 |
|
|
137 | 144 |
// We could have gotten here after the activity went to the background |
138 | 145 |
// for a brief amount of time; in this case mTexture is already created. |
139 | 146 |
// Do not leak memory by creating it the second time around. |
Also available in: Unified diff
First fixes for moving the Vertex and Fragment centers of effect to the center of the Mesh.