1 |
e1e94682
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
c4d06f90
|
Leszek Koltunski
|
// Copyright 2018 Leszek Koltunski leszek@koltunski.pl //
|
3 |
e1e94682
|
Leszek Koltunski
|
// //
|
4 |
46b572b5
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
e1e94682
|
Leszek Koltunski
|
// //
|
6 |
c4d06f90
|
Leszek Koltunski
|
// 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 |
e1e94682
|
Leszek Koltunski
|
// //
|
11 |
c4d06f90
|
Leszek Koltunski
|
// This library is distributed in the hope that it will be useful, //
|
12 |
e1e94682
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
c4d06f90
|
Leszek Koltunski
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
|
14 |
|
|
// Lesser General Public License for more details. //
|
15 |
e1e94682
|
Leszek Koltunski
|
// //
|
16 |
c4d06f90
|
Leszek Koltunski
|
// 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 |
e1e94682
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20 |
|
|
|
21 |
|
|
package org.distorted.library.mesh;
|
22 |
|
|
|
23 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
24 |
|
|
/**
|
25 |
fc3b9f16
|
Leszek Koltunski
|
* Create a quad - two triangles with vertices at (+-0.5,+-0.5).
|
26 |
e1e94682
|
Leszek Koltunski
|
* <p>
|
27 |
|
|
* Mainly to have a simple example showing how to create a Mesh; otherwise a MeshQuad can be perfectly
|
28 |
12e379d6
|
Leszek Koltunski
|
* emulated by a MeshRectangles(1,1) or a MeshCubes(1,1,0).
|
29 |
e1e94682
|
Leszek Koltunski
|
*/
|
30 |
|
|
public class MeshQuad extends MeshBase
|
31 |
|
|
{
|
32 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
e54bfada
|
Leszek Koltunski
|
private void addVertex( float x, float y, float[] attribs1, float[] attribs2, int index)
|
35 |
e1e94682
|
Leszek Koltunski
|
{
|
36 |
e54bfada
|
Leszek Koltunski
|
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 |
e1e94682
|
Leszek Koltunski
|
|
40 |
e54bfada
|
Leszek Koltunski
|
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 |
e1e94682
|
Leszek Koltunski
|
|
44 |
e54bfada
|
Leszek Koltunski
|
attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB ] = x;
|
45 |
|
|
attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB+1] = 1.0f-y;
|
46 |
e1e94682
|
Leszek Koltunski
|
}
|
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 |
0f10a0b6
|
Leszek Koltunski
|
super();
|
57 |
e1e94682
|
Leszek Koltunski
|
|
58 |
e54bfada
|
Leszek Koltunski
|
float[] attribs1= new float[VERT1_ATTRIBS*4];
|
59 |
|
|
float[] attribs2= new float[VERT2_ATTRIBS*4];
|
60 |
e1e94682
|
Leszek Koltunski
|
|
61 |
e54bfada
|
Leszek Koltunski
|
addVertex(0.0f,0.0f, attribs1, attribs2, 0);
|
62 |
c2032d8c
|
Leszek Koltunski
|
addVertex(1.0f,0.0f, attribs1, attribs2, 1);
|
63 |
|
|
addVertex(0.0f,1.0f, attribs1, attribs2, 2);
|
64 |
e54bfada
|
Leszek Koltunski
|
addVertex(1.0f,1.0f, attribs1, attribs2, 3);
|
65 |
|
|
|
66 |
|
|
setAttribs(attribs1,attribs2);
|
67 |
e1e94682
|
Leszek Koltunski
|
}
|
68 |
cbd502ec
|
Leszek Koltunski
|
|
69 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
/**
|
71 |
4f81e0c8
|
Leszek Koltunski
|
* Copy constructor.
|
72 |
cbd502ec
|
Leszek Koltunski
|
*/
|
73 |
4f81e0c8
|
Leszek Koltunski
|
public MeshQuad(MeshQuad mesh, boolean deep)
|
74 |
cbd502ec
|
Leszek Koltunski
|
{
|
75 |
4f81e0c8
|
Leszek Koltunski
|
super(mesh,deep);
|
76 |
cbd502ec
|
Leszek Koltunski
|
}
|
77 |
|
|
|
78 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79 |
|
|
/**
|
80 |
4f81e0c8
|
Leszek Koltunski
|
* 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 |
aee078f8
|
Leszek Koltunski
|
* coordinates and effect associations, is always deep copied)
|
85 |
cbd502ec
|
Leszek Koltunski
|
*/
|
86 |
4f81e0c8
|
Leszek Koltunski
|
public MeshQuad copy(boolean deep)
|
87 |
cbd502ec
|
Leszek Koltunski
|
{
|
88 |
4f81e0c8
|
Leszek Koltunski
|
return new MeshQuad(this,deep);
|
89 |
cbd502ec
|
Leszek Koltunski
|
}
|
90 |
e1e94682
|
Leszek Koltunski
|
}
|