Project

General

Profile

« Previous | Next » 

Revision d44ac567

Added by Leszek Koltunski over 8 years ago

Minor stuff - make the Bitmaps and the Cubes agree on the size of the grid, mostly.

View differences:

src/main/java/org/distorted/library/DistortedBitmap.java
70 70
 */
71 71
   public DistortedBitmap(int width, int height, int cols)
72 72
     {     
73
     int xsize = cols;
74
     int ysize = cols*height/width;
73
     int xsize = (cols+1);
74
     int ysize = (cols+1)*height/width;
75 75
     
76 76
     if( xsize<2   ) xsize=  2;
77 77
     if( xsize>256 ) xsize=256;
src/main/java/org/distorted/library/DistortedBitmapGrid.java
31 31

  
32 32
  DistortedBitmapGrid(int xLength, int yLength)
33 33
    {
34
    float tmpx,tmpy,tmpz;
35
    float[] bufferData;
36

  
34 37
    dataLength = 2*xLength*(yLength-1)+2*(yLength-2); // (yLength-1) strips, 2*xLength triangles in each, plus 2 degenerate triangles per each of (yLength-2) joins 
38

  
39
    ////////////////////////////////////////////////////////////
40
    // vertex indices
41

  
42
    int offset=0;
35 43
    final short[] indexData = new short[dataLength];
36
    
37
    int offset=0;    
38
    for(int y=0; y<yLength-1; y++) 
44

  
45
    for(int y=0; y<yLength-1; y++)
39 46
      {
40 47
      if (y>0) indexData[offset++] = (short) (y*xLength); // Degenerate begin: repeat first vertex
41 48

  
42
      for (int x = 0; x < xLength; x++) 
49
      for (int x = 0; x < xLength; x++)
43 50
        {
44 51
        indexData[offset++] = (short) (( y   *xLength)+x);
45 52
        indexData[offset++] = (short) (((y+1)*xLength)+x);
......
48 55
      if (y<yLength-2) indexData[offset++] = (short) (((y+1)*xLength) + (xLength-1)); // Degenerate end: repeat last vertex
49 56
      }
50 57

  
51
    // for(int g=0; g<dataLength; g++) Log.e(TAG_BACKGROUND, "index["+g+"]="+indexData[g]);
58
    // for(int g=0; g<dataLength; g++) Log.e("grid", "index["+g+"]="+indexData[g]);
52 59

  
53
    float[] bufferData = new float[NORMAL_DATA_SIZE*dataLength];
60
    ////////////////////////////////////////////////////////////
61
    // texture
54 62

  
55 63
    offset=0;
56
    for(int i=0; i<dataLength; i++)
57
      {
58
      bufferData[offset++] = 0.0f; // x
59
      bufferData[offset++] = 0.0f; // y
60
      bufferData[offset++] = 1.0f; // z
61
      }
62
    mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
63
    mGridNormals.put(bufferData).position(0); 
64

  
65
    float tmpx,tmpy,tmpz;
66 64
    bufferData = new float[TEX_DATA_SIZE*dataLength];
67 65

  
68
    offset=0;
69 66
    for(int i=0; i<dataLength; i++)
70 67
      {
71 68
      tmpx = ((float)(indexData[offset/2]%xLength))/(xLength-1);
......
74 71
      bufferData[offset++] = tmpx; // s=x
75 72
      bufferData[offset++] = tmpy; // t=y
76 73
      }
77
    mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
78
    mGridTexture.put(bufferData).position(0); 
74
    mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
75
    mGridTexture.put(bufferData).position(0);
79 76

  
80
    //for(int g=0; g<dataLength; g++) Log.e(TAG_BACKGROUND, "tex["+g+"]=("+bufferData[2*g]+","+bufferData[2*g+1]+")");
81
    //Log.e(TAG, "regWidth="+(2*mRegW)+" regHeight="+(2*mRegH)+" xLength="+xLength+" yLength="+yLength);
77
    //for(int g=0; g<dataLength; g++) Log.e("grid", "tex["+g+"]=("+bufferData[2*g]+","+bufferData[2*g+1]+")");
78
    //Log.e("grid", "regWidth="+(2*mRegW)+" regHeight="+(2*mRegH)+" xLength="+xLength+" yLength="+yLength);
79

  
80
    ////////////////////////////////////////////////////////////
81
    // vertex positions
82 82

  
83 83
    offset=0;
84 84
    bufferData= new float[POSITION_DATA_SIZE*dataLength];
......
93 93
      bufferData[offset++] = (0.5f-tmpy); // y
94 94
      bufferData[offset++] =        tmpz; // z
95 95
      }
96
    mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
97
    mGridPositions.put(bufferData).position(0); 
96
    mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
97
    mGridPositions.put(bufferData).position(0);
98

  
99
    //for(int g=0; g<dataLength; g++) android.util.Log.e("grid", "pos["+g+"]=("+bufferData[3*g]+","+bufferData[3*g+1]+")");
100
 
101
    ////////////////////////////////////////////////////////////
102
    // normals
98 103

  
99
    //for(int g=0; g<dataLength; g++) android.util.Log.e("BACKGROUND", "pos["+g+"]=("+bufferData[3*g]+","+bufferData[3*g+1]+")");
104
    offset=0;
105
    bufferData = new float[NORMAL_DATA_SIZE*dataLength];
106

  
107
    for(int i=0; i<dataLength; i++)
108
      {
109
      bufferData[offset++] = 0.0f; // x
110
      bufferData[offset++] = 0.0f; // y
111
      bufferData[offset++] = 1.0f; // z
112
      }
113
    mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
114
    mGridNormals.put(bufferData).position(0);
100 115
    }
101 116
  }

Also available in: Unified diff