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.FloatBuffer;
|
23 |
|
|
|
24 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25 |
e0b6c593
|
Leszek Koltunski
|
/**
|
26 |
26df012c
|
Leszek Koltunski
|
* Abstract class which represents a Mesh, ie 3 arrays of Vertex attributes: 1) positions
|
27 |
e0b6c593
|
Leszek Koltunski
|
* 2) normals 3) texture coordinates.
|
28 |
|
|
* <p>
|
29 |
|
|
* If you want to render to a particular shape, extend from here, construct the three FloatBuffers and
|
30 |
|
|
* provide correct dataLength, i.e. the number of vertices.
|
31 |
|
|
*/
|
32 |
26df012c
|
Leszek Koltunski
|
public abstract class MeshObject
|
33 |
6a06a912
|
Leszek Koltunski
|
{
|
34 |
55c14a19
|
Leszek Koltunski
|
static final int BYTES_PER_FLOAT = 4; //
|
35 |
|
|
static final int POSITION_DATA_SIZE= 3; // Size of the position data in elements
|
36 |
|
|
static final int NORMAL_DATA_SIZE = 3; // Size of the normal data in elements.
|
37 |
|
|
static final int TEX_DATA_SIZE = 2; // Size of the texture coordinate data in elements.
|
38 |
6a06a912
|
Leszek Koltunski
|
|
39 |
55c14a19
|
Leszek Koltunski
|
int dataLength;
|
40 |
|
|
FloatBuffer mMeshPositions, mMeshNormals, mMeshTexture;
|
41 |
3ef3364d
|
Leszek Koltunski
|
|
42 |
1942537e
|
Leszek Koltunski
|
final float zFactor; // strange workaround for the fact that we need to somehow store the 'depth'
|
43 |
26df012c
|
Leszek Koltunski
|
// of the Mesh. Used in DistortedEffects. See DistortedTexture.getDepth().
|
44 |
3ef3364d
|
Leszek Koltunski
|
|
45 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46 |
3ef3364d
|
Leszek Koltunski
|
|
47 |
26df012c
|
Leszek Koltunski
|
MeshObject(float factor)
|
48 |
3ef3364d
|
Leszek Koltunski
|
{
|
49 |
|
|
zFactor = factor;
|
50 |
|
|
}
|
51 |
11fb6ce0
|
Leszek Koltunski
|
|
52 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53 |
69ed1eb4
|
Leszek Koltunski
|
/**
|
54 |
|
|
* Get the minimal set of Vertices which have the same convex hull as the whole set.
|
55 |
|
|
* <p>
|
56 |
|
|
* In case of Flat Meshes, the set is obviously just the 4 corners. In case of the Cubes Mesh,
|
57 |
|
|
* it is a subset of the set of each rightmost- and leftmost- corners in each row.
|
58 |
|
|
* <p>
|
59 |
|
|
* This is used to be able to quickly compute, in window coordinates, the Mesh'es bounding rectangle.
|
60 |
|
|
*/
|
61 |
|
|
abstract float[] getBoundingVertices();
|
62 |
6a06a912
|
Leszek Koltunski
|
}
|