Project

General

Profile

« Previous | Next » 

Revision 19938eb7

Added by Leszek Koltunski over 7 years ago

Convert a few more APPs to the new resolution-independent Matrix Effects.

View differences:

src/main/java/org/distorted/examples/mirror/MirrorRenderer.java
46 46
class MirrorRenderer implements GLSurfaceView.Renderer
47 47
{
48 48
   private static final float MIRROR_SCALE     =0.70f;  // each next mirror will be 70% of the size or the previous
49
   private static final float HEAD_SCALE       =0.30f;  // Head's height will be 30% of the height of the mirror
49
   private static final float HEAD_SCALE       =0.40f;  // Head's height will be 30% of the height of the mirror
50 50
   private static final float MIRROR_BRIGHTNESS=0.70f;  // Each next mirror 30% darker
51
   private static final float MIRROR_MARGIN    =0.11f;  // The frame of the mirror takes up 11% of its width
51
   private static final float MIRROR_MARGIN    =0.09f;  // The frame of the mirror takes up 9% of its width
52 52
   private static final float MIRROR_MOVE      =0.12f;  // Each next mirror is moved to the right by 12% of
53 53
                                                        // the length of the previous one
54 54

  
55 55
   private GLSurfaceView mView;
56
   private DistortedEffects mEffectsMirror, mEffectsHead, mEffectsNull;
57
   private DistortedEffects mEffectsOffscreen1, mEffectsOffscreen2;
56
   private DistortedEffects mEffectsHead, mEffectsNull, mEffectsOffscreen1, mEffectsOffscreen2;
58 57
   private DistortedTexture mTextureMirror, mTextureHead;
59 58
   private DistortedFramebuffer mOffScreen1, mOffScreen2;
60 59
   private DistortedScreen mScreen;
......
63 62
   private Dynamic3D mHeadDyn;
64 63
   private int mX;
65 64

  
66
   private int mMirrorW, mMirrorH, mHeadW, mHeadH;
65
   private int mHeadW, mHeadH;
67 66
   private int mScreenW, mScreenH;
68 67

  
69 68
///////////////////////////////////////////////////////////////////////////////////////////////////
......
74 73
      mQuad    = new MeshFlat(1,1);
75 74
      mScreen  = new DistortedScreen();
76 75

  
77
      mEffectsMirror    = new DistortedEffects();
78
      mEffectsHead      = new DistortedEffects();
79
      mEffectsOffscreen1= new DistortedEffects();
80
      mEffectsOffscreen2= new DistortedEffects();
81
      mEffectsNull      = new DistortedEffects();
76
      mEffectsHead       = new DistortedEffects();
77
      mEffectsOffscreen1 = new DistortedEffects();
78
      mEffectsOffscreen2 = new DistortedEffects();
79
      mEffectsNull       = new DistortedEffects();
82 80

  
83 81
      mX = MirrorActivity.INIT_POSITION;
84 82

  
......
92 90
   void setPosition(int pos)
93 91
      {
94 92
      mX = pos;
95

  
96
      float headW = (HEAD_SCALE *mScreenH* mHeadW) / (mScreenW* mHeadH);
97

  
98
      mHeadPosition.set1(mX*(1.0f-2*MIRROR_MARGIN-headW)*mScreenW / 100.0f + MIRROR_MARGIN*mScreenW);
93
      mHeadPosition.set1( (mX/50.0f-1)*(0.5f-MIRROR_MARGIN-HEAD_SCALE/2) );
99 94
      }
100 95
   
101 96
///////////////////////////////////////////////////////////////////////////////////////////////////
......
133 128
        mOffScreen2 = new DistortedFramebuffer( (int)(MIRROR_SCALE*mScreenW), (int)(MIRROR_SCALE*mScreenH) );
134 129

  
135 130
        mEffectsHead.abortAllEffects();
136
        mEffectsMirror.abortAllEffects();
137 131
        mEffectsOffscreen1.abortAllEffects();
138 132
        mEffectsOffscreen2.abortAllEffects();
139 133

  
140
        mEffectsMirror.scale( new Static3D( (float)mScreenW/mMirrorW, (float)mScreenH/mMirrorH, 1.0f) );
141
        mEffectsOffscreen1.scale(MIRROR_SCALE);
142 134
        mEffectsOffscreen1.brightness(new Static1D(MIRROR_BRIGHTNESS));
143
        mEffectsOffscreen2.move( new Static3D( MIRROR_MOVE*mScreenW, MIRROR_MOVE*mScreenH*mMirrorW/mMirrorH, 0) );
135
        mEffectsOffscreen2.move( new Static3D( MIRROR_MOVE-0.5f+MIRROR_SCALE/2, MIRROR_MOVE-0.5f+MIRROR_SCALE/2, 0) );
136
        mEffectsOffscreen2.scale( new Static3D( MIRROR_SCALE, MIRROR_SCALE, 1) );
144 137

  
145 138
        mEffectsHead.move(mHeadDyn);
146
        float headScale = HEAD_SCALE *mScreenH/ mHeadH;
147
        mEffectsHead.scale(headScale);
148
        mHeadPosition.set2( mScreenH*(1.0f-MIRROR_MARGIN*mMirrorW/mMirrorH) - headScale* mHeadH);
139
        float qx = mScreenW/ mHeadW;
140
        float qy = mScreenH/ mHeadH;
141

  
142
        if( qx<qy )
143
          {
144
          mEffectsHead.scale(new Static3D(HEAD_SCALE, HEAD_SCALE*qx/qy, 1) );
145
          mHeadPosition.set2(0.5f-MIRROR_MARGIN-(HEAD_SCALE/2)*qx/qy);
146
          }
147
        else
148
          {
149
          mEffectsHead.scale( new Static3D(HEAD_SCALE*qy/qx, HEAD_SCALE, 1) );
150
          mHeadPosition.set2(0.5f-MIRROR_MARGIN-HEAD_SCALE/2);
151
          }
152

  
149 153
        setPosition(mX);
150 154

  
151
        mOffScreen1.attach( mTextureMirror, mEffectsMirror    , mQuad );
155
        mOffScreen1.attach( mTextureMirror, mEffectsNull      , mQuad );
152 156
        mOffScreen1.attach( mOffScreen2   , mEffectsOffscreen2, mQuad );
153 157
        mOffScreen1.attach( mTextureHead  , mEffectsHead      , mQuad );
154 158
        mOffScreen2.attach( mOffScreen1   , mEffectsOffscreen1, mQuad );
155 159

  
156 160
        mScreen.detachAll();
157
        mScreen.attach    ( mOffScreen1   , mEffectsNull      , mQuad );
161
        mScreen.attach    ( mOffScreen1   , mEffectsNull     , mQuad );
158 162
        mScreen.resize(mScreenW,mScreenH);
159 163
        }
160 164
      }
......
183 187
        catch(IOException e) { }
184 188
        }
185 189

  
186
      mMirrorW = bitmapM.getWidth();
187
      mMirrorH = bitmapM.getHeight();
188
      mHeadW   = bitmapH.getWidth();
189
      mHeadH   = bitmapH.getHeight();
190
      mHeadW = bitmapH.getWidth();
191
      mHeadH = bitmapH.getHeight();
190 192

  
191
      if( mTextureMirror==null ) mTextureMirror = new DistortedTexture(mMirrorW,mMirrorH);
193
      if( mTextureMirror==null ) mTextureMirror = new DistortedTexture(bitmapM.getWidth(),bitmapM.getHeight());
192 194
      if( mTextureHead  ==null ) mTextureHead   = new DistortedTexture(mHeadW, mHeadH);
193 195

  
194 196
      mTextureMirror.setTexture(bitmapM);
src/main/java/org/distorted/examples/quaternion/QuaternionRenderer.java
41 41

  
42 42
import android.graphics.Bitmap;
43 43
import android.graphics.BitmapFactory;
44
import android.opengl.GLES30;
45 44
import android.opengl.GLSurfaceView;
46 45

  
47 46
///////////////////////////////////////////////////////////////////////////////////////////////////
......
99 98
    
100 99
  public void onSurfaceChanged(GL10 glUnused, int width, int height) 
101 100
    {
102
    float scaleFactor = width>height ? height/3:width/3;
101
    float qx = (float)width ;
102
    float qy = (float)height;
103
    float scale = 0.5f;
103 104

  
104 105
    mEffects.abortEffects(EffectTypes.MATRIX);
105
    mEffects.move( new Static3D( (width-scaleFactor)/2 , (height-scaleFactor)/2 , 0) );
106
    mEffects.scale(scaleFactor);
107
    mEffects.quaternion( mRot, new Static3D( (float)mTexture.getWidth()/2, (float)mTexture.getHeight()/2 , 0) );
108
       
106
    mEffects.quaternion( mRot, new Static3D(0,0,0) );
107
    mEffects.scale(  qx<qy ? (new Static3D(scale,scale*qx/qy,scale)) : (new Static3D(scale*qy/qx,scale,scale)) );
108

  
109 109
    mScreen.resize(width, height);
110 110
    }
111 111

  

Also available in: Unified diff