@Override
 public void initialize(AppStateManager stateManager, Application app) {
   super.initialize(stateManager, app);
   this.assetManager = app.getAssetManager();
   this.audioRenderer = app.getAudioRenderer();
   this.worldManager = app.getStateManager().getState(WorldManager.class);
 }
  public static void createCanvas(String appClass) {
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);

    try {
      Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass);
      app = clazz.newInstance();
    } catch (ClassNotFoundException ex) {
      ex.printStackTrace();
    } catch (InstantiationException ex) {
      ex.printStackTrace();
    } catch (IllegalAccessException ex) {
      ex.printStackTrace();
    }

    app.setPauseOnLostFocus(false);
    app.setSettings(settings);
    app.createCanvas();
    app.startCanvas();

    context = (JmeCanvasContext) app.getContext();
    canvas = context.getCanvas();
    canvas.setSize(settings.getWidth(), settings.getHeight());
  }
  @Override
  public void update(float tpf) {

    if (forward ^ backward) {
      //            float yCoord = charControl.getRigidBody().getLinearVelocity().getY();
      Vector3f charLocation = charControl.getPhysicsLocation();
      Vector3f walkDir =
          charLocation
              .subtract(app.getCamera().getLocation().clone().setY(charLocation.getY()))
              .normalizeLocal();
      if (backward) {
        walkDir.negateLocal();
      }

      charControl.setWalkDirection(walkDir);
      charControl.setMove(true);
    } else {
      charControl.setMove(false);
    }

    if (jump) {
      charControl.setJump();
      jump = false;
    }
    Vector3f camdir = app.getCamera().getDirection().clone();
    Quaternion newRot = new Quaternion();
    newRot.lookAt(camdir.setY(0), Vector3f.UNIT_Y);
    charControl.setRotationInUpdate(newRot);
  }
 public static void startApp() {
   app.startCanvas();
   app.enqueue(
       new Callable<Void>() {
         public Void call() {
           if (app instanceof SimpleApplication) {
             SimpleApplication simpleApp = (SimpleApplication) app;
             simpleApp.getFlyByCamera().setDragToRotate(true);
           }
           return null;
         }
       });
 }
Ejemplo n.º 5
0
 public void updateSize() {
   float width = app.getCamera().getWidth();
   float height = app.getCamera().getHeight();
   float w, h;
   if (width < height * 1.75f) {
     h = height;
     w = (imageWidth * h) / imageHeight;
   } else {
     w = width;
     h = (w * imageHeight) / imageWidth;
   }
   splash.setWidth(w);
   splash.setHeight(h);
   splash.setLocalTranslation((width / 2) - (w / 2), (height / 2) - (h / 2), 0);
 }
Ejemplo n.º 6
0
  @Override
  public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    app.getRenderer().applyRenderState(RenderState.DEFAULT);

    initNifty();
  }
Ejemplo n.º 7
0
 @Override
 public Optional<Level> loadLevelById(final String levelId, final Application app) {
   Level level = new Level(this.terrainGenerator, app.getAssetManager());
   level.setSize(32);
   level.setTileSize(65);
   level.setName("testterrain");
   level.setPath("Levels/testterrain");
   return Optional.of(level);
 }
Ejemplo n.º 8
0
  @Override
  protected void initialize(Application app) {

    ed = getState(EntityDataState.class).getEntityData();
    entities = ed.getEntities(Position.class, ModelType.class);

    // Calculate how big min/max needs to be to incorporate
    // the full view + margin at z = 0
    Camera cam = app.getCamera();
    float z = cam.getViewToProjectionZ(cam.getLocation().z);
    Vector3f worldMin = cam.getWorldCoordinates(new Vector2f(0, 0), z);
    Vector3f worldMax = cam.getWorldCoordinates(new Vector2f(cam.getWidth(), cam.getHeight()), z);
    min = worldMin.addLocal(-margin, -margin, 0);
    max = worldMax.addLocal(margin, margin, 0);
  }
Ejemplo n.º 9
0
  @Override
  public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    this.app = app;
    if (guiNode == null && app instanceof SimpleApplication) {
      guiNode = ((SimpleApplication) app).getGuiNode();
    }
    if (guiNode == null) {
      throw new NullPointerException("missing required variables");
    }
    if (!imageLoaded) {
      loadImage(app.getAssetManager());
    }

    guiNode.attachChild(splash);
    updateSize();
  }
Ejemplo n.º 10
0
  @Override
  public void initialize(AppStateManager stateManager, Application application) {
    System.out.println("Inititalize " + getClass().getSimpleName());
    super.initialize(stateManager, application);
    this.app = (SimpleApplication) application;
    this.assetManager = application.getAssetManager();

    worldAppState = app.getStateManager().getState(WorldAppState.class);
    houseAppState = app.getStateManager().getState(HouseAppState.class);
    bulletAppState = app.getStateManager().getState(BulletAppState.class);

    SmartPhoneFactory.init(
        bulletAppState,
        assetManager,
        app.getRenderManager(),
        app.getCamera(),
        app.getAudioRenderer());
  }
Ejemplo n.º 11
0
  @SuppressWarnings("unchecked")
  @Override
  public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);

    bulletAppState = new BulletAppState();
    app.getStateManager().attach(bulletAppState);

    StaticWorldHelper.addStaticWorld(
        App.rally.getRootNode(), getPhysicsSpace(), world, App.rally.sky.ifShadow);

    cb = new CarBuilder();
    cb.addCar(getPhysicsSpace(), 0, car, world.start, Matrix3f.IDENTITY, false);

    camNode = new MyCamera("Cam Node 2", App.rally.getCamera(), null);
    camNode.setLocalTranslation(0, 3, 7);
    camNode.lookAt(new Vector3f(0, 1.2f, 0), new Vector3f(0, 1, 0));

    Container myWindow = new Container();
    App.rally.getGuiNode().attachChild(myWindow);
    myWindow.setLocalTranslation(300, 300, 0);

    // Add some elements to it
    myWindow.addChild(new Label("Main Menu"));
    Button startFast = myWindow.addChild(new Button("Start Fast"));
    startFast.addClickCommands(
        new Command<Button>() {
          @Override
          public void execute(Button source) {
            startFast();
            App.rally.getGuiNode().detachChild(myWindow);
          }
        });
    Button start = myWindow.addChild(new Button("Start"));
    start.addClickCommands(
        new Command<Button>() {
          @Override
          public void execute(Button source) {
            startBasic();
            App.rally.getGuiNode().detachChild(myWindow);
          }
        });
  }
  private void setupKeys() {
    InputManager inputManager = app.getInputManager();

    inputManager.addMapping(
        "Rotate Left", new KeyTrigger(KeyInput.KEY_A), new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping(
        "Rotate Right", new KeyTrigger(KeyInput.KEY_D), new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping(
        "Walk Forward", new KeyTrigger(KeyInput.KEY_W), new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping(
        "Walk Backward", new KeyTrigger(KeyInput.KEY_S), new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));

    //        inputManager.addListener(this, "Strafe Left", "Strafe Right");
    inputManager.addListener(this, "Rotate Left", "Rotate Right");
    inputManager.addListener(this, "Walk Forward", "Walk Backward");
    inputManager.addListener(this, "Jump");

    inputManager = null;
  }
  @Override
  public void runCommand(Application app) {
    DevicesAppState devicesAppState = app.getStateManager().getState(DevicesAppState.class);

    Spatial device = SpatialUtils.getSpatialById(((SimpleApplication) app).getRootNode(), sensorID);
    Node sensor;
    System.out.println("DEVICE ===== " + device);
    if (device != null && device instanceof Node) {
      sensor = (Node) device;
    } else {
      sensor = SmartPhoneFactory.createAccelGeometry(sensorID, dimensions);
    }
    sensor.setName(sensorID);

    SmartPhoneFactory.enableAccelerometerFacility(sensor);

    if (attachCoordinateAxes) {
      Debug.attachCoordinateAxes(Vector3f.ZERO, 0.5f, SmartPhoneFactory.assetManager, sensor);
    }
    devicesAppState.addDevice(sensorID, sensor);
    setState(State.Success);
  }
Ejemplo n.º 14
0
 @Override
 protected void initialize(Application app) {
   this.camera = app.getCamera();
   this.listener = app.getListener();
 }
 public void removeListener() {
   app.getInputManager().removeListener(this);
 }
 public void addListener() {
   app.getInputManager().addListener(this, mappings);
 }