1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2018 Leszek Koltunski leszek@koltunski.pl //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// This library is free software; you can redistribute it and/or //
|
7
|
// modify it under the terms of the GNU Lesser General Public //
|
8
|
// License as published by the Free Software Foundation; either //
|
9
|
// version 2.1 of the License, or (at your option) any later version. //
|
10
|
// //
|
11
|
// This library 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 GNU //
|
14
|
// Lesser General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU Lesser General Public //
|
17
|
// License along with this library; if not, write to the Free Software //
|
18
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //
|
19
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20
|
|
21
|
package org.distorted.library.mesh;
|
22
|
|
23
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
24
|
/**
|
25
|
* Create a quad - two triangles with vertices at (+-0.5,+-0.5).
|
26
|
* <p>
|
27
|
* Mainly to have a simple example showing how to create a Mesh; otherwise a MeshQuad can be perfectly
|
28
|
* emulated by a MeshRectangles(1,1) or a MeshCubes(1,1,0).
|
29
|
*/
|
30
|
public class MeshQuad extends MeshBase
|
31
|
{
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
private void addVertex( float x, float y, float[] attribs1, float[] attribs2, int index)
|
35
|
{
|
36
|
attribs1[VERT1_ATTRIBS*index + POS_ATTRIB ] = x-0.5f;
|
37
|
attribs1[VERT1_ATTRIBS*index + POS_ATTRIB+1] = 0.5f-y;
|
38
|
attribs1[VERT1_ATTRIBS*index + POS_ATTRIB+2] = 0.0f;
|
39
|
|
40
|
attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB ] = 0.0f;
|
41
|
attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB+1] = 0.0f;
|
42
|
attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB+2] = 1.0f;
|
43
|
|
44
|
attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB ] = x;
|
45
|
attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB+1] = 1.0f-y;
|
46
|
}
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
// PUBLIC API
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
/**
|
52
|
* Creates the underlying grid of 4 vertices, normals, inflates and texture coords.
|
53
|
*/
|
54
|
public MeshQuad()
|
55
|
{
|
56
|
super();
|
57
|
|
58
|
float[] attribs1= new float[VERT1_ATTRIBS*4];
|
59
|
float[] attribs2= new float[VERT2_ATTRIBS*4];
|
60
|
|
61
|
addVertex(0.0f,0.0f, attribs1, attribs2, 0);
|
62
|
addVertex(1.0f,0.0f, attribs1, attribs2, 1);
|
63
|
addVertex(0.0f,1.0f, attribs1, attribs2, 2);
|
64
|
addVertex(1.0f,1.0f, attribs1, attribs2, 3);
|
65
|
|
66
|
setAttribs(attribs1,attribs2);
|
67
|
}
|
68
|
|
69
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
/**
|
71
|
* Copy constructor.
|
72
|
*/
|
73
|
public MeshQuad(MeshQuad mesh, boolean deep)
|
74
|
{
|
75
|
super(mesh,deep);
|
76
|
}
|
77
|
|
78
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79
|
/**
|
80
|
* Copy the Mesh.
|
81
|
*
|
82
|
* @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
|
83
|
* normals and inflates (the rest, in particular the mVertAttribs2 containing texture
|
84
|
* coordinates and effect associations, is always deep copied)
|
85
|
*/
|
86
|
public MeshQuad copy(boolean deep)
|
87
|
{
|
88
|
return new MeshQuad(this,deep);
|
89
|
}
|
90
|
}
|