Revision e8b6aa95
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
import org.distorted.examples.R; |
29 | 29 |
import org.distorted.library.Distorted; |
30 |
import org.distorted.library.DistortedBitmap; |
|
30 |
import org.distorted.library.DistortedObject; |
|
31 |
import org.distorted.library.DistortedBitmapGrid; |
|
31 | 32 |
import org.distorted.library.EffectTypes; |
32 | 33 |
import org.distorted.library.type.Dynamic3D; |
33 |
import org.distorted.library.type.Static2D; |
|
34 | 34 |
import org.distorted.library.type.Static3D; |
35 | 35 |
import org.distorted.library.type.Static4D; |
36 | 36 |
|
... | ... | |
44 | 44 |
class MonaLisaRenderer implements GLSurfaceView.Renderer |
45 | 45 |
{ |
46 | 46 |
private GLSurfaceView mView; |
47 |
private DistortedBitmap monaLisa; |
|
47 |
private DistortedObject mObject; |
|
48 |
private DistortedBitmapGrid mGrid; |
|
48 | 49 |
private Static3D pLeft, pRight; |
49 | 50 |
private Static4D rLeft, rRight; |
50 | 51 |
private Dynamic3D dLeft, dRight; |
... | ... | |
75 | 76 |
public void onDrawFrame(GL10 glUnused) |
76 | 77 |
{ |
77 | 78 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
78 |
monaLisa.draw(System.currentTimeMillis());
|
|
79 |
mObject.draw(System.currentTimeMillis(),mGrid);
|
|
79 | 80 |
} |
80 | 81 |
|
81 | 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
82 | 83 |
|
83 | 84 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
84 | 85 |
{ |
85 |
monaLisa.abortEffects(EffectTypes.MATRIX);
|
|
86 |
mObject.abortEffects(EffectTypes.MATRIX);
|
|
86 | 87 |
|
87 | 88 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
88 | 89 |
{ |
89 | 90 |
int w = (height*bmpWidth)/bmpHeight; |
90 | 91 |
float factor = (float)height/bmpHeight; |
91 |
monaLisa.move( new Static3D((width-w)/2,0,0) );
|
|
92 |
monaLisa.scale(factor);
|
|
92 |
mObject.move( new Static3D((width-w)/2,0,0) );
|
|
93 |
mObject.scale(factor);
|
|
93 | 94 |
} |
94 | 95 |
else |
95 | 96 |
{ |
96 | 97 |
int h = (width*bmpHeight)/bmpWidth; |
97 | 98 |
float factor = (float)width/bmpWidth; |
98 |
monaLisa.move( new Static3D(0,(height-h)/2,0) );
|
|
99 |
monaLisa.scale(factor);
|
|
99 |
mObject.move( new Static3D(0,(height-h)/2,0) );
|
|
100 |
mObject.scale(factor);
|
|
100 | 101 |
} |
101 | 102 |
|
102 | 103 |
Distorted.onSurfaceChanged(width, height); |
... | ... | |
127 | 128 |
bmpHeight = bitmap.getHeight(); |
128 | 129 |
bmpWidth = bitmap.getWidth(); |
129 | 130 |
|
130 |
monaLisa = new DistortedBitmap(bitmap, 9); |
|
131 |
monaLisa.distort( dLeft, pLeft , rLeft ); |
|
132 |
monaLisa.distort(dRight, pRight, rRight); |
|
131 |
mGrid = new DistortedBitmapGrid(9,9*bmpHeight/bmpWidth); |
|
132 |
mObject = new DistortedObject(bmpWidth,bmpHeight,1); |
|
133 |
mObject.setTexture(bitmap); |
|
134 |
mObject.distort( dLeft, pLeft , rLeft ); |
|
135 |
mObject.distort(dRight, pRight, rRight); |
|
133 | 136 |
|
134 | 137 |
try |
135 | 138 |
{ |
Also available in: Unified diff
Major change in API: separate the GRID from DistortedObject; completely remove classes derived from DistortedObject.