Пример #1
0
  @Override
  public void simpleUpdate(float tpf) {
    Vector3f intersection = getWorldIntersection();
    updateHintText(intersection);

    if (raiseTerrain) {

      if (intersection != null) {
        adjustHeight(intersection, 64, tpf * 60);
      }
    } else if (lowerTerrain) {
      if (intersection != null) {
        adjustHeight(intersection, 64, -tpf * 60);
      }
    }

    if (terrain != null && intersection != null) {
      float h = terrain.getHeight(new Vector2f(intersection.x, intersection.z));
      Vector3f tl = terrain.getWorldTranslation();
      marker.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));
      markerNormal.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));

      Vector3f normal = terrain.getNormal(new Vector2f(intersection.x, intersection.z));
      ((Arrow) markerNormal.getMesh()).setArrowExtent(normal);
    }
  }
Пример #2
0
  public void onAnalog(String name, float value, float tpf) {
    if ((Boolean) player.getUserData("alive")) {
      if (name.equals("mousePick")) {
        // shoot Bullet
        if (System.currentTimeMillis() - bulletCooldown > 83f) {
          bulletCooldown = System.currentTimeMillis();

          Vector3f aim = getAimDirection();
          Vector3f offset = new Vector3f(aim.y / 3, -aim.x / 3, 0);

          //                    init bullet 1
          Spatial bullet = getSpatial("Bullet");
          Vector3f finalOffset = aim.add(offset).mult(30);
          Vector3f trans = player.getLocalTranslation().add(finalOffset);
          bullet.setLocalTranslation(trans);
          bullet.addControl(
              new BulletControl(
                  aim, settings.getWidth(), settings.getHeight(), particleManager, grid));
          bulletNode.attachChild(bullet);

          //                    init bullet 2
          Spatial bullet2 = getSpatial("Bullet");
          finalOffset = aim.add(offset.negate()).mult(30);
          trans = player.getLocalTranslation().add(finalOffset);
          bullet2.setLocalTranslation(trans);
          bullet2.addControl(
              new BulletControl(
                  aim, settings.getWidth(), settings.getHeight(), particleManager, grid));
          bulletNode.attachChild(bullet2);

          sound.shoot();
        }
      }
    }
  }
Пример #3
0
 /**
  * Create a prop, add it to the scene with its base at the insertion point, and pick it. Assumes
  * that the application is in world-building mode.
  *
  * @param propType which kind of prop to add (not null)
  * @param relativeSize the prop's size relative to standard (>0)
  */
 private void addAsPick(String propType, float relativeSize) {
   assert propType != null;
   assert relativeSize > 0f : relativeSize;
   /*
    * Create the prop.
    */
   Node node = create(propType, relativeSize);
   /*
    * The new prop is to be the ONLY picked spatial, so unpick the rest.
    */
   PickablesNode pickables = scene.getWorld().getPickables();
   pickables.clearPick();
   /*
    * Add and pick the prop.
    */
   pickables.add(node);
   SpatialProperties.setPicked(node, true);
   /*
    * Initialize the prop's position.
    */
   Cursor3DIndicator cursor3D = scene.getIndicators().getCursor3D();
   Vector3f baseLocation = cursor3D.getWorldLocation();
   float baseY = MySpatial.getMinY(node);
   Vector3f centerLocation = baseLocation.add(0f, -baseY, 0f);
   MySpatial.setWorldLocation(node, centerLocation);
 }
Пример #4
0
  @Override
  public void onPreUpdate(float tpf) {
    Vector3f delta = velocity.mult(tpf);
    Vector3f pos = movedNode.getLocalTranslation().clone();
    smal.checkMotionAllowed(pos, delta, normal);
    movedNode.setLocalTranslation(pos.add(delta));
    velocity.set(0, 0, 0);

    normalAligned.rotateUpTo(normal);
  }
  /**
   * Method for calculating new velocity of agent based on steering vector.
   *
   * @see AbstractSteeringBehavior#calculateSteering()
   * @return The new velocity for this agent based on steering vector
   */
  protected Vector3f calculateNewVelocity() {
    agent.setAcceleration(calculateSteering().mult(1 / agentTotalMass()));
    velocity = velocity.add(agent.getAcceleration());
    agent.setVelocity(velocity);

    if (velocity.length() > agent.getMaxMoveSpeed()) {
      velocity = velocity.normalize().mult(agent.getMaxMoveSpeed());
    }
    return velocity;
  }
Пример #6
0
  /**
   * Compute bounds from an array of points
   *
   * @param pts
   * @param transform
   * @return
   */
  public static BoundingBox computeBoundForPoints(Vector3f[] pts, Transform transform) {
    Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY);
    Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY);
    Vector3f temp = new Vector3f();
    for (int i = 0; i < pts.length; i++) {
      transform.transformVector(pts[i], temp);

      min.minLocal(temp);
      max.maxLocal(temp);
    }
    Vector3f center = min.add(max).multLocal(0.5f);
    Vector3f extent = max.subtract(min).multLocal(0.5f);
    return new BoundingBox(center, extent.x, extent.y, extent.z);
  }
  void moveTo(Vector3f pos) {
    float speed = playerInfo.getRealSpeed();
    Vector3f location = spatial.getLocalTranslation();
    Vector3f target = pos.clone();

    Vector3f distance = target.subtract(location);
    if (distance.length() < 0.3f) {
      return;
    }
    Vector3f newVel = distance.normalize().mult(speed);
    // Vector3f steering = desierdVel.subtract(velocity).negate();

    spatial.setLocalTranslation(location.add(newVel));
  }
Пример #8
0
  private void refreshFont() {
    Camera cam = IsoCamera.getInstance().getCam();

    Vector3f start = from.getPlanet().getPosition();
    Vector3f end = to.getPlanet().getPosition();

    float width = label.getLineWidth();
    Random r = new Random();
    //        float height = r.nextFloat() * end.subtract(start).z;

    Vector3f position = new Vector3f(width / 2, .15f, 0);
    Vector3f fontPos = start.add(end.subtract(start).mult(0.4f + 0.75f * r.nextFloat()));
    position.addLocal(fontPos);

    Vector3f up = cam.getUp().clone();
    Vector3f dir = cam.getDirection().clone().negateLocal().normalizeLocal();
    Vector3f left = cam.getLeft().clone().normalizeLocal().negateLocal();

    Quaternion look = new Quaternion();
    look.fromAxes(left, up, dir);

    label.setLocalTransform(new Transform(position, look));

    //        Vector3f camPos = IsoCamera.getInstance().getCam().getLocation();
    //        Vector3f fontPos = to.getPlanet().getPosition().
    //                subtract(from.getPlanet().getPosition());
    //        Vector3f up = IsoCamera.getInstance().getCam().getUp().clone();
    //        Vector3f dir = camPos.subtract(fontPos);
    ////        Vector3f dir = Vector3f.UNIT_Y.clone().subtract(fontPos);
    //
    //        Vector3f left = IsoCamera.getInstance().getCam().getLeft().clone();
    //        dir.normalizeLocal();
    //        left.negateLocal();
    //        left.normalizeLocal();
    //        up.normalizeLocal();
    ////        dir.negateLocal();
    //
    //        Quaternion look = new Quaternion();
    //        look.fromAxes(left, up, dir);
    //
    //        Vector3f newPos = to.getPlanet().getPosition().
    //                subtract(from.getPlanet().getPosition());
    //
    //        newPos.x -= label.getLineWidth() / 2;
    //
    //        Transform t = new Transform(newPos, look);
    //
    //        label.setLocalTransform(t);
  }
Пример #9
0
  @Override
  public void update(float tpf) {
    super.update(tpf);

    // If the mouse is being dragged, update the locations of any dragged
    // temporary geometries. To determine if the locations need to be
    // updated, the mouse button must be down AND the mouse must have moved
    // since the last update.
    if (!click.get() && newTemporaryPosition.getAndSet(false)) {
      // Add the temporary spatials node if the drag has just started.
      if (!showTemporarySpatials.getAndSet(true)) {
        appState.getRootNode().attachChild(tempSpatials);
      }
      // Get the cursor's current location on the grid.
      CollisionResults results = getCollision(grid, appState.getCursorRay());
      if (results.size() > 0) {
        // Determine the vector between the start point for the mouse
        // drag and the current location of the mouse drag.
        Vector3f dragLoc =
            appState.getClosestGridPoint(results.getClosestCollision().getContactPoint());
        dragLoc.subtractLocal(dragStart);

        // We need to modify the controllers for all the
        // currently-selected vertices. It's possible that
        // selectionChanged() is executing at the same time, so we need
        // to temporarily "lock" the selected vertex data structures.
        selectionLock.lock();
        try {
          // Add the vector to all temporary vertices.
          for (Entry<Integer, Vertex> e : selectedVertices.entrySet()) {
            float[] array = e.getValue().getLocation();
            Vector3f location = dragLoc.add(array[0], array[1], array[2]);
            vertexControllers.get(e.getKey()).setLocation(location);
          }
        } finally {
          selectionLock.unlock();
        }
      }
    }
    // If the dragging has stopped and we are still showing temporary
    // spatials in the scene, stop showing them.
    else if (!drag.get() && showTemporarySpatials.getAndSet(false)) {
      appState.getRootNode().detachChild(tempSpatials);
    }

    return;
  }
  private void drawTransportLine(Location start, Location end, double cost) {
    Vector3f lineStart = new Vector3f(start.getX(), 0.5f, start.getY());
    Vector3f lineEnd = new Vector3f(end.getX(), 0.5f, end.getY());
    Vector3f middle = lineStart.add(lineEnd).divide(2.0f);

    displayTransportCost(cost, middle);

    Line line = new Line(lineStart, lineEnd);
    line.setLineWidth(3.0f);

    Material lineMaterial =
        new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    lineMaterial.setColor("Color", ColorRGBA.Magenta);

    Geometry lineGeometry = new Geometry("line", line);
    lineGeometry.setMaterial(lineMaterial);

    lineNodes.attachChild(lineGeometry);
  }
Пример #11
0
  /**
   * Compute bounds from an array of points
   *
   * @param pts
   * @param mat
   * @return
   */
  public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrix4f mat) {
    Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY);
    Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY);
    Vector3f temp = new Vector3f();

    for (int i = 0; i < pts.length; i++) {
      float w = mat.multProj(pts[i], temp);

      temp.x /= w;
      temp.y /= w;
      // Why was this commented out?
      temp.z /= w;

      min.minLocal(temp);
      max.maxLocal(temp);
    }

    Vector3f center = min.add(max).multLocal(0.5f);
    Vector3f extent = max.subtract(min).multLocal(0.5f);
    // Nehon 08/18/2010 : Added an offset to the extend to avoid banding artifacts when the frustum
    // are aligned
    return new BoundingBox(center, extent.x + 2.0f, extent.y + 2.0f, extent.z + 2.5f);
  }
Пример #12
0
    public Hallway(Vector3f start, float xi, float zi) {
      float x = start.getX() + xi;
      float z = start.getZ() + zi;
      float rng, dist;
      int len = 0;
      int spread = 0;
      int lenMax = FastMath.nextRandomInt(HALL_LENGTH_MIN, HALL_LENGTH_MAX);
      boolean b = false;
      // Make sure both xi and zi have an absolute value of 1:
      xi = A.sign(xi);
      zi = A.sign(zi);
      // Assign the first 2 corners:
      corners[0] =
          new Vector3f(
              (zi * (HALL_WIDTH - 1)) + x,
              start.getY(),
              (xi * (HALL_WIDTH - 1)) + z); // Bottom Left
      corners[1] =
          new Vector3f(
              (-zi * (HALL_WIDTH - 1)) + x,
              start.getY(),
              (-xi * (HALL_WIDTH - 1)) + z); // Bottom Right
      Vector3f left = corners[0].clone();
      Vector3f right = corners[1].clone();
      ArrayList<HallData> newHalls = new ArrayList(1);
      while (len <= lenMax) {
        if (world.get(left) != null && world.get(left).contains("h")) {
          b = true;
        }
        if (world.get(right) != null && world.get(right).contains("h")) {
          b = true;
        }
        // Check each of the spaces in this step for hallway:
        if (b) {
          right.addLocal(-xi, 0, -zi);
          left.addLocal(-xi, 0, -zi);
          break;
        }
        world.put(left.clone(), "h");
        world.put(right.add(zi, 0, xi), "h");
        world.put(right.clone(), "h");
        // Check distance & random to see if more hallways should be created:
        dist = left.distance(Vector3f.ZERO);
        rng = FastMath.nextRandomFloat();
        if (dist < HALL_MAX_RADIUS && spread > HALL_SPREAD && len < lenMax) {
          if (rng < 0.13f) {
            newHalls.add(new HallData(left.clone(), zi, xi));
            spread = 0;
          } else if (rng < 0.26f) {
            newHalls.add(new HallData(right.clone(), -zi, -xi));
            spread = 0;
          } else if (rng < 0.33f) {
            newHalls.add(new HallData(left.clone(), zi, xi));
            newHalls.add(new HallData(right.clone(), -zi, -xi));
            spread = 0;
          }
        }
        x += xi;
        z += zi;
        spread++;
        len++;
        left.addLocal(xi, 0, zi);
        right.addLocal(xi, 0, zi);
      }
      corners[2] = right.clone(); // Top Right
      corners[3] = left.clone(); // Top Left

      // Generate hallways:
      int j = 0;
      while (j < newHalls.size()) {
        hallways.add(new Hallway(newHalls.get(j).start, newHalls.get(j).xi, newHalls.get(j).zi));
        j++;
      }

      // Return if there's no hallway to generate (0 in size):
      float xs = FastMath.abs(corners[1].getX() - corners[3].getX()) + 1;
      float zs = FastMath.abs(corners[1].getZ() - corners[3].getZ()) + 1;
      if (Math.min(FastMath.abs(xs), FastMath.abs(zs)) < 1) {
        return;
      }

      // Generate the front wall:
      walls.add(new Wall(left.add(xi, 0, zi), -zi, -xi, HALL_WIDTH * 2 - 1));
      walls.add(new Wall(left.add(zi, 0, xi), -xi, -zi, len + 1));
      walls.add(new Wall(right.add(-zi, 0, -xi), -xi, -zi, len + 1));

      // Generate the actual floor:
      float xloc = (corners[3].getX() + corners[1].getX()) * 0.5f;
      float zloc = (corners[3].getZ() + corners[1].getZ()) * 0.5f;
      NPCManager.addNew("grunt", new Vector3f(xloc, start.getY(), zloc).mult(ZS).add(0, 5, 0));
      center = new Vector3f(xloc, start.getY() - 0.5f, zloc);
      floor = geoFloor(center, xs, zs, T.getMaterialPath("BC_Tex"), new Vector2f(zs, xs), true);
      map.add(floor);
    }
  private double basicCSG(Vector3f point, Skeleton currentSkeleton) {
    double sum = 0;
    boolean isCSG = SceneManager.get().csgEnabled;

    for (int i = 0; i < currentSkeleton.branches.size(); i++) {
      SkeletonBranch branch = currentSkeleton.branches.get(i);
      for (int j = 0; j < branch.points.size() - 1; j++) {
        SkeletonPoint SP1 = branch.points.get(j);
        SkeletonPoint SP2 = branch.points.get(j + 1);
        //            TriangulationPoint P1 = SP1.point;
        //            TriangulationPoint P2 = SP2.point;
        //            Vector3f p = new Vector3f(P1.getXf(), P1.getYf(), P1.getZf());
        //            Vector3f q = new Vector3f(P2.getXf(), P2.getYf(), P2.getZf());
        Vector3f p = SP1.point;
        Vector3f q = SP2.point;

        // calculate radius of influence
        float Rp = (float) SP1.radius;
        float Rq = (float) SP2.radius;

        // calculate surface points Sp and Sq
        Vector3f PQ = q.subtract(p);
        Vector3f normalVector = new Vector3f(-PQ.getY(), PQ.getX(), PQ.getZ()).normalize();
        Vector3f Sp = p.add(normalVector.mult(Rp));
        Vector3f Sq = q.add(normalVector.mult(Rq));
        Vector3f Smid = Sp.add(Sq).divide(2f);

        // System.out.println("L: " + PQ.length() + " Sp: " + Sp + " Sq: " +
        // Sq + " Smid: " + Smid);

        // calculate weights
        double w0 = T / flt(Sp, p, q);
        double w1 = T / ft(Sq, p, q);

        // division factor
        w0 /= (double) SP1.divisionFactor;
        w1 /= (double) SP2.divisionFactor;

        double k = T / (w0 * flt(Smid, p, q) + w1 * ft(Smid, p, q));

        // scale factor
        w0 *= k;
        w1 *= k;

        // System.out.println("j " + j);
        // System.out.println("w0 " + w0 + " w1 " + w1);

        // CSG blending
        if (isCSG) {
          double fx = cauchy(point, p, q, w0, w1);
          double R = cauchy(Smid, p, q, w0, w1);
          double blending = blending(-fx + T, R);
          sum += blending;
        } else {
          // common sum
          sum += cauchy(point, p, q, w0, w1);
        }
      }
    }

    // if(sum > 1)
    // blendingGTone++;
    // else if(sum < 1)
    // blendingLTone++;

    // sum /= n;

    // Vector3f A = new Vector3f(-5f, 0.0f, 0.0f);
    // Vector3f B = new Vector3f(5f, 0.0f, 0.0f);
    // Vector3f C = new Vector3f(-5f, 4.0f, 0.0f);
    // Vector3f D = new Vector3f(5f, 4.0f, 0.0f);
    //
    // // define threshold based on a pre determined surface point
    // float radius = 5.0f;
    // Vector3f AB = B.subtract(A);
    // Vector3f normalVectorAB = new Vector3f(-AB.getY(), AB.getX(),
    // AB.getZ()).normalize().mult(radius);
    // Vector3f midPointAB = (A.add(B)).divide(2f);
    // Vector3f surfacePointAB = midPointAB.add(normalVectorAB);
    //
    // T = 1.0;
    //
    // sum += blending(-cauchy(point, A, B) + T, cauchy(surfacePointAB, A,
    // B));
    // sum += blending(-cauchy(point, C, D) + T, cauchy(surfacePointAB, C,
    // D));

    // sum = cauchy(point, A, B) + cauchy(point, C, D);

    //      if(!single) //i.e. is multiple
    //      {
    //          // common sum
    ////          double result = -sum + T;
    ////          if (result > 0)
    ////             positive++;
    ////          else if (result < 0)
    ////             negative++;
    ////          return result;
    //          return sum;
    //      }
    //      else
    //      {
    if (!isCSG) return T - sum;
    else
      // CSG composition
      return 1 - sum;
    //      }
  }
Пример #14
0
 public void update(float tpf) {
   if (alive) {
     position = position.add(velocity);
     bullet.setLocalTranslation(position);
   }
 }