# The jME3 Camera

## Default Camera

The default com.jme3.renderer.Camera object is `cam` in com.jme3.app.Application.

The camera object is created with the following defaults:

- Width and height are set to the current Application's settings.getWidth() and settings.getHeight() values.
- Frustum Perspective:
  - Frame of view angle of 45?? along the Y axis
  - Aspect ratio of width divided by height
  - Near view plane of 1 wu
  - Far view plane of 1000 wu
- Start location at (0f, 0f, 10f).
- Start direction is looking at the origin.

Method | Usage
--- | ---
cam.getLocation(), setLocation() | The camera position
cam.getRotation(), setRotation() | The camera rotation
cam.getLeft(), setLeft() | The left axis of the camera
cam.getUp(), setUp() | The up axis of the camera, usually Vector3f(0,1,0)
cam.getDirection(), setDirection() | The vector the camera is facing
cam.getAxes(), setAxes(left,up,dir) | One accessor for the three properties left/up/direction.
cam.getFrame(), setFrame(loc,left,up,dir) | One accessor for the four properties location/left/up/direction.
cam.resize(width, height, fixAspect) | Resize an existing camera object while keeping all other settings. Set fixAspect to true to adjust the aspect ratio (?)
cam.setFrustum( near, far, left, right, top, bottom ) | The frustum is defined by the near/far plane, left/right plane, top/bottom plane (all distances as float values)
cam.setFrustumPerspective( fovY, aspect ratio, near, far) | The frustum is defined by view angle along the Y axis (in degrees), aspect ratio, and the near/far plane.
cam.lookAt(target,up) | Turn the camera to look at Coordinate target, and rotate it around the up axis.
cam.setParallelProjection(false) | Normal perspective
cam.setParallelProjection(true) | Parallel projection perspective
cam.getScreenCoordinates() | ?

Tip: After you change view port, frustum, or frame, call `cam.update();`

## FlyBy Camera

The flyby camera is an AppState that extends the default camera in com.jme3.app.SimpleApplication. It is preconfigured to respond to the WASD keys for walking forwards and backwards, and strafing to the sides; move the mouse to rotate the camera ("Mouse Look"), scroll the mouse wheel for zooming in or out. The QZ keys raise or lower the camera vertically.

Method | Usage
--- | ---
flyCam.setEnabled(true); | Activate the flyby cam
flyCam.setMoveSpeed(10); | Control the move speed
flyCam.setRotationSpeed(10); | Control the rotation speed
flyCam.setDragToRotate(true) | Forces the player to keep mouse button pressed to rotate camera, typically used for Applets. If false (default), all mouse movement will be captured and interpreted as rotations.

## Chase Camera

jME3 also supports a Chase Cam that can follow a moving target Spatial (`com.jme3.input.ChaseCamera`). Click and hold the mouse button to rotate around the target.

    flyCam.setEnabled(false);
    ChaseCamera chaseCam = new ChaseCamera(cam, target, inputManager);

Method | Usage
--- | ---
chaseCam.setSmoothMotion(true); | Interpolates a smoother acceleration/deceleration when the camera moves.
chaseCam.setChasingSensitivity(5f) | The lower the chasing sensitivity, the slower the camera will follow the target when it moves.
chaseCam.setTrailingSensitivity(0.5f) | The lower the traling sensitivity, the slower the camera will begin to go after the target when it moves. Default is 0.5;
chaseCam.setRotationSensitivity(5f) | The lower the sensitivity, the slower the camera will rotate around the target when the mosue is dragged. Default is 5.
chaseCam.setTrailingRotationInertia(0.1f) | This prevents the camera to stop too abruptly when the target stops rotating before the camera has reached the target's trailing position. Default is 0.1f.
chaseCam.setDefaultDistance(40); | The default distance to the target at the start of the application.
chaseCam.setMaxDistance(40); | The maximum zoom distance. Default is 40f.
chaseCam.setMinDistance(1); | The minimum zoom distance. Default is 1f.
chaseCam.setMinVerticalRotation(-FastMath.PI/2); | The minimal vertical rotation angle of the camera around the target. Default is 0.
chaseCam.setDefaultVerticalRotation(-FastMath.PI/2); | The default vertical rotation angle of the camera around the target at the start of the application.
chaseCam.setDefaultHorizontalRotation(-FastMath.PI/2); | The default horizontal rotation angle of the camera around the target at the start of the application.

camera, documentation

view online version