Project

General

Profile

« Previous | Next » 

Revision e1e94682

Added by Leszek Koltunski over 5 years ago

New MeshQuad class.

View differences:

src/main/java/org/distorted/library/main/DistortedScreen.java
27 27
import android.opengl.GLES31;
28 28

  
29 29
import org.distorted.library.effect.MatrixEffectMove;
30
import org.distorted.library.mesh.MeshBase;
31
import org.distorted.library.mesh.MeshFlat;
30
import org.distorted.library.mesh.MeshQuad;
32 31
import org.distorted.library.type.Static3D;
33 32

  
34 33
/**
......
43 42

  
44 43
  private static final int NUM_FRAMES  = 100;
45 44

  
46
  private MeshBase fpsMesh;
45
  private MeshQuad fpsMesh;
47 46
  private DistortedTexture fpsTexture;
48 47
  private DistortedEffects fpsEffects;
49 48
  private Canvas fpsCanvas;
......
162 161

  
163 162
      fpsString = "";
164 163
      fpsBitmap = Bitmap.createBitmap(fpsW, fpsH, Bitmap.Config.ARGB_8888);
165
      fpsMesh = new MeshFlat(1, 1);
164
      fpsMesh = new MeshQuad();
166 165
      fpsTexture = new DistortedTexture(fpsW, fpsH);
167 166
      fpsTexture.setTexture(fpsBitmap);
168 167
      fpsCanvas = new Canvas(fpsBitmap);
src/main/java/org/distorted/library/mesh/MeshQuad.java
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, 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
 * emulated by a MeshFlat(1,1) or a MeshCubes(1,1,0).
28
 */
29
public class MeshQuad extends MeshBase
30
  {
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
  private void addVertex(int vertex, float x, float y, float[] attribs)
34
    {
35
    attribs[VERT_ATTRIBS*vertex + POS_ATTRIB  ] = x-0.5f;
36
    attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = 0.5f-y;
37
    attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = 0.0f;
38

  
39
    attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB  ] = 0.0f;
40
    attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;
41
    attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;
42

  
43
    attribs[VERT_ATTRIBS*vertex + INF_ATTRIB  ] = (x-0.5f);
44
    attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = (0.5f-y);
45
    attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.01f   ;  // Inflated surface needs to be slightly in front
46

  
47
    attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB  ] = x;
48
    attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f-y;
49
    }
50

  
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52
// PUBLIC API
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
  /**
55
   * Creates the underlying grid of 4 vertices, normals, inflates and texture coords.
56
   */
57
  public MeshQuad()
58
    {
59
    super(0.0f);
60

  
61
    float[] attribs= new float[VERT_ATTRIBS*4];
62

  
63
    addVertex(0, 0.0f,0.0f, attribs);
64
    addVertex(1, 0.0f,1.0f, attribs);
65
    addVertex(2, 1.0f,0.0f, attribs);
66
    addVertex(3, 1.0f,1.0f, attribs);
67

  
68
    setAttribs(attribs);
69
    }
70
  }

Also available in: Unified diff