1 |
6a06a912
|
Leszek Koltunski
|
package org.distorted.library;
|
2 |
|
|
|
3 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
4 |
|
|
/**
|
5 |
9361b337
|
Leszek Koltunski
|
* Instance of this class represents a flat set of cubes optionally textured as a whole.
|
6 |
6a06a912
|
Leszek Koltunski
|
* (a subset of a NxMx1 cuboid build with 1x1x1 cubes, i.e. the MxNx1 cuboid with arbitrary cubes missing)
|
7 |
|
|
* <p>
|
8 |
|
|
* General idea is as follows:
|
9 |
|
|
* <ul>
|
10 |
|
|
* <li> Create an instance of this class
|
11 |
|
|
* <li> Optionally texture it
|
12 |
|
|
* <li> Apply some effects
|
13 |
|
|
* <li> Draw it!
|
14 |
|
|
* </ul>
|
15 |
|
|
* <p>
|
16 |
|
|
* The effects we can apply fall into three general categories:
|
17 |
|
|
* <ul>
|
18 |
|
|
* <li> Matrix Effects, i.e. ones that change the Cuboid's ModelView Matrix (moves, scales, rotations)
|
19 |
|
|
* <li> Vertex Effects, i.e. effects that are implemented in the Vertex Shader. Those typically change
|
20 |
|
|
* the shape of (some sub-Region of) the Cuboid in some way (deforms, distortions, sinks)
|
21 |
|
|
* <li> Fragment Effects, i.e. effects that change (some of) the pixels of the Texture (transparency, macroblock)
|
22 |
|
|
* </ul>
|
23 |
|
|
* <p>
|
24 |
|
|
*
|
25 |
|
|
*/
|
26 |
|
|
public class DistortedCubes extends DistortedObject
|
27 |
|
|
{
|
28 |
|
|
|
29 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30 |
|
|
// PUBLIC API
|
31 |
9361b337
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32 |
6a06a912
|
Leszek Koltunski
|
/**
|
33 |
|
|
* Creates internal memory representation of a cuboid subset.
|
34 |
9361b337
|
Leszek Koltunski
|
*
|
35 |
6a06a912
|
Leszek Koltunski
|
* @param cols Integer helping to parse the next parameter.
|
36 |
|
|
* @param desc String describing the subset of a MxNx1 cuboid that we want to create.
|
37 |
|
|
* Its MxN characters - all 0 or 1 - decide of appropriate field is taken or not.
|
38 |
9361b337
|
Leszek Koltunski
|
*
|
39 |
6a06a912
|
Leszek Koltunski
|
* For example, (cols=2, desc="111010") describes the following shape:
|
40 |
9361b337
|
Leszek Koltunski
|
*
|
41 |
6a06a912
|
Leszek Koltunski
|
* XX
|
42 |
|
|
* X
|
43 |
|
|
* X
|
44 |
9361b337
|
Leszek Koltunski
|
*
|
45 |
6a06a912
|
Leszek Koltunski
|
* whereas (cols=2,desc="110001") describes
|
46 |
9361b337
|
Leszek Koltunski
|
*
|
47 |
6a06a912
|
Leszek Koltunski
|
* XX
|
48 |
9361b337
|
Leszek Koltunski
|
*
|
49 |
6a06a912
|
Leszek Koltunski
|
* X
|
50 |
9361b337
|
Leszek Koltunski
|
*
|
51 |
6a06a912
|
Leszek Koltunski
|
* @param gridSize size, in pixels, of the single 1x1x1 cube our cuboid is built from
|
52 |
|
|
* @param frontOnly Only create the front wall or side and back as well?
|
53 |
|
|
*/
|
54 |
9361b337
|
Leszek Koltunski
|
public DistortedCubes(int cols, String desc, int gridSize, boolean frontOnly)
|
55 |
|
|
{
|
56 |
|
|
int Rs = 0;
|
57 |
|
|
int Cs = 0;
|
58 |
6a06a912
|
Leszek Koltunski
|
|
59 |
9361b337
|
Leszek Koltunski
|
if( cols>0 )
|
60 |
|
|
{
|
61 |
|
|
int reallen = desc.length();
|
62 |
|
|
int len = reallen;
|
63 |
6a06a912
|
Leszek Koltunski
|
|
64 |
9361b337
|
Leszek Koltunski
|
if( (reallen/cols)*cols != reallen )
|
65 |
|
|
{
|
66 |
|
|
len = ((reallen/cols)+1)*cols;
|
67 |
|
|
for(int i=reallen; i<len; i++) desc += "0";
|
68 |
|
|
}
|
69 |
6a06a912
|
Leszek Koltunski
|
|
70 |
ada90d33
|
Leszek Koltunski
|
if( desc.contains("1") )
|
71 |
9361b337
|
Leszek Koltunski
|
{
|
72 |
|
|
Cs = cols;
|
73 |
|
|
Rs = len/cols;
|
74 |
6a06a912
|
Leszek Koltunski
|
}
|
75 |
|
|
}
|
76 |
9361b337
|
Leszek Koltunski
|
|
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 |
|
|
|
93 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94 |
|
|
/**
|
95 |
ada90d33
|
Leszek Koltunski
|
* {@see DistortedObject#DistortedObject(DistortedObject,flags)}
|
96 |
6a06a912
|
Leszek Koltunski
|
*/
|
97 |
9361b337
|
Leszek Koltunski
|
public DistortedCubes(DistortedCubes dc, int flags)
|
98 |
|
|
{
|
99 |
|
|
super(dc,flags);
|
100 |
|
|
}
|
101 |
6a06a912
|
Leszek Koltunski
|
|
102 |
ada90d33
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103 |
|
|
|
104 |
|
|
protected DistortedObject deepCopy(int flags)
|
105 |
|
|
{
|
106 |
|
|
return new DistortedCubes(this,flags);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110 |
9361b337
|
Leszek Koltunski
|
}
|