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