Revision 2c2616f1
Added by Leszek Koltunski almost 9 years ago
| src/main/java/org/distorted/examples/mirror/MirrorRenderer.java | ||
|---|---|---|
| 43 | 43 |
|
| 44 | 44 |
class MirrorRenderer implements GLSurfaceView.Renderer |
| 45 | 45 |
{
|
| 46 |
private static final float MIRROR_SCALE = 0.60f; // each next mirror will be 60% of the size |
|
| 47 |
private static final float GIRL_SCALE = 0.30f; // Girl's height will be 30% of the height of the mirror
|
|
| 46 |
private static final float MIRROR_SCALE = 0.60f; // each next mirror will be 60% of the size or the previous
|
|
| 47 |
private static final float HEAD_SCALE = 0.30f; // Head's height will be 30% of the height of the mirror
|
|
| 48 | 48 |
private static final float MIRROR_MARGIN= 0.11f; // The frame of the mirror takes up 11% of its width |
| 49 | 49 |
private static final float MIRROR_MOVE = 0.13f; // Each next mirror is moved to the right by 13% of |
| 50 | 50 |
// the length of the previous one |
| 51 | 51 |
|
| 52 | 52 |
private GLSurfaceView mView; |
| 53 |
private DistortedEffects mEffectsMirror, mEffectsGirl, mEffectsNull;
|
|
| 53 |
private DistortedEffects mEffectsMirror, mEffectsHead, mEffectsNull;
|
|
| 54 | 54 |
private DistortedEffects mEffectsOffscreen1, mEffectsOffscreen2; |
| 55 |
private DistortedTexture mTextureMirror, mTextureGirl;
|
|
| 55 |
private DistortedTexture mTextureMirror, mTextureHead;
|
|
| 56 | 56 |
private DistortedFramebuffer mScreen, mOffScreen1, mOffScreen2; |
| 57 | 57 |
private GridFlat mQuad; |
| 58 |
private Static3D mGirlPosition;
|
|
| 59 |
private Dynamic3D mGirlDyn;
|
|
| 58 |
private Static3D mHeadPosition;
|
|
| 59 |
private Dynamic3D mHeadDyn;
|
|
| 60 | 60 |
private int mX; |
| 61 | 61 |
|
| 62 |
private int mMirrorW, mMirrorH, mGirlW, mGirlH;
|
|
| 62 |
private int mMirrorW, mMirrorH, mHeadW, mHeadH;
|
|
| 63 | 63 |
private int mScreenW, mScreenH; |
| 64 | 64 |
|
| 65 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 71 | 71 |
mScreen = new DistortedFramebuffer(0); |
| 72 | 72 |
|
| 73 | 73 |
mEffectsMirror = new DistortedEffects(); |
| 74 |
mEffectsGirl = new DistortedEffects();
|
|
| 74 |
mEffectsHead = new DistortedEffects();
|
|
| 75 | 75 |
mEffectsOffscreen1= new DistortedEffects(); |
| 76 | 76 |
mEffectsOffscreen2= new DistortedEffects(); |
| 77 | 77 |
mEffectsNull = new DistortedEffects(); |
| 78 | 78 |
|
| 79 | 79 |
mX = MirrorActivity.INIT_POSITION; |
| 80 | 80 |
|
| 81 |
mGirlPosition = new Static3D(0,0,0);
|
|
| 82 |
mGirlDyn = new Dynamic3D();
|
|
| 83 |
mGirlDyn.add(mGirlPosition);
|
|
| 81 |
mHeadPosition = new Static3D(0,0,0);
|
|
| 82 |
mHeadDyn = new Dynamic3D();
|
|
| 83 |
mHeadDyn.add(mHeadPosition);
|
|
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 89 | 89 |
{
|
| 90 | 90 |
mX = pos; |
| 91 | 91 |
|
| 92 |
float girlW = (GIRL_SCALE*mScreenH*mGirlW) / (mScreenW*mGirlH);
|
|
| 92 |
float headW = (HEAD_SCALE *mScreenH* mHeadW) / (mScreenW* mHeadH);
|
|
| 93 | 93 |
|
| 94 |
mGirlPosition.set1(mX*(1.0f-2*MIRROR_MARGIN-girlW)*mScreenW / 100.0f + MIRROR_MARGIN*mScreenW);
|
|
| 94 |
mHeadPosition.set1(mX*(1.0f-2*MIRROR_MARGIN-headW)*mScreenW / 100.0f + MIRROR_MARGIN*mScreenW);
|
|
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 112 | 112 |
|
| 113 | 113 |
mOffScreen1.renderTo( mTextureMirror, mQuad, mEffectsMirror , time ); |
| 114 | 114 |
mOffScreen1.renderTo( mOffScreen2 , mQuad, mEffectsOffscreen2, time ); |
| 115 |
mOffScreen1.renderTo( mTextureGirl , mQuad, mEffectsGirl , time );
|
|
| 115 |
mOffScreen1.renderTo( mTextureHead , mQuad, mEffectsHead , time );
|
|
| 116 | 116 |
mOffScreen2.renderTo( mOffScreen1 , mQuad, mEffectsOffscreen1, time ); |
| 117 | 117 |
mScreen.renderTo ( mOffScreen1 , mQuad, mEffectsNull , time ); |
| 118 | 118 |
} |
| ... | ... | |
| 129 | 129 |
mOffScreen1 = new DistortedFramebuffer(mScreenW,mScreenH); |
| 130 | 130 |
mOffScreen2 = new DistortedFramebuffer( (int)(MIRROR_SCALE*mScreenW), (int)(MIRROR_SCALE*mScreenH) ); |
| 131 | 131 |
|
| 132 |
mEffectsGirl.abortAllEffects();
|
|
| 132 |
mEffectsHead.abortAllEffects();
|
|
| 133 | 133 |
mEffectsMirror.abortAllEffects(); |
| 134 | 134 |
mEffectsOffscreen1.abortAllEffects(); |
| 135 | 135 |
mEffectsOffscreen2.abortAllEffects(); |
| ... | ... | |
| 138 | 138 |
mEffectsOffscreen1.scale(MIRROR_SCALE); |
| 139 | 139 |
mEffectsOffscreen2.move( new Static3D( MIRROR_MOVE*mScreenW, MIRROR_MOVE*mScreenH*mMirrorW/mMirrorH, 0) ); |
| 140 | 140 |
|
| 141 |
mEffectsGirl.move(mGirlDyn);
|
|
| 142 |
float girlScale = GIRL_SCALE*mScreenH/mGirlH;
|
|
| 143 |
mEffectsGirl.scale(girlScale);
|
|
| 144 |
mGirlPosition.set2( mScreenH*(1.0f-MIRROR_MARGIN*mMirrorW/mMirrorH) - girlScale*mGirlH);
|
|
| 141 |
mEffectsHead.move(mHeadDyn);
|
|
| 142 |
float headScale = HEAD_SCALE *mScreenH/ mHeadH;
|
|
| 143 |
mEffectsHead.scale(headScale);
|
|
| 144 |
mHeadPosition.set2( mScreenH*(1.0f-MIRROR_MARGIN*mMirrorW/mMirrorH) - headScale* mHeadH);
|
|
| 145 | 145 |
setPosition(mX); |
| 146 | 146 |
|
| 147 | 147 |
mScreen.resize(mScreenW,mScreenH); |
| ... | ... | |
| 155 | 155 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 156 | 156 |
|
| 157 | 157 |
InputStream isM = mView.getContext().getResources().openRawResource(R.raw.mirror); |
| 158 |
InputStream isG = mView.getContext().getResources().openRawResource(R.raw.face);
|
|
| 158 |
InputStream isH = mView.getContext().getResources().openRawResource(R.raw.messi);
|
|
| 159 | 159 |
|
| 160 |
Bitmap bitmapM, bitmapG;
|
|
| 160 |
Bitmap bitmapM, bitmapH;
|
|
| 161 | 161 |
|
| 162 | 162 |
try |
| 163 | 163 |
{
|
| 164 | 164 |
bitmapM = BitmapFactory.decodeStream(isM); |
| 165 |
bitmapG = BitmapFactory.decodeStream(isG);
|
|
| 165 |
bitmapH = BitmapFactory.decodeStream(isH);
|
|
| 166 | 166 |
} |
| 167 | 167 |
finally |
| 168 | 168 |
{
|
| 169 | 169 |
try |
| 170 | 170 |
{
|
| 171 | 171 |
isM.close(); |
| 172 |
isG.close();
|
|
| 172 |
isH.close();
|
|
| 173 | 173 |
} |
| 174 | 174 |
catch(IOException e) { }
|
| 175 | 175 |
} |
| 176 | 176 |
|
| 177 | 177 |
mMirrorW = bitmapM.getWidth(); |
| 178 | 178 |
mMirrorH = bitmapM.getHeight(); |
| 179 |
mGirlW = bitmapG.getWidth();
|
|
| 180 |
mGirlH = bitmapG.getHeight();
|
|
| 179 |
mHeadW = bitmapH.getWidth();
|
|
| 180 |
mHeadH = bitmapH.getHeight();
|
|
| 181 | 181 |
|
| 182 | 182 |
mTextureMirror = new DistortedTexture(mMirrorW,mMirrorH); |
| 183 |
mTextureGirl = new DistortedTexture(mGirlW, mGirlH);
|
|
| 183 |
mTextureHead = new DistortedTexture(mHeadW, mHeadH);
|
|
| 184 | 184 |
|
| 185 | 185 |
mTextureMirror.setTexture(bitmapM); |
| 186 |
mTextureGirl.setTexture(bitmapG);
|
|
| 186 |
mTextureHead.setTexture(bitmapH);
|
|
| 187 | 187 |
|
| 188 | 188 |
try |
| 189 | 189 |
{
|
Also available in: Unified diff
Mirror: replace the Head bitmap.