コード例 #1
0
  @Override
  public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    createMaterial();

    Node node = new Node("node1");
    attachRandomGeometry(node, mat1);
    randomizeTransform(node);

    Node node2 = new Node("node2");
    attachRandomGeometry(node2, mat2);
    randomizeTransform(node2);

    node.attachChild(node2);
    rootNode.attachChild(node);

    RigidBodyControl control = new RigidBodyControl(0);
    node.addControl(control);
    getPhysicsSpace().add(control);

    // test single geometry too
    Geometry myGeom = new Geometry("cylinder", new Cylinder(16, 16, 0.5f, 1));
    myGeom.setMaterial(mat3);
    randomizeTransform(myGeom);
    rootNode.attachChild(myGeom);
    RigidBodyControl control3 = new RigidBodyControl(0);
    myGeom.addControl(control3);
    getPhysicsSpace().add(control3);
  }
コード例 #2
0
 /** Make a solid floor and add it to the scene. */
 public void initFloor() {
   Geometry floor_geo = new Geometry("Floor", floor);
   floor_geo.setMaterial(floor_mat);
   floor_geo.setShadowMode(ShadowMode.Receive);
   floor_geo.setLocalTranslation(0, -0.1f, 0);
   this.rootNode.attachChild(floor_geo);
   /* Make the floor physical with mass 0.0f! */
   floor_phy = new RigidBodyControl(0.0f);
   floor_geo.addControl(floor_phy);
   bulletAppState.getPhysicsSpace().add(floor_phy);
 }
コード例 #3
0
ファイル: TestBrickTower.java プロジェクト: pilsnils/LEGO
 public void addBrick(Vector3f ori) {
   Geometry reBoxg = new Geometry("brick", brick);
   reBoxg.setMaterial(mat);
   reBoxg.setLocalTranslation(ori);
   reBoxg.rotate(0f, (float) Math.toRadians(angle), 0f);
   reBoxg.addControl(new RigidBodyControl(1.5f));
   reBoxg.setShadowMode(ShadowMode.CastAndReceive);
   reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f);
   this.rootNode.attachChild(reBoxg);
   this.getPhysicsSpace().add(reBoxg);
 }
コード例 #4
0
ファイル: TestBrickTower.java プロジェクト: pilsnils/LEGO
  public void initFloor() {
    Box floorBox = new Box(Vector3f.ZERO, 10f, 0.1f, 5f);
    floorBox.scaleTextureCoordinates(new Vector2f(3, 6));

    Geometry floor = new Geometry("floor", floorBox);
    floor.setMaterial(mat3);
    floor.setShadowMode(ShadowMode.Receive);
    floor.setLocalTranslation(0, 0, 0);
    floor.addControl(new RigidBodyControl(0));
    this.rootNode.attachChild(floor);
    this.getPhysicsSpace().add(floor);
  }
コード例 #5
0
ファイル: WorldManagerImpl.java プロジェクト: gedim21/game
  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]);
    }
  }
コード例 #6
0
 /** This method creates one individual physical brick. */
 public void makeBrick(Vector3f loc) {
   /** Create a brick geometry and attach to scene graph. */
   Geometry brick_geo = new Geometry("brick", box);
   brick_geo.setMaterial(wall_mat);
   rootNode.attachChild(brick_geo);
   /** Position the brick geometry and activate shadows */
   brick_geo.setLocalTranslation(loc);
   brick_geo.setShadowMode(ShadowMode.CastAndReceive);
   /** Make brick physical with a mass > 0.0f. */
   brick_phy = new RigidBodyControl(2f);
   /** Add physical brick to physics space. */
   brick_geo.addControl(brick_phy);
   bulletAppState.getPhysicsSpace().add(brick_phy);
 }
コード例 #7
0
ファイル: TestCcd.java プロジェクト: wufuyue/TCL_S820
 public void onAction(String binding, boolean value, float tpf) {
   if (binding.equals("shoot") && !value) {
     Geometry bulletg = new Geometry("bullet", bullet);
     bulletg.setMaterial(mat);
     bulletg.setName("bullet");
     bulletg.setLocalTranslation(cam.getLocation());
     bulletg.setShadowMode(ShadowMode.CastAndReceive);
     bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
     bulletg.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.1f);
     bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
     rootNode.attachChild(bulletg);
     getPhysicsSpace().add(bulletg);
   } else if (binding.equals("shoot2") && !value) {
     Geometry bulletg = new Geometry("bullet", bullet);
     bulletg.setMaterial(mat2);
     bulletg.setName("bullet");
     bulletg.setLocalTranslation(cam.getLocation());
     bulletg.setShadowMode(ShadowMode.CastAndReceive);
     bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
     bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
     rootNode.attachChild(bulletg);
     getPhysicsSpace().add(bulletg);
   }
 }
コード例 #8
0
ファイル: TestBrickTower.java プロジェクト: pilsnils/LEGO
 public void onAction(String name, boolean keyPressed, float tpf) {
   if (name.equals("shoot") && !keyPressed) {
     Geometry bulletg = new Geometry("bullet", bullet);
     bulletg.setMaterial(mat2);
     bulletg.setShadowMode(ShadowMode.CastAndReceive);
     bulletg.setLocalTranslation(getCam().getLocation());
     RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
     //                RigidBodyControl bulletNode = new
     // RigidBodyControl(bulletCollisionShape, 1);
     bulletNode.setLinearVelocity(getCam().getDirection().mult(25));
     bulletg.addControl(bulletNode);
     rootNode.attachChild(bulletg);
     getPhysicsSpace().add(bulletNode);
   }
 }
コード例 #9
0
 /**
  * This method creates one individual physical cannon ball. By defaul, the ball is accelerated and
  * flies from the camera position in the camera direction.
  */
 public void makeCannonBall() {
   /** Create a cannon ball geometry and attach to scene graph. */
   Geometry ball_geo = new Geometry("cannon ball", sphere);
   ball_geo.setMaterial(stone_mat);
   rootNode.attachChild(ball_geo);
   /** Position the cannon ball and activate shadows */
   ball_geo.setLocalTranslation(cam.getLocation());
   ball_geo.setShadowMode(ShadowMode.CastAndReceive);
   /** Make the ball physcial with a mass > 0.0f */
   ball_phy = new RigidBodyControl(1f);
   /** Add physical ball to physics space. */
   ball_geo.addControl(ball_phy);
   bulletAppState.getPhysicsSpace().add(ball_phy);
   /** Accelerate the physcial ball to shoot it. */
   ball_phy.setLinearVelocity(cam.getDirection().mult(25));
 }
コード例 #10
0
ファイル: WorldManagerImpl.java プロジェクト: gedim21/game
  @Override
  public Entity createPlayer(UUID id) {
    Entity entity = new Player(id);

    Box box = new Box(0.1f, 1f, 0.1f);
    Geometry geometry = new Geometry("geometry", box);
    entity.attachChild(geometry);

    CapsuleCollisionShape ccs = new CapsuleCollisionShape(0.25f, 1f);
    CharacterControl characterControl = new CharacterControl(ccs, 1f);
    geometry.addControl(characterControl);

    getPhysicsSpace().add(characterControl);
    serverState.addEntity(entity);

    return entity;
  }
コード例 #11
0
  @Override
  protected void controlUpdate(float tpf) {

    if (fire) {
      bulletTimer += tpf;

      if (bulletTimer > 0.07f) {
        Geometry newBullet = bullet.clone(false);
        newBullet.setLocalRotation(
            shipNode.getControl(RigidBodyControl.class).getPhysicsRotation().clone());
        newBullet.setLocalTranslation(
            shipNode.getControl(RigidBodyControl.class).getPhysicsLocation().clone());
        newBullet.addControl(
            new BulletControl(newBullet.getLocalTranslation(), newBullet, bulletApp, shape, asm));
        asm.getRootNode().attachChild(newBullet);
        bulletTimer = 0f;
      }
    } else if (!fire) {
      bulletTimer = 0f;
    }
  }
コード例 #12
0
ファイル: Main.java プロジェクト: Wigglez/GSP362
  @Override
  public void simpleInitApp() {

    //        setUpKeys();
    flyCam.setEnabled(false);

    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);

    Juggernaut = new Character(this, bulletAppState);

    setUpCameraBoxes();
    // Load in the level
    // Material m = assetManager.loadMaterial("Models/levelLayout - Update.mtl");
    Spatial map = assetManager.loadModel("Models/levelLayout - Update_cameraPos.obj");
    rootNode.attachChild(map);

    Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    //       mark_mat.setColor("Color", ColorRGBA.White);
    //       mark.setMaterial(mark_mat);
    //        mark.setLocalTranslation(1f,1f,1f);
    //        rootNode.attachChild(mark);

    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(map);
    landscape = new RigidBodyControl(sceneShape, 0);
    map.addControl(landscape);
    landscape.setCollisionGroup(1);
    landscape.removeCollideWithGroup(2);

    //        //Load Ninja as filler for character model
    //        ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    //        //ninja.rotate(0, -1.5f, 0);
    //        ninja.scale(0.02f, 0.02f, 0.02f);
    //        ninja.setLocalTranslation(new Vector3f(341, 300, 0));
    //        //ninja.setMaterial(mark_mat);
    //        rootNode.attachChild(ninja);
    //        CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1f, 2f);
    //        player = new CharacterControl(capsuleShape, .05f);
    //        player.setJumpSpeed(50);
    //        player.setFallSpeed(50);
    //        player.setGravity(120);
    //        player.setPhysicsLocation(new Vector3f(1f,8f,1f));
    //        player.setViewDirection(new Vector3f(-1.0f, 0, 0));
    //        player.setCollideWithGroups(2);
    //
    //
    //
    //        playerDebug = player.createDebugShape(assetManager);
    //        ninja.addControl(player);
    //        rootNode.attachChild(playerDebug);
    //
    //        bulletAppState.getPhysicsSpace().add(player);
    bulletAppState.getPhysicsSpace().add(landscape);

    // Elevator 1
    elevator1 = new Geometry("Elevator1", new Box(4, 1, 5));
    elevator1.setLocalTranslation(304, 20, 0);
    elevator1.setMaterial(mark_mat);
    elvtr1 = new RigidBodyControl(10);

    elevator1.addControl(elvtr1);
    elvtr1.setFriction(1000.0f);
    elvtr1.setKinematic(true);
    bulletAppState.getPhysicsSpace().add(elvtr1);
    rootNode.attachChild(elevator1);

    // Elevator 2
    elevator2 = new Geometry("Elevator2", new Box(4, 1, 5));
    elevator2.setLocalTranslation(192, 208, 0);
    elevator2.setMaterial(mark_mat);
    elvtr2 = new RigidBodyControl(1000000000);

    elevator2.addControl(elvtr2);
    elvtr2.setAngularDamping(100000.0f);
    elvtr2.setFriction(1000.0f);
    //        elvtr2.setKinematic(true);
    bulletAppState.getPhysicsSpace().add(elvtr2);
    rootNode.attachChild(elevator2);

    // Add lights to see the models
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);

    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White);
    rootNode.addLight(al);

    //        cam.setLocation(new Vector3f(player.getPhysicsLocation().x,
    // player.getPhysicsLocation().y + 5, player.getPhysicsLocation().z +40 ));
    //        cam.lookAt(player.getPhysicsLocation(), Vector3f.UNIT_Y);
    cam.setLocation(new Vector3f(0, 5, 40));
    cam.lookAt(new Vector3f(0, 5, 0), Vector3f.UNIT_Y);
  }