public void onDrawFrame(GL10 glUnused) {
      super.onDrawFrame(glUnused);
      // -- no proper physics here, just a bad approximation to keep
      // this example as short as possible ;-)
      mRaptor.setZ(mRaptor.getZ() + 2f);
      mRaptor.setX((float) Math.sin(mTime) * 20f);
      mRaptor.setRotZ((float) Math.sin(mTime + 8f) * -30f);
      mRaptor.setRotY(180 + (mRaptor.getRotZ() * .1f));
      mRaptor.setRotY(180);
      mRaptor.setY((float) Math.cos(mTime) * 10f);
      mRaptor.setRotX((float) Math.cos(mTime + 1f) * -20f);

      mSphere.setZ(mRaptor.getZ());
      mTime += .01f;

      if (mRootCube.getZ() - mRaptor.getZ() <= (30 * -6)) {
        mRootCube.setZ(mRaptor.getZ());
      }
    }
Exemple #2
0
  private void buildMesh(Model model, Stack<ALight> lights)
      throws TextureException, ParsingException {
    Object3D o = new Object3D(model.name);
    boolean hasUVs = model.layerElementUV.uVIndex != null;

    int[] vidx = model.polygonVertexIndex.data;
    int[] uvidx = null;
    float[] modelVerts = model.vertices.data;
    float[] modelNorm = model.layerElementNormal.normals.data;
    float[] modelUv = null;

    ArrayList<Integer> indices = new ArrayList<Integer>();
    ArrayList<Float> vertices = new ArrayList<Float>();
    ArrayList<Float> normals = new ArrayList<Float>();
    ArrayList<Float> uvs = null;

    if (hasUVs) {
      uvs = new ArrayList<Float>();
      uvidx = model.layerElementUV.uVIndex.data;
      modelUv = model.layerElementUV.uV.data;
    }

    int count = 0;
    int indexCount = 0;
    int[] triIds = new int[3];
    int[] quadIds = new int[6];
    int i = 0, j = 0, k = 0;
    int vidxLen = vidx.length;

    for (i = 0; i < vidxLen; ++i) {
      count++;

      if (vidx[i] < 0) {
        if (count == 3) {
          int index1 = vidx[i - 2], index2 = vidx[i - 1], index3 = (vidx[i] * -1) - 1;

          indices.add(indexCount++);
          indices.add(indexCount++);
          indices.add(indexCount++);

          triIds[0] = index1 * 3;
          triIds[1] = index2 * 3;
          triIds[2] = index3 * 3;

          for (j = 0; j < 3; ++j) {
            int cid = triIds[j];
            for (k = 0; k < 3; ++k) {
              vertices.add(modelVerts[cid + k]);
              int dir = i == 0 ? -1 : 1;
              normals.add(modelNorm[cid + k] * dir);
            }
          }

          if (hasUVs) {
            int uvIndex3 = uvidx[i] * 2;
            int uvIndex2 = uvidx[i - 1] * 2;
            int uvIndex1 = uvidx[i - 2] * 2;

            uvs.add(modelUv[uvIndex1 + 0]);
            uvs.add(1f - modelUv[uvIndex1 + 1]);

            uvs.add(modelUv[uvIndex2 + 0]);
            uvs.add(1f - modelUv[uvIndex2 + 1]);

            uvs.add(modelUv[uvIndex3 + 0]);
            uvs.add(1f - modelUv[uvIndex3 + 1]);
          }
        } else {
          int index1 = vidx[i - 3];
          int index2 = vidx[i - 2];
          int index3 = vidx[i - 1];
          int index4 = (vidx[i] * -1) - 1;

          indices.add(indexCount++);
          indices.add(indexCount++);
          indices.add(indexCount++);
          indices.add(indexCount++);
          indices.add(indexCount++);
          indices.add(indexCount++);

          quadIds[0] = index1 * 3;
          quadIds[1] = index2 * 3;
          quadIds[2] = index3 * 3;
          quadIds[3] = index4 * 3;
          quadIds[4] = index1 * 3;
          quadIds[5] = index3 * 3;

          for (j = 0; j < 6; ++j) {
            int cid = quadIds[j];
            for (k = 0; k < 3; ++k) {
              vertices.add(modelVerts[cid + k]);
              normals.add(modelNorm[cid + k]);
            }
          }

          if (hasUVs) {
            int uvIndex1 = uvidx[i - 3] * 2;
            int uvIndex2 = uvidx[i - 2] * 2;
            int uvIndex3 = uvidx[i - 1] * 2;
            int uvIndex4 = uvidx[i] * 2;

            quadIds[0] = uvIndex1;
            quadIds[1] = uvIndex2;
            quadIds[2] = uvIndex3;
            quadIds[3] = uvIndex4;
            quadIds[4] = uvIndex1;
            quadIds[5] = uvIndex3;

            for (j = 0; j < 6; ++j) {
              int cid = quadIds[j];
              for (k = 0; k < 2; ++k) {
                if (k == 0) uvs.add(modelUv[cid + k]);
                else uvs.add(1f - modelUv[cid + k]);
              }
            }
          }
        }
        count = 0;
      }
    }

    o.setData(
        convertFloats(vertices),
        convertFloats(normals),
        hasUVs ? convertFloats(uvs) : null,
        null,
        convertIntegers(indices));

    vertices.clear();
    vertices = null;
    normals.clear();
    normals = null;
    if (hasUVs) {
      uvs.clear();
      uvs = null;
    }
    indices.clear();
    indices = null;
    o.setMaterial(getMaterialForMesh(o, model.name));
    setMeshTextures(o, model.name);

    o.setPosition(model.properties.lclTranslation);
    o.setX(o.getX() * -1);
    o.setScale(model.properties.lclScaling);
    o.setRotation(model.properties.lclRotation);
    o.setRotZ(-o.getRotZ());

    mRootObject.addChild(o);
  }