1
|
package org.distorted.library;
|
2
|
|
3
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
4
|
/**
|
5
|
* Instance of this class represents a flat set of cubes optionally textured as a whole.
|
6
|
* (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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
/**
|
33
|
* Creates internal memory representation of a cuboid subset.
|
34
|
*
|
35
|
* @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
|
*
|
39
|
* For example, (cols=2, desc="111010") describes the following shape:
|
40
|
*
|
41
|
* XX
|
42
|
* X
|
43
|
* X
|
44
|
*
|
45
|
* whereas (cols=2,desc="110001") describes
|
46
|
*
|
47
|
* XX
|
48
|
*
|
49
|
* X
|
50
|
*
|
51
|
* @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
|
public DistortedCubes(int cols, String desc, int gridSize, boolean frontOnly)
|
55
|
{
|
56
|
int Rs = 0;
|
57
|
int Cs = 0;
|
58
|
|
59
|
if( cols>0 )
|
60
|
{
|
61
|
int reallen = desc.length();
|
62
|
int len = reallen;
|
63
|
|
64
|
if( (reallen/cols)*cols != reallen )
|
65
|
{
|
66
|
len = ((reallen/cols)+1)*cols;
|
67
|
for(int i=reallen; i<len; i++) desc += "0";
|
68
|
}
|
69
|
|
70
|
if( desc.contains("1") )
|
71
|
{
|
72
|
Cs = cols;
|
73
|
Rs = len/cols;
|
74
|
}
|
75
|
}
|
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
|
|
93
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94
|
/**
|
95
|
* {@see DistortedObject#DistortedObject(DistortedObject,flags)}
|
96
|
*/
|
97
|
public DistortedCubes(DistortedCubes dc, int flags)
|
98
|
{
|
99
|
super(dc,flags);
|
100
|
}
|
101
|
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103
|
|
104
|
protected DistortedObject deepCopy(int flags)
|
105
|
{
|
106
|
return new DistortedCubes(this,flags);
|
107
|
}
|
108
|
|
109
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110
|
}
|