hi here is my code so far:
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));
gm.addControl("rot_up").addBinding(new MouseAxisBinding(MouseAxisBinding.AXIS_Y,true));
gm.addControl("rot_down").addBinding(new MouseAxisBinding(MouseAxisBinding.AXIS_Y,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);
RotationController rotatePlayer2 = new RotationController(playerNode,
gm.getControl("rot_down"), gm.getControl("rot_up"), 1, Axis.X);
playerNode.addController(rotatePlayer);
playerNode.addController(rotatePlayer2);
// 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;
}
static Vector3f playervect;
@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();
}
}
the mouse controls the ball's flight,
What I want to do is put the camera behind the ball and make the camera look a few units ahead of the ball,
I need the camera's up vector to match the ball's up vector also.
Can anyone help please?