Exemplo n.º 1
0
  public void applyMatrix(Matrix3 matrix) {
    float position[] = new float[3];
    float normal[] = new float[3];
    float result[] = new float[3];
    int nbVert = this.mVertices.capacity() / D3DMesh.nbFloatPerVertex;

    for (int i = 0; i < nbVert; i++) {
      position[0] = this.mVertices.get(i * D3DMesh.nbFloatPerVertex + 0);
      position[1] = this.mVertices.get(i * D3DMesh.nbFloatPerVertex + 1);
      position[2] = this.mVertices.get(i * D3DMesh.nbFloatPerVertex + 2);

      normal[0] = this.mVertices.get(i * D3DMesh.nbFloatPerVertex + 3);
      normal[1] = this.mVertices.get(i * D3DMesh.nbFloatPerVertex + 4);
      normal[2] = this.mVertices.get(i * D3DMesh.nbFloatPerVertex + 5);

      Matrix3.mul(result, matrix, position);

      this.mVertices.put(i * D3DMesh.nbFloatPerVertex + 0, result[0]);
      this.mVertices.put(i * D3DMesh.nbFloatPerVertex + 1, result[1]);
      this.mVertices.put(i * D3DMesh.nbFloatPerVertex + 2, result[2]);

      Matrix3.mul(result, matrix, normal);

      this.mVertices.put(i * D3DMesh.nbFloatPerVertex + 3, result[0]);
      this.mVertices.put(i * D3DMesh.nbFloatPerVertex + 4, result[1]);
      this.mVertices.put(i * D3DMesh.nbFloatPerVertex + 5, result[2]);
    }
  }
Exemplo n.º 2
0
 public static Matrix3 getRotationMatrix(float ax, float ay, float az) {
   float cosax = getCos(ax);
   float sinax = getSin(ax);
   float cosay = getCos(ay);
   float sinay = getSin(ay);
   float cosaz = getCos(az);
   float sinaz = getSin(az);
   float tx[] = {1, 0, 0, 0, cosax, -sinax, 0, sinax, cosax};
   float ty[] = {cosay, 0, sinay, 0, 1.f, 0.f, -sinay, 0, cosay};
   float tz[] = {cosaz, -sinaz, 0, sinaz, cosaz, 0, 0, 0, 1};
   Matrix3 Rx = new Matrix3(tx);
   Matrix3 Ry = new Matrix3(ty);
   Matrix3 Rz = new Matrix3(tz);
   Matrix3 result = new Matrix3();
   Matrix3 tmpresult = new Matrix3();
   Matrix3.mul(tmpresult, Rx, Ry);
   Matrix3.mul(result, tmpresult, Rz);
   return result;
 }
Exemplo n.º 3
0
  private int eatChunk(
      byte buffer[], int offset, int count, float angle_y, float z_adjust, float scale) {
    int chunkid;
    int chunklength;
    int i = 0;
    int j;
    chunkid = read16(buffer, i + offset);
    byte buf[] = new byte[2];
    buf[0] = buffer[i + offset];
    buf[1] = buffer[i + offset + 1];
    chunklength = read32(buffer, i + 2 + offset);
    i = 6;

    float tmpV[] = new float[3];
    float tmpRes[] = new float[3];

    Matrix3 m = getRotationMatrix(-90, angle_y, 0);

    float v1[] = new float[4];

    int numVerts = 0;

    switch (chunkid) {
      case 0x4D4D:
        while ((read16(buffer, i + offset) != 0x3D3D) && (read16(buffer, i + offset) != 0xB000))
          i += 2;
        break;
      case 0x3D3D:
        break;
      case 0x4000:
        while (buffer[i + offset] != 0) {
          i++;
        }
        i++;
        currentcount++;
        break;
      case 0x4100:
        break;
      case 0x4110:
        if ((numVerts == 0) && (currentcount == count)) {
          numVerts = read16(buffer, i + offset);
          i += 2;
          buffVerts = new float[numVerts * 3];
          for (j = 0; j < numVerts; j++) {
            v1[0] = Float.intBitsToFloat(read32(buffer, i + offset));
            i += 4;
            v1[1] = Float.intBitsToFloat(read32(buffer, i + offset));
            i += 4;
            v1[2] = Float.intBitsToFloat(read32(buffer, i + offset));
            i += 4;
            v1[3] = 0.f;

            tmpV[0] = v1[0];
            tmpV[1] = v1[1];
            tmpV[2] = v1[2];

            Matrix3.mul(tmpRes, m, tmpV);

            buffVerts[j * 3] = tmpRes[0] * scale;
            buffVerts[j * 3 + 1] = tmpRes[1] * scale;
            buffVerts[j * 3 + 2] = tmpRes[2] * scale;

            this.mMeshPosition[0] = this.mMeshPosition[0] + (buffVerts[j * 3] / (float) numVerts);
            this.mMeshPosition[1] =
                this.mMeshPosition[1] + (buffVerts[j * 3 + 1] / (float) numVerts);
            this.mMeshPosition[2] =
                this.mMeshPosition[2] + (buffVerts[j * 3 + 2] / (float) numVerts);
          }

          for (j = 0; j < numVerts; j++) {
            buffVerts[j * 3] = buffVerts[j * 3] - this.mMeshPosition[0];
            buffVerts[j * 3 + 1] = buffVerts[j * 3 + 1] - this.mMeshPosition[1] + z_adjust;
            buffVerts[j * 3 + 2] = buffVerts[j * 3 + 2] - this.mMeshPosition[2];
          }

        } else {
          i = chunklength;
        }
        break;

      case 0x4120:
        if ((indices == null) && (currentcount == count)) {
          int numpolys = read16(buffer, i + offset);
          i += 2;
          indices = new char[numpolys * 3];
          for (j = 0; j < numpolys; j++) {
            indices[j * 3 + 2] = (char) read16(buffer, i + offset);
            i += 2;
            indices[j * 3 + 1] = (char) read16(buffer, i + offset);
            i += 2;
            indices[j * 3] = (char) read16(buffer, i + offset);
            i += 2;
            i += 2;
          }

          this.init(buffVerts, null, texCoords, indices);
        } else i = chunklength;
        break;

      case 0x4140:
        if (currentcount == count) {
          int numuvmaps = read16(buffer, i + offset);
          i += 2;

          texCoords = new float[numuvmaps * 2];
          for (j = 0; j < numuvmaps; j++) {
            texCoords[j * 2] = Float.intBitsToFloat(read32(buffer, i + offset));

            i += 4;
            texCoords[j * 2 + 1] = 1.f - Float.intBitsToFloat(read32(buffer, i + offset));

            i += 4;
          }
        }

        i = chunklength;

        break;

      default:
        i = chunklength;
        break;
    }

    while (i < chunklength) {
      i += eatChunk(buffer, i + offset, count, angle_y, z_adjust, scale);
    }
    return chunklength;
  }