Project

General

Profile

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

examples / src / main / java / org / distorted / examples / generic / GenericMeshList.java @ 83e0ca5e

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
  CUBES      ( "Cubes"      , 3 ),
35
  RECTANGLES ( "Rectangles" , 2 ),
36
  SPHERE     ( "Sphere"     , 1 ),
37
  QUAD       ( "Quad"       , 0 ),
38
  TRIANGLES  ( "Triangles"  , 1 ),
39
  ;
40

    
41
  static final int LENGTH = values().length;
42
  private static final GenericMeshList[] meshes;
43
  private String mName;
44
  private int mDimension;
45

    
46
  static
47
    {
48
    int i=0;
49
    meshes = new GenericMeshList[LENGTH];
50

    
51
    for(GenericMeshList mesh: GenericMeshList.values())
52
      {
53
      meshes[i++] = mesh;
54
      }
55
    }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  GenericMeshList(String name, int dim )
60
    {
61
    mName      = name;
62
    mDimension =  dim;
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  static String getName(int ordinal)
68
    {
69
    return meshes[ordinal].mName;
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  static int getDimension(int ordinal)
75
    {
76
    return  meshes[ordinal].mDimension;
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
  static MeshBase createMesh(int ordinal, int cols, int rows, int slic, int bitmapID, String str)
82
    {
83
    MeshBase mesh;
84

    
85
    int maxsize = cols > rows ? (cols>slic ? cols:slic) : (rows>slic ? rows:slic) ;
86

    
87
    switch( meshes[ordinal] )
88
      {
89
      case CUBES     : if( bitmapID!=-1 )
90
                         {
91
                         mesh = new MeshCubes(cols, str, slic);
92
                         }
93
                       else
94
                         {
95
                         Static4D mapFB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)rows/maxsize);
96
                         Static4D mapLR = new Static4D(0.0f,0.0f, (float)slic/maxsize, (float)rows/maxsize);
97
                         Static4D mapTB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)slic/maxsize);
98

    
99
                         mesh = new MeshCubes(cols, str, slic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB);
100
                         }
101
                       mesh.setStretch(cols,rows,slic);
102
                       break;
103
      case RECTANGLES: mesh = new MeshRectangles(cols,rows);
104
                       mesh.setStretch(cols,rows,0);
105
                       break;
106
      case SPHERE    : mesh = new MeshSphere(rows);
107
                       mesh.setStretch(rows,rows,rows);
108
                       break;
109
      case QUAD      : mesh = new MeshQuad();
110
                       mesh.setStretch(1,1,0);
111
                       break;
112
      case TRIANGLES : mesh = new MeshTriangles(rows);
113
                       mesh.setStretch(rows,rows,0);
114
                       break;
115
      default:         mesh = null;
116
                       android.util.Log.e("Meshes", "Error: unimplemented Mesh!");
117
      }
118

    
119
    return mesh;
120
    }
121
  }
(4-4/8)