Project

General

Profile

« Previous | Next » 

Revision ac6a08e7

Added by Leszek Koltunski about 4 years ago

Progress with MeshPolygon.

View differences:

src/main/java/org/distorted/library/mesh/MeshPolygon.java
43 43
  private void computeNumberOfVertices(int numPolygonVertices, int numPolygonBands)
44 44
     {
45 45
     numVertices = (numPolygonVertices*numPolygonBands+2)*(numPolygonBands-1) - 1;
46
     remainingVert = numVertices;
46 47
     }
47 48

  
48 49
///////////////////////////////////////////////////////////////////////////////////////////////////
......
51 52
    {
52 53
    remainingVert--;
53 54

  
54
    float band = mPolygonBands[2*polyBand  ];
55
    float elev = mPolygonBands[2*polyBand+1];
55
    if( polyBand<mNumPolygonBands-1 )
56
      {
57
      float band = mPolygonBands[2*polyBand  ];
58
      float elev = mPolygonBands[2*polyBand+1];
59

  
60
      float Xfirst  = mPolygonVertices[2*polyVertex  ];
61
      float Yfirst  = mPolygonVertices[2*polyVertex+1];
62

  
63
      int polyEndVer = polyVertex==mNumPolygonVertices-1 ? 0 : polyVertex+1;
64

  
65
      float Xlast   = mPolygonVertices[2*polyEndVer  ];
66
      float Ylast   = mPolygonVertices[2*polyEndVer+1];
67

  
68
      float quot = (float)index / (mNumPolygonBands-1-polyBand);
56 69

  
57
    float Xfirst  = mPolygonVertices[2*polyVertex  ]*band;
58
    float Yfirst  = mPolygonVertices[2*polyVertex+1]*band;
70
      float xEdge = Xfirst + quot*(Xlast-Xfirst);
71
      float yEdge = Yfirst + quot*(Ylast-Yfirst);
59 72

  
60
    int polyEndVer = polyVertex==mNumPolygonVertices-1 ? 0 : polyVertex+1;
73
      float x = band*xEdge;
74
      float y = band*yEdge;
61 75

  
62
    float Xlast   = mPolygonVertices[2*polyEndVer  ]*band;
63
    float Ylast   = mPolygonVertices[2*polyEndVer+1]*band;
76
      int nextPolyBand = polyBand+1;
77
      int prevPolyBand = (polyBand==0 ? polyBand : polyBand-1);
64 78

  
65
    float quot = (float)index / (polyBand-1);
79
      float concentricStep = mPolygonBands[2*nextPolyBand]-mPolygonBands[2*prevPolyBand];
80
      float nx = concentricStep*xEdge;
81
      float ny = concentricStep*yEdge;
66 82

  
67
    float x = Xfirst + quot*(Xlast-Xfirst);
68
    float y = Yfirst + quot*(Ylast-Yfirst);
83
      float nz = mPolygonBands[2*prevPolyBand+1]-mPolygonBands[2*nextPolyBand+1];
84
      float lenXYZ = (float)Math.sqrt(nx*nx + ny*ny + nz*nz);
85
      float lenXY  = (float)Math.sqrt(nx*nx + ny*ny);
69 86

  
70
    attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB  ] =    x;
71
    attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+1] =    y;
72
    attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+2] = elev;
87
      attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB  ] =    x;
88
      attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+1] =    y;
89
      attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+2] = elev;
73 90

  
74
    attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB  ] = 0.0f;  //
75
    attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;  // TODO
76
    attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;  //
91
      attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB  ] = (nz*nx) / (lenXY*lenXYZ);
92
      attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = (nz*ny) / (lenXY*lenXYZ);
93
      attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = lenXY / lenXYZ;
77 94

  
78
    attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB  ] = x+0.5f;
79
    attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = y+0.5f;
95
      attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB  ] = x+0.5f;
96
      attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = y+0.5f;
97
      }
98
    else
99
      {
100
      attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB  ] = 0.0f;
101
      attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+1] = 0.0f;
102
      attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+2] = mPolygonBands[2*polyBand+1];
103

  
104
      attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB  ] = 0.0f;
105
      attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;
106
      attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;
107

  
108
      attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB  ] = 0.5f;
109
      attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = 0.5f;
110
      }
80 111

  
81 112
    return vertex+1;
82 113
    }
......
112 143
    {
113 144
    int vertex=0;
114 145

  
115
    for(int band=0; band<mNumPolygonBands-1; band++)
146
    for(int polyBand=0; polyBand<mNumPolygonBands-1; polyBand++)
116 147
      for(int polyVertex=0; polyVertex<mNumPolygonVertices; polyVertex++)
117 148
        {
118
        vertex = createBandStrip(vertex,band,polyVertex,attribs1,attribs2);
149
        vertex = createBandStrip(vertex,polyBand,polyVertex,attribs1,attribs2);
119 150
        }
120 151
    }
121 152

  
......
129 160
 * @param bands      2K floats; K pairs of two floats each describing a single band.
130 161
 *                   From (1.0,Z[0]) (outer edge, its Z elevation) to (0.0,Z[K]) (the center,
131 162
 *                   its elevation). The polygon is split into such concentric bands.
163
 *                   Must be band[2*i] > band[2*(i+1)] !
132 164
 */
133 165
  public MeshPolygon(float[] verticesXY, float[] bands)
134 166
    {
......
137 169
    mPolygonVertices      = verticesXY;
138 170
    mPolygonBands         = bands;
139 171
    mNumPolygonVertices   = mPolygonVertices.length /2;
140
    mNumPolygonBands      = mPolygonBands.length;
172
    mNumPolygonBands      = mPolygonBands.length /2;
141 173

  
142 174
    computeNumberOfVertices(mNumPolygonVertices,mNumPolygonBands);
143 175

  

Also available in: Unified diff