Revision f925d455
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/objectlib/objects/TwistyCamouflage.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.objectlib.objects; |
11 | 11 |
|
12 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD; |
|
13 |
|
|
14 |
import org.distorted.library.effect.EffectName; |
|
12 | 15 |
import org.distorted.library.type.Static3D; |
13 | 16 |
import org.distorted.library.type.Static4D; |
17 |
import org.distorted.objectlib.helpers.ObjectFaceShape; |
|
18 |
import org.distorted.objectlib.helpers.ObjectShape; |
|
14 | 19 |
import org.distorted.objectlib.helpers.ObjectSignature; |
20 |
import org.distorted.objectlib.helpers.ObjectVertexEffects; |
|
15 | 21 |
import org.distorted.objectlib.main.InitData; |
16 | 22 |
import org.distorted.objectlib.main.ObjectType; |
17 | 23 |
|
... | ... | |
23 | 29 |
{ |
24 | 30 |
public static final float[][] CAM_333 = new float[][] |
25 | 31 |
{ |
26 |
// TODO: define centers of the Camouflage 3x3x3 cube. |
|
32 |
getCenters( -1.0f, 1.0f, 1.0f, 2, 2, 2), |
|
33 |
|
|
34 |
getCenters( 0.5f, 1.0f, 1.0f, 1, 2, 2), |
|
35 |
getCenters( 1.5f, 1.0f, 1.0f, 1, 2, 2), |
|
36 |
getCenters( -1.0f,-0.5f, 1.0f, 2, 1, 2), |
|
37 |
getCenters( -1.0f,-1.5f, 1.0f, 2, 1, 2), |
|
38 |
getCenters( -1.0f, 1.0f,-0.5f, 2, 2, 1), |
|
39 |
getCenters( -1.0f, 1.0f,-1.5f, 2, 2, 1), |
|
40 |
|
|
41 |
getCenters( -1.0f,-1.5f,-0.5f, 2, 1, 1), |
|
42 |
getCenters( -1.0f,-1.5f,-1.5f, 2, 1, 1), |
|
43 |
getCenters( -1.0f,-0.5f,-0.5f, 2, 1, 1), |
|
44 |
getCenters( -1.0f,-0.5f,-1.5f, 2, 1, 1), |
|
45 |
getCenters( 0.5f, 1.0f,-1.5f, 1, 2, 1), |
|
46 |
getCenters( 1.5f, 1.0f,-1.5f, 1, 2, 1), |
|
47 |
getCenters( 0.5f, 1.0f,-0.5f, 1, 2, 1), |
|
48 |
getCenters( 1.5f, 1.0f,-0.5f, 1, 2, 1), |
|
49 |
getCenters( 0.5f,-0.5f, 1.0f, 1, 1, 2), |
|
50 |
getCenters( 1.5f,-0.5f, 1.0f, 1, 1, 2), |
|
51 |
getCenters( 0.5f,-1.5f, 1.0f, 1, 1, 2), |
|
52 |
getCenters( 1.5f,-1.5f, 1.0f, 1, 1, 2), |
|
53 |
|
|
54 |
getCenters( 0.5f,-0.5f,-1.5f, 1, 1, 1), |
|
55 |
getCenters( 1.5f,-0.5f,-1.5f, 1, 1, 1), |
|
56 |
getCenters( 0.5f,-1.5f,-1.5f, 1, 1, 1), |
|
57 |
getCenters( 1.5f,-1.5f,-1.5f, 1, 1, 1), |
|
58 |
getCenters( 0.5f,-1.5f,-0.5f, 1, 1, 1), |
|
59 |
getCenters( 1.5f,-0.5f,-0.5f, 1, 1, 1), |
|
60 |
getCenters( 1.5f,-1.5f,-0.5f, 1, 1, 1), |
|
61 |
}; |
|
62 |
|
|
63 |
private static final int[][] DIMS = new int[][] |
|
64 |
{ |
|
65 |
{2,2,2}, |
|
66 |
{1,2,2}, |
|
67 |
{2,1,2}, |
|
68 |
{2,2,1}, |
|
69 |
{2,1,1}, |
|
70 |
{1,2,1}, |
|
71 |
{1,1,2}, |
|
72 |
{1,1,1}, |
|
27 | 73 |
}; |
28 | 74 |
|
75 |
private static final float[][] OFFSETS = new float[][] |
|
76 |
{ |
|
77 |
{ 0.0f, 0.0f, 0.0f}, |
|
78 |
{ 0.5f, 0.0f, 0.0f}, |
|
79 |
{-0.5f, 0.0f, 0.0f}, |
|
80 |
{ 0.0f, 0.5f, 0.0f}, |
|
81 |
{ 0.0f,-0.5f, 0.0f}, |
|
82 |
{ 0.0f, 0.0f, 0.5f}, |
|
83 |
{ 0.0f, 0.0f,-0.5f}, |
|
84 |
{ 0.0f,-0.5f,-0.5f}, |
|
85 |
{ 0.5f, 0.0f,-0.5f}, |
|
86 |
{ 0.5f,-0.5f, 0.0f}, |
|
87 |
{ 0.5f,-0.5f,-0.5f}, |
|
88 |
}; |
|
89 |
|
|
90 |
private int[] mDimsIndices, mOffsIndices; |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
private static float[] getCenters( float x, float y, float z, int xd, int yd, int zd ) |
|
95 |
{ |
|
96 |
float XS = 0.5f*(1-xd) + x; |
|
97 |
float YS = 0.5f*(1-yd) + y; |
|
98 |
float ZS = 0.5f*(1-zd) + z; |
|
99 |
|
|
100 |
int index=0; |
|
101 |
float[] result = new float[3*xd*yd*zd]; |
|
102 |
|
|
103 |
for(int i=0; i<xd; i++) |
|
104 |
for(int j=0; j<yd; j++) |
|
105 |
for(int k=0; k<zd; k++) |
|
106 |
{ |
|
107 |
result[3*index ] = XS+i; |
|
108 |
result[3*index+1] = YS+j; |
|
109 |
result[3*index+2] = ZS+k; |
|
110 |
index++; |
|
111 |
} |
|
112 |
|
|
113 |
return result; |
|
114 |
} |
|
115 |
|
|
29 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
30 | 117 |
|
31 | 118 |
public TwistyCamouflage(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream) |
... | ... | |
35 | 122 |
|
36 | 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
37 | 124 |
|
38 |
float[][] getVertices(int variant)
|
|
125 |
private int getDimsIndex(int variant)
|
|
39 | 126 |
{ |
40 | 127 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
41 | 128 |
|
42 | 129 |
if( mPosition==CAM_333 ) |
43 | 130 |
{ |
44 |
// TODO: vertices of the Camouflage 3x3x3 |
|
131 |
if( mDimsIndices==null ) mDimsIndices = new int[] |
|
132 |
{ 0, |
|
133 |
1,0,2,0,3,0, |
|
134 |
3,0,4,2,1,0,5,3,6,2,1,0, |
|
135 |
6,2,1,0,5,4,3 }; |
|
45 | 136 |
} |
46 | 137 |
|
47 |
return null; |
|
138 |
return mDimsIndices[variant]; |
|
139 |
} |
|
140 |
|
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
|
|
143 |
private int getOffsetsIndex(int variant) |
|
144 |
{ |
|
145 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
|
146 |
|
|
147 |
if( mPosition==CAM_333 ) |
|
148 |
{ |
|
149 |
if( mOffsIndices==null ) mOffsIndices = new int[] |
|
150 |
{ 0, |
|
151 |
0,1,0,4,0,6, |
|
152 |
4,7,0,6,6,8,0,1,0,1,4,9, |
|
153 |
6,8,7,10,4,1,9 }; |
|
154 |
} |
|
155 |
|
|
156 |
return mOffsIndices[variant]; |
|
157 |
} |
|
158 |
|
|
159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
160 |
|
|
161 |
private float[][] getVertices(int variant) |
|
162 |
{ |
|
163 |
int indexD = getDimsIndex(variant); |
|
164 |
|
|
165 |
int X=DIMS[indexD][0]; |
|
166 |
int Y=DIMS[indexD][1]; |
|
167 |
int Z=DIMS[indexD][2]; |
|
168 |
|
|
169 |
int indexO = getOffsetsIndex(variant); |
|
170 |
|
|
171 |
float XF = OFFSETS[indexO][0]; |
|
172 |
float YF = OFFSETS[indexO][1]; |
|
173 |
float ZF = OFFSETS[indexO][2]; |
|
174 |
|
|
175 |
return new float[][] |
|
176 |
{ |
|
177 |
{ 0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF}, |
|
178 |
{ 0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF}, |
|
179 |
{ 0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF}, |
|
180 |
{ 0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF}, |
|
181 |
{-0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF}, |
|
182 |
{-0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF}, |
|
183 |
{-0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF}, |
|
184 |
{-0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF} |
|
185 |
}; |
|
48 | 186 |
} |
49 | 187 |
|
50 | 188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 189 |
// PUBLIC API |
52 | 190 |
|
191 |
public int getTouchControlType() |
|
192 |
{ |
|
193 |
return TC_CHANGING_SHAPEMOD; |
|
194 |
} |
|
195 |
|
|
196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
197 |
|
|
198 |
public Static4D getCubitQuats(int cubit, int[] numLayers) |
|
199 |
{ |
|
200 |
return mObjectQuats[0]; |
|
201 |
} |
|
202 |
|
|
203 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
204 |
|
|
205 |
public ObjectShape getObjectShape(int variant) |
|
206 |
{ |
|
207 |
int[][] indices = |
|
208 |
{ |
|
209 |
{2,3,1,0}, |
|
210 |
{7,6,4,5}, |
|
211 |
{4,0,1,5}, |
|
212 |
{7,3,2,6}, |
|
213 |
{6,2,0,4}, |
|
214 |
{3,7,5,1}, |
|
215 |
}; |
|
216 |
|
|
217 |
return new ObjectShape( getVertices(variant), indices); |
|
218 |
} |
|
219 |
|
|
220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
221 |
|
|
222 |
public ObjectFaceShape getObjectFaceShape(int variant) |
|
223 |
{ |
|
224 |
int index = getDimsIndex(variant); |
|
225 |
|
|
226 |
int X = DIMS[index][0]; |
|
227 |
int Y = DIMS[index][1]; |
|
228 |
int Z = DIMS[index][2]; |
|
229 |
|
|
230 |
float height = isInIconMode() ? 0.001f : 0.03f; |
|
231 |
int[] bandIndices= { 0,0,1,1,2,2 }; |
|
232 |
|
|
233 |
int maxXY = Math.max(X,Y); |
|
234 |
int maxXZ = Math.max(X,Z); |
|
235 |
int maxYZ = Math.max(Y,Z); |
|
236 |
|
|
237 |
int angle = 45; |
|
238 |
float R = 0.10f; |
|
239 |
float S = 0.25f; |
|
240 |
float N = 4; |
|
241 |
|
|
242 |
float[][] bands = |
|
243 |
{ |
|
244 |
{height/maxYZ,angle,R,S,N,0,0}, |
|
245 |
{height/maxXZ,angle,R,S,N,0,0}, |
|
246 |
{height/maxXY,angle,R,S,N,0,0} |
|
247 |
}; |
|
248 |
|
|
249 |
return new ObjectFaceShape(bands,bandIndices,null); |
|
250 |
} |
|
251 |
|
|
252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
253 |
|
|
254 |
public ObjectVertexEffects getVertexEffects(int variant) |
|
255 |
{ |
|
256 |
boolean round = false; |
|
257 |
float[][] vertices = getVertices(variant); |
|
258 |
float A = -0.03f; |
|
259 |
|
|
260 |
float[][] variables = |
|
261 |
{ |
|
262 |
{ 0, A, A, A, 1 }, |
|
263 |
{ 0, A, A,-A, 1 }, |
|
264 |
{ 0, A,-A, A, 1 }, |
|
265 |
{ 0, A,-A,-A, 1 }, |
|
266 |
{ 0,-A, A, A, 1 }, |
|
267 |
{ 0,-A, A,-A, 1 }, |
|
268 |
{ 0,-A,-A, A, 1 }, |
|
269 |
{ 0,-A,-A,-A, 1 }, |
|
270 |
}; |
|
271 |
|
|
272 |
String name = EffectName.DEFORM.name(); |
|
273 |
float[] reg = {0,0,0,0.10f}; |
|
274 |
|
|
275 |
String[] names = {name,name,name,name,name,name,name,name}; |
|
276 |
float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg}; |
|
277 |
boolean[] uses = {round,round,round,round,round,round,round,round}; |
|
278 |
|
|
279 |
return new ObjectVertexEffects(names,variables,vertices,regions,uses); |
|
280 |
} |
|
281 |
|
|
282 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
283 |
|
|
284 |
public int getCubitVariant(int cubit, int[] numLayers) |
|
285 |
{ |
|
286 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
|
287 |
|
|
288 |
if( mPosition==CAM_333 ) |
|
289 |
{ |
|
290 |
return cubit; |
|
291 |
} |
|
292 |
|
|
293 |
return 0; |
|
294 |
} |
|
295 |
|
|
296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
297 |
|
|
298 |
public int getNumCubitVariants(int[] numLayers) |
|
299 |
{ |
|
300 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
|
301 |
|
|
302 |
if( mPosition==CAM_333 ) return 26; |
|
303 |
|
|
304 |
return 0; |
|
305 |
} |
|
306 |
|
|
307 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
308 |
|
|
309 |
public float getStickerRadius() |
|
310 |
{ |
|
311 |
return 0.18f; |
|
312 |
} |
|
313 |
|
|
314 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
315 |
|
|
316 |
public float getStickerStroke() |
|
317 |
{ |
|
318 |
return isInIconMode() ? 0.25f : 0.15f; |
|
319 |
} |
|
320 |
|
|
321 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
322 |
|
|
53 | 323 |
public String getShortName() |
54 | 324 |
{ |
55 | 325 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
Also available in: Unified diff
Progress with the Camouflage 3x3x3.