camera.adoc 5.3 KB

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