Revision 9e79b20f
Added by Leszek Koltunski about 2 years ago
| src/main/java/org/distorted/objectlib/bandaged/BandagedCubit.java | ||
|---|---|---|
| 9 | 9 |
|
| 10 | 10 |
package org.distorted.objectlib.bandaged; |
| 11 | 11 |
|
| 12 |
import android.graphics.Bitmap; |
|
| 13 |
import android.graphics.Canvas; |
|
| 14 |
import android.graphics.Paint; |
|
| 15 |
|
|
| 16 | 12 |
import org.distorted.library.effect.EffectType; |
| 17 | 13 |
import org.distorted.library.effect.FragmentEffectBrightness; |
| 18 | 14 |
import org.distorted.library.effect.MatrixEffectMove; |
| ... | ... | |
| 21 | 17 |
import org.distorted.library.main.DistortedEffects; |
| 22 | 18 |
import org.distorted.library.main.DistortedNode; |
| 23 | 19 |
import org.distorted.library.main.DistortedTexture; |
| 24 |
import org.distorted.library.helpers.QuatHelper; |
|
| 25 | 20 |
import org.distorted.library.mesh.MeshBase; |
| 26 | 21 |
import org.distorted.library.type.Static1D; |
| 27 | 22 |
import org.distorted.library.type.Static3D; |
| 28 | 23 |
import org.distorted.library.type.Static4D; |
| 29 |
import org.distorted.objectlib.helpers.FactoryCubit; |
|
| 30 | 24 |
|
| 31 | 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | 26 |
|
| 33 | 27 |
public class BandagedCubit |
| 34 | 28 |
{
|
| 35 | 29 |
private static final Static3D CENTER = new Static3D(0,0,0); |
| 36 |
private static final float[] mTmp = new float[4]; |
|
| 37 | 30 |
private static final Static1D mAlpha = new Static1D(20.0f); |
| 38 |
private static Bitmap mBitmap; |
|
| 39 |
private static Static4D[] mTextureMaps; |
|
| 40 | 31 |
|
| 41 | 32 |
private final BandagedObject mObject; |
| 42 | 33 |
private final DistortedNode mNode; |
| ... | ... | |
| 51 | 42 |
private boolean mIsAttached; |
| 52 | 43 |
private long mMarkedEffectID; |
| 53 | 44 |
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
|
|
| 56 |
private static void createBitmap(int[] colors) |
|
| 57 |
{
|
|
| 58 |
final int NUM = colors.length; |
|
| 59 |
final int SIZE= 32; |
|
| 60 |
|
|
| 61 |
mTextureMaps = new Static4D[NUM]; |
|
| 62 |
|
|
| 63 |
Paint paint = new Paint(); |
|
| 64 |
paint.setStyle(Paint.Style.FILL); |
|
| 65 |
mBitmap = Bitmap.createBitmap( NUM*SIZE, SIZE, Bitmap.Config.ARGB_4444); |
|
| 66 |
Canvas canvas = new Canvas(mBitmap); |
|
| 67 |
|
|
| 68 |
for(int color=0; color<NUM; color++) |
|
| 69 |
{
|
|
| 70 |
paint.setColor(colors[color]); |
|
| 71 |
canvas.drawRect(color*SIZE, 0, (color+1)*SIZE, SIZE, paint); |
|
| 72 |
mTextureMaps[color] = new Static4D( ((float)color)/NUM, 0.0f, 1.0f/NUM, 1.0f ); |
|
| 73 |
} |
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 77 |
|
|
| 78 |
private void resetTextureMaps(MeshBase mesh) |
|
| 79 |
{
|
|
| 80 |
FactoryCubit fact = FactoryCubit.getInstance(); |
|
| 81 |
int numComponents = mesh.getNumTexComponents(); |
|
| 82 |
Static4D[] maps = new Static4D[numComponents]; |
|
| 83 |
|
|
| 84 |
if( mTextureMaps==null || mTextureMaps.length!=numComponents || mBitmap==null ) |
|
| 85 |
{
|
|
| 86 |
createBitmap(mObject.getColors()); |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
for(int i=0; i<numComponents; i++) |
|
| 90 |
{
|
|
| 91 |
Static4D q = fact.getQuaternion(i); |
|
| 92 |
QuatHelper.rotateVectorByQuat(mTmp,0,0,1,0,q); |
|
| 93 |
int index = mObject.computeMapsIndex(mTmp); |
|
| 94 |
|
|
| 95 |
if( index>=mTextureMaps.length ) |
|
| 96 |
{
|
|
| 97 |
android.util.Log.e("D", "index="+index+" texMapLen="+mTextureMaps.length);
|
|
| 98 |
} |
|
| 99 |
|
|
| 100 |
maps[i] = mTextureMaps[index]; |
|
| 101 |
} |
|
| 102 |
|
|
| 103 |
mesh.setTextureMap(maps,0); |
|
| 104 |
} |
|
| 105 |
|
|
| 106 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 107 | 46 |
|
| 108 | 47 |
private void computeMove(float[] position) |
| ... | ... | |
| 144 | 83 |
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners); |
| 145 | 84 |
|
| 146 | 85 |
mTexture = new DistortedTexture(); |
| 147 |
if( mBitmap==null ) createBitmap(mObject.getColors()); |
|
| 148 |
mTexture.setTextureAlreadyInverted(mBitmap); |
|
| 149 |
|
|
| 150 |
resetTextureMaps(mesh); |
|
| 86 |
mObject.recreateBitmap(mTexture); |
|
| 87 |
mObject.resetTextureMaps(mesh); |
|
| 151 | 88 |
|
| 152 | 89 |
MatrixEffectScale scaleEffect = new MatrixEffectScale(scale); |
| 153 | 90 |
MatrixEffectQuaternion quat1Effect = new MatrixEffectQuaternion(quat1, CENTER); |
| ... | ... | |
| 177 | 114 |
|
| 178 | 115 |
computeMove(mPosition); |
| 179 | 116 |
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners); |
| 180 |
resetTextureMaps(mesh); |
|
| 117 |
mObject.resetTextureMaps(mesh);
|
|
| 181 | 118 |
mNode.setMesh(mesh); |
| 182 | 119 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
| 183 | 120 |
} |
| ... | ... | |
| 197 | 134 |
|
| 198 | 135 |
computeMove(mPosition); |
| 199 | 136 |
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners); |
| 200 |
resetTextureMaps(mesh); |
|
| 137 |
mObject.resetTextureMaps(mesh);
|
|
| 201 | 138 |
mNode.setMesh(mesh); |
| 202 | 139 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
| 203 | 140 |
} |
| 204 | 141 |
|
| 205 | 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 206 | 143 |
|
| 207 |
public void recreateBitmap()
|
|
| 144 |
public DistortedTexture getTexture()
|
|
| 208 | 145 |
{
|
| 209 |
if( mBitmap==null ) createBitmap(mObject.getColors()); |
|
| 210 |
mTexture.setTextureAlreadyInverted(mBitmap); |
|
| 146 |
return mTexture; |
|
| 211 | 147 |
} |
| 212 | 148 |
|
| 213 | 149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/objectlib/bandaged/BandagedObject.java | ||
|---|---|---|
| 9 | 9 |
|
| 10 | 10 |
package org.distorted.objectlib.bandaged; |
| 11 | 11 |
|
| 12 |
import android.graphics.Bitmap; |
|
| 13 |
import android.graphics.Canvas; |
|
| 14 |
import android.graphics.Paint; |
|
| 15 |
|
|
| 16 |
import org.distorted.library.helpers.QuatHelper; |
|
| 12 | 17 |
import org.distorted.library.main.DistortedNode; |
| 13 | 18 |
import org.distorted.library.main.DistortedScreen; |
| 19 |
import org.distorted.library.main.DistortedTexture; |
|
| 14 | 20 |
import org.distorted.library.mesh.MeshBase; |
| 15 | 21 |
import org.distorted.library.type.Static3D; |
| 16 | 22 |
import org.distorted.library.type.Static4D; |
| 23 |
import org.distorted.objectlib.helpers.FactoryCubit; |
|
| 17 | 24 |
import org.distorted.objectlib.main.TwistyObject; |
| 18 | 25 |
|
| 19 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 27 |
|
| 21 | 28 |
public abstract class BandagedObject |
| 22 | 29 |
{
|
| 30 |
private static final float[] mTmp = new float[4]; |
|
| 31 |
|
|
| 23 | 32 |
private final DistortedScreen mScreen; |
| 24 | 33 |
private final float[][] mFaceAxis; |
| 25 | 34 |
private BandagedCubit[] mCubits; |
| 26 | 35 |
private final float[][] mRotAxis; |
| 36 |
private Bitmap mBitmap; |
|
| 37 |
private Static4D[] mTextureMaps; |
|
| 27 | 38 |
|
| 28 | 39 |
float[][] mCuts; |
| 29 | 40 |
final int[] mSize; |
| ... | ... | |
| 63 | 74 |
public abstract Static3D[] getFaceAxis(); |
| 64 | 75 |
public abstract float getScreenRatio(); |
| 65 | 76 |
|
| 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 78 |
|
|
| 79 |
private void createBitmap(int[] colors) |
|
| 80 |
{
|
|
| 81 |
final int NUM = colors.length; |
|
| 82 |
final int SIZE= 32; |
|
| 83 |
|
|
| 84 |
mTextureMaps = new Static4D[NUM]; |
|
| 85 |
|
|
| 86 |
Paint paint = new Paint(); |
|
| 87 |
paint.setStyle(Paint.Style.FILL); |
|
| 88 |
mBitmap = Bitmap.createBitmap( NUM*SIZE, SIZE, Bitmap.Config.ARGB_4444); |
|
| 89 |
Canvas canvas = new Canvas(mBitmap); |
|
| 90 |
|
|
| 91 |
for(int color=0; color<NUM; color++) |
|
| 92 |
{
|
|
| 93 |
paint.setColor(colors[color]); |
|
| 94 |
canvas.drawRect(color*SIZE, 0, (color+1)*SIZE, SIZE, paint); |
|
| 95 |
mTextureMaps[color] = new Static4D( ((float)color)/NUM, 0.0f, 1.0f/NUM, 1.0f ); |
|
| 96 |
} |
|
| 97 |
} |
|
| 98 |
|
|
| 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 100 |
|
|
| 101 |
void resetTextureMaps(MeshBase mesh) |
|
| 102 |
{
|
|
| 103 |
FactoryCubit fact = FactoryCubit.getInstance(); |
|
| 104 |
int numComponents = mesh.getNumTexComponents(); |
|
| 105 |
Static4D[] maps = new Static4D[numComponents]; |
|
| 106 |
|
|
| 107 |
if( mTextureMaps==null || mBitmap==null ) |
|
| 108 |
{
|
|
| 109 |
android.util.Log.e("D", "RECREATING TEXTURE");
|
|
| 110 |
createBitmap(getColors()); |
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
for(int i=0; i<numComponents; i++) |
|
| 114 |
{
|
|
| 115 |
Static4D q = fact.getQuaternion(i); |
|
| 116 |
QuatHelper.rotateVectorByQuat(mTmp,0,0,1,0,q); |
|
| 117 |
int index = computeMapsIndex(mTmp); |
|
| 118 |
maps[i] = mTextureMaps[index]; |
|
| 119 |
} |
|
| 120 |
|
|
| 121 |
mesh.setTextureMap(maps,0); |
|
| 122 |
} |
|
| 123 |
|
|
| 66 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 67 | 125 |
|
| 68 | 126 |
private float getRotRow(int ax, float d) |
| ... | ... | |
| 248 | 306 |
} |
| 249 | 307 |
else |
| 250 | 308 |
{
|
| 251 |
for(int i=0; i<mNumCubits; i++) mCubits[i].recreateBitmap(); |
|
| 309 |
for(int i=0; i<mNumCubits; i++) |
|
| 310 |
{
|
|
| 311 |
DistortedTexture tex = mCubits[i].getTexture(); |
|
| 312 |
recreateBitmap(tex); |
|
| 313 |
} |
|
| 252 | 314 |
} |
| 253 | 315 |
} |
| 254 | 316 |
|
| 317 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 318 |
|
|
| 319 |
void recreateBitmap(DistortedTexture tex) |
|
| 320 |
{
|
|
| 321 |
if( mBitmap==null ) createBitmap(getColors()); |
|
| 322 |
tex.setTextureAlreadyInverted(mBitmap); |
|
| 323 |
} |
|
| 324 |
|
|
| 255 | 325 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 256 | 326 |
|
| 257 | 327 |
public void touchCubit(int index) |
| src/main/java/org/distorted/objectlib/helpers/ObjectSignature.java | ||
|---|---|---|
| 30 | 30 |
import org.distorted.objectlib.bandaged.BandagedObjectMegaminx; |
| 31 | 31 |
import org.distorted.objectlib.bandaged.FactoryBandagedMegaminx; |
| 32 | 32 |
import org.distorted.objectlib.bandaged.FactoryBandagedPyraminx; |
| 33 |
import org.distorted.objectlib.objects.TwistyBandagedMegaminx; |
|
| 34 |
import org.distorted.objectlib.objects.TwistyBandagedPyraminx; |
|
| 33 | 35 |
import org.distorted.objectlib.touchcontrol.TouchControlDodecahedron; |
| 34 | 36 |
|
| 35 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 162 | 164 |
|
| 163 | 165 |
char name = shortName.charAt(0); |
| 164 | 166 |
|
| 165 |
if( name == 'P' )
|
|
| 167 |
if( name == TwistyBandagedPyraminx.MARKER )
|
|
| 166 | 168 |
{
|
| 167 | 169 |
mTmp = new float[4]; |
| 168 | 170 |
int x=shortName.charAt(1)-'0'; |
| ... | ... | |
| 172 | 174 |
prepareTouchRowsPyraminx(); |
| 173 | 175 |
prepareAllCyclesPyraminx(); |
| 174 | 176 |
} |
| 175 |
else if( name == 'M' )
|
|
| 177 |
else if( name == TwistyBandagedMegaminx.MARKER )
|
|
| 176 | 178 |
{
|
| 177 | 179 |
mTmp = new float[4]; |
| 178 | 180 |
mParam=shortName.charAt(1)-'0'; |
| src/main/java/org/distorted/objectlib/objects/TwistyBandagedMegaminx.java | ||
|---|---|---|
| 34 | 34 |
public static final int MEGAMINX5 = 5; |
| 35 | 35 |
|
| 36 | 36 |
public static final String OBJECT_NAME_MEGAMINX = "LOCAL_MEGAMINX"; |
| 37 |
public static final char MARKER = 'm'; // keep lowercase |
|
| 37 | 38 |
|
| 38 | 39 |
// TODO |
| 39 | 40 |
private static final int OCT_1 = 0; |
| ... | ... | |
| 407 | 408 |
{
|
| 408 | 409 |
if( mSignature==null ) mSignature = getSignature(); |
| 409 | 410 |
int param = getInitData().getParam(); |
| 410 |
return "M"+param+"_"+mSignature.getString();
|
|
| 411 |
return MARKER+(param+"_"+mSignature.getString());
|
|
| 411 | 412 |
} |
| 412 | 413 |
|
| 413 | 414 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/objectlib/objects/TwistyBandagedPyraminx.java | ||
|---|---|---|
| 32 | 32 |
public class TwistyBandagedPyraminx extends ShapeTetrahedron |
| 33 | 33 |
{
|
| 34 | 34 |
public static final String OBJECT_NAME_PYRAMINX = "LOCAL_PYRAMINX"; |
| 35 |
public static final char MARKER = 'p'; // keep lowercase |
|
| 35 | 36 |
|
| 36 | 37 |
private static final Static3D[] ROT_AXIS = new Static3D[] |
| 37 | 38 |
{
|
| ... | ... | |
| 411 | 412 |
{
|
| 412 | 413 |
if( mSignature==null ) mSignature = getSignature(); |
| 413 | 414 |
int[] numLayers = getNumLayers(); |
| 414 |
return "P"+numLayers[0]+"_"+mSignature.getString();
|
|
| 415 |
return MARKER+(numLayers[0]+"_"+mSignature.getString());
|
|
| 415 | 416 |
} |
| 416 | 417 |
|
| 417 | 418 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
progress with TwistyBandagedMegaminx.