com.jme3.bullet.BulletAppState Java Examples

The following examples show how to use com.jme3.bullet.BulletAppState. 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: TestIssue1120.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void initializeNewTest() {
    bulletAppState = new BulletAppState();
    bulletAppState.setDebugEnabled(physicsDebug);
    stateManager.attach(bulletAppState);

    bulletAppState.setSpeed(bulletSpeed);

    dropTest();

    Geometry leftFloor = PhysicsTestHelper.createMeshTestFloor(assetManager, 20, new Vector3f(-11, -5, -10));
    addObject(leftFloor);

    //Hide physics debug visualization for floors
    if (physicsDebug) {
        BulletDebugAppState bulletDebugAppState = stateManager.getState(BulletDebugAppState.class);
        bulletDebugAppState.setFilter((Object obj) -> {
            return !(obj.equals(leftFloor.getControl(RigidBodyControl.class)));
        });
    }
}
 
Example #2
Source File: TestWalkingChar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);
    setupKeys();
    prepareBullet();
    prepareEffect();
    createLight();
    createSky();
    createTerrain();
    createWall();
    createCharacter();
    setupChaseCamera();
    setupAnimationController();
    setupFilter();
}
 
Example #3
Source File: TestWalkingChar.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);
    setupKeys();
    prepareBullet();
    prepareEffect();
    createLight();
    createSky();
    createTerrain();
    createWall();
    createCharacter();
    setupChaseCamera();
    setupAnimationController();
    setupFilter();
}
 
Example #4
Source File: TestIssue931.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    String sinbadPath = "Models/Sinbad/SinbadOldAnim.j3o";
    Node sinbad = (Node) assetManager.loadModel(sinbadPath);

    Node extender = new Node();
    for (Spatial child : sinbad.getChildren()) {
        extender.attachChild(child);
    }
    sinbad.attachChild(extender);

    //Note: PhysicsRagdollControl is still a WIP, constructor will change
    KinematicRagdollControl ragdoll = new KinematicRagdollControl(0.5f);
    sinbad.addControl(ragdoll);

    stop();
}
 
Example #5
Source File: TestBrickTower.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
 //   bulletAppState.setEnabled(false);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);

    brick = new Box(brickWidth, brickHeight, brickDepth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    initMaterial();
    initTower();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 25f, 8f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(80);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    rootNode.setShadowMode(ShadowMode.Off);
}
 
Example #6
Source File: TestIssue928.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
    if (frame % 4 == 0) {
        System.out.println(++count);
        bulletAppState = new BulletAppState();
        bulletAppState.setThreadingType(ThreadingType.PARALLEL);
        stateManager.attach(bulletAppState);
    } else if (frame % 4 == 2) {
        stateManager.detach(bulletAppState);
    }

    frame++;
    if (count == 70) {
        System.exit(0);
    }
}
 
Example #7
Source File: HelloPhysics.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
  /** Set up Physics Game */
  bulletAppState = new BulletAppState();
  stateManager.attach(bulletAppState);
  //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
  /** Configure cam to look at scene */
  cam.setLocation(new Vector3f(0, 4f, 6f));
  cam.lookAt(new Vector3f(2, 2, 0), Vector3f.UNIT_Y);
  /** Initialize the scene, materials, inputs, and physics space */
  initInputs();
  initMaterials();
  initWall();
  initFloor();
  initCrossHairs();
}
 
Example #8
Source File: HelloPhysics.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
  /** Set up Physics Game */
  bulletAppState = new BulletAppState();
  stateManager.attach(bulletAppState);
  //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
  /** Configure cam to look at scene */
  cam.setLocation(new Vector3f(0, 4f, 6f));
  cam.lookAt(new Vector3f(2, 2, 0), Vector3f.UNIT_Y);
  /** Initialize the scene, materials, inputs, and physics space */
  initInputs();
  initMaterials();
  initWall();
  initFloor();
  initCrossHairs();
}
 
Example #9
Source File: TestAttachDriver.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    setupKeys();
    setupFloor();
    buildPlayer();
}
 
Example #10
Source File: MainRTS.java    From OpenRTS with MIT License 5 votes vote down vote up
@Override
public void simpleInitApp() {
	bulletAppState = new BulletAppState();
	stateManager.attach(bulletAppState);
	bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0, 0, -1));
	// stateManager.detach(bulletAppState);

	flyCam.setUpVector(new Vector3f(0, 0, 1));
	flyCam.setEnabled(false);

	MaterialManager.setAssetManager(assetManager);
	view = new EditorView(rootNode, guiNode, bulletAppState.getPhysicsSpace(), assetManager, viewPort);

	NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);

	fieldCtrl = new BattlefieldController(view, niftyDisplay.getNifty(), inputManager, cam);
	editorCtrl = new EditorController(view, niftyDisplay.getNifty(), inputManager, cam);
	groundCtrl = new GroundController(view, niftyDisplay.getNifty(), inputManager, cam);
	EventManager.register(this);

	niftyDisplay.getNifty().setIgnoreKeyboardEvents(true);
	// TODO: validation is needed to be sure everyting in XML is fine. see http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:nifty_gui_best_practices
	// niftyDisplay.getNifty().validateXml("interface/screen.xml");
	niftyDisplay.getNifty().fromXml("interface/screen.xml", "editor");

	actualCtrl = editorCtrl;
	stateManager.attach(actualCtrl);
	actualCtrl.setEnabled(true);

	guiViewPort.addProcessor(niftyDisplay);

	CollisionTester.setAssetManager(assetManager);
	CollisionTester.root = rootNode;
	
	ModelManager.setNewBattlefield();
}
 
Example #11
Source File: Game.java    From OpenRTS with MIT License 5 votes vote down vote up
@Override
public void simpleInitApp() {
	BulletAppState bulletAppState = new BulletAppState();
	stateManager.attach(bulletAppState);
	bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0, 0, -1));
	// stateManager.detach(bulletAppState);

	flyCam.setUpVector(new Vector3f(0, 0, 1));
	flyCam.setEnabled(false);

	view = new MapView(rootNode, guiNode, bulletAppState.getPhysicsSpace(), assetManager, viewPort);

	NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
	fieldCtrl = new BattlefieldController(view, niftyDisplay.getNifty(), inputManager, cam);
	EventManager.register(this);

	niftyDisplay.getNifty().setIgnoreKeyboardEvents(true);
	// TODO: validation is needed to be sure everyting in XML is fine. see http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:nifty_gui_best_practices
	// niftyDisplay.getNifty().validateXml("interface/screen.xml");
	niftyDisplay.getNifty().fromXml("interface/screen.xml", "hud");

	stateManager.attach(fieldCtrl);
	fieldCtrl.setEnabled(true);
	if (view.getMapRend() != null) {
		view.getMapRend().renderTiles();
	}
	guiViewPort.addProcessor(niftyDisplay);
}
 
Example #12
Source File: GameMutliplayer.java    From OpenRTS with MIT License 5 votes vote down vote up
@Override
public void simpleInitApp() {
	BulletAppState bulletAppState = new BulletAppState();
	stateManager.attach(bulletAppState);
	bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0, 0, -1));
	// stateManager.detach(bulletAppState);

	flyCam.setUpVector(new Vector3f(0, 0, 1));
	flyCam.setEnabled(false);

	EditorView view = new EditorView(rootNode, guiNode, bulletAppState.getPhysicsSpace(), assetManager, viewPort);

	NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);

	BattlefieldController fieldCtrl = new BattlefieldController(view, niftyDisplay.getNifty(), inputManager, cam);

	niftyDisplay.getNifty().setIgnoreKeyboardEvents(true);
	// TODO: validation is needed to be sure everyting in XML is fine. see http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:nifty_gui_best_practices
	// niftyDisplay.getNifty().validateXml("interface/screen.xml");
	niftyDisplay.getNifty().fromXml("interface/screen.xml", "hud");

	stateManager.attach(fieldCtrl);
	fieldCtrl.setEnabled(true);

	guiViewPort.addProcessor(niftyDisplay);

	if (!mapfilename.isEmpty()) {
		ModelManager.loadBattlefield(mapfilename);
	} else {
		ModelManager.setNewBattlefield();
	}
}
 
Example #13
Source File: Editor.java    From OpenRTS with MIT License 5 votes vote down vote up
@Override
public void simpleInitApp() {
	BulletAppState bulletAppState = new BulletAppState();
	stateManager.attach(bulletAppState);
	bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0, 0, -1));
	// stateManager.detach(bulletAppState);

	flyCam.setUpVector(new Vector3f(0, 0, 1));
	flyCam.setEnabled(false);

	EditorView view = new EditorView(rootNode, guiNode, bulletAppState.getPhysicsSpace(), assetManager, viewPort);

	NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);

	EditorController editorCtrl = new EditorController(view, niftyDisplay.getNifty(), inputManager, cam);

	niftyDisplay.getNifty().setIgnoreKeyboardEvents(true);
	// TODO: validation is needed to be sure everyting in XML is fine. see http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:nifty_gui_best_practices
	// niftyDisplay.getNifty().validateXml("interface/screen.xml");
	niftyDisplay.getNifty().fromXml("interface/screen.xml", "editor");

	stateManager.attach(editorCtrl);
	editorCtrl.setEnabled(true);

	ModelManager.setNewBattlefield();

	guiViewPort.addProcessor(niftyDisplay);
}
 
Example #14
Source File: Game.java    From OpenRTS with MIT License 5 votes vote down vote up
@Override
public void simpleInitApp() {
	BulletAppState bulletAppState = new BulletAppState();
	stateManager.attach(bulletAppState);
	bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0, 0, -1));
	// stateManager.detach(bulletAppState);

	flyCam.setUpVector(new Vector3f(0, 0, 1));
	flyCam.setEnabled(false);

	MaterialManager.setAssetManager(assetManager);
	MapView view = new MapView(rootNode, guiNode, bulletAppState.getPhysicsSpace(), assetManager, viewPort);

	NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
	BattlefieldController fieldCtrl = new BattlefieldController(view, niftyDisplay.getNifty(), inputManager, cam);

	niftyDisplay.getNifty().setIgnoreKeyboardEvents(true);
	// TODO: validation is needed to be sure everyting in XML is fine. see http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:nifty_gui_best_practices
	// niftyDisplay.getNifty().validateXml("interface/screen.xml");
	niftyDisplay.getNifty().fromXml("interface/screen.xml", "editor");

	stateManager.attach(fieldCtrl);
	fieldCtrl.setEnabled(true);

	ModelManager.setNewBattlefield();

	guiViewPort.addProcessor(niftyDisplay);
}
 
Example #15
Source File: TestPhysicsCar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    setupKeys();
    buildPlayer();
}
 
Example #16
Source File: TestIssue883.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {

    BulletAppState bulletAppState = new BulletAppState() {
        @Override
        public void physicsTick(PhysicsSpace space, float timeStep) {
            physicsTime += timeStep;
        }
    };
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);
}
 
Example #17
Source File: TestPhysicsHingeJoint.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    setupKeys();
    setupJoint();
}
 
Example #18
Source File: TestPhysicsHingeJoint.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    setupKeys();
    setupJoint();
}
 
Example #19
Source File: OpenRTSApplication.java    From OpenRTS with MIT License 5 votes vote down vote up
@Override
public void initialize() {
	bulletAppState = new BulletAppState();
	bulletAppState.startPhysics();

	super.initialize();

	guiNode.setQueueBucket(Bucket.Gui);
	guiNode.setCullHint(CullHint.Never);
	initTexts();
	loadStatsView();
	viewPort.attachScene(rootNode);
	guiViewPort.attachScene(guiNode);

	if (inputManager != null) {
		flyCam = new AzertyFlyByCamera(cam);
		flyCam.setMoveSpeed(1f);
		flyCam.registerWithInput(inputManager);

		if (context.getType() == Type.Display) {
			inputManager.addMapping("SIMPLEAPP_Exit", new KeyTrigger(KeyInput.KEY_ESCAPE));
		}

		inputManager.addMapping("SIMPLEAPP_CameraPos", new KeyTrigger(KeyInput.KEY_C));
		inputManager.addMapping("SIMPLEAPP_Memory", new KeyTrigger(KeyInput.KEY_M));
		inputManager.addListener(actionListener, "SIMPLEAPP_Exit", "SIMPLEAPP_CameraPos", "SIMPLEAPP_Memory");
	}

	// call user code
	simpleInitApp();
	stateManager.attach(bulletAppState);
	getPhysicsSpace().addTickListener(this);
}
 
Example #20
Source File: TestBrickWall.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);

    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);
    brick = new Box(Vector3f.ZERO, bLength, bHeight, bWidth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));

    initMaterial();
    initWall();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 6f, 6f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(15);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    inputManager.addMapping("gc", new KeyTrigger(KeyInput.KEY_X));
    inputManager.addListener(actionListener, "gc");

    rootNode.setShadowMode(ShadowMode.Off);
    bsr = new BasicShadowRenderer(assetManager, 256);
    bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    viewPort.addProcessor(bsr);
}
 
Example #21
Source File: TestAttachGhostObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    setupKeys();
    setupJoint();
}
 
Example #22
Source File: TestCollisionShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example #23
Source File: TestHoveringTank.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
    public void simpleInitApp() {
        bulletAppState = new BulletAppState();
        bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
        stateManager.attach(bulletAppState);
//        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
        bulletAppState.getPhysicsSpace().setAccuracy(1f/30f);
        rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));

        PssmShadowRenderer pssmr = new PssmShadowRenderer(assetManager, 2048, 3);
        pssmr.setDirection(new Vector3f(-0.5f, -0.3f, -0.3f).normalizeLocal());
        pssmr.setLambda(0.55f);
        pssmr.setShadowIntensity(0.6f);
        pssmr.setCompareMode(CompareMode.Hardware);
        pssmr.setFilterMode(FilterMode.Bilinear);
        viewPort.addProcessor(pssmr);

        setupKeys();
        createTerrain();
        buildPlayer();

        DirectionalLight dl = new DirectionalLight();
        dl.setColor(new ColorRGBA(1.0f, 0.94f, 0.8f, 1f).multLocal(1.3f));
        dl.setDirection(new Vector3f(-0.5f, -0.3f, -0.3f).normalizeLocal());
        rootNode.addLight(dl);

        Vector3f lightDir2 = new Vector3f(0.70518064f, 0.5902297f, -0.39287305f);
        DirectionalLight dl2 = new DirectionalLight();
        dl2.setColor(new ColorRGBA(0.7f, 0.85f, 1.0f, 1f));
        dl2.setDirection(lightDir2);
        rootNode.addLight(dl2);
    }
 
Example #24
Source File: TestRagdollCharacter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
        setupKeys();

        bulletAppState = new BulletAppState();
        bulletAppState.setEnabled(true);
        stateManager.attach(bulletAppState);


//        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
        PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
        initWall(2,1,1);
        setupLight();

        cam.setLocation(new Vector3f(-8,0,-4));
        cam.lookAt(new Vector3f(4,0,-7), Vector3f.UNIT_Y);

        model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
        model.lookAt(new Vector3f(0,0,-1), Vector3f.UNIT_Y);
        model.setLocalTranslation(4, 0, -7f);

        ragdoll = new KinematicRagdollControl(0.5f);
        model.addControl(ragdoll);

        getPhysicsSpace().add(ragdoll);
        speed = 1.3f;

        rootNode.attachChild(model);


        AnimControl control = model.getControl(AnimControl.class);
        animChannel = control.createChannel();
        animChannel.setAnim("IdleTop");
        control.addListener(this);

    }
 
Example #25
Source File: TestCollisionGroups.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    
    // Add a physics sphere to the world
    Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
    physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
    rootNode.attachChild(physicsSphere);
    getPhysicsSpace().add(physicsSphere);

    // Add a physics sphere to the world
    Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
    physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
    physicsSphere2.getControl(RigidBodyControl.class).addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
    rootNode.attachChild(physicsSphere2);
    getPhysicsSpace().add(physicsSphere2);

    // an obstacle mesh, does not move (mass=0)
    Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
    node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
    node2.getControl(RigidBodyControl.class).setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
    node2.getControl(RigidBodyControl.class).setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_02);
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);

    // the floor, does not move (mass=0)
    Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Box(Vector3f.ZERO, 100f, 0.2f, 100f)), 0);
    node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);
}
 
Example #26
Source File: TestPhysicsCar.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    setupKeys();
    buildPlayer();
}
 
Example #27
Source File: TestCcd.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.1f);
    setupKeys();

    mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);

    mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.getAdditionalRenderState().setWireframe(true);
    mat2.setColor("Color", ColorRGBA.Red);

    // An obstacle mesh, does not move (mass=0)
    Node node2 = new Node();
    node2.setName("mesh");
    node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
    node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(Vector3f.ZERO, 4, 4, 0.1f)), 0));
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);

    // The floor, does not move (mass=0)
    Node node3 = new Node();
    node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
    node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);

}
 
Example #28
Source File: TestGhostObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);

    // Mesh to be shared across several boxes.
    Box boxGeom = new Box(Vector3f.ZERO, 1f, 1f, 1f);
    // CollisionShape to be shared across several boxes.
    CollisionShape shape = new BoxCollisionShape(new Vector3f(1, 1, 1));

    Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox.setName("box0");
    physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
    rootNode.attachChild(physicsBox);
    getPhysicsSpace().add(physicsBox);

    Node physicsBox1 = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox1.setName("box1");
    physicsBox1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0, 40, 0));
    rootNode.attachChild(physicsBox1);
    getPhysicsSpace().add(physicsBox1);

    Node physicsBox2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
    physicsBox2.setName("box0");
    physicsBox2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.5f, 80, -.8f));
    rootNode.attachChild(physicsBox2);
    getPhysicsSpace().add(physicsBox2);

    // the floor, does not move (mass=0)
    Node node = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(100, 1, 100)), 0);
    node.setName("floor");
    node.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node);
    getPhysicsSpace().add(node);

    initGhostObject();
}
 
Example #29
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 #30
Source File: TestRagDoll.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    inputManager.addMapping("Pull ragdoll up", new MouseButtonTrigger(0));
    inputManager.addListener(this, "Pull ragdoll up");
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    createRagDoll();
}