Project

General

Profile

« Previous | Next » 

Revision 14bd7976

Added by Leszek Koltunski almost 4 years ago

1) Cube: convert it to the latest library. Main difference: objects are rendered better, individual cubits have rounded corners.
2) Examples: some adjustments to MeshJoin & Predeform
3) Library: fix a bug in main_vertex_shader's 'degree' function, which didn't work proprely in case of a vertex which was exactly at the center (i.e. vector PS was zero)

View differences:

src/main/java/org/distorted/main/RubikRenderer.java
24 24

  
25 25
import org.distorted.effects.BaseEffect;
26 26
import org.distorted.library.effect.EffectType;
27
import org.distorted.library.effect.VertexEffectSink;
28 27
import org.distorted.library.main.DistortedLibrary;
29 28
import org.distorted.library.main.DistortedScreen;
30 29

  
......
44 43

  
45 44
   RubikRenderer(RubikSurfaceView v)
46 45
     {
46
     final float BRIGHTNESS = 0.1f;
47

  
47 48
     mView = v;
48 49
     mScreen = new DistortedScreen();
50
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
51

  
52
     mScreen.showFPS();
49 53
     }
50 54

  
51 55
///////////////////////////////////////////////////////////////////////////////////////////////////
......
74 78
   @Override
75 79
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
76 80
      {
77
      DistortedLibrary.setMax(EffectType.VERTEX,12);
78
      VertexEffectSink.enable();
81
      DistortedLibrary.setMax(EffectType.VERTEX,15);
79 82
      BaseEffect.Type.enableEffects();
80 83

  
81 84
      try
src/main/java/org/distorted/objects/Cubit.java
187 187
    computeRotationRow();
188 188

  
189 189
    mEffect = new DistortedEffects();
190
    mEffect.apply(mParent.mSinkEffect);
191 190
    mEffect.apply( new MatrixEffectMove(vector) );
192 191
    mEffect.apply( new MatrixEffectQuaternion(mQuatScramble, matrCenter));
193 192
    mEffect.apply(mRotateEffect);
src/main/java/org/distorted/objects/RubikCube.java
22 22
import android.graphics.Canvas;
23 23
import android.graphics.Paint;
24 24

  
25
import org.distorted.library.effect.VertexEffectDeform;
25 26
import org.distorted.library.effect.VertexEffectMove;
26 27
import org.distorted.library.effect.VertexEffectRotate;
27 28
import org.distorted.library.effect.VertexEffectSink;
......
141 142

  
142 143
///////////////////////////////////////////////////////////////////////////////////////////////////
143 144

  
144
  VertexEffectSink getSink(int size)
145
    {
146
    Static3D center = new Static3D(0,0,0);
147
    Static4D region = new Static4D(0,0,0,0.72f);
148
    float strength;
149

  
150
    switch(size)
151
      {
152
      case 1 : strength= 1.1f; break;
153
      case 2 : strength= 1.5f; break;
154
      case 3 : strength= 1.8f; break;
155
      case 4 : strength= 2.0f; break;
156
      default: strength= 3.0f - 4.0f/size;
157
      }
158

  
159
    return new VertexEffectSink( new Static1D(strength), center, region );
160
    }
161

  
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

  
164
  MeshBase createCubitMesh(int cubit, int vertices)
145
  MeshBase createCubitMesh(int cubit)
165 146
    {
166 147
    if( mMesh==null )
167 148
      {
168 149
      final int MESHES=6;
169 150
      int association = 1;
170 151
      MeshBase[] meshes = new MeshRectangles[MESHES];
171
      meshes[0] = new MeshRectangles(vertices,vertices);
152
      meshes[0] = new MeshRectangles(14,14);
172 153
      meshes[0].setEffectAssociation(0,association);
173 154

  
174 155
      for(int i=1; i<MESHES; i++)
......
187 168
      Static1D angle180= new Static1D(180);
188 169
      Static1D angle270= new Static1D(270);
189 170

  
171
      float d1 = 1.0f;
172
      float d2 =-0.05f;
173
      float d3 = 0.12f;
174

  
175
      Static3D dCen0 = new Static3D( d1*(+0.5f), d1*(+0.5f), d1*(+0.5f) );
176
      Static3D dCen1 = new Static3D( d1*(+0.5f), d1*(+0.5f), d1*(-0.5f) );
177
      Static3D dCen2 = new Static3D( d1*(+0.5f), d1*(-0.5f), d1*(+0.5f) );
178
      Static3D dCen3 = new Static3D( d1*(+0.5f), d1*(-0.5f), d1*(-0.5f) );
179
      Static3D dCen4 = new Static3D( d1*(-0.5f), d1*(+0.5f), d1*(+0.5f) );
180
      Static3D dCen5 = new Static3D( d1*(-0.5f), d1*(+0.5f), d1*(-0.5f) );
181
      Static3D dCen6 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*(+0.5f) );
182
      Static3D dCen7 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*(-0.5f) );
183

  
184
      Static3D dVec0 = new Static3D( d2*(+0.5f), d2*(+0.5f), d2*(+0.5f) );
185
      Static3D dVec1 = new Static3D( d2*(+0.5f), d2*(+0.5f), d2*(-0.5f) );
186
      Static3D dVec2 = new Static3D( d2*(+0.5f), d2*(-0.5f), d2*(+0.5f) );
187
      Static3D dVec3 = new Static3D( d2*(+0.5f), d2*(-0.5f), d2*(-0.5f) );
188
      Static3D dVec4 = new Static3D( d2*(-0.5f), d2*(+0.5f), d2*(+0.5f) );
189
      Static3D dVec5 = new Static3D( d2*(-0.5f), d2*(+0.5f), d2*(-0.5f) );
190
      Static3D dVec6 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*(+0.5f) );
191
      Static3D dVec7 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*(-0.5f) );
192

  
193
      Static4D dReg  = new Static4D(0,0,0,d3);
194
      Static1D dRad  = new Static1D(1);
195

  
190 196
      VertexEffectMove   effect0 = new VertexEffectMove(new Static3D(0,0,+0.5f));
191 197
      effect0.setMeshAssociation(63);  // all 6 sides
192 198
      VertexEffectRotate effect1 = new VertexEffectRotate( angle180, axisX, center );
......
200 206
      VertexEffectRotate effect5 = new VertexEffectRotate( angle90 , axisY, center );
201 207
      effect5.setMeshAssociation(1);  // right
202 208

  
209
      VertexEffectDeform effect6 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
210
      VertexEffectDeform effect7 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
211
      VertexEffectDeform effect8 = new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
212
      VertexEffectDeform effect9 = new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
213
      VertexEffectDeform effect10= new VertexEffectDeform(dVec4, dRad, dCen4, dReg);
214
      VertexEffectDeform effect11= new VertexEffectDeform(dVec5, dRad, dCen5, dReg);
215
      VertexEffectDeform effect12= new VertexEffectDeform(dVec6, dRad, dCen6, dReg);
216
      VertexEffectDeform effect13= new VertexEffectDeform(dVec7, dRad, dCen7, dReg);
217

  
218
      VertexEffectSink   effect14= new VertexEffectSink( new Static1D(1.5f), center, new Static4D(0,0,0,0.72f) );
219

  
203 220
      mMesh.apply(effect0);
204 221
      mMesh.apply(effect1);
205 222
      mMesh.apply(effect2);
206 223
      mMesh.apply(effect3);
207 224
      mMesh.apply(effect4);
208 225
      mMesh.apply(effect5);
226
      mMesh.apply(effect6);
227
      mMesh.apply(effect7);
228
      mMesh.apply(effect8);
229
      mMesh.apply(effect9);
230
      mMesh.apply(effect10);
231
      mMesh.apply(effect11);
232
      mMesh.apply(effect12);
233
      mMesh.apply(effect13);
234
      mMesh.apply(effect14);
209 235
      }
210 236

  
211 237
    return mMesh.copy(false);
src/main/java/org/distorted/objects/RubikObject.java
27 27
import org.distorted.library.effect.Effect;
28 28
import org.distorted.library.effect.MatrixEffectQuaternion;
29 29
import org.distorted.library.effect.MatrixEffectScale;
30
import org.distorted.library.effect.VertexEffectSink;
31 30
import org.distorted.library.main.DistortedEffects;
32 31
import org.distorted.library.main.DistortedNode;
33 32
import org.distorted.library.main.DistortedTexture;
......
42 41

  
43 42
public abstract class RubikObject extends DistortedNode
44 43
  {
44
  static final int INTERIOR_COLOR = 0xff000000;
45 45
  public static final int NODE_FBO_SIZE = 600;
46 46

  
47 47
  private static final int TEXTURE_HEIGHT = 128;
......
65 65
  Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
66 66
  DistortedTexture mTexture;
67 67

  
68
  VertexEffectSink mSinkEffect;
69 68
  MatrixEffectScale mScaleEffect;
70 69
  MatrixEffectQuaternion mQuatCEffect;
71 70
  MatrixEffectQuaternion mQuatAEffect;
......
91 90
    computeStartAndStep(mOrigPos);
92 91
    mNodeScale= new Static3D(1,1,1);
93 92
    mQuatAccumulated = quatAcc;
94
    mSinkEffect  = getSink(mSize);
95 93

  
96 94
    mRotationAngleStatic = new Static1D(0);
97 95
    mRotationAngleMiddle = new Static1D(0);
......
109 107
    mCubits = new Cubit[NUM_CUBITS];
110 108
    mTexture = new DistortedTexture();
111 109

  
112
    int vertices = (int)(24.0f/mSize + 2.0f);
113

  
114 110
    for(int i=0; i<NUM_CUBITS; i++)
115 111
      {
116
      MeshBase cubitMesh = createCubitMesh(i,vertices);
112
      MeshBase cubitMesh = createCubitMesh(i);
117 113
      mCubits[i] = new Cubit(this,cubitMesh,mOrigPos[i]);
118 114
      textureCubitMesh(cubitMesh,i);
119 115

  
......
300 296
    paint.setTextAlign(Paint.Align.CENTER);
301 297
    paint.setStyle(Paint.Style.FILL);
302 298

  
303
    paint.setColor(0xff000000);
299
    paint.setColor(INTERIOR_COLOR);
304 300
    canvas.drawRect(0, 0, (numColors+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, paint);
305 301

  
306 302
    for(int i=0; i<numColors; i++)
......
596 592
///////////////////////////////////////////////////////////////////////////////////////////////////
597 593

  
598 594
  abstract float getScreenRatio();
599
  abstract VertexEffectSink getSink(int size);
600 595
  abstract Static3D[] getCubitPositions(int size);
601 596
  abstract float[] getLegalQuats();
602 597
  abstract int getNumFaces();
603
  abstract MeshBase createCubitMesh(int cubit, int vertices);
598
  abstract MeshBase createCubitMesh(int cubit);
604 599
  abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side);
605 600
  public abstract Static3D[] getRotationAxis();
606 601
  public abstract int getBasicAngle();
src/main/java/org/distorted/objects/RubikPyraminx.java
205 205

  
206 206
///////////////////////////////////////////////////////////////////////////////////////////////////
207 207

  
208
  VertexEffectSink getSink(int size)
209
    {
210
    Static3D center = new Static3D(0,0,0);
211
    Static4D region = new Static4D(0,0,0,0.6f);
212
    return new VertexEffectSink( new Static1D(1.3f), center, region );
213
    }
214

  
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

  
217
  private MeshBase createStaticMesh(int cubit, int vertices)
208
  private MeshBase createStaticMesh(int cubit)
218 209
    {
219 210
    final float SQ2 = (float)Math.sqrt(2);
220 211
    final float SQ3 = (float)Math.sqrt(3);
......
269 260
    Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
270 261
    Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
271 262

  
263
    Static3D center = new Static3D(0,0,0);
264
    Static4D region = new Static4D(0,0,0,0.6f);
265

  
272 266
    VertexEffectScale effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) );
273 267
    VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
274 268
    VertexEffectMove effect3 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
......
282 276
    VertexEffectDeform effect10= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
283 277
    VertexEffectDeform effect11= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
284 278

  
285
    effect1.setMeshAssociation(15);  // apply to all 4 meshes
286
    effect2.setMeshAssociation(15);  // apply to all 4 meshes
287
    effect3.setMeshAssociation(15);  // apply to all 4 meshes
279
    VertexEffectSink   effect12= new VertexEffectSink( new Static1D(1.3f), center, region );
280

  
288 281
    effect4.setMeshAssociation(14);  // apply to mesh[1], [2] and [3]
289 282
    effect5.setMeshAssociation( 2);  // apply only to mesh[1]
290 283
    effect6.setMeshAssociation( 4);  // apply only to mesh[2]
291 284
    effect7.setMeshAssociation( 8);  // apply only to mesh[3]
292
    effect8.setMeshAssociation(15);  // apply to all 4 meshes
293
    effect9.setMeshAssociation(15);  // apply to all 4 meshes
294
    effect10.setMeshAssociation(15); // apply to all 4 meshes
295
    effect11.setMeshAssociation(15); // apply to all 4 meshes
296 285

  
297 286
    result.apply(effect1);
298 287
    result.apply(effect2);
......
305 294
    result.apply(effect9);
306 295
    result.apply(effect10);
307 296
    result.apply(effect11);
297
    result.apply(effect12);
308 298

  
309 299
    if( mRotArray[cubit]>=0 )
310 300
      {
......
316 306

  
317 307
///////////////////////////////////////////////////////////////////////////////////////////////////
318 308

  
319
  MeshBase createCubitMesh(int cubit, int vertices)
309
  MeshBase createCubitMesh(int cubit)
320 310
    {
321 311
    int kind = mRotArray[cubit];
322 312

  
323 313
    if( kind>=0 )
324 314
      {
325
      if( mMeshRotated[kind]==null ) mMeshRotated[kind] = createStaticMesh(cubit,vertices);
315
      if( mMeshRotated[kind]==null ) mMeshRotated[kind] = createStaticMesh(cubit);
326 316
      return mMeshRotated[kind].copy(false);
327 317
      }
328 318
    else
329 319
      {
330
      if( mMesh==null ) mMesh = createStaticMesh(cubit,vertices);
320
      if( mMesh==null ) mMesh = createStaticMesh(cubit);
331 321
      return mMesh.copy(false);
332 322
      }
333 323
    }
......
354 344

  
355 345
    canvas.drawRect(left,top,left+side,top+side,paint);
356 346

  
357
    paint.setColor(0xff000000);
347
    paint.setColor(INTERIOR_COLOR);
358 348
    paint.setStyle(Paint.Style.STROKE);
359 349

  
360 350
    canvas.drawLine(           left, HEIGHT,  side       +left, HEIGHT, paint);

Also available in: Unified diff