Revision e6cf7283
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/objects/Cubit.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.content.SharedPreferences; |
23 | 23 |
|
24 |
import org.distorted.library.type.Static3D; |
|
25 | 24 |
import org.distorted.library.type.Static4D; |
26 | 25 |
import org.distorted.main.RubikSurfaceView; |
27 | 26 |
|
... | ... | |
29 | 28 |
|
30 | 29 |
class Cubit |
31 | 30 |
{ |
32 |
private final Static3D mOrigPosition;
|
|
33 |
private final Static3D mCurrentPosition;
|
|
31 |
private final float[] mOrigPosition;
|
|
32 |
private final float[] mCurrentPosition;
|
|
34 | 33 |
private TwistyObject mParent; |
35 | 34 |
private final int mNumAxis; |
35 |
private final int mLen; |
|
36 | 36 |
|
37 | 37 |
int mQuatIndex; |
38 | 38 |
int[] mRotationRow; |
39 | 39 |
|
40 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 | 41 |
|
42 |
Cubit(TwistyObject parent, Static3D position)
|
|
42 |
Cubit(TwistyObject parent, float[] position)
|
|
43 | 43 |
{ |
44 |
float x = position.get0();
|
|
45 |
float y = position.get1();
|
|
46 |
float z = position.get2();
|
|
44 |
mQuatIndex= 0;
|
|
45 |
mParent = parent;
|
|
46 |
mLen = position.length;
|
|
47 | 47 |
|
48 |
mParent = parent; |
|
49 |
mOrigPosition = new Static3D(x,y,z); |
|
50 |
mCurrentPosition = new Static3D(x,y,z); |
|
51 |
mQuatIndex = 0; |
|
48 |
mOrigPosition = new float[mLen]; |
|
49 |
mCurrentPosition = new float[mLen]; |
|
50 |
|
|
51 |
for(int i=0; i<mLen; i++) |
|
52 |
{ |
|
53 |
mOrigPosition[i] = position[i]; |
|
54 |
mCurrentPosition[i] = position[i]; |
|
55 |
} |
|
52 | 56 |
|
53 | 57 |
mNumAxis = mParent.ROTATION_AXIS.length; |
54 | 58 |
mRotationRow = new int[mNumAxis]; |
... | ... | |
113 | 117 |
|
114 | 118 |
private void computeRotationRow() |
115 | 119 |
{ |
116 |
float x = mCurrentPosition.get0(); |
|
117 |
float y = mCurrentPosition.get1(); |
|
118 |
float z = mCurrentPosition.get2(); |
|
119 |
|
|
120 | 120 |
for(int i=0; i<mNumAxis; i++) |
121 | 121 |
{ |
122 |
mRotationRow[i] = mParent.computeRow(x,y,z,i);
|
|
122 |
mRotationRow[i] = mParent.computeRow(mCurrentPosition,i);
|
|
123 | 123 |
} |
124 | 124 |
} |
125 | 125 |
|
126 | 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
127 | 127 |
|
128 |
Static3D getOrigPosition()
|
|
128 |
float[] getOrigPosition()
|
|
129 | 129 |
{ |
130 | 130 |
return mOrigPosition; |
131 | 131 |
} |
... | ... | |
134 | 134 |
|
135 | 135 |
void modifyCurrentPosition(Static4D quat) |
136 | 136 |
{ |
137 |
float cubitCenterX = mCurrentPosition.get0();
|
|
138 |
float cubitCenterY = mCurrentPosition.get1();
|
|
139 |
float cubitCenterZ = mCurrentPosition.get2();
|
|
137 |
Static4D cubitCenter;
|
|
138 |
Static4D rotatedCenter;
|
|
139 |
int len = mLen/3;
|
|
140 | 140 |
|
141 |
Static4D cubitCenter = new Static4D(cubitCenterX, cubitCenterY, cubitCenterZ, 0); |
|
142 |
Static4D rotatedCenter = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat); |
|
141 |
for(int i=0; i<len; i++) |
|
142 |
{ |
|
143 |
cubitCenter = new Static4D(mCurrentPosition[3*i], mCurrentPosition[3*i+1], mCurrentPosition[3*i+2], 0); |
|
144 |
rotatedCenter = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat); |
|
143 | 145 |
|
144 |
float rotatedX = rotatedCenter.get0();
|
|
145 |
float rotatedY = rotatedCenter.get1();
|
|
146 |
float rotatedZ = rotatedCenter.get2();
|
|
146 |
mCurrentPosition[3*i ] = rotatedCenter.get0();
|
|
147 |
mCurrentPosition[3*i+1] = rotatedCenter.get1();
|
|
148 |
mCurrentPosition[3*i+2] = rotatedCenter.get2();
|
|
147 | 149 |
|
148 |
mCurrentPosition.set(rotatedX, rotatedY, rotatedZ);
|
|
149 |
mParent.clampPos(mCurrentPosition);
|
|
150 |
mParent.clampPos(mCurrentPosition, 3*i);
|
|
151 |
}
|
|
150 | 152 |
|
151 | 153 |
computeRotationRow(); |
152 | 154 |
} |
... | ... | |
170 | 172 |
|
171 | 173 |
void savePreferences(SharedPreferences.Editor editor) |
172 | 174 |
{ |
173 |
String number = mOrigPosition.get0()+"_"+mOrigPosition.get1()+"_"+mOrigPosition.get2();
|
|
175 |
String number = mOrigPosition[0]+"_"+mOrigPosition[1]+"_"+mOrigPosition[2];
|
|
174 | 176 |
editor.putInt("q_"+number, mQuatIndex); |
175 | 177 |
} |
176 | 178 |
|
... | ... | |
178 | 180 |
|
179 | 181 |
int restorePreferences(SharedPreferences preferences) |
180 | 182 |
{ |
181 |
String number = mOrigPosition.get0()+"_"+mOrigPosition.get1()+"_"+mOrigPosition.get2();
|
|
183 |
String number = mOrigPosition[0]+"_"+mOrigPosition[1]+"_"+mOrigPosition[2];
|
|
182 | 184 |
mQuatIndex = preferences.getInt("q_"+number, 0); |
183 | 185 |
return mQuatIndex; |
184 | 186 |
} |
... | ... | |
200 | 202 |
void solve() |
201 | 203 |
{ |
202 | 204 |
mQuatIndex = 0; |
203 |
mCurrentPosition.set(mOrigPosition);
|
|
205 |
System.arraycopy(mOrigPosition, 0, mCurrentPosition, 0, mCurrentPosition.length);
|
|
204 | 206 |
computeRotationRow(); |
205 | 207 |
} |
206 | 208 |
|
... | ... | |
212 | 214 |
} |
213 | 215 |
|
214 | 216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
217 |
// this is only needed for MODE_REPLACE objects (i.e. - currently - CUBE_3), so it is enough to only |
|
218 |
// take into consideration the first position. |
|
215 | 219 |
|
216 | 220 |
float getDistSquared(float[] point) |
217 | 221 |
{ |
218 |
float dx = mCurrentPosition.get0() - point[0];
|
|
219 |
float dy = mCurrentPosition.get1() - point[1];
|
|
220 |
float dz = mCurrentPosition.get2() - point[2];
|
|
222 |
float dx = mCurrentPosition[0] - point[0];
|
|
223 |
float dy = mCurrentPosition[1] - point[1];
|
|
224 |
float dz = mCurrentPosition[2] - point[2];
|
|
221 | 225 |
|
222 | 226 |
return dx*dx + dy*dy + dz*dz; |
223 | 227 |
} |
Also available in: Unified diff
Change the Cubit center from a Static3D to a float[].
The point: now we can have more than one center, and bandaged objects need more than one, because in this way they are going to fill up their RotationRow bitmaps.