Revision 9361b337
Added by Leszek Koltunski over 9 years ago
| src/main/java/org/distorted/library/DistortedCubes.java | ||
|---|---|---|
| 1 | 1 |
package org.distorted.library; |
| 2 | 2 |
|
| 3 |
import android.graphics.Bitmap; |
|
| 4 |
|
|
| 5 | 3 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 6 | 4 |
/** |
| 7 |
* Instance of this class represents a connected, flat set of cubes optionally textured as a whole.
|
|
| 5 |
* Instance of this class represents a flat set of cubes optionally textured as a whole. |
|
| 8 | 6 |
* (a subset of a NxMx1 cuboid build with 1x1x1 cubes, i.e. the MxNx1 cuboid with arbitrary cubes missing) |
| 9 | 7 |
* <p> |
| 10 | 8 |
* General idea is as follows: |
| ... | ... | |
| 30 | 28 |
|
| 31 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | 30 |
// PUBLIC API |
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 35 | 32 |
/** |
| 36 | 33 |
* Creates internal memory representation of a cuboid subset. |
| 37 |
*
|
|
| 34 |
* |
|
| 38 | 35 |
* @param cols Integer helping to parse the next parameter. |
| 39 | 36 |
* @param desc String describing the subset of a MxNx1 cuboid that we want to create. |
| 40 | 37 |
* Its MxN characters - all 0 or 1 - decide of appropriate field is taken or not. |
| 41 |
*
|
|
| 38 |
* |
|
| 42 | 39 |
* For example, (cols=2, desc="111010") describes the following shape: |
| 43 |
*
|
|
| 40 |
* |
|
| 44 | 41 |
* XX |
| 45 | 42 |
* X |
| 46 | 43 |
* X |
| 47 |
*
|
|
| 44 |
* |
|
| 48 | 45 |
* whereas (cols=2,desc="110001") describes |
| 49 |
*
|
|
| 46 |
* |
|
| 50 | 47 |
* XX |
| 51 |
*
|
|
| 48 |
* |
|
| 52 | 49 |
* X |
| 53 |
*
|
|
| 50 |
* |
|
| 54 | 51 |
* @param gridSize size, in pixels, of the single 1x1x1 cube our cuboid is built from |
| 55 |
* |
|
| 56 |
*/ |
|
| 57 |
public DistortedCubes(int cols, String desc, int gridSize) |
|
| 58 |
{
|
|
| 59 |
this(cols,desc,gridSize,false); |
|
| 60 |
} |
|
| 61 |
|
|
| 62 |
/** |
|
| 63 | 52 |
* @param frontOnly Only create the front wall or side and back as well? |
| 64 | 53 |
*/ |
| 65 |
|
|
| 66 |
public DistortedCubes(int cols, String desc, int gridSize, boolean frontOnly) |
|
| 67 |
{
|
|
| 68 |
int Rs = 0; |
|
| 69 |
int Cs = 0; |
|
| 54 |
public DistortedCubes(int cols, String desc, int gridSize, boolean frontOnly) |
|
| 55 |
{
|
|
| 56 |
int Rs = 0; |
|
| 57 |
int Cs = 0; |
|
| 70 | 58 |
|
| 71 |
if( cols>0 )
|
|
| 72 |
{
|
|
| 73 |
int reallen = desc.length();
|
|
| 74 |
int len = reallen;
|
|
| 59 |
if( cols>0 ) |
|
| 60 |
{
|
|
| 61 |
int reallen = desc.length(); |
|
| 62 |
int len = reallen; |
|
| 75 | 63 |
|
| 76 |
if( (reallen/cols)*cols != reallen )
|
|
| 77 |
{
|
|
| 78 |
len = ((reallen/cols)+1)*cols;
|
|
| 79 |
for(int i=reallen; i<len; i++) desc += "0";
|
|
| 80 |
}
|
|
| 64 |
if( (reallen/cols)*cols != reallen ) |
|
| 65 |
{
|
|
| 66 |
len = ((reallen/cols)+1)*cols;
|
|
| 67 |
for(int i=reallen; i<len; i++) desc += "0"; |
|
| 68 |
} |
|
| 81 | 69 |
|
| 82 |
if( desc.indexOf("1")>=0 )
|
|
| 83 |
{
|
|
| 84 |
Cs = cols; |
|
| 85 |
Rs = len/cols; |
|
| 86 |
} |
|
| 70 |
if( desc.indexOf("1")>=0 )
|
|
| 71 |
{
|
|
| 72 |
Cs = cols; |
|
| 73 |
Rs = len/cols; |
|
| 87 | 74 |
} |
| 88 |
|
|
| 89 |
mSizeX= gridSize*Cs; |
|
| 90 |
mSizeY= gridSize*Rs; |
|
| 91 |
mSizeZ= frontOnly ? 0 : gridSize; |
|
| 92 |
mGrid = new GridCubes(cols,desc, frontOnly); |
|
| 93 |
initializeData(gridSize); |
|
| 94 | 75 |
} |
| 95 |
|
|
| 76 |
|
|
| 77 |
mSizeX= gridSize*Cs; |
|
| 78 |
mSizeY= gridSize*Rs; |
|
| 79 |
mSizeZ= frontOnly ? 0 : gridSize; |
|
| 80 |
mGrid = new GridCubes(cols,desc, frontOnly); |
|
| 81 |
initializeData(gridSize); |
|
| 82 |
} |
|
| 83 |
|
|
| 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 85 |
/** |
|
| 86 |
* Convenience constructor |
|
| 87 |
*/ |
|
| 88 |
public DistortedCubes(int cols, String desc, int gridSize) |
|
| 89 |
{
|
|
| 90 |
this(cols,desc,gridSize,false); |
|
| 91 |
} |
|
| 92 |
|
|
| 96 | 93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 97 | 94 |
/** |
| 98 | 95 |
* Copy constructor used to create a DistortedCubes based on various parts of another object. |
| 99 | 96 |
* <p> |
| 100 | 97 |
* Whatever we do not clone gets created just like in the default constructor. |
| 101 |
*
|
|
| 98 |
* |
|
| 102 | 99 |
* @param dc Source object to create our object from |
| 103 | 100 |
* @param flags A bitmask of values specifying what to copy. |
| 104 | 101 |
* For example, CLONE_BITMAP | CLONE_MATRIX. |
| 105 | 102 |
*/ |
| 106 |
public DistortedCubes(DistortedCubes dc, int flags) |
|
| 107 |
{
|
|
| 108 |
initializeEffectLists(dc,flags); |
|
| 109 |
|
|
| 110 |
mID = DistortedObjectList.add(this); |
|
| 111 |
|
|
| 112 |
mSizeX = dc.mSizeX; |
|
| 113 |
mSizeY = dc.mSizeY; |
|
| 114 |
mSizeZ = dc.mSizeZ; |
|
| 115 |
mSize = dc.mSize; |
|
| 116 |
mGrid = dc.mGrid; |
|
| 117 |
|
|
| 118 |
if( (flags & Distorted.CLONE_BITMAP) != 0 ) |
|
| 119 |
{
|
|
| 120 |
mTextureDataH = dc.mTextureDataH; |
|
| 121 |
mBmp = dc.mBmp; |
|
| 122 |
mBitmapSet = dc.mBitmapSet; |
|
| 123 |
} |
|
| 124 |
else |
|
| 125 |
{
|
|
| 126 |
mTextureDataH = new int[1]; |
|
| 127 |
mTextureDataH[0]= 0; |
|
| 128 |
mBitmapSet = new boolean[1]; |
|
| 129 |
mBitmapSet[0] = false; |
|
| 130 |
mBmp = new Bitmap[1]; |
|
| 131 |
mBmp[0] = null; |
|
| 132 |
|
|
| 133 |
if( Distorted.isInitialized() ) resetTexture(); |
|
| 134 |
} |
|
| 135 |
} |
|
| 103 |
public DistortedCubes(DistortedCubes dc, int flags) |
|
| 104 |
{
|
|
| 105 |
super(dc,flags); |
|
| 106 |
} |
|
| 136 | 107 |
|
| 137 | 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 138 |
} |
|
| 109 |
} |
|
Also available in: Unified diff
Provide support to add any class derived from DistortedObject to DistortedNode.