Project

General

Profile

Download (4.49 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / mesh / MeshQuad.java @ 4f81e0c8

1 e1e94682 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2018 Leszek Koltunski                                                               //
3
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 e1e94682 Leszek Koltunski
//                                                                                               //
6 46b572b5 Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 e1e94682 Leszek Koltunski
// 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 46b572b5 Leszek Koltunski
// Distorted 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
// 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 46b572b5 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 e1e94682 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.library.mesh;
21
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
/**
24
 * Create a quad, i.e. two triangles with vertices at (+-0.5,+-0.5).
25
 * <p>
26
 * Mainly to have a simple example showing how to create a Mesh; otherwise a MeshQuad can be perfectly
27 12e379d6 Leszek Koltunski
 * emulated by a MeshRectangles(1,1) or a MeshCubes(1,1,0).
28 e1e94682 Leszek Koltunski
 */
29
public class MeshQuad extends MeshBase
30
  {
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 e54bfada Leszek Koltunski
  private void addVertex( float x, float y, float[] attribs1, float[] attribs2, int index)
34 e1e94682 Leszek Koltunski
    {
35 e54bfada Leszek Koltunski
    attribs1[VERT1_ATTRIBS*index + POS_ATTRIB  ] = x-0.5f;
36
    attribs1[VERT1_ATTRIBS*index + POS_ATTRIB+1] = 0.5f-y;
37
    attribs1[VERT1_ATTRIBS*index + POS_ATTRIB+2] = 0.0f;
38 e1e94682 Leszek Koltunski
39 e54bfada Leszek Koltunski
    attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB  ] = 0.0f;
40
    attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB+1] = 0.0f;
41
    attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB+2] = 1.0f;
42 e1e94682 Leszek Koltunski
43 e54bfada Leszek Koltunski
    attribs1[VERT1_ATTRIBS*index + INF_ATTRIB  ] = (x-0.5f);
44
    attribs1[VERT1_ATTRIBS*index + INF_ATTRIB+1] = (0.5f-y);
45
    attribs1[VERT1_ATTRIBS*index + INF_ATTRIB+2] = 0.01f   ;  // Inflated surface needs to be slightly in front
46 e1e94682 Leszek Koltunski
47 e54bfada Leszek Koltunski
    attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB  ] = x;
48
    attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB+1] = 1.0f-y;
49 1e672c1d Leszek Koltunski
    attribs2[VERT2_ATTRIBS*index + ASS_ATTRIB  ] = DEFAULT_ASSOCIATION;
50 e1e94682 Leszek Koltunski
    }
51
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
// PUBLIC API
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
  /**
56
   * Creates the underlying grid of 4 vertices, normals, inflates and texture coords.
57
   */
58
  public MeshQuad()
59
    {
60 0f10a0b6 Leszek Koltunski
    super();
61 e1e94682 Leszek Koltunski
62 e54bfada Leszek Koltunski
    float[] attribs1= new float[VERT1_ATTRIBS*4];
63
    float[] attribs2= new float[VERT2_ATTRIBS*4];
64 e1e94682 Leszek Koltunski
65 e54bfada Leszek Koltunski
    addVertex(0.0f,0.0f, attribs1, attribs2, 0);
66
    addVertex(0.0f,1.0f, attribs1, attribs2, 1);
67
    addVertex(1.0f,0.0f, attribs1, attribs2, 2);
68
    addVertex(1.0f,1.0f, attribs1, attribs2, 3);
69
70
    setAttribs(attribs1,attribs2);
71 e1e94682 Leszek Koltunski
    }
72 cbd502ec Leszek Koltunski
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
/**
75 4f81e0c8 Leszek Koltunski
 * Copy constructor.
76 cbd502ec Leszek Koltunski
 */
77 4f81e0c8 Leszek Koltunski
  public MeshQuad(MeshQuad mesh, boolean deep)
78 cbd502ec Leszek Koltunski
    {
79 4f81e0c8 Leszek Koltunski
    super(mesh,deep);
80 cbd502ec Leszek Koltunski
    }
81
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
/**
84 4f81e0c8 Leszek Koltunski
 * Copy the Mesh.
85
 *
86
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
87
 *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
88
 *             coordinates and effect assocciations, is always deep copied)
89 cbd502ec Leszek Koltunski
 */
90 4f81e0c8 Leszek Koltunski
  public MeshQuad copy(boolean deep)
91 cbd502ec Leszek Koltunski
    {
92 4f81e0c8 Leszek Koltunski
    return new MeshQuad(this,deep);
93 cbd502ec Leszek Koltunski
    }
94 e1e94682 Leszek Koltunski
  }