Beispiel #1
0
 public void setTexturedQuad(
     float x1,
     float y1,
     float z1,
     float x2,
     float y2,
     float z2,
     float x3,
     float y3,
     float z3,
     float x4,
     float y4,
     float z4,
     float x1t,
     float y1t,
     float x2t,
     float y2t,
     float x3t,
     float y3t,
     float x4t,
     float y4t) {
   int trianglecount = 2;
   int verticecount = 4;
   init(trianglecount, verticecount);
   putTexturedQuad(
       x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x1t, y1t, x2t, y2t, x3t, y3t, x4t, y4t);
 }
Beispiel #2
0
 public static float getSin(float a) {
   if (sind == null) {
     init();
   }
   if (a >= 0.) {
     return sind[((int) a) % 360];
   } else return -sind[-((int) a) % 360];
 }
Beispiel #3
0
 public static float getCos(float a) {
   if (cosd == null) {
     init();
   }
   if (a >= 0.) {
     return cosd[((int) a) % 360];
   } else return cosd[-((int) a % 360)];
 }
Beispiel #4
0
  public D3DMesh buildShadowVolume(D3DVector lightVector) {

    int nbface = this.mIndices.capacity() / 3;

    int trianglecount = 0;
    D3DMesh shadowMesh = new D3DMesh();

    boolean faceToLight[] = new boolean[nbface];

    D3DVector v0 = new D3DVector();
    D3DVector v1 = new D3DVector();
    D3DVector v2 = new D3DVector();
    D3DVector vm1 = new D3DVector();
    D3DVector vm2 = new D3DVector();
    D3DVector res = new D3DVector();
    D3DVector vf = new D3DVector();
    for (int i = 0; i < this.mIndices.capacity(); i = i + 3) {
      int a = (int) (mIndices.get(i));
      int b = (int) (mIndices.get(i + 1));
      int c = (int) (mIndices.get(i + 2));

      v0.setFromVertice(mVertices, a);
      v1.setFromVertice(mVertices, b);
      v2.setFromVertice(mVertices, c);

      D3DVector.sub(vm1, v1, v0);
      D3DVector.sub(vm2, v2, v0);
      D3DVector.cross(res, vm1, vm2);
      res.normalize();

      D3DVector.add(vf, v0, v1);
      D3DVector.add(vf, vf, v2);

      float scalar = D3DVector.dot(res, lightVector);

      if (scalar > 0.0) {
        faceToLight[i / 3] = true;
      } else {

        trianglecount++;
      }
    }

    for (int i = 0; i < this.mIndices.capacity(); i = i + 3) {
      if (faceToLight[i / 3]) {
        for (int k = 0; k < 3; k++) {
          int a = mIndices.get(i + k);
          int b = mIndices.get(i + (k + 1) % 3);

          for (int l = 0; l < this.mIndices.capacity(); l = l + 3) {
            if (!faceToLight[l / 3]) {

              for (int z = 0; z < 3; z++) {
                int a2 = mIndices.get(l + z);
                int b2 = mIndices.get(l + (z + 1) % 3);

                if (((a == a2) && (b == b2)) || ((a == b2) && (b == a2))) {

                  trianglecount++;
                  trianglecount++;
                }
              }
            }
          }
        }
      }
    }

    shadowMesh.init(trianglecount);

    for (int i = 0; i < this.mIndices.capacity(); i = i + 3) {
      int a = (int) (mIndices.get(i));
      int b = (int) (mIndices.get(i + 1));
      int c = (int) (mIndices.get(i + 2));

      v0.setFromVertice(mVertices, a);
      v1.setFromVertice(mVertices, b);
      v2.setFromVertice(mVertices, c);

      D3DVector.sub(vm1, v1, v0);
      D3DVector.sub(vm2, v2, v0);
      D3DVector.cross(res, vm1, vm2);
      res.normalize();

      D3DVector.add(vf, v0, v1);
      D3DVector.add(vf, vf, v2);

      float scalar = D3DVector.dot(res, lightVector);

      if (scalar > 0.0) {
        faceToLight[i / 3] = true;
      } else {

        shadowMesh.putTriangle(
            mVertices.get(a * nbFloatPerVertex),
            mVertices.get(a * nbFloatPerVertex + 1),
            mVertices.get(a * nbFloatPerVertex + 2),
            mVertices.get(b * nbFloatPerVertex),
            mVertices.get(b * nbFloatPerVertex + 1),
            mVertices.get(b * nbFloatPerVertex + 2),
            mVertices.get(c * nbFloatPerVertex),
            mVertices.get(c * nbFloatPerVertex + 1),
            mVertices.get(c * nbFloatPerVertex + 2));
      }
    }

    for (int i = 0; i < this.mIndices.capacity(); i = i + 3) {
      if (faceToLight[i / 3]) {
        for (int k = 0; k < 3; k++) {
          int a = mIndices.get(i + k);
          int b = mIndices.get(i + (k + 1) % 3);

          for (int l = 0; l < this.mIndices.capacity(); l = l + 3) {
            if (!faceToLight[l / 3]) {

              for (int z = 0; z < 3; z++) {
                int a2 = mIndices.get(l + z);
                int b2 = mIndices.get(l + (z + 1) % 3);

                if (((a == a2) && (b == b2)) || ((a == b2) && (b == a2))) {
                  D3DVector lightVectP = lightVector.cpy();
                  lightVectP.mul(10000.f);

                  D3DVector vt1 = new D3DVector();
                  vt1.setFromVertice(mVertices, a2);
                  D3DVector vt1p = new D3DVector();
                  D3DVector.sub(vt1p, vt1, lightVectP);

                  D3DVector vt2 = new D3DVector();
                  vt2.setFromVertice(mVertices, b2);
                  D3DVector vt2p = new D3DVector();
                  D3DVector.sub(vt2p, vt2, lightVectP);

                  shadowMesh.putTriangle(
                      mVertices.get(a * nbFloatPerVertex),
                      mVertices.get(a * nbFloatPerVertex + 1),
                      mVertices.get(a * nbFloatPerVertex + 2),
                      mVertices.get(b * nbFloatPerVertex),
                      mVertices.get(b * nbFloatPerVertex + 1),
                      mVertices.get(b * nbFloatPerVertex + 2),
                      vt2p.get(0),
                      vt2p.get(1),
                      vt2p.get(2));

                  shadowMesh.putTriangle(
                      vt2p.get(0),
                      vt2p.get(1),
                      vt2p.get(2),
                      vt1p.get(0),
                      vt1p.get(1),
                      vt1p.get(2),
                      mVertices.get(a * nbFloatPerVertex),
                      mVertices.get(a * nbFloatPerVertex + 1),
                      mVertices.get(a * nbFloatPerVertex + 2));
                }
              }
            }
          }
        }
      }
    }

    shadowMesh.mVertices.position(0);
    shadowMesh.mIndices.position(0);
    return shadowMesh;
  }