com.jme3.bullet.control.CharacterControl Java Examples

The following examples show how to use com.jme3.bullet.control.CharacterControl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SceneToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected void attachPhysicsSelection(Spatial geom) {
    PhysicsCollisionObject control = geom.getControl(RigidBodyControl.class);
    if (control == null) {
        control = geom.getControl(VehicleControl.class);
    }
    if (control == null) {
        control = geom.getControl(GhostControl.class);
    }
    if (control == null) {
        control = geom.getControl(CharacterControl.class);
    }
    if (control == null) {
        return;
    }
    Spatial selectionGeometry = DebugShapeFactory.getDebugShape(control.getCollisionShape());
    if (selectionGeometry != null) {
        selectionGeometry.setMaterial(blueMat);
        selectionGeometry.setLocalTransform(geom.getWorldTransform());
        toolsNode.attachChild(selectionGeometry);
        selectionShape = selectionGeometry;
    }
}
 
Example #2
Source File: TestWalkingChar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createCharacter() {
    CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f);
    character = new CharacterControl(capsule, 0.01f);
    model = (Node) assetManager.loadModel("Models/Oto/OtoOldAnim.j3o");
    //model.setLocalScale(0.5f);
    model.addControl(character);
    character.setPhysicsLocation(new Vector3f(-140, 40, -10));
    rootNode.attachChild(model);
    getPhysicsSpace().add(character);
}
 
Example #3
Source File: TestPhysicsCharacter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
  // activate physics
  bulletAppState = new BulletAppState();
  stateManager.attach(bulletAppState);

  // init a physical test scene
  PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace());
  setupKeys();

  // Add a physics character to the world
  physicsCharacter = new CharacterControl(new CapsuleCollisionShape(0.5f, 1.8f), .1f);
  physicsCharacter.setPhysicsLocation(new Vector3f(0, 1, 0));
  characterNode = new Node("character node");
  Spatial model = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
  model.scale(0.25f);
  characterNode.addControl(physicsCharacter);
  getPhysicsSpace().add(physicsCharacter);
  rootNode.attachChild(characterNode);
  characterNode.attachChild(model);

  // set forward camera node that follows the character
  camNode = new CameraNode("CamNode", cam);
  camNode.setControlDir(ControlDirection.SpatialToCamera);
  camNode.setLocalTranslation(new Vector3f(0, 1, -5));
  camNode.lookAt(model.getLocalTranslation(), Vector3f.UNIT_Y);
  characterNode.attachChild(camNode);

  //disable the default 1st-person flyCam (don't forget this!!)
  flyCam.setEnabled(false);

}
 
Example #4
Source File: TestWalkingChar.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void createCharacter() {
    CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f);
    character = new CharacterControl(capsule, 0.01f);
    model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    //model.setLocalScale(0.5f);
    model.addControl(character);
    character.setPhysicsLocation(new Vector3f(-140, 15, -10));
    rootNode.attachChild(model);
    getPhysicsSpace().add(character);
}
 
Example #5
Source File: TestPhysicsCharacter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
  // activate physics
  bulletAppState = new BulletAppState();
  stateManager.attach(bulletAppState);

  // init a physical test scene
  PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace());
  setupKeys();

  // Add a physics character to the world
  physicsCharacter = new CharacterControl(new CapsuleCollisionShape(0.5f, 1.8f), .1f);
  physicsCharacter.setPhysicsLocation(new Vector3f(0, 1, 0));
  characterNode = new Node("character node");
  Spatial model = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
  model.scale(0.25f);
  characterNode.addControl(physicsCharacter);
  getPhysicsSpace().add(physicsCharacter);
  rootNode.attachChild(characterNode);
  characterNode.attachChild(model);

  // set forward camera node that follows the character
  camNode = new CameraNode("CamNode", cam);
  camNode.setControlDir(ControlDirection.SpatialToCamera);
  camNode.setLocalTranslation(new Vector3f(0, 1, -5));
  camNode.lookAt(model.getLocalTranslation(), Vector3f.UNIT_Y);
  characterNode.attachChild(camNode);

  //disable the default 1st-person flyCam (don't forget this!!)
  flyCam.setEnabled(false);

}
 
Example #6
Source File: JmeCharacterControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public JmeCharacterControl(CharacterControl spatial, DataObject dataObject) {
    super(dataObject);
    getLookupContents().add(this);
    getLookupContents().add(spatial);
    this.geom = spatial;
    setName("CharacterControl");
}
 
Example #7
Source File: JmeCharacterControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected Sheet createSheet() {
    Sheet sheet = super.createSheet();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("CharacterControl");
    set.setName(CharacterControl.class.getName());
    CharacterControl obj = geom;//getLookup().lookup(Spatial.class);
    if (obj == null) {
        return sheet;
    }

    set.put(makeProperty(obj, Vector3f.class, "getPhysicsLocation", "setPhysicsLocation", "Physics Location"));

    set.put(makeProperty(obj, CollisionShape.class, "getCollisionShape", "setCollisionShape", "Collision Shape"));
    set.put(makeProperty(obj, int.class, "getCollisionGroup", "setCollisionGroup", "Collision Group"));
    set.put(makeProperty(obj, int.class, "getCollideWithGroups", "setCollideWithGroups", "Collide With Groups"));
    
    set.put(makeProperty(obj, int.class, "getUpAxis", "setUpAxis", "Up Axis"));
    set.put(makeProperty(obj, float.class, "getFallSpeed", "setFallSpeed", "Fall Speed"));
    set.put(makeProperty(obj, float.class, "getJumpSpeed", "setJumpSpeed", "Jump Speed"));
    set.put(makeProperty(obj, float.class, "getGravity", "setGravity", "Gravity"));
    set.put(makeProperty(obj, float.class, "getMaxSlope", "setMaxSlope", "Max Slope"));

    sheet.put(set);
    return sheet;

}
 
Example #8
Source File: HelloCollision.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
  /** Set up Physics */
  bulletAppState = new BulletAppState();
  stateManager.attach(bulletAppState);
  //bulletAppState.getPhysicsSpace().enableDebug(assetManager);

  // We re-use the flyby camera for rotation, while positioning is handled by physics
  viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
  flyCam.setMoveSpeed(100);
  setUpKeys();
  setUpLight();

  // We load the scene from the zip file and adjust its size.
  assetManager.registerLocator(
                  "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/town.zip",
                  HttpZipLocator.class);
  sceneModel = assetManager.loadModel("main.scene");
  sceneModel.setLocalScale(2f);

  // We set up collision detection for the scene by creating a
  // compound collision shape and a static RigidBodyControl with mass zero.
  CollisionShape sceneShape =
          CollisionShapeFactory.createMeshShape(sceneModel);
  landscape = new RigidBodyControl(sceneShape, 0);
  sceneModel.addControl(landscape);

  // We set up collision detection for the player by creating
  // a capsule collision shape and a CharacterControl.
  // The CharacterControl offers extra settings for
  // size, stepheight, jumping, falling, and gravity.
  // We also put the player in its starting position.
  CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
  player = new CharacterControl(capsuleShape, 0.05f);
  player.setJumpSpeed(20);
  player.setFallSpeed(30);
  player.setGravity(30);
  player.setPhysicsLocation(new Vector3f(0, 10, 0));

  // We attach the scene and the player to the rootnode and the physics space,
  // to make them appear in the game world.
  rootNode.attachChild(sceneModel);
  bulletAppState.getPhysicsSpace().add(landscape);
  bulletAppState.getPhysicsSpace().add(player);
}
 
Example #9
Source File: HelloCollision.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void simpleInitApp() {
  /** Set up Physics */
  bulletAppState = new BulletAppState();
  stateManager.attach(bulletAppState);
  //bulletAppState.getPhysicsSpace().enableDebug(assetManager);

  // We re-use the flyby camera for rotation, while positioning is handled by physics
  viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
  flyCam.setMoveSpeed(100);
  setUpKeys();
  setUpLight();

  // We load the scene from the zip file and adjust its size.
  assetManager.registerLocator("town.zip", ZipLocator.class.getName());
  sceneModel = assetManager.loadModel("main.scene");
  sceneModel.setLocalScale(2f);

  // We set up collision detection for the scene by creating a
  // compound collision shape and a static RigidBodyControl with mass zero.
  CollisionShape sceneShape =
          CollisionShapeFactory.createMeshShape((Node) sceneModel);
  landscape = new RigidBodyControl(sceneShape, 0);
  sceneModel.addControl(landscape);

  // We set up collision detection for the player by creating
  // a capsule collision shape and a CharacterControl.
  // The CharacterControl offers extra settings for
  // size, stepheight, jumping, falling, and gravity.
  // We also put the player in its starting position.
  CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
  player = new CharacterControl(capsuleShape, 0.05f);
  player.setJumpSpeed(20);
  player.setFallSpeed(30);
  player.setGravity(30);
  player.setPhysicsLocation(new Vector3f(0, 10, 0));

  // We attach the scene and the player to the rootnode and the physics space,
  // to make them appear in the game world.
  rootNode.attachChild(sceneModel);
  bulletAppState.getPhysicsSpace().add(landscape);
  bulletAppState.getPhysicsSpace().add(player);
}
 
Example #10
Source File: JmeCharacterControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Class getExplorerObjectClass() {
    return CharacterControl.class;
}
 
Example #11
Source File: JmeCharacterControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public org.openide.nodes.Node[] createNodes(Object key, DataObject key2, boolean cookie) {
    return new org.openide.nodes.Node[]{new JmeCharacterControl((CharacterControl) key, key2).setReadOnly(cookie)};
}