I have setup a very primitive scene with a terrain(box) and 2 objects (another box and a sphere)
I am trying to set up some keybindings in order to move my object by it seems as though it ignores my key pressing.
the code follows:
import com.jme.app.SimpleGame;
import com.jme.scene.shape.Sphere;
import com.jme.scene.shape.Box;
import com.jme.math.Vector3f;
import com.jmex.physics.*;
import com.jme.light.PointLight;
import com.jme.scene.state.LightState;
import com.jme.renderer.ColorRGBA;
import com.jmex.physics.effects.Attractor;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.bounding.OrientedBoundingBox;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
public class Main extends SimpleGame{
Box h;
public static void main (String[] args)
{
Main app = new Main();
app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
protected void simpleInitGame() {
PhysicsWorld.create();
Sphere b=new Sphere("My sphere",15,15,1f);
b.setModelBound(new BoundingSphere());
b.updateModelBound();
b.setSolidColor(ColorRGBA.red);
rootNode.attachChild(b);
DynamicPhysicsObject s = new DynamicPhysicsObject(b,.5f);
PhysicsWorld.getInstance().addObject(s);
s.setGravityMode(1);
s.setEnabled(true);
s.syncWithGraphical();
h = new Box("mymovingbox",new Vector3f(9, -8, 0), 1f,1f, 1f);
h.setModelBound(new OrientedBoundingBox());
h.updateModelBound();
h.setSolidColor(ColorRGBA.red);
rootNode.attachChild(h);
DynamicPhysicsObject d = new DynamicPhysicsObject(h,15f);
PhysicsWorld.getInstance().addObject(d);
KeyBindingManager.getKeyBindingManager().set("for",KeyInput.KEY_1);
KeyBindingManager.getKeyBindingManager().set("left",KeyInput.KEY_2);
KeyBindingManager.getKeyBindingManager().set("back",KeyInput.KEY_3);
KeyBindingManager.getKeyBindingManager().set("right",KeyInput.KEY_4);
rootNode.updateWorldData(1f);
d.setGravityMode(0);
d.setEnabled(true);
d.syncWithGraphical();
Box c = new Box ("Terrain", new Vector3f (-10, -10, -10), 1000,1, 1000);
StaticPhysicsObject myTerrain = new StaticPhysicsObject(c);
c.hasCollision(c, true);
c.setModelBound(new BoundingBox());
c.updateModelBound();
rootNode.attachChild(c);
PhysicsWorld.getInstance().addObject(myTerrain);
myTerrain.syncWithGraphical();
LightState ls=display.getRenderer().createLightState();
PointLight pl = new PointLight();
pl.setEnabled(true);
pl.setAmbient(ColorRGBA.green);
ls.attach(pl);
rootNode.setRenderState(ls);
rootNode.updateWorldBound();
}
protected void simpleUpdate() {
Vector3f v = new Vector3f(h.getLocalTranslation());
if (KeyBindingManager.getKeyBindingManager().isValidCommand("for", false)) {
v.x = v.x+.1f;
h.setLocalTranslation(v);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("left", false)) {
v.y = v.y-.1f;
h.setLocalTranslation(v);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("back", false)) {
v.x = v.x-.1f;
h.setLocalTranslation(v);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("for", false)) {
v.y = v.y+.1f;
h.setLocalTranslation(v);
}
PhysicsWorld.getInstance().update(1f);
}
}
I know that I am missing something here but I cannot figure out exactly what :P
Thank you very much
PS: Irrelevant but I just figure out and would like to be of help to other noobs as me.
I used to get an OPENGLException 1281 with a 3ds model and it was fixed when I changed the textures from tga format to bmp.
I also got texture loading problems when loading 3ds files and having jpg textures so I ust converted them to jpg