public double f1(Vector3f point, Vector3f A, Vector3f B) {
    // ****** basic parameters ******
    Vector3f vec_b = B;
    Vector3f vec_a = A.subtract(vec_b);
    Vector3f vec_r = point;
    double L = vec_a.length();
    Vector3f vec_d = vec_r.subtract(vec_b);
    double d = vec_d.length();
    double h = vec_d.dot(vec_a.normalize());

    // terms
    double s2 = s * s;
    double h2 = h * h;
    double lmh = L - h;
    double d2 = d * d;
    double p2 = 1 + s2 * (d2 - h2);
    double p = Math.sqrt(p2);
    double ww = p2 + s2 * h2;
    double qq = p2 + s2 * lmh * lmh;
    double sdp = s / p;
    double tpp = 2.0 * p2;
    double sp = s * p;
    double term = Math.atan(sdp * h) + Math.atan(sdp * lmh);

    return (h / ww + lmh / qq) / tpp + term / (tpp * sp);
  }
Ejemplo n.º 2
0
  public void setDirection(Vector3f dir) {
    // Ensure that direction is normalized
    this.direction = dir.normalize();

    // restrict direction to x-y axis
    this.direction.z = 0.0f;
    this.direction = this.direction.normalize();
  }
Ejemplo n.º 3
0
  public Vector3f calculateForce(
      Vector3f location,
      Vector3f velocity,
      float collisionRadius,
      float speed,
      float turnSpeed,
      float tpf,
      List<Obstacle> obstacles) {
    float cautionRange = speed * 1.5f / turnSpeed;
    Line line = new Line(location, velocity.normalize());
    Plane plane = new Plane(velocity, 1);
    Vector3f closest = Vector3f.ZERO;
    float shortestDistance = -1;

    for (Obstacle obs : obstacles) {

      Vector3f target = obs.getLocation();

      Vector3f loc = target.subtract(location);

      // If the obstacle isn't ahead of him, just ignore it
      if (plane.whichSide(loc) != Side.Positive) {
        continue;
      }

      // Check if the target is inside the check range
      if (location.distance(target) <= collisionRadius + cautionRange + obs.getRadius()) {

        // Check if the target will collide with the source
        if (obs.distance(line) < collisionRadius) {

          float newDistance = obs.distance(location);
          // Store the closest target
          if (shortestDistance == -1 || newDistance < shortestDistance)
            shortestDistance = newDistance;
          closest = target;
        }
      }
    }

    // If any target was found
    if (shortestDistance != -1) {

      // Find in wich side the target is
      // To do that, we do a signed distance by
      // subtracing the location from the target
      // and the dot product between the line's normal
      float dot = closest.subtract(location).dot(line.getDirection().cross(Vector3f.UNIT_Y));

      if (dot <= 0) return velocity.cross(Vector3f.UNIT_Y);
      else return velocity.cross(Vector3f.UNIT_Y).negate();
    }

    // No target found, just return a zero value
    return Vector3f.ZERO;
  }
  /**
   * 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;
  }
  void lookAt(Vector3f pos) {
    Vector3f location = spatial.getLocalTranslation();
    Vector3f target = pos.clone();

    Vector3f distance = target.subtract(location);
    if (distance.length() < 0.3f) {
      return;
    }
    Vector3f newVel = distance.normalize();
    Quaternion q = new Quaternion();
    q.lookAt(newVel, Vector3f.UNIT_Y);
    // q.addLocal(playerInfo.initalRot);
    spatial.setLocalRotation(q);
  }
  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));
  }
Ejemplo n.º 7
0
  private void applyGravity(Spatial blackHole, Spatial target, float tpf) {
    Vector3f difference = blackHole.getLocalTranslation().subtract(target.getLocalTranslation());

    Vector3f gravity = difference.normalize().multLocal(tpf);
    float distance = difference.length();

    if (target.getName().equals("Player")) {
      gravity.multLocal(250f / distance);
      target.getControl(PlayerControl.class).applyGravity(gravity.mult(80f));
    } else if (target.getName().equals("Bullet")) {
      gravity.multLocal(250f / distance);
      target.getControl(BulletControl.class).applyGravity(gravity.mult(-0.8f));
    } else if (target.getName().equals("Seeker")) {
      target.getControl(SeekerControl.class).applyGravity(gravity.mult(150000));
    } else if (target.getName().equals("Wanderer")) {
      target.getControl(WandererControl.class).applyGravity(gravity.mult(150000));
    } else if (target.getName().equals("Laser") || target.getName().equals("Glow")) {
      target.getControl(ParticleControl.class).applyGravity(gravity.mult(15000), distance);
    }
  }
  public double ft(Vector3f point, Vector3f A, Vector3f B) {
    // ****** basic parameters ******
    Vector3f vec_b = B;
    Vector3f vec_a = A.subtract(vec_b);
    Vector3f vec_r = point;
    double L = vec_a.length();
    Vector3f vec_d = vec_r.subtract(vec_b);
    double d = vec_d.length();
    double h = vec_d.dot(vec_a.normalize());

    // terms
    double s2 = s * s;
    double h2 = h * h;
    double lmh = L - h;
    double d2 = d * d;
    double p2 = 1 + s2 * (d2 - h2);
    double ww = p2 + s2 * h2;
    double qq = p2 + s2 * lmh * lmh;

    double ts2 = 2.0 * s2;
    return h * f1(point, A, B) + (1.0 / ww - 1.0 / qq) / ts2;
  }
Ejemplo n.º 9
0
 @Override
 public void simpleUpdate(float lastTimePerFrame) {
   float playerMoveSpeed = ((cubesSettings.getBlockSize() * 6.5f) * lastTimePerFrame);
   Vector3f camDir = cam.getDirection().mult(playerMoveSpeed);
   Vector3f camLeft = cam.getLeft().mult(playerMoveSpeed);
   walkDirection.set(0, 0, 0);
   if (arrowKeys[0]) {
     walkDirection.addLocal(camDir);
   }
   if (arrowKeys[1]) {
     walkDirection.addLocal(camLeft.negate());
   }
   if (arrowKeys[2]) {
     walkDirection.addLocal(camDir.negate());
   }
   if (arrowKeys[3]) {
     walkDirection.addLocal(camLeft);
   }
   walkDirection.setY(0);
   walkDirection.normalize();
   walkDirection.multLocal(lastTimePerFrame * 10);
   playerControl.setWalkDirection(walkDirection);
   cam.setLocation(playerControl.getPhysicsLocation());
 }
Ejemplo n.º 10
0
  @Override
  public void simpleUpdate(float tpf) {
    for (Planet planet : planets) {
      planet.getGeom().rotate(0, 0, planet.getRotationSpeed() * tpf);
      planet.getPivot().rotate(0, planet.getTranslationSpeed() * tpf, 0);
    }

    for (Spatial spatial : explosions.getChildren()) {
      ParticleEmitter explosion = (ParticleEmitter) spatial;
      if (explosion.getNumVisibleParticles() < 1) {
        explosion.removeFromParent();
      }
    }

    Vector3f rotation = new Vector3f(0, 0, 0);
    if (left) {
      rotation.addLocal(0, 1, 0);
    }
    if (right) {
      rotation.addLocal(0, -1, 0);
    }
    if (up) {
      rotation.addLocal(1, 0, 0);
    }
    if (down) {
      rotation.addLocal(-1, 0, 0);
    }
    if (leftSide) {
      rotation.addLocal(0, 0, 1);
    }
    if (rightSide) {
      rotation.addLocal(0, 0, -1);
    }

    Vector3f transformed = new Vector3f(0, 0, 0);
    spaceship.getLocalRotation().mult(rotation, transformed);
    spaceship.getControl().setAngularVelocity(transformed);

    Vector3f movement = new Vector3f(0, 0, 0);
    if (moving) {
      spaceship.getWorldRotation().mult(new Vector3f(0, 0, -6), movement);
    }
    spaceship.getControl().setLinearVelocity(movement);

    bloom.setBloomIntensity(bloom.getBloomIntensity() + (bloomDirection * tpf / 8));
    if (bloom.getBloomIntensity() > 4) {
      bloomDirection = -1;
    }
    if (bloom.getBloomIntensity() < 2) {
      bloomDirection = 1;
    }

    Vector3f direction = spaceship.getRear().getWorldTranslation().subtract(cam.getLocation());
    float magnitude = direction.length();
    if (magnitude > 0) {
      cam.setLocation(
          cam.getLocation().add(direction.normalize().mult(tpf * magnitude * magnitude / 2)));
    }
    cam.lookAt(spaceship.getFront().getWorldTranslation(), Vector3f.UNIT_Y);

    for (Spatial spatial : asteroids.getChildren()) {
      if (spatial.getWorldTranslation().subtract(Vector3f.ZERO).length() > 200) {
        spatial.removeFromParent();
      }
    }

    if (Math.random() < 0.01 && asteroids.getChildren().size() < MAX_ASTEROIDS) {
      generateRandomAsteroid();
    }

    for (Spatial spatial : lasers.getChildren()) {
      Laser laser = (Laser) spatial;
      if (laser.getWorldTranslation().subtract(Vector3f.ZERO).length() > 200) {
        bap.getPhysicsSpace().remove(laser.getControl());
        laser.removeFromParent();
        continue;
      }
      laser.move(laser.getDirection().mult(laser.getSpeed()));
    }

    scoreText.setText("Score: " + score);
  }