Project

General

Profile

Download (5.39 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / bandaged / BandagedObjectCuboid.java @ f8c52090

1 86308421 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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.bandaged;
11
12
import org.distorted.library.main.DistortedScreen;
13
import org.distorted.library.mesh.MeshBase;
14
import org.distorted.library.type.Static3D;
15 462b983d Leszek Koltunski
import org.distorted.objectlib.helpers.FactoryBandagedCuboid;
16 86308421 Leszek Koltunski
import org.distorted.objectlib.main.InitData;
17
import org.distorted.objectlib.main.TwistyObject;
18
import org.distorted.objectlib.objects.TwistyBandagedCuboid;
19
import org.distorted.objectlib.shape.ShapeHexahedron;
20
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
21
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
24
public class BandagedObjectCuboid extends BandagedObject
25
{
26
   BandagedObjectCuboid(DistortedScreen screen)
27
     {
28
     super(screen);
29
     }
30
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 b2de7562 Leszek Koltunski
   float[] getDist3D()
34 86308421 Leszek Koltunski
     {
35 b2de7562 Leszek Koltunski
     float max = mMax;
36 86308421 Leszek Koltunski
37 b2de7562 Leszek Koltunski
     float x = 0.5f*(mSize[0]/max);
38
     float y = 0.5f*(mSize[1]/max);
39
     float z = 0.5f*(mSize[2]/max);
40
41
     return new float[] {x,x,y,y,z,z};
42
     }
43 86308421 Leszek Koltunski
44 b2de7562 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
45 86308421 Leszek Koltunski
46 b2de7562 Leszek Koltunski
   float getDist2D()
47
     {
48
     return 0.5f;
49 86308421 Leszek Koltunski
     }
50
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52
53 b2de7562 Leszek Koltunski
   int[] getColors()
54 86308421 Leszek Koltunski
     {
55 b2de7562 Leszek Koltunski
     return ShapeHexahedron.FACE_COLORS;
56 86308421 Leszek Koltunski
     }
57
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59
60 b2de7562 Leszek Koltunski
  Static3D[] getFaceAxis()
61
    {
62
    return TouchControlHexahedron.FACE_AXIS;
63
    }
64
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
67
  boolean isAdjacent(float dx, float dy, float dz)
68
    {
69 f8c52090 Leszek Koltunski
    return dx*dx + dy*dy + dz*dz <= 1;
70 b2de7562 Leszek Koltunski
    }
71
72 86308421 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
73
74 6c295be1 Leszek Koltunski
  float[][][] getPositions()
75 b2de7562 Leszek Koltunski
    {
76 6c295be1 Leszek Koltunski
    float[][][] pos = new float[1][mNumCubits][];
77 b2de7562 Leszek Koltunski
    int c=0;
78
    int sx = mSize[0];
79
    int sy = mSize[1];
80
    int sz = mSize[2];
81
82
    float begX = 0.5f*(1-sx);
83
    float begY = 0.5f*(1-sy);
84
    float begZ = 0.5f*(1-sz);
85
86
    for(int x=0; x<sx; x++)
87
      for(int y=0; y<sy; y++)
88
         for(int z=0; z<sz; z++)
89
           if( x==0 || x==sx-1 || y==0 || y==sy-1 || z==0 || z==sz-1 )
90 86308421 Leszek Koltunski
              {
91 6c295be1 Leszek Koltunski
              pos[0][c++] = new float[] { begX+x,begY+y,begZ+z };
92 86308421 Leszek Koltunski
              }
93
94 b2de7562 Leszek Koltunski
    return pos;
95 86308421 Leszek Koltunski
    }
96
97 462b983d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99
  boolean tryChangeObject(int x, int y, int z)
100
     {
101
     if( mSize[0]!=x || mSize[1]!=y || mSize[2]!=z )
102
       {
103
       mSize[0] = x;
104
       mSize[1] = y;
105
       mSize[2] = z;
106
       mMax = x>y ? Math.max(x,z) : Math.max(y,z);
107
       mNumCubits = ( x<=1 || y<=1 || z<=1 ) ? x*y*z : x*y*z-(x-2)*(y-2)*(z-2);
108
       return true;
109
       }
110
111
     return false;
112
     }
113
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115
116
  int computeProjectionAngle()
117
     {
118
     float quot1 = mSize[2]/ (float)mSize[0];
119
     float quot2 = mSize[2]/ (float)mSize[1];
120
     float quot3 = mSize[0]/ (float)mSize[2];
121
     float quot4 = mSize[0]/ (float)mSize[1];
122
123
     float quot5 = Math.max(quot1,quot2);
124
     float quot6 = Math.max(quot3,quot4);
125
     float quot7 = Math.max(quot5,quot6);
126
127
          if( quot7<=1.0f ) return 120;
128
     else if( quot7<=1.5f ) return 90;
129
     else if( quot7<=2.0f ) return 60;
130
     else                   return 30;
131
     }
132
133 86308421 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
134
135
  boolean isInsideFace(int face, float[] p)
136
    {
137 b2de7562 Leszek Koltunski
    float max = mMax;
138
139
    switch(face/2)
140
      {
141
      case 0: p[0] *= (max/mSize[2]); p[1] *= (max/mSize[1]); break;
142
      case 1: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[2]); break;
143
      case 2: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[1]); break;
144
      }
145
146 86308421 Leszek Koltunski
    return ( p[0]<=mDist2D && p[0]>=-mDist2D && p[1]<=mDist2D && p[1]>=-mDist2D );
147
    }
148 b2de7562 Leszek Koltunski
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150
151 f8c52090 Leszek Koltunski
  MeshBase createMesh(float[] pos, boolean round)
152 b2de7562 Leszek Koltunski
     {
153 462b983d Leszek Koltunski
     FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
154 f8c52090 Leszek Koltunski
     return factory.createMesh(pos,mSize,false,round);
155 b2de7562 Leszek Koltunski
     }
156
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
159
  TwistyObject createObject(int mode, float size)
160
     {
161
     float[][] pos = getCubitPositions();
162
     InitData data = new InitData( mSize,pos);
163
     return new TwistyBandagedCuboid( TwistyObject.MESH_NICE, mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
164
     }
165 86308421 Leszek Koltunski
}