1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2022 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.effect.EffectType;
|
13
|
import org.distorted.library.effect.FragmentEffectBrightness;
|
14
|
import org.distorted.library.effect.MatrixEffectMove;
|
15
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
16
|
import org.distorted.library.effect.MatrixEffectScale;
|
17
|
import org.distorted.library.main.DistortedEffects;
|
18
|
import org.distorted.library.main.DistortedNode;
|
19
|
import org.distorted.library.main.DistortedTexture;
|
20
|
import org.distorted.library.mesh.MeshBase;
|
21
|
import org.distorted.library.type.Static1D;
|
22
|
import org.distorted.library.type.Static3D;
|
23
|
import org.distorted.library.type.Static4D;
|
24
|
|
25
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26
|
|
27
|
public class BandagedCubit
|
28
|
{
|
29
|
private static final Static3D CENTER = new Static3D(0,0,0);
|
30
|
private static final Static1D mAlpha = new Static1D(20.0f);
|
31
|
|
32
|
private final BandagedObject mObject;
|
33
|
private final DistortedNode mNode;
|
34
|
private final DistortedEffects mEffects;
|
35
|
private final DistortedTexture mTexture;
|
36
|
private final Static3D mMove;
|
37
|
private final boolean mRoundCorners;
|
38
|
|
39
|
private float mUnscaledX, mUnscaledY, mUnscaledZ;
|
40
|
private float[] mPosition;
|
41
|
private float[][] mRotRow;
|
42
|
private boolean mIsAttached;
|
43
|
private long mMarkedEffectID;
|
44
|
|
45
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46
|
|
47
|
private void computeMove(float[] position)
|
48
|
{
|
49
|
int numCenters = position.length/3;
|
50
|
mUnscaledX=0.0f;
|
51
|
mUnscaledY=0.0f;
|
52
|
mUnscaledZ=0.0f;
|
53
|
|
54
|
for(int center=0; center<numCenters; center++)
|
55
|
{
|
56
|
mUnscaledX += position[3*center ];
|
57
|
mUnscaledY += position[3*center+1];
|
58
|
mUnscaledZ += position[3*center+2];
|
59
|
}
|
60
|
|
61
|
mUnscaledX /= numCenters;
|
62
|
mUnscaledY /= numCenters;
|
63
|
mUnscaledZ /= numCenters;
|
64
|
}
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
// PUBLIC API
|
68
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69
|
|
70
|
public BandagedCubit(BandagedObject object, float[] position, Static4D quat1,
|
71
|
Static4D quat2, Static3D scale, boolean roundCorners)
|
72
|
{
|
73
|
mObject = object;
|
74
|
mRoundCorners = roundCorners;
|
75
|
mPosition = position;
|
76
|
mRotRow = mObject.getRotRows(mPosition);
|
77
|
mIsAttached = true;
|
78
|
mMarkedEffectID = -1;
|
79
|
|
80
|
computeMove(mPosition);
|
81
|
mMove = new Static3D(0,0,0);
|
82
|
|
83
|
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners);
|
84
|
|
85
|
mTexture = new DistortedTexture();
|
86
|
mObject.recreateBitmap(mTexture);
|
87
|
mObject.resetTextureMaps(mesh);
|
88
|
|
89
|
MatrixEffectScale scaleEffect = new MatrixEffectScale(scale);
|
90
|
MatrixEffectQuaternion quat1Effect = new MatrixEffectQuaternion(quat1, CENTER);
|
91
|
MatrixEffectQuaternion quat2Effect = new MatrixEffectQuaternion(quat2, CENTER);
|
92
|
MatrixEffectMove moveEffect = new MatrixEffectMove(mMove);
|
93
|
|
94
|
mEffects = new DistortedEffects();
|
95
|
mEffects.apply(scaleEffect);
|
96
|
mEffects.apply(moveEffect);
|
97
|
mEffects.apply(quat2Effect);
|
98
|
mEffects.apply(quat1Effect);
|
99
|
|
100
|
mNode = new DistortedNode(mTexture,mEffects,mesh);
|
101
|
}
|
102
|
|
103
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104
|
|
105
|
public void join(float[] position, float scale)
|
106
|
{
|
107
|
int len1 = mPosition.length;
|
108
|
int len2 = position.length;
|
109
|
float[] tmpPosition = new float[len1+len2];
|
110
|
System.arraycopy(mPosition, 0, tmpPosition, 0, len1);
|
111
|
System.arraycopy(position , 0, tmpPosition, len1, len2);
|
112
|
mPosition = tmpPosition;
|
113
|
mRotRow = mObject.getRotRows(mPosition);
|
114
|
|
115
|
computeMove(mPosition);
|
116
|
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners);
|
117
|
mObject.resetTextureMaps(mesh);
|
118
|
mNode.setMesh(mesh);
|
119
|
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
|
124
|
public void reset(float scale)
|
125
|
{
|
126
|
float x = mPosition[0];
|
127
|
float y = mPosition[1];
|
128
|
float z = mPosition[2];
|
129
|
|
130
|
mPosition = new float[3];
|
131
|
mPosition[0] = x;
|
132
|
mPosition[1] = y;
|
133
|
mPosition[2] = z;
|
134
|
mRotRow = mObject.getRotRows(mPosition);
|
135
|
|
136
|
computeMove(mPosition);
|
137
|
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners);
|
138
|
mObject.resetTextureMaps(mesh);
|
139
|
mNode.setMesh(mesh);
|
140
|
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
|
141
|
}
|
142
|
|
143
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144
|
|
145
|
public DistortedTexture getTexture()
|
146
|
{
|
147
|
return mTexture;
|
148
|
}
|
149
|
|
150
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151
|
|
152
|
public void scaleMove(float scale)
|
153
|
{
|
154
|
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
|
155
|
}
|
156
|
|
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158
|
|
159
|
public void setMarked()
|
160
|
{
|
161
|
if( mMarkedEffectID<0 )
|
162
|
{
|
163
|
FragmentEffectBrightness effect = new FragmentEffectBrightness(mAlpha);
|
164
|
mMarkedEffectID = effect.getID();
|
165
|
mEffects.apply(effect);
|
166
|
}
|
167
|
}
|
168
|
|
169
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
170
|
|
171
|
public void setUnmarked()
|
172
|
{
|
173
|
mEffects.abortByType(EffectType.FRAGMENT);
|
174
|
mMarkedEffectID = -1;
|
175
|
}
|
176
|
|
177
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
178
|
|
179
|
public void detach()
|
180
|
{
|
181
|
mIsAttached = false;
|
182
|
}
|
183
|
|
184
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185
|
|
186
|
public void attach()
|
187
|
{
|
188
|
mIsAttached = true;
|
189
|
}
|
190
|
|
191
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192
|
|
193
|
public boolean isAttached()
|
194
|
{
|
195
|
return mIsAttached;
|
196
|
}
|
197
|
|
198
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
199
|
|
200
|
public float[] getPosition()
|
201
|
{
|
202
|
return mPosition;
|
203
|
}
|
204
|
|
205
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
206
|
|
207
|
public float[][] getRotRow()
|
208
|
{
|
209
|
return mRotRow;
|
210
|
}
|
211
|
|
212
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
213
|
|
214
|
public DistortedNode getNode()
|
215
|
{
|
216
|
return mNode;
|
217
|
}
|
218
|
}
|
219
|
|