Bullet (and jBullet): Update Test Classes to use BulletAppState.setDebugEnabled instead of PhysicsSpace.enableDebug.
This commit is contained in:
parent
70b03ea28a
commit
a52bc0a82c
@ -69,7 +69,7 @@ public class TestAttachDriver extends SimpleApplication implements ActionListene
|
|||||||
private float accelerationValue = 0;
|
private float accelerationValue = 0;
|
||||||
private Vector3f jumpForce = new Vector3f(0, 3000, 0);
|
private Vector3f jumpForce = new Vector3f(0, 3000, 0);
|
||||||
private BulletAppState bulletAppState;
|
private BulletAppState bulletAppState;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TestAttachDriver app = new TestAttachDriver();
|
TestAttachDriver app = new TestAttachDriver();
|
||||||
app.start();
|
app.start();
|
||||||
@ -79,7 +79,7 @@ public class TestAttachDriver extends SimpleApplication implements ActionListene
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
setupKeys();
|
setupKeys();
|
||||||
setupFloor();
|
setupFloor();
|
||||||
buildPlayer();
|
buildPlayer();
|
||||||
|
@ -85,7 +85,7 @@ public class TestAttachGhostObject extends SimpleApplication implements AnalogLi
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
setupKeys();
|
setupKeys();
|
||||||
setupJoint();
|
setupJoint();
|
||||||
}
|
}
|
||||||
|
@ -1,152 +1,152 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
* met:
|
* met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package jme3test.bullet;
|
package jme3test.bullet;
|
||||||
|
|
||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.bullet.BulletAppState;
|
import com.jme3.bullet.BulletAppState;
|
||||||
import com.jme3.bullet.PhysicsSpace;
|
import com.jme3.bullet.PhysicsSpace;
|
||||||
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
|
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
|
||||||
import com.jme3.bullet.collision.shapes.MeshCollisionShape;
|
import com.jme3.bullet.collision.shapes.MeshCollisionShape;
|
||||||
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
|
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
|
||||||
import com.jme3.bullet.control.RigidBodyControl;
|
import com.jme3.bullet.control.RigidBodyControl;
|
||||||
import com.jme3.input.MouseInput;
|
import com.jme3.input.MouseInput;
|
||||||
import com.jme3.input.controls.ActionListener;
|
import com.jme3.input.controls.ActionListener;
|
||||||
import com.jme3.input.controls.MouseButtonTrigger;
|
import com.jme3.input.controls.MouseButtonTrigger;
|
||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.renderer.RenderManager;
|
import com.jme3.renderer.RenderManager;
|
||||||
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.shape.Box;
|
import com.jme3.scene.shape.Box;
|
||||||
import com.jme3.scene.shape.Sphere;
|
import com.jme3.scene.shape.Sphere;
|
||||||
import com.jme3.scene.shape.Sphere.TextureMode;
|
import com.jme3.scene.shape.Sphere.TextureMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author normenhansen
|
* @author normenhansen
|
||||||
*/
|
*/
|
||||||
public class TestCcd extends SimpleApplication implements ActionListener {
|
public class TestCcd extends SimpleApplication implements ActionListener {
|
||||||
|
|
||||||
private Material mat;
|
private Material mat;
|
||||||
private Material mat2;
|
private Material mat2;
|
||||||
private Sphere bullet;
|
private Sphere bullet;
|
||||||
private SphereCollisionShape bulletCollisionShape;
|
private SphereCollisionShape bulletCollisionShape;
|
||||||
private BulletAppState bulletAppState;
|
private BulletAppState bulletAppState;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TestCcd app = new TestCcd();
|
TestCcd app = new TestCcd();
|
||||||
app.start();
|
app.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupKeys() {
|
private void setupKeys() {
|
||||||
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
|
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
|
||||||
inputManager.addMapping("shoot2", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
|
inputManager.addMapping("shoot2", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
|
||||||
inputManager.addListener(this, "shoot");
|
inputManager.addListener(this, "shoot");
|
||||||
inputManager.addListener(this, "shoot2");
|
inputManager.addListener(this, "shoot2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
bullet = new Sphere(32, 32, 0.4f, true, false);
|
bullet = new Sphere(32, 32, 0.4f, true, false);
|
||||||
bullet.setTextureMode(TextureMode.Projected);
|
bullet.setTextureMode(TextureMode.Projected);
|
||||||
bulletCollisionShape = new SphereCollisionShape(0.1f);
|
bulletCollisionShape = new SphereCollisionShape(0.1f);
|
||||||
setupKeys();
|
setupKeys();
|
||||||
|
|
||||||
mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
mat.getAdditionalRenderState().setWireframe(true);
|
mat.getAdditionalRenderState().setWireframe(true);
|
||||||
mat.setColor("Color", ColorRGBA.Green);
|
mat.setColor("Color", ColorRGBA.Green);
|
||||||
|
|
||||||
mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
mat2.getAdditionalRenderState().setWireframe(true);
|
mat2.getAdditionalRenderState().setWireframe(true);
|
||||||
mat2.setColor("Color", ColorRGBA.Red);
|
mat2.setColor("Color", ColorRGBA.Red);
|
||||||
|
|
||||||
// An obstacle mesh, does not move (mass=0)
|
// An obstacle mesh, does not move (mass=0)
|
||||||
Node node2 = new Node();
|
Node node2 = new Node();
|
||||||
node2.setName("mesh");
|
node2.setName("mesh");
|
||||||
node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
|
node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
|
||||||
node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(Vector3f.ZERO, 4, 4, 0.1f)), 0));
|
node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(Vector3f.ZERO, 4, 4, 0.1f)), 0));
|
||||||
rootNode.attachChild(node2);
|
rootNode.attachChild(node2);
|
||||||
getPhysicsSpace().add(node2);
|
getPhysicsSpace().add(node2);
|
||||||
|
|
||||||
// The floor, does not move (mass=0)
|
// The floor, does not move (mass=0)
|
||||||
Node node3 = new Node();
|
Node node3 = new Node();
|
||||||
node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
|
node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
|
||||||
node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
|
node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
|
||||||
rootNode.attachChild(node3);
|
rootNode.attachChild(node3);
|
||||||
getPhysicsSpace().add(node3);
|
getPhysicsSpace().add(node3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PhysicsSpace getPhysicsSpace() {
|
private PhysicsSpace getPhysicsSpace() {
|
||||||
return bulletAppState.getPhysicsSpace();
|
return bulletAppState.getPhysicsSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
//TODO: add update code
|
//TODO: add update code
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleRender(RenderManager rm) {
|
public void simpleRender(RenderManager rm) {
|
||||||
//TODO: add render code
|
//TODO: add render code
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAction(String binding, boolean value, float tpf) {
|
public void onAction(String binding, boolean value, float tpf) {
|
||||||
if (binding.equals("shoot") && !value) {
|
if (binding.equals("shoot") && !value) {
|
||||||
Geometry bulletg = new Geometry("bullet", bullet);
|
Geometry bulletg = new Geometry("bullet", bullet);
|
||||||
bulletg.setMaterial(mat);
|
bulletg.setMaterial(mat);
|
||||||
bulletg.setName("bullet");
|
bulletg.setName("bullet");
|
||||||
bulletg.setLocalTranslation(cam.getLocation());
|
bulletg.setLocalTranslation(cam.getLocation());
|
||||||
bulletg.setShadowMode(ShadowMode.CastAndReceive);
|
bulletg.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
|
bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
|
||||||
bulletg.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.1f);
|
bulletg.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.1f);
|
||||||
bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
|
bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
|
||||||
rootNode.attachChild(bulletg);
|
rootNode.attachChild(bulletg);
|
||||||
getPhysicsSpace().add(bulletg);
|
getPhysicsSpace().add(bulletg);
|
||||||
} else if (binding.equals("shoot2") && !value) {
|
} else if (binding.equals("shoot2") && !value) {
|
||||||
Geometry bulletg = new Geometry("bullet", bullet);
|
Geometry bulletg = new Geometry("bullet", bullet);
|
||||||
bulletg.setMaterial(mat2);
|
bulletg.setMaterial(mat2);
|
||||||
bulletg.setName("bullet");
|
bulletg.setName("bullet");
|
||||||
bulletg.setLocalTranslation(cam.getLocation());
|
bulletg.setLocalTranslation(cam.getLocation());
|
||||||
bulletg.setShadowMode(ShadowMode.CastAndReceive);
|
bulletg.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
|
bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
|
||||||
bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
|
bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
|
||||||
rootNode.attachChild(bulletg);
|
rootNode.attachChild(bulletg);
|
||||||
getPhysicsSpace().add(bulletg);
|
getPhysicsSpace().add(bulletg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,8 @@ public class TestCollisionGroups extends SimpleApplication {
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
|
|
||||||
// Add a physics sphere to the world
|
// Add a physics sphere to the world
|
||||||
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
|
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
|
||||||
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
|
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
|
||||||
|
@ -1,98 +1,98 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
* met:
|
* met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jme3test.bullet;
|
package jme3test.bullet;
|
||||||
|
|
||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.bullet.BulletAppState;
|
import com.jme3.bullet.BulletAppState;
|
||||||
import com.jme3.bullet.PhysicsSpace;
|
import com.jme3.bullet.PhysicsSpace;
|
||||||
import com.jme3.bullet.collision.PhysicsCollisionEvent;
|
import com.jme3.bullet.collision.PhysicsCollisionEvent;
|
||||||
import com.jme3.bullet.collision.PhysicsCollisionListener;
|
import com.jme3.bullet.collision.PhysicsCollisionListener;
|
||||||
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
|
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
|
||||||
import com.jme3.renderer.RenderManager;
|
import com.jme3.renderer.RenderManager;
|
||||||
import com.jme3.scene.shape.Sphere;
|
import com.jme3.scene.shape.Sphere;
|
||||||
import com.jme3.scene.shape.Sphere.TextureMode;
|
import com.jme3.scene.shape.Sphere.TextureMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author normenhansen
|
* @author normenhansen
|
||||||
*/
|
*/
|
||||||
public class TestCollisionListener extends SimpleApplication implements PhysicsCollisionListener {
|
public class TestCollisionListener extends SimpleApplication implements PhysicsCollisionListener {
|
||||||
|
|
||||||
private BulletAppState bulletAppState;
|
private BulletAppState bulletAppState;
|
||||||
private Sphere bullet;
|
private Sphere bullet;
|
||||||
private SphereCollisionShape bulletCollisionShape;
|
private SphereCollisionShape bulletCollisionShape;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TestCollisionListener app = new TestCollisionListener();
|
TestCollisionListener app = new TestCollisionListener();
|
||||||
app.start();
|
app.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
bullet = new Sphere(32, 32, 0.4f, true, false);
|
bullet = new Sphere(32, 32, 0.4f, true, false);
|
||||||
bullet.setTextureMode(TextureMode.Projected);
|
bullet.setTextureMode(TextureMode.Projected);
|
||||||
bulletCollisionShape = new SphereCollisionShape(0.4f);
|
bulletCollisionShape = new SphereCollisionShape(0.4f);
|
||||||
|
|
||||||
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
||||||
PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace());
|
PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace());
|
||||||
|
|
||||||
// add ourselves as collision listener
|
// add ourselves as collision listener
|
||||||
getPhysicsSpace().addCollisionListener(this);
|
getPhysicsSpace().addCollisionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PhysicsSpace getPhysicsSpace(){
|
private PhysicsSpace getPhysicsSpace(){
|
||||||
return bulletAppState.getPhysicsSpace();
|
return bulletAppState.getPhysicsSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
//TODO: add update code
|
//TODO: add update code
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleRender(RenderManager rm) {
|
public void simpleRender(RenderManager rm) {
|
||||||
//TODO: add render code
|
//TODO: add render code
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collision(PhysicsCollisionEvent event) {
|
public void collision(PhysicsCollisionEvent event) {
|
||||||
if ("Box".equals(event.getNodeA().getName()) || "Box".equals(event.getNodeB().getName())) {
|
if ("Box".equals(event.getNodeA().getName()) || "Box".equals(event.getNodeB().getName())) {
|
||||||
if ("bullet".equals(event.getNodeA().getName()) || "bullet".equals(event.getNodeB().getName())) {
|
if ("bullet".equals(event.getNodeA().getName()) || "bullet".equals(event.getNodeB().getName())) {
|
||||||
fpsText.setText("You hit the box!");
|
fpsText.setText("You hit the box!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public class TestCollisionShapeFactory extends SimpleApplication {
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
createMaterial();
|
createMaterial();
|
||||||
|
|
||||||
Node node = new Node("node1");
|
Node node = new Node("node1");
|
||||||
|
@ -62,7 +62,7 @@ public class TestGhostObject extends SimpleApplication {
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
|
|
||||||
// Mesh to be shared across several boxes.
|
// Mesh to be shared across several boxes.
|
||||||
Box boxGeom = new Box(Vector3f.ZERO, 1f, 1f, 1f);
|
Box boxGeom = new Box(Vector3f.ZERO, 1f, 1f, 1f);
|
||||||
|
@ -60,7 +60,7 @@ public class TestKinematicAddToPhysicsSpaceIssue extends SimpleApplication {
|
|||||||
|
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
// Add a physics sphere to the world
|
// Add a physics sphere to the world
|
||||||
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
|
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
|
||||||
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
|
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
|
||||||
@ -69,7 +69,7 @@ public class TestKinematicAddToPhysicsSpaceIssue extends SimpleApplication {
|
|||||||
//Setting the rigidBody to kinematic before adding it to the physic space
|
//Setting the rigidBody to kinematic before adding it to the physic space
|
||||||
physicsSphere.getControl(RigidBodyControl.class).setKinematic(true);
|
physicsSphere.getControl(RigidBodyControl.class).setKinematic(true);
|
||||||
//adding it to the physic space
|
//adding it to the physic space
|
||||||
getPhysicsSpace().add(physicsSphere);
|
getPhysicsSpace().add(physicsSphere);
|
||||||
//Making it not kinematic again, it should fall under gravity, it doesn't
|
//Making it not kinematic again, it should fall under gravity, it doesn't
|
||||||
physicsSphere.getControl(RigidBodyControl.class).setKinematic(false);
|
physicsSphere.getControl(RigidBodyControl.class).setKinematic(false);
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ public class TestKinematicAddToPhysicsSpaceIssue extends SimpleApplication {
|
|||||||
Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
|
Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
|
||||||
physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(5, 6, 0));
|
physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(5, 6, 0));
|
||||||
rootNode.attachChild(physicsSphere2);
|
rootNode.attachChild(physicsSphere2);
|
||||||
|
|
||||||
//Adding the rigid body to physic space
|
//Adding the rigid body to physic space
|
||||||
getPhysicsSpace().add(physicsSphere2);
|
getPhysicsSpace().add(physicsSphere2);
|
||||||
//making it kinematic
|
//making it kinematic
|
||||||
@ -85,7 +85,7 @@ public class TestKinematicAddToPhysicsSpaceIssue extends SimpleApplication {
|
|||||||
//Making it not kinematic again, it works properly, the rigidbody is affected by grvity.
|
//Making it not kinematic again, it works properly, the rigidbody is affected by grvity.
|
||||||
physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false);
|
physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// an obstacle mesh, does not move (mass=0)
|
// an obstacle mesh, does not move (mass=0)
|
||||||
Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
|
Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
|
||||||
|
@ -59,7 +59,7 @@ public class TestLocalPhysics extends SimpleApplication {
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
|
|
||||||
// Add a physics sphere to the world
|
// Add a physics sphere to the world
|
||||||
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
|
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
|
||||||
|
@ -69,7 +69,7 @@ public class TestPhysicsCar extends SimpleApplication implements ActionListener
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
||||||
setupKeys();
|
setupKeys();
|
||||||
buildPlayer();
|
buildPlayer();
|
||||||
|
@ -76,7 +76,7 @@ public class TestPhysicsHingeJoint extends SimpleApplication implements AnalogLi
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
setupKeys();
|
setupKeys();
|
||||||
setupJoint();
|
setupJoint();
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ public class TestPhysicsHingeJoint extends SimpleApplication implements AnalogLi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package jme3test.bullet;
|
package jme3test.bullet;
|
||||||
|
|
||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.bullet.BulletAppState;
|
import com.jme3.bullet.BulletAppState;
|
||||||
import com.jme3.bullet.collision.PhysicsCollisionObject;
|
import com.jme3.bullet.collision.PhysicsCollisionObject;
|
||||||
@ -16,30 +16,30 @@ import java.util.List;
|
|||||||
* @author @wezrule
|
* @author @wezrule
|
||||||
*/
|
*/
|
||||||
public class TestPhysicsRayCast extends SimpleApplication {
|
public class TestPhysicsRayCast extends SimpleApplication {
|
||||||
|
|
||||||
private BulletAppState bulletAppState = new BulletAppState();
|
private BulletAppState bulletAppState = new BulletAppState();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new TestPhysicsRayCast().start();
|
new TestPhysicsRayCast().start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
initCrossHair();
|
initCrossHair();
|
||||||
|
|
||||||
Spatial s = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
|
Spatial s = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
|
||||||
s.setLocalScale(0.1f);
|
s.setLocalScale(0.1f);
|
||||||
|
|
||||||
CollisionShape collisionShape = CollisionShapeFactory.createMeshShape(s);
|
CollisionShape collisionShape = CollisionShapeFactory.createMeshShape(s);
|
||||||
Node n = new Node("elephant");
|
Node n = new Node("elephant");
|
||||||
n.addControl(new RigidBodyControl(collisionShape, 1));
|
n.addControl(new RigidBodyControl(collisionShape, 1));
|
||||||
n.getControl(RigidBodyControl.class).setKinematic(true);
|
n.getControl(RigidBodyControl.class).setKinematic(true);
|
||||||
bulletAppState.getPhysicsSpace().add(n);
|
bulletAppState.getPhysicsSpace().add(n);
|
||||||
rootNode.attachChild(n);
|
rootNode.attachChild(n);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
List<PhysicsRayTestResult> rayTest = bulletAppState.getPhysicsSpace().rayTest(cam.getLocation(), cam.getLocation().add(cam.getDirection()));
|
List<PhysicsRayTestResult> rayTest = bulletAppState.getPhysicsSpace().rayTest(cam.getLocation(), cam.getLocation().add(cam.getDirection()));
|
||||||
@ -50,7 +50,7 @@ public class TestPhysicsRayCast extends SimpleApplication {
|
|||||||
fpsText.setText(collisionObject.getUserObject().toString());
|
fpsText.setText(collisionObject.getUserObject().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCrossHair() {
|
private void initCrossHair() {
|
||||||
BitmapText bitmapText = new BitmapText(guiFont);
|
BitmapText bitmapText = new BitmapText(guiFont);
|
||||||
bitmapText.setText("+");
|
bitmapText.setText("+");
|
||||||
|
@ -69,7 +69,7 @@ public class TestPhysicsReadWrite extends SimpleApplication{
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
physicsRootNode=new Node("PhysicsRootNode");
|
physicsRootNode=new Node("PhysicsRootNode");
|
||||||
rootNode.attachChild(physicsRootNode);
|
rootNode.attachChild(physicsRootNode);
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class TestRagDoll extends SimpleApplication implements ActionListener {
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
inputManager.addMapping("Pull ragdoll up", new MouseButtonTrigger(0));
|
inputManager.addMapping("Pull ragdoll up", new MouseButtonTrigger(0));
|
||||||
inputManager.addListener(this, "Pull ragdoll up");
|
inputManager.addListener(this, "Pull ragdoll up");
|
||||||
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
||||||
|
@ -59,7 +59,7 @@ public class TestSimplePhysics extends SimpleApplication {
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
bulletAppState = new BulletAppState();
|
bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
|
|
||||||
// Add a physics sphere to the world
|
// Add a physics sphere to the world
|
||||||
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
|
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
|
||||||
|
@ -35,7 +35,7 @@ public class TestSweepTest extends SimpleApplication {
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
obstacleCollisionShape = new CapsuleCollisionShape(0.3f, 0.5f);
|
obstacleCollisionShape = new CapsuleCollisionShape(0.3f, 0.5f);
|
||||||
capsuleCollisionShape = new CapsuleCollisionShape(1f, 1f);
|
capsuleCollisionShape = new CapsuleCollisionShape(1f, 1f);
|
||||||
|
|
||||||
stateManager.attach(bulletAppState);
|
stateManager.attach(bulletAppState);
|
||||||
|
|
||||||
capsule = new Node("capsule");
|
capsule = new Node("capsule");
|
||||||
@ -52,7 +52,7 @@ public class TestSweepTest extends SimpleApplication {
|
|||||||
bulletAppState.getPhysicsSpace().add(obstacle);
|
bulletAppState.getPhysicsSpace().add(obstacle);
|
||||||
rootNode.attachChild(obstacle);
|
rootNode.attachChild(obstacle);
|
||||||
|
|
||||||
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
bulletAppState.setDebugEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,7 +70,7 @@ public class TestSweepTest extends SimpleApplication {
|
|||||||
colliding = true;
|
colliding = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!colliding) {
|
if (!colliding) {
|
||||||
// if the sweep is clear then move the spatial
|
// if the sweep is clear then move the spatial
|
||||||
capsule.move(move, 0, 0);
|
capsule.move(move, 0, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user