Project

General

Profile

« Previous | Next » 

Revision 4c42bc15

Added by Leszek Koltunski almost 5 years ago

Some cleanups in MonaLisa, Bean & Sink.

View differences:

src/main/java/org/distorted/examples/bean/BeanRenderer.java
93 93
      mEffects.apply( new VertexEffectDistort(dynRight, pointRight, regionRight));
94 94
      mEffects.apply( new MatrixEffectScale(mScale) );
95 95

  
96
      mScreen = new DistortedScreen();
96
      mTexture = new DistortedTexture();
97
      mScreen  = new DistortedScreen();
97 98
      }
98 99

  
99 100
///////////////////////////////////////////////////////////////////////////////////////////////////
......
134 135
       }
135 136
      
136 137
     mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth();
137

  
138
     if( mTexture==null ) mTexture = new DistortedTexture();
139 138
     mTexture.setTexture(bitmap);
140 139

  
141 140
     // we need a denser Mesh lattice this time for the Distorts to look good.
src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
59 59
      {
60 60
      mView = v;
61 61

  
62
      // Centers of the Effects.
63
      // center = (0,0,0) would be the midpoint of the Bitmap.
62 64
      // MonaLisa bitmap is 320x366, this is thus (90,108) pixels from the lower-left corner
63 65
      Static3D centerLeft  = new Static3D( ( 90-320*0.5f)/320.0f, (108-366*0.5f)/366.0f, 0);
64 66
      // (176,111) from the lower left
65 67
      Static3D centerRight = new Static3D( (176-320*0.5f)/320.0f, (111-366*0.5f)/366.0f, 0);
66 68

  
67
      // two regions defining the areas affected by the Distort effect
68
      Static4D rLeft  = new Static4D( -10/320.0f, 10/366.0f, 0, 25/320.0f);
69
      Static4D rRight = new Static4D(  10/320.0f,  5/366.0f, 0, 25/320.0f);
69
      // two Regions defining the areas affected by the Distort effect
70
      // a Region is like a mask that specifies which area around the Center is affected by
71
      // the Distort. Here (-10,10,0) pixels from the left center, with radius 25 pixels
72
      Static4D regionLeft  = new Static4D( -10/320.0f, 10/366.0f, 0, 25/320.0f);
73
      // and likewise (10,5,0) pixels from the right Center, radius 25 pixels.
74
      Static4D regionRight = new Static4D(  10/320.0f,  5/366.0f, 0, 25/320.0f);
70 75

  
71 76
      // two dynamics for interpolating through vectors of distortion. Interpolate
72 77
      // every 1000 milliseconds, indefinitely ('0.0f').
73
      Dynamic3D dLeft = new Dynamic3D(1000,0.0f);
74
      Dynamic3D dRight= new Dynamic3D(1000,0.0f);
78
      Dynamic3D degLeft = new Dynamic3D(1000,0.0f);
79
      Dynamic3D degRight= new Dynamic3D(1000,0.0f);
75 80

  
76 81
      // two vectors of distortion the left tip of the mouth gets distorted with -
77
      // interpolated from (0,0,0) - i.e. no distortion - to (-20 pixels, 20 pixels, 0), i.e.
78
      // slightly to the top left.
79
      dLeft.add ( new Static3D(         0,         0, 0) );
80
      dLeft.add ( new Static3D(-20/320.0f, 20/366.0f, 0) );
82
      // interpolated from (0,0,0) - i.e. no distortion - to (-20 pixels, 20 pixels, 0),
83
      // i.e. slightly to the top left.
84
      degLeft.add ( new Static3D(         0,         0, 0) );
85
      degLeft.add ( new Static3D(-20/320.0f, 20/366.0f, 0) );
81 86

  
82 87
      // likewise two vectors the right tip is distorted with.
83
      dRight.add( new Static3D(         0,         0, 0) );
84
      dRight.add( new Static3D( 20/320.0f, 10/366.0f, 0) );
88
      degRight.add( new Static3D(         0,         0, 0) );
89
      degRight.add( new Static3D( 20/320.0f, 10/366.0f, 0) );
85 90

  
86 91
      // Equip MonaLisa with the Effects we want to draw her with - i.e. two Distorts of the mouth
87 92
      mEffects = new DistortedEffects();
88
      mEffects.apply( new VertexEffectDistort(dLeft , centerLeft , rLeft ) );
89
      mEffects.apply( new VertexEffectDistort(dRight, centerRight, rRight) );
93
      mEffects.apply( new VertexEffectDistort( degLeft , centerLeft , regionLeft ) );
94
      mEffects.apply( new VertexEffectDistort( degRight, centerRight, regionRight) );
90 95

  
91 96
      // ... and a Scale - so far by (1,1,1), i.e. no scale. The mScale point will be computed
92
      // later, in onSurfaceChanged, when we actually know the size of the screen and know how
97
      // later, in onSurfaceChanged, when we actually know the size of the screen and thus how
93 98
      // much to scale the initial Mesh (which is 1x1x0 in size)
94 99
      mScale= new Static3D(1,1,1);
95 100
      mEffects.apply(new MatrixEffectScale(mScale));
96 101

  
97
      mScreen = new DistortedScreen();
102
      mTexture = new DistortedTexture();
103
      mScreen  = new DistortedScreen();
98 104
      }
99 105

  
100 106
///////////////////////////////////////////////////////////////////////////////////////////////////
......
136 142

  
137 143
      mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth();
138 144

  
139
      // We could have gotten here after the activity went to the background
140
      // for a brief amount of time; in this case mTexture is already created.
141
      // Do not create it the second time around then.
142
      if( mTexture==null ) mTexture = new DistortedTexture();
143

  
144
      // likewise the Mesh
145 145
      // Create an underlying Mesh of 9x10 vertices - this is for the Distort
146 146
      // effect to have vertices to distort. We multiply by mBmpRatio here so
147 147
      // that the Mesh's cells are as close to squares as possible (when they
148 148
      // finally be rendered with a Scale - see mScale)
149 149
      if( mMesh==null ) mMesh = new MeshRectangles(9, (int)(9*mBmpRatio) );
150 150

  
151
      // even if mTexture wasn't null, we still need to call setTexture() on it
152
      // because every time activity goes to background, its OpenGL resources
153
      // - including Textures - get deleted. We always need to call setTexture()
154
      // to recreate the internal OpenGL textures.
151
      // Every time activity goes to background, its OpenGL resources - including
152
      // Textures - get deleted. We always need to call setTexture() here to
153
      // recreate the internal OpenGL textures.
155 154
      mTexture.setTexture(bitmap);
156 155

  
157 156
      // Build the Scene Graph - attach all Objects we want to be rendered to the Screen.
src/main/java/org/distorted/examples/sink/SinkRenderer.java
58 58

  
59 59
  SinkRenderer(GLSurfaceView v)
60 60
    { 
61
    mView = v;
61
    mView    = v;
62
    mTexture = new DistortedTexture();
63
    mEffects = new DistortedEffects();
64
    mScreen  = new DistortedScreen();
62 65

  
63 66
    Dynamic1D sinkStrength = new Dynamic1D(2000,0.0f);
64 67
    sinkStrength.add(new Static1D(1.0f));
65 68
    sinkStrength.add(new Static1D(0.2f));
66 69

  
67
    mEffects = new DistortedEffects();
68

  
69 70
    // strength [changing in time from 1.0 to 0.2 and back],
70 71
    // center   [(0,0,0), i.e. center of the bitmap],
71 72
    // region   [null - apply to the whole bitmap
......
74 75

  
75 76
    mScale = new Static3D(1,1,1);
76 77
    mEffects.apply(new MatrixEffectScale(mScale));
77

  
78
    mScreen = new DistortedScreen();
79 78
    }
80 79

  
81 80
///////////////////////////////////////////////////////////////////////////////////////////////////
......
117 116
      
118 117
    mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth();
119 118

  
120
    if( mTexture==null ) mTexture = new DistortedTexture();
121 119
    mTexture.setTexture(bitmap);
122 120

  
123 121
    if( mMesh==null ) mMesh = new MeshRectangles(30,(int)(30*mBmpRatio));

Also available in: Unified diff