Cool…thanks.
Basically as an exercise I’m trying to modify the Hello Collision tutorial to map navigation onto the arrow keys (which is working fine), but still have the same camera behavior mapped onto mouse movement (i.e. looking around when scrolling).
To replicate the mouse behavior as you suggest, I looked at the source of FlyByCamera and attempted to replicate the relevant logic. I had HelloCollision implement AnalogListener, disabled the flyCam, added new mappings and listeners for mouse input along the X and Y axes, and added these two methods from FlyByCamera:
public void onAnalog(String name, float value, float tpf) {
if (name.equals(“CamLeft”)){
rotateCamera(value, initialUpVec);
}else if (name.equals(“CamRight”)){
rotateCamera(-value, initialUpVec);
}else if (name.equals(“CamUp”)){
rotateCamera(-value, cam.getLeft());
}else if (name.equals(“CamDown”)){
rotateCamera(value, cam.getLeft());
}
}
protected void rotateCamera(float value, Vector3f axis){
Matrix3f mat = new Matrix3f();
mat.fromAngleNormalAxis(rotationSpeed * value, axis);
Vector3f up = cam.getUp();
Vector3f left = cam.getLeft();
Vector3f dir = cam.getDirection();
mat.mult(up, up);
mat.mult(left, left);
mat.mult(dir, dir);
Quaternion q = new Quaternion();
q.fromAxes(left, up, dir);
q.normalize();
cam.setAxes(q);
}
It sort of works, though the behavior is not ideal (looking up and down seems restricted to about a 90 degree arc, and side-to-side is also restricted). The problem might be the initial value of the initialUpVec? HelloCollision initializes the player like so:
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
player.setPhysicsLocation(new Vector3f(0, 10, 0));
I seem to get the best behavior when I initialize initialUpVec with the same vector that the player is initialized, but it still doesn’t work quite right. Thanks in advance for any input.