- 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. 63
      engine/src/test/jme3test/bullet/TestBoneRagdoll.java

@ -169,12 +169,16 @@ public abstract class PhysicsCollisionObject implements Savable {
public Spatial attachDebugShape(AssetManager manager) {
debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
// debugMaterialBlue.getAdditionalRenderState().setDepthTest(false);
debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
debugMaterialGreen.setColor("Color", ColorRGBA.Green);
// debugMaterialGreen.getAdditionalRenderState().setDepthTest(false);
debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
debugMaterialRed.setColor("Color", ColorRGBA.Red);
// debugMaterialRed.getAdditionalRenderState().setDepthTest(false);
debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
// debugMaterialYellow.getAdditionalRenderState().setDepthTest(false);
debugArrow = new Arrow(Vector3f.UNIT_XYZ);
debugArrowGeom = new Geometry("DebugArrow", debugArrow);
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
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package jme3test.bullet;
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.Bone;
import com.jme3.animation.LoopMode;
import com.jme3.bullet.BulletAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.TextureKey;
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.control.RagdollControl;
import com.jme3.bullet.control.RigidBodyControl;
@ -50,10 +54,8 @@ import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.debug.SkeletonDebugger;
@ -65,11 +67,12 @@ import com.jme3.texture.Texture;
* PHYSICS RAGDOLLS ARE NOT WORKING PROPERLY YET!
* @author normenhansen
*/
public class TestBoneRagdoll extends SimpleApplication {
public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisionListener {
private BulletAppState bulletAppState;
Material matBullet;
Node model;
RagdollControl ragdoll;
public static void main(String[] args) {
TestBoneRagdoll app = new TestBoneRagdoll();
@ -103,10 +106,16 @@ public class TestBoneRagdoll extends SimpleApplication {
mat2.getAdditionalRenderState().setDepthTest(false);
skeletonDebug.setMaterial(mat2);
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
RagdollControl ragdoll = new RagdollControl();
ragdoll = new RagdollControl();
ragdoll.addCollisionListener(this);
// ragdoll.setEnabled(true);
// ragdoll.attachDebugShape(assetManager);
@ -119,7 +128,7 @@ public class TestBoneRagdoll extends SimpleApplication {
speed = 1f;
rootNode.attachChild(model);
rootNode.attachChild(skeletonDebug);
// rootNode.attachChild(skeletonDebug);
//flyCam.setEnabled(false);
flyCam.setMoveSpeed(50);
// ChaseCamera chaseCamera=new ChaseCamera(cam, inputManager);
@ -130,14 +139,14 @@ public class TestBoneRagdoll extends SimpleApplication {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("toggle") && isPressed) {
bulletAppState.setEnabled(!bulletAppState.isEnabled());
ragdoll.setControl(false);
}
if (name.equals("shoot") && !isPressed) {
Geometry bulletg = new Geometry("bullet", bullet);
bulletg.setMaterial(matBullet);
bulletg.setLocalTranslation(cam.getLocation());
// 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));
bulletg.addControl(bulletNode);
rootNode.attachChild(bulletg);
@ -152,13 +161,6 @@ public class TestBoneRagdoll extends SimpleApplication {
}
@Override
public void simpleUpdate(float tpf) {
}
private void setupLight() {
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
@ -169,13 +171,8 @@ public class TestBoneRagdoll extends SimpleApplication {
private PhysicsSpace getPhysicsSpace() {
return bulletAppState.getPhysicsSpace();
}
Material mat;
Material mat3;
private static final Sphere bullet;
private static final SphereCollisionShape bulletCollisionShape;
@ -185,7 +182,6 @@ public class TestBoneRagdoll extends SimpleApplication {
bulletCollisionShape = new SphereCollisionShape(0.4f);
}
public void initMaterial() {
matBullet = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
@ -195,8 +191,6 @@ public class TestBoneRagdoll extends SimpleApplication {
matBullet.setTexture("ColorMap", tex2);
}
protected void initCrossHairs() {
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText ch = new BitmapText(guiFont, false);
@ -207,4 +201,25 @@ public class TestBoneRagdoll extends SimpleApplication {
settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
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