@ -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 , 2 0) ;
RigidBodyControl bulletNode = new RigidBodyControl ( bulletCollisionShape , 5 0) ;
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 ;
}
}
}