I have my actionlistener on and working, mapped WASD for movement and wanted to add mouse control to turn when click+drag and look up and down.
The mouse is visible unless you click, then drag (then goes invisible), I record previous mousePos X then use the difference to rotate the camera. here is the code for turning:
This code works great to get the camera to turn using the mouse:
[java]
if (mouseClick) { //this listen for MouseInput.BUTTON_LEFT, set to true if left mouse button is pressed
if (mousebuttondown) { // my own bool var that tells me the button is already pressed so now testing for movement.
mouseposx = inputManager.getCursorPosition().x; // getting new mouse X value, old value is set to oldmouseposx below for next round
if (oldmouseposx != mouseposx) {
inputManager.setCursorVisible(false);
Quaternion rotateR = new Quaternion().fromAngleAxis(((oldmouseposx - mouseposx)/5) * tpf, Vector3f.UNIT_Y); // I divide by 5 because it went too fast (mouse sensibility)
rotateR.multLocal(viewDirection);
}
}
mousebuttondown = true;
oldmouseposx = inputManager.getCursorPosition().x;
} else { mousebuttondown = false; inputManager.setCursorVisible(true);}
playerControl.setViewDirection(viewDirection); // turn!
}[/java]
The problem is I am trying to get it to look up/down too, doing the same thing but with the Y value of the mouse and Vector3f.UNIT_X but all it does it switch my view 180deg.
Any idea?
Here is the code I tried to look up and down:
[java]
mouseposy = inputManager.getCursorPosition().y;
if (oldmouseposy != mouseposy) {
inputManager.setCursorVisible(false);
Quaternion rotateR = new Quaternion().fromAngleAxis(((oldmouseposy - mouseposy)/2) * tpf, Vector3f.UNIT_X);
rotateR.multLocal(viewDirection);
}
}[/java]
Thanks