Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / bandaged / BandagedObjectCuboid.java @ bb85236a

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.bandaged;
11

    
12
import org.distorted.library.main.DistortedScreen;
13
import org.distorted.library.mesh.MeshBase;
14
import org.distorted.library.type.Static3D;
15
import org.distorted.objectlib.main.InitData;
16
import org.distorted.objectlib.main.TwistyObject;
17
import org.distorted.objectlib.objects.TwistyBandagedCuboid;
18
import org.distorted.objectlib.shape.ShapeHexahedron;
19
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
20

    
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22

    
23
public class BandagedObjectCuboid extends BandagedObject
24
{
25
  float getDist2D()
26
     {
27
     return 0.5f;
28
     }
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
  int[] getColors()
33
     {
34
     return ShapeHexahedron.FACE_COLORS;
35
     }
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
  boolean isAdjacent(float dx, float dy, float dz)
40
    {
41
    return dx*dx + dy*dy + dz*dz <= 1;
42
    }
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
  float[][][] getPositions()
47
    {
48
    float[][][] pos = new float[1][mNumCubits][];
49
    int c=0;
50
    int sx = mSize[0];
51
    int sy = mSize[1];
52
    int sz = mSize[2];
53

    
54
    float begX = 0.5f*(1-sx);
55
    float begY = 0.5f*(1-sy);
56
    float begZ = 0.5f*(1-sz);
57

    
58
    for(int x=0; x<sx; x++)
59
      for(int y=0; y<sy; y++)
60
         for(int z=0; z<sz; z++)
61
           if( x==0 || x==sx-1 || y==0 || y==sy-1 || z==0 || z==sz-1 )
62
              {
63
              pos[0][c++] = new float[] { begX+x,begY+y,begZ+z };
64
              }
65

    
66
    return pos;
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  MeshBase createMesh(float[] pos, boolean round)
72
     {
73
     FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
74
     return factory.createMesh(pos,mSize,false,round);
75
     }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
// PUBLIC API
79

    
80
  public BandagedObjectCuboid(DistortedScreen screen)
81
     {
82
     super(screen,3);
83
     }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  public float getScreenRatio()
88
     {
89
     return 0.5f;
90
     }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  public float[] getDist3D()
95
     {
96
     float max = mMax;
97

    
98
     float x = 0.5f*(mSize[0]/max);
99
     float y = 0.5f*(mSize[1]/max);
100
     float z = 0.5f*(mSize[2]/max);
101

    
102
     return new float[] {x,x,y,y,z,z};
103
     }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  public Static3D[] getFaceAxis()
108
     {
109
     return TouchControlHexahedron.FACE_AXIS;
110
     }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  public boolean isInsideFace(int face, float[] p)
115
     {
116
     float max = mMax;
117

    
118
     switch(face/2)
119
        {
120
        case 0: p[0] *= (max/mSize[2]); p[1] *= (max/mSize[1]); break;
121
        case 1: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[2]); break;
122
        case 2: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[1]); break;
123
        }
124

    
125
     return ( p[0]<=mDist2D && p[0]>=-mDist2D && p[1]<=mDist2D && p[1]>=-mDist2D );
126
     }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  public int computeProjectionAngle()
131
     {
132
     float quot1 = mSize[2]/ (float)mSize[0];
133
     float quot2 = mSize[2]/ (float)mSize[1];
134
     float quot3 = mSize[0]/ (float)mSize[2];
135
     float quot4 = mSize[0]/ (float)mSize[1];
136

    
137
     float quot5 = Math.max(quot1,quot2);
138
     float quot6 = Math.max(quot3,quot4);
139
     float quot7 = Math.max(quot5,quot6);
140

    
141
          if( quot7<=1.0f ) return 120;
142
     else if( quot7<=1.5f ) return 90;
143
     else if( quot7<=2.0f ) return 60;
144
     else                   return 30;
145
     }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

    
149
  public boolean tryChangeObject(int x, int y, int z)
150
     {
151
     if( mSize[0]!=x || mSize[1]!=y || mSize[2]!=z )
152
        {
153
        mSize[0] = x;
154
        mSize[1] = y;
155
        mSize[2] = z;
156
        mMax = x>y ? Math.max(x,z) : Math.max(y,z);
157
        mNumCubits = ( x<=1 || y<=1 || z<=1 ) ? x*y*z : x*y*z-(x-2)*(y-2)*(z-2);
158
        return true;
159
        }
160

    
161
     return false;
162
     }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
  public TwistyObject createObject(int mode, float size)
167
     {
168
     float[][] pos = getCubitPositions();
169
     InitData data = new InitData( mSize,pos);
170
     return new TwistyBandagedCuboid( TwistyObject.MESH_NICE, mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
171
     }
172
}
(4-4/8)