Revision 936333aa
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/examples/catanddog/CatAndDogRenderer.java | ||
|---|---|---|
| 35 | 35 |
import org.distorted.library.main.DistortedEffects; |
| 36 | 36 |
import org.distorted.library.main.DistortedScreen; |
| 37 | 37 |
import org.distorted.library.main.DistortedTexture; |
| 38 |
import org.distorted.library.mesh.MeshRectangles;
|
|
| 38 |
import org.distorted.library.mesh.MeshQuad;
|
|
| 39 | 39 |
import org.distorted.library.type.Dynamic; |
| 40 | 40 |
import org.distorted.library.type.Dynamic1D; |
| 41 | 41 |
import org.distorted.library.type.Dynamic3D; |
| ... | ... | |
| 50 | 50 |
|
| 51 | 51 |
class CatAndDogRenderer implements GLSurfaceView.Renderer |
| 52 | 52 |
{
|
| 53 |
private static final int DURATION_CHROMA_ALPHA = 3000; |
|
| 54 |
private static final int DURATION_MATRIX_EFFECTS = 10000; |
|
| 55 |
|
|
| 56 | 53 |
private GLSurfaceView mView; |
| 57 |
private DistortedEffects mEffects; |
|
| 58 |
private MeshRectangles mMesh; |
|
| 59 | 54 |
private DistortedTexture mTexture; |
| 60 | 55 |
private DistortedScreen mScreen; |
| 61 |
private int mObjHeight, mObjWidth;
|
|
| 62 |
private Static3D mMoveStartingPoint, mMoveEndPoint;
|
|
| 56 |
private Static3D mScaleStart, mScaleEnd, mMoveStart, mMoveEnd;
|
|
| 57 |
private float mBmpRatio;
|
|
| 63 | 58 |
|
| 64 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 65 | 60 |
|
| 66 | 61 |
CatAndDogRenderer(GLSurfaceView v) |
| 67 |
{
|
|
| 68 |
mView = v; |
|
| 69 |
|
|
| 70 |
mMesh = new MeshRectangles(1,1); // no vertex effects, grid can be a (1x1) quad. |
|
| 71 |
|
|
| 72 |
Dynamic3D moveDyn= new Dynamic3D(DURATION_MATRIX_EFFECTS,0.0f); |
|
| 73 |
|
|
| 74 |
mMoveStartingPoint = new Static3D(0,0,0); |
|
| 75 |
mMoveEndPoint = new Static3D(0,0,0); |
|
| 62 |
{
|
|
| 63 |
final int DURATION_CHROMA_ALPHA = 3000; |
|
| 64 |
final int DURATION_MATRIX_EFFECTS = 10000; |
|
| 76 | 65 |
|
| 77 |
moveDyn.add(mMoveStartingPoint); |
|
| 78 |
moveDyn.add(mMoveEndPoint); |
|
| 66 |
mView = v; |
|
| 79 | 67 |
|
| 80 |
Static3D chromaCenter= new Static3D( 130, 50, 0 ); |
|
| 81 |
Static3D chromaRegion= new Static3D( 100, 100, 100 ); |
|
| 82 |
Static3D alphaCenter = new Static3D(-170, 50, 0 ); |
|
| 83 |
Static3D alphaRegion = new Static3D( 100, 100, 100 ); |
|
| 68 |
DistortedEffects effects = new DistortedEffects(); |
|
| 84 | 69 |
|
| 85 |
Dynamic1D chromaDyn = new Dynamic1D(DURATION_CHROMA_ALPHA,0.0f); |
|
| 86 |
chromaDyn.add(new Static1D(1)); |
|
| 87 |
chromaDyn.add(new Static1D(0)); |
|
| 88 |
Dynamic1D alphaDyn = new Dynamic1D(DURATION_CHROMA_ALPHA,0.0f); |
|
| 89 |
alphaDyn.add(new Static1D(1)); |
|
| 90 |
alphaDyn.add(new Static1D(0)); |
|
| 70 |
mScaleStart= new Static3D(1,1,1); |
|
| 71 |
mScaleEnd = new Static3D(1,1,1); |
|
| 91 | 72 |
Dynamic3D diScale = new Dynamic3D(DURATION_MATRIX_EFFECTS,0.0f); |
| 92 |
diScale.add(new Static3D(1,1,1));
|
|
| 93 |
diScale.add(new Static3D(0.33f,0.33f,1));
|
|
| 94 |
diScale.add(new Static3D(1,1,1));
|
|
| 73 |
diScale.add(mScaleStart);
|
|
| 74 |
diScale.add(mScaleEnd );
|
|
| 75 |
diScale.add(mScaleStart);
|
|
| 95 | 76 |
diScale.setMode(Dynamic.MODE_PATH); |
| 77 |
effects.apply( new MatrixEffectScale( diScale )); |
|
| 78 |
|
|
| 96 | 79 |
Dynamic1D diRotate = new Dynamic1D(DURATION_MATRIX_EFFECTS,0.0f); |
| 97 | 80 |
diRotate.add(new Static1D( 0)); |
| 98 | 81 |
diRotate.add(new Static1D(360)); |
| 99 |
|
|
| 100 |
mEffects = new DistortedEffects(); |
|
| 101 |
mEffects.apply( new FragmentEffectChroma( chromaDyn, new Static3D(1,0,0), chromaCenter, chromaRegion ,true) ); |
|
| 102 |
mEffects.apply( new FragmentEffectAlpha(alphaDyn, alphaCenter, alphaRegion, false) ); |
|
| 103 |
mEffects.apply( new MatrixEffectMove(moveDyn)); |
|
| 104 |
mEffects.apply( new MatrixEffectScale(diScale)); |
|
| 105 |
mEffects.apply( new MatrixEffectRotate( diRotate, new Static3D(0,0,1), new Static3D(0,0,0)) ); |
|
| 106 |
|
|
| 107 |
mScreen = new DistortedScreen(); |
|
| 82 |
effects.apply( new MatrixEffectRotate( diRotate, new Static3D(0,0,1), new Static3D(0,0,0)) ); |
|
| 83 |
|
|
| 84 |
mMoveStart= new Static3D(0,0,0); |
|
| 85 |
mMoveEnd = new Static3D(0,0,0); |
|
| 86 |
Dynamic3D diMove= new Dynamic3D(DURATION_MATRIX_EFFECTS,0.0f); |
|
| 87 |
diMove.add( mMoveStart ); |
|
| 88 |
diMove.add( mMoveEnd ); |
|
| 89 |
effects.apply( new MatrixEffectMove( diMove )); |
|
| 90 |
|
|
| 91 |
Dynamic1D diChroma = new Dynamic1D(DURATION_CHROMA_ALPHA,0.0f); |
|
| 92 |
diChroma.add(new Static1D(1)); |
|
| 93 |
diChroma.add(new Static1D(0)); |
|
| 94 |
Static3D chromaCenter= new Static3D( -0.25f, 0, 0 ); |
|
| 95 |
Static3D chromaRegion= new Static3D( 0.2f, 0.3f, 0.2f ); |
|
| 96 |
effects.apply( new FragmentEffectChroma( diChroma, new Static3D(1,0,0), chromaCenter, chromaRegion ,true) ); |
|
| 97 |
|
|
| 98 |
Dynamic1D diAlpha = new Dynamic1D(DURATION_CHROMA_ALPHA,0.0f); |
|
| 99 |
diAlpha.add(new Static1D(1)); |
|
| 100 |
diAlpha.add(new Static1D(0)); |
|
| 101 |
Static3D alphaCenter = new Static3D( +0.25f, 0, 0 ); |
|
| 102 |
Static3D alphaRegion = new Static3D( 0.2f, 0.3f, 0.2f ); |
|
| 103 |
effects.apply( new FragmentEffectAlpha( diAlpha, alphaCenter, alphaRegion, false) ); |
|
| 104 |
|
|
| 105 |
mTexture = new DistortedTexture(); |
|
| 106 |
mScreen = new DistortedScreen(); |
|
| 107 |
|
|
| 108 |
mScreen.attach(mTexture,effects,new MeshQuad()); |
|
| 108 | 109 |
} |
| 109 | 110 |
|
| 110 | 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 111 | 112 |
|
| 112 | 113 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 113 | 114 |
{
|
| 114 |
mMoveStartingPoint.set( (width-mObjWidth)/2, (height-mObjHeight)/2, 0); |
|
| 115 |
mMoveEndPoint .set(-(width-mObjWidth)/2,-(height-mObjHeight)/2, 0); |
|
| 115 |
final float SCALE_START = 0.3f; |
|
| 116 |
final float SCALE_END = 0.6f; |
|
| 117 |
float min= (width>height ? height : width); |
|
| 118 |
|
|
| 119 |
mScaleStart.set( SCALE_START*min, SCALE_START*min*mBmpRatio, 1 ); |
|
| 120 |
mScaleEnd .set( SCALE_END *min, SCALE_END *min*mBmpRatio, 1 ); |
|
| 121 |
|
|
| 122 |
mMoveStart.set( 0.5f*width - (SCALE_START/2)*min , 0.5f*height - SCALE_START/2*min*mBmpRatio, 0); |
|
| 123 |
mMoveEnd .set(-0.5f*width + (SCALE_START/2)*min , -0.5f*height + SCALE_START/2*min*mBmpRatio, 0); |
|
| 116 | 124 |
|
| 117 | 125 |
mScreen.resize(width, height); |
| 118 | 126 |
} |
| ... | ... | |
| 143 | 151 |
catch(IOException e) { }
|
| 144 | 152 |
} |
| 145 | 153 |
|
| 146 |
mObjHeight = bitmap.getHeight(); |
|
| 147 |
mObjWidth = bitmap.getWidth(); |
|
| 148 |
|
|
| 149 |
mMesh.setStretch(mObjWidth,mObjHeight,0); |
|
| 150 |
|
|
| 151 |
if( mTexture==null ) mTexture = new DistortedTexture(); |
|
| 154 |
mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth(); |
|
| 152 | 155 |
mTexture.setTexture(bitmap); |
| 153 | 156 |
|
| 154 |
mScreen.detachAll(); |
|
| 155 |
mScreen.attach(mTexture,mEffects,mMesh); |
|
| 156 |
|
|
| 157 | 157 |
FragmentEffectChroma.enable(); |
| 158 | 158 |
FragmentEffectAlpha.enable(); |
| 159 | 159 |
|
Also available in: Unified diff
Port Cat and Dog to the new setStretch-less API.