Project

General

Profile

Download (2.26 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / helpers / BandagedElementCuboid.java @ c65d5889

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.helpers;
11

    
12
///////////////////////////////////////////////////////////////////////////////////////////////////
13

    
14
public class BandagedElementCuboid
15
  {
16
  private final float mX, mY, mZ;
17
  private final int mNumFaces;
18
  private final float[][] mCuts;
19
  private final int[] mNumCuts;
20
  private final float[][] mNormal;
21
  private final int[] mRotationRow;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

    
25
  BandagedElementCuboid(float[] pos, int index, float[][] normalVector, float[][] cuts)
26
    {
27
    mX = pos[index  ];
28
    mY = pos[index+1];
29
    mZ = pos[index+2];
30

    
31
    mNormal   = normalVector;
32
    mNumFaces = normalVector.length;
33
    mRotationRow = new int[mNumFaces];
34
    mCuts = cuts;
35

    
36
    mNumCuts = new int[mNumFaces];
37

    
38
    for(int i=0; i<mNumFaces; i++)
39
      {
40
      mNumCuts[i] = (mCuts==null || mCuts[i]==null ? 0 : mCuts[i].length);
41
      mRotationRow[i] = computeRow(i);
42
      }
43
    }
44

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

    
47
  private int computeRow(int face)
48
    {
49
    float[] ax = mNormal[face];
50
    float casted = mX*ax[0] + mY*ax[1] + mZ*ax[2];
51
    int num = mNumCuts[face];
52

    
53
    for(int i=0; i<num; i++)
54
      {
55
      if( casted<mCuts[face][i] ) return i;
56
      }
57

    
58
    return num;
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  int[] getRotRow()
64
    {
65
    return mRotationRow;
66
    }
67
  }
(1-1/16)