Project

General

Profile

« Previous | Next » 

Revision c523e2ea

Added by Leszek Koltunski over 5 years ago

Improvements for the 'Rubik' app.

View differences:

src/main/java/org/distorted/examples/TableOfContents.java
409 409

  
410 410
   {
411 411
   final Map<String, Object> item = new HashMap<>();
412
   item.put(ITEM_IMAGE, R.drawable.icon_example_wip);
412
   item.put(ITEM_IMAGE, R.drawable.icon_example_rubik);
413 413
   item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_rubik));
414 414
   item.put(ITEM_SUBTITLE, getText(R.string.example_rubik_subtitle));
415 415
   data.add(item);
src/main/java/org/distorted/examples/rubik/RubikRenderer.java
20 20
package org.distorted.examples.rubik;
21 21

  
22 22
import android.graphics.Bitmap;
23
import android.graphics.BitmapFactory;
23
import android.graphics.Canvas;
24
import android.graphics.Paint;
24 25
import android.opengl.GLSurfaceView;
25 26

  
26
import org.distorted.examples.R;
27 27
import org.distorted.library.effect.MatrixEffectMove;
28 28
import org.distorted.library.effect.MatrixEffectQuaternion;
29 29
import org.distorted.library.effect.MatrixEffectScale;
30
import org.distorted.library.effect.VertexEffect;
31
import org.distorted.library.effect.VertexEffectDistort;
32 30
import org.distorted.library.main.Distorted;
33 31
import org.distorted.library.main.DistortedEffects;
34 32
import org.distorted.library.main.DistortedScreen;
35 33
import org.distorted.library.main.DistortedTexture;
36 34
import org.distorted.library.mesh.MeshCubes;
37
import org.distorted.library.mesh.MeshFlat;
38
import org.distorted.library.type.Dynamic3D;
39 35
import org.distorted.library.type.Static3D;
40 36
import org.distorted.library.type.Static4D;
41 37

  
42
import java.io.IOException;
43
import java.io.InputStream;
44

  
45 38
import javax.microedition.khronos.egl.EGLConfig;
46 39
import javax.microedition.khronos.opengles.GL10;
47 40

  
......
70 63
      mView = v;
71 64

  
72 65
      mScreen = new DistortedScreen();
66
   // mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
73 67

  
74 68
      mQuat1 = new Static4D(           0,         0,           0,          1);  // unity quaternion
75 69
      mQuat2 = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);  // something semi-random that looks good
......
87 81
      MatrixEffectQuaternion quat1 = new MatrixEffectQuaternion(mQuat1, mCenter);
88 82
      MatrixEffectQuaternion quat2 = new MatrixEffectQuaternion(mQuat2, mCenter);
89 83

  
84
      // 3x2 bitmap = 6 squares:
85
      //
86
      // RED     GREEN   BLUE
87
      // YELLOW  WHITE   BROWN
88

  
89
      final float ze = 0.0f;
90
      final float ot = 1.0f/3.0f;
91
      final float tt = 2.0f/3.0f;
92
      final float oh = 1.0f/2.0f;
93
      final float of = 1.0f/40.0f;
94

  
95
      final Static4D mapFront = new Static4D(ze,oh, ze+ot,oh+oh);
96
      final Static4D mapBack  = new Static4D(tt,ze, tt+ot,ze+oh);
97
      final Static4D mapLeft  = new Static4D(ot,ze, ot+ot,ze+oh);
98
      final Static4D mapRight = new Static4D(ze,ze, ze+ot,ze+oh);
99
      final Static4D mapTop   = new Static4D(tt,oh, tt+ot,oh+oh);
100
      final Static4D mapBottom= new Static4D(ot,oh, ot+ot,oh+oh);
101

  
102
      final Static4D mapBlack = new Static4D(ze,ze, ze+of,ze+of);
103

  
104
      Static4D tmpFront, tmpBack, tmpLeft, tmpRight, tmpTop, tmpBottom;
105

  
90 106
      for(int x=0; x<CUBE_SIZE; x++)
91 107
        for(int y=0; y<CUBE_SIZE; y++)
92 108
          for(int z=0; z<CUBE_SIZE; z++)
93 109
            {
94
            mCubes[x][y][z] = new MeshCubes(VERTICES,VERTICES,VERTICES);
110
            tmpLeft  = (x==          0 ? mapLeft  :mapBlack);
111
            tmpRight = (x==CUBE_SIZE-1 ? mapRight :mapBlack);
112
            tmpFront = (z==CUBE_SIZE-1 ? mapFront :mapBlack);
113
            tmpBack  = (z==          0 ? mapBack  :mapBlack);
114
            tmpTop   = (y==CUBE_SIZE-1 ? mapTop   :mapBlack);
115
            tmpBottom= (y==          0 ? mapBottom:mapBlack);
116

  
117
            mCubes[x][y][z] = new MeshCubes(VERTICES,VERTICES,VERTICES, tmpFront, tmpBack, tmpLeft, tmpRight, tmpTop, tmpBottom);
95 118

  
96 119
            cubeVectors[x][y][z] = new Static3D( SIZE*(x-0.5f*(CUBE_SIZE-1)), SIZE*(y-0.5f*(CUBE_SIZE-1)), SIZE*(z-0.5f*(CUBE_SIZE-1)) );
97 120

  
......
135 158
    
136 159
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
137 160
      {
138
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.monalisa);
139 161
      Bitmap bitmap;
140
        
141
      try 
142
        {
143
        bitmap = BitmapFactory.decodeStream(is);
144
        } 
145
      finally 
146
        {
147
        try 
148
          {
149
          is.close();
150
          } 
151
        catch(IOException e) { }
152
        }  
162

  
163
      final int S = 128;
164
      final int W = 3*S;
165
      final int H = 2*S;
166
      final int R = S/10;
167
      final int M = S/20;
168

  
169
      Paint paint = new Paint();
170
      bitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
171
      Canvas canvas = new Canvas(bitmap);
172

  
173
      paint.setAntiAlias(true);
174
      paint.setTextAlign(Paint.Align.CENTER);
175
      paint.setStyle(Paint.Style.FILL);
176

  
177
      // 3x2 bitmap = 6 squares:
178
      //
179
      // RED     GREEN   BLUE
180
      // YELLOW  WHITE   BROWN
181

  
182
      paint.setColor(0xff000000);                                  // BLACK BACKGROUND
183
      canvas.drawRect(0, 0, W, H, paint);                          //
184

  
185
      paint.setColor(0xffff0000);                                  // RED
186
      canvas.drawRoundRect(  0+M, 0+M,   S-M,   S-M, R, R, paint); //
187
      paint.setColor(0xff00ff00);                                  // GREEN
188
      canvas.drawRoundRect(  S+M, 0+M, 2*S-M,   S-M, R, R, paint); //
189
      paint.setColor(0xff0000ff);                                  // BLUE
190
      canvas.drawRoundRect(2*S+M, 0+M, 3*S-M,   S-M, R, R, paint); //
191
      paint.setColor(0xffffff00);                                  // YELLOW
192
      canvas.drawRoundRect(  0+M, S+M,   S-M, 2*S-M, R, R, paint); //
193
      paint.setColor(0xffffffff);                                  // WHITE
194
      canvas.drawRoundRect(  S+M, S+M, 2*S-M, 2*S-M, R, R, paint); //
195
      paint.setColor(0xffb5651d);                                  // BROWN
196
      canvas.drawRoundRect(2*S+M, S+M, 3*S-M, 2*S-M, R, R, paint); //
153 197

  
154 198
      if( mTexture==null ) mTexture = new DistortedTexture(SIZE,SIZE);
155 199
      mTexture.setTexture(bitmap);
src/main/java/org/distorted/examples/rubik/RubikSurfaceView.java
23 23
import android.content.Context;
24 24
import android.content.pm.ConfigurationInfo;
25 25
import android.opengl.GLSurfaceView;
26
import android.util.AttributeSet;
27 26
import android.view.MotionEvent;
28 27

  
29 28
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff