Java Code Examples for com.jme3.bullet.BulletAppState#getPhysicsSpace()

The following examples show how to use com.jme3.bullet.BulletAppState#getPhysicsSpace() . 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: TestIssue889.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setEnabled(false);

    BulletAppState bulletAppState = new BulletAppState();
    bulletAppState.setDebugEnabled(true);
    bulletAppState.setSpeed(0f);
    stateManager.attach(bulletAppState);
    PhysicsSpace space = bulletAppState.getPhysicsSpace();

    float radius = 1f;
    CollisionShape sphere = new SphereCollisionShape(radius);
    CollisionShape box = new BoxCollisionShape(Vector3f.UNIT_XYZ);

    RigidBodyControl rbc = new RigidBodyControl(box);
    rbc.setEnabled(false);
    rbc.setPhysicsSpace(space);
    rootNode.addControl(rbc);

    BetterCharacterControl bcc = new BetterCharacterControl(radius, 4f, 1f);
    bcc.setEnabled(false);
    bcc.setPhysicsSpace(space);
    rootNode.addControl(bcc);

    GhostControl gc = new GhostControl(sphere);
    gc.setEnabled(false);
    gc.setPhysicsSpace(space);
    rootNode.addControl(gc);
}
 
Example 2
Source File: TestRagdollCharacter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(50f);
    cam.setLocation(new Vector3f(-16f, 4.7f, -1.6f));
    cam.setRotation(new Quaternion(0.0484f, 0.804337f, -0.066f, 0.5885f));

    setupKeys();
    setupLight();

    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    //bulletAppState.setDebugEnabled(true);
    physicsSpace = bulletAppState.getPhysicsSpace();

    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager,
            physicsSpace);
    initWall(2f, 1f, 1f);

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

    composer = model.getControl(AnimComposer.class);
    composer.setCurrentAction("IdleTop");

    Action slice = composer.action("SliceHorizontal");
    composer.actionSequence("SliceOnce",
            slice, Tweens.callMethod(this, "onSliceDone"));

    ragdoll = new DynamicAnimControl();
    setupSinbad(ragdoll);
    model.addControl(ragdoll);
    physicsSpace.add(ragdoll);
}
 
Example 3
Source File: TestIssue1283.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Configure physics during startup.
 */
private void configurePhysics() {
    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    physicsSpace = bulletAppState.getPhysicsSpace();
    Vector3f gravityVector = new Vector3f(0f, -30f, 0f);
    physicsSpace.setGravity(gravityVector);
}
 
Example 4
Source File: TestIssue1125.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Configure physics during startup.
 */
private void configurePhysics() {
    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    physicsSpace = bulletAppState.getPhysicsSpace();
}
 
Example 5
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 6
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 7
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 8
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 9
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 10
Source File: TestBoneRagdoll.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(50f);
    cam.setLocation(new Vector3f(0.3f, 6.7f, 22.3f));
    cam.setRotation(new Quaternion(-2E-4f, 0.993025f, -0.1179f, -0.0019f));

    initCrossHairs();
    initMaterial();
    setupKeys();
    setupLight();

    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    //bulletAppState.setDebugEnabled(true);
    physicsSpace = bulletAppState.getPhysicsSpace();

    bullet = new Sphere(32, 32, 1f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(1f);

    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager,
            physicsSpace);

    model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
    rootNode.attachChild(model);

    composer = model.getControl(AnimComposer.class);
    composer.setCurrentAction("Dance");

    Action standUpFront = composer.action("StandUpFront");
    composer.actionSequence("FrontOnce",
            standUpFront, Tweens.callMethod(this, "onStandDone"));
    Action standUpBack = composer.action("StandUpBack");
    composer.actionSequence("BackOnce",
            standUpBack, Tweens.callMethod(this, "onStandDone"));

    ragdoll = new DynamicAnimControl();
    TestRagdollCharacter.setupSinbad(ragdoll);
    model.addControl(ragdoll);
    physicsSpace.add(ragdoll);
    ragdoll.addCollisionListener(this);
}