Project

General

Profile

« Previous | Next » 

Revision f6d884d5

Added by Leszek Koltunski over 7 years ago

Complete the split DistortedObject -> (DistortedTexture,DistortedEffectQueue)

View differences:

src/main/java/org/distorted/examples/projection/ProjectionRenderer.java
24 24

  
25 25
import org.distorted.library.Distorted;
26 26
import org.distorted.library.GridFlat;
27
import org.distorted.library.DistortedObject;
27
import org.distorted.library.DistortedTexture;
28
import org.distorted.library.DistortedEffectQueues;
28 29
import org.distorted.library.type.Static3D;
29 30
import org.distorted.library.type.Static4D;
30 31

  
......
40 41
class ProjectionRenderer implements GLSurfaceView.Renderer
41 42
{
42 43
   private GLSurfaceView mView;
43
   private DistortedObject mProjection;
44
   private DistortedTexture mTexture;
45
   private DistortedEffectQueues mQueues;
44 46
   private GridFlat mGrid;
45 47

  
46 48
   private static float mF, mX, mY;
......
51 53
   ProjectionRenderer(GLSurfaceView view)
52 54
      { 
53 55
      mView = view;
56
      mQueues = new DistortedEffectQueues();
54 57
      }
55 58

  
56 59
///////////////////////////////////////////////////////////////////////////////////////////////////
......
85 88
   public void onDrawFrame(GL10 glUnused) 
86 89
      {
87 90
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
88
      mProjection.draw(System.currentTimeMillis(), mGrid);
91
      mQueues.draw(System.currentTimeMillis(), mTexture,mGrid);
89 92
      }
90 93

  
91 94
///////////////////////////////////////////////////////////////////////////////////////////////////
......
95 98
      mWidth = width;
96 99
      mHeight= height;
97 100

  
98
      Distorted.onSurfaceChanged(width, height);
99
      setupBitmap(width,height);
100
      }
101

  
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
    
104
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
105
      {
106
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
107

  
108
      try
109
        {
110
        Distorted.onSurfaceCreated(mView.getContext());
111
        }
112
      catch(Exception ex)
113
        {
114
        android.util.Log.e("Projection", ex.getMessage() );
115
        }
116
      }
117
    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

  
120
    private void setupBitmap(int w, int h)
121
      {
122 101
      Paint paint = new Paint();
123
      mProjection = new DistortedObject(w,h,1);
124
      mGrid       = new GridFlat(50,50*h/w);
125
      Bitmap bmp = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
102
      mTexture    = new DistortedTexture(width,height,0);
103
      mGrid       = new GridFlat(50,50*height/width);
104
      Bitmap bmp  = Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
126 105
      Canvas bmpCanvas = new Canvas(bmp);
127 106

  
128 107
      paint.setColor(0xff008800);
129 108
      paint.setStyle(Style.FILL);
130
      bmpCanvas.drawRect(0, 0, w, h, paint);
109
      bmpCanvas.drawRect(0, 0, width, height, paint);
131 110
      paint.setColor(0xffffffff);
132 111

  
133 112
      final int NUMLINES = 10;
134 113

  
135 114
      for(int i=0; i<=NUMLINES ; i++ )
136 115
        {
137
        bmpCanvas.drawRect(w*i/NUMLINES - 1,                0,  w*i/NUMLINES + 1,  h               , paint);
138
        bmpCanvas.drawRect(               0, h *i/NUMLINES -1,  w               ,  h*i/NUMLINES + 1, paint);
116
        bmpCanvas.drawRect(width*i/NUMLINES - 1,                    0,  width*i/NUMLINES + 1,  height               , paint);
117
        bmpCanvas.drawRect(                   0, height*i/NUMLINES -1,  width               ,  height*i/NUMLINES + 1, paint);
139 118
        }
140
        
141
      mProjection.setTexture(bmp);
142
        
143
      int min = w<h ? w:h;
144
        
119

  
120
      mTexture.setTexture(bmp);
121

  
122
      int min = width<height ? width:height;
123

  
145 124
      Static3D vector = new Static3D(0,0,min/5);
146 125
      Static4D region = new Static4D(0,0,min/5,min/5);
147 126

  
148
      mProjection.distort(vector, new Static3D(  w/4,   h/4, 0), region);
149
      mProjection.distort(vector, new Static3D(3*w/4,   h/4, 0), region);
150
      mProjection.distort(vector, new Static3D(  w/4, 3*h/4, 0), region);
151
      mProjection.distort(vector, new Static3D(3*w/4, 3*h/4, 0), region);
127
      mQueues.distort(vector, new Static3D(  width/4,   height/4, 0), region);
128
      mQueues.distort(vector, new Static3D(3*width/4,   height/4, 0), region);
129
      mQueues.distort(vector, new Static3D(  width/4, 3*height/4, 0), region);
130
      mQueues.distort(vector, new Static3D(3*width/4, 3*height/4, 0), region);
131

  
132
      Distorted.onSurfaceChanged(width, height);
152 133
      }
153 134

  
154 135
///////////////////////////////////////////////////////////////////////////////////////////////////
155 136
    
137
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
138
      {
139
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
140

  
141
      try
142
        {
143
        Distorted.onSurfaceCreated(mView.getContext());
144
        }
145
      catch(Exception ex)
146
        {
147
        android.util.Log.e("Projection", ex.getMessage() );
148
        }
149
      }
156 150
}

Also available in: Unified diff