Project

General

Profile

« Previous | Next » 

Revision 26c4e181

Added by Leszek Koltunski almost 5 years ago

First fixes for moving the Vertex and Fragment centers of effect to the center of the Mesh.

View differences:

src/main/java/org/distorted/examples/bean/BeanRenderer.java
51 51
   private DistortedScreen mScreen;
52 52
   private DistortedTexture mTexture;
53 53
   private MeshRectangles mMesh;
54
   private Static3D mScale;
54
   private Static3D mScale, mBrowL, mBrowR;
55 55

  
56 56
///////////////////////////////////////////////////////////////////////////////////////////////////
57 57

  
......
59 59
      {
60 60
      mView = v;
61 61
     
62
      Static3D pointLeft  = new Static3D( 98, 297, 0);
63
      Static3D pointRight = new Static3D(233, 340, 0);
62

  
64 63
      Static4D regionLeft = new Static4D( -3, 33, 0, 47);
65 64
      Static4D regionRight= new Static4D(-14, 33, 0, 47);
66 65
      Dynamic3D dynLeft   = new Dynamic3D(2000,0.0f);
......
84 83
      dynRight.add(vect1);
85 84

  
86 85
      mScale= new Static3D(1,1,1);
86
      mBrowL= new Static3D(0,0,0);
87
      mBrowR= new Static3D(0,0,0);
87 88

  
88 89
      mEffects = new DistortedEffects();
89
      mEffects.apply( new VertexEffectDistort(dynLeft , pointLeft , regionLeft) );
90
      mEffects.apply( new VertexEffectDistort(dynRight, pointRight, regionRight));
90
      mEffects.apply( new VertexEffectDistort(dynLeft , mBrowL, regionLeft) );
91
      mEffects.apply( new VertexEffectDistort(dynRight, mBrowR, regionRight));
91 92
      mEffects.apply( new MatrixEffectScale(mScale) );
92 93

  
93 94
      mScreen = new DistortedScreen();
......
135 136
     int bmpHeight = bitmap.getHeight();
136 137
     int bmpWidth  = bitmap.getWidth();
137 138

  
139
     mBrowL.set( 98 - bmpWidth/2, 297 - bmpHeight/2, 0);
140
     mBrowR.set(233 - bmpWidth/2, 340 - bmpHeight/2, 0);
141

  
138 142
     if( mTexture==null ) mTexture = new DistortedTexture();
139 143
     mTexture.setTexture(bitmap);
144

  
140 145
     if( mMesh==null )
141 146
       {
142 147
       mMesh = new MeshRectangles(25,25*bmpHeight/bmpWidth);
src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
51 51
    private MeshRectangles mMesh;
52 52
    private DistortedScreen mScreen;
53 53
    private Static3D mScale;
54
    private Static3D mCenterLeft, mCenterRight;
54 55

  
55 56
///////////////////////////////////////////////////////////////////////////////////////////////////
56 57

  
......
60 61

  
61 62
      // two points, centers of the Distort effect
62 63
      // the left and right tip of the mouth
63
      Static3D pLeft  = new Static3D( 90, 108, 0);
64
      Static3D pRight = new Static3D(176, 111, 0);
64
      // (0,0,0) for now because we don't know the size of the bitmap yet.
65
      mCenterLeft  = new Static3D(0,0,0);
66
      mCenterRight = new Static3D(0,0,0);
65 67

  
66 68
      // two regions defining the areas affected by the Distort effect
67 69
      Static4D rLeft  = new Static4D(-10, 10, 0, 25);
......
83 85
      dRight.add( new Static3D( 20, 10, 0) );
84 86

  
85 87
      mEffects = new DistortedEffects();
86
      mEffects.apply( new VertexEffectDistort(dLeft , pLeft , rLeft ) );
87
      mEffects.apply( new VertexEffectDistort(dRight, pRight, rRight) );
88
      mEffects.apply( new VertexEffectDistort(dLeft , mCenterLeft , rLeft ) );
89
      mEffects.apply( new VertexEffectDistort(dRight, mCenterRight, rRight) );
88 90

  
89 91
      mScale= new Static3D(1,1,1);
90 92
      mEffects.apply(new MatrixEffectScale(mScale));
......
103 105
    
104 106
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
105 107
      {
106
      float horiRatio = (float)width / mTexture.getWidth();
107
      float vertRatio = (float)height/ mTexture.getHeight();
108
      float horiRatio = (float)width / mMesh.getStretchX();
109
      float vertRatio = (float)height/ mMesh.getStretchY();
108 110
      float factor    = horiRatio > vertRatio ? vertRatio : horiRatio;
109 111

  
110 112
      mScale.set( factor,factor,factor );
......
134 136
      int bmpHeight = bitmap.getHeight();
135 137
      int bmpWidth  = bitmap.getWidth();
136 138

  
139
      // Now we know the size of the bitmap, we can set the centers of effects
140
      // to (90,108) from the lower-left corner (CenterLeft) and (176,111) from the corner.
141
      mCenterLeft .set( 90 - bmpWidth/2, 108 - bmpHeight/2, 0);
142
      mCenterRight.set(176 - bmpWidth/2, 111 - bmpHeight/2, 0);
143

  
137 144
      // We could have gotten here after the activity went to the background
138 145
      // for a brief amount of time; in this case mTexture is already created.
139 146
      // Do not leak memory by creating it the second time around.
src/main/java/org/distorted/examples/projection/ProjectionRenderer.java
126 126
      mRegion.set(0,0,0,min/4);
127 127

  
128 128
      mPoint1.set(  width/4,   height/4, 0);
129
      mPoint2.set(3*width/4,   height/4, 0);
130
      mPoint3.set(  width/4, 3*height/4, 0);
131
      mPoint4.set(3*width/4, 3*height/4, 0);
129
      mPoint2.set( -width/4,   height/4, 0);
130
      mPoint3.set(  width/4,  -height/4, 0);
131
      mPoint4.set( -width/4,  -height/4, 0);
132 132

  
133 133
      // Avoid memory leaks: delete old texture if it exists (it might if we
134 134
      // got here after a brief amount of time spent in the background)
src/main/java/org/distorted/examples/sink/SinkRenderer.java
64 64
    sink.add(new Static1D(0.2f));
65 65

  
66 66
    mEffects = new DistortedEffects();
67
    VertexEffectSink sinkEffect = new VertexEffectSink(sink, new Static3D(297, 280, 0), null);
67
    VertexEffectSink sinkEffect = new VertexEffectSink(sink, new Static3D(0,0,0), null);
68 68
    mEffects.apply(sinkEffect);
69 69

  
70 70
    mScale = new Static3D(1,1,1);
......
117 117

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

  
120 121
    if( mMesh==null )
121 122
      {
122 123
      mMesh = new MeshRectangles(30,30*bmpHeight/bmpWidth);
123 124
      mMesh.setStretch(bmpWidth,bmpHeight,0);
124 125
      }
125 126

  
126

  
127 127
    mScreen.detachAll();
128 128
    mScreen.attach(mTexture,mEffects,mMesh);
129 129

  

Also available in: Unified diff