Project

General

Profile

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

library / src / main / java / org / distorted / library / mesh / MeshQuad.java @ fc3b9f16

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2018 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
package org.distorted.library.mesh;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
/**
24
 * Create a quad - 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
 * emulated by a MeshRectangles(1,1) or a MeshCubes(1,1,0).
28
 */
29
public class MeshQuad extends MeshBase
30
  {
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
  private void addVertex( float x, float y, float[] attribs1, float[] attribs2, int index)
34
    {
35
    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

    
39
    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

    
43
    attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB  ] = x;
44
    attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB+1] = 1.0f-y;
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
// PUBLIC API
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
  /**
51
   * Creates the underlying grid of 4 vertices, normals, inflates and texture coords.
52
   */
53
  public MeshQuad()
54
    {
55
    super();
56

    
57
    float[] attribs1= new float[VERT1_ATTRIBS*4];
58
    float[] attribs2= new float[VERT2_ATTRIBS*4];
59

    
60
    addVertex(0.0f,0.0f, attribs1, attribs2, 0);
61
    addVertex(0.0f,1.0f, attribs1, attribs2, 1);
62
    addVertex(1.0f,0.0f, attribs1, attribs2, 2);
63
    addVertex(1.0f,1.0f, attribs1, attribs2, 3);
64

    
65
    setAttribs(attribs1,attribs2);
66
    }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
/**
70
 * Copy constructor.
71
 */
72
  public MeshQuad(MeshQuad mesh, boolean deep)
73
    {
74
    super(mesh,deep);
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
/**
79
 * Copy the Mesh.
80
 *
81
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
82
 *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
83
 *             coordinates and effect associations, is always deep copied)
84
 */
85
  public MeshQuad copy(boolean deep)
86
    {
87
    return new MeshQuad(this,deep);
88
    }
89
  }
(7-7/10)