Revision fa9b6494
Added by Leszek Koltunski almost 7 years ago
src/main/java/org/distorted/examples/bean/BeanRenderer.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
import org.distorted.examples.R; |
29 | 29 |
|
30 |
import org.distorted.library.effect.EffectName; |
|
31 |
import org.distorted.library.effect.MatrixEffectMove; |
|
32 |
import org.distorted.library.effect.MatrixEffectScale; |
|
33 |
import org.distorted.library.effect.VertexEffectDistort; |
|
30 | 34 |
import org.distorted.library.main.DistortedEffects; |
31 | 35 |
import org.distorted.library.main.DistortedScreen; |
32 |
import org.distorted.library.EffectNames; |
|
33 |
import org.distorted.library.EffectTypes; |
|
34 | 36 |
import org.distorted.library.main.Distorted; |
35 | 37 |
import org.distorted.library.main.DistortedTexture; |
36 | 38 |
import org.distorted.library.main.MeshFlat; |
... | ... | |
51 | 53 |
private DistortedScreen mScreen; |
52 | 54 |
private DistortedTexture mTexture; |
53 | 55 |
private MeshFlat mMesh; |
54 |
private int bmpHeight, bmpWidth; |
|
55 |
|
|
56 |
private int mObjHeight, mObjWidth; |
|
57 |
private Static3D mMove, mScale; |
|
58 |
|
|
56 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
57 | 60 |
|
58 | 61 |
BeanRenderer(GLSurfaceView v) |
... | ... | |
85 | 88 |
dRight.add(p1); |
86 | 89 |
dRight.add(p1); |
87 | 90 |
|
91 |
mMove = new Static3D(0,0,0); |
|
92 |
mScale= new Static3D(1,1,1); |
|
93 |
|
|
88 | 94 |
mEffects = new DistortedEffects(); |
89 |
mEffects.distort(dLeft , pLeft , rLeft ); |
|
90 |
mEffects.distort(dRight, pRight, rRight); |
|
95 |
mEffects.apply( new VertexEffectDistort(dLeft , pLeft , rLeft) ); |
|
96 |
mEffects.apply( new VertexEffectDistort(dRight, pRight, rRight)); |
|
97 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
98 |
mEffects.apply(new MatrixEffectScale(mScale)); |
|
91 | 99 |
|
92 | 100 |
mScreen = new DistortedScreen(mView); |
93 | 101 |
} |
94 | 102 |
|
95 | 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
96 | 104 |
|
97 |
public void onDrawFrame(GL10 glUnused)
|
|
105 |
public void onDrawFrame(GL10 glUnused)
|
|
98 | 106 |
{ |
99 | 107 |
mScreen.render( System.currentTimeMillis() ); |
100 | 108 |
} |
101 | 109 |
|
102 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
103 | 111 |
|
104 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
105 |
{ |
|
106 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
107 |
|
|
108 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
112 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
113 |
{ |
|
114 |
if( (float)mObjHeight/mObjWidth > (float)height/width ) |
|
109 | 115 |
{ |
110 |
int w = (height*bmpWidth)/bmpHeight; |
|
111 |
float factor = (float)height/bmpHeight; |
|
112 |
|
|
113 |
mEffects.move( new Static3D((width-w)/2,0,0) ); |
|
114 |
mEffects.scale(factor); |
|
116 |
int w = (height*mObjWidth)/mObjHeight; |
|
117 |
float factor = (float)height/mObjHeight; |
|
118 |
mMove.set((width-w)/2,0,0); |
|
119 |
mScale.set(factor,factor,factor); |
|
115 | 120 |
} |
116 | 121 |
else |
117 | 122 |
{ |
118 |
int h = (width*bmpHeight)/bmpWidth; |
|
119 |
float factor = (float)width/bmpWidth; |
|
120 |
|
|
121 |
mEffects.move( new Static3D(0,(height-h)/2,0) ); |
|
122 |
mEffects.scale(factor); |
|
123 |
int h = (width*mObjHeight)/mObjWidth; |
|
124 |
float factor = (float)width/mObjWidth; |
|
125 |
mMove.set(0,(height-h)/2,0); |
|
126 |
mScale.set(factor,factor,factor); |
|
123 | 127 |
} |
124 |
|
|
125 |
mScreen.resize(width, height);
|
|
126 |
}
|
|
128 |
|
|
129 |
mScreen.resize(width,height); |
|
130 |
} |
|
127 | 131 |
|
128 | 132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
129 | 133 |
|
130 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
131 |
{
|
|
132 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.bean);
|
|
133 |
Bitmap bitmap;
|
|
134 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
135 |
{ |
|
136 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.bean); |
|
137 |
Bitmap bitmap; |
|
134 | 138 |
|
135 |
try
|
|
136 |
{
|
|
137 |
bitmap = BitmapFactory.decodeStream(is);
|
|
138 |
}
|
|
139 |
finally
|
|
140 |
{
|
|
141 |
try
|
|
142 |
{
|
|
143 |
is.close();
|
|
144 |
}
|
|
145 |
catch(IOException e) { }
|
|
146 |
}
|
|
139 |
try
|
|
140 |
{ |
|
141 |
bitmap = BitmapFactory.decodeStream(is); |
|
142 |
}
|
|
143 |
finally
|
|
144 |
{ |
|
145 |
try
|
|
146 |
{ |
|
147 |
is.close(); |
|
148 |
}
|
|
149 |
catch(IOException e) { } |
|
150 |
}
|
|
147 | 151 |
|
148 |
bmpHeight = bitmap.getHeight();
|
|
149 |
bmpWidth = bitmap.getWidth();
|
|
152 |
mObjHeight = bitmap.getHeight();
|
|
153 |
mObjWidth = bitmap.getWidth();
|
|
150 | 154 |
|
151 |
if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
|
|
152 |
mTexture.setTexture(bitmap);
|
|
153 |
if( mMesh==null ) mMesh = new MeshFlat(25,25*bmpHeight/bmpWidth);
|
|
154 |
mScreen.detachAll();
|
|
155 |
mScreen.attach(mTexture,mEffects,mMesh);
|
|
156 |
|
|
157 |
DistortedEffects.enableEffect(EffectNames.DISTORT);
|
|
158 |
|
|
159 |
try
|
|
160 |
{
|
|
161 |
Distorted.onCreate(mView.getContext());
|
|
162 |
}
|
|
163 |
catch(Exception ex)
|
|
164 |
{
|
|
165 |
android.util.Log.e("Bean", ex.getMessage() );
|
|
166 |
}
|
|
167 |
}
|
|
155 |
if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
|
|
156 |
mTexture.setTexture(bitmap); |
|
157 |
if( mMesh==null ) mMesh = new MeshFlat(25,25*mObjHeight/mObjWidth);
|
|
158 |
mScreen.detachAll(); |
|
159 |
mScreen.attach(mTexture,mEffects,mMesh); |
|
160 |
|
|
161 |
DistortedEffects.enableEffect(EffectName.DISTORT);
|
|
162 |
|
|
163 |
try |
|
164 |
{ |
|
165 |
Distorted.onCreate(mView.getContext()); |
|
166 |
} |
|
167 |
catch(Exception ex) |
|
168 |
{ |
|
169 |
android.util.Log.e("Bean", ex.getMessage() ); |
|
170 |
} |
|
171 |
} |
|
168 | 172 |
} |
Also available in: Unified diff
Convert the first few Apps to the new Effect API.