Revision 97dadfe5
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/movingeffects/MovingEffectsRenderer.java | ||
---|---|---|
31 | 31 |
|
32 | 32 |
import org.distorted.library.DistortedBitmap; |
33 | 33 |
import org.distorted.library.Distorted; |
34 |
import org.distorted.library.EffectTypes; |
|
35 |
import org.distorted.library.type.Static3D; |
|
36 | 34 |
|
37 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 36 |
|
39 |
public class MovingEffectsRenderer implements GLSurfaceView.Renderer
|
|
37 |
class MovingEffectsRenderer implements GLSurfaceView.Renderer
|
|
40 | 38 |
{ |
41 |
public static final int NUMLINES = 10; |
|
42 |
public static final int BWID = 300; |
|
43 |
public static final int BHEI = 400; |
|
44 |
|
|
45 | 39 |
private GLSurfaceView mView; |
46 |
public static DistortedBitmap mBackground; |
|
47 | 40 |
private Canvas mCanvas; |
48 | 41 |
private Bitmap mBitmap; |
49 | 42 |
private Paint mPaint; |
50 |
private int texWidth, texHeight; |
|
51 |
|
|
43 |
private int texW, texH; |
|
44 |
|
|
45 |
static DistortedBitmap mBackground; |
|
46 |
|
|
52 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
53 | 48 |
|
54 |
public MovingEffectsRenderer(GLSurfaceView v)
|
|
49 |
MovingEffectsRenderer(GLSurfaceView v) |
|
55 | 50 |
{ |
56 | 51 |
mPaint = new Paint(); |
57 | 52 |
mPaint.setAntiAlias(true); |
... | ... | |
59 | 54 |
mPaint.setStyle(Style.FILL); |
60 | 55 |
|
61 | 56 |
mView = v; |
62 |
|
|
63 |
texWidth = BWID; |
|
64 |
texHeight= BHEI; |
|
65 | 57 |
} |
66 | 58 |
|
67 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 60 |
|
69 | 61 |
private void drawBackground() |
70 | 62 |
{ |
63 |
int NW, NH; |
|
64 |
|
|
65 |
if( texH<texW ) |
|
66 |
{ |
|
67 |
NH = 10; |
|
68 |
NW = NH*texW/texH; |
|
69 |
} |
|
70 |
else |
|
71 |
{ |
|
72 |
NW = 10; |
|
73 |
NH = NW*texH/texW; |
|
74 |
} |
|
75 |
|
|
71 | 76 |
mPaint.setColor(0xff008800); |
72 |
mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
|
|
77 |
mCanvas.drawRect(0, 0, texW, texH, mPaint);
|
|
73 | 78 |
mPaint.setColor(0xffffffff); |
74 | 79 |
|
75 |
for(int i=0; i<=NUMLINES ; i++ ) |
|
76 |
{ |
|
77 |
mCanvas.drawRect(texWidth*i/NUMLINES - 2, 0, texWidth*i/NUMLINES + 2, texHeight , mPaint); |
|
78 |
mCanvas.drawRect( 0, texHeight*i/NUMLINES -2, texWidth , texHeight*i/NUMLINES + 2, mPaint); |
|
79 |
} |
|
80 |
for(int i=0; i<=NH ; i++ ) mCanvas.drawRect( 0, texH*i/NH -2, texW, texH*i/NH + 2, mPaint); |
|
81 |
for(int i=0; i<=NW ; i++ ) mCanvas.drawRect( texW*i/NW - 2, 0, texW*i/NW + 2, texH, mPaint); |
|
80 | 82 |
} |
81 | 83 |
|
82 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | 85 |
|
84 | 86 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
85 |
{ |
|
86 |
mBackground = new DistortedBitmap(texWidth,texHeight, 80); |
|
87 |
mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888); |
|
88 |
mCanvas = new Canvas(mBitmap); |
|
89 |
|
|
87 |
{ |
|
90 | 88 |
try |
91 |
{
|
|
92 |
Distorted.onSurfaceCreated(mView.getContext());
|
|
93 |
}
|
|
94 |
catch(Exception ex)
|
|
95 |
{
|
|
96 |
android.util.Log.e("Renderer", ex.getMessage() );
|
|
97 |
}
|
|
89 |
{ |
|
90 |
Distorted.onSurfaceCreated(mView.getContext()); |
|
91 |
} |
|
92 |
catch(Exception ex) |
|
93 |
{ |
|
94 |
android.util.Log.e("Renderer", ex.getMessage() ); |
|
95 |
} |
|
98 | 96 |
} |
99 | 97 |
|
100 | 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
101 | 99 |
|
102 | 100 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
103 | 101 |
{ |
104 |
mBackground.abortEffects(EffectTypes.MATRIX); |
|
105 |
mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) ); |
|
106 |
|
|
107 |
Distorted.onSurfaceChanged(width, height); |
|
108 |
MovingEffectsSurfaceView.setScreenSize(width, height); |
|
102 |
texW = width; |
|
103 |
texH = height; |
|
104 |
|
|
105 |
mBackground = new DistortedBitmap(texW,texH, 80); |
|
106 |
mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888); |
|
107 |
mCanvas = new Canvas(mBitmap); |
|
108 |
|
|
109 |
Distorted.onSurfaceChanged(texW, texH); |
|
110 |
MovingEffectsSurfaceView.onSurfaceChanged(texW,texH); |
|
109 | 111 |
} |
110 | 112 |
|
111 | 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
1. Attempt to deal with unstable Orthonormal Base in Dynamic class (so far unsuccessful)
2. Improvements to the 'Dynamic' (and by necessity, 'MovingEffects') applications (to be able to debug the previous)