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/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);

Also available in: Unified diff