Project

General

Profile

« Previous | Next » 

Revision dd19d6e0

Added by Leszek Koltunski almost 4 years ago

Some progress with 'MeshJoin' app.

View differences:

src/main/java/org/distorted/examples/meshjoin/MeshJoinRenderer.java
24 24
import android.graphics.Paint;
25 25
import android.opengl.GLSurfaceView;
26 26

  
27
import org.distorted.library.effect.EffectType;
27 28
import org.distorted.library.effect.MatrixEffectQuaternion;
28 29
import org.distorted.library.effect.MatrixEffectScale;
30
import org.distorted.library.effect.VertexEffectMove;
31
import org.distorted.library.effect.VertexEffectRotate;
32
import org.distorted.library.effect.VertexEffectScale;
29 33
import org.distorted.library.effect.VertexEffectSink;
30 34
import org.distorted.library.main.DistortedEffects;
31 35
import org.distorted.library.main.DistortedLibrary;
......
100 104
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
101 105
      {
102 106
      final float SCALE = 0.7f;
103
      mScreenMin = width<height ? width:height;
107
      mScreenMin = Math.min(width, height);
104 108
      float factor = SCALE*mScreenMin;
105 109
      mScale.set(factor,factor,factor);
106 110
      mScreen.resize(width, height);
......
118 122
      mScreen.detachAll();
119 123
      mScreen.attach(mTexture,mEffects,mMesh);
120 124

  
121
      VertexEffectSink.enable();
125
      DistortedLibrary.setMax(EffectType.VERTEX, 7);
122 126

  
123 127
      try
124 128
        {
......
185 189
      final float angleFaces = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
186 190
      final int MESHES=4;
187 191

  
192
      int association = 1;
188 193
      MeshBase[] meshes = new MeshTriangles[MESHES];
189
      for(int i=0; i<MESHES; i++) meshes[i] = new MeshTriangles(10);
190
/*
191
      MatrixEffect[] effects0 = new MatrixEffect[3];
192
      effects0[0] = new MatrixEffectScale( new Static3D(1,SQ3/2,1) );
193
      effects0[1] = new MatrixEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
194
      effects0[2] = new MatrixEffectMove( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
195

  
196
      meshes[0].apply(effects0);
197

  
198
      Static1D angle = new Static1D(angleFaces);
199
      Static3D axis  = new Static3D(-1,0,0);
200
      Static3D center= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
201

  
202
      MatrixEffect[] effects1 = new MatrixEffect[5];
203
      effects1[0] = effects0[0];
204
      effects1[1] = effects0[1];
205
      effects1[2] = effects0[2];
206
      effects1[3] = new MatrixEffectRotate( new Static1D(180), new Static3D(0,0,1), center );
207
      effects1[4] = new MatrixEffectRotate( angle, axis, center );
208
      meshes[1].apply(effects1);
209

  
210
      axis.set(0.5f,0,-SQ3/2);
211
      center.set2(SQ3/3);
212
      meshes[2].apply(effects1);
213

  
214
      axis.set2(SQ3/2);
215
      meshes[3].apply(effects1);
216
*/
217
      Static4D[] textureMaps = new Static4D[MESHES];
218 194

  
219
      for(int i=0; i<MESHES; i++) textureMaps[i] = new Static4D(i*0.25f,0.0f,0.25f,1.0f);
195
      for(int i=0; i<MESHES; i++)
196
        {
197
        meshes[i] = new MeshTriangles(10);
198
        meshes[i].setEffectAssociation(0,association);
199
        association <<= 1;
200
        }
220 201

  
202
      Static4D[] textureMaps = new Static4D[MESHES];
203
      for(int i=0; i<MESHES; i++) textureMaps[i] = new Static4D(i*0.25f,0.0f,0.25f,1.0f);
221 204
      MeshBase result = new MeshJoined(meshes);
222 205
      result.setTextureMap(textureMaps);
223 206

  
207
      Static1D angle  = new Static1D(angleFaces);
208
      Static3D axis1  = new Static3D(  -1, 0,      0);
209
      Static3D axis2  = new Static3D(0.5f, 0, -SQ3/2);
210
      Static3D axis3  = new Static3D(0.5f, 0, +SQ3/2);
211
      Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
212
      Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
213

  
214
      VertexEffectScale  effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) );
215
      VertexEffectRotate effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
216
      VertexEffectMove   effect3 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
217
      VertexEffectRotate effect4 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
218
      VertexEffectRotate effect5 = new VertexEffectRotate( angle, axis1, center1 );
219
      VertexEffectRotate effect6 = new VertexEffectRotate( angle, axis2, center2 );
220
      VertexEffectRotate effect7 = new VertexEffectRotate( angle, axis3, center2 );
221

  
222
      effect1.setMeshAssociation(15);  // apply to all 4 meshes
223
      effect2.setMeshAssociation(15);  // apply to all 4 meshes
224
      effect3.setMeshAssociation(15);  // apply to all 4 meshes
225
      effect4.setMeshAssociation(14);  // apply to mesh[1], [2] and [3]
226
      effect5.setMeshAssociation( 2);  // apply only to mesh[1]
227
      effect6.setMeshAssociation( 0);  // apply onlt to mesh[2]
228
      effect7.setMeshAssociation( 0);  // apply only to mesh[3]
229

  
230
      result.apply(effect1);
231
      result.apply(effect2);
232
      result.apply(effect3);
233
      result.apply(effect4);
234
      result.apply(effect5);
235
      result.apply(effect6);
236
      result.apply(effect7);
237

  
224 238
      return result;
225 239
      }
226 240
}

Also available in: Unified diff