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 |
|
|
import java.nio.ByteBuffer;
|
23 |
|
|
import java.nio.ByteOrder;
|
24 |
|
|
|
25 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26 |
|
|
|
27 |
e458a4ba
|
Leszek Koltunski
|
class DistortedBitmapGrid extends DistortedObjectGrid
|
28 |
6a06a912
|
Leszek Koltunski
|
{
|
29 |
|
|
|
30 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31 |
|
|
|
32 |
e458a4ba
|
Leszek Koltunski
|
DistortedBitmapGrid(int xLength, int yLength)
|
33 |
6a06a912
|
Leszek Koltunski
|
{
|
34 |
|
|
dataLength = 2*xLength*(yLength-1)+2*(yLength-2); // (yLength-1) strips, 2*xLength triangles in each, plus 2 degenerate triangles per each of (yLength-2) joins
|
35 |
|
|
final short[] indexData = new short[dataLength];
|
36 |
|
|
|
37 |
|
|
int offset=0;
|
38 |
|
|
for(int y=0; y<yLength-1; y++)
|
39 |
|
|
{
|
40 |
|
|
if (y>0) indexData[offset++] = (short) (y*xLength); // Degenerate begin: repeat first vertex
|
41 |
|
|
|
42 |
|
|
for (int x = 0; x < xLength; x++)
|
43 |
|
|
{
|
44 |
|
|
indexData[offset++] = (short) (( y *xLength)+x);
|
45 |
|
|
indexData[offset++] = (short) (((y+1)*xLength)+x);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
if (y<yLength-2) indexData[offset++] = (short) (((y+1)*xLength) + (xLength-1)); // Degenerate end: repeat last vertex
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
// for(int g=0; g<dataLength; g++) Log.e(TAG_BACKGROUND, "index["+g+"]="+indexData[g]);
|
52 |
|
|
|
53 |
2dacdeb2
|
Leszek Koltunski
|
float[] bufferData = new float[NORMAL_DATA_SIZE*dataLength];
|
54 |
6a06a912
|
Leszek Koltunski
|
|
55 |
|
|
offset=0;
|
56 |
|
|
for(int i=0; i<dataLength; i++)
|
57 |
|
|
{
|
58 |
|
|
bufferData[offset++] = 0.0f; // x
|
59 |
|
|
bufferData[offset++] = 0.0f; // y
|
60 |
|
|
bufferData[offset++] = 1.0f; // z
|
61 |
|
|
}
|
62 |
|
|
mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
63 |
|
|
mGridNormals.put(bufferData).position(0);
|
64 |
|
|
|
65 |
|
|
float tmpx,tmpy,tmpz;
|
66 |
|
|
bufferData = new float[TEX_DATA_SIZE*dataLength];
|
67 |
|
|
|
68 |
|
|
offset=0;
|
69 |
|
|
for(int i=0; i<dataLength; i++)
|
70 |
|
|
{
|
71 |
|
|
tmpx = ((float)(indexData[offset/2]%xLength))/(xLength-1);
|
72 |
|
|
tmpy = ((float)(indexData[offset/2]/xLength))/(yLength-1);
|
73 |
|
|
|
74 |
|
|
bufferData[offset++] = tmpx; // s=x
|
75 |
|
|
bufferData[offset++] = tmpy; // t=y
|
76 |
|
|
}
|
77 |
|
|
mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
78 |
|
|
mGridTexture.put(bufferData).position(0);
|
79 |
|
|
|
80 |
|
|
//for(int g=0; g<dataLength; g++) Log.e(TAG_BACKGROUND, "tex["+g+"]=("+bufferData[2*g]+","+bufferData[2*g+1]+")");
|
81 |
|
|
//Log.e(TAG, "regWidth="+(2*mRegW)+" regHeight="+(2*mRegH)+" xLength="+xLength+" yLength="+yLength);
|
82 |
|
|
|
83 |
|
|
offset=0;
|
84 |
|
|
bufferData= new float[POSITION_DATA_SIZE*dataLength];
|
85 |
|
|
|
86 |
|
|
for(int i=0; i<dataLength; i++)
|
87 |
|
|
{
|
88 |
|
|
tmpx = ((float)(indexData[offset/3]%xLength))/(xLength-1);
|
89 |
|
|
tmpy = ((float)(indexData[offset/3]/xLength))/(yLength-1);
|
90 |
|
|
tmpz = 0;
|
91 |
|
|
|
92 |
|
|
bufferData[offset++] = (tmpx-0.5f); // x
|
93 |
|
|
bufferData[offset++] = (0.5f-tmpy); // y
|
94 |
|
|
bufferData[offset++] = tmpz; // z
|
95 |
|
|
}
|
96 |
|
|
mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
97 |
|
|
mGridPositions.put(bufferData).position(0);
|
98 |
|
|
|
99 |
|
|
//for(int g=0; g<dataLength; g++) android.util.Log.e("BACKGROUND", "pos["+g+"]=("+bufferData[3*g]+","+bufferData[3*g+1]+")");
|
100 |
|
|
}
|
101 |
39cbf9dc
|
Leszek Koltunski
|
}
|