예제 #1
0
  public void loadCollisionMask() {
    // float minX = verticies.get(1).x, minY = verticies.get(1).y, minZ =
    // verticies.get(1).z, maxX = verticies.get(1).x, maxY =
    // verticies.get(1).y, maxZ = verticies.get(1).z;

    for (int i = 0; i < verticies.size(); i++) {
      if (verticies.get(i).x < xMin) xMin = verticies.get(i).x;
      else if (verticies.get(i).x > xMax) xMax = verticies.get(i).x;

      if (verticies.get(i).y < yMin) yMin = verticies.get(i).y;
      else if (verticies.get(i).y > yMax) yMax = verticies.get(i).y;

      if (verticies.get(i).z < zMin) zMin = verticies.get(i).z;
      else if (verticies.get(i).z > zMax) zMax = verticies.get(i).z;
    }
    // System.out.println("min:(" + xMin + ", " + yMin + ", " + zMin + ")   max:(" + xMax + ", " +
    // yMax + ", " + zMax + ")");

    maskVerticies.add(new Vector3f(xMin, yMin, zMin)); // Left-Back-Bottom
    maskVerticies.add(new Vector3f(xMin, yMax, zMin)); // Left-Back-Top
    maskVerticies.add(new Vector3f(xMin, yMin, zMax)); // Left-Front-Bottom
    maskVerticies.add(new Vector3f(xMin, yMax, zMax)); // Left-Front-Top
    maskVerticies.add(new Vector3f(xMax, yMin, zMin)); // Right-Back-Bottom
    maskVerticies.add(new Vector3f(xMax, yMax, zMin)); // Right-Back-Top
    maskVerticies.add(new Vector3f(xMax, yMin, zMax)); // Right-Front-Bottom
    maskVerticies.add(new Vector3f(xMax, yMax, zMax)); // Right-Front-Top

    // System.out.println(maskVerticies.size());
    maskNormals.add(new Vector3f(-1, -1, -1)); // Left-Back-Bottom
    maskNormals.get(0).normalise();
    maskNormals.add(new Vector3f(-1, 1, -1)); // Left-Back-Top
    maskNormals.get(1).normalise();
    maskNormals.add(new Vector3f(-1, -1, 1)); // Left-Front-Bottom
    maskNormals.get(2).normalise();
    maskNormals.add(new Vector3f(-1, 1, 1)); // Left-Front-Top
    maskNormals.get(3).normalise();
    maskNormals.add(new Vector3f(1, -1, -1)); // Right-Back-Bottom
    maskNormals.get(4).normalise();
    maskNormals.add(new Vector3f(1, 1, -1)); // Right-Back-Top
    maskNormals.get(5).normalise();
    maskNormals.add(new Vector3f(1, -1, 1)); // Right-Front-Bottom
    maskNormals.get(6).normalise();
    maskNormals.add(new Vector3f(1, 1, 1)); // Right-Front-Top
    maskNormals.get(7).normalise();
    // System.out.println(maskNormals.get(0).x);

    maskFaces.add(new QuadFace(new Vector4f(2, 3, 1, 0), new Vector4f(0, 1, 3, 2)));
    maskFaces.add(new QuadFace(new Vector4f(4, 5, 7, 6), new Vector4f(4, 5, 7, 6)));
    maskFaces.add(new QuadFace(new Vector4f(0, 1, 5, 4), new Vector4f(0, 1, 5, 4)));
    maskFaces.add(new QuadFace(new Vector4f(6, 7, 3, 2), new Vector4f(2, 3, 7, 6)));
    maskFaces.add(new QuadFace(new Vector4f(4, 6, 2, 0), new Vector4f(0, 2, 6, 4)));
    maskFaces.add(new QuadFace(new Vector4f(1, 3, 7, 5), new Vector4f(1, 3, 7, 5)));
    // System.out.println(maskFaces.size());

    xCollisionRadii = Math.abs(xMax - xMin) / 2;
    yCollisionRadii = Math.abs(yMax - yMin) / 2;
    zCollisionRadii = Math.abs(zMax - zMin) / 2;
  }
 public void collid(Vector2f vec) {
   if (Math.abs(vec.x) > Math.abs(vec.y)) {
     this.y += vec.y;
     if (vec.y < 0) inGround = true;
   } else {
     this.x += vec.x;
   }
   collided = true;
 }