1 |
6a06a912
|
Leszek Koltunski
|
package org.distorted.library;
|
2 |
|
|
|
3 |
|
|
import android.graphics.Bitmap;
|
4 |
|
|
|
5 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
6 |
|
|
/**
|
7 |
|
|
* Instance of this class represents a connected, flat set of cubes optionally textured as a whole.
|
8 |
|
|
* (a subset of a NxMx1 cuboid build with 1x1x1 cubes, i.e. the MxNx1 cuboid with arbitrary cubes missing)
|
9 |
|
|
* <p>
|
10 |
|
|
* General idea is as follows:
|
11 |
|
|
* <ul>
|
12 |
|
|
* <li> Create an instance of this class
|
13 |
|
|
* <li> Optionally texture it
|
14 |
|
|
* <li> Apply some effects
|
15 |
|
|
* <li> Draw it!
|
16 |
|
|
* </ul>
|
17 |
|
|
* <p>
|
18 |
|
|
* The effects we can apply fall into three general categories:
|
19 |
|
|
* <ul>
|
20 |
|
|
* <li> Matrix Effects, i.e. ones that change the Cuboid's ModelView Matrix (moves, scales, rotations)
|
21 |
|
|
* <li> Vertex Effects, i.e. effects that are implemented in the Vertex Shader. Those typically change
|
22 |
|
|
* the shape of (some sub-Region of) the Cuboid in some way (deforms, distortions, sinks)
|
23 |
|
|
* <li> Fragment Effects, i.e. effects that change (some of) the pixels of the Texture (transparency, macroblock)
|
24 |
|
|
* </ul>
|
25 |
|
|
* <p>
|
26 |
|
|
*
|
27 |
|
|
*/
|
28 |
|
|
public class DistortedCubes extends DistortedObject
|
29 |
|
|
{
|
30 |
|
|
|
31 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32 |
|
|
// PUBLIC API
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
|
|
/**
|
36 |
|
|
* Creates internal memory representation of a cuboid subset.
|
37 |
|
|
*
|
38 |
|
|
* @param cols Integer helping to parse the next parameter.
|
39 |
|
|
* @param desc String describing the subset of a MxNx1 cuboid that we want to create.
|
40 |
|
|
* Its MxN characters - all 0 or 1 - decide of appropriate field is taken or not.
|
41 |
|
|
*
|
42 |
|
|
* For example, (cols=2, desc="111010") describes the following shape:
|
43 |
|
|
*
|
44 |
|
|
* XX
|
45 |
|
|
* X
|
46 |
|
|
* X
|
47 |
|
|
*
|
48 |
|
|
* whereas (cols=2,desc="110001") describes
|
49 |
|
|
*
|
50 |
|
|
* XX
|
51 |
|
|
*
|
52 |
|
|
* X
|
53 |
|
|
*
|
54 |
|
|
* @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 |
|
|
* @param frontOnly Only create the front wall or side and back as well?
|
64 |
|
|
*/
|
65 |
|
|
|
66 |
|
|
public DistortedCubes(int cols, String desc, int gridSize, boolean frontOnly)
|
67 |
|
|
{
|
68 |
|
|
int Rs = 0;
|
69 |
|
|
int Cs = 0;
|
70 |
|
|
|
71 |
|
|
if( cols>0 )
|
72 |
|
|
{
|
73 |
|
|
int reallen = desc.length();
|
74 |
|
|
int len = reallen;
|
75 |
|
|
|
76 |
|
|
if( (reallen/cols)*cols != reallen )
|
77 |
|
|
{
|
78 |
|
|
len = ((reallen/cols)+1)*cols;
|
79 |
|
|
for(int i=reallen; i<len; i++) desc += "0";
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
if( desc.indexOf("1")>=0 )
|
83 |
|
|
{
|
84 |
|
|
Cs = cols;
|
85 |
|
|
Rs = len/cols;
|
86 |
|
|
}
|
87 |
|
|
}
|
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 |
|
|
}
|
95 |
|
|
|
96 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97 |
|
|
/**
|
98 |
|
|
* Copy constructor used to create a DistortedCubes based on various parts of another object.
|
99 |
|
|
* <p>
|
100 |
|
|
* Whatever we do not clone gets created just like in the default constructor.
|
101 |
|
|
*
|
102 |
|
|
* @param dc Source object to create our object from
|
103 |
|
|
* @param flags A bitmask of values specifying what to copy.
|
104 |
|
|
* For example, CLONE_BITMAP | CLONE_MATRIX.
|
105 |
|
|
*/
|
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 |
|
|
}
|
136 |
|
|
|
137 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138 |
|
|
}
|