rcamera.d 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*******************************************************************************************
  2. *
  3. * rcamera - Basic camera system with support for multiple camera modes
  4. *
  5. * CONFIGURATION:
  6. * #define RCAMERA_IMPLEMENTATION
  7. * Generates the implementation of the library into the included file.
  8. * If not defined, the library is in header only mode and can be included in other headers
  9. * or source files without problems. But only ONE file should hold the implementation.
  10. *
  11. * #define RCAMERA_STANDALONE
  12. * If defined, the library can be used as standalone as a camera system but some
  13. * functions must be redefined to manage inputs accordingly.
  14. *
  15. * CONTRIBUTORS:
  16. * Ramon Santamaria: Supervision, review, update and maintenance
  17. * Christoph Wagner: Complete redesign, using raymath (2022)
  18. * Marc Palau: Initial implementation (2014)
  19. *
  20. *
  21. * LICENSE: zlib/libpng
  22. *
  23. * Copyright (c) 2022-2024 Christoph Wagner (@Crydsch) & Ramon Santamaria (@raysan5)
  24. *
  25. * This software is provided "as-is", without any express or implied warranty. In no event
  26. * will the authors be held liable for any damages arising from the use of this software.
  27. *
  28. * Permission is granted to anyone to use this software for any purpose, including commercial
  29. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  30. *
  31. * 1. The origin of this software must not be misrepresented; you must not claim that you
  32. * wrote the original software. If you use this software in a product, an acknowledgment
  33. * in the product documentation would be appreciated but is not required.
  34. *
  35. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  36. * as being the original software.
  37. *
  38. * 3. This notice may not be removed or altered from any source distribution.
  39. *
  40. **********************************************************************************************/
  41. module raylib.rcamera;
  42. import raylib;
  43. extern (C) @nogc nothrow:
  44. //----------------------------------------------------------------------------------
  45. // Defines and Macros
  46. //----------------------------------------------------------------------------------
  47. // Function specifiers definition
  48. // Function specifiers in case library is build/used as a shared library (Windows)
  49. // NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
  50. // We are building the library as a Win32 shared library (.dll)
  51. // We are using the library as a Win32 shared library (.dll) // Functions defined as 'extern' by default (implicit specifiers)
  52. enum CAMERA_CULL_DISTANCE_NEAR = RL_CULL_DISTANCE_NEAR;
  53. enum CAMERA_CULL_DISTANCE_FAR = RL_CULL_DISTANCE_FAR;
  54. //----------------------------------------------------------------------------------
  55. // Types and Structures Definition
  56. // NOTE: Below types are required for standalone usage
  57. //----------------------------------------------------------------------------------
  58. // Vector2, 2 components
  59. // Vector x component
  60. // Vector y component
  61. // Vector3, 3 components
  62. // Vector x component
  63. // Vector y component
  64. // Vector z component
  65. // Matrix, 4x4 components, column major, OpenGL style, right-handed
  66. // Matrix first row (4 components)
  67. // Matrix second row (4 components)
  68. // Matrix third row (4 components)
  69. // Matrix fourth row (4 components)
  70. // Camera type, defines a camera position/orientation in 3d space
  71. // Camera position
  72. // Camera target it looks-at
  73. // Camera up vector (rotation over its axis)
  74. // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
  75. // Camera projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
  76. // Camera type fallback, defaults to Camera3D
  77. // Camera projection
  78. // Perspective projection
  79. // Orthographic projection
  80. // Camera system modes
  81. // Camera custom, controlled by user (UpdateCamera() does nothing)
  82. // Camera free mode
  83. // Camera orbital, around target, zoom supported
  84. // Camera first person
  85. // Camera third person
  86. //----------------------------------------------------------------------------------
  87. // Global Variables Definition
  88. //----------------------------------------------------------------------------------
  89. //...
  90. //----------------------------------------------------------------------------------
  91. // Module Functions Declaration
  92. //----------------------------------------------------------------------------------
  93. // Prevents name mangling of functions
  94. Vector3 GetCameraForward(Camera* camera);
  95. Vector3 GetCameraUp(Camera* camera);
  96. Vector3 GetCameraRight(Camera* camera);
  97. // Camera movement
  98. void CameraMoveForward(Camera* camera, float distance, bool moveInWorldPlane);
  99. void CameraMoveUp(Camera* camera, float distance);
  100. void CameraMoveRight(Camera* camera, float distance, bool moveInWorldPlane);
  101. void CameraMoveToTarget(Camera* camera, float delta);
  102. // Camera rotation
  103. void CameraYaw(Camera* camera, float angle, bool rotateAroundTarget);
  104. void CameraPitch(Camera* camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp);
  105. void CameraRoll(Camera* camera, float angle);
  106. Matrix GetCameraViewMatrix(Camera* camera);
  107. Matrix GetCameraProjectionMatrix(Camera* camera, float aspect);
  108. // RCAMERA_H
  109. /***********************************************************************************
  110. *
  111. * CAMERA IMPLEMENTATION
  112. *
  113. ************************************************************************************/
  114. // Required for vector maths:
  115. // Vector3Add()
  116. // Vector3Subtract()
  117. // Vector3Scale()
  118. // Vector3Normalize()
  119. // Vector3Distance()
  120. // Vector3CrossProduct()
  121. // Vector3RotateByAxisAngle()
  122. // Vector3Angle()
  123. // Vector3Negate()
  124. // MatrixLookAt()
  125. // MatrixPerspective()
  126. // MatrixOrtho()
  127. // MatrixIdentity()
  128. // raylib required functionality:
  129. // GetMouseDelta()
  130. // GetMouseWheelMove()
  131. // IsKeyDown()
  132. // IsKeyPressed()
  133. // GetFrameTime()
  134. //----------------------------------------------------------------------------------
  135. // Defines and Macros
  136. //----------------------------------------------------------------------------------
  137. // Units per second
  138. // Camera mouse movement sensitivity
  139. // Camera orbital speed in CAMERA_ORBITAL mode
  140. // Radians per second
  141. //----------------------------------------------------------------------------------
  142. // Types and Structures Definition
  143. //----------------------------------------------------------------------------------
  144. //...
  145. //----------------------------------------------------------------------------------
  146. // Global Variables Definition
  147. //----------------------------------------------------------------------------------
  148. //...
  149. //----------------------------------------------------------------------------------
  150. // Module specific Functions Declaration
  151. //----------------------------------------------------------------------------------
  152. //...
  153. //----------------------------------------------------------------------------------
  154. // Module Functions Definition
  155. //----------------------------------------------------------------------------------
  156. // Returns the cameras forward vector (normalized)
  157. // Returns the cameras up vector (normalized)
  158. // Note: The up vector might not be perpendicular to the forward vector
  159. // Returns the cameras right vector (normalized)
  160. // Moves the camera in its forward direction
  161. // Project vector onto world plane
  162. // Scale by distance
  163. // Move position and target
  164. // Moves the camera in its up direction
  165. // Scale by distance
  166. // Move position and target
  167. // Moves the camera target in its current right direction
  168. // Project vector onto world plane
  169. // Scale by distance
  170. // Move position and target
  171. // Moves the camera position closer/farther to/from the camera target
  172. // Apply delta
  173. // Distance must be greater than 0
  174. // Set new distance by moving the position along the forward vector
  175. // Rotates the camera around its up vector
  176. // Yaw is "looking left and right"
  177. // If rotateAroundTarget is false, the camera rotates around its position
  178. // Note: angle must be provided in radians
  179. // Rotation axis
  180. // View vector
  181. // Rotate view vector around up axis
  182. // Move position relative to target
  183. // rotate around camera.position
  184. // Move target relative to position
  185. // Rotates the camera around its right vector, pitch is "looking up and down"
  186. // - lockView prevents camera overrotation (aka "somersaults")
  187. // - rotateAroundTarget defines if rotation is around target or around its position
  188. // - rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
  189. // NOTE: angle must be provided in radians
  190. // Up direction
  191. // View vector
  192. // In these camera modes we clamp the Pitch angle
  193. // to allow only viewing straight up or down.
  194. // Clamp view up
  195. // avoid numerical errors
  196. // Clamp view down
  197. // downwards angle is negative
  198. // avoid numerical errors
  199. // Rotation axis
  200. // Rotate view vector around right axis
  201. // Move position relative to target
  202. // rotate around camera.position
  203. // Move target relative to position
  204. // Rotate up direction around right axis
  205. // Rotates the camera around its forward vector
  206. // Roll is "turning your head sideways to the left or right"
  207. // Note: angle must be provided in radians
  208. // Rotation axis
  209. // Rotate up direction around forward axis
  210. // Returns the camera view matrix
  211. // Returns the camera projection matrix
  212. // Update camera position for selected mode
  213. // Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM
  214. // Camera speeds based on frame time
  215. // Orbital can just orbit
  216. // Camera rotation
  217. // Camera movement
  218. // Camera pan (for CAMERA_FREE)
  219. // Mouse support
  220. // Keyboard support
  221. // Gamepad movement
  222. // Gamepad controller support
  223. // Zoom target distance
  224. // !RCAMERA_STANDALONE
  225. // Update camera movement, movement/rotation values should be provided by user
  226. // Required values
  227. // movement.x - Move forward/backward
  228. // movement.y - Move right/left
  229. // movement.z - Move up/down
  230. // rotation.x - yaw
  231. // rotation.y - pitch
  232. // rotation.z - roll
  233. // zoom - Move towards target
  234. // Camera rotation
  235. // Camera movement
  236. // Zoom target distance
  237. // RCAMERA_IMPLEMENTATION