Revision db0d3a90
Added by Leszek Koltunski over 2 years ago
| src/main/java/org/distorted/objectlib/bandaged/BandagedCubit.java | ||
|---|---|---|
| 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 android.graphics.Bitmap; |
|
| 13 |
import android.graphics.Canvas; |
|
| 14 |
import android.graphics.Paint; |
|
| 15 |
|
|
| 16 |
import org.distorted.library.effect.EffectType; |
|
| 17 |
import org.distorted.library.effect.FragmentEffectBrightness; |
|
| 18 |
import org.distorted.library.effect.MatrixEffectMove; |
|
| 19 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
|
| 20 |
import org.distorted.library.effect.MatrixEffectScale; |
|
| 21 |
import org.distorted.library.main.DistortedEffects; |
|
| 22 |
import org.distorted.library.main.DistortedNode; |
|
| 23 |
import org.distorted.library.main.DistortedTexture; |
|
| 24 |
import org.distorted.library.helpers.QuatHelper; |
|
| 25 |
import org.distorted.library.mesh.MeshBase; |
|
| 26 |
import org.distorted.library.type.Static1D; |
|
| 27 |
import org.distorted.library.type.Static3D; |
|
| 28 |
import org.distorted.library.type.Static4D; |
|
| 29 |
import org.distorted.objectlib.helpers.FactoryCubit; |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
|
|
| 33 |
public class BandagedCubit |
|
| 34 |
{
|
|
| 35 |
private static final Static3D CENTER = new Static3D(0,0,0); |
|
| 36 |
private static final float[] mTmp = new float[4]; |
|
| 37 |
private static final Static1D mAlpha = new Static1D(2.0f); |
|
| 38 |
private static Bitmap mBitmap; |
|
| 39 |
private static Static4D[] mTextureMaps; |
|
| 40 |
|
|
| 41 |
private final BandagedObject mObject; |
|
| 42 |
private final DistortedNode mNode; |
|
| 43 |
private final DistortedEffects mEffects; |
|
| 44 |
private final DistortedTexture mTexture; |
|
| 45 |
private final Static3D mMove; |
|
| 46 |
private final int mVariant; |
|
| 47 |
private final boolean mRoundCorners; |
|
| 48 |
|
|
| 49 |
private float mUnscaledX, mUnscaledY, mUnscaledZ; |
|
| 50 |
private float[] mPosition; |
|
| 51 |
private boolean mIsAttached; |
|
| 52 |
private long mMarkedEffectID; |
|
| 53 |
|
|
| 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 |
for(int i=0; i<numComponents; i++) |
|
| 85 |
{
|
|
| 86 |
Static4D q = fact.getQuaternion(i); |
|
| 87 |
QuatHelper.rotateVectorByQuat(mTmp,0,0,1,0,q); |
|
| 88 |
int index = mObject.computeMapsIndex(mTmp); |
|
| 89 |
maps[i] = mTextureMaps[index]; |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
mesh.setTextureMap(maps,0); |
|
| 93 |
} |
|
| 94 |
|
|
| 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 96 |
|
|
| 97 |
private void computeMove(float[] position) |
|
| 98 |
{
|
|
| 99 |
int numCenters = position.length/3; |
|
| 100 |
mUnscaledX=0.0f; |
|
| 101 |
mUnscaledY=0.0f; |
|
| 102 |
mUnscaledZ=0.0f; |
|
| 103 |
|
|
| 104 |
for(int center=0; center<numCenters; center++) |
|
| 105 |
{
|
|
| 106 |
mUnscaledX += position[3*center ]; |
|
| 107 |
mUnscaledY += position[3*center+1]; |
|
| 108 |
mUnscaledZ += position[3*center+2]; |
|
| 109 |
} |
|
| 110 |
|
|
| 111 |
mUnscaledX /= numCenters; |
|
| 112 |
mUnscaledY /= numCenters; |
|
| 113 |
mUnscaledZ /= numCenters; |
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 117 |
// PUBLIC API |
|
| 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 119 |
|
|
| 120 |
public BandagedCubit(BandagedObject object, float[] position, int variant, Static4D quat1, |
|
| 121 |
Static4D quat2, Static3D scale, boolean roundCorners) |
|
| 122 |
{
|
|
| 123 |
mObject = object; |
|
| 124 |
mRoundCorners = roundCorners; |
|
| 125 |
mPosition = position; |
|
| 126 |
mIsAttached = true; |
|
| 127 |
mMarkedEffectID = -1; |
|
| 128 |
mVariant = variant; |
|
| 129 |
|
|
| 130 |
computeMove(mPosition); |
|
| 131 |
mMove = new Static3D(0,0,0); |
|
| 132 |
|
|
| 133 |
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners); |
|
| 134 |
|
|
| 135 |
mTexture = new DistortedTexture(); |
|
| 136 |
if( mBitmap==null ) createBitmap(mObject.getColors()); |
|
| 137 |
mTexture.setTextureAlreadyInverted(mBitmap); |
|
| 138 |
|
|
| 139 |
resetTextureMaps(mesh); |
|
| 140 |
|
|
| 141 |
MatrixEffectScale scaleEffect = new MatrixEffectScale(scale); |
|
| 142 |
MatrixEffectQuaternion quat1Effect = new MatrixEffectQuaternion(quat1, CENTER); |
|
| 143 |
MatrixEffectQuaternion quat2Effect = new MatrixEffectQuaternion(quat2, CENTER); |
|
| 144 |
MatrixEffectMove moveEffect = new MatrixEffectMove(mMove); |
|
| 145 |
|
|
| 146 |
mEffects = new DistortedEffects(); |
|
| 147 |
mEffects.apply(scaleEffect); |
|
| 148 |
mEffects.apply(moveEffect); |
|
| 149 |
mEffects.apply(quat2Effect); |
|
| 150 |
mEffects.apply(quat1Effect); |
|
| 151 |
|
|
| 152 |
mNode = new DistortedNode(mTexture,mEffects,mesh); |
|
| 153 |
} |
|
| 154 |
|
|
| 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 156 |
|
|
| 157 |
public void join(float[] position, float scale) |
|
| 158 |
{
|
|
| 159 |
int len1 = mPosition.length; |
|
| 160 |
int len2 = position.length; |
|
| 161 |
float[] tmpPosition = new float[len1+len2]; |
|
| 162 |
System.arraycopy(mPosition, 0, tmpPosition, 0, len1); |
|
| 163 |
System.arraycopy(position , 0, tmpPosition, len1, len2); |
|
| 164 |
mPosition = tmpPosition; |
|
| 165 |
|
|
| 166 |
computeMove(mPosition); |
|
| 167 |
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners); |
|
| 168 |
resetTextureMaps(mesh); |
|
| 169 |
mNode.setMesh(mesh); |
|
| 170 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
|
| 171 |
} |
|
| 172 |
|
|
| 173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 174 |
|
|
| 175 |
public void reset(float scale) |
|
| 176 |
{
|
|
| 177 |
float x = mPosition[0]; |
|
| 178 |
float y = mPosition[1]; |
|
| 179 |
float z = mPosition[2]; |
|
| 180 |
|
|
| 181 |
mPosition = new float[3]; |
|
| 182 |
mPosition[0] = x; |
|
| 183 |
mPosition[1] = y; |
|
| 184 |
mPosition[2] = z; |
|
| 185 |
|
|
| 186 |
computeMove(mPosition); |
|
| 187 |
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners); |
|
| 188 |
resetTextureMaps(mesh); |
|
| 189 |
mNode.setMesh(mesh); |
|
| 190 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
|
| 191 |
} |
|
| 192 |
|
|
| 193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 194 |
|
|
| 195 |
public void recreateBitmap() |
|
| 196 |
{
|
|
| 197 |
if( mBitmap==null ) createBitmap(mObject.getColors()); |
|
| 198 |
mTexture.setTextureAlreadyInverted(mBitmap); |
|
| 199 |
} |
|
| 200 |
|
|
| 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 202 |
|
|
| 203 |
public void scaleMove(float scale) |
|
| 204 |
{
|
|
| 205 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
|
| 206 |
} |
|
| 207 |
|
|
| 208 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 209 |
|
|
| 210 |
public void setMarked() |
|
| 211 |
{
|
|
| 212 |
if( mMarkedEffectID<0 ) |
|
| 213 |
{
|
|
| 214 |
FragmentEffectBrightness effect = new FragmentEffectBrightness(mAlpha); |
|
| 215 |
mMarkedEffectID = effect.getID(); |
|
| 216 |
mEffects.apply(effect); |
|
| 217 |
} |
|
| 218 |
} |
|
| 219 |
|
|
| 220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 221 |
|
|
| 222 |
public void setUnmarked() |
|
| 223 |
{
|
|
| 224 |
mEffects.abortByType(EffectType.FRAGMENT); |
|
| 225 |
mMarkedEffectID = -1; |
|
| 226 |
} |
|
| 227 |
|
|
| 228 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 229 |
|
|
| 230 |
public void detach() |
|
| 231 |
{
|
|
| 232 |
mIsAttached = false; |
|
| 233 |
} |
|
| 234 |
|
|
| 235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 236 |
|
|
| 237 |
public void attach() |
|
| 238 |
{
|
|
| 239 |
mIsAttached = true; |
|
| 240 |
} |
|
| 241 |
|
|
| 242 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 243 |
|
|
| 244 |
public boolean isAttached() |
|
| 245 |
{
|
|
| 246 |
return mIsAttached; |
|
| 247 |
} |
|
| 248 |
|
|
| 249 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 250 |
|
|
| 251 |
public float[] getPosition() |
|
| 252 |
{
|
|
| 253 |
return mPosition; |
|
| 254 |
} |
|
| 255 |
|
|
| 256 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 257 |
|
|
| 258 |
public DistortedNode getNode() |
|
| 259 |
{
|
|
| 260 |
return mNode; |
|
| 261 |
} |
|
| 262 |
} |
|
| 263 |
|
|
| src/main/java/org/distorted/objectlib/bandaged/BandagedElement.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2023 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 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 13 |
|
|
| 14 |
public class BandagedElement |
|
| 15 |
{
|
|
| 16 |
private final float[][] mCuts; |
|
| 17 |
private final int[] mNumCuts; |
|
| 18 |
private final float[][] mRotAxis; |
|
| 19 |
private final int[] mRotationRow; |
|
| 20 |
private final float[] mPos; |
|
| 21 |
private final int mVariant; |
|
| 22 |
|
|
| 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 24 |
|
|
| 25 |
BandagedElement(float[] pos, int index, float[][] rotAxis, float[][] cuts, int variant) |
|
| 26 |
{
|
|
| 27 |
mPos = new float[] { pos[index], pos[index+1], pos[index+2] };
|
|
| 28 |
|
|
| 29 |
int numAxis = rotAxis.length; |
|
| 30 |
mRotAxis = rotAxis; |
|
| 31 |
mRotationRow = new int[numAxis]; |
|
| 32 |
mNumCuts = new int[numAxis]; |
|
| 33 |
mCuts = cuts; |
|
| 34 |
mVariant = variant; |
|
| 35 |
|
|
| 36 |
for(int i=0; i<numAxis; i++) |
|
| 37 |
{
|
|
| 38 |
mNumCuts[i] = (mCuts==null || mCuts[i]==null ? 0 : mCuts[i].length); |
|
| 39 |
mRotationRow[i] = computeRow(i); |
|
| 40 |
} |
|
| 41 |
} |
|
| 42 |
|
|
| 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 44 |
|
|
| 45 |
private int computeRow(int rotAx) |
|
| 46 |
{
|
|
| 47 |
float[] ax = mRotAxis[rotAx]; |
|
| 48 |
float casted = mPos[0]*ax[0] + mPos[1]*ax[1] + mPos[2]*ax[2]; |
|
| 49 |
int num = mNumCuts[rotAx]; |
|
| 50 |
float[] cuts = mCuts[rotAx]; |
|
| 51 |
|
|
| 52 |
for(int i=0; i<num; i++) |
|
| 53 |
if( casted<cuts[i] ) return i; |
|
| 54 |
|
|
| 55 |
return num; |
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 59 |
|
|
| 60 |
int[] getRotRow() |
|
| 61 |
{
|
|
| 62 |
return mRotationRow; |
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 66 |
|
|
| 67 |
float[] getPos() |
|
| 68 |
{
|
|
| 69 |
return mPos; |
|
| 70 |
} |
|
| 71 |
|
|
| 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 73 |
|
|
| 74 |
int getVariant() |
|
| 75 |
{
|
|
| 76 |
return mVariant; |
|
| 77 |
} |
|
| 78 |
} |
|
| src/main/java/org/distorted/objectlib/bandaged/BandagedObject.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2023 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.main.DistortedNode; |
|
| 13 |
import org.distorted.library.main.DistortedScreen; |
|
| 14 |
import org.distorted.library.mesh.MeshBase; |
|
| 15 |
import org.distorted.library.type.Static3D; |
|
| 16 |
import org.distorted.library.type.Static4D; |
|
| 17 |
import org.distorted.objectlib.main.TwistyObject; |
|
| 18 |
|
|
| 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
public abstract class BandagedObject |
|
| 22 |
{
|
|
| 23 |
private final DistortedScreen mScreen; |
|
| 24 |
private final float[][] mFaceAxis; |
|
| 25 |
private BandagedCubit[] mCubits; |
|
| 26 |
|
|
| 27 |
final int[] mSize; |
|
| 28 |
final float mDist2D; |
|
| 29 |
|
|
| 30 |
int mMax; |
|
| 31 |
int mNumCubits; |
|
| 32 |
|
|
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 35 |
BandagedObject(DistortedScreen screen) |
|
| 36 |
{
|
|
| 37 |
mScreen = screen; |
|
| 38 |
mSize = new int[3]; |
|
| 39 |
mDist2D = getDist2D(); |
|
| 40 |
Static3D[] axis = getFaceAxis(); |
|
| 41 |
int numAxis = axis.length; |
|
| 42 |
mFaceAxis = new float[numAxis][]; |
|
| 43 |
for(int i=0; i<numAxis; i++) mFaceAxis[i] = new float[] { axis[i].get0(), axis[i].get1(), axis[1].get2() };
|
|
| 44 |
} |
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 48 |
abstract float getDist2D(); |
|
| 49 |
abstract int[] getColors(); |
|
| 50 |
abstract float[][][] getPositions(); |
|
| 51 |
abstract boolean isAdjacent(float dx, float dy, float dz); |
|
| 52 |
abstract MeshBase createMesh(float[] pos, boolean round); |
|
| 53 |
|
|
| 54 |
public abstract TwistyObject createObject(int mode, float scale ); |
|
| 55 |
public abstract float[] getDist3D(); |
|
| 56 |
public abstract int computeProjectionAngle(); |
|
| 57 |
public abstract boolean tryChangeObject(int x, int y, int z); |
|
| 58 |
public abstract boolean isInsideFace(int face, float[] p); |
|
| 59 |
public abstract Static3D[] getFaceAxis(); |
|
| 60 |
|
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 |
|
|
| 63 |
public void createCubits(Static4D quatT, Static4D quatA, Static3D scale) |
|
| 64 |
{
|
|
| 65 |
mCubits = new BandagedCubit[mNumCubits]; |
|
| 66 |
float[][][] pos = getPositions(); |
|
| 67 |
int c=0,numVariants = pos.length; |
|
| 68 |
|
|
| 69 |
for(int v=0; v<numVariants; v++) |
|
| 70 |
{
|
|
| 71 |
int numCubits = pos[v].length; |
|
| 72 |
|
|
| 73 |
for(int vi=0; vi<numCubits; vi++) |
|
| 74 |
mCubits[c++] = new BandagedCubit(this,pos[v][vi],v,quatT,quatA,scale,false); |
|
| 75 |
} |
|
| 76 |
} |
|
| 77 |
|
|
| 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 79 |
|
|
| 80 |
int computeMapsIndex(float[] faceAx) |
|
| 81 |
{
|
|
| 82 |
int min=-1, numAxis = mFaceAxis.length; |
|
| 83 |
float error = Float.MAX_VALUE; |
|
| 84 |
float x = faceAx[0]; |
|
| 85 |
float y = faceAx[1]; |
|
| 86 |
float z = faceAx[2]; |
|
| 87 |
|
|
| 88 |
for(int i=0; i<numAxis; i++) |
|
| 89 |
{
|
|
| 90 |
float[] ax = mFaceAxis[i]; |
|
| 91 |
float dx = x-ax[0]; |
|
| 92 |
float dy = y-ax[1]; |
|
| 93 |
float dz = z-ax[2]; |
|
| 94 |
|
|
| 95 |
float diff = dx*dx + dy*dy + dz*dz; |
|
| 96 |
|
|
| 97 |
if( error>diff ) |
|
| 98 |
{
|
|
| 99 |
error = diff; |
|
| 100 |
min = i; |
|
| 101 |
} |
|
| 102 |
} |
|
| 103 |
|
|
| 104 |
return min; |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 108 |
|
|
| 109 |
public void resetObject(float scale) |
|
| 110 |
{
|
|
| 111 |
for(int c=0; c<mNumCubits; c++) |
|
| 112 |
{
|
|
| 113 |
if( !mCubits[c].isAttached() ) |
|
| 114 |
{
|
|
| 115 |
mCubits[c].attach(); |
|
| 116 |
mScreen.attach(mCubits[c].getNode()); |
|
| 117 |
} |
|
| 118 |
if( mCubits[c].getPosition().length>3 ) |
|
| 119 |
{
|
|
| 120 |
mCubits[c].reset(scale); |
|
| 121 |
} |
|
| 122 |
mCubits[c].setUnmarked(); |
|
| 123 |
} |
|
| 124 |
} |
|
| 125 |
|
|
| 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 127 |
|
|
| 128 |
public float getMaxSize() |
|
| 129 |
{
|
|
| 130 |
return mMax; |
|
| 131 |
} |
|
| 132 |
|
|
| 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 134 |
|
|
| 135 |
float[][] getCubitPositions() |
|
| 136 |
{
|
|
| 137 |
int numAttached = 0; |
|
| 138 |
|
|
| 139 |
for(int i=0; i<mNumCubits; i++) |
|
| 140 |
if( mCubits[i].isAttached() ) numAttached++; |
|
| 141 |
|
|
| 142 |
float[][] pos = new float[numAttached][]; |
|
| 143 |
int attached=0; |
|
| 144 |
|
|
| 145 |
for(int i=0; i<mNumCubits; i++) |
|
| 146 |
if( mCubits[i].isAttached() ) |
|
| 147 |
{
|
|
| 148 |
pos[attached++] = mCubits[i].getPosition(); |
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
return pos; |
|
| 152 |
} |
|
| 153 |
|
|
| 154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 155 |
|
|
| 156 |
public void tryConnectingCubits(int index1, int index2, float scale) |
|
| 157 |
{
|
|
| 158 |
if( index1!=index2 ) |
|
| 159 |
{
|
|
| 160 |
float[] pos1 = mCubits[index1].getPosition(); |
|
| 161 |
float[] pos2 = mCubits[index2].getPosition(); |
|
| 162 |
|
|
| 163 |
if( isAdjacent(pos1,pos2) ) |
|
| 164 |
{
|
|
| 165 |
mCubits[index2].join(pos1,scale); |
|
| 166 |
mCubits[index1].detach(); |
|
| 167 |
mScreen.detach(mCubits[index1].getNode()); |
|
| 168 |
} |
|
| 169 |
} |
|
| 170 |
} |
|
| 171 |
|
|
| 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 173 |
|
|
| 174 |
public void attachCubits(float scale) |
|
| 175 |
{
|
|
| 176 |
for(int i=0; i<mNumCubits; i++) |
|
| 177 |
{
|
|
| 178 |
mCubits[i].scaleMove(scale); |
|
| 179 |
DistortedNode node = mCubits[i].getNode(); |
|
| 180 |
mScreen.attach(node); |
|
| 181 |
} |
|
| 182 |
} |
|
| 183 |
|
|
| 184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 185 |
|
|
| 186 |
public void attachAndMarkCubits(float scale, int touched) |
|
| 187 |
{
|
|
| 188 |
for(int i=0; i<mNumCubits; i++) |
|
| 189 |
{
|
|
| 190 |
if( mCubits[i].isAttached() ) |
|
| 191 |
{
|
|
| 192 |
mCubits[i].scaleMove(scale); |
|
| 193 |
if( touched==i ) mCubits[i].setMarked(); |
|
| 194 |
else mCubits[i].setUnmarked(); |
|
| 195 |
DistortedNode node = mCubits[i].getNode(); |
|
| 196 |
mScreen.attach(node); |
|
| 197 |
} |
|
| 198 |
} |
|
| 199 |
} |
|
| 200 |
|
|
| 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 202 |
|
|
| 203 |
public void scaleCubits(float scale) |
|
| 204 |
{
|
|
| 205 |
for(int i=0; i<mNumCubits; i++) mCubits[i].scaleMove(scale); |
|
| 206 |
} |
|
| 207 |
|
|
| 208 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 209 |
|
|
| 210 |
public void recreateCubits(Static4D quatT, Static4D quatA, Static3D scale) |
|
| 211 |
{
|
|
| 212 |
if( mCubits==null ) |
|
| 213 |
{
|
|
| 214 |
createCubits(quatT,quatA,scale); |
|
| 215 |
} |
|
| 216 |
else |
|
| 217 |
{
|
|
| 218 |
for(int i=0; i<mNumCubits; i++) mCubits[i].recreateBitmap(); |
|
| 219 |
} |
|
| 220 |
} |
|
| 221 |
|
|
| 222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 223 |
|
|
| 224 |
public void touchCubit(int index) |
|
| 225 |
{
|
|
| 226 |
if( index>=0 && index<mNumCubits && mCubits[index]!=null ) mCubits[index].setMarked(); |
|
| 227 |
} |
|
| 228 |
|
|
| 229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 230 |
|
|
| 231 |
public void untouchCubit(int index) |
|
| 232 |
{
|
|
| 233 |
if( index>=0 && index<mNumCubits && mCubits[index]!=null ) mCubits[index].setUnmarked(); |
|
| 234 |
} |
|
| 235 |
|
|
| 236 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 237 |
|
|
| 238 |
public int whichCubitTouched(float[] point3D) |
|
| 239 |
{
|
|
| 240 |
float x = point3D[0]*mMax; |
|
| 241 |
float y = point3D[1]*mMax; |
|
| 242 |
float z = point3D[2]*mMax; |
|
| 243 |
|
|
| 244 |
int minIndex = -1; |
|
| 245 |
float minDist = Float.MAX_VALUE; |
|
| 246 |
|
|
| 247 |
for(int c=0; c<mNumCubits; c++) |
|
| 248 |
if( mCubits[c].isAttached() ) |
|
| 249 |
{
|
|
| 250 |
float[] pos = mCubits[c].getPosition(); |
|
| 251 |
int len = pos.length/3; |
|
| 252 |
|
|
| 253 |
for(int p=0; p<len; p++) |
|
| 254 |
{
|
|
| 255 |
float dx = pos[3*p ]-x; |
|
| 256 |
float dy = pos[3*p+1]-y; |
|
| 257 |
float dz = pos[3*p+2]-z; |
|
| 258 |
float dist = dx*dx + dy*dy + dz*dz; |
|
| 259 |
|
|
| 260 |
if( dist<minDist ) |
|
| 261 |
{
|
|
| 262 |
minDist = dist; |
|
| 263 |
minIndex = c; |
|
| 264 |
} |
|
| 265 |
} |
|
| 266 |
} |
|
| 267 |
|
|
| 268 |
return minIndex; |
|
| 269 |
} |
|
| 270 |
|
|
| 271 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 272 |
|
|
| 273 |
boolean isAdjacent(float[] pos1, float[] pos2) |
|
| 274 |
{
|
|
| 275 |
int len1 = pos1.length/3; |
|
| 276 |
int len2 = pos2.length/3; |
|
| 277 |
|
|
| 278 |
for(int i=0; i<len1; i++) |
|
| 279 |
for(int j=0; j<len2; j++) |
|
| 280 |
{
|
|
| 281 |
float dx = pos1[3*i ] - pos2[3*j ]; |
|
| 282 |
float dy = pos1[3*i+1] - pos2[3*j+1]; |
|
| 283 |
float dz = pos1[3*i+2] - pos2[3*j+2]; |
|
| 284 |
|
|
| 285 |
if( isAdjacent(dx,dy,dz) ) return true; |
|
| 286 |
} |
|
| 287 |
|
|
| 288 |
return false; |
|
| 289 |
} |
|
| 290 |
} |
|
| src/main/java/org/distorted/objectlib/bandaged/BandagedObjectCuboid.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2023 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.main.DistortedScreen; |
|
| 13 |
import org.distorted.library.mesh.MeshBase; |
|
| 14 |
import org.distorted.library.type.Static3D; |
|
| 15 |
import org.distorted.objectlib.main.InitData; |
|
| 16 |
import org.distorted.objectlib.main.TwistyObject; |
|
| 17 |
import org.distorted.objectlib.objects.TwistyBandagedCuboid; |
|
| 18 |
import org.distorted.objectlib.shape.ShapeHexahedron; |
|
| 19 |
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron; |
|
| 20 |
|
|
| 21 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 22 |
|
|
| 23 |
public class BandagedObjectCuboid extends BandagedObject |
|
| 24 |
{
|
|
| 25 |
float getDist2D() |
|
| 26 |
{
|
|
| 27 |
return 0.5f; |
|
| 28 |
} |
|
| 29 |
|
|
| 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 31 |
|
|
| 32 |
int[] getColors() |
|
| 33 |
{
|
|
| 34 |
return ShapeHexahedron.FACE_COLORS; |
|
| 35 |
} |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
boolean isAdjacent(float dx, float dy, float dz) |
|
| 40 |
{
|
|
| 41 |
return dx*dx + dy*dy + dz*dz <= 1; |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 46 |
float[][][] getPositions() |
|
| 47 |
{
|
|
| 48 |
float[][][] pos = new float[1][mNumCubits][]; |
|
| 49 |
int c=0; |
|
| 50 |
int sx = mSize[0]; |
|
| 51 |
int sy = mSize[1]; |
|
| 52 |
int sz = mSize[2]; |
|
| 53 |
|
|
| 54 |
float begX = 0.5f*(1-sx); |
|
| 55 |
float begY = 0.5f*(1-sy); |
|
| 56 |
float begZ = 0.5f*(1-sz); |
|
| 57 |
|
|
| 58 |
for(int x=0; x<sx; x++) |
|
| 59 |
for(int y=0; y<sy; y++) |
|
| 60 |
for(int z=0; z<sz; z++) |
|
| 61 |
if( x==0 || x==sx-1 || y==0 || y==sy-1 || z==0 || z==sz-1 ) |
|
| 62 |
{
|
|
| 63 |
pos[0][c++] = new float[] { begX+x,begY+y,begZ+z };
|
|
| 64 |
} |
|
| 65 |
|
|
| 66 |
return pos; |
|
| 67 |
} |
|
| 68 |
|
|
| 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 70 |
|
|
| 71 |
MeshBase createMesh(float[] pos, boolean round) |
|
| 72 |
{
|
|
| 73 |
FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance(); |
|
| 74 |
return factory.createMesh(pos,mSize,false,round); |
|
| 75 |
} |
|
| 76 |
|
|
| 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 78 |
// PUBLIC API |
|
| 79 |
|
|
| 80 |
public BandagedObjectCuboid(DistortedScreen screen) |
|
| 81 |
{
|
|
| 82 |
super(screen); |
|
| 83 |
} |
|
| 84 |
|
|
| 85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 86 |
|
|
| 87 |
public float[] getDist3D() |
|
| 88 |
{
|
|
| 89 |
float max = mMax; |
|
| 90 |
|
|
| 91 |
float x = 0.5f*(mSize[0]/max); |
|
| 92 |
float y = 0.5f*(mSize[1]/max); |
|
| 93 |
float z = 0.5f*(mSize[2]/max); |
|
| 94 |
|
|
| 95 |
return new float[] {x,x,y,y,z,z};
|
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 99 |
|
|
| 100 |
public Static3D[] getFaceAxis() |
|
| 101 |
{
|
|
| 102 |
return TouchControlHexahedron.FACE_AXIS; |
|
| 103 |
} |
|
| 104 |
|
|
| 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 106 |
|
|
| 107 |
public boolean isInsideFace(int face, float[] p) |
|
| 108 |
{
|
|
| 109 |
float max = mMax; |
|
| 110 |
|
|
| 111 |
switch(face/2) |
|
| 112 |
{
|
|
| 113 |
case 0: p[0] *= (max/mSize[2]); p[1] *= (max/mSize[1]); break; |
|
| 114 |
case 1: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[2]); break; |
|
| 115 |
case 2: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[1]); break; |
|
| 116 |
} |
|
| 117 |
|
|
| 118 |
return ( p[0]<=mDist2D && p[0]>=-mDist2D && p[1]<=mDist2D && p[1]>=-mDist2D ); |
|
| 119 |
} |
|
| 120 |
|
|
| 121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 122 |
|
|
| 123 |
public int computeProjectionAngle() |
|
| 124 |
{
|
|
| 125 |
float quot1 = mSize[2]/ (float)mSize[0]; |
|
| 126 |
float quot2 = mSize[2]/ (float)mSize[1]; |
|
| 127 |
float quot3 = mSize[0]/ (float)mSize[2]; |
|
| 128 |
float quot4 = mSize[0]/ (float)mSize[1]; |
|
| 129 |
|
|
| 130 |
float quot5 = Math.max(quot1,quot2); |
|
| 131 |
float quot6 = Math.max(quot3,quot4); |
|
| 132 |
float quot7 = Math.max(quot5,quot6); |
|
| 133 |
|
|
| 134 |
if( quot7<=1.0f ) return 120; |
|
| 135 |
else if( quot7<=1.5f ) return 90; |
|
| 136 |
else if( quot7<=2.0f ) return 60; |
|
| 137 |
else return 30; |
|
| 138 |
} |
|
| 139 |
|
|
| 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 141 |
|
|
| 142 |
public boolean tryChangeObject(int x, int y, int z) |
|
| 143 |
{
|
|
| 144 |
if( mSize[0]!=x || mSize[1]!=y || mSize[2]!=z ) |
|
| 145 |
{
|
|
| 146 |
mSize[0] = x; |
|
| 147 |
mSize[1] = y; |
|
| 148 |
mSize[2] = z; |
|
| 149 |
mMax = x>y ? Math.max(x,z) : Math.max(y,z); |
|
| 150 |
mNumCubits = ( x<=1 || y<=1 || z<=1 ) ? x*y*z : x*y*z-(x-2)*(y-2)*(z-2); |
|
| 151 |
return true; |
|
| 152 |
} |
|
| 153 |
|
|
| 154 |
return false; |
|
| 155 |
} |
|
| 156 |
|
|
| 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 158 |
|
|
| 159 |
public TwistyObject createObject(int mode, float size) |
|
| 160 |
{
|
|
| 161 |
float[][] pos = getCubitPositions(); |
|
| 162 |
InitData data = new InitData( mSize,pos); |
|
| 163 |
return new TwistyBandagedCuboid( TwistyObject.MESH_NICE, mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null ); |
|
| 164 |
} |
|
| 165 |
} |
|
| src/main/java/org/distorted/objectlib/bandaged/BandagedObjectPyraminx.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2023 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 static org.distorted.objectlib.main.TwistyObject.SQ2; |
|
| 13 |
import static org.distorted.objectlib.main.TwistyObject.SQ3; |
|
| 14 |
import static org.distorted.objectlib.main.TwistyObject.SQ6; |
|
| 15 |
|
|
| 16 |
import org.distorted.library.main.DistortedScreen; |
|
| 17 |
import org.distorted.library.mesh.MeshBase; |
|
| 18 |
import org.distorted.library.type.Static3D; |
|
| 19 |
import org.distorted.objectlib.main.InitData; |
|
| 20 |
import org.distorted.objectlib.main.TwistyObject; |
|
| 21 |
import org.distorted.objectlib.objects.TwistyBandagedPyraminx; |
|
| 22 |
import org.distorted.objectlib.shape.ShapeTetrahedron; |
|
| 23 |
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron; |
|
| 24 |
|
|
| 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 26 |
|
|
| 27 |
public class BandagedObjectPyraminx extends BandagedObject |
|
| 28 |
{
|
|
| 29 |
private boolean isFaceInverted(int face) |
|
| 30 |
{
|
|
| 31 |
return face>1; |
|
| 32 |
} |
|
| 33 |
|
|
| 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 35 |
|
|
| 36 |
private void addTetrahedralLattice(int size, float[][] pos) |
|
| 37 |
{
|
|
| 38 |
final float DX = 1.0f; |
|
| 39 |
final float DY = SQ2/2; |
|
| 40 |
final float DZ = 1.0f; |
|
| 41 |
|
|
| 42 |
float startX = 0.0f; |
|
| 43 |
float startY =-DY*(size-1)/2; |
|
| 44 |
float startZ = DZ*(size-1)/2; |
|
| 45 |
|
|
| 46 |
int index = 0; |
|
| 47 |
|
|
| 48 |
for(int layer=0; layer<size; layer++) |
|
| 49 |
{
|
|
| 50 |
float currX = startX; |
|
| 51 |
float currY = startY; |
|
| 52 |
|
|
| 53 |
for(int x=0; x<layer+1; x++) |
|
| 54 |
{
|
|
| 55 |
float currZ = startZ; |
|
| 56 |
|
|
| 57 |
for(int z=0; z<size-layer; z++) |
|
| 58 |
{
|
|
| 59 |
pos[index] = new float[] {currX,currY,currZ};
|
|
| 60 |
index++; |
|
| 61 |
currZ -= DZ; |
|
| 62 |
} |
|
| 63 |
|
|
| 64 |
currX += DX; |
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
startX-=DX/2; |
|
| 68 |
startY+=DY; |
|
| 69 |
startZ-=DZ/2; |
|
| 70 |
} |
|
| 71 |
} |
|
| 72 |
|
|
| 73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 74 |
|
|
| 75 |
float getDist2D() |
|
| 76 |
{
|
|
| 77 |
return SQ3/6; |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
|
|
| 82 |
int[] getColors() |
|
| 83 |
{
|
|
| 84 |
return ShapeTetrahedron.FACE_COLORS; |
|
| 85 |
} |
|
| 86 |
|
|
| 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 88 |
|
|
| 89 |
boolean isAdjacent(float dx, float dy, float dz) |
|
| 90 |
{
|
|
| 91 |
return dx*dx + dy*dy + dz*dz < (SQ3/4)*1.01f; |
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 95 |
|
|
| 96 |
float[][][] getPositions() |
|
| 97 |
{
|
|
| 98 |
int num = mSize[0]; |
|
| 99 |
int numO= (num-1)*num*(num+1)/6; |
|
| 100 |
int numT= (num+1)*num*(num+2)/6; |
|
| 101 |
|
|
| 102 |
float[][] retO = new float[numO][]; |
|
| 103 |
float[][] retT = new float[numT][]; |
|
| 104 |
|
|
| 105 |
addTetrahedralLattice(num-1,retO); |
|
| 106 |
addTetrahedralLattice(num ,retT); |
|
| 107 |
|
|
| 108 |
return new float[][][] { retO,retT };
|
|
| 109 |
} |
|
| 110 |
|
|
| 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 112 |
|
|
| 113 |
MeshBase createMesh(float[] pos, boolean round) |
|
| 114 |
{
|
|
| 115 |
FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance(); |
|
| 116 |
return factory.createMesh(pos,mSize,false,round); |
|
| 117 |
} |
|
| 118 |
|
|
| 119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 120 |
// PUBLIC API |
|
| 121 |
|
|
| 122 |
public BandagedObjectPyraminx(DistortedScreen screen) |
|
| 123 |
{
|
|
| 124 |
super(screen); |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
|
|
| 129 |
public float[] getDist3D() |
|
| 130 |
{
|
|
| 131 |
float d = mSize[0]*SQ6/12; |
|
| 132 |
return new float[] {d,d,d,d};
|
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 136 |
|
|
| 137 |
public Static3D[] getFaceAxis() |
|
| 138 |
{
|
|
| 139 |
return TouchControlTetrahedron.FACE_AXIS; |
|
| 140 |
} |
|
| 141 |
|
|
| 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 143 |
|
|
| 144 |
public boolean tryChangeObject(int x, int y, int z) |
|
| 145 |
{
|
|
| 146 |
if( mSize[0]!=x ) |
|
| 147 |
{
|
|
| 148 |
mSize[0] = x; |
|
| 149 |
mMax = mSize[0]; |
|
| 150 |
int numOcta = (x-1)*x*(x+1)/6; |
|
| 151 |
int numTetra= x*(x+1)*(x+2)/6; |
|
| 152 |
mNumCubits = numOcta + numTetra; |
|
| 153 |
return true; |
|
| 154 |
} |
|
| 155 |
|
|
| 156 |
return false; |
|
| 157 |
} |
|
| 158 |
|
|
| 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 160 |
|
|
| 161 |
public int computeProjectionAngle() |
|
| 162 |
{
|
|
| 163 |
return 120; |
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 167 |
|
|
| 168 |
public boolean isInsideFace(int face, float[] p) |
|
| 169 |
{
|
|
| 170 |
float y = (isFaceInverted(face) ? p[1] : -p[1]); |
|
| 171 |
float x = p[0]; |
|
| 172 |
return (y >= -mDist2D) && (y <= mDist2D*(2-6*x)) && (y <= mDist2D*(2+6*x)); |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 176 |
|
|
| 177 |
public TwistyObject createObject(int mode, float size) |
|
| 178 |
{
|
|
| 179 |
float[][] pos = getCubitPositions(); |
|
| 180 |
InitData data = new InitData( mSize,pos); |
|
| 181 |
return new TwistyBandagedPyraminx( TwistyObject.MESH_NICE, mode, ShapeTetrahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null ); |
|
| 182 |
} |
|
| 183 |
} |
|
| src/main/java/org/distorted/objectlib/bandaged/FactoryBandaged.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2023 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 static org.distorted.objectlib.main.TwistyObject.MESH_NICE; |
|
| 13 |
import static org.distorted.objectlib.objects.TwistyBandagedCuboid.REGION_SIZE; |
|
| 14 |
import static org.distorted.objectlib.objects.TwistyBandagedCuboid.STRENGTH; |
|
| 15 |
|
|
| 16 |
import org.distorted.library.mesh.MeshBase; |
|
| 17 |
import org.distorted.library.type.Static3D; |
|
| 18 |
import org.distorted.objectlib.helpers.FactoryCubit; |
|
| 19 |
import org.distorted.objectlib.helpers.ObjectFaceShape; |
|
| 20 |
import org.distorted.objectlib.helpers.ObjectShape; |
|
| 21 |
import org.distorted.objectlib.helpers.ObjectVertexEffects; |
|
| 22 |
|
|
| 23 |
import java.util.ArrayList; |
|
| 24 |
|
|
| 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 26 |
|
|
| 27 |
abstract public class FactoryBandaged |
|
| 28 |
{
|
|
| 29 |
private ArrayList<float[]> mTmpArray; |
|
| 30 |
private float[] mDist3D; |
|
| 31 |
private int[][] mFaceBelongsBitmap; |
|
| 32 |
private float[][] mCuts; |
|
| 33 |
private float[][] mRotAxis; |
|
| 34 |
|
|
| 35 |
BandagedElement[] mElements; |
|
| 36 |
ArrayList<float[][]> mVertexArray; |
|
| 37 |
|
|
| 38 |
int[][] mBandIndices; |
|
| 39 |
float[][][] mVertices; |
|
| 40 |
int[][][][] mIndices; |
|
| 41 |
float[][] mMove; |
|
| 42 |
int mNumElements; |
|
| 43 |
int mNumFaces; |
|
| 44 |
int mNumAxis; |
|
| 45 |
Static3D[] mNormals; |
|
| 46 |
|
|
| 47 |
int[] mNumLayers; |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
FactoryBandaged() |
|
| 52 |
{
|
|
| 53 |
|
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 58 |
abstract float faceDiameter(float[][] vertices, int[][] indices); |
|
| 59 |
abstract Static3D[] getNormals(); |
|
| 60 |
abstract float[] getDist3D(); |
|
| 61 |
abstract float[][] getBands(boolean iconMode); |
|
| 62 |
abstract float[][] getCuts(int[] numLayers); |
|
| 63 |
abstract float[][] getRotAxis(); |
|
| 64 |
abstract float[] elementVertices(int ax, boolean left, int element); |
|
| 65 |
abstract int getElementVariant(int index); |
|
| 66 |
|
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
|
|
| 69 |
int[] computeFaceBelongsBitmap(float[][] vertices, float[] move) |
|
| 70 |
{
|
|
| 71 |
int numVerts = vertices.length; |
|
| 72 |
int[] ret = new int[numVerts]; |
|
| 73 |
|
|
| 74 |
for(int i=0; i<numVerts; i++) |
|
| 75 |
{
|
|
| 76 |
int vertBelongsBitmap=0x00000000; |
|
| 77 |
float[] vert=vertices[i]; |
|
| 78 |
|
|
| 79 |
for(int j=0; j<mNumFaces; j++) |
|
| 80 |
if( vertInFace(vert, move, mNormals[j], mDist3D[j]) ) vertBelongsBitmap |= (1<<j); |
|
| 81 |
|
|
| 82 |
ret[i]=vertBelongsBitmap; |
|
| 83 |
} |
|
| 84 |
|
|
| 85 |
return ret; |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 89 |
// return array of: |
|
| 90 |
// 0 if this is an inner face, 1 if its diameter is 1, 2 if diameter is 2, 3 if 3, etc |
|
| 91 |
// but only up to 5 (because the number of bands is 6 - see createIrregularFaceShape() ) |
|
| 92 |
|
|
| 93 |
int[] generateBandIndices(float[][] vertices, int[][][] indices, int[] belongs) |
|
| 94 |
{
|
|
| 95 |
int numCubitFaces = indices.length; |
|
| 96 |
int[] bandIndices = new int[numCubitFaces]; |
|
| 97 |
|
|
| 98 |
for(int f=0; f<numCubitFaces; f++) |
|
| 99 |
{
|
|
| 100 |
bandIndices[f] = 0xffffffff; |
|
| 101 |
for( int index : indices[f][0] ) bandIndices[f] &= belongs[index]; |
|
| 102 |
|
|
| 103 |
if( bandIndices[f]!=0 ) // outer face |
|
| 104 |
{
|
|
| 105 |
float diameter = faceDiameter(vertices, indices[f]); |
|
| 106 |
bandIndices[f] = (diameter>=6 ? 5: (int)diameter); |
|
| 107 |
} |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
return bandIndices; |
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 114 |
|
|
| 115 |
void computeMove(float[] pos, int variant) |
|
| 116 |
{
|
|
| 117 |
int numMoves = pos.length/3; |
|
| 118 |
float[] m = mMove[variant]; |
|
| 119 |
m[0]=0.0f; |
|
| 120 |
m[1]=0.0f; |
|
| 121 |
m[2]=0.0f; |
|
| 122 |
|
|
| 123 |
for(int i=0; i<numMoves; i++) |
|
| 124 |
{
|
|
| 125 |
m[0] += pos[3*i ]; |
|
| 126 |
m[1] += pos[3*i+1]; |
|
| 127 |
m[2] += pos[3*i+2]; |
|
| 128 |
} |
|
| 129 |
|
|
| 130 |
m[0]/=numMoves; |
|
| 131 |
m[1]/=numMoves; |
|
| 132 |
m[2]/=numMoves; |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 136 |
|
|
| 137 |
float[][] getVertices(ArrayList<float[][]> list, int variant) |
|
| 138 |
{
|
|
| 139 |
int total = 0; |
|
| 140 |
int length = list.size(); |
|
| 141 |
float[][][] vertices = new float[length][][]; |
|
| 142 |
|
|
| 143 |
for( int i=0; i<length; i++ ) |
|
| 144 |
{
|
|
| 145 |
vertices[i] = list.get(i); |
|
| 146 |
int len = vertices[i].length; |
|
| 147 |
for(int j=0; j<len; j++) total += vertices[i][j].length/3; |
|
| 148 |
} |
|
| 149 |
|
|
| 150 |
float[][] verts = new float[total][3]; |
|
| 151 |
int pointer = 0; |
|
| 152 |
|
|
| 153 |
for(int i=0; i<length; i++) |
|
| 154 |
{
|
|
| 155 |
int len = vertices[i].length; |
|
| 156 |
|
|
| 157 |
for(int j=0; j<len; j++) |
|
| 158 |
{
|
|
| 159 |
float[] v = vertices[i][j]; |
|
| 160 |
int l = v.length/3; |
|
| 161 |
|
|
| 162 |
for(int k=0; k<l; k++) |
|
| 163 |
{
|
|
| 164 |
verts[pointer][0] = v[3*k ] - mMove[variant][0]; |
|
| 165 |
verts[pointer][1] = v[3*k+1] - mMove[variant][1]; |
|
| 166 |
verts[pointer][2] = v[3*k+2] - mMove[variant][2]; |
|
| 167 |
pointer++; |
|
| 168 |
} |
|
| 169 |
} |
|
| 170 |
} |
|
| 171 |
|
|
| 172 |
return verts; |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 176 |
|
|
| 177 |
int[][][] getIndices(ArrayList<float[][]> list) |
|
| 178 |
{
|
|
| 179 |
int indicesSoFar=0; |
|
| 180 |
int length = list.size(); |
|
| 181 |
int[][][] indices = new int[length][][]; |
|
| 182 |
|
|
| 183 |
for( int i=0; i<length; i++ ) |
|
| 184 |
{
|
|
| 185 |
float[][] face = list.get(i); |
|
| 186 |
int len = face.length; |
|
| 187 |
int[][] ind = new int[len][]; |
|
| 188 |
|
|
| 189 |
for(int j=0; j<len; j++) |
|
| 190 |
{
|
|
| 191 |
int l = face[j].length/3; |
|
| 192 |
ind[j] = new int[l]; |
|
| 193 |
for(int k=0; k<l; k++) ind[j][k] = (indicesSoFar++); |
|
| 194 |
} |
|
| 195 |
|
|
| 196 |
indices[i] = ind; |
|
| 197 |
} |
|
| 198 |
|
|
| 199 |
return indices; |
|
| 200 |
} |
|
| 201 |
|
|
| 202 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 203 |
|
|
| 204 |
private void markAllVertices(float[] vertex, float[][] vertices, int[][][] indices, int pointer, int variant) |
|
| 205 |
{
|
|
| 206 |
int numFaces = indices.length; |
|
| 207 |
|
|
| 208 |
for(int face=0; face<numFaces; face++) |
|
| 209 |
{
|
|
| 210 |
int len = indices[face].length; |
|
| 211 |
|
|
| 212 |
for(int comp=0; comp<len; comp++) |
|
| 213 |
{
|
|
| 214 |
int l = indices[face][comp].length; |
|
| 215 |
|
|
| 216 |
for(int v=0; v<l; v++) |
|
| 217 |
{
|
|
| 218 |
if( mIndices[variant][face][comp][v]==-1 ) |
|
| 219 |
{
|
|
| 220 |
int ind=indices[face][comp][v]; |
|
| 221 |
float[] ver=vertices[ind]; |
|
| 222 |
|
|
| 223 |
if(vertex[0]==ver[0] && vertex[1]==ver[1] && vertex[2]==ver[2]) |
|
| 224 |
{
|
|
| 225 |
mIndices[variant][face][comp][v]=pointer; |
|
| 226 |
} |
|
| 227 |
} |
|
| 228 |
} |
|
| 229 |
} |
|
| 230 |
} |
|
| 231 |
} |
|
| 232 |
|
|
| 233 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 234 |
// So far the 'vertices/indices' are stored inefficiently, with each vertex stored three times |
|
| 235 |
// (each one normally is a corner of three faces) or even six times. Compress! |
|
| 236 |
// Example of six times: the central vertex here: |
|
| 237 |
// |
|
| 238 |
// { 1.0f, 0.0f, -1.0f,
|
|
| 239 |
// 1.0f, -1.0f, -1.0f, |
|
| 240 |
// 1.0f, -1.0f, +0.0f, |
|
| 241 |
// 0.0f, -1.0f, -1.0f }, |
|
| 242 |
|
|
| 243 |
void compressVerticesAndIndices(int variant, float[][] vertices, int[][][] indices) |
|
| 244 |
{
|
|
| 245 |
if( mTmpArray==null ) mTmpArray = new ArrayList<>(); |
|
| 246 |
|
|
| 247 |
int numFaces = indices.length; |
|
| 248 |
int pointer=0; |
|
| 249 |
|
|
| 250 |
mIndices[variant] = new int[numFaces][][]; |
|
| 251 |
|
|
| 252 |
for(int face=0; face<numFaces;face++) |
|
| 253 |
{
|
|
| 254 |
int len = indices[face].length; |
|
| 255 |
mIndices[variant][face] = new int[len][]; |
|
| 256 |
|
|
| 257 |
for(int comp=0; comp<len; comp++) |
|
| 258 |
{
|
|
| 259 |
int l = indices[face][comp].length; |
|
| 260 |
mIndices[variant][face][comp] = new int[l]; |
|
| 261 |
for(int v=0; v<l; v++) mIndices[variant][face][comp][v] = -1; |
|
| 262 |
} |
|
| 263 |
} |
|
| 264 |
|
|
| 265 |
for(int face=0; face<numFaces; face++) |
|
| 266 |
{
|
|
| 267 |
int len = indices[face].length; |
|
| 268 |
|
|
| 269 |
for(int comp=0; comp<len; comp++) |
|
| 270 |
{
|
|
| 271 |
int l = indices[face][comp].length; |
|
| 272 |
|
|
| 273 |
for(int v=0; v<l; v++) |
|
| 274 |
{
|
|
| 275 |
if( mIndices[variant][face][comp][v]==-1 ) |
|
| 276 |
{
|
|
| 277 |
int ind=indices[face][comp][v]; |
|
| 278 |
float[] ver=vertices[ind]; |
|
| 279 |
mTmpArray.add(ver); |
|
| 280 |
markAllVertices(ver, vertices, indices, pointer, variant); |
|
| 281 |
pointer++; |
|
| 282 |
} |
|
| 283 |
} |
|
| 284 |
} |
|
| 285 |
} |
|
| 286 |
|
|
| 287 |
int len = mTmpArray.size(); |
|
| 288 |
mVertices[variant] = new float[len][]; |
|
| 289 |
|
|
| 290 |
for(int i=0; i<len; i++) |
|
| 291 |
{
|
|
| 292 |
mVertices[variant][i] = mTmpArray.remove(0); |
|
| 293 |
} |
|
| 294 |
} |
|
| 295 |
|
|
| 296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 297 |
|
|
| 298 |
boolean elementDoesntExist(int[] p) |
|
| 299 |
{
|
|
| 300 |
boolean res; |
|
| 301 |
|
|
| 302 |
for(int i=0; i<mNumElements; i++) |
|
| 303 |
{
|
|
| 304 |
int[] row = mElements[i].getRotRow(); |
|
| 305 |
res = true; |
|
| 306 |
|
|
| 307 |
for(int j=0; j<mNumAxis; j++) |
|
| 308 |
if( row[j]!=p[j] ) |
|
| 309 |
{
|
|
| 310 |
res = false; |
|
| 311 |
break; |
|
| 312 |
} |
|
| 313 |
|
|
| 314 |
if( res ) return false; |
|
| 315 |
} |
|
| 316 |
|
|
| 317 |
return true; |
|
| 318 |
} |
|
| 319 |
|
|
| 320 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 321 |
|
|
| 322 |
static boolean vertInFace(float[] vertex, float[] move, Static3D faceAxis, float dist) |
|
| 323 |
{
|
|
| 324 |
final float MAX_ERROR = 0.01f; |
|
| 325 |
|
|
| 326 |
float x= faceAxis.get0(); |
|
| 327 |
float y= faceAxis.get1(); |
|
| 328 |
float z= faceAxis.get2(); |
|
| 329 |
|
|
| 330 |
float a = (vertex[0]+move[0])*x + (vertex[1]+move[1])*y + (vertex[2]+move[2])*z; |
|
| 331 |
float diff = a - dist; |
|
| 332 |
|
|
| 333 |
return diff>-MAX_ERROR && diff<MAX_ERROR; |
|
| 334 |
} |
|
| 335 |
|
|
| 336 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 337 |
|
|
| 338 |
private void computeVectorFace(float[] prev, float[] curr, float[] next, float[] output) |
|
| 339 |
{
|
|
| 340 |
float ax = prev[0]-curr[0]; |
|
| 341 |
float ay = prev[1]-curr[1]; |
|
| 342 |
float az = prev[2]-curr[2]; |
|
| 343 |
|
|
| 344 |
float bx = next[0]-curr[0]; |
|
| 345 |
float by = next[1]-curr[1]; |
|
| 346 |
float bz = next[2]-curr[2]; |
|
| 347 |
|
|
| 348 |
float lena = (float)Math.sqrt(ax*ax + ay*ay + az*az); |
|
| 349 |
float lenb = (float)Math.sqrt(bx*bx + by*by + bz*bz); |
|
| 350 |
|
|
| 351 |
ax /= lena; |
|
| 352 |
ay /= lena; |
|
| 353 |
az /= lena; |
|
| 354 |
|
|
| 355 |
bx /= lenb; |
|
| 356 |
by /= lenb; |
|
| 357 |
bz /= lenb; |
|
| 358 |
|
|
| 359 |
output[0] = ay*bz - az*by; |
|
| 360 |
output[1] = az*bx - ax*bz; |
|
| 361 |
output[2] = ax*by - ay*bx; |
|
| 362 |
|
|
| 363 |
output[3] = ax; |
|
| 364 |
output[4] = ay; |
|
| 365 |
output[5] = az; |
|
| 366 |
|
|
| 367 |
output[6] = bx; |
|
| 368 |
output[7] = by; |
|
| 369 |
output[8] = bz; |
|
| 370 |
} |
|
| 371 |
|
|
| 372 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 373 |
// 'concave' vertices do not get pushed! |
|
| 374 |
|
|
| 375 |
private boolean vertexIsConcave(float[][] vecs, int numVecs) |
|
| 376 |
{
|
|
| 377 |
for(int i=0; i<numVecs; i++) |
|
| 378 |
{
|
|
| 379 |
float[] v1 = vecs[i]; |
|
| 380 |
|
|
| 381 |
for(int j=0; j<numVecs; j++) |
|
| 382 |
{
|
|
| 383 |
if( i==j ) continue; |
|
| 384 |
|
|
| 385 |
float[] v2 = vecs[j]; |
|
| 386 |
|
|
| 387 |
float scalar1 = v1[0]*v2[3] + v1[1]*v2[4] + v1[2]*v2[5]; |
|
| 388 |
float scalar2 = v1[0]*v2[6] + v1[1]*v2[7] + v1[2]*v2[8]; |
|
| 389 |
|
|
| 390 |
if( scalar1<0 || scalar2<0 ) return true; |
|
| 391 |
} |
|
| 392 |
} |
|
| 393 |
|
|
| 394 |
return false; |
|
| 395 |
} |
|
| 396 |
|
|
| 397 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 398 |
|
|
| 399 |
private float[] computeVector(int index, float[][] vertices, int[][][] indices, int[] bandIndices) |
|
| 400 |
{
|
|
| 401 |
int band=0; |
|
| 402 |
int numFaces = indices.length; |
|
| 403 |
int numBordering = 0; |
|
| 404 |
float x=0, y=0, z=0; |
|
| 405 |
|
|
| 406 |
float[][] vecs = new float[numFaces][9]; |
|
| 407 |
int vecIndex = 0; |
|
| 408 |
|
|
| 409 |
for(int f=0; f<numFaces; f++) |
|
| 410 |
{
|
|
| 411 |
int numComponentsInFace = indices[f].length; |
|
| 412 |
|
|
| 413 |
for(int c=0; c<numComponentsInFace; c++) |
|
| 414 |
{
|
|
| 415 |
int[] ind = indices[f][c]; |
|
| 416 |
int numVertsInComponent = ind.length; |
|
| 417 |
|
|
| 418 |
for(int v=0; v<numVertsInComponent; v++) |
|
| 419 |
{
|
|
| 420 |
if(ind[v]==index) |
|
| 421 |
{
|
|
| 422 |
int prev=v>0 ? v-1 : numVertsInComponent-1; |
|
| 423 |
int next=v<numVertsInComponent-1 ? v+1 : 0; |
|
| 424 |
|
|
| 425 |
int prevIndex=ind[prev]; |
|
| 426 |
int currIndex=ind[v]; |
|
| 427 |
int nextIndex=ind[next]; |
|
| 428 |
|
|
| 429 |
float[] vec = vecs[vecIndex++]; |
|
| 430 |
computeVectorFace(vertices[prevIndex], vertices[currIndex], vertices[nextIndex], vec); |
|
| 431 |
band|=bandIndices[f]; |
|
| 432 |
v = numVertsInComponent; |
|
| 433 |
c = numComponentsInFace; |
|
| 434 |
numBordering++; |
|
| 435 |
|
|
| 436 |
x += vec[0]; |
|
| 437 |
y += vec[1]; |
|
| 438 |
z += vec[2]; |
|
| 439 |
} |
|
| 440 |
} |
|
| 441 |
} |
|
| 442 |
} |
|
| 443 |
|
|
| 444 |
boolean concave = vertexIsConcave(vecs,vecIndex); |
|
| 445 |
|
|
| 446 |
return ( concave || band==0 || numBordering<3 ) ? null : new float[] { x/numBordering, y/numBordering, z/numBordering};
|
|
| 447 |
} |
|
| 448 |
|
|
| 449 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 450 |
|
|
| 451 |
private float[][] generateVectors(float[][] vertices, int[][][] indices, int[] bandIndices) |
|
| 452 |
{
|
|
| 453 |
int len = vertices.length; |
|
| 454 |
float[][] vectors = new float[len][]; |
|
| 455 |
|
|
| 456 |
for(int i=0; i<len; i++) |
|
| 457 |
{
|
|
| 458 |
vectors[i] = computeVector(i,vertices,indices,bandIndices); |
|
| 459 |
} |
|
| 460 |
|
|
| 461 |
return vectors; |
|
| 462 |
} |
|
| 463 |
|
|
| 464 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 465 |
|
|
| 466 |
private boolean elementsFormSection(int e1, int e2, int ax) |
|
| 467 |
{
|
|
| 468 |
int[] r1 = mElements[e1].getRotRow(); |
|
| 469 |
int[] r2 = mElements[e2].getRotRow(); |
|
| 470 |
|
|
| 471 |
if( r1[ax]==r2[ax] ) |
|
| 472 |
{
|
|
| 473 |
int dist=0; |
|
| 474 |
|
|
| 475 |
for(int i=0; i<mNumAxis; i++) |
|
| 476 |
{
|
|
| 477 |
int d=r1[i]-r2[i]; |
|
| 478 |
dist+=d*d; |
|
| 479 |
} |
|
| 480 |
|
|
Also available in: Unified diff
move the non-UI bandaged stuff to its own package in the object library.