1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
6a06a912
|
Leszek Koltunski
|
package org.distorted.library;
|
21 |
|
|
|
22 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
23 |
|
|
/**
|
24 |
9361b337
|
Leszek Koltunski
|
* Instance of this class represents a flat set of cubes optionally textured as a whole.
|
25 |
6a06a912
|
Leszek Koltunski
|
* (a subset of a NxMx1 cuboid build with 1x1x1 cubes, i.e. the MxNx1 cuboid with arbitrary cubes missing)
|
26 |
|
|
* <p>
|
27 |
|
|
* General idea is as follows:
|
28 |
|
|
* <ul>
|
29 |
|
|
* <li> Create an instance of this class
|
30 |
|
|
* <li> Optionally texture it
|
31 |
|
|
* <li> Apply some effects
|
32 |
|
|
* <li> Draw it!
|
33 |
|
|
* </ul>
|
34 |
|
|
* <p>
|
35 |
|
|
* The effects we can apply fall into three general categories:
|
36 |
|
|
* <ul>
|
37 |
|
|
* <li> Matrix Effects, i.e. ones that change the Cuboid's ModelView Matrix (moves, scales, rotations)
|
38 |
|
|
* <li> Vertex Effects, i.e. effects that are implemented in the Vertex Shader. Those typically change
|
39 |
|
|
* the shape of (some sub-Region of) the Cuboid in some way (deforms, distortions, sinks)
|
40 |
|
|
* <li> Fragment Effects, i.e. effects that change (some of) the pixels of the Texture (transparency, macroblock)
|
41 |
|
|
* </ul>
|
42 |
|
|
* <p>
|
43 |
|
|
*
|
44 |
|
|
*/
|
45 |
|
|
public class DistortedCubes extends DistortedObject
|
46 |
|
|
{
|
47 |
|
|
|
48 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49 |
|
|
// PUBLIC API
|
50 |
9361b337
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
6a06a912
|
Leszek Koltunski
|
/**
|
52 |
|
|
* Creates internal memory representation of a cuboid subset.
|
53 |
9361b337
|
Leszek Koltunski
|
*
|
54 |
6a06a912
|
Leszek Koltunski
|
* @param cols Integer helping to parse the next parameter.
|
55 |
|
|
* @param desc String describing the subset of a MxNx1 cuboid that we want to create.
|
56 |
|
|
* Its MxN characters - all 0 or 1 - decide of appropriate field is taken or not.
|
57 |
9361b337
|
Leszek Koltunski
|
*
|
58 |
6a06a912
|
Leszek Koltunski
|
* For example, (cols=2, desc="111010") describes the following shape:
|
59 |
9361b337
|
Leszek Koltunski
|
*
|
60 |
6a06a912
|
Leszek Koltunski
|
* XX
|
61 |
|
|
* X
|
62 |
|
|
* X
|
63 |
9361b337
|
Leszek Koltunski
|
*
|
64 |
6a06a912
|
Leszek Koltunski
|
* whereas (cols=2,desc="110001") describes
|
65 |
9361b337
|
Leszek Koltunski
|
*
|
66 |
6a06a912
|
Leszek Koltunski
|
* XX
|
67 |
9361b337
|
Leszek Koltunski
|
*
|
68 |
6a06a912
|
Leszek Koltunski
|
* X
|
69 |
9361b337
|
Leszek Koltunski
|
*
|
70 |
6a06a912
|
Leszek Koltunski
|
* @param gridSize size, in pixels, of the single 1x1x1 cube our cuboid is built from
|
71 |
|
|
* @param frontOnly Only create the front wall or side and back as well?
|
72 |
|
|
*/
|
73 |
9361b337
|
Leszek Koltunski
|
public DistortedCubes(int cols, String desc, int gridSize, boolean frontOnly)
|
74 |
|
|
{
|
75 |
|
|
int Rs = 0;
|
76 |
|
|
int Cs = 0;
|
77 |
6a06a912
|
Leszek Koltunski
|
|
78 |
9361b337
|
Leszek Koltunski
|
if( cols>0 )
|
79 |
|
|
{
|
80 |
|
|
int reallen = desc.length();
|
81 |
|
|
int len = reallen;
|
82 |
6a06a912
|
Leszek Koltunski
|
|
83 |
9361b337
|
Leszek Koltunski
|
if( (reallen/cols)*cols != reallen )
|
84 |
|
|
{
|
85 |
|
|
len = ((reallen/cols)+1)*cols;
|
86 |
|
|
for(int i=reallen; i<len; i++) desc += "0";
|
87 |
|
|
}
|
88 |
6a06a912
|
Leszek Koltunski
|
|
89 |
ada90d33
|
Leszek Koltunski
|
if( desc.contains("1") )
|
90 |
9361b337
|
Leszek Koltunski
|
{
|
91 |
|
|
Cs = cols;
|
92 |
|
|
Rs = len/cols;
|
93 |
6a06a912
|
Leszek Koltunski
|
}
|
94 |
|
|
}
|
95 |
9361b337
|
Leszek Koltunski
|
|
96 |
|
|
mSizeX= gridSize*Cs;
|
97 |
|
|
mSizeY= gridSize*Rs;
|
98 |
|
|
mSizeZ= frontOnly ? 0 : gridSize;
|
99 |
e458a4ba
|
Leszek Koltunski
|
mGrid = new DistortedCubesGrid(cols,desc, frontOnly);
|
100 |
9361b337
|
Leszek Koltunski
|
initializeData(gridSize);
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104 |
|
|
/**
|
105 |
|
|
* Convenience constructor
|
106 |
|
|
*/
|
107 |
|
|
public DistortedCubes(int cols, String desc, int gridSize)
|
108 |
|
|
{
|
109 |
|
|
this(cols,desc,gridSize,false);
|
110 |
|
|
}
|
111 |
|
|
|
112 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113 |
|
|
/**
|
114 |
ada90d33
|
Leszek Koltunski
|
* {@see DistortedObject#DistortedObject(DistortedObject,flags)}
|
115 |
6a06a912
|
Leszek Koltunski
|
*/
|
116 |
9361b337
|
Leszek Koltunski
|
public DistortedCubes(DistortedCubes dc, int flags)
|
117 |
|
|
{
|
118 |
|
|
super(dc,flags);
|
119 |
|
|
}
|
120 |
6a06a912
|
Leszek Koltunski
|
|
121 |
ada90d33
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
122 |
|
|
|
123 |
|
|
protected DistortedObject deepCopy(int flags)
|
124 |
|
|
{
|
125 |
|
|
return new DistortedCubes(this,flags);
|
126 |
|
|
}
|
127 |
|
|
|
128 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129 |
9361b337
|
Leszek Koltunski
|
}
|