@ -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 ( ) ;
}
@ -87,28 +90,34 @@ public class TestBoneRagdoll extends SimpleApplication {
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());
@ -119,8 +128,8 @@ public class TestBoneRagdoll extends SimpleApplication {
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));
@ -129,22 +138,22 @@ public class TestBoneRagdoll extends SimpleApplication {
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 , 2 0) ;
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 , 5 0) ;
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 ) ) ;
@ -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 ( ) ) ;
@ -166,16 +168,11 @@ 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 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 ;
}
}
}