camera.adoc 5.6 KB

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