Project

General

Profile

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

examples / src / main / java / org / distorted / examples / generic / GenericMeshList.java @ 1535f677

1 83e0ca5e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.examples.generic;
21
22
import org.distorted.library.mesh.MeshBase;
23
import org.distorted.library.mesh.MeshCubes;
24
import org.distorted.library.mesh.MeshQuad;
25
import org.distorted.library.mesh.MeshRectangles;
26
import org.distorted.library.mesh.MeshSphere;
27
import org.distorted.library.mesh.MeshTriangles;
28
import org.distorted.library.type.Static4D;
29
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31
32
public enum GenericMeshList
33
  {
34 1535f677 Leszek Koltunski
  Cubes      ( 3 ),
35
  Rectangles ( 2 ),
36
  Sphere     ( 1 ),
37
  Quad       ( 0 ),
38
  Triangles  ( 1 ),
39 83e0ca5e Leszek Koltunski
  ;
40
41
  static final int LENGTH = values().length;
42
  private static final GenericMeshList[] meshes;
43
  private int mDimension;
44
45
  static
46
    {
47
    int i=0;
48
    meshes = new GenericMeshList[LENGTH];
49
50
    for(GenericMeshList mesh: GenericMeshList.values())
51
      {
52
      meshes[i++] = mesh;
53
      }
54
    }
55
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58 1535f677 Leszek Koltunski
  GenericMeshList( int dim )
59 83e0ca5e Leszek Koltunski
    {
60
    mDimension =  dim;
61
    }
62
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
65
  static String getName(int ordinal)
66
    {
67 1535f677 Leszek Koltunski
    return meshes[ordinal].name();
68 83e0ca5e Leszek Koltunski
    }
69
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
72
  static int getDimension(int ordinal)
73
    {
74
    return  meshes[ordinal].mDimension;
75
    }
76
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
79
  static MeshBase createMesh(int ordinal, int cols, int rows, int slic, int bitmapID, String str)
80
    {
81
    MeshBase mesh;
82
83
    int maxsize = cols > rows ? (cols>slic ? cols:slic) : (rows>slic ? rows:slic) ;
84
85
    switch( meshes[ordinal] )
86
      {
87 1535f677 Leszek Koltunski
      case Cubes     : if( bitmapID!=-1 )
88 83e0ca5e Leszek Koltunski
                         {
89
                         mesh = new MeshCubes(cols, str, slic);
90
                         }
91
                       else
92
                         {
93
                         Static4D mapFB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)rows/maxsize);
94
                         Static4D mapLR = new Static4D(0.0f,0.0f, (float)slic/maxsize, (float)rows/maxsize);
95
                         Static4D mapTB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)slic/maxsize);
96
97
                         mesh = new MeshCubes(cols, str, slic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB);
98
                         }
99
                       mesh.setStretch(cols,rows,slic);
100
                       break;
101 1535f677 Leszek Koltunski
      case Rectangles: mesh = new MeshRectangles(cols,rows);
102 83e0ca5e Leszek Koltunski
                       mesh.setStretch(cols,rows,0);
103
                       break;
104 1535f677 Leszek Koltunski
      case Sphere    : mesh = new MeshSphere(rows);
105 83e0ca5e Leszek Koltunski
                       mesh.setStretch(rows,rows,rows);
106
                       break;
107 1535f677 Leszek Koltunski
      case Quad      : mesh = new MeshQuad();
108 83e0ca5e Leszek Koltunski
                       mesh.setStretch(1,1,0);
109
                       break;
110 1535f677 Leszek Koltunski
      case Triangles : mesh = new MeshTriangles(rows);
111 83e0ca5e Leszek Koltunski
                       mesh.setStretch(rows,rows,0);
112
                       break;
113
      default:         mesh = null;
114
                       android.util.Log.e("Meshes", "Error: unimplemented Mesh!");
115
      }
116
117
    return mesh;
118
    }
119
  }