Revision f209a803
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/examples/sink/SinkRenderer.java | ||
---|---|---|
52 | 52 |
private DistortedTexture mTexture; |
53 | 53 |
private MeshRectangles mMesh; |
54 | 54 |
private Static3D mScale; |
55 |
private float mBmpRatio; |
|
55 | 56 |
|
56 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
57 | 58 |
|
... | ... | |
59 | 60 |
{ |
60 | 61 |
mView = v; |
61 | 62 |
|
62 |
Dynamic1D sink = new Dynamic1D(2000,0.0f); |
|
63 |
sink.add(new Static1D(1.0f)); |
|
64 |
sink.add(new Static1D(0.2f)); |
|
63 |
Dynamic1D sinkStrength = new Dynamic1D(2000,0.0f);
|
|
64 |
sinkStrength.add(new Static1D(1.0f));
|
|
65 |
sinkStrength.add(new Static1D(0.2f));
|
|
65 | 66 |
|
66 | 67 |
mEffects = new DistortedEffects(); |
67 |
VertexEffectSink sinkEffect = new VertexEffectSink(sink, new Static3D(0,0,0), null); |
|
68 |
|
|
69 |
// strength [changing in time from 1.0 to 0.2 and back], |
|
70 |
// center [(0,0,0), i.e. center of the bitmap], |
|
71 |
// region [null - apply to the whole bitmap |
|
72 |
VertexEffectSink sinkEffect = new VertexEffectSink(sinkStrength, new Static3D(0,0,0), null); |
|
68 | 73 |
mEffects.apply(sinkEffect); |
69 | 74 |
|
70 | 75 |
mScale = new Static3D(1,1,1); |
... | ... | |
84 | 89 |
|
85 | 90 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
86 | 91 |
{ |
87 |
float horiRatio = (float)width / mMesh.getStretchX(); |
|
88 |
float vertRatio = (float)height/ mMesh.getStretchY(); |
|
89 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
92 |
float min= width>height ? height : width; |
|
90 | 93 |
|
91 |
mScale.set( factor,factor,factor );
|
|
94 |
mScale.set( min, min*mBmpRatio, 1 );
|
|
92 | 95 |
mScreen.resize(width, height); |
93 | 96 |
} |
94 | 97 |
|
... | ... | |
112 | 115 |
catch(IOException e) { } |
113 | 116 |
} |
114 | 117 |
|
115 |
int bmpHeight = bitmap.getHeight(); |
|
116 |
int bmpWidth = bitmap.getWidth(); |
|
118 |
mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth(); |
|
117 | 119 |
|
118 | 120 |
if( mTexture==null ) mTexture = new DistortedTexture(); |
119 | 121 |
mTexture.setTexture(bitmap); |
120 | 122 |
|
121 |
if( mMesh==null ) |
|
122 |
{ |
|
123 |
mMesh = new MeshRectangles(30,30*bmpHeight/bmpWidth); |
|
124 |
mMesh.setStretch(bmpWidth,bmpHeight,0); |
|
125 |
} |
|
123 |
if( mMesh==null ) mMesh = new MeshRectangles(30,(int)(30*mBmpRatio)); |
|
126 | 124 |
|
127 | 125 |
mScreen.detachAll(); |
128 | 126 |
mScreen.attach(mTexture,mEffects,mMesh); |
Also available in: Unified diff
Convert Sink to not use the depreciated MeshBase.setStretch() API.