public void showCar() {
    for (int i = 0; i < 4; i++) {
      cars[i] = factory.getCar(car_names[i], assetManager);
      car_con[i] = cars[i].getControl(VehicleControl.class);
    }
    Camera camera = cam.clone();

    camera.setViewPort(.25f, .9f, .1f, .75f);
    carView = this.app.getRenderManager().createPostView("carview", camera);

    space.add(car_con[index]);
    dl = new DirectionalLight();
    localRootNode.addLight(dl);
    ai = new AmbientLight();
    localRootNode.addLight(ai);
    car_con[index].setPhysicsLocation(new Vector3f(0, 1, 0));
    localRootNode.attachChild(cars[index]);
    floor = assetManager.loadModel("Models/garage/garage.mesh.j3o");
    control = new RigidBodyControl(0);
    floor.addControl(control);
    control.setPhysicsLocation(Vector3f.ZERO);
    space.add(control);
    localRootNode.attachChild(floor);

    camera.setLocation(car_con[index].getPhysicsLocation().add(new Vector3f(3, 1f, 0)));
    camera.lookAt(car_con[index].getPhysicsLocation().add(new Vector3f(0, -1, 0)), Vector3f.UNIT_Y);
    dl.setDirection(camera.getDirection());

    carView.attachScene(localRootNode);
  }
Beispiel #2
0
  @Override
  public void simpleUpdate(float tpf) {
    Juggernaut.Update(tpf);
    // Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
    //        walkDirection.set( 0, 0, 0);
    //        if(left)    { walkDirection.addLocal(Vector3f.UNIT_X.negate().multLocal(0.4f));}
    //        if(right)   { walkDirection.addLocal(Vector3f.UNIT_X.clone().multLocal(0.4f));}
    //        player.setWalkDirection(walkDirection);
    //        if( walkDirection != Vector3f.ZERO){
    //            player.setViewDirection(walkDirection.negate());
    //        }
    //
    //        playerDebug.setLocalTranslation(player.getPhysicsLocation());
    elevator1.setLocalTranslation(304 + 20 * FastMath.cos(timer.getTimeInSeconds()), 20, 0);
    elvtr1.setPhysicsLocation(elevator1.getLocalTranslation());

    //        elevator2.setLocalTranslation( 192, 208 + 35*FastMath.cos(timer.getTimeInSeconds()),
    // 0);
    //        elvtr2.setPhysicsLocation(elevator2.getLocalTranslation());
    elvtr2.setLinearVelocity(new Vector3f(0, 25 * FastMath.cos(timer.getTimeInSeconds()), 0));
    elvtr2.setPhysicsRotation(Matrix3f.IDENTITY);
    System.out.print(landscape.getCollideWithGroups() + "\n");

    for (int i = 0; i < views.length; i++) {
      if (views[i].testForPlayer(Juggernaut)) {
        currentView = views[i];
      }
    }

    cam.setLocation(currentView.CamPosition());
    cam.lookAt(currentView.CamLookAt(), Vector3f.UNIT_Y);
  }
Beispiel #3
0
  public void loadLevel() {

    // create ground
    Vector3f pos = new Vector3f(0f, -1.5f, 0f);
    float size = 10f;
    Geometry ground = new Geometry("ground", new Box(Vector3f.ZERO, size, 1.0f, size));

    // create node
    Node groundNode = new Node();
    groundNode.attachChild(ground);

    // setup physics
    RigidBodyControl grbc = new RigidBodyControl(0f);
    ground.addControl(grbc);
    getPhysicsSpace().add(grbc);
    grbc.setPhysicsLocation(pos);

    // create boxes
    Vector3f[] positions =
        new Vector3f[] {
          new Vector3f(2f, 0f, 2f),
          new Vector3f(2f, 0f, -2f),
          new Vector3f(-2f, 0f, -2f),
          new Vector3f(-2f, 0f, 2f)
        };
    for (int i = 0; i < 4; i++) {
      Box box = new Box(1f, 1f, 1f);
      Geometry geometry = new Geometry("geometry", box);
      Node node = new Node("box");
      node.attachChild(geometry);

      RigidBodyControl rbc = new RigidBodyControl(0f);
      geometry.addControl(rbc);
      getPhysicsSpace().add(rbc);

      rbc.setPhysicsLocation(positions[i]);
    }
  }
  public void setPosition(String objectID, Vector3f position) {
    // get "visual" or "physical" spatial
    // search in all sub-nodes of root node (scene node, trigger node, ...)
    Spatial object = Util.findNode(sim.getRootNode(), objectID);
    RigidBodyControl control = null;

    try {
      control = (RigidBodyControl) object.getControl(0);
    } catch (IndexOutOfBoundsException e2) {
      System.err.println("Could not manipulate physics of '" + objectID + "'!");
    }

    if (control != null) control.setPhysicsLocation(position);
    else object.setLocalTranslation(position);
  }
 @Override
 protected void controlUpdate(float tpf) {
   RigidBodyControl diceControl = spatial.getControl(RigidBodyControl.class);
   if (number != 0) {
     diceControl.setEnabled(true);
     int numberValue = 0;
     synchronized (spatial) {
       numberValue = number;
     }
     switch (numberValue) {
       case 1:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(FastMath.HALF_PI, new Vector3f(1, 0, 0)));
         break;
       case 2:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(-FastMath.HALF_PI, new Vector3f(0, 1, 0)));
         break;
       case 3:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(FastMath.ZERO_TOLERANCE, new Vector3f(1, 0, 0)));
         break;
       case 4:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(FastMath.PI, new Vector3f(1, 0, 0)));
         break;
       case 5:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(FastMath.HALF_PI, new Vector3f(0, 1, 0)));
         break;
       case 6:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(-FastMath.HALF_PI, new Vector3f(1, 0, 0)));
         break;
     }
     diceControl.setLinearVelocity(new Vector3f(0, 0, 0));
     diceControl.setAngularVelocity(new Vector3f(0, 0, 0));
     diceControl.setPhysicsLocation(putLocation);
     spatial.getControl(AbstractRollControl.class).setEnabled(false);
     Geometry d6 = ((Geometry) spatial);
     d6.getMaterial().setColor("Diffuse", ColorRGBA.White);
     number = 0;
   } else {
     diceControl.setEnabled(false);
     this.setEnabled(false);
   }
 }