Project

General

Profile

« Previous | Next » 

Revision aaeef328

Added by Leszek Koltunski about 1 year ago

Support split type 'EDGE_COIN' in case of every shape.

View differences:

src/main/java/org/distorted/objectlib/touchcontrol/TouchControlIcosahedron.java
138 138
    }
139 139

  
140 140
///////////////////////////////////////////////////////////////////////////////////////////////////
141
// corner    edge
142
//   |       \ 0 /
143
// 2 | 0      \ /
144
//  / \      2 | 1
145
// / 1 \       |
146 141

  
147
  int returnPart(int type, int face, float[] touchPoint)
142
  private int partEdge(float[] point, int face)
148 143
    {
149
    switch(type)
150
      {
151
      case TYPE_NOT_SPLIT   : return 0;
144
    float y = (isFaceInverted(face) ? point[1] : -point[1]);
145
    float x = point[0];
152 146

  
153
      case TYPE_SPLIT_EDGE  : float y1 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]);
154
                              float x1 = touchPoint[0];
147
    boolean e0 = x>0;
148
    boolean e1 = y>( SQ3/3)*x;
149
    boolean e2 = y>(-SQ3/3)*x;
155 150

  
156
                              boolean e0 = x1>0;
157
                              boolean e1 = y1>( SQ3/3)*x1;
158
                              boolean e2 = y1>(-SQ3/3)*x1;
151
    if(  e1 && e2 ) return 0;
152
    if( !e1 && e0 ) return 1;
153
    return 2;
154
    }
159 155

  
160
                              if(  e1 && e2 ) return 0;
161
                              if( !e1 && e0 ) return 1;
162
                              if( !e0 &&!e2 ) return 2;
163
                              return 0;
156
///////////////////////////////////////////////////////////////////////////////////////////////////
164 157

  
165
      case TYPE_SPLIT_CORNER: float y2 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]);
166
                              float x2 = touchPoint[0];
158
  private int partCorner(float[] point, int face)
159
    {
160
    float y2 = (isFaceInverted(face) ? point[1] : -point[1]);
161
    float x2 = point[0];
167 162

  
168
                              boolean c0 = x2>0;
169
                              boolean c1 = y2>( SQ3/3)*x2;
170
                              boolean c2 = y2>(-SQ3/3)*x2;
163
    boolean c0 = x2>0;
164
    boolean c1 = y2>( SQ3/3)*x2;
165
    boolean c2 = y2>(-SQ3/3)*x2;
171 166

  
172
                              if(  c0 && c2 ) return 0;
173
                              if( !c1 &&!c2 ) return 1;
174
                              if( !c0 && c1 ) return 2;
175
                              return 0;
167
    if(  c0 && c2 ) return 0;
168
    if( !c1 &&!c2 ) return 1;
169
    return 2;
170
    }
176 171

  
177
      case TYPE_SPLIT_EDGE_COIN: //  not supported
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
// corner    edge
174
//   |       \ 0 /
175
// 2 | 0      \ /
176
//  / \      2 | 1
177
// / 1 \       |
178

  
179
  int returnPart(int type, int face, float[] point)
180
    {
181
    switch(type)
182
      {
183
      case TYPE_NOT_SPLIT      : return 0;
184
      case TYPE_SPLIT_EDGE     : return partEdge(point,face);
185
      case TYPE_SPLIT_CORNER   : return partCorner(point,face);
186
      case TYPE_SPLIT_EDGE_COIN: float y = point[1];
187
                                 float x = point[0];
188
                                 return partEdge(point,face) + (x*x+y*y < DIST2D*DIST2D ? 0:3 );
178 189
      }
179 190

  
180 191
    return 0;
......
182 193

  
183 194
///////////////////////////////////////////////////////////////////////////////////////////////////
184 195

  
185
  boolean isInsideFace(int face, float[] p)
196
  boolean isInsideFace(int face, float[] point)
186 197
    {
187
    float y = (isFaceInverted(face) ? p[1] : -p[1]);
188
    float x = p[0];
198
    float y = (isFaceInverted(face) ? point[1] : -point[1]);
199
    float x = point[0];
189 200
    return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
190 201
    }
191 202
}

Also available in: Unified diff