Ragdoll :
- 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
This commit is contained in:
parent
0a82e1ee11
commit
916f4f203c
@ -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,13 +67,14 @@ 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){
|
||||
public static void main(String[] args) {
|
||||
TestBoneRagdoll app = new TestBoneRagdoll();
|
||||
app.start();
|
||||
}
|
||||
@ -79,85 +82,84 @@ public class TestBoneRagdoll extends SimpleApplication {
|
||||
public void simpleInitApp() {
|
||||
initCrossHairs();
|
||||
initMaterial();
|
||||
|
||||
|
||||
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.setEnabled(true);
|
||||
stateManager.attach(bulletAppState);
|
||||
// bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
||||
// bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
||||
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
||||
setupLight();
|
||||
|
||||
model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
|
||||
// model.setLocalTranslation(5,5,5);
|
||||
// model.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
|
||||
// model.setLocalTranslation(5,5,5);
|
||||
// model.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
|
||||
|
||||
//debug view
|
||||
AnimControl control= model.getControl(AnimControl.class);
|
||||
AnimControl control = model.getControl(AnimControl.class);
|
||||
SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton());
|
||||
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
|
||||
mat2.setColor("Color", ColorRGBA.Green);
|
||||
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.setEnabled(true);
|
||||
// ragdoll.attachDebugShape(assetManager);
|
||||
|
||||
ragdoll = new RagdollControl();
|
||||
ragdoll.addCollisionListener(this);
|
||||
// ragdoll.setEnabled(true);
|
||||
// ragdoll.attachDebugShape(assetManager);
|
||||
|
||||
// ragdoll.setSpatial(model);
|
||||
// ragdoll.setPhysicsSpace(getPhysicsSpace());
|
||||
// control.setRagdoll(ragdoll);
|
||||
|
||||
|
||||
model.addControl(ragdoll);
|
||||
getPhysicsSpace().add(ragdoll);
|
||||
speed = 1f;
|
||||
|
||||
rootNode.attachChild(model);
|
||||
rootNode.attachChild(skeletonDebug);
|
||||
// flyCam.setEnabled(false);
|
||||
// rootNode.attachChild(skeletonDebug);
|
||||
//flyCam.setEnabled(false);
|
||||
flyCam.setMoveSpeed(50);
|
||||
// ChaseCamera chaseCamera=new ChaseCamera(cam, inputManager);
|
||||
// chaseCamera.setLookAtOffset(Vector3f.UNIT_Y.mult(4));
|
||||
// model.addControl(chaseCamera);
|
||||
|
||||
|
||||
inputManager.addListener(new ActionListener() {
|
||||
|
||||
public void onAction(String name, boolean isPressed, float tpf) {
|
||||
if(name.equals("toggle") && isPressed){
|
||||
bulletAppState.setEnabled(!bulletAppState.isEnabled());
|
||||
}
|
||||
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);
|
||||
bulletNode.setLinearVelocity(cam.getDirection().mult(80));
|
||||
bulletg.addControl(bulletNode);
|
||||
rootNode.attachChild(bulletg);
|
||||
getPhysicsSpace().add(bulletNode);
|
||||
|
||||
|
||||
}
|
||||
if (name.equals("toggle") && isPressed) {
|
||||
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, 50);
|
||||
bulletNode.setLinearVelocity(cam.getDirection().mult(80));
|
||||
bulletg.addControl(bulletNode);
|
||||
rootNode.attachChild(bulletg);
|
||||
getPhysicsSpace().add(bulletNode);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}, "toggle", "shoot");
|
||||
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
|
||||
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void simpleUpdate(float tpf) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void setupLight() {
|
||||
DirectionalLight dl = new DirectionalLight();
|
||||
@ -166,37 +168,29 @@ public class TestBoneRagdoll extends SimpleApplication {
|
||||
rootNode.addLight(dl);
|
||||
}
|
||||
|
||||
private PhysicsSpace getPhysicsSpace(){
|
||||
private PhysicsSpace getPhysicsSpace() {
|
||||
return bulletAppState.getPhysicsSpace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Material mat;
|
||||
|
||||
Material mat3;
|
||||
|
||||
private static final Sphere bullet;
|
||||
private static final Sphere bullet;
|
||||
private static final SphereCollisionShape bulletCollisionShape;
|
||||
|
||||
static {
|
||||
bullet = new Sphere(32, 32, 0.4f, true, false);
|
||||
bullet.setTextureMode(TextureMode.Projected);
|
||||
bulletCollisionShape = new SphereCollisionShape(0.4f);
|
||||
bulletCollisionShape = new SphereCollisionShape(0.4f);
|
||||
}
|
||||
|
||||
|
||||
public void initMaterial() {
|
||||
|
||||
|
||||
matBullet = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
|
||||
TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
|
||||
key2.setGenerateMips(true);
|
||||
Texture tex2 = assetManager.loadTexture(key2);
|
||||
matBullet.setTexture("ColorMap", tex2);
|
||||
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…
x
Reference in New Issue
Block a user