camera.adoc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. = The jME3 Camera
  2. :author:
  3. :revnumber:
  4. :revdate: 2016/03/17 20:48
  5. :keywords: camera, documentation
  6. :relfileprefix: ../../
  7. :imagesdir: ../..
  8. ifdef::env-github,env-browser[:outfilesuffix: .adoc]
  9. Note that by default, the mouse pointer is invisible, and the mouse is set up to control the camera rotation.
  10. == Default Camera
  11. The default com.jme3.renderer.Camera object is `cam` in com.jme3.app.Application.
  12. The camera object is created with the following defaults:
  13. * Width and height are set to the current Application's settings.getWidth() and settings.getHeight() values.
  14. * Frustum Perspective:
  15. ** Frame of view angle of 45° along the Y axis
  16. ** Aspect ratio of width divided by height
  17. ** Near view plane of 1 wu
  18. ** Far view plane of 1000 wu
  19. * Start location at (0f, 0f, 10f).
  20. * Start direction is looking at the origin.
  21. [cols="2", options="header"]
  22. |===
  23. a|Method
  24. a|Usage
  25. a|cam.getLocation(), setLocation()
  26. a|The camera position
  27. a|cam.getRotation(), setRotation()
  28. a|The camera rotation
  29. a|cam.getLeft(), setLeft()
  30. a|The left axis of the camera
  31. a|cam.getUp(), setUp()
  32. a|The up axis of the camera, usually Vector3f(0,1,0)
  33. a|cam.getDirection()
  34. a|The vector the camera is facing
  35. a|cam.getAxes(), setAxes(left,up,dir)
  36. a|One accessor for the three properties left/up/direction.
  37. a|cam.getFrame(), setFrame(loc,left,up,dir)
  38. a|One accessor for the four properties location/left/up/direction.
  39. a|cam.resize(width, height, fixAspect)
  40. a|Resize an existing camera object while keeping all other settings. Set fixAspect to true to adjust the aspect ratio (?)
  41. a|cam.setFrustum( near, far, left, right, top, bottom )
  42. a|The frustum is defined by the near/far plane, left/right plane, top/bottom plane (all distances as float values)
  43. a|cam.setFrustumPerspective( fovY, aspect ratio, near, far)
  44. a|The frustum is defined by view angle along the Y axis (in degrees), aspect ratio, and the near/far plane.
  45. a|cam.lookAt(target,up)
  46. a|Turn the camera to look at Coordinate target, and rotate it around the up axis.
  47. a|cam.setParallelProjection(false)
  48. a|Normal perspective
  49. a|cam.setParallelProjection(true)
  50. a|Parallel projection perspective
  51. a|cam.getScreenCoordinates()
  52. a|?
  53. |===
  54. *Tip:* After you change view port, frustum, or frame, call `cam.update();`
  55. == FlyBy Camera
  56. The `flyCam` class field gives you access to an AppState that extends the default camera in `com.jme3.app.SimpleApplication` with more features. The input manager of the `com.jme3.input.FlyByCamera` AppState 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.
  57. [source]
  58. ----
  59. Q W up forw
  60. A S D --> left back right
  61. Z down
  62. ----
  63. [cols="2", options="header"]
  64. |===
  65. a|Method
  66. a|Usage
  67. a|flyCam.setEnabled(true);
  68. a|Activate the flyby cam
  69. a|flyCam.setMoveSpeed(10);
  70. a|Control the move speed
  71. a|flyCam.setRotationSpeed(10);
  72. a|Control the rotation speed
  73. a|flyCam.setDragToRotate(true)
  74. a|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.
  75. |===
  76. The FlyByCamera is active by default, but you can change all these defaults for your game.
  77. == Chase Camera
  78. jME3 also supports an optional Chase Cam that can follow a moving target Spatial (`com.jme3.input.ChaseCamera`). When you use the chase cam, the player clicks and hold the mouse button to rotate the camera around the camera target. You can use a chase cam if you need the mouse pointer visible in your game.
  79. [source,java]
  80. ----
  81. flyCam.setEnabled(false);
  82. ChaseCamera chaseCam = new ChaseCamera(cam, target, inputManager);
  83. ----
  84. [cols="2", options="header"]
  85. |===
  86. a|Method
  87. a|Usage
  88. a|chaseCam.setSmoothMotion(true);
  89. a|Interpolates a smoother acceleration/deceleration when the camera moves.
  90. a|chaseCam.setChasingSensitivity(5f)
  91. a|The lower the chasing sensitivity, the slower the camera will follow the target when it moves.
  92. a|chaseCam.setTrailingSensitivity(0.5f)
  93. a|The lower the traling sensitivity, the slower the camera will begin to go after the target when it moves. Default is 0.5;
  94. a|chaseCam.setRotationSensitivity(5f)
  95. a|The lower the sensitivity, the slower the camera will rotate around the target when the mosue is dragged. Default is 5.
  96. a|chaseCam.setTrailingRotationInertia(0.1f)
  97. a|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.
  98. a|chaseCam.setDefaultDistance(40);
  99. a|The default distance to the target at the start of the application.
  100. a|chaseCam.setMaxDistance(40);
  101. a|The maximum zoom distance. Default is 40f.
  102. a|chaseCam.setMinDistance(1);
  103. a|The minimum zoom distance. Default is 1f.
  104. a|chaseCam.setMinVerticalRotation(-FastMath.PI/2);
  105. a|The minimal vertical rotation angle of the camera around the target. Default is 0.
  106. a|chaseCam.setDefaultVerticalRotation(-FastMath.PI/2);
  107. a|The default vertical rotation angle of the camera around the target at the start of the application.
  108. a|chaseCam.setDefaultHorizontalRotation(-FastMath.PI/2);
  109. a|The default horizontal rotation angle of the camera around the target at the start of the application.
  110. |===