Project

General

Profile

« Previous | Next » 

Revision adb5b717

Added by Leszek Koltunski 4 months ago

new detection of the solved state - beginnings.

View differences:

src/main/java/org/distorted/objectlib/helpers/ObjectShape.java
172 172
      }
173 173
    }
174 174

  
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

  
177
  private void computeNormalVector(float[] v0, float[] v1, float[] v2, float[] output)
178
    {
179
    float x1 = v0[0];
180
    float y1 = v0[1];
181
    float z1 = v0[2];
182
    float x2 = v1[0];
183
    float y2 = v1[1];
184
    float z2 = v1[2];
185
    float x3 = v2[0];
186
    float y3 = v2[1];
187
    float z3 = v2[2];
188

  
189
    float v1x = x2-x1;
190
    float v1y = y2-y1;
191
    float v1z = z2-z1;
192
    float v2x = x3-x1;
193
    float v2y = y3-y1;
194
    float v2z = z3-z1;
195

  
196
    output[0] = v1y*v2z - v2y*v1z;
197
    output[1] = v1z*v2x - v2z*v1x;
198
    output[2] = v1x*v2y - v2x*v1y;
199

  
200
    double len = output[0]*output[0] + output[1]*output[1] + output[2]*output[2];
201
    len = Math.sqrt(len);
202
    output[0] /= len;
203
    output[1] /= len;
204
    output[2] /= len;
205
    }
206

  
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208
// return surface defined by the face, i.e. a 4-tuple [ (nx,ny,nz), d ]
209

  
210
  public void getFaceSurface(int face, float[] output)
211
    {
212
    int[] loopI = mFacesMultigon ? getMultigonIndices()[face][0] : getVertIndices()[face];
213

  
214
    float[] v0 = mVertices[loopI[0]];
215
    float[] v1 = mVertices[loopI[1]];
216
    float[] v2 = mVertices[loopI[2]];
217

  
218
    computeNormalVector(v0,v1,v2,output);
219

  
220
    output[3] = output[0]*v0[0] + output[1]*v0[1] + output[2]*v0[2];
221
    }
222

  
175 223
///////////////////////////////////////////////////////////////////////////////////////////////////
176 224

  
177 225
  public static int computeNumComponents(ObjectShape[] shapes)

Also available in: Unified diff