My rotations aren’t working for some reason. Knowing me, it’s probably super simple & in the docs somewhere(I actually did look).
This is what happens when i press W, S, D, A.
What I’m trying to do is rotate the cube Forward, Backward, Left, & Right.
(getting this under 50 KB was not fun. It’s also faster than it should be for some reason.)
Input Manager:
inputManager.addMapping("Up_KB", new KeyTrigger(KeyInput.KEY_UP), new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("Down_KB", new KeyTrigger(KeyInput.KEY_DOWN), new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("Left_KB", new KeyTrigger(KeyInput.KEY_LEFT), new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping("Right_KB", new KeyTrigger(KeyInput.KEY_RIGHT), new KeyTrigger(KeyInput.KEY_D));
inputManager.addListener((ActionListener) (String name, boolean isPressed, float tpf) -> {
gl.player.slerpNewRot(0);
}, "Up_KB");
inputManager.addListener((ActionListener) (String name, boolean isPressed, float tpf) -> {
gl.player.slerpNewRot(180);
}, "Down_KB");
inputManager.addListener((ActionListener) (String name, boolean isPressed, float tpf) -> {
gl.player.slerpNewRot(90);
}, "Left_KB");
inputManager.addListener((ActionListener) (String name, boolean isPressed, float tpf) -> {
gl.player.slerpNewRot(270);
}, "Right_KB");
Player Class:
public class Player {
public Vector3f position = new Vector3f();
public Quaternion rotation = new Quaternion();
protected Quaternion newRot, oldRot;
protected float rotSlerp = 0;
public Node node;
public void buildNode() {
this.node = new Node();
Geometry g = new Geometry("Box", new Box(0.5f, 0.5f, 0.5f));
Material mat = new Material(Main.assets, "Common/MatDefs/Light/Lighting.j3md");
mat.setColor("Diffuse", ColorRGBA.Blue);
mat.setColor("Specular", ColorRGBA.Blue);
g.setMaterial(mat);
this.node.attachChild(g);
//this.node.attachChild(CrusherBuilder.types.get(0));
}
public void slerpNewRot(int degrees) {
oldRot = this.rotation;
newRot = Quaternion.ZERO.fromAngleAxis(degrees*FastMath.DEG_TO_RAD, Vector3f.UNIT_Y);
this.rotSlerp = 0;
}
public void update(GameLogic logic) {
this.position.add(0.01f, 0, 0);
if (newRot != null) {
this.rotation = oldRot.slerp(oldRot, newRot, rotSlerp+=0.01f);
if (rotSlerp >= 1) {
//this.rotation = newRot;
newRot = null;
oldRot = null;
System.out.println("done");
}
}
this.node.setLocalTranslation(position);
this.node.setLocalRotation(rotation);
}
}