Project

General

Profile

« Previous | Next » 

Revision 6c295be1

Added by Leszek Koltunski over 1 year ago

Progress with BandagedObjectPyraminx.

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorTouchControl.java
23 23
  private final float[] mPoint2D;
24 24
  private float mObjectRatio;
25 25
  private final Static3D[] mFaceAxis;
26
  private final int mNumFaces;
26 27

  
27 28
  private float[] mDist3D;
28 29
  private int mLastTouchedFace;
......
127 128
    mCamera[1] = rotatedCamera.get1()/mObjectRatio;
128 129
    mCamera[2] = rotatedCamera.get2()/mObjectRatio;
129 130

  
130
    for( mLastTouchedFace=0; mLastTouchedFace<6; mLastTouchedFace++)
131
    for( mLastTouchedFace=0; mLastTouchedFace<mNumFaces; mLastTouchedFace++)
131 132
      {
132 133
      if( faceIsVisible(mLastTouchedFace) )
133 134
        {
......
160 161
    mDist3D  = new float[6];
161 162
    mFaceAxis = mObject.getFaceAxis();
162 163
    mObjectRatio = ratio;
164
    mNumFaces = mFaceAxis.length;
163 165

  
164 166
    double halfFOV = fov * (Math.PI/360);
165 167
    float tanHalf = (float)Math.tan(halfFOV);
src/main/java/org/distorted/bandaged/BandagedCubit.java
43 43
    private final DistortedEffects mEffects;
44 44
    private final DistortedTexture mTexture;
45 45
    private final Static3D mMove;
46
    private final int mVariant;
46 47
    private final boolean mRoundCorners;
47 48

  
48 49
    private float mUnscaledX, mUnscaledY, mUnscaledZ;
......
116 117
// PUBLIC API
117 118
///////////////////////////////////////////////////////////////////////////////////////////////////
118 119

  
119
    public BandagedCubit(BandagedObject object, float[] position, Static4D quat1,
120
    public BandagedCubit(BandagedObject object, float[] position, int variant, Static4D quat1,
120 121
                         Static4D quat2, Static3D scale, boolean roundCorners)
121 122
      {
122 123
      mObject = object;
......
124 125
      mPosition = position;
125 126
      mIsAttached = true;
126 127
      mMarkedEffectID = -1;
128
      mVariant = variant;
127 129

  
128 130
      computeMove(mPosition);
129 131
      mMove = new Static3D(0,0,0);
130
      MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners);
132
      MeshBase mesh = mObject.createMesh(mVariant,mPosition,mRoundCorners);
131 133

  
132 134
      mTexture = new DistortedTexture();
133 135
      if( mBitmap==null ) createBitmap(mObject.getColors());
......
155 157
      {
156 158
      int len1 = mPosition.length;
157 159
      int len2 = position.length;
158

  
159 160
      float[] tmpPosition = new float[len1+len2];
160

  
161 161
      System.arraycopy(mPosition, 0, tmpPosition,    0, len1);
162 162
      System.arraycopy(position , 0, tmpPosition, len1, len2);
163

  
164
      computeMove(tmpPosition);
165 163
      mPosition = tmpPosition;
166
      MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners);
164

  
165
      computeMove(mPosition);
166
      MeshBase mesh = mObject.createMesh(mVariant,mPosition,mRoundCorners);
167 167
      resetTextureMaps(mesh);
168 168
      mNode.setMesh(mesh);
169 169
      mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
......
183 183
      mPosition[2] = z;
184 184

  
185 185
      computeMove(mPosition);
186
      MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners);
186
      MeshBase mesh = mObject.createMesh(mVariant,mPosition,mRoundCorners);
187 187
      resetTextureMaps(mesh);
188 188
      mNode.setMesh(mesh);
189 189
      mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
src/main/java/org/distorted/bandaged/BandagedObject.java
51 51
   abstract float[] getDist3D();
52 52
   abstract int[] getColors();
53 53
   abstract Static3D[] getFaceAxis();
54
   abstract float[][] getPositions();
54
   abstract float[][][] getPositions();
55 55
   abstract boolean isAdjacent(float dx, float dy, float dz);
56 56
   abstract int computeProjectionAngle();
57 57
   abstract boolean tryChangeObject(int x, int y, int z);
58 58
   abstract void getTouchedPosition(float[] output, int face, float pointX, float pointY);
59 59
   abstract boolean isInsideFace(int face, float[] p);
60 60
   abstract TwistyObject createObject(int mode, float scale );
61
   abstract MeshBase createMesh(float[] pos, boolean round);
61
   abstract MeshBase createMesh(int variant, float[] pos, boolean round);
62 62

  
63 63
///////////////////////////////////////////////////////////////////////////////////////////////////
64 64

  
......
72 72
   void createCubits(Static4D quatT, Static4D quatA, Static3D scale)
73 73
     {
74 74
     mCubits = new BandagedCubit[mNumCubits];
75
     int c=0;
76
     for(float[] p : getPositions() ) mCubits[c++] = new BandagedCubit(this,p,quatT,quatA,scale,false);
75
     float[][][] pos = getPositions();
76
     int c=0,numVariants = pos.length;
77

  
78
     for(int v=0; v<numVariants; v++)
79
       {
80
       int numCubits = pos[v].length;
81

  
82
       for(int vi=0; vi<numCubits; vi++)
83
         mCubits[c++] = new BandagedCubit(this,pos[v][vi],v,quatT,quatA,scale,false);
84
       }
77 85
     }
78 86

  
79 87
///////////////////////////////////////////////////////////////////////////////////////////////////
......
247 255
        int len = pos.length/3;
248 256

  
249 257
        for(int p=0; p<len; p++)
250
          if( pos[3*p]==mTmp[0] && pos[3*p+1]==mTmp[1] && pos[3*p+2]==mTmp[2] ) return c;
258
          {
259
          float dx = pos[3*p  ]-mTmp[0];
260
          float dy = pos[3*p+1]-mTmp[1];
261
          float dz = pos[3*p+2]-mTmp[2];
262

  
263
          if( dx*dx + dy*dy + dz*dz < 0.01f ) return c;
264
          }
251 265
        }
252 266

  
253 267
    android.util.Log.e("D", "whichCubitTouched: IMPOSSIBLE!!");
src/main/java/org/distorted/bandaged/BandagedObjectCuboid.java
71 71

  
72 72
///////////////////////////////////////////////////////////////////////////////////////////////////
73 73

  
74
  float[][] getPositions()
74
  float[][][] getPositions()
75 75
    {
76
    float[][] pos = new float[mNumCubits][];
76
    float[][][] pos = new float[1][mNumCubits][];
77 77
    int c=0;
78 78
    int sx = mSize[0];
79 79
    int sy = mSize[1];
......
88 88
         for(int z=0; z<sz; z++)
89 89
           if( x==0 || x==sx-1 || y==0 || y==sy-1 || z==0 || z==sz-1 )
90 90
              {
91
              pos[c++] = new float[] { begX+x,begY+y,begZ+z };
91
              pos[0][c++] = new float[] { begX+x,begY+y,begZ+z };
92 92
              }
93 93

  
94 94
    return pos;
......
185 185

  
186 186
///////////////////////////////////////////////////////////////////////////////////////////////////
187 187

  
188
  MeshBase createMesh(float[] pos, boolean round)
188
  MeshBase createMesh(int variant, float[] pos, boolean round)
189 189
     {
190 190
     FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
191 191
     return factory.createMesh(pos,mSize[0],mSize[1],mSize[2],false,round);
src/main/java/org/distorted/bandaged/BandagedObjectPyraminx.java
9 9

  
10 10
package org.distorted.bandaged;
11 11

  
12
import static org.distorted.objectlib.main.TwistyObject.SQ2;
12 13
import static org.distorted.objectlib.main.TwistyObject.SQ3;
13 14
import static org.distorted.objectlib.main.TwistyObject.SQ6;
14 15

  
......
31 32
     super(screen);
32 33
     }
33 34

  
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

  
37
  private boolean isFaceInverted(int face)
38
    {
39
    return face>1;
40
    }
41

  
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

  
44
  private void addTetrahedralLattice(int size, float[][] pos)
45
    {
46
    final float DX = 1.0f;
47
    final float DY = SQ2/2;
48
    final float DZ = 1.0f;
49

  
50
    float startX = 0.0f;
51
    float startY =-DY*(size-1)/2;
52
    float startZ = DZ*(size-1)/2;
53

  
54
    int index = 0;
55

  
56
    for(int layer=0; layer<size; layer++)
57
      {
58
      float currX = startX;
59
      float currY = startY;
60

  
61
      for(int x=0; x<layer+1; x++)
62
        {
63
        float currZ = startZ;
64

  
65
        for(int z=0; z<size-layer; z++)
66
          {
67
          pos[index] = new float[] {currX,currY,currZ};
68
          index++;
69
          currZ -= DZ;
70
          }
71

  
72
        currX += DX;
73
        }
74

  
75
      startX-=DX/2;
76
      startY+=DY;
77
      startZ-=DZ/2;
78
      }
79
    }
80

  
34 81
///////////////////////////////////////////////////////////////////////////////////////////////////
35 82

  
36 83
   float[] getDist3D()
......
85 132
     }
86 133

  
87 134
///////////////////////////////////////////////////////////////////////////////////////////////////
88
// TODO
89 135

  
90 136
  boolean isAdjacent(float dx, float dy, float dz)
91 137
    {
92
    return false;
138
    return dx*dx + dy*dy + dz*dz < (SQ3/4)*1.01f;
93 139
    }
94 140

  
95 141
///////////////////////////////////////////////////////////////////////////////////////////////////
96 142
// TODO
97 143

  
98
  float[][] getPositions()
144
  void getTouchedPosition(float[] output, int face, float pointX, float pointY)
99 145
    {
100
    return null;
146

  
101 147
    }
102 148

  
103 149
///////////////////////////////////////////////////////////////////////////////////////////////////
104
// TODO
105 150

  
106
  void getTouchedPosition(float[] output, int face, float pointX, float pointY)
151
  float[][][] getPositions()
107 152
    {
153
    int num = mSize[0];
154
    int numO= (num-1)*num*(num+1)/6;
155
    int numT= (num+1)*num*(num+2)/6;
156

  
157
    float[][] retO = new float[numO][];
158
    float[][] retT = new float[numT][];
108 159

  
160
    addTetrahedralLattice(num-1,retO);
161
    addTetrahedralLattice(num  ,retT);
162

  
163
    return new float[][][] { retO,retT };
109 164
    }
110 165

  
111 166
///////////////////////////////////////////////////////////////////////////////////////////////////
112
// TODO
113 167

  
114 168
  boolean isInsideFace(int face, float[] p)
115 169
    {
116
    return false;
170
    float y = (isFaceInverted(face) ? p[1] : -p[1]);
171
    float x = p[0];
172
    return (y >= -mDist2D) && (y <= mDist2D*(2-6*x)) && (y <= mDist2D*(2+6*x));
117 173
    }
118 174

  
119 175
///////////////////////////////////////////////////////////////////////////////////////////////////
120 176

  
121
  MeshBase createMesh(float[] pos, boolean round)
177
  MeshBase createMesh(int variant, float[] pos, boolean round)
122 178
     {
123 179
     FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
124
     return factory.createMesh(pos,mSize[0],false,round);
180
     return factory.createMesh(variant,pos,mSize[0],false,round);
125 181
     }
126 182

  
127 183
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff