Project

General

Profile

« Previous | Next » 

Revision 7f9d5a91

Added by Leszek Koltunski almost 8 years ago

Mirror app finished (well, we still need to get some better bitmap for the girl)

View differences:

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 SCALE = 0.5f;
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
48
   private static final float MIRROR_MARGIN= 0.11f;  // The frame of the mirror takes up 11% of its width
49
   private static final float MIRROR_MOVE  = 0.13f;  // Each next mirror is moved to the right by 13% of
50
                                                     // the length of the previous one
47 51

  
48 52
   private GLSurfaceView mView;
49
   private DistortedEffects mEffectsMirror, mEffectsGirl, mEffectsOffscreen, mEffectsNull;
53
   private DistortedEffects mEffectsMirror, mEffectsGirl, mEffectsNull;
54
   private DistortedEffects mEffectsOffscreen1, mEffectsOffscreen2;
50 55
   private DistortedTexture mTextureMirror, mTextureGirl;
51 56
   private DistortedFramebuffer mScreen, mOffScreen1, mOffScreen2;
52 57
   private GridFlat mQuad;
53 58
   private Static3D mGirlPosition;
54 59
   private Dynamic3D mGirlDyn;
60
   private int mX;
55 61

  
56 62
   private int mMirrorW, mMirrorH, mGirlW, mGirlH;
57 63
   private int mScreenW, mScreenH;
......
64 70
      mQuad    = new GridFlat(1,1);
65 71
      mScreen  = new DistortedFramebuffer(0);
66 72

  
67
      mEffectsMirror   = new DistortedEffects();
68
      mEffectsGirl     = new DistortedEffects();
69
      mEffectsOffscreen= new DistortedEffects();
70
      mEffectsNull     = new DistortedEffects();
73
      mEffectsMirror    = new DistortedEffects();
74
      mEffectsGirl      = new DistortedEffects();
75
      mEffectsOffscreen1= new DistortedEffects();
76
      mEffectsOffscreen2= new DistortedEffects();
77
      mEffectsNull      = new DistortedEffects();
78

  
79
      mX = 100;
71 80

  
72 81
      mGirlPosition = new Static3D(0,0,0);
73 82
      mGirlDyn      = new Dynamic3D();
......
78 87

  
79 88
   void setPosition(int pos)
80 89
      {
81
      mGirlPosition.set1(pos*mScreenW / 100.0f);
90
      mX = pos;
91

  
92
      float girlW = (GIRL_SCALE*mScreenH*mGirlW) / (mScreenW*mGirlH);
93

  
94
      mGirlPosition.set1(mX*(1.0f-2*MIRROR_MARGIN-girlW)*mScreenW / 100.0f + MIRROR_MARGIN*mScreenW);
82 95
      }
83 96
   
84 97
///////////////////////////////////////////////////////////////////////////////////////////////////
......
97 110

  
98 111
      long time = System.currentTimeMillis();
99 112

  
100
      mOffScreen1.renderTo( mTextureMirror, mQuad, mEffectsMirror   , time );
101
      mOffScreen1.renderTo( mOffScreen2   , mQuad, mEffectsOffscreen, time );
102
      mOffScreen1.renderTo( mTextureGirl  , mQuad, mEffectsGirl     , time );
103
      mOffScreen2.renderTo( mOffScreen1   , mQuad, mEffectsNull     , time );
104
      mScreen.renderTo    ( mOffScreen1   , mQuad, mEffectsMirror   , time );
113
      mOffScreen1.renderTo( mTextureMirror, mQuad, mEffectsMirror    , time );
114
      mOffScreen1.renderTo( mOffScreen2   , mQuad, mEffectsOffscreen2, time );
115
      mOffScreen1.renderTo( mTextureGirl  , mQuad, mEffectsGirl      , time );
116
      mOffScreen2.renderTo( mOffScreen1   , mQuad, mEffectsOffscreen1, time );
117
      mScreen.renderTo    ( mOffScreen1   , mQuad, mEffectsNull      , time );
105 118
      }
106 119

  
107 120
///////////////////////////////////////////////////////////////////////////////////////////////////
......
114 127
        mScreenH = height;
115 128

  
116 129
        mOffScreen1 = new DistortedFramebuffer(mScreenW,mScreenH);
117
        mOffScreen2 = new DistortedFramebuffer( (int)(SCALE*mScreenW), (int)(SCALE*mScreenH) );
130
        mOffScreen2 = new DistortedFramebuffer( (int)(MIRROR_SCALE*mScreenW), (int)(MIRROR_SCALE*mScreenH) );
118 131

  
119 132
        mEffectsGirl.abortAllEffects();
120 133
        mEffectsMirror.abortAllEffects();
121
        mEffectsOffscreen.abortAllEffects();
134
        mEffectsOffscreen1.abortAllEffects();
135
        mEffectsOffscreen2.abortAllEffects();
122 136

  
123 137
        mEffectsMirror.scale( new Static3D( (float)mScreenW/mMirrorW, (float)mScreenH/mMirrorH, 1.0f) );
124
        mEffectsOffscreen.move( new Static3D( mScreenW/10, mScreenH/10, 0) );
138
        mEffectsOffscreen1.scale(MIRROR_SCALE);
139
        mEffectsOffscreen2.move( new Static3D( MIRROR_MOVE*mScreenW, MIRROR_MOVE*mScreenH*mMirrorW/mMirrorH, 0) );
140

  
125 141
        mEffectsGirl.move(mGirlDyn);
126
        mGirlPosition.set2(mScreenH*0.9f);
142
        float girlScale = GIRL_SCALE*mScreenH/mGirlH;
143
        mEffectsGirl.scale(girlScale);
144
        mGirlPosition.set2( mScreenH*(1.0f-MIRROR_MARGIN*mMirrorW/mMirrorH) - girlScale*mGirlH);
145
        setPosition(mX);
127 146

  
128 147
        mScreen.resize(mScreenW,mScreenH);
129 148
        }

Also available in: Unified diff