- added ragdollCollisionListener
 - Switch between animControl and ragDollControl
 - TestBoneRagdoll : Shoot with left click, reset Oto with spacebar. Added bullet time on first impact :D have fun!

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7186 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 0a82e1ee11
commit 916f4f203c
  1. 4
      engine/src/jbullet/com/jme3/bullet/collision/PhysicsCollisionObject.java
  2. 17
      engine/src/jbullet/com/jme3/bullet/collision/RagdollCollisionListener.java
  3. 129
      engine/src/test/jme3test/bullet/TestBoneRagdoll.java

@ -169,12 +169,16 @@ public abstract class PhysicsCollisionObject implements Savable {
public Spatial attachDebugShape(AssetManager manager) { public Spatial attachDebugShape(AssetManager manager) {
debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md"); debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
debugMaterialBlue.setColor("Color", ColorRGBA.Blue); debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
// debugMaterialBlue.getAdditionalRenderState().setDepthTest(false);
debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md"); debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
debugMaterialGreen.setColor("Color", ColorRGBA.Green); debugMaterialGreen.setColor("Color", ColorRGBA.Green);
// debugMaterialGreen.getAdditionalRenderState().setDepthTest(false);
debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md"); debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
debugMaterialRed.setColor("Color", ColorRGBA.Red); debugMaterialRed.setColor("Color", ColorRGBA.Red);
// debugMaterialRed.getAdditionalRenderState().setDepthTest(false);
debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md"); debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
debugMaterialYellow.setColor("Color", ColorRGBA.Yellow); debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
// debugMaterialYellow.getAdditionalRenderState().setDepthTest(false);
debugArrow = new Arrow(Vector3f.UNIT_XYZ); debugArrow = new Arrow(Vector3f.UNIT_XYZ);
debugArrowGeom = new Geometry("DebugArrow", debugArrow); debugArrowGeom = new Geometry("DebugArrow", debugArrow);
debugArrowGeom.setMaterial(debugMaterialGreen); debugArrowGeom.setMaterial(debugMaterialGreen);

@ -0,0 +1,17 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.jme3.bullet.collision;
import com.jme3.animation.Bone;
/**
*
* @author Nehon
*/
public interface RagdollCollisionListener {
public void collide(Bone bone, PhysicsCollisionObject object);
}

@ -29,14 +29,18 @@
* 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.animation.AnimChannel;
import com.jme3.animation.AnimControl; import com.jme3.animation.AnimControl;
import com.jme3.animation.Bone;
import com.jme3.animation.LoopMode;
import com.jme3.bullet.BulletAppState; import com.jme3.bullet.BulletAppState;
import com.jme3.app.SimpleApplication; import com.jme3.app.SimpleApplication;
import com.jme3.asset.TextureKey; import com.jme3.asset.TextureKey;
import com.jme3.bullet.PhysicsSpace; import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.PhysicsCollisionObject;
import com.jme3.bullet.collision.RagdollCollisionListener;
import com.jme3.bullet.collision.shapes.SphereCollisionShape; import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.RagdollControl; import com.jme3.bullet.control.RagdollControl;
import com.jme3.bullet.control.RigidBodyControl; import com.jme3.bullet.control.RigidBodyControl;
@ -50,10 +54,8 @@ import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.DirectionalLight; import com.jme3.light.DirectionalLight;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
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.debug.SkeletonDebugger; import com.jme3.scene.debug.SkeletonDebugger;
@ -65,13 +67,14 @@ import com.jme3.texture.Texture;
* PHYSICS RAGDOLLS ARE NOT WORKING PROPERLY YET! * PHYSICS RAGDOLLS ARE NOT WORKING PROPERLY YET!
* @author normenhansen * @author normenhansen
*/ */
public class TestBoneRagdoll extends SimpleApplication { public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisionListener {
private BulletAppState bulletAppState; private BulletAppState bulletAppState;
Material matBullet; Material matBullet;
Node model; Node model;
RagdollControl ragdoll;
public static void main(String[] args){ public static void main(String[] args) {
TestBoneRagdoll app = new TestBoneRagdoll(); TestBoneRagdoll app = new TestBoneRagdoll();
app.start(); app.start();
} }
@ -79,85 +82,84 @@ public class TestBoneRagdoll extends SimpleApplication {
public void simpleInitApp() { public void simpleInitApp() {
initCrossHairs(); initCrossHairs();
initMaterial(); initMaterial();
cam.setLocation(new Vector3f(0.26924422f, 6.646658f, 22.265987f)); cam.setLocation(new Vector3f(0.26924422f, 6.646658f, 22.265987f));
cam.setRotation(new Quaternion(-2.302544E-4f, 0.99302495f, -0.117888905f, -0.0019395084f)); cam.setRotation(new Quaternion(-2.302544E-4f, 0.99302495f, -0.117888905f, -0.0019395084f));
bulletAppState = new BulletAppState(); bulletAppState = new BulletAppState();
bulletAppState.setEnabled(true); bulletAppState.setEnabled(true);
stateManager.attach(bulletAppState); stateManager.attach(bulletAppState);
// bulletAppState.getPhysicsSpace().enableDebug(assetManager); // bulletAppState.getPhysicsSpace().enableDebug(assetManager);
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace()); PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
setupLight(); setupLight();
model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml"); model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
// model.setLocalTranslation(5,5,5); // model.setLocalTranslation(5,5,5);
// model.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X)); // model.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
//debug view //debug view
AnimControl control= model.getControl(AnimControl.class); AnimControl control = model.getControl(AnimControl.class);
SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton()); SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton());
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md"); Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
mat2.setColor("Color", ColorRGBA.Green); mat2.setColor("Color", ColorRGBA.Green);
mat2.getAdditionalRenderState().setDepthTest(false); mat2.getAdditionalRenderState().setDepthTest(false);
skeletonDebug.setMaterial(mat2); skeletonDebug.setMaterial(mat2);
skeletonDebug.setLocalTranslation(model.getLocalTranslation()); skeletonDebug.setLocalTranslation(model.getLocalTranslation());
control.createChannel().setAnim("Walk"); // AnimChannel channel=control.createChannel();
// channel.setAnim("Dodge");
// channel.setLoopMode(LoopMode.Cycle);
// channel.setSpeed(0.1f);
//Note: PhysicsRagdollControl is still TODO, constructor will change //Note: PhysicsRagdollControl is still TODO, constructor will change
RagdollControl ragdoll = new RagdollControl(); ragdoll = new RagdollControl();
// ragdoll.setEnabled(true); ragdoll.addCollisionListener(this);
// ragdoll.attachDebugShape(assetManager); // ragdoll.setEnabled(true);
// ragdoll.attachDebugShape(assetManager);
// ragdoll.setSpatial(model); // ragdoll.setSpatial(model);
// ragdoll.setPhysicsSpace(getPhysicsSpace()); // ragdoll.setPhysicsSpace(getPhysicsSpace());
// control.setRagdoll(ragdoll); // control.setRagdoll(ragdoll);
model.addControl(ragdoll); model.addControl(ragdoll);
getPhysicsSpace().add(ragdoll); getPhysicsSpace().add(ragdoll);
speed = 1f; speed = 1f;
rootNode.attachChild(model); rootNode.attachChild(model);
rootNode.attachChild(skeletonDebug); // rootNode.attachChild(skeletonDebug);
// flyCam.setEnabled(false); //flyCam.setEnabled(false);
flyCam.setMoveSpeed(50); flyCam.setMoveSpeed(50);
// ChaseCamera chaseCamera=new ChaseCamera(cam, inputManager); // ChaseCamera chaseCamera=new ChaseCamera(cam, inputManager);
// chaseCamera.setLookAtOffset(Vector3f.UNIT_Y.mult(4)); // chaseCamera.setLookAtOffset(Vector3f.UNIT_Y.mult(4));
// model.addControl(chaseCamera); // model.addControl(chaseCamera);
inputManager.addListener(new ActionListener() { inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) { public void onAction(String name, boolean isPressed, float tpf) {
if(name.equals("toggle") && isPressed){ if (name.equals("toggle") && isPressed) {
bulletAppState.setEnabled(!bulletAppState.isEnabled()); ragdoll.setControl(false);
} }
if (name.equals("shoot") && !isPressed) { if (name.equals("shoot") && !isPressed) {
Geometry bulletg = new Geometry("bullet", bullet); Geometry bulletg = new Geometry("bullet", bullet);
bulletg.setMaterial(matBullet); bulletg.setMaterial(matBullet);
bulletg.setLocalTranslation(cam.getLocation()); bulletg.setLocalTranslation(cam.getLocation());
// RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1); // RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 20); RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 50);
bulletNode.setLinearVelocity(cam.getDirection().mult(80)); bulletNode.setLinearVelocity(cam.getDirection().mult(80));
bulletg.addControl(bulletNode); bulletg.addControl(bulletNode);
rootNode.attachChild(bulletg); rootNode.attachChild(bulletg);
getPhysicsSpace().add(bulletNode); getPhysicsSpace().add(bulletNode);
} }
} }
}, "toggle", "shoot"); }, "toggle", "shoot");
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
}
@Override
public void simpleUpdate(float tpf) {
} }
private void setupLight() { private void setupLight() {
DirectionalLight dl = new DirectionalLight(); DirectionalLight dl = new DirectionalLight();
@ -166,37 +168,29 @@ public class TestBoneRagdoll extends SimpleApplication {
rootNode.addLight(dl); rootNode.addLight(dl);
} }
private PhysicsSpace getPhysicsSpace(){ private PhysicsSpace getPhysicsSpace() {
return bulletAppState.getPhysicsSpace(); return bulletAppState.getPhysicsSpace();
} }
Material mat; Material mat;
Material mat3; Material mat3;
private static final Sphere bullet;
private static final Sphere bullet;
private static final SphereCollisionShape bulletCollisionShape; private static final SphereCollisionShape bulletCollisionShape;
static { static {
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);
} }
public void initMaterial() { public void initMaterial() {
matBullet = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md"); matBullet = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG"); TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
key2.setGenerateMips(true); key2.setGenerateMips(true);
Texture tex2 = assetManager.loadTexture(key2); Texture tex2 = assetManager.loadTexture(key2);
matBullet.setTexture("ColorMap", tex2); matBullet.setTexture("ColorMap", tex2);
} }
protected void initCrossHairs() { protected void initCrossHairs() {
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt"); guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText ch = new BitmapText(guiFont, false); BitmapText ch = new BitmapText(guiFont, false);
@ -207,4 +201,25 @@ public class TestBoneRagdoll extends SimpleApplication {
settings.getHeight() / 2 + ch.getLineHeight() / 2, 0); settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
guiNode.attachChild(ch); guiNode.attachChild(ch);
} }
public void collide(Bone bone, PhysicsCollisionObject object) {
if (!ragdoll.hasControl()) {
bulletTime();
ragdoll.setControl(true);
}
}
private void bulletTime() {
speed = 0.1f;
elTime = 0;
}
float elTime = 0;
@Override
public void simpleUpdate(float tpf) {
elTime += tpf;
if (elTime > 0.05f && speed < 1.0f) {
speed += tpf * 8;
}
}
} }

Loading…
Cancel
Save