public void keyPressed(KeyEvent e) { keyMove = new Matrix4f(); keyMove.setIdentity(); Vector3f keyMovement = new Vector3f(); switch (e.getKeyChar()) { case 's': keyMovement.z = -1 * scale; keyMove.setTranslation(keyMovement); break; case 'w': keyMovement.z = 1 * scale; keyMove.setTranslation(keyMovement); break; case 'a': keyMovement.x = 1 * scale; keyMove.setTranslation(keyMovement); break; case 'd': keyMovement.x = -1 * scale; keyMove.setTranslation(keyMovement); break; default: System.out.println("invalid key"); break; } }
public void mouseDragged(MouseEvent e) { oldMoveVector = new Vector3f(fixOldX, oldY, oldZ); oldWorldZMoveVector = new Vector3f(oldX, oldY, oldZ); // get x,y newX = e.getX() / (adjustToScreenSize / 2) - 1; // used to be (float)jframe.getWidth() newY = 1 - e.getY() / (adjustToScreenSize / 2); // used to be (float)jframe.getWidth() newZ = calculateZ(newX, newY); newMoveVector = new Vector3f(fixNewX, newY, newZ); newWorldZMoveVector = new Vector3f(newX, newY, newZ); // now calculate the Camera movement Vector3f moveAxis = new Vector3f(); // moving around this axis moveAxis.cross( oldMoveVector, newMoveVector); // TODO identify, if the axis points down or upwards => adjust the angle float moveAngle = oldMoveVector.angle(newMoveVector); // moving by this angle // special Vector including the angle AxisAngle4f moveAxisAngle = new AxisAngle4f(); moveAxisAngle.set(moveAxis, moveAngle); // calculate turning axis mouseTurn = new Matrix4f(); mouseTurn.setIdentity(); mouseTurn.set(moveAxisAngle); // the new Multiplication-Matrix // now calculate the World movement Vector3f worldMoveAxis = new Vector3f(); // moving around this axis worldMoveAxis.x = 0; worldMoveAxis.y = 0; worldMoveAxis.z = 1; float worldMoveAngle = oldWorldZMoveVector.angle(newWorldZMoveVector); // moving by this angle // adjust world Angle for turning back Vector3f worldMoveAxisTemp = new Vector3f(); worldMoveAxisTemp.cross(oldWorldZMoveVector, newWorldZMoveVector); if (worldMoveAxisTemp.z < 0) { worldMoveAngle = -worldMoveAngle; } // special Vector including the angle AxisAngle4f worldMoveAxisAngle = new AxisAngle4f(); worldMoveAxisAngle.set(worldMoveAxis, worldMoveAngle); // calculate turning axis mouseWorldTurn = new Matrix4f(); mouseWorldTurn.setIdentity(); mouseWorldTurn.set(worldMoveAxisAngle); // the new Multiplication-Matrix // override the initial starting values fixOldX = fixNewX; oldX = newX; oldY = newY; oldZ = newZ; }