Project

General

Profile

« Previous | Next » 

Revision 44771819

Added by Leszek Koltunski almost 8 years ago

Further improve Olimpic. This seems to expose some Node bugs.

View differences:

src/main/java/org/distorted/examples/olimpic/OlimpicActivity.java
27 27
import android.os.Bundle;
28 28
import android.view.View;
29 29
import android.widget.Button;
30
import android.widget.CheckBox;
30 31
import android.widget.TextView;
31 32

  
32 33
///////////////////////////////////////////////////////////////////////////////////////////////////
......
46 47

  
47 48
  public void onClick(View view)
48 49
    {
49
    Button tmp = (Button)view;
50
    int id = tmp.getId();
50
    CheckBox box = (CheckBox)view;
51
    int id = box.getId();
52
    boolean checked = box.isChecked();
51 53
    OlimpicSurfaceView sView = (OlimpicSurfaceView) this.findViewById(R.id.olimpicSurfaceView);
52 54

  
53 55
    switch(id)
54 56
      {
55
      case R.id.olimpicCheckBoxBlue0  : sView.getRenderer().pressed(0,0); break;
56
      case R.id.olimpicCheckBoxBlue1  : sView.getRenderer().pressed(0,1); break;
57
      case R.id.olimpicCheckBoxBlue2  : sView.getRenderer().pressed(0,2); break;
58
      case R.id.olimpicCheckBoxBlue3  : sView.getRenderer().pressed(0,3); break;
59
      case R.id.olimpicCheckBoxBlue4  : sView.getRenderer().pressed(0,4); break;
60
      case R.id.olimpicCheckBoxBlue5  : sView.getRenderer().pressed(0,5); break;
61
      case R.id.olimpicCheckBoxBlue6  : sView.getRenderer().pressed(0,6); break;
62
      case R.id.olimpicCheckBoxBlue7  : sView.getRenderer().pressed(0,7); break;
63
      case R.id.olimpicCheckBoxBlue8  : sView.getRenderer().pressed(0,8); break;
64

  
65
      case R.id.olimpicCheckBoxBlack0 : sView.getRenderer().pressed(1,0); break;
66
      case R.id.olimpicCheckBoxBlack1 : sView.getRenderer().pressed(1,1); break;
67
      case R.id.olimpicCheckBoxBlack2 : sView.getRenderer().pressed(1,2); break;
68
      case R.id.olimpicCheckBoxBlack3 : sView.getRenderer().pressed(1,3); break;
69
      case R.id.olimpicCheckBoxBlack4 : sView.getRenderer().pressed(1,4); break;
70
      case R.id.olimpicCheckBoxBlack5 : sView.getRenderer().pressed(1,5); break;
71
      case R.id.olimpicCheckBoxBlack6 : sView.getRenderer().pressed(1,6); break;
72
      case R.id.olimpicCheckBoxBlack7 : sView.getRenderer().pressed(1,7); break;
73
      case R.id.olimpicCheckBoxBlack8 : sView.getRenderer().pressed(1,8); break;
74

  
75
      case R.id.olimpicCheckBoxRed0   : sView.getRenderer().pressed(2,0); break;
76
      case R.id.olimpicCheckBoxRed1   : sView.getRenderer().pressed(2,1); break;
77
      case R.id.olimpicCheckBoxRed2   : sView.getRenderer().pressed(2,2); break;
78
      case R.id.olimpicCheckBoxRed3   : sView.getRenderer().pressed(2,3); break;
79
      case R.id.olimpicCheckBoxRed4   : sView.getRenderer().pressed(2,4); break;
80
      case R.id.olimpicCheckBoxRed5   : sView.getRenderer().pressed(2,5); break;
81
      case R.id.olimpicCheckBoxRed6   : sView.getRenderer().pressed(2,6); break;
82
      case R.id.olimpicCheckBoxRed7   : sView.getRenderer().pressed(2,7); break;
83
      case R.id.olimpicCheckBoxRed8   : sView.getRenderer().pressed(2,8); break;
84

  
85
      case R.id.olimpicCheckBoxYellow0: sView.getRenderer().pressed(3,0); break;
86
      case R.id.olimpicCheckBoxYellow1: sView.getRenderer().pressed(3,1); break;
87
      case R.id.olimpicCheckBoxYellow2: sView.getRenderer().pressed(3,2); break;
88
      case R.id.olimpicCheckBoxYellow3: sView.getRenderer().pressed(3,3); break;
89
      case R.id.olimpicCheckBoxYellow4: sView.getRenderer().pressed(3,4); break;
90
      case R.id.olimpicCheckBoxYellow5: sView.getRenderer().pressed(3,5); break;
91
      case R.id.olimpicCheckBoxYellow6: sView.getRenderer().pressed(3,6); break;
92
      case R.id.olimpicCheckBoxYellow7: sView.getRenderer().pressed(3,7); break;
93
      case R.id.olimpicCheckBoxYellow8: sView.getRenderer().pressed(3,8); break;
94

  
95
      case R.id.olimpicCheckBoxGreen0 : sView.getRenderer().pressed(4,0); break;
96
      case R.id.olimpicCheckBoxGreen1 : sView.getRenderer().pressed(4,1); break;
97
      case R.id.olimpicCheckBoxGreen2 : sView.getRenderer().pressed(4,2); break;
98
      case R.id.olimpicCheckBoxGreen3 : sView.getRenderer().pressed(4,3); break;
99
      case R.id.olimpicCheckBoxGreen4 : sView.getRenderer().pressed(4,4); break;
100
      case R.id.olimpicCheckBoxGreen5 : sView.getRenderer().pressed(4,5); break;
101
      case R.id.olimpicCheckBoxGreen6 : sView.getRenderer().pressed(4,6); break;
102
      case R.id.olimpicCheckBoxGreen7 : sView.getRenderer().pressed(4,7); break;
103
      case R.id.olimpicCheckBoxGreen8 : sView.getRenderer().pressed(4,8); break;
57
      case R.id.olimpicCheckBoxBlue0  : sView.getRenderer().pressed(0,0,checked); break;
58
      case R.id.olimpicCheckBoxBlue1  : sView.getRenderer().pressed(0,1,checked); break;
59
      case R.id.olimpicCheckBoxBlue2  : sView.getRenderer().pressed(0,2,checked); break;
60
      case R.id.olimpicCheckBoxBlue3  : sView.getRenderer().pressed(0,3,checked); break;
61
      case R.id.olimpicCheckBoxBlue4  : sView.getRenderer().pressed(0,4,checked); break;
62
      case R.id.olimpicCheckBoxBlue5  : sView.getRenderer().pressed(0,5,checked); break;
63
      case R.id.olimpicCheckBoxBlue6  : sView.getRenderer().pressed(0,6,checked); break;
64
      case R.id.olimpicCheckBoxBlue7  : sView.getRenderer().pressed(0,7,checked); break;
65
      case R.id.olimpicCheckBoxBlue8  : sView.getRenderer().pressed(0,8,checked); break;
66

  
67
      case R.id.olimpicCheckBoxBlack0 : sView.getRenderer().pressed(1,0,checked); break;
68
      case R.id.olimpicCheckBoxBlack1 : sView.getRenderer().pressed(1,1,checked); break;
69
      case R.id.olimpicCheckBoxBlack2 : sView.getRenderer().pressed(1,2,checked); break;
70
      case R.id.olimpicCheckBoxBlack3 : sView.getRenderer().pressed(1,3,checked); break;
71
      case R.id.olimpicCheckBoxBlack4 : sView.getRenderer().pressed(1,4,checked); break;
72
      case R.id.olimpicCheckBoxBlack5 : sView.getRenderer().pressed(1,5,checked); break;
73
      case R.id.olimpicCheckBoxBlack6 : sView.getRenderer().pressed(1,6,checked); break;
74
      case R.id.olimpicCheckBoxBlack7 : sView.getRenderer().pressed(1,7,checked); break;
75
      case R.id.olimpicCheckBoxBlack8 : sView.getRenderer().pressed(1,8,checked); break;
76

  
77
      case R.id.olimpicCheckBoxRed0   : sView.getRenderer().pressed(2,0,checked); break;
78
      case R.id.olimpicCheckBoxRed1   : sView.getRenderer().pressed(2,1,checked); break;
79
      case R.id.olimpicCheckBoxRed2   : sView.getRenderer().pressed(2,2,checked); break;
80
      case R.id.olimpicCheckBoxRed3   : sView.getRenderer().pressed(2,3,checked); break;
81
      case R.id.olimpicCheckBoxRed4   : sView.getRenderer().pressed(2,4,checked); break;
82
      case R.id.olimpicCheckBoxRed5   : sView.getRenderer().pressed(2,5,checked); break;
83
      case R.id.olimpicCheckBoxRed6   : sView.getRenderer().pressed(2,6,checked); break;
84
      case R.id.olimpicCheckBoxRed7   : sView.getRenderer().pressed(2,7,checked); break;
85
      case R.id.olimpicCheckBoxRed8   : sView.getRenderer().pressed(2,8,checked); break;
86

  
87
      case R.id.olimpicCheckBoxYellow0: sView.getRenderer().pressed(3,0,checked); break;
88
      case R.id.olimpicCheckBoxYellow1: sView.getRenderer().pressed(3,1,checked); break;
89
      case R.id.olimpicCheckBoxYellow2: sView.getRenderer().pressed(3,2,checked); break;
90
      case R.id.olimpicCheckBoxYellow3: sView.getRenderer().pressed(3,3,checked); break;
91
      case R.id.olimpicCheckBoxYellow4: sView.getRenderer().pressed(3,4,checked); break;
92
      case R.id.olimpicCheckBoxYellow5: sView.getRenderer().pressed(3,5,checked); break;
93
      case R.id.olimpicCheckBoxYellow6: sView.getRenderer().pressed(3,6,checked); break;
94
      case R.id.olimpicCheckBoxYellow7: sView.getRenderer().pressed(3,7,checked); break;
95
      case R.id.olimpicCheckBoxYellow8: sView.getRenderer().pressed(3,8,checked); break;
96

  
97
      case R.id.olimpicCheckBoxGreen0 : sView.getRenderer().pressed(4,0,checked); break;
98
      case R.id.olimpicCheckBoxGreen1 : sView.getRenderer().pressed(4,1,checked); break;
99
      case R.id.olimpicCheckBoxGreen2 : sView.getRenderer().pressed(4,2,checked); break;
100
      case R.id.olimpicCheckBoxGreen3 : sView.getRenderer().pressed(4,3,checked); break;
101
      case R.id.olimpicCheckBoxGreen4 : sView.getRenderer().pressed(4,4,checked); break;
102
      case R.id.olimpicCheckBoxGreen5 : sView.getRenderer().pressed(4,5,checked); break;
103
      case R.id.olimpicCheckBoxGreen6 : sView.getRenderer().pressed(4,6,checked); break;
104
      case R.id.olimpicCheckBoxGreen7 : sView.getRenderer().pressed(4,7,checked); break;
105
      case R.id.olimpicCheckBoxGreen8 : sView.getRenderer().pressed(4,8,checked); break;
104 106
      }
105 107
    }
106 108

  
src/main/java/org/distorted/examples/olimpic/OlimpicRenderer.java
38 38
import org.distorted.library.Distorted;
39 39
import org.distorted.library.DistortedTexture;
40 40

  
41
import android.content.Context;
42 41
import android.graphics.Bitmap;
43 42
import android.graphics.BitmapFactory;
44 43
import android.opengl.GLES30;
......
56 55
   private DistortedNode mRoot;
57 56
   private DistortedTexture mLeaf;
58 57
   private DistortedScreen mScreen;
58
   private MeshFlat mMesh;
59 59
   private int mScreenW, mScreenH;
60 60
   private int mPrevRendered, mCurrRendered;
61 61

  
62
   private DistortedNode[] mCircleNode = new DistortedNode[NUM_CIRCLES];
63
   private DistortedEffects[] mEffects = new DistortedEffects[NUM_LEAVES];
64

  
62 65
///////////////////////////////////////////////////////////////////////////////////////////////////
63 66

  
64
   void pressed(int color, int number)
67
   void pressed(int color, int number, boolean checked)
65 68
     {
66
     android.util.Log.d("Olimpic","Color: "+color+" number:"+number+" pressed!");
69
     android.util.Log.d("Olimpic","Color: "+color+" number:"+number+" checked: "+checked);
70

  
71
     if( color>=0 && color<NUM_CIRCLES )
72
       {
73
       if( number==0 )
74
         {
75
         if( checked ) mRoot.attach(mCircleNode[color]);
76
         else          mRoot.detach(mCircleNode[color]);
77
         }
78
       else if( number>0 && number<=NUM_LEAVES )
79
         {
80
         if( checked ) mCircleNode[color].attach( mLeaf, mEffects[number-1], mMesh);
81
         else          mCircleNode[color].detach(mEffects[number-1]);
82
         }
83
       }
67 84
     }
68 85

  
69 86
///////////////////////////////////////////////////////////////////////////////////////////////////
......
76 93
      mCurrRendered = 0;
77 94

  
78 95
      mLeaf = new DistortedTexture(LEAF_SIZE,LEAF_SIZE);
79
      MeshFlat mesh = new MeshFlat(1,1);
96
      DistortedTexture surface = new DistortedTexture(3*LEAF_SIZE,3*LEAF_SIZE);
97
      mMesh = new MeshFlat(1,1);
80 98
      DistortedEffects effects = new DistortedEffects();
81 99

  
82 100
      mScreenW = 9*LEAF_SIZE;
83 101
      mScreenH = 9*LEAF_SIZE;
84
      mRoot = new DistortedNode(new DistortedTexture(mScreenW,mScreenH), effects, mesh);
102
      mRoot = new DistortedNode(new DistortedTexture(mScreenW,mScreenH), effects, mMesh);
85 103
     
86 104
      Dynamic1D rot = new Dynamic1D(5000,0.0f);
87 105
      rot.setMode(Dynamic1D.MODE_JUMP);
88 106
      rot.add(new Static1D(  0));
89 107
      rot.add(new Static1D(360));
90
      
91
      DistortedNode[] mCircleNode = new DistortedNode[NUM_CIRCLES];
92
    
108

  
93 109
      int[] colors    = new int[] {0,0,1,  0,0,0,  1,0,0,  1,1,0,  0,1,0}; // blue, black, red, yellow, green  
94 110
      int[] positions = new int[] {0,2*LEAF_SIZE,  3*LEAF_SIZE,2*LEAF_SIZE,  6*LEAF_SIZE,2*LEAF_SIZE,  3*LEAF_SIZE/2,9*LEAF_SIZE/2,  9*LEAF_SIZE/2,9*LEAF_SIZE/2};
95 111
      
......
97 113
      Static3D axis   = new Static3D(0,0,1);
98 114
      Static3D moveVector = new Static3D(0,LEAF_SIZE,0);
99 115

  
100
      for(int i=0; i<NUM_CIRCLES; i++)
116
      for(int j=0; j<NUM_LEAVES; j++)
101 117
        {
102
        if( i<=1 )
103
          {
104
          effects = new DistortedEffects();
105
          mCircleNode[i] = new DistortedNode(new DistortedTexture(3*LEAF_SIZE,3*LEAF_SIZE), effects, mesh);
106
        
107
          for(int j=0; j<NUM_LEAVES-i; j++)
108
            {
109
            effects = new DistortedEffects();
110
            mCircleNode[i].attach(mLeaf, effects, mesh);
111
            effects.rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
112
            effects.move(moveVector);
113
            }
114
          }
115
        else
116
          {
117
          mCircleNode[i] = new DistortedNode(mCircleNode[0], Distorted.CLONE_SURFACE |Distorted.CLONE_CHILDREN);
118
          }
118
        mEffects[j] = new DistortedEffects();
119
        mEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
120
        mEffects[j].move(moveVector);
121
        }
119 122

  
120
        mRoot.attach(mCircleNode[i]);
121
        effects = mCircleNode[i].getEffects();
123
      for(int i=0; i<NUM_CIRCLES; i++)
124
        {
125
        effects = new DistortedEffects();
122 126
        effects.move( new Static3D(positions[2*i], positions[2*i+1], 0) );
123 127
        effects.rotate( rot, axis, center );
124 128
        effects.chroma( new Static1D(0.5f), new Static3D(colors[3*i],colors[3*i+1], colors[3*i+2]) );
129

  
130
        mCircleNode[i] = new DistortedNode( surface, effects, mMesh);
131
        mRoot.attach(mCircleNode[i]);
132

  
133
        for(int j=0; j<NUM_LEAVES; j++) mCircleNode[i].attach(mLeaf, mEffects[j], mMesh);
125 134
        }
126 135

  
127 136
      mScreen = new DistortedScreen();

Also available in: Unified diff