public void update(float tpf) {
    if (isSnowing) {
      snowParticleEmitter.setLocalTranslation(sim.getCar().getPosition());

      if (snowingPercentageHasChanged) {
        snowParticleEmitter.setPercentage(snowingPercentage);
        System.out.println("snowing intensity: " + snowingPercentage);
        snowingPercentageHasChanged = false;
      }
    }

    if (isRaining) {
      rainParticleEmitter.setLocalTranslation(sim.getCar().getPosition());

      if (rainingPercentageHasChanged) {
        rainParticleEmitter.setPercentage(rainingPercentage);
        System.out.println("raining intensity: " + rainingPercentage);
        rainingPercentageHasChanged = false;
      }
    }

    if (isFog) {
      if (fogPercentageHasChanged) {
        for (FogFilter fogFilter : fogFilterList)
          fogFilter.setFogDensity(2.0f * (fogPercentage / 100f));
        System.out.println("fog intensity: " + fogPercentage);
        fogPercentageHasChanged = false;
      }
    }
  }
  public static void action(boolean value) {
    float accelerationValue = SimulatorActionListener.getAccelerationValue();
    Simulator sim = SimulatorActionListener.getSimulator();
    SteeringCar car = SimulatorActionListener.getCar();
    if (value) {
      sim.getSteeringTask().getPrimaryTask().reportRedLight();
      accelerationValue += 1;
      // sim.getPhysicalTraffic().getTrafficCar("car2").setBrakeLight(true);
    } else {
      accelerationValue -= 1;
    }

    SimulatorActionListener.setAccelerationValue(accelerationValue);
    car.setAcceleratorPedalIntensity(accelerationValue);
  }
示例#3
0
  private Spatial createFollowBox() {
    // add spatial representing the position the driving car is steering towards
    Box box = new Box(new Vector3f(0, 0, 0), 1f, 1f, 1f);
    Geometry followBox = new Geometry("followBox", box);
    followBox.setLocalTranslation(0, 0, 0);
    Material followBoxMaterial =
        new Material(sim.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    followBoxMaterial.setColor("Color", ColorRGBA.Green);
    followBox.setMaterial(followBoxMaterial);
    followBox.setLocalScale(0.4f);
    sim.getSceneNode().attachChild(followBox);

    if (!settings.isPathVisible()) followBox.setCullHint(CullHint.Always);

    return followBox;
  }
示例#4
0
  public void update(Vector3f vehiclePos) {
    if (setWayPoint) {
      // first iteration --> set control to play in order to make
      // position change have effect
      if (frameCounter <= 0) {
        motionControl.play();
        frameCounter++;
      }

      // second iteration --> set position of follow box
      else if (frameCounter == 1) {
        // set follow box to way point
        motionControl.setCurrentWayPoint(setToWayPointIndex);

        // place follow box at beginning of line currentWP-nextWP
        motionControl.setCurrentValue(0);

        frameCounter++;
      }

      // third iteration --> reset counter & exit branch
      else if (frameCounter >= 2) {
        frameCounter = 0;
        setWayPoint = false;
      }
    } else {
      // pause movement of follower box if vehicle's distance
      // has exceeded maximum
      if (maxDistanceExceeded(vehiclePos) || sim.isPause()) motionControl.pause();
      else motionControl.play();
    }
  }
  @Override
  protected void execute() {
    if (!isExceeded()) {
      sim.getReactionCenter()
          .setupKeyReactionTimer(timerID, reactionGroup, correctReaction, failureReaction, comment);

      updateCounter();
    }
  }
  public EffectCenter(Simulator sim) {
    this.sim = sim;
    AssetManager assetManager = sim.getAssetManager();

    WeatherSettings weatherSettings =
        Simulator.getDrivingTask().getScenarioLoader().getWeatherSettings();
    snowingPercentage =
        Math.max(
            weatherSettings.getSnowingPercentage(),
            -1); // use -1 to suppress construction of SnowParticleEmitter
    rainingPercentage =
        Math.max(
            weatherSettings.getRainingPercentage(),
            -1); // use -1 to suppress construction of RainParticleEmitter
    fogPercentage =
        Math.max(
            weatherSettings.getFogPercentage(), -1); // use -1 to suppress construction of FogFilter
    isSnowing = (snowingPercentage >= 0);
    isRaining = (rainingPercentage >= 0);
    isFog = (fogPercentage >= 0);
    isBloom = !Simulator.oculusRiftAttached; // switch off bloom filter when Oculus Rift is used
    isShadow = true;

    if (isSnowing) {
      // init snow
      snowParticleEmitter = new SnowParticleEmitter(assetManager, snowingPercentage);
      sim.getSceneNode().attachChild(snowParticleEmitter);
    }

    if (isRaining) {
      // init rain
      rainParticleEmitter = new RainParticleEmitter(assetManager, rainingPercentage);
      sim.getSceneNode().attachChild(rainParticleEmitter);
    }

    if (isFog || isBloom) {
      for (ViewPort viewPort : CameraFactory.getViewPortList()) {
        FilterPostProcessor processor = new FilterPostProcessor(assetManager);

        int numSamples = sim.getContext().getSettings().getSamples();
        if (numSamples > 0) processor.setNumSamples(numSamples);

        if (isFog) {
          FogFilter fogFilter = new FogFilter();
          fogFilter.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
          fogFilter.setFogDistance(155);
          fogFilter.setFogDensity(2.0f * (fogPercentage / 100f));
          fogFilterList.add(fogFilter);
          processor.addFilter(fogFilter);
        }

        if (isBloom) {
          // ensure any object is set to glow, e.g. car chassis:
          // chassis.getMaterial().setColor("GlowColor", ColorRGBA.Orange);

          BloomFilter bloom = new BloomFilter(GlowMode.Objects);
          processor.addFilter(bloom);
        }

        viewPort.addProcessor(processor);
      }
    }

    if (isShadow) { // TODO
      DirectionalLight sun = new DirectionalLight();
      Vector3f sunLightDirection = new Vector3f(-0.2f, -0.9f, 0.2f); // TODO get from DT files
      sun.setDirection(sunLightDirection.normalizeLocal());

      ArrayList<ViewPort> viewPortList = CameraFactory.getViewPortList();

      if (sim.getNumberOfScreens() > 1) {
        int shadowMapSize = 4096;
        if (viewPortList.size() > 1) shadowMapSize = 1024;

        for (ViewPort viewPort : viewPortList) {
          DirectionalLightShadowRenderer dlsr =
              new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
          dlsr.setLight(sun);
          dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
          viewPort.addProcessor(dlsr);
        }

        shadowMapSize = 1024;
        DirectionalLightShadowRenderer dlsrBack =
            new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
        dlsrBack.setLight(sun);
        CameraFactory.getBackViewPort().addProcessor(dlsrBack);

        DirectionalLightShadowRenderer dlsrLeft =
            new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
        dlsrLeft.setLight(sun);
        CameraFactory.getLeftBackViewPort().addProcessor(dlsrLeft);

        DirectionalLightShadowRenderer dlsrRight =
            new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
        dlsrRight.setLight(sun);
        CameraFactory.getRightBackViewPort().addProcessor(dlsrRight);
      } else {
        // does not work with more than one screen
        for (ViewPort viewPort : viewPortList) {
          DirectionalLightShadowFilter dlsf =
              new DirectionalLightShadowFilter(assetManager, 1024, 3);
          dlsf.setLight(sun);
          dlsf.setLambda(1f);
          dlsf.setShadowIntensity(0.3f);
          dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
          dlsf.setEnabled(true);

          FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
          fpp.addFilter(dlsf);

          viewPort.addProcessor(fpp);
        }
      }
    }
  }
示例#7
0
  public FollowBox(Simulator sim, final TrafficCar vehicle, FollowBoxSettings settings) {
    this.sim = sim;
    this.vehicle = vehicle;
    this.settings = settings;

    waypointList = settings.getWayPoints();
    maxDistance = settings.getMaxDistance();

    motionPath = new MotionPath();

    motionPath.setCycle(settings.isPathCyclic());

    for (Waypoint wayPoint : waypointList) motionPath.addWayPoint(wayPoint.getPosition());

    motionPath.setPathSplineType(SplineType.CatmullRom); // --> default: CatmullRom
    motionPath.setCurveTension(settings.getCurveTension());

    if (settings.isPathVisible())
      motionPath.enableDebugShape(sim.getAssetManager(), sim.getSceneNode());

    motionPath.addListener(
        new MotionPathListener() {
          public void onWayPointReach(MotionTrack control, int wayPointIndex) {
            // set speed limit for next way point
            int index = wayPointIndex % waypointList.size();
            float speed = waypointList.get(index).getSpeed();
            setSpeed(speed);

            // if last way point reached
            if (motionPath.getNbWayPoints() == wayPointIndex + 1) {
              // reset vehicle to first way point if not cyclic
              if (!motionPath.isCycle()) setToWayPoint(0);
            }
          }
        });

    followBox = createFollowBox();
    motionControl = new MotionTrack(followBox, motionPath);

    // get start way point
    int startWayPointIndex = settings.getStartWayPointIndex();

    // set start speed
    float initialSpeed = waypointList.get(startWayPointIndex).getSpeed();
    setSpeed(initialSpeed);

    // set start position
    setToWayPoint(startWayPointIndex);

    // move object along path considering rotation
    motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);

    // loop movement of object
    motionControl.setLoopMode(LoopMode.Loop);

    // rotate moving object
    // motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI,
    // Vector3f.UNIT_Y));

    // set moving object to position "20 seconds"
    // motionPath.interpolatePath(20, motionControl);

    // start movement
    // motionControl.play(); // already contained in update method
  }