When I look through the code it seems like russian dolls, you keep finding something inside something else.
I wanted to alter the controls of the 3rd or 4th flagrush tutorial so that the cube can be tilted up or down,
preferably with the mouse instead of the keys
I went looking through all the code and couldnt even find the bit where it specifies W as the key to move forward.
I looked through com.input.chasecamera.java
com.input.keybinding and those kind of files.
Could someone please post a simple demo with or without importing simplegame (preferably without) where you can alter the direction of a cube by moving the mouse and the cube moves fowards by itself?
Loooooool… russian dolls xD, that's excactly how it is. Very good analogy.
A friend of mine who is a modellerer, calls programming "canoefuck" XD, by which he means slow and complicated activity.
You can get the cameras rotation by cam.getRotation(); and use this to rotate you cube somehow. the cam.getRotation().getRotation(2); will return the z-orientation vector of the camera as Vector3f.
Then u can use the someNode.setLocalRotation(… I'm not sure how to set it right since i'm a jme noob and dont understand Quaterions and Matrices.
If u just want to rotate your cube using mouse and not relative to camera then i think you should use MouseInput. Altough i havent used it, i think its use should be similar to KeyInput, I saw it used in some code I was diggin throuh… after checking the javadoc, I found these classes, that i think you might also find useful.
MouseAxisBinding
MouseButtonBinding
I recommend also to find some example files where MouseInput is used, i think.
CHECK OUT THE jmetest.input.; package lots of examples there
u might also check jmetest.TutorialGuide.;
I hope i was able to help you, since I've heard JME has great community, but I haven't gotten any replies to half of my posts.
thanks, i can do some more digging i suppose :?
Ive done 3D programming in other languages that was a lot easier (blitz3d) but it was windows only.
Thats why I got into Java.
Could someone please post a simple demo with or without importing simplegame (preferably without) where you can alter the direction of a cube by moving the mouse and the cube moves fowards by itself?
I used GameControls and a RotationController to rotate the player.
If you want to camera to follow the player, you could also just create a CameraNode and attach it to the player.
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.input.InputHandler;
import com.jme.input.controls.GameControlManager;
import com.jme.input.controls.binding.MouseAxisBinding;
import com.jme.input.controls.controller.Axis;
import com.jme.input.controls.controller.RotationController;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.scene.shape.Arrow;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.MaterialState;
public class TestSimpleRotation extends SimpleGame {
private Node playerNode;
@Override
protected void simpleInitGame() {
// remove simple games controls
input = new InputHandler();
// create the floor and attach it to the scene
Box floor = new Box("floor", new Vector3f(), 100, 1, 100);
floor.setModelBound(new BoundingBox());
floor.updateModelBound();
MaterialState ms = display.getRenderer().createMaterialState();
ms.setDiffuse(ColorRGBA.green);
floor.setRenderState(ms);
rootNode.attachChild(floor);
// create the player and attach it to the scene
playerNode = createPlayer();
rootNode.attachChild(playerNode);
// create a simple anonymous controller to move the player continously forward
playerNode.addController(new Controller() {
float speed = 5;
@Override
public void update(float time) {
// move player forward
playerNode.getLocalTranslation().addLocal(
playerNode.getLocalRotation().getRotationColumn(2).mult(time*speed));
}
});
// set up game controls using the mouse axis (try MouseOffsetBinding as an alternative)
GameControlManager gm = new GameControlManager();
gm.addControl("rot_left").addBinding(new MouseAxisBinding(MouseAxisBinding.AXIS_X, true));
gm.addControl("rot_right").addBinding(new MouseAxisBinding(MouseAxisBinding.AXIS_X, false));
// create a rotation controller using the game controls
RotationController rotatePlayer = new RotationController(playerNode,
gm.getControl("rot_left"), gm.getControl("rot_right"), 1, Axis.Y);
playerNode.addController(rotatePlayer);
// set the cam above the player and look at him
cam.setLocation(new Vector3f(0, 20, -5));
cam.lookAt(playerNode.getLocalTranslation().clone(), Vector3f.UNIT_Y);
cam.update();
}
// create a blue sphere with a Arrow pointing into the players direction
private Node createPlayer() {
playerNode = new Node("playerNode");
Sphere player = new Sphere("player", new Vector3f(), 10, 10, 1);
player.setModelBound(new BoundingBox());
player.updateModelBound();
Arrow arrow = new Arrow("arr", 2, 0.3f);
arrow.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.DEG_TO_RAD * 90, Vector3f.UNIT_X));
arrow.setModelBound(new BoundingBox());
arrow.updateModelBound();
arrow.getLocalTranslation().addLocal(0, 0, 2);
playerNode.attachChild(arrow);
MaterialState msp = display.getRenderer().createMaterialState();
msp.setDiffuse(ColorRGBA.blue);
player.setRenderState(msp);
playerNode.attachChild(player);
playerNode.getLocalTranslation().addLocal(0, 2f, 0);
return playerNode;
}
@Override
protected void simpleUpdate() {
cam.lookAt(playerNode.getLocalTranslation().clone(), Vector3f.UNIT_Y);
cam.update();
}
public static void main(String[] args) {
TestSimpleRotation game = new TestSimpleRotation();
game.setConfigShowMode(ConfigShowMode.AlwaysShow);
game.start();
}
}
hey nice demo, thanks