I can run the example with the robot and pressing spacebar then it fires the bullet with an effect in the TestWalkingChar. Now I want it to work with my scene with jmeplanet and a UFO that should be able to fire bullet / bomb with effect like in the TestWalkingChar. But when I add the functionality and start the app and press spacebar, nothing get rendered. Could you know what I’m doing wrong?
[java]public class UFOSpaceWorld extends SimpleApplication implements AnalogListener,
ActionListener, PhysicsCollisionListener { //
boolean player2update = false;
private PlanetAppState planetAppState;
private Geometry mark;
private Node ufoNode;
private RigidBodyControl ufoControl;
private RigidBodyControl ufoControl2;
private Node ufoNode2;
private CylinderCollisionShape shape;
private BoundingBox bv;
private RigidBodyControl jumpGateControl;
private RigidBodyControl jumpGateControl2;
private AnimChannel channel;
private AnimControl control;
private Node spacemanNode;
private RigidBodyControl spacemanControl;
private Node alien;
private String serverName = "localhost";
private int portNumber = 6143;
private RigidBodyControl alienControl;
Spatial jumpgateSpatial;
CameraNode camNode;
ChaseCamera chaseCam;
Planet moon;
static UFOSpaceWorld app;
Client myClient = null;
Vector3f ufoDirection = new Vector3f();
Vector3f ufoDirection2 = new Vector3f();
Vector3f ufoCamDir2 = new Vector3f();
Vector3f gate2vector = new Vector3f(10f, 10f, 1598300f);
Vector3f gate1vector = new Vector3f(10f, 10f, 1098300f);
private BulletAppState bulletAppState;
private boolean left = false, right = false, up = false, down = false,
forward = false, backward = false, attack = false, rotate = false,
pitch1 = false, yaw1 = false, roll1 = false;
private long starttime = 0;
private long playtime = 0;
public void collision(PhysicsCollisionEvent event) {
if (event.getObjectA() instanceof BombControl) {
final Spatial node = event.getNodeA();
/*effect.killAllParticles();
effect.setLocalTranslation(node.getLocalTranslation());
effect.emitAllParticles();*/
} else if (event.getObjectB() instanceof BombControl) {
final Spatial node = event.getNodeB();
/*effect.killAllParticles();
effect.setLocalTranslation(node.getLocalTranslation());
effect.emitAllParticles();*/
}
}
public Vector3f getUfoCamDir2() {
return ufoCamDir2;
}
public void setUfoCamDir2(Vector3f ufoCamDir2) {
this.ufoCamDir2 = ufoCamDir2;
}
public Vector3f getUfoDirection2() {
return ufoDirection2;
}
public void setUfoDirection2(Vector3f ufoDirection2) {
this.ufoDirection2 = ufoDirection2;
}
private void setupChaseCamera() {
flyCam.setEnabled(false);
chaseCam = new ChaseCamera(cam, ufoNode, inputManager);
chaseCam.setDefaultDistance(2237);
}
@Override
public void destroy() {
// custom code
if (myClient != null) {
myClient.close();
}
super.destroy();
}
public static void main(String[] args) {
AppSettings settings = new AppSettings(true);
settings.setResolution(1280, 1024);
settings.setSettingsDialogImage("Interface/spacesplash.png");
settings.setTitle("Space World");
app = new UFOSpaceWorld();
if (args.length > 0) {
app.serverName = args[0];
}
if (args.length > 1) {
app.portNumber = new Integer(args[0]);
}
app.setSettings(settings);
app.start();
}
@Override
public void simpleInitApp() {
playtime = 0;
starttime = System.currentTimeMillis();
this.setDisplayStatView(false);
setDisplayFps(false);
java.util.logging.Logger.getLogger("com.jme3").setLevel(
java.util.logging.Level.SEVERE);
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(false);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-.1f, 0f, -1f));
sun.setColor(new ColorRGBA(0.75f, 0.75f, 0.75f, 1.0f));
rootNode.addLight(sun);
// Add sky
Node sceneNode = new Node("Scene");
sceneNode.attachChild(Utility.createSkyBox(this.getAssetManager(),
"Textures/blue-glow-1024.dds"));
rootNode.attachChild(sceneNode);
// Create collision test mark
Sphere sphere = new Sphere(30, 30, 5f);
mark = new Geometry("mark", sphere);
Material mark_mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mark_mat.setColor("Color", ColorRGBA.Red);
mark.setMaterial(mark_mat);
// Add planet app state
planetAppState = new PlanetAppState(rootNode, sun);
stateManager.attach(planetAppState);
// Add planet
FractalDataSource planetDataSource = new FractalDataSource(4);
planetDataSource.setHeightScale(900f);
Planet planet = Utility.createEarthLikePlanet(getAssetManager(),
293710.0f, null, planetDataSource);
planet.addControl(new RigidBodyControl(new PlanetCollisionShape(planet
.getLocalTranslation(), planet.getRadius(), planetDataSource),
0f));
planetAppState.addPlanet(planet);
rootNode.attachChild(planet);
bulletAppState.getPhysicsSpace().add(planet);
// Add moon
FractalDataSource moonDataSource = new FractalDataSource(5);
moonDataSource.setHeightScale(300f);
moon = Utility.createMoonLikePlanet(getAssetManager(), 50000,
moonDataSource);
moon.setLocalTranslation(new Vector3f(10f, 10f, 1505000f));
RigidBodyControl moonControl = new RigidBodyControl(
new PlanetCollisionShape(moon.getLocalTranslation(),
moon.getRadius(), moonDataSource), 0f);
moon.addControl(moonControl);
planetAppState.addPlanet(moon);
// add saucer
addSaucer();
jumpgateSpatial = assetManager.loadModel("JumpGate.j3o");
jumpgateSpatial.setLocalScale(10000f);
BoundingBox jbv = (BoundingBox) jumpgateSpatial.getWorldBound();
CylinderCollisionShape jshape = new CylinderCollisionShape(
new Vector3f(jbv.getXExtent(), jbv.getYExtent(),
jbv.getZExtent()), 1);
;
jumpGateControl = new RigidBodyControl(jshape, 0);
jumpgateSpatial.addControl(jumpGateControl);
jumpGateControl.setMass(0f);
jumpGateControl.setPhysicsLocation(gate1vector);
jumpGateControl.setPhysicsRotation(new Quaternion().fromAngleAxis(
90 * FastMath.DEG_TO_RAD, new Vector3f(1, 0, 0)));
Spatial jumpgateSpatial2 = assetManager.loadModel("JumpGate.j3o");
jumpgateSpatial2.setLocalScale(10000f);
BoundingBox jbv2 = (BoundingBox) jumpgateSpatial2.getWorldBound();
CylinderCollisionShape jshape2 = new CylinderCollisionShape(
new Vector3f(jbv2.getXExtent(), jbv2.getYExtent(),
jbv2.getZExtent()), 1);
;
Quaternion roll180 = new Quaternion();
roll180.fromAngleAxis(FastMath.PI / 2, new Vector3f(0, 1, 0));
jumpGateControl2 = new RigidBodyControl(jshape2, 0);
jumpgateSpatial2.addControl(jumpGateControl2);
jumpGateControl2.setMass(0f);
jumpGateControl2.setPhysicsLocation(gate2vector);
jumpGateControl2.setPhysicsRotation(new Quaternion().fromAngleAxis(
90 * FastMath.DEG_TO_RAD, new Vector3f(1, 0, 0)));
Spatial spaceStationSpatial = assetManager
.loadModel("SpaceStation.blend");
spaceStationSpatial.setLocalScale(3500f);
BoundingBox sbv = (BoundingBox) spaceStationSpatial.getWorldBound();
CompoundCollisionShape shape3 = new CompoundCollisionShape();
shape3.addChildShape(
new CylinderCollisionShape(new Vector3f(sbv.getXExtent(), sbv
.getYExtent(), sbv.getZExtent()), 1), new Vector3f(0,
0, 0));
RigidBodyControl spaceStationControl = new RigidBodyControl(shape3, 0);
spaceStationSpatial.addControl(spaceStationControl);
spaceStationControl.setMass(0f);
spaceStationControl.setPhysicsLocation(new Vector3f(10000f, -10f,
705000f));
BlenderKey blenderKey = new BlenderKey(
"objects/creatures/alien/alienmodel.blend");
Spatial alien = (Spatial) assetManager.loadModel(blenderKey);
alien.setLocalScale(20 * 2000f);
alienControl = new RigidBodyControl(3 * 500f);
alien.addControl(alienControl);
alienControl.setPhysicsLocation(new Vector3f(11000f, -50f, 755000f));
//
BlenderKey blenderKey2 = new BlenderKey(
"objects/creatures/spaceman/man.mesh.xml");
Spatial man = (Spatial) assetManager.loadModel(blenderKey2);
man.setLocalScale(200f);
spacemanControl = new RigidBodyControl(4 * 500f);
man.addControl(spacemanControl);
spacemanControl
.setPhysicsLocation(new Vector3f(10700f, -590f, 775000f));
createNewOtoBot();
BulletAppState bas = app.getStateManager().getState(
BulletAppState.class);
bas.getPhysicsSpace().addAll(spaceStationSpatial);
bas.getPhysicsSpace().addAll(man);
bas.getPhysicsSpace().addAll(alien);
bas.getPhysicsSpace().addAll(jumpgateSpatial);
bas.getPhysicsSpace().addAll(jumpgateSpatial2);
bas.getPhysicsSpace().addAll(moon);
bas.getPhysicsSpace().addAll(planet);
bas.getPhysicsSpace().setGravity(new Vector3f(0, 0, 0));
prepareBullet();
// rootNode.attachChild(man);
// rootNode.attachChild(alien);
rootNode.attachChild(spaceStationSpatial);
rootNode.attachChild(jumpgateSpatial);
rootNode.attachChild(jumpgateSpatial2);
rootNode.attachChild(moon);
setupChaseCamera();
registerInput();
try {
System.out.println("connecting to " + serverName);
myClient = Network.connectToServer(serverName, portNumber);
System.out.println("connected to " + serverName);
// Serializer.registerClass(AutoControlMessage.class);
Serializer.registerClass(ActionMessage.class);
ClientListener cl = new ClientListener(app, myClient);
myClient.addMessageListener(cl, ActionMessage.class);// ,
// AutoControlMessage.class);
myClient.addMessageListener(cl, AutoControlMessage.class);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (myClient != null) {
myClient.start();
System.out.println("myClient started");
} else {
System.out.println("myClient == null " + serverName);
}
}
public void clientConnected(Client c) {
System.out.println("clientConnected ");
}
private PhysicsSpace getPhysicsSpace() {
return bulletAppState.getPhysicsSpace();
}
public void addSaucer() {
ufoNode = (Node) assetManager.loadModel("usaucer_v01.j3o");
ufoNode.setLocalScale(200f);
BoundingBox bv = (BoundingBox) ufoNode.getWorldBound();
CylinderCollisionShape shape = new CylinderCollisionShape(new Vector3f(
bv.getXExtent(), bv.getYExtent(), bv.getZExtent()), 1);
ufoControl = new RigidBodyControl(shape, 500f);
ufoNode.addControl(ufoControl);
System.out.println("addSaucer 200:");
ufoControl.setPhysicsLocation(new Vector3f(10850f, -5979f, 785020f));
BulletAppState bas = app.getStateManager().getState(
BulletAppState.class);
bas.getPhysicsSpace().addAll(ufoNode);
rootNode.attachChild(ufoNode);
}
public void addNewSaucer() {
ufoNode2 = (Node) assetManager.loadModel("usaucer_v01.j3o");
ufoNode2.setLocalScale(700f);
bv = (BoundingBox) ufoNode2.getWorldBound();
shape = new CylinderCollisionShape(new Vector3f(bv.getXExtent(),
bv.getYExtent(), bv.getZExtent()), 1);
ufoControl2 = new RigidBodyControl(shape, 500f);
ufoNode2.addControl(ufoControl2);
ufoControl2.setPhysicsLocation(new Vector3f(10850f, -5979f, 785020f));
ufoControl2.setGravity(Vector3f.ZERO);
ufoControl2.setLinearVelocity(Vector3f.ZERO);
ufoControl2.clearForces();
BulletAppState bas = app.getStateManager().getState(
BulletAppState.class);
bas.getPhysicsSpace().addAll(ufoNode2);
rootNode.attachChild(ufoNode2);
}
public void createNewOtoBot() {
BlenderKey otoblenderKey = new BlenderKey("Models/Oto/Oto.mesh.xml");
Spatial otoBot = (Spatial) assetManager.loadModel(otoblenderKey);
otoBot.setLocalScale(600f);
RigidBodyControl otoControl = new RigidBodyControl(30 * 500f);
otoBot.addControl(otoControl);
otoControl.setPhysicsLocation(new Vector3f(10800f, -579f, 785000f));
control = otoBot.getControl(AnimControl.class);
channel = control.createChannel();
for (String anim : control.getAnimationNames())
System.out.println("otoBot can:" + anim);
channel.setAnim("pull");
BulletAppState bas = app.getStateManager().getState(
BulletAppState.class);
bas.getPhysicsSpace().addAll(otoBot);
rootNode.attachChild(otoBot);
}
public void registerInput() {
inputManager.addMapping("moveForward", new KeyTrigger(keyInput.KEY_UP),
new KeyTrigger(keyInput.KEY_W));
inputManager.addMapping("moveBackward", new KeyTrigger(
keyInput.KEY_DOWN), new KeyTrigger(keyInput.KEY_S));
inputManager.addMapping("moveRight",
new KeyTrigger(keyInput.KEY_RIGHT), new KeyTrigger(
keyInput.KEY_D));
inputManager.addMapping("moveLeft", new KeyTrigger(keyInput.KEY_LEFT),
new KeyTrigger(keyInput.KEY_A));
inputManager.addMapping("moveUp", new KeyTrigger(keyInput.KEY_E));
inputManager.addMapping("startServer", new KeyTrigger(keyInput.KEY_M));
inputManager.addMapping("moveDown", new KeyTrigger(keyInput.KEY_C));
inputManager.addMapping("pitch1", new KeyTrigger(keyInput.KEY_P));
inputManager.addMapping("roll1", new KeyTrigger(keyInput.KEY_R));
inputManager.addMapping("yaw1", new KeyTrigger(keyInput.KEY_Y));
inputManager.addMapping("toggleRotate", new MouseButtonTrigger(
MouseInput.BUTTON_LEFT));
inputManager.addMapping("rotateRight", new MouseAxisTrigger(
MouseInput.AXIS_X, true));
inputManager.addMapping("rotateLeft", new MouseAxisTrigger(
MouseInput.AXIS_X, false));
inputManager.addMapping("rotateUp", new MouseAxisTrigger(
MouseInput.AXIS_Y, true));
inputManager.addMapping("rotateDown", new MouseAxisTrigger(
MouseInput.AXIS_Y, false));
inputManager.addListener(this, "moveForward", "moveBackward",
"moveRight", "moveLeft", "moveUp", "moveDown", "pitch1",
"roll1", "yaw1");
inputManager.addListener(this, "rotateRight", "rotateLeft", "rotateUp",
"rotateDown", "toggleRotate", "startServer");
// Toggle mouse cursor
inputManager.addMapping("TOGGLE_CURSOR", new MouseButtonTrigger(
MouseInput.BUTTON_LEFT), new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(actionListener, "TOGGLE_CURSOR");
// Toggle wireframe
inputManager.addMapping("TOGGLE_WIREFRAME", new KeyTrigger(
KeyInput.KEY_T));
inputManager.addListener(actionListener, "TOGGLE_WIREFRAME");
// Collision test
inputManager.addMapping("COLLISION_TEST", new MouseButtonTrigger(
MouseInput.BUTTON_RIGHT));
inputManager.addListener(actionListener, "COLLISION_TEST");
inputManager
.addMapping("CharShoot", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(this, "CharShoot");
}
public void toggleToFullscreen() {
GraphicsDevice device = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode[] modes = device.getDisplayModes();
int i = 0; // note: there are usually several, let's pick the first
settings.setResolution(modes[i].getWidth(), modes[i].getHeight());
settings.setFrequency(modes[i].getRefreshRate());
settings.setBitsPerPixel(modes[i].getBitDepth());
settings.setFullscreen(device.isFullScreenSupported());
app.setSettings(settings);
app.restart(); // restart the context to apply changes
}
long time = 0;
public void simpleUpdatePlayer2(float tpf) {
System.out.println("LOOP simpleUpdatePlayer2 player 2");
int speed = 8000 * 25;// *
Vector3f camDir = cam.getDirection().clone().multLocal(speed * tpf);
Vector3f camUp = cam.getUp().clone().mult(speed * tpf);
Quaternion roll = new Quaternion();
camDir.y = 0;
ufoDirection2.set(0, 0, 0);
// ufoControl2.setLinearVelocity(Vector3f.ZERO);
if (doRoll == true) {
System.out.println("doRoll == true");
roll.fromAngleAxis(FastMath.QUARTER_PI / 3, cam.getDirection());
ufoDirection2.set(cam.getLeft()).multLocal(-speed * tpf);
}
if (doRoll2 == true) {
System.out.println("doRoll2 == true");
roll.fromAngleAxis(-FastMath.QUARTER_PI / 3, cam.getDirection());
ufoDirection2.set(cam.getLeft()).multLocal(speed * tpf);
}
if (doRoll3 == true) {
System.out.println("doRoll3 == true");
roll.fromAngleAxis(0, cam.getDirection());
ufoDirection2.addLocal(camUp);
}
if (doRoll4 == true) {
System.out.println("doRoll4 == true");
roll.fromAngleAxis(0, cam.getDirection());
ufoDirection2.addLocal(cam.getUp().multLocal(-speed * tpf));
}
if (doRoll5 == true) {
System.out.println("doRoll5 == true");
roll.fromAngleAxis(0, cam.getDirection());
ufoDirection2.set(camDir);
}
if (doRoll6 == true) {
System.out.println("doRoll6 == true");
roll.fromAngleAxis(0, cam.getDirection());
ufoDirection2.set(camDir.multLocal(-1f));
}
/*
* if (up) { roll.fromAngleAxis(0, cam.getDirection());
* ufoDirection.addLocal(camUp); } if (down) { roll.fromAngleAxis(0,
* cam.getDirection());
* ufoDirection.addLocal(cam.getUp().multLocal(-speed * tpf)); }
*/
if (ufoControl2 == null) {
System.out.println("ufoControl2 == null");
}
ufoControl2.setPhysicsRotation(roll);
ufoControl2.setLinearVelocity(ufoDirection2);
if (System.currentTimeMillis() - time > 1000) {
System.out.println("LOOP BREAK");
ufoDirection2.set(0, 0, 0);
ufoControl2.setLinearVelocity(Vector3f.ZERO);
time = 0;
player2update = false;
}
}
private boolean doRoll2 = false;
private boolean doRoll3 = false;
private boolean doRoll5 = false;
public boolean isDoRoll5() {
return doRoll5;
}
public void setDoRoll5(boolean doRoll5) {
this.doRoll5 = doRoll5;
}
private boolean doRoll6 = false;
public boolean isDoRoll6() {
return doRoll6;
}
public void setDoRoll6(boolean doRoll6) {
this.doRoll6 = doRoll6;
}
public boolean isDoRoll3() {
return doRoll3;
}
public void setDoRoll3(boolean doRoll3) {
this.doRoll3 = doRoll3;
}
private boolean doRoll4 = false;
public boolean isDoRoll4() {
return doRoll4;
}
public void setDoRoll4(boolean doRoll4) {
this.doRoll4 = doRoll4;
}
public boolean isDoRoll2() {
return doRoll2;
}
public void setDoRoll2(boolean doRoll2) {
this.doRoll2 = doRoll2;
}
private boolean doRoll = false;
public boolean isDoRoll() {
return doRoll;
}
public void setDoRoll(boolean doRoll) {
this.doRoll = doRoll;
}
@Override
public void simpleUpdate(float tpf) {
playtime = System.currentTimeMillis() - starttime;
int speed = 25 * 80000;
Vector3f camDir = cam.getDirection().clone().multLocal(speed * tpf);
Vector3f camUp = cam.getUp().clone().mult(speed * tpf);
Quaternion roll = new Quaternion();
Quaternion yaw = new Quaternion();
Quaternion pitch = new Quaternion();
camDir.y = 0;
ufoDirection.set(0, 0, 0);
ufoControl.setLinearVelocity(Vector3f.ZERO);
if (left) {
roll.fromAngleAxis(-FastMath.QUARTER_PI / 3, cam.getDirection());
ufoDirection.set(cam.getLeft().multLocal(speed * tpf));
}
if (right) {
roll.fromAngleAxis(FastMath.QUARTER_PI / 3, cam.getDirection());
ufoDirection.set(cam.getLeft()).multLocal(-speed * tpf);
}
if (up) {
roll.fromAngleAxis(0, cam.getDirection());
ufoDirection.addLocal(camUp);
}
if (down) {
roll.fromAngleAxis(0, cam.getDirection());
ufoDirection.addLocal(cam.getUp().multLocal(-speed * tpf));
}
if (forward) {
roll.fromAngleAxis(0, cam.getDirection());
ufoDirection.set(camDir);
}
if (backward) {
roll.fromAngleAxis(0, cam.getDirection());
ufoDirection.set(camDir.multLocal(-1f));
}
if (pitch1) {
System.out.println("PITCH1");
roll.fromAngleAxis(-FastMath.QUARTER_PI / 2, cam.getDirection()
.cross(Vector3f.UNIT_Y));
}
if (yaw1) {
System.out.println("yaw1");
// pitch.fromAngleAxis(angle, axis)
// roll.fromAngleAxis(-FastMath.QUARTER_PI, );
roll.fromAngles(0, FastMath.QUARTER_PI / 2, 0);
// ufoControl.setP
// ufoControl.setPhysicsLocation(Vector3f.UNIT_Y);
// ufoControl.setPhysicsRotation(roll);
}
if (roll1) {
System.out.println("roll1");
roll.fromAngleAxis(-FastMath.QUARTER_PI / 2, cam.getDirection());
}
ufoControl.setPhysicsRotation(roll);
ufoControl.setLinearVelocity(ufoDirection);
CollisionResults results = new CollisionResults();
// System.out.println("1 #Collisions between" + ufoNode.getName()
// + " and " + jumpgateSpatial.getName() + ": " + results.size());
ufoNode.collideWith((BoundingBox) jumpgateSpatial.getWorldBound(),
results);
// System.out.println("2 #Collisions between" + ufoNode.getName()
// + " and " + jumpgateSpatial.getName() + ": " + results.size());
CollisionResults results2 = new CollisionResults();
// Use the results
if (results.size() > 0 && playtime > 50000) {
System.out.println("playtime" + playtime);
System.out.println("#Collisions between" + ufoNode.getName()
+ " and " + jumpgateSpatial.getName() + ": "
+ results.size());
// how to react when a collision was detected
CollisionResult closest = results.getClosestCollision();
System.out.println("What was hit? "
+ closest.getGeometry().getName());
System.out
.println("Where was it hit? " + closest.getContactPoint());
System.out.println("Distance? " + closest.getDistance());
ufoControl
.setPhysicsLocation(jumpGateControl2.getPhysicsLocation());
System.out.println("Warped");
} else {
// how to react when no collision occured
}
if (results2.size() > 0) {
System.out.println("Number of Collisions between"
+ ufoNode.getName() + " and " + moon.getName() + ": "
+ results2.size());
// how to react when a collision was detected
CollisionResult closest2 = results2.getClosestCollision();
System.out.println("What was hit? "
+ closest2.getGeometry().getName());
System.out.println("Where was it hit? "
+ closest2.getContactPoint());
System.out.println("Distance? " + closest2.getDistance());
}
if (myClient != null) {
Message message = new ActionMessage(1, myClient.getId(), right, 1);
Message message2 = new ActionMessage(2, myClient.getId(), left, 2);
Message message3 = new ActionMessage(2, myClient.getId(), up, 3);
Message message4 = new ActionMessage(2, myClient.getId(), down, 4);
Message message5 = new ActionMessage(2, myClient.getId(), forward,
5);
Message message6 = new ActionMessage(2, myClient.getId(), backward,
6);
if (myClient != null) {
myClient.send(message);
myClient.send(message2);
myClient.send(message3);
myClient.send(message4);
myClient.send(message5);
myClient.send(message6);
}
if (player2update == true) {
System.out.println("simpleUpdatePlayer2 player 2 "
+ message.toString());
time = System.currentTimeMillis();
simpleUpdatePlayer2(tpf);
}
}
}
public boolean isPlayer2update() {
return player2update;
}
public void setPlayer2update(boolean player2update) {
this.player2update = player2update;
}
private void createOto() {
BlenderKey blenderKey = new BlenderKey("Models/Oto/Oto.mesh.xml");
Spatial man = (Spatial) assetManager.loadModel(blenderKey);
man.setLocalTranslation(new Vector3f(69, 15, -60));
man.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(man);
}
public void onAnalog(String name, float value, float tpf) {
if (name.equals("rotateRight") && rotate) {
ufoNode.rotate(0, 1 * tpf, 0);
}
if (name.equals("rotateLeft") && rotate) {
ufoNode.rotate(0, -1 * tpf, 0);
}
if (name.equals("rotateUp") && rotate) {
ufoNode.rotate(0, 0, -1 * tpf);
}
if (name.equals("rotateDown") && rotate) {
ufoNode.rotate(0, 0, 1 * tpf);
}
}
public void onAction(String name, boolean keyPressed, float tpf) {
Message message = new ActionMessage(name, keyPressed);
if (myClient != null) {
myClient.send(message);
}
if (name.equals("moveLeft")) {
if (keyPressed) {
left = true;
} else {
left = false;
}
} else if (name.equals("moveRight")) {
if (keyPressed) {
right = true;
} else {
right = false;
}
} else if (name.equals("moveUp")) {
if (keyPressed) {
up = true;
} else {
up = false;
}
} else if (name.equals("moveDown")) {
if (keyPressed) {
down = true;
} else {
down = false;
}
} else if (name.equals("moveForward")) {
if (keyPressed) {
forward = true;
} else {
forward = false;
}
} else if (name.equals("moveBackward")) {
if (keyPressed) {
backward = true;
} else {
backward = false;
}
}
else if (name.equals("pitch1")) {
if (keyPressed) {
pitch1 = true;
} else {
pitch1 = false;
}
} else if (name.equals("CharShoot") ) { // && !keyPressed) {
System.out.println("CharShoot ");
bulletControl();
}
else if (name.equals("roll1")) {
if (keyPressed) {
roll1 = true;
} else {
roll1 = false;
}
}
else if (name.equals("yaw1")) {
if (keyPressed) {
yaw1 = true;
} else {
yaw1 = false;
}
}
// toggling rotation on or off
if (name.equals("toggleRotate") && keyPressed) {
rotate = true;
inputManager.setCursorVisible(false);
}
if (name.equals("toggleRotate") && !keyPressed) {
rotate = false;
inputManager.setCursorVisible(true);
}
if (name.equals("TOGGLE_CURSOR") && !keyPressed) {
if (inputManager.isCursorVisible()) {
inputManager.setCursorVisible(false);
} else {
inputManager.setCursorVisible(true);
}
}
if (name.equals("TOGGLE_WIREFRAME") && !keyPressed) {
for (Planet planet : planetAppState.getPlanets()) {
planet.toogleWireframe();
}
}
if (name.equals("COLLISION_TEST") && !keyPressed) {
CollisionResults results = new CollisionResults();
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
// Test collision with closest planet's terrain only
planetAppState.getNearestPlanet().getTerrainNode()
.collideWith(ray, results);
System.out.println("----- Collisions? " + results.size() + "-----");
for (int i = 0; i < results.size(); i++) {
// For each hit, we know distance, impact point, name of
// geometry.
float dist = results.getCollision(i).getDistance();
Vector3f pt = results.getCollision(i).getContactPoint();
String hit = results.getCollision(i).getGeometry().getName();
System.out.println("* Collision #" + i);
System.out.println(" You shot " + hit + " at " + pt + ", "
+ dist + " wu away.");
}
if (results.size() > 0) {
// The closest collision point is what was truly hit:
CollisionResult closest = results.getClosestCollision();
// Let's interact - we mark the hit with a red dot.
mark.setLocalTranslation(closest.getContactPoint());
rootNode.attachChild(mark);
} else {
// No hits? Then remove the red mark.
rootNode.detachChild(mark);
}
}
}
Material matRock;
Material matBullet;
Sphere bullet;
SphereCollisionShape bulletCollisionShape;
private void prepareBullet() {
System.out.println("prepareBullet ");
bullet = new Sphere(40*32, 40*32, 40*0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(40*0.4f);
matBullet = new Material(getAssetManager(),
"Common/MatDefs/Misc/Unshaded.j3md");
matBullet.setColor("Color", ColorRGBA.Green);
matBullet.setColor("GlowColor", ColorRGBA.Green);
getPhysicsSpace().addCollisionListener(this);
}
private void bulletControl() {
System.out.println("bulletControl ");
// shootingChannel.setAnim("Dodge", 0.1f);
// shootingChannel.setLoopMode(LoopMode.DontLoop);
Geometry bulletg = new Geometry("bullet", bullet);
bulletg.setMaterial(matBullet);
bulletg.setShadowMode(ShadowMode.CastAndReceive);
bulletg.setLocalTranslation(ufoControl.getPhysicsLocation().add(
cam.getDirection().mult(5)));
RigidBodyControl bulletControl = new BombControl(bulletCollisionShape,
1);
bulletControl.setCcdMotionThreshold(0.1f);
bulletControl.setLinearVelocity(cam.getDirection().mult(80));
bulletg.addControl(bulletControl);
rootNode.attachChild(bulletg);
getPhysicsSpace().add(bulletControl);
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean pressed, float tpf) {
if (name.equals("TOGGLE_CURSOR") && !pressed) {
if (inputManager.isCursorVisible()) {
inputManager.setCursorVisible(false);
} else {
inputManager.setCursorVisible(true);
}
}
if (name.equals("TOGGLE_WIREFRAME") && !pressed) {
for (Planet planet : planetAppState.getPlanets()) {
planet.toogleWireframe();
}
}
if (name.equals("COLLISION_TEST") && !pressed) {
CollisionResults results = new CollisionResults();
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
// Test collision with closest planet's terrain only
planetAppState.getNearestPlanet().getTerrainNode()
.collideWith(ray, results);
System.out.println("----- Collisions? " + results.size()
+ "-----");
for (int i = 0; i < results.size(); i++) {
// For each hit, we know distance, impact point, name of
// geometry.
float dist = results.getCollision(i).getDistance();
Vector3f pt = results.getCollision(i).getContactPoint();
String hit = results.getCollision(i).getGeometry()
.getName();
System.out.println("* Collision #" + i);
System.out.println(" You shot " + hit + " at " + pt + ", "
+ dist + " wu away.");
}
if (results.size() > 0) {
// The closest collision point is what was truly hit:
CollisionResult closest = results.getClosestCollision();
// Let's interact - we mark the hit with a red dot.
mark.setLocalTranslation(closest.getContactPoint());
rootNode.attachChild(mark);
} else {
// No hits? Then remove the red mark.
rootNode.detachChild(mark);
}
}
}
};
}
[/java]