Revision 19f0f767
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/objects/RubikObject.java | ||
---|---|---|
28 | 28 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
29 | 29 |
|
30 | 30 |
import org.distorted.library.effect.Effect; |
31 |
import org.distorted.library.effect.MatrixEffectMove; |
|
31 | 32 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
32 | 33 |
import org.distorted.library.effect.MatrixEffectScale; |
33 | 34 |
import org.distorted.library.effect.VertexEffectQuaternion; |
... | ... | |
37 | 38 |
import org.distorted.library.main.DistortedTexture; |
38 | 39 |
import org.distorted.library.mesh.MeshBase; |
39 | 40 |
import org.distorted.library.mesh.MeshFile; |
41 |
import org.distorted.library.mesh.MeshJoined; |
|
40 | 42 |
import org.distorted.library.mesh.MeshRectangles; |
41 | 43 |
import org.distorted.library.message.EffectListener; |
42 | 44 |
import org.distorted.library.type.Dynamic1D; |
... | ... | |
56 | 58 |
private static final float MAX_SIZE_CHANGE = 1.3f; |
57 | 59 |
private static final float MIN_SIZE_CHANGE = 0.8f; |
58 | 60 |
|
61 |
private static boolean mCreateFromDMesh = true; |
|
62 |
|
|
59 | 63 |
private static final Static3D CENTER = new Static3D(0,0,0); |
60 | 64 |
static final int INTERIOR_COLOR = 0xff000000; |
61 | 65 |
private static final int POST_ROTATION_MILLISEC = 500; |
... | ... | |
126 | 130 |
mRotationAngleMiddle = new Static1D(0); |
127 | 131 |
mRotationAngleFinal = new Static1D(0); |
128 | 132 |
|
129 |
float scale = mObjectScreenRatio*mNodeSize/mSize; |
|
130 |
mObjectScale= new Static3D(scale,scale,scale); |
|
133 |
float scale = mObjectScreenRatio*mNodeSize/mSize;
|
|
134 |
mObjectScale = new Static3D(scale,scale,scale);
|
|
131 | 135 |
mScaleEffect = new MatrixEffectScale(mObjectScale); |
132 | 136 |
mQuatEffect = new MatrixEffectQuaternion(quat, CENTER); |
133 | 137 |
|
134 | 138 |
MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale); |
135 | 139 |
nodeEffects.apply(nodeScaleEffect); |
136 | 140 |
|
137 |
mCubits = new Cubit[NUM_CUBITS]; |
|
138 |
mTexture = new DistortedTexture(); |
|
139 |
|
|
140 |
int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),mSize); |
|
141 |
int resourceID= list.getResourceIDs()[sizeIndex]; |
|
142 |
|
|
143 |
InputStream is = res.openRawResource(resourceID); |
|
144 |
DataInputStream dos = new DataInputStream(is); |
|
145 |
mMesh = new MeshFile(dos); |
|
146 |
|
|
147 |
try |
|
148 |
{ |
|
149 |
is.close(); |
|
150 |
} |
|
151 |
catch(IOException e) |
|
152 |
{ |
|
153 |
android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString()); |
|
154 |
} |
|
155 |
|
|
156 |
for(int i=0; i<NUM_CUBITS; i++) |
|
157 |
{ |
|
158 |
mCubits[i] = new Cubit(this,mOrigPos[i]); |
|
159 |
mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0); |
|
160 |
} |
|
141 |
createMeshAndCubits(list,res); |
|
161 | 142 |
|
143 |
mTexture = new DistortedTexture(); |
|
162 | 144 |
mEffects = new DistortedEffects(); |
163 | 145 |
|
164 | 146 |
int num_quats = QUATS.length; |
... | ... | |
180 | 162 |
setProjection(fov, 0.1f); |
181 | 163 |
} |
182 | 164 |
|
165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
166 |
|
|
167 |
private void createMeshAndCubits(RubikObjectList list, Resources res) |
|
168 |
{ |
|
169 |
mCubits = new Cubit[NUM_CUBITS]; |
|
170 |
|
|
171 |
if( mCreateFromDMesh ) |
|
172 |
{ |
|
173 |
int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),mSize); |
|
174 |
int resourceID= list.getResourceIDs()[sizeIndex]; |
|
175 |
|
|
176 |
InputStream is = res.openRawResource(resourceID); |
|
177 |
DataInputStream dos = new DataInputStream(is); |
|
178 |
mMesh = new MeshFile(dos); |
|
179 |
|
|
180 |
try |
|
181 |
{ |
|
182 |
is.close(); |
|
183 |
} |
|
184 |
catch(IOException e) |
|
185 |
{ |
|
186 |
android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString()); |
|
187 |
} |
|
188 |
|
|
189 |
for(int i=0; i<NUM_CUBITS; i++) |
|
190 |
{ |
|
191 |
mCubits[i] = new Cubit(this,mOrigPos[i]); |
|
192 |
mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0); |
|
193 |
} |
|
194 |
} |
|
195 |
else |
|
196 |
{ |
|
197 |
MeshBase[] cubitMesh = new MeshBase[NUM_CUBITS]; |
|
198 |
|
|
199 |
for(int i=0; i<NUM_CUBITS; i++) |
|
200 |
{ |
|
201 |
mCubits[i] = new Cubit(this,mOrigPos[i]); |
|
202 |
cubitMesh[i] = createCubitMesh(i); |
|
203 |
cubitMesh[i].apply(new MatrixEffectMove(mOrigPos[i]),1,0); |
|
204 |
cubitMesh[i].setEffectAssociation(0, mCubits[i].computeAssociation(), 0); |
|
205 |
} |
|
206 |
|
|
207 |
mMesh = new MeshJoined(cubitMesh); |
|
208 |
resetAllTextureMaps(); |
|
209 |
} |
|
210 |
} |
|
211 |
|
|
183 | 212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
184 | 213 |
|
185 | 214 |
public void setObjectRatio(float sizeChange) |
Also available in: Unified diff
Re-introduce possibility to dynamically create object mesh.