Revision f6d884d5
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/bean/BeanRenderer.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import org.distorted.library.EffectTypes; |
31 | 31 |
import org.distorted.library.Distorted; |
32 |
import org.distorted.library.DistortedObject; |
|
32 |
import org.distorted.library.DistortedTexture; |
|
33 |
import org.distorted.library.DistortedEffectQueues; |
|
33 | 34 |
import org.distorted.library.GridFlat; |
34 | 35 |
import org.distorted.library.type.Dynamic3D; |
35 | 36 |
import org.distorted.library.type.Static3D; |
... | ... | |
45 | 46 |
class BeanRenderer implements GLSurfaceView.Renderer |
46 | 47 |
{ |
47 | 48 |
private GLSurfaceView mView; |
48 |
private DistortedObject mBean; |
|
49 |
private DistortedTexture mTexture; |
|
50 |
private DistortedEffectQueues mQueues; |
|
49 | 51 |
private GridFlat mGrid; |
50 |
private Static3D pLeft, pRight; |
|
51 |
private Dynamic3D dLeft, dRight; |
|
52 |
private Static4D rLeft, rRight; |
|
53 | 52 |
private int bmpHeight, bmpWidth; |
54 | 53 |
|
55 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
58 | 57 |
{ |
59 | 58 |
mView = v; |
60 | 59 |
|
61 |
pLeft = new Static3D( 98, 183, 0); |
|
62 |
pRight= new Static3D(233, 140, 0); |
|
60 |
Static3D pLeft = new Static3D( 98, 183, 0);
|
|
61 |
Static3D pRight= new Static3D(233, 140, 0);
|
|
63 | 62 |
|
64 |
rLeft = new Static4D( -3,-33,47,47); |
|
65 |
rRight= new Static4D(-14,-33,47,47); |
|
63 |
Static4D rLeft = new Static4D( -3,-33,47,47);
|
|
64 |
Static4D rRight= new Static4D(-14,-33,47,47);
|
|
66 | 65 |
|
67 |
dLeft = new Dynamic3D(2000,0.0f); |
|
68 |
dRight= new Dynamic3D(2000,0.0f); |
|
66 |
Dynamic3D dLeft = new Dynamic3D(2000,0.0f);
|
|
67 |
Dynamic3D dRight= new Dynamic3D(2000,0.0f);
|
|
69 | 68 |
|
70 | 69 |
Static3D p1 = new Static3D( 0, 0, 0); |
71 | 70 |
Static3D p2 = new Static3D(-15,-30, 0); |
... | ... | |
83 | 82 |
dRight.add(p1); |
84 | 83 |
dRight.add(p1); |
85 | 84 |
dRight.add(p1); |
85 |
|
|
86 |
mQueues = new DistortedEffectQueues(); |
|
87 |
mQueues.distort(dLeft , pLeft , rLeft ); |
|
88 |
mQueues.distort(dRight, pRight, rRight); |
|
86 | 89 |
} |
87 | 90 |
|
88 | 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
90 | 93 |
public void onDrawFrame(GL10 glUnused) |
91 | 94 |
{ |
92 | 95 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
93 |
mBean.draw(System.currentTimeMillis(), mGrid);
|
|
96 |
mQueues.draw(System.currentTimeMillis(), mTexture, mGrid);
|
|
94 | 97 |
} |
95 | 98 |
|
96 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
97 | 100 |
|
98 | 101 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
99 | 102 |
{ |
100 |
mBean.abortEffects(EffectTypes.MATRIX);
|
|
103 |
mQueues.abortEffects(EffectTypes.MATRIX);
|
|
101 | 104 |
|
102 | 105 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
103 | 106 |
{ |
104 | 107 |
int w = (height*bmpWidth)/bmpHeight; |
105 | 108 |
float factor = (float)height/bmpHeight; |
106 | 109 |
|
107 |
mBean.move( new Static3D((width-w)/2,0,0) );
|
|
108 |
mBean.scale(factor);
|
|
110 |
mQueues.move( new Static3D((width-w)/2,0,0) );
|
|
111 |
mQueues.scale(factor);
|
|
109 | 112 |
} |
110 | 113 |
else |
111 | 114 |
{ |
112 | 115 |
int h = (width*bmpHeight)/bmpWidth; |
113 | 116 |
float factor = (float)width/bmpWidth; |
114 | 117 |
|
115 |
mBean.move( new Static3D(0,(height-h)/2,0) );
|
|
116 |
mBean.scale(factor);
|
|
118 |
mQueues.move( new Static3D(0,(height-h)/2,0) );
|
|
119 |
mQueues.scale(factor);
|
|
117 | 120 |
} |
118 | 121 |
|
119 | 122 |
Distorted.onSurfaceChanged(width, height); |
... | ... | |
144 | 147 |
bmpHeight = bitmap.getHeight(); |
145 | 148 |
bmpWidth = bitmap.getWidth(); |
146 | 149 |
|
147 |
mBean = new DistortedObject(bmpWidth, bmpHeight, 1); |
|
148 |
mBean.setTexture(bitmap); |
|
149 |
mBean.distort(dLeft , pLeft , rLeft ); |
|
150 |
mBean.distort(dRight, pRight, rRight); |
|
151 |
|
|
150 |
mTexture = new DistortedTexture(bmpWidth, bmpHeight, 0); |
|
151 |
mTexture.setTexture(bitmap); |
|
152 | 152 |
mGrid = new GridFlat(25,25*bmpHeight/bmpWidth); |
153 | 153 |
|
154 | 154 |
try |
Also available in: Unified diff
Complete the split DistortedObject -> (DistortedTexture,DistortedEffectQueue)