|
|
@ -48,6 +48,7 @@ import com.jme3.input.KeyInput; |
|
|
|
import com.jme3.input.MouseInput; |
|
|
|
import com.jme3.input.MouseInput; |
|
|
|
import com.jme3.input.controls.ActionListener; |
|
|
|
import com.jme3.input.controls.ActionListener; |
|
|
|
import com.jme3.input.controls.KeyTrigger; |
|
|
|
import com.jme3.input.controls.KeyTrigger; |
|
|
|
|
|
|
|
import com.jme3.input.controls.MouseAxisTrigger; |
|
|
|
import com.jme3.input.controls.MouseButtonTrigger; |
|
|
|
import com.jme3.input.controls.MouseButtonTrigger; |
|
|
|
import com.jme3.light.AmbientLight; |
|
|
|
import com.jme3.light.AmbientLight; |
|
|
|
import com.jme3.light.DirectionalLight; |
|
|
|
import com.jme3.light.DirectionalLight; |
|
|
@ -73,7 +74,7 @@ public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisi |
|
|
|
Material matBullet; |
|
|
|
Material matBullet; |
|
|
|
Node model; |
|
|
|
Node model; |
|
|
|
RagdollControl ragdoll; |
|
|
|
RagdollControl ragdoll; |
|
|
|
float timer = 0; |
|
|
|
float bulletSize = 1f; |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
TestBoneRagdoll app = new TestBoneRagdoll(); |
|
|
|
TestBoneRagdoll app = new TestBoneRagdoll(); |
|
|
@ -135,10 +136,18 @@ public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisi |
|
|
|
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) { |
|
|
|
ragdoll.setControl(false); |
|
|
|
ragdoll.setControl(false); |
|
|
|
|
|
|
|
model.setLocalTranslation(0, 0, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
if (name.equals("shoot") && isPressed) { |
|
|
|
if (name.equals("bullet+") && isPressed) { |
|
|
|
timer = 0; |
|
|
|
bulletSize += 0.1f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (name.equals("bullet-") && isPressed) { |
|
|
|
|
|
|
|
bulletSize -= 0.1f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (name.equals("shoot") && isPressed) { |
|
|
|
|
|
|
|
// bulletSize = 0;
|
|
|
|
} |
|
|
|
} |
|
|
|
if (name.equals("stop") && isPressed) { |
|
|
|
if (name.equals("stop") && isPressed) { |
|
|
|
bulletAppState.setEnabled(!bulletAppState.isEnabled()); |
|
|
|
bulletAppState.setEnabled(!bulletAppState.isEnabled()); |
|
|
@ -148,10 +157,10 @@ public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisi |
|
|
|
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()); |
|
|
|
bulletg.setLocalScale(timer); |
|
|
|
bulletg.setLocalScale(bulletSize); |
|
|
|
bulletCollisionShape = new SphereCollisionShape(timer); |
|
|
|
bulletCollisionShape = new SphereCollisionShape(bulletSize); |
|
|
|
// RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
|
|
|
|
// RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
|
|
|
|
RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, timer * 10); |
|
|
|
RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, bulletSize * 10); |
|
|
|
bulletNode.setCcdMotionThreshold(0.001f); |
|
|
|
bulletNode.setCcdMotionThreshold(0.001f); |
|
|
|
bulletNode.setLinearVelocity(cam.getDirection().mult(80)); |
|
|
|
bulletNode.setLinearVelocity(cam.getDirection().mult(80)); |
|
|
|
bulletg.addControl(bulletNode); |
|
|
|
bulletg.addControl(bulletNode); |
|
|
@ -161,10 +170,13 @@ public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisi |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, "toggle", "shoot","stop"); |
|
|
|
}, "toggle", "shoot", "stop", "bullet+", "bullet-"); |
|
|
|
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)); |
|
|
|
inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_H)); |
|
|
|
inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_H)); |
|
|
|
|
|
|
|
inputManager.addMapping("bullet-", new KeyTrigger(KeyInput.KEY_COMMA)); |
|
|
|
|
|
|
|
inputManager.addMapping("bullet+", new KeyTrigger(KeyInput.KEY_PERIOD)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -329,14 +341,28 @@ public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisi |
|
|
|
elTime = 0; |
|
|
|
elTime = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
float elTime = 0; |
|
|
|
float elTime = 0; |
|
|
|
|
|
|
|
boolean forward = true; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void simpleUpdate(float tpf) { |
|
|
|
public void simpleUpdate(float tpf) { |
|
|
|
// System.out.println(model.getLocalTranslation());
|
|
|
|
// System.out.println(model.getLocalTranslation());
|
|
|
|
elTime += tpf; |
|
|
|
// elTime += tpf;
|
|
|
|
if (elTime > 0.05f && speed < 1.0f) { |
|
|
|
// if (elTime > 0.05f && speed < 1.0f) {
|
|
|
|
speed += tpf * 8; |
|
|
|
// speed += tpf * 8;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// timer += tpf;
|
|
|
|
|
|
|
|
fpsText.setText("Bullet Size: " + bulletSize); |
|
|
|
|
|
|
|
if (!ragdoll.hasControl()) { |
|
|
|
|
|
|
|
if (model.getLocalTranslation().getZ() < -10) { |
|
|
|
|
|
|
|
forward = true; |
|
|
|
|
|
|
|
} else if (model.getLocalTranslation().getZ() > 10) { |
|
|
|
|
|
|
|
forward = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (forward) { |
|
|
|
|
|
|
|
model.move(-tpf, 0, tpf); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
model.move(tpf, 0, -tpf); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
timer += tpf; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|