Project

General

Profile

« Previous | Next » 

Revision a76cc4f4

Added by Leszek Koltunski almost 3 years ago

Progress with BandagedCreator.

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
38 38
   private final GLSurfaceView mView;
39 39
   private final DistortedScreen mScreen;
40 40
   private final Static3D mScale;
41
   private final Static3D[] mMove;
41 42

  
42 43
   private final float[][] POSITIONS = new float[][]
43 44
        {
......
87 88
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
88 89
     mScale= new Static3D(1,1,1);
89 90

  
90
     BandagedCubit cubit = new BandagedCubit(POSITIONS[0], mQuat1, mQuat2, mScale);
91
     DistortedNode node = cubit.getNode();
92
     mScreen.attach(node);
91
     int len = POSITIONS.length;
92
     mMove = new Static3D[len];
93

  
94
     for(int i=0; i<len; i++) mMove[i] = new Static3D(0,0,0);
95

  
96
     BandagedCubit[] cubits = createCubits();
93 97
     }
94 98

  
95 99
///////////////////////////////////////////////////////////////////////////////////////////////////
96
/*
100

  
97 101
   private BandagedCubit[] createCubits()
98 102
     {
99 103
     int len = POSITIONS.length;
......
101 105

  
102 106
     for(int c=0; c<len; c++)
103 107
       {
104
       cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,mScale);
108
       computeMove(mMove[c],POSITIONS[c]);
109
       cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,mMove[c],mScale);
105 110
       DistortedNode node = cubits[c].getNode();
106 111
       mScreen.attach(node);
107 112
       }
108 113

  
109 114
     return cubits;
110 115
     }
111
*/
116

  
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

  
119
    private void computeMove(Static3D move, float[] position)
120
      {
121
      int numCenters = position.length/3;
122
      float totalX=0.0f, totalY=0.0f, totalZ=0.0f;
123

  
124
      for(int center=0; center<numCenters; center++)
125
        {
126
        totalX += position[3*center  ];
127
        totalY += position[3*center+1];
128
        totalZ += position[3*center+2];
129
        }
130

  
131
      totalX /= numCenters;
132
      totalY /= numCenters;
133
      totalZ /= numCenters;
134

  
135
      move.set(totalX,totalY,totalZ);
136
      }
137

  
112 138
///////////////////////////////////////////////////////////////////////////////////////////////////
113 139

  
114 140
   @Override
......
123 149
   @Override
124 150
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
125 151
      {
126
      final float Q = 0.3f;
127
      final float scale = width<height ? Q*width : Q*height;
152
      final float Q = 0.15f;
153
      float scale = width<height ? Q*width : Q*height;
154

  
155
      int len = POSITIONS.length;
156

  
157
      for(int i=0; i<len; i++)
158
        {
159
        float x = mMove[i].get0();
160
        float y = mMove[i].get1();
161
        float z = mMove[i].get2();
162

  
163
        mMove[i].set(x*scale,y*scale,z*scale);
164
        }
128 165

  
129 166
      mScale.set( scale,scale,scale );
130 167
      mScreenMin = Math.min(width, height);
src/main/java/org/distorted/bandaged/BandagedCubit.java
42 42
    private final MeshBase mMesh;
43 43
    private final float[] mPosition;
44 44

  
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

  
47
    private Static3D computeMove(float[] position)
48
      {
49
      int numCenters = position.length/3;
50
      float totalX=0.0f, totalY=0.0f, totalZ=0.0f;
51

  
52
      for(int center=0; center<numCenters; center++)
53
        {
54
        totalX += position[3*center  ];
55
        totalY += position[3*center+1];
56
        totalZ += position[3*center+2];
57
        }
58

  
59
      totalX /= numCenters;
60
      totalY /= numCenters;
61
      totalZ /= numCenters;
62

  
63
      return new Static3D(totalX,totalY,totalZ);
64
      }
65

  
66 45
///////////////////////////////////////////////////////////////////////////////////////////////////
67 46
// PUBLIC API
68 47
///////////////////////////////////////////////////////////////////////////////////////////////////
69 48

  
70
    public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D scale)
49
    public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D move, Static3D scale)
71 50
      {
72 51
      mPosition = position;
73 52

  
......
77 56
      mTexture = new DistortedTexture();
78 57
      mTexture.setColorARGB(0xffffff55);
79 58

  
80
      Static3D move = computeMove(position);
81

  
82 59
      MatrixEffectScale scaleEffect = new MatrixEffectScale(scale);
83
      MatrixEffectQuaternion quat1Effect = new MatrixEffectQuaternion(quat2, CENTER);
84
      MatrixEffectQuaternion quat2Effect = new MatrixEffectQuaternion(quat1, CENTER);
60
      MatrixEffectQuaternion quat1Effect = new MatrixEffectQuaternion(quat1, CENTER);
61
      MatrixEffectQuaternion quat2Effect = new MatrixEffectQuaternion(quat2, CENTER);
85 62
      MatrixEffectMove moveEffect = new MatrixEffectMove(move);
86 63

  
87 64
      mEffects = new DistortedEffects();
88
      mEffects.apply(quat1Effect);
89
      mEffects.apply(quat2Effect);
90 65
      mEffects.apply(scaleEffect);
91 66
      mEffects.apply(moveEffect);
67
      mEffects.apply(quat2Effect);
68
      mEffects.apply(quat1Effect);
92 69

  
93 70
      mNode = new DistortedNode(mTexture,mEffects,mMesh);
94 71
      }

Also available in: Unified diff