├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── cameras ├── README.md ├── rlFPCamera │ ├── README.md │ ├── rlFPCamera.c │ ├── rlFPCamera.h │ └── samples │ │ └── example.c └── rlTPCamera │ ├── README.md │ ├── rlTPCamera.c │ ├── rlTPCamera.h │ └── samples │ └── example.c ├── path_utils ├── app_dir.c ├── app_dir.h ├── resource_dir.h └── samples │ └── application_dir │ └── main.c ├── premake-VisualStudio.bat ├── premake-mingw.bat ├── premake5 ├── premake5.exe ├── premake5.lua ├── premake5.osx ├── ray_collision_2d.h ├── raylib_premake5.lua └── raylib_win32.h /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | /build/ImGuiSample.vcxproj 352 | /build/ImGuiSample.vcxproj.filters 353 | /build/editor.vcxproj 354 | /build/editor.vcxproj.filters 355 | /build/imgui.ini 356 | /build/raylib.vcxproj 357 | /build/raylib.vcxproj.filters 358 | /build/rlImGui.vcxproj 359 | /build/rlImGui.vcxproj.filters 360 | /build/simple.vcxproj 361 | /build/simple.vcxproj.filters 362 | /examples/editor.vcxproj 363 | /examples/editor.vcxproj.filters 364 | /examples/simple.vcxproj 365 | /examples/simple.vcxproj.filters 366 | /premake5.exe 367 | /rlImGui.sln 368 | /build/rlFPCamera.vcxproj.filters 369 | /examples/rlFPCamera_sample.vcxproj 370 | /examples/rlFPCamera_sample.vcxproj.filters 371 | /extras.sln 372 | /build/rlTPCamera.vcxproj 373 | /build/rlTPCamera.vcxproj.filters 374 | /cameras/rlFPCamera/samples/rlFPCamera_sample.vcxproj 375 | /cameras/rlFPCamera/samples/rlFPCamera_sample.vcxproj.filters 376 | /cameras/rlTPCamera/samples/rlTPCamera_sample.vcxproj 377 | /cameras/rlTPCamera/samples/rlTPCamera_sample.vcxproj.filters 378 | raylib-master 379 | Catalog 380 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing to raylib-extras 2 | 3 | Thank you for taking an intrerest in contributing to raylib-extras 4 | 5 | ## Guidelines 6 | 7 | - Please Make a PR with your change or addition. Add your name to this file under Contributors. Please do not change the copyright on the file you are changing or adding. 8 | - Please follow the existing style conventions with your change. 9 | - When possible use raymath for math functions, don't make your own. 10 | - When possible break your functions up into sub functions, especially if that sub function may be useful on it's own. 11 | 12 | # Contributors 13 | Dor Shapira (sDos280) 14 | Jaedeok Kim (jdeokkim) 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020-2021 Jeffery Myers 2 | 3 | This software is provided "as-is", without any express or implied warranty. In no event 4 | will the authors be held liable for any damages arising from the use of this software. 5 | 6 | Permission is granted to anyone to use this software for any purpose, including commercial 7 | applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | 9 | 1. The origin of this software must not be misrepresented; you must not claim that you 10 | wrote the original software. If you use this software in a product, an acknowledgment 11 | in the product documentation would be appreciated but is not required. 12 | 13 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented 14 | as being the original software. 15 | 16 | 3. This notice may not be removed or altered from any source distribution. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # extras-c 2 | 3 | 4 | Useful comonents for use the [Raylib](https://www.raylib.com/) library (C language version). 5 | 6 | Note that the C versions of any extra can be used in C++ without issue. 7 | 8 | # Building 9 | raylib-extras is setup to use premake to generate static libraries and examples for Visual Studio 2022 and makefiles for gcc on linux/mac OS and mingw on windows. 10 | The system is based on game-premake and will download raylib for you. Please see https://github.com/raylib-extras/game-premake for more info. 11 | 12 | # Components 13 | raylib-extras is broken up into modular components. Most components are designed to be used standalone. 14 | 15 | ## ray_collision_2d.h 16 | A single file header with utillities to help detect collisions between 2d rays and various shapes. 17 | 18 | ## path_utils 19 | Utilities to help manage paths with raylib and other games. 20 | 21 | ### application_dir 22 | A single function to locate the folder/directory that the running executable is in. Used to set your working directory for future raylib resource loads. 23 | 24 | ### resource_dir 25 | A single function to locate a named resource/assets folder relative to several common locations and set it as the working directory. 26 | Checks the follopwing paths untill it finds the specificed folder name. 27 | 1) Working Dir 28 | 2) Applicaiton Dir 29 | 3) Up to 3 levels above the application dir 30 | 31 | This can be very useful to ensure that the working dir is set correctly on whatever platform your game is running on, regardless of how it is started. 32 | 33 | A simple way to call the funciton would be. 34 | ``` 35 | if (!SearchAndSetResourceDir("resources")) 36 | TraceLog(LOG_ERROR, "Resources dir Not Found!"); 37 | TraceLog(LOG_INFO, "Using working dir %s", GetWorkingDirectory()); 38 | ``` 39 | 40 | ## Cameras 41 | There are 3 different camera controllers provided in raylib-extras. Each one is intended to show an example of a different way to move the camera around a scene. 42 | 43 | ### rlFPCamera 44 | This is a first person camera. It uses the traditional mouse and WASD keys for movement. It provides position and view angle data back to the calling application. 45 | See cameras/rlFPCamera/samples/example.c for a simple use case. 46 | 47 | ![fpCamera](https://user-images.githubusercontent.com/322174/136627569-64e0b660-d846-4b1c-9239-5e09b030b2aa.gif) 48 | 49 | ### rlTPCamera 50 | This is a third person camera. It uses the traditional mouse and WASD keys for movement. It follows a target position and lets the user rotate around that as it moves. 51 | See cameras/rlTPCamera/samples/example.c for a simple use case. 52 | ![tpCamera](https://user-images.githubusercontent.com/322174/136641801-3f7f0a05-e79a-4f67-b05a-217e183eedde.gif) 53 | 54 | 55 | # Other langauges 56 | raylib-extras is broken up into seperate repositories per language. 57 | 58 | * C and C++ https://github.com/raylib-extras/extras-c 59 | * C++ https://github.com/raylib-extras/extras-cpp 60 | * C# https://github.com/raylib-extras/extras-cs 61 | 62 | -------------------------------------------------------------------------------- /cameras/README.md: -------------------------------------------------------------------------------- 1 | ## Cameras 2 | There are 3 different camera controllers provided in raylib-extras. Each one is intended to show an example of a different way to move the camera around a scene. 3 | 4 | ### rlFPCamera 5 | This is a first person camera. It uses the traditional mouse and WASD keys for movement. It provides position and view angle data back to the calling application. 6 | See cameras/rlFPCamera/samples/example.c for a simple use case. 7 | 8 | ![fpCamera](https://user-images.githubusercontent.com/322174/136627569-64e0b660-d846-4b1c-9239-5e09b030b2aa.gif) 9 | 10 | ### rlTPCamera 11 | This is a third person camera. It uses the traditional mouse and WASD keys for movement. It follows a target position and lets the user rotate around that as it moves. 12 | See cameras/rlTPCamera/samples/example.c for a simple use case. 13 | 14 | ![tpCamera](https://user-images.githubusercontent.com/322174/136641801-3f7f0a05-e79a-4f67-b05a-217e183eedde.gif) 15 | 16 | ### rlFreeCamera 17 | TODO 18 | -------------------------------------------------------------------------------- /cameras/rlFPCamera/README.md: -------------------------------------------------------------------------------- 1 | # rlFPCamera 2 | A simple first person camera controller for raylib 3 | 4 | # API 5 | All data for the first person camera is managed by the rlFPCamera structure. 6 | 7 | This structure is setup by calling rlFPCameraInit with a camera, FOV, and Position. 8 | ``` 9 | rlFPCameraInit(&camera, fov, pos); 10 | ``` 11 | 12 | The fov argument is the vertical field of view, 45degrees is a good starting point. The horizontal view will be computed using the aspect ratio of the screen. 13 | The position will be the inital location of the camera in world space. 14 | 15 | Once the camera is initalized, options in the camera structure can be set, such as view bob, speed, control keys, and render distance. 16 | 17 | Whenever a window, or render texture is resized rlFPCameraResizeView needs to be called for any cameras used in that space, to properly recompute the FOV. 18 | 19 | Once per frame rlFPCameraUpdate with the camera should be called, this will apply any input events and move the camera. 20 | Once a camera is updated it can be used on screen or in a render texture by calling. 21 | 22 | rlFPCameraBeginMode3D and rlFPCameraEndMode3D. These work just like BeginMode3d and EndMode3d for raylib cameras, but use the extended features of rlFPCamera 23 | 24 | 25 | -------------------------------------------------------------------------------- /cameras/rlFPCamera/rlFPCamera.c: -------------------------------------------------------------------------------- 1 | /********************************************************************************************** 2 | * 3 | * raylibExtras * Utilities and Shared Components for Raylib 4 | * 5 | * FPCamera * Simple First person camera (C version) 6 | * 7 | * LICENSE: MIT 8 | * 9 | * Copyright (c) 2020 Jeffery Myers 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | * SOFTWARE. 28 | * 29 | **********************************************************************************************/ 30 | 31 | 32 | #include "rlFPCamera.h" 33 | #include "rlgl.h" 34 | #include 35 | #include 36 | 37 | void rlFPCameraInit(rlFPCamera* camera, float fovY, Vector3 position) 38 | { 39 | if (camera == NULL) 40 | return; 41 | 42 | camera->ControlsKeys[0] = 'W'; 43 | camera->ControlsKeys[1] = 'S'; 44 | camera->ControlsKeys[2] = 'D'; 45 | camera->ControlsKeys[3] = 'A'; 46 | camera->ControlsKeys[4] = 'E'; 47 | camera->ControlsKeys[5] = 'Q'; 48 | camera->ControlsKeys[6] = KEY_LEFT; 49 | camera->ControlsKeys[7] = KEY_RIGHT; 50 | camera->ControlsKeys[8] = KEY_UP; 51 | camera->ControlsKeys[9] = KEY_DOWN; 52 | camera->ControlsKeys[10] = KEY_LEFT_SHIFT; 53 | 54 | 55 | camera->MoveSpeed = (Vector3){ 1,1,1 }; 56 | camera->TurnSpeed = (Vector2){ 90,90 }; 57 | 58 | camera->UseMouse = true; 59 | camera->MouseSensitivity = 600; 60 | camera->InvertY = false; 61 | 62 | camera->MinimumViewY = -89.0f; 63 | camera->MaximumViewY = 89.0f; 64 | 65 | camera->ViewBobbleFreq = 0.0f; 66 | camera->ViewBobbleMagnatude = 0.02f; 67 | camera->ViewBobbleWaverMagnitude = 0.002f; 68 | camera->CurrentBobble = 0; 69 | 70 | camera->Focused = IsWindowFocused(); 71 | 72 | camera->TargetDistance = 1; 73 | camera->PlayerEyesPosition = 0.5f; 74 | camera->ViewAngles = (Vector2){ 0,0 }; 75 | 76 | camera->CameraPosition = position; 77 | camera->FOV.y = fovY; 78 | 79 | camera->ViewCamera.position = position; 80 | camera->ViewCamera.position.y += camera->PlayerEyesPosition; 81 | camera->ViewCamera.target = Vector3Add(camera->ViewCamera.position, (Vector3) { 0, 0, camera->TargetDistance }); 82 | camera->ViewCamera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; 83 | camera->ViewCamera.fovy = fovY; 84 | camera->ViewCamera.projection = CAMERA_PERSPECTIVE; 85 | 86 | camera->AllowFlight = false; 87 | 88 | camera->NearPlane = 0.01; 89 | camera->FarPlane = 1000.0; 90 | 91 | rlFPCameraResizeView(camera); 92 | rlFPCameraUseMouse(camera, camera->UseMouse); 93 | } 94 | 95 | void rlFPCameraUseMouse(rlFPCamera* camera, bool useMouse) 96 | { 97 | if (!camera) 98 | return; 99 | 100 | camera->UseMouse = useMouse; 101 | 102 | if (useMouse && IsWindowFocused()) 103 | DisableCursor(); 104 | else if (!useMouse && IsWindowFocused()) 105 | EnableCursor(); 106 | } 107 | 108 | void rlFPCameraResizeView(rlFPCamera* camera) 109 | { 110 | if (camera == NULL) 111 | return; 112 | 113 | float width = (float)GetScreenWidth(); 114 | float height = (float)GetScreenHeight(); 115 | 116 | camera->FOV.y = camera->ViewCamera.fovy; 117 | 118 | if (height != 0) 119 | camera->FOV.x = camera->FOV.y * (width / height); 120 | } 121 | 122 | Vector3 rlFPCameraGetPosition(rlFPCamera* camera) 123 | { 124 | return camera->CameraPosition; 125 | } 126 | 127 | void rlFPCameraSetPosition(rlFPCamera* camera, Vector3 pos) 128 | { 129 | camera->CameraPosition = pos; 130 | Vector3 forward = Vector3Subtract(camera->ViewCamera.target, camera->ViewCamera.position); 131 | camera->ViewCamera.position = camera->CameraPosition; 132 | camera->ViewCamera.target = Vector3Add(camera->CameraPosition, forward); 133 | } 134 | 135 | RLAPI Ray rlFPCameraGetViewRay(rlFPCamera* camera) 136 | { 137 | return (Ray) { camera->CameraPosition, camera->Forward }; 138 | } 139 | 140 | static float GetSpeedForAxis(rlFPCamera* camera, rlFPCameraControls axis, float speed) 141 | { 142 | if (camera == NULL) 143 | return 0; 144 | 145 | int key = camera->ControlsKeys[axis]; 146 | if (key == -1) 147 | return 0; 148 | 149 | float factor = 1.0f; 150 | if (IsKeyDown(camera->ControlsKeys[SPRINT])) 151 | factor = 2; 152 | 153 | if (IsKeyDown(camera->ControlsKeys[axis])) 154 | return speed * GetFrameTime() * factor; 155 | 156 | return 0.0f; 157 | } 158 | 159 | void rlFPCameraUpdate(rlFPCamera* camera) 160 | { 161 | if (camera == NULL) 162 | return; 163 | 164 | if (IsWindowFocused() != camera->Focused && camera->UseMouse) 165 | { 166 | camera->Focused = IsWindowFocused(); 167 | if (camera->Focused) 168 | { 169 | DisableCursor(); 170 | } 171 | else 172 | { 173 | EnableCursor(); 174 | } 175 | } 176 | 177 | // Mouse movement detection 178 | Vector2 mousePositionDelta = GetMouseDelta(); 179 | 180 | // Keys input detection 181 | float direction[MOVE_DOWN + 1] = { GetSpeedForAxis(camera,MOVE_FRONT,camera->MoveSpeed.z), 182 | GetSpeedForAxis(camera,MOVE_BACK,camera->MoveSpeed.z), 183 | GetSpeedForAxis(camera,MOVE_RIGHT,camera->MoveSpeed.x), 184 | GetSpeedForAxis(camera,MOVE_LEFT,camera->MoveSpeed.x), 185 | GetSpeedForAxis(camera,MOVE_UP,camera->MoveSpeed.y), 186 | GetSpeedForAxis(camera,MOVE_DOWN,camera->MoveSpeed.y) }; 187 | 188 | 189 | // let someone modify the projected position 190 | // Camera orientation calculation 191 | float turnRotation = GetSpeedForAxis(camera, TURN_LEFT, camera->TurnSpeed.x) - GetSpeedForAxis(camera, TURN_RIGHT, camera->TurnSpeed.x); 192 | float tiltRotation = GetSpeedForAxis(camera, TURN_DOWN, camera->TurnSpeed.y) - GetSpeedForAxis(camera, TURN_UP, camera->TurnSpeed.y); 193 | 194 | if (turnRotation != 0) 195 | camera->ViewAngles.x -= turnRotation * DEG2RAD; 196 | else if (camera->UseMouse && camera->Focused) 197 | camera->ViewAngles.x += (mousePositionDelta.x / camera->MouseSensitivity); 198 | 199 | float yFactor = camera->InvertY ? -1.0f : 1.0f; 200 | 201 | if (tiltRotation) 202 | camera->ViewAngles.y += yFactor * tiltRotation * DEG2RAD; 203 | else if (camera->UseMouse && camera->Focused) 204 | camera->ViewAngles.y += (yFactor * mousePositionDelta.y / camera->MouseSensitivity); 205 | 206 | // Angle clamp 207 | if (camera->ViewAngles.y < camera->MinimumViewY * DEG2RAD) 208 | camera->ViewAngles.y = camera->MinimumViewY * DEG2RAD; 209 | else if (camera->ViewAngles.y > camera->MaximumViewY * DEG2RAD) 210 | camera->ViewAngles.y = camera->MaximumViewY * DEG2RAD; 211 | 212 | // Recalculate camera target considering translation and rotation 213 | Vector3 target = Vector3Transform((Vector3) { 0, 0, 1 }, MatrixRotateZYX((Vector3) { camera->ViewAngles.y, -camera->ViewAngles.x, 0 })); 214 | 215 | if (camera->AllowFlight) 216 | camera->Forward = target; 217 | else 218 | camera->Forward = Vector3Transform((Vector3) { 0, 0, 1 }, MatrixRotateZYX((Vector3) { 0, -camera->ViewAngles.x, 0 })); 219 | 220 | camera->Right = (Vector3){ camera->Forward.z * -1.0f, 0, camera->Forward.x }; 221 | 222 | camera->CameraPosition = Vector3Add(camera->CameraPosition, Vector3Scale(camera->Forward, direction[MOVE_FRONT] - direction[MOVE_BACK])); 223 | camera->CameraPosition = Vector3Add(camera->CameraPosition, Vector3Scale(camera->Right, direction[MOVE_RIGHT] - direction[MOVE_LEFT])); 224 | 225 | camera->CameraPosition.y += direction[MOVE_UP] - direction[MOVE_DOWN]; 226 | 227 | camera->ViewCamera.position = camera->CameraPosition; 228 | 229 | float eyeOffset = camera->PlayerEyesPosition; 230 | 231 | if (camera->ViewBobbleFreq > 0) 232 | { 233 | float swingDelta = (float)(fmax(fabs(direction[MOVE_FRONT] - direction[MOVE_BACK]), fabs(direction[MOVE_RIGHT] - direction[MOVE_LEFT]))); 234 | 235 | camera->CurrentBobble += swingDelta * camera->ViewBobbleFreq; 236 | 237 | static float viewBobbleDampen = 8.0f; 238 | 239 | eyeOffset -= sinf(camera->CurrentBobble / viewBobbleDampen) * camera->ViewBobbleMagnatude; 240 | 241 | camera->ViewCamera.up.x = sinf(camera->CurrentBobble / (viewBobbleDampen * 2)) * camera->ViewBobbleWaverMagnitude; 242 | camera->ViewCamera.up.z = -sinf(camera->CurrentBobble / (viewBobbleDampen * 2)) * camera->ViewBobbleWaverMagnitude; 243 | } 244 | else 245 | { 246 | camera->CurrentBobble = 0; 247 | camera->ViewCamera.up.x = 0; 248 | camera->ViewCamera.up.z = 0; 249 | } 250 | 251 | camera->ViewCamera.position.y += eyeOffset; 252 | 253 | camera->ViewCamera.target.x = camera->ViewCamera.position.x + target.x; 254 | camera->ViewCamera.target.y = camera->ViewCamera.position.y + target.y; 255 | camera->ViewCamera.target.z = camera->ViewCamera.position.z + target.z; 256 | } 257 | 258 | static void SetupCamera(rlFPCamera* camera, float aspect) 259 | { 260 | rlDrawRenderBatchActive(); // Draw Buffers (Only OpenGL 3+ and ES2) 261 | rlMatrixMode(RL_PROJECTION); // Switch to projection matrix 262 | rlPushMatrix(); // Save previous matrix, which contains the settings for the 2d ortho projection 263 | rlLoadIdentity(); // Reset current matrix (projection) 264 | 265 | if (camera->ViewCamera.projection == CAMERA_PERSPECTIVE) 266 | { 267 | // Setup perspective projection 268 | double top = RL_CULL_DISTANCE_NEAR * tan(camera->ViewCamera.fovy * 0.5 * DEG2RAD); 269 | double right = top * aspect; 270 | 271 | rlFrustum(-right, right, -top, top, camera->NearPlane, camera->FarPlane); 272 | } 273 | else if (camera->ViewCamera.projection == CAMERA_ORTHOGRAPHIC) 274 | { 275 | // Setup orthographic projection 276 | double top = camera->ViewCamera.fovy / 2.0; 277 | double right = top * aspect; 278 | 279 | rlOrtho(-right, right, -top, top, camera->NearPlane, camera->FarPlane); 280 | } 281 | 282 | // NOTE: zNear and zFar values are important when computing depth buffer values 283 | 284 | rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix 285 | rlLoadIdentity(); // Reset current matrix (modelview) 286 | 287 | // Setup Camera view 288 | Matrix matView = MatrixLookAt(camera->ViewCamera.position, camera->ViewCamera.target, camera->ViewCamera.up); 289 | 290 | rlMultMatrixf(MatrixToFloatV(matView).v); // Multiply modelview matrix by view matrix (camera) 291 | 292 | rlEnableDepthTest(); // Enable DEPTH_TEST for 3D 293 | } 294 | 295 | void rlFPCameraBeginMode3D(rlFPCamera* camera) 296 | { 297 | if (camera == NULL) 298 | return; 299 | 300 | float aspect = (float)GetScreenWidth() / (float)GetScreenHeight(); 301 | SetupCamera(camera, aspect); 302 | } 303 | 304 | void rlFPCameraEndMode3D() 305 | { 306 | EndMode3D(); 307 | } 308 | -------------------------------------------------------------------------------- /cameras/rlFPCamera/rlFPCamera.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************************** 2 | * 3 | * raylib-extras * Utilities and Shared Components for Raylib 4 | * 5 | * rlFPCamera * First person camera (C version) 6 | * 7 | * LICENSE: ZLib 8 | * 9 | * Copyright (c) 2021 Jeffery Myers 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | * SOFTWARE. 28 | * 29 | **********************************************************************************************/ 30 | 31 | 32 | #ifndef FP_CAMERA_H 33 | #define FP_CAMERA_H 34 | 35 | #include "raylib.h" 36 | #include "raymath.h" 37 | 38 | typedef enum 39 | { 40 | MOVE_FRONT = 0, 41 | MOVE_BACK, 42 | MOVE_RIGHT, 43 | MOVE_LEFT, 44 | MOVE_UP, 45 | MOVE_DOWN, 46 | TURN_LEFT, 47 | TURN_RIGHT, 48 | TURN_UP, 49 | TURN_DOWN, 50 | SPRINT, 51 | LAST_CONTROL 52 | }rlFPCameraControls; 53 | 54 | typedef struct 55 | { 56 | // keys used to control the camera 57 | int ControlsKeys[LAST_CONTROL]; 58 | 59 | // the speed in units/second to move 60 | // X = sidestep 61 | // Y = jump/fall 62 | // Z = forward 63 | Vector3 MoveSpeed; 64 | 65 | // the speed for turning when using keys to look 66 | // degrees/second 67 | Vector2 TurnSpeed; 68 | 69 | // use the mouse for looking? 70 | bool UseMouse; 71 | 72 | bool InvertY; 73 | 74 | // how many pixels equate out to an angle move, larger numbers mean slower, more accurate mouse 75 | float MouseSensitivity; 76 | 77 | // how far down can the camera look 78 | float MinimumViewY; 79 | 80 | // how far up can the camera look 81 | float MaximumViewY; 82 | 83 | // how fast the view should bobble as you move 84 | // defaults to 0 for no bobble 85 | float ViewBobbleFreq; 86 | 87 | // how high up/down will the bobble be 88 | float ViewBobbleMagnatude; 89 | 90 | // how far left and right should the view bobble 91 | float ViewBobbleWaverMagnitude; 92 | 93 | // the position of the base of the camera (on the floor) 94 | // note that this will not be the view position because it is offset by the eye height. 95 | // this value is also not changed by the view bobble 96 | Vector3 CameraPosition; 97 | 98 | // how far from the base of the camera is the player's view 99 | float PlayerEyesPosition; 100 | 101 | // the field of view in X and Y 102 | Vector2 FOV; 103 | 104 | // state for view movement 105 | float TargetDistance; 106 | 107 | // state for view angles 108 | Vector2 ViewAngles; 109 | 110 | // state for bobble 111 | float CurrentBobble; 112 | 113 | // state for window focus 114 | bool Focused; 115 | 116 | bool AllowFlight; 117 | 118 | // raylib camera for use with raylib modes. 119 | Camera3D ViewCamera; 120 | 121 | Vector3 Forward; 122 | Vector3 Right; 123 | 124 | //clipping planes 125 | // note must use BeginModeFP3D and EndModeFP3D instead of BeginMode3D/EndMode3D for clipping planes to work 126 | double NearPlane; 127 | double FarPlane; 128 | }rlFPCamera; 129 | 130 | // called to initialize a camera to default values 131 | RLAPI void rlFPCameraInit(rlFPCamera* camera, float fovY, Vector3 position); 132 | 133 | // called to update field of view in X when window resizes 134 | RLAPI void rlFPCameraResizeView(rlFPCamera* camera); 135 | 136 | // turn the use of mouselook on/off, also updates the cursor visibility 137 | RLAPI void rlFPCameraUseMouse(rlFPCamera* camera, bool useMouse); 138 | 139 | // Get the camera's position in world (or game) space 140 | RLAPI Vector3 rlFPCameraGetPosition(rlFPCamera* camera); 141 | 142 | // Set the camera's position in world (or game) space 143 | RLAPI void rlFPCameraSetPosition(rlFPCamera* camera, Vector3 pos); 144 | 145 | // returns the ray from the camera through the center of the view 146 | RLAPI Ray rlFPCameraGetViewRay(rlFPCamera* camera); 147 | 148 | // update the camera for the current frame 149 | RLAPI void rlFPCameraUpdate(rlFPCamera* camera); 150 | 151 | // start drawing using the camera, with near/far plane support 152 | RLAPI void rlFPCameraBeginMode3D(rlFPCamera* camera); 153 | 154 | // end drawing with the camera 155 | RLAPI void rlFPCameraEndMode3D(); 156 | 157 | 158 | #endif //FP_CAMERA_H 159 | -------------------------------------------------------------------------------- /cameras/rlFPCamera/samples/example.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * raylib [core] example - First Person Orbit Camera Example 4 | * 5 | * Welcome to raylib! 6 | * 7 | * To test examples, just press F6 and execute raylib_compile_execute script 8 | * Note that compiled executable is placed in the same folder as .c file 9 | * 10 | * You can find all basic examples on C:\raylib\raylib\examples folder or 11 | * raylib official webpage: www.raylib.com 12 | * 13 | * Enjoy using raylib. :) 14 | * 15 | * This example has been created using raylib 1.0 (www.raylib.com) 16 | * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 17 | * 18 | * Copyright (c) 2014 Ramon Santamaria (@raysan5) 19 | * 20 | ********************************************************************************************/ 21 | 22 | #include "raylib.h" 23 | #include "rlFPCamera.h" 24 | #include "rlgl.h" 25 | 26 | int main() 27 | { 28 | // Initialization 29 | //-------------------------------------------------------------------------------------- 30 | int screenWidth = 1900; 31 | int screenHeight = 900; 32 | 33 | SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT); 34 | InitWindow(screenWidth, screenHeight, "raylib-extras [camera] example - First person camera"); 35 | SetTargetFPS(60); 36 | 37 | //-------------------------------------------------------------------------------------- 38 | Image img = GenImageChecked(256, 256, 32, 32, DARKGRAY, WHITE); 39 | Texture tx = LoadTextureFromImage(img); 40 | UnloadImage(img); 41 | SetTextureFilter(tx, TEXTURE_FILTER_ANISOTROPIC_16X); 42 | SetTextureWrap(tx, TEXTURE_WRAP_CLAMP); 43 | 44 | Mesh cube = GenMeshCube(1, 1, 1); 45 | Material greenMaterial = LoadMaterialDefault(); 46 | greenMaterial.maps[MATERIAL_MAP_ALBEDO].color = GREEN; 47 | greenMaterial.maps[MATERIAL_MAP_ALBEDO].texture = tx; 48 | 49 | Material brownMaterial = LoadMaterialDefault(); 50 | brownMaterial.maps[MATERIAL_MAP_ALBEDO].color = BROWN; 51 | brownMaterial.maps[MATERIAL_MAP_ALBEDO].texture = tx; 52 | 53 | 54 | // setup initial camera data 55 | rlFPCamera cam; 56 | rlFPCameraInit(&cam, 45, (Vector3) { 1, 0, 0 }); 57 | cam.MoveSpeed.z = 10; 58 | cam.MoveSpeed.x = 5; 59 | 60 | cam.FarPlane = 5000; 61 | 62 | // Main game loop 63 | while (!WindowShouldClose()) // Detect window close button or ESC key 64 | { 65 | if (IsKeyPressed(KEY_F1)) 66 | cam.AllowFlight = !cam.AllowFlight; 67 | 68 | rlFPCameraUpdate(&cam); 69 | BeginDrawing(); 70 | ClearBackground(SKYBLUE); 71 | 72 | rlFPCameraBeginMode3D(&cam); 73 | 74 | // grid of cube trees on a plane to make a "world" 75 | DrawPlane((Vector3) { 0, 0, 0 }, (Vector2) { 50, 50 }, BEIGE); // simple world plane 76 | float spacing = 4; 77 | int count = 5; 78 | 79 | for (float x = -count * spacing; x <= count * spacing; x += spacing) 80 | { 81 | for (float z = -count * spacing; z <= count * spacing; z += spacing) 82 | { 83 | Matrix transform = MatrixTranslate(x, 1.5f, z); 84 | DrawMesh(cube, greenMaterial, transform); 85 | 86 | transform = MatrixTranslate(x, 0.5f, z); 87 | transform = MatrixMultiply(MatrixScale(0.25, 1, 0.25), transform); 88 | DrawMesh(cube, brownMaterial, transform); 89 | } 90 | } 91 | 92 | rlFPCameraEndMode3D(); 93 | 94 | if (cam.AllowFlight) 95 | DrawText("(F1) Flight", 2, 20, 20, BLACK); 96 | else 97 | DrawText("(F1) Running", 2, 20, 20, BLACK); 98 | // instructions 99 | DrawFPS(0, 0); 100 | EndDrawing(); 101 | //---------------------------------------------------------------------------------- 102 | } 103 | 104 | UnloadMesh(cube); 105 | // De-Initialization 106 | //-------------------------------------------------------------------------------------- 107 | CloseWindow(); // Close window and OpenGL context 108 | //-------------------------------------------------------------------------------------- 109 | 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /cameras/rlTPCamera/README.md: -------------------------------------------------------------------------------- 1 | # rlTPCamera 2 | A simple third person camera controller for raylib 3 | 4 | # API 5 | All data for the third person camera is managed by the rlTPCamera structure. 6 | 7 | This structure is setup by calling rlTPCameraInit with a camera, FOV, and Position. 8 | ``` 9 | rlTPCameraInit(&camera, fov, pos); 10 | ``` 11 | 12 | The fov argument is the vertical field of view, 45degrees is a good starting point. The horizontal view will be computed using the aspect ratio of the screen. 13 | The position will be the inital location of the camera in world space. 14 | 15 | Once the camera is initalized, options in the camera structure can be set, such as view bob, speed, control keys, and render distance. 16 | 17 | Whenever a window, or render texture is resized rlTPCameraResizeView needs to be called for any cameras used in that space, to properly recompute the FOV. 18 | 19 | Once per frame rlTPCameraUpdate with the camera should be called, this will apply any input events and move the camera. 20 | Once a camera is updated it can be used on screen or in a render texture by calling. 21 | 22 | rlTPCameraBeginMode3D and rlTPCameraEndMode3D. These work just like BeginMode3d and EndMode3d for raylib cameras, but use the extended features of rlTPCamera 23 | 24 | 25 | -------------------------------------------------------------------------------- /cameras/rlTPCamera/rlTPCamera.c: -------------------------------------------------------------------------------- 1 | /********************************************************************************************** 2 | * 3 | * raylibExtras * Utilities and Shared Components for Raylib 4 | * 5 | * TPOrbitCamera * Third Person Camera Example 6 | * 7 | * LICENSE: MIT 8 | * 9 | * Copyright (c) 2021 Jeffery Myers 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | * SOFTWARE. 28 | * 29 | **********************************************************************************************/ 30 | 31 | 32 | #include "rlTPCamera.h" 33 | #include "raylib.h" 34 | #include "rlgl.h" 35 | #include 36 | #include 37 | 38 | static void ResizeTPOrbitCameraView(rlTPCamera* camera) 39 | { 40 | if (camera == NULL) 41 | return; 42 | 43 | float width = (float)GetScreenWidth(); 44 | float height = (float)GetScreenHeight(); 45 | 46 | camera->FOV.y = camera->ViewCamera.fovy; 47 | 48 | if (height != 0) 49 | camera->FOV.x = camera->FOV.y * (width / height); 50 | } 51 | 52 | void rlTPCameraInit(rlTPCamera* camera, float fovY, Vector3 position) 53 | { 54 | if (camera == NULL) 55 | return; 56 | 57 | camera->ControlsKeys[0] = 'W'; 58 | camera->ControlsKeys[1] = 'S'; 59 | camera->ControlsKeys[2] = 'D'; 60 | camera->ControlsKeys[3] = 'A'; 61 | camera->ControlsKeys[4] = 'E'; 62 | camera->ControlsKeys[5] = 'Q'; 63 | camera->ControlsKeys[6] = KEY_LEFT; 64 | camera->ControlsKeys[7] = KEY_RIGHT; 65 | camera->ControlsKeys[8] = KEY_UP; 66 | camera->ControlsKeys[9] = KEY_DOWN; 67 | camera->ControlsKeys[10] = KEY_LEFT_SHIFT; 68 | 69 | camera->MoveSpeed = (Vector3){ 3,3,3 }; 70 | camera->TurnSpeed = (Vector2){ 90,90 }; 71 | 72 | camera->MouseSensitivity = 600; 73 | 74 | camera->MinimumViewY = -89.0f; 75 | camera->MaximumViewY = 0.0f; 76 | 77 | camera->Focused = IsWindowFocused(); 78 | 79 | camera->CameraPullbackDistance = 5; 80 | 81 | camera->ViewAngles = (Vector2){ 0,0 }; 82 | 83 | camera->CameraPosition = position; 84 | camera->FOV.y = fovY; 85 | 86 | camera->ViewCamera.target = position; 87 | camera->ViewCamera.position = Vector3Add(camera->ViewCamera.target, (Vector3) { 0, 0, camera->CameraPullbackDistance }); 88 | camera->ViewCamera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; 89 | camera->ViewCamera.fovy = fovY; 90 | camera->ViewCamera.projection = CAMERA_PERSPECTIVE; 91 | 92 | camera->NearPlane = 0.01; 93 | camera->FarPlane = 1000.0; 94 | 95 | ResizeTPOrbitCameraView(camera); 96 | rlTPCameraUseMouse(camera, true, 1); 97 | } 98 | 99 | void rlTPCameraUseMouse(rlTPCamera* camera, bool useMouse, int button) 100 | { 101 | if (camera == NULL) 102 | return; 103 | 104 | camera->UseMouse = useMouse; 105 | camera->UseMouseButton = button; 106 | 107 | bool showCursor = !useMouse || button >= 0; 108 | 109 | if (!showCursor && IsWindowFocused()) 110 | DisableCursor(); 111 | else if (showCursor && IsWindowFocused()) 112 | EnableCursor(); 113 | } 114 | 115 | Vector3 rlTPCameraGetPosition(rlTPCamera* camera) 116 | { 117 | return camera->CameraPosition; 118 | } 119 | 120 | void rlTPCameraSetPosition(rlTPCamera* camera, Vector3 position) 121 | { 122 | camera->CameraPosition = position; 123 | } 124 | 125 | RLAPI Ray rlTPCameraGetViewRay(rlTPCamera* camera) 126 | { 127 | return (Ray) {camera->ViewCamera.position, Vector3Subtract(camera->ViewCamera.target, camera->ViewCamera.position)}; 128 | } 129 | 130 | static float GetSpeedForAxis(rlTPCamera* camera, rlTPCameraControls axis, float speed) 131 | { 132 | if (camera == NULL) 133 | return 0; 134 | 135 | int key = camera->ControlsKeys[axis]; 136 | if (key == -1) 137 | return 0; 138 | 139 | float factor = 1.0f; 140 | if (IsKeyDown(camera->ControlsKeys[SPRINT])) 141 | factor = 2; 142 | 143 | if (IsKeyDown(camera->ControlsKeys[axis])) 144 | return speed * GetFrameTime() * factor; 145 | 146 | return 0.0f; 147 | } 148 | 149 | void rlTPCameraUpdate(rlTPCamera* camera) 150 | { 151 | if (camera == NULL) 152 | return; 153 | 154 | if (IsWindowResized()) 155 | ResizeTPOrbitCameraView(camera); 156 | 157 | bool showCursor = !camera->UseMouse || camera->UseMouseButton >= 0; 158 | 159 | if (IsWindowFocused() != camera->Focused && !showCursor) 160 | { 161 | camera->Focused = IsWindowFocused(); 162 | if (camera->Focused) 163 | { 164 | DisableCursor(); 165 | } 166 | else 167 | { 168 | EnableCursor(); 169 | } 170 | } 171 | 172 | // Mouse movement detection 173 | Vector2 mousePositionDelta = GetMouseDelta(); 174 | float mouseWheelMove = GetMouseWheelMove(); 175 | 176 | // Keys input detection 177 | float direction[MOVE_DOWN + 1] = { -GetSpeedForAxis(camera,MOVE_FRONT,camera->MoveSpeed.z), 178 | -GetSpeedForAxis(camera,MOVE_BACK,camera->MoveSpeed.z), 179 | GetSpeedForAxis(camera,MOVE_RIGHT,camera->MoveSpeed.x), 180 | GetSpeedForAxis(camera,MOVE_LEFT,camera->MoveSpeed.x), 181 | GetSpeedForAxis(camera,MOVE_UP,camera->MoveSpeed.y), 182 | GetSpeedForAxis(camera,MOVE_DOWN,camera->MoveSpeed.y) }; 183 | 184 | bool useMouse = camera->UseMouse && (camera->UseMouseButton < 0 || IsMouseButtonDown(camera->UseMouseButton)); 185 | 186 | float turnRotation = GetSpeedForAxis(camera, TURN_RIGHT, camera->TurnSpeed.x) - GetSpeedForAxis(camera, TURN_LEFT, camera->TurnSpeed.x); 187 | float tiltRotation = GetSpeedForAxis(camera, TURN_UP, camera->TurnSpeed.y) - GetSpeedForAxis(camera, TURN_DOWN, camera->TurnSpeed.y); 188 | 189 | if (turnRotation != 0) 190 | camera->ViewAngles.x -= turnRotation * DEG2RAD; 191 | else if (useMouse && camera->Focused) 192 | camera->ViewAngles.x -= (mousePositionDelta.x / camera->MouseSensitivity); 193 | 194 | if (tiltRotation) 195 | camera->ViewAngles.y += tiltRotation * DEG2RAD; 196 | else if (useMouse && camera->Focused) 197 | camera->ViewAngles.y += (mousePositionDelta.y / -camera->MouseSensitivity); 198 | 199 | // Angle clamp 200 | if (camera->ViewAngles.y < camera->MinimumViewY * DEG2RAD) 201 | camera->ViewAngles.y = camera->MinimumViewY * DEG2RAD; 202 | else if (camera->ViewAngles.y > camera->MaximumViewY * DEG2RAD) 203 | camera->ViewAngles.y = camera->MaximumViewY * DEG2RAD; 204 | 205 | //movement in plane rotation space 206 | Vector3 moveVec = { 0,0,0 }; 207 | moveVec.z = direction[MOVE_FRONT] - direction[MOVE_BACK]; 208 | moveVec.x = direction[MOVE_RIGHT] - direction[MOVE_LEFT]; 209 | 210 | // update zoom 211 | camera->CameraPullbackDistance += GetMouseWheelMove(); 212 | if (camera->CameraPullbackDistance < 1) 213 | camera->CameraPullbackDistance = 1; 214 | 215 | // vector we are going to transform to get the camera offset from the target point 216 | Vector3 camPos = { 0, 0, camera->CameraPullbackDistance }; 217 | 218 | Matrix tiltMat = MatrixRotateX(camera->ViewAngles.y); // a matrix for the tilt rotation 219 | Matrix rotMat = MatrixRotateY(camera->ViewAngles.x); // a matrix for the plane rotation 220 | Matrix mat = MatrixMultiply(tiltMat, rotMat); // the combined transformation matrix for the camera position 221 | 222 | camPos = Vector3Transform(camPos, mat); // transform the camera position into a vector in world space 223 | moveVec = Vector3Transform(moveVec, rotMat); // transform the movement vector into world space, but ignore the tilt so it is in plane 224 | 225 | camera->CameraPosition = Vector3Add(camera->CameraPosition, moveVec); // move the target to the moved position 226 | 227 | // validate cam pos here 228 | 229 | // set the view camera 230 | camera->ViewCamera.target = camera->CameraPosition; 231 | camera->ViewCamera.position = Vector3Add(camera->CameraPosition, camPos); // offset the camera position by the vector from the target position 232 | } 233 | 234 | static void SetupCamera(rlTPCamera* camera, float aspect) 235 | { 236 | rlDrawRenderBatchActive(); // Draw Buffers (Only OpenGL 3+ and ES2) 237 | rlMatrixMode(RL_PROJECTION); // Switch to projection matrix 238 | rlPushMatrix(); // Save previous matrix, which contains the settings for the 2d ortho projection 239 | rlLoadIdentity(); // Reset current matrix (projection) 240 | 241 | if (camera->ViewCamera.projection == CAMERA_PERSPECTIVE) 242 | { 243 | // Setup perspective projection 244 | double top = RL_CULL_DISTANCE_NEAR * tan(camera->ViewCamera.fovy * 0.5 * DEG2RAD); 245 | double right = top * aspect; 246 | 247 | rlFrustum(-right, right, -top, top, camera->NearPlane, camera->FarPlane); 248 | } 249 | else if (camera->ViewCamera.projection == CAMERA_ORTHOGRAPHIC) 250 | { 251 | // Setup orthographic projection 252 | double top = camera->ViewCamera.fovy / 2.0; 253 | double right = top * aspect; 254 | 255 | rlOrtho(-right, right, -top, top, camera->NearPlane, camera->FarPlane); 256 | } 257 | 258 | // NOTE: zNear and zFar values are important when computing depth buffer values 259 | 260 | rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix 261 | rlLoadIdentity(); // Reset current matrix (modelview) 262 | 263 | // Setup Camera view 264 | Matrix matView = MatrixLookAt(camera->ViewCamera.position, camera->ViewCamera.target, camera->ViewCamera.up); 265 | rlMultMatrixf(MatrixToFloatV(matView).v); // Multiply modelview matrix by view matrix (camera) 266 | 267 | rlEnableDepthTest(); // Enable DEPTH_TEST for 3D 268 | } 269 | 270 | // start drawing using the camera, with near/far plane support 271 | void rlTPCameraBeginMode3D(rlTPCamera* camera) 272 | { 273 | if (camera == NULL) 274 | return; 275 | 276 | float aspect = (float)GetScreenWidth() / (float)GetScreenHeight(); 277 | SetupCamera(camera, aspect); 278 | } 279 | 280 | // end drawing with the camera 281 | void rlTPCameraEndMode3D() 282 | { 283 | EndMode3D(); 284 | } -------------------------------------------------------------------------------- /cameras/rlTPCamera/rlTPCamera.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************************** 2 | * 3 | * raylibExtras * Utilities and Shared Components for Raylib 4 | * 5 | * TPOrbitCamera * Third Person Camera Example 6 | * 7 | * LICENSE: MIT 8 | * 9 | * Copyright (c) 2021 Jeffery Myers 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | * SOFTWARE. 28 | * 29 | **********************************************************************************************/ 30 | 31 | 32 | #ifndef TP_CAMERA_H 33 | #define TP_CAMERA_H 34 | 35 | #include "raylib.h" 36 | #include "raymath.h" 37 | 38 | typedef enum 39 | { 40 | MOVE_FRONT = 0, 41 | MOVE_BACK, 42 | MOVE_RIGHT, 43 | MOVE_LEFT, 44 | MOVE_UP, 45 | MOVE_DOWN, 46 | TURN_LEFT, 47 | TURN_RIGHT, 48 | TURN_UP, 49 | TURN_DOWN, 50 | SPRINT, 51 | LAST_CONTROL 52 | }rlTPCameraControls; 53 | 54 | typedef struct 55 | { 56 | // keys used to control the camera 57 | int ControlsKeys[LAST_CONTROL]; 58 | 59 | // the speed in units/second to move 60 | // X = sidestep 61 | // Y = jump/fall 62 | // Z = forward 63 | Vector3 MoveSpeed; 64 | 65 | // the speed for turning when using keys to look 66 | // degrees/second 67 | Vector2 TurnSpeed; 68 | 69 | // use the mouse for looking? 70 | bool UseMouse; 71 | int UseMouseButton; 72 | 73 | // how many pixels equate out to an angle move, larger numbers mean slower, more accurate mouse 74 | float MouseSensitivity; 75 | 76 | // how far down can the camera look 77 | float MinimumViewY; 78 | 79 | // how far up can the camera look 80 | float MaximumViewY; 81 | 82 | // the position of the base of the camera (on the floor) 83 | // note that this will not be the view position because it is offset by the eye height. 84 | // this value is also not changed by the view bobble 85 | Vector3 CameraPosition; 86 | 87 | // how far from the target position to the camera's view point (the zoom) 88 | float CameraPullbackDistance; 89 | 90 | // the Raylib camera to pass to raylib view functions. 91 | Camera ViewCamera; 92 | 93 | // the vector in the ground plane that the camera is facing 94 | Vector3 ViewForward; 95 | 96 | // the field of view in X and Y 97 | Vector2 FOV; 98 | 99 | // state for view angles 100 | Vector2 ViewAngles; 101 | 102 | // state for window focus 103 | bool Focused; 104 | 105 | //clipping planes 106 | // note must use BeginModeFP3D and EndModeFP3D instead of BeginMode3D/EndMode3D for clipping planes to work 107 | double NearPlane; 108 | double FarPlane; 109 | }rlTPCamera; 110 | 111 | // called to initialize a camera to default values 112 | RLAPI void rlTPCameraInit(rlTPCamera* camera, float fovY, Vector3 position); 113 | 114 | // turn the use of mouselook on/off, also updates the cursor visibility and what button to use, set button to -1 to disable mouse 115 | RLAPI void rlTPCameraUseMouse(rlTPCamera* camera, bool useMouse, int button); 116 | 117 | // Get the camera's position in world (or game) space 118 | RLAPI Vector3 rlTPCameraGetPosition(rlTPCamera* camera); 119 | 120 | // Set the camera's position in world (or game) space 121 | RLAPI void rlTPCameraSetPosition(rlTPCamera* camera, Vector3 position); 122 | 123 | // returns the ray from the camera through the center of the view 124 | RLAPI Ray rlTPCameraGetViewRay(rlTPCamera* camera); 125 | 126 | // update the camera for the current frame 127 | RLAPI void rlTPCameraUpdate(rlTPCamera* camera); 128 | 129 | // start drawing using the camera, with near/far plane support 130 | RLAPI void rlTPCameraBeginMode3D(rlTPCamera* camera); 131 | 132 | // end drawing with the camera 133 | RLAPI void rlTPCameraEndMode3D(); 134 | 135 | #endif //TP_CAMERA_H 136 | -------------------------------------------------------------------------------- /cameras/rlTPCamera/samples/example.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * raylib [core] example - Third Person Orbit Camera Example 4 | * 5 | * Welcome to raylib! 6 | * 7 | * To test examples, just press F6 and execute raylib_compile_execute script 8 | * Note that compiled executable is placed in the same folder as .c file 9 | * 10 | * You can find all basic examples on C:\raylib\raylib\examples folder or 11 | * raylib official webpage: www.raylib.com 12 | * 13 | * Enjoy using raylib. :) 14 | * 15 | * This example has been created using raylib 1.0 (www.raylib.com) 16 | * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 17 | * 18 | * Copyright (c) 2014 Ramon Santamaria (@raysan5) 19 | * 20 | ********************************************************************************************/ 21 | 22 | #include "raylib.h" 23 | #include "raymath.h" 24 | #include "rlTPCamera.h" 25 | 26 | int main(int argc, char* argv[]) 27 | { 28 | // Initialization 29 | //-------------------------------------------------------------------------------------- 30 | int screenWidth = 800; 31 | int screenHeight = 800; 32 | 33 | InitWindow(screenWidth, screenHeight, "raylib [camera] example - third person orbit camera"); 34 | SetTargetFPS(60); 35 | //-------------------------------------------------------------------------------------- 36 | 37 | Image img = GenImageChecked(256, 256, 64, 64, LIGHTGRAY, WHITE); 38 | Texture tx = LoadTextureFromImage(img); 39 | 40 | Mesh cube = GenMeshCube(1, 1, 1); 41 | Material whiteMaterial = LoadMaterialDefault(); 42 | whiteMaterial.maps[MATERIAL_MAP_ALBEDO].color = WHITE; 43 | whiteMaterial.maps[MATERIAL_MAP_ALBEDO].texture = tx; 44 | 45 | // setup initial camera data 46 | rlTPCamera orbitCam; 47 | rlTPCameraInit(&orbitCam, 45, (Vector3){ 1, 0 ,0 }); 48 | orbitCam.ViewAngles.y = -15 * DEG2RAD; 49 | 50 | // Main game loop 51 | while (!WindowShouldClose()) // Detect window close button or ESC key 52 | { 53 | rlTPCameraUpdate(&orbitCam); 54 | 55 | BeginDrawing(); 56 | ClearBackground(SKYBLUE); 57 | 58 | rlTPCameraBeginMode3D(&orbitCam); 59 | 60 | // grid of cubes on a plane to make a "world" 61 | DrawPlane((Vector3){ 0,0,0 }, (Vector2){ 50,50 }, BLUE); // simple world plane 62 | float spacing = 3; 63 | int count = 5; 64 | 65 | for (float x = -count * spacing; x <= count * spacing; x += spacing) 66 | { 67 | for (float z = -count * spacing; z <= count * spacing; z += spacing) 68 | { 69 | DrawMesh(cube, whiteMaterial, MatrixTranslate(x, 0.5f, z)); 70 | } 71 | } 72 | 73 | // target point 74 | DrawSphere(orbitCam.CameraPosition, 0.25f, RED); 75 | 76 | rlTPCameraEndMode3D(); 77 | 78 | // instructions 79 | DrawText("Right drag to rotate, Wheel to zoom, WASD to move", 100, 760, 20, GREEN); 80 | DrawFPS(0, 0); 81 | EndDrawing(); 82 | //---------------------------------------------------------------------------------- 83 | } 84 | 85 | UnloadTexture(tx); 86 | UnloadMesh(cube); 87 | // De-Initialization 88 | //-------------------------------------------------------------------------------------- 89 | CloseWindow(); // Close window and OpenGL context 90 | //-------------------------------------------------------------------------------------- 91 | 92 | return 0; 93 | } -------------------------------------------------------------------------------- /path_utils/app_dir.c: -------------------------------------------------------------------------------- 1 | /********************************************************************************************** 2 | * 3 | * raylibExtras * Utilities and Shared Components for Raylib 4 | * 5 | * path_utils * functions to help manage paths on different OSs 6 | * 7 | * LICENSE: MIT 8 | * 9 | * Copyright (c) 2020 Jeffery Myers 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | * SOFTWARE. 28 | * 29 | **********************************************************************************************/ 30 | 31 | #include 32 | #include 33 | 34 | #if defined(_WIN32) 35 | #ifndef MAX_PATH 36 | #define MAX_PATH 1025 37 | #endif 38 | 39 | 40 | void* LoadLibraryA(void* lpLibFileName); 41 | void* LoadLibraryW(void* lpLibFileName); 42 | 43 | #ifdef UNICODE 44 | #define LoadLibrary LoadLibraryW 45 | #else 46 | #define LoadLibrary LoadLibraryA 47 | #endif // !UNICODE 48 | 49 | void* GetProcAddress(void* hModule, void* lpProcName); 50 | 51 | void* GetCurrentProcess(void); 52 | bool FreeLibrary(void* hLibModule); 53 | 54 | int WideCharToMultiByte(unsigned int cp, unsigned long flags, const unsigned short* widestr, int cchwide, char* str, int cbmb, const char* defchar, int* used_default); 55 | 56 | const char PathDelim = '\\'; 57 | 58 | #elif defined(__linux__) 59 | #include 60 | const char PathDelim = '/'; 61 | 62 | #elif defined(__APPLE__) 63 | #include 64 | const char PathDelim = '/'; 65 | 66 | #endif // OSs 67 | 68 | char appDir[4096 + 1] = { 0 }; 69 | 70 | const char* rlGetApplicationBasePath() 71 | { 72 | if (appDir[0] == 0) 73 | { 74 | appDir[0] = '/' ; // default for everyone to start out with 75 | 76 | #if defined(_WIN32) 77 | typedef unsigned long(*GetModuleFileNameFunc)(void*, void*, void*, unsigned long); 78 | GetModuleFileNameFunc getModuleFileNameExWPtr = NULL; 79 | void* lib = LoadLibrary(L"psapi.dll"); 80 | if (lib == NULL) 81 | { 82 | appDir[0] = '\\'; 83 | } 84 | else 85 | { 86 | #if defined (UNICODE) 87 | getModuleFileNameExWPtr = (GetModuleFileNameFunc)GetProcAddress(lib, "GetModuleFileNameExW"); 88 | #else 89 | getModuleFileNameExWPtr = (GetModuleFileNameFunc)GetProcAddress(lib, "GetModuleFileNameExA"); 90 | #endif 91 | 92 | if (getModuleFileNameExWPtr == NULL) 93 | { 94 | appDir[0] = '\\'; 95 | } 96 | else 97 | { 98 | int len = 0; 99 | #if defined (UNICODE) 100 | unsigned short widePath[MAX_PATH]; 101 | len = getModuleFileNameExWPtr(GetCurrentProcess(), NULL, widePath, MAX_PATH); 102 | 103 | len = WideCharToMultiByte(0, 0, widePath, len, appDir, MAX_PATH, NULL, NULL); 104 | #else 105 | len = getModuleFileNameExWPtr(GetCurrentProcess(), NULL, appDir, MAX_PATH); 106 | #endif 107 | if (len > 0) 108 | { 109 | for (int i = len; i >= 0; --i) 110 | { 111 | if (appDir[i] == '\\') 112 | { 113 | appDir[i + 1] = '\0'; 114 | i = -1; 115 | } 116 | } 117 | } 118 | } 119 | FreeLibrary(lib); 120 | } 121 | #elif defined(__linux__) 122 | unsigned int size = sizeof(appDir); 123 | 124 | ssize_t len = readlink("/proc/self/exe", appDir, size); 125 | if (len > 0) 126 | { 127 | for (int i = len; i >= 0; --i) 128 | { 129 | if (appDir[i] == '/') 130 | { 131 | appDir[i + 1] = '\0'; 132 | i = -1; 133 | } 134 | } 135 | } 136 | 137 | #elif defined(__APPLE__) 138 | uint32_t size = sizeof(appDir); 139 | 140 | if (_NSGetExecutablePath(appDir, &size) == 0) 141 | { 142 | int len = strlen(appDir); 143 | for (int i = len; i >= 0; --i) 144 | { 145 | if (appDir[i] == '/') 146 | { 147 | appDir[i + 1] = '\0'; 148 | i = -1; 149 | } 150 | } 151 | } 152 | #endif 153 | } 154 | return appDir; 155 | } -------------------------------------------------------------------------------- /path_utils/app_dir.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************************** 2 | * 3 | * raylibExtras * Utilities and Shared Components for Raylib 4 | * 5 | * RLAssets * Simple Asset Managment System for Raylib 6 | * 7 | * LICENSE: MIT 8 | * 9 | * Copyright (c) 2020 Jeffery Myers 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | * SOFTWARE. 28 | * 29 | **********************************************************************************************/ 30 | 31 | #pragma once 32 | 33 | /// 34 | /// Gets the application (exe) directory for the currently running program 35 | /// This can then be passed to ChangeDirectory in raylib to make the working directory relative to the exe location 36 | /// 37 | /// The path on disk in the current OSs format 38 | const char* rlGetApplicationBasePath(); -------------------------------------------------------------------------------- /path_utils/resource_dir.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************************** 2 | * 3 | * raylibExtras * Utilities and Shared Components for Raylib 4 | * 5 | * Resource Dir * function to help find resource dir in common locations 6 | * 7 | * LICENSE: MIT 8 | * 9 | * Copyright (c) 2022 Jeffery Myers 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | * SOFTWARE. 28 | * 29 | **********************************************************************************************/ 30 | 31 | #pragma once 32 | 33 | #include "raylib.h" 34 | 35 | #if defined(__cplusplus) 36 | extern "C" { // Prevents name mangling of functions 37 | #endif 38 | /// 39 | /// Looks for the specified resource dir in several common locations 40 | /// The working dir 41 | /// The app dir 42 | /// Up to 3 levels above the app dir 43 | /// When found the dir will be set as the working dir so that assets can be loaded relative to that. 44 | /// 45 | /// The name of the resources dir to look for 46 | /// True if a dir with the name was found, false if no change was made to the working dir 47 | inline bool SearchAndSetResourceDir(const char* folderName) 48 | { 49 | // check the working dir 50 | if (DirectoryExists(folderName)) 51 | { 52 | ChangeDirectory(TextFormat("%s/%s", GetWorkingDirectory(), folderName)); 53 | return true; 54 | } 55 | 56 | const char* appDir = GetApplicationDirectory(); 57 | 58 | // check the applicationDir 59 | const char* dir = TextFormat("%s%s", appDir, folderName); 60 | if (DirectoryExists(dir)) 61 | { 62 | ChangeDirectory(dir); 63 | return true; 64 | } 65 | 66 | // check one up from the app dir 67 | dir = TextFormat("%s../%s", appDir, folderName); 68 | if (DirectoryExists(dir)) 69 | { 70 | ChangeDirectory(dir); 71 | return true; 72 | } 73 | 74 | // check two up from the app dir 75 | dir = TextFormat("%s../../%s", appDir, folderName); 76 | if (DirectoryExists(dir)) 77 | { 78 | ChangeDirectory(dir); 79 | return true; 80 | } 81 | 82 | // check three up from the app dir 83 | dir = TextFormat("%s../../../%s", appDir, folderName); 84 | if (DirectoryExists(dir)) 85 | { 86 | ChangeDirectory(dir); 87 | return true; 88 | } 89 | 90 | return false; 91 | } 92 | 93 | #if defined(__cplusplus) 94 | } 95 | #endif -------------------------------------------------------------------------------- /path_utils/samples/application_dir/main.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * 3 | * raylib extras samples * application path sample 4 | * 5 | * Welcome to raylib! 6 | * 7 | * Shows how to get the folder your game is running in 8 | * 9 | * You can find all basic examples on C:\raylib\raylib\examples folder or 10 | * raylib official webpage: www.raylib.com 11 | * 12 | * Enjoy using raylib. :) 13 | * 14 | * This example has been created using raylib 1.0 (www.raylib.com) 15 | * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) 16 | * 17 | * Copyright (c) 2014 Ramon Santamaria (@raysan5) 18 | * 19 | ********************************************************************************************/ 20 | 21 | #include "app_dir.h" 22 | #include "raylib.h" 23 | 24 | #include 25 | 26 | int main(int argc, char* argv[]) 27 | { 28 | // get the app path 29 | const char *appPath = rlGetApplicationBasePath(); 30 | printf("application path = %s\n", appPath); 31 | 32 | // tell raylib to use this path as the new root 33 | ChangeDirectory(appPath); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /premake-VisualStudio.bat: -------------------------------------------------------------------------------- 1 | premake5.exe vs2022 2 | pause 3 | -------------------------------------------------------------------------------- /premake-mingw.bat: -------------------------------------------------------------------------------- 1 | premake5.exe gmake2 2 | pause 3 | -------------------------------------------------------------------------------- /premake5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raylib-extras/extras-c/1091d52de0ad1b1abf5157f0e0766b51655cc006/premake5 -------------------------------------------------------------------------------- /premake5.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raylib-extras/extras-c/1091d52de0ad1b1abf5157f0e0766b51655cc006/premake5.exe -------------------------------------------------------------------------------- /premake5.lua: -------------------------------------------------------------------------------- 1 | newoption 2 | { 3 | trigger = "graphics", 4 | value = "OPENGL_VERSION", 5 | description = "version of OpenGL to build raylib against", 6 | allowed = { 7 | { "opengl11", "OpenGL 1.1"}, 8 | { "opengl21", "OpenGL 2.1"}, 9 | { "opengl33", "OpenGL 3.3"}, 10 | { "opengl43", "OpenGL 4.3"} 11 | }, 12 | default = "opengl33" 13 | } 14 | 15 | function define_C() 16 | language "C" 17 | end 18 | 19 | function define_Cpp() 20 | language "C++" 21 | end 22 | 23 | function string.starts(String,Start) 24 | return string.sub(String,1,string.len(Start))==Start 25 | end 26 | 27 | function link_to(lib) 28 | links (lib) 29 | includedirs ("../"..lib.."/include", "../"..lib.."/" ) 30 | end 31 | 32 | function download_progress(total, current) 33 | local ratio = current / total; 34 | ratio = math.min(math.max(ratio, 0), 1); 35 | local percent = math.floor(ratio * 100); 36 | print("Download progress (" .. percent .. "%/100%)") 37 | end 38 | 39 | function check_raylib() 40 | if(os.isdir("raylib") == false and os.isdir("raylib-master") == false) then 41 | if(not os.isfile("raylib-master.zip")) then 42 | print("Raylib not found, downloading from github") 43 | local result_str, response_code = http.download("https://github.com/raysan5/raylib/archive/refs/heads/master.zip", "raylib-master.zip", { 44 | progress = download_progress, 45 | headers = { "From: Premake", "Referer: Premake" } 46 | }) 47 | end 48 | print("Unzipping to " .. os.getcwd()) 49 | zip.extract("raylib-master.zip", os.getcwd()) 50 | os.remove("raylib-master.zip") 51 | end 52 | end 53 | 54 | workspace "raylib-extras-c" 55 | configurations { "Debug", "Release"} 56 | platforms { "x64", "x86"} 57 | 58 | filter "configurations:Debug" 59 | defines { "DEBUG" } 60 | symbols "On" 61 | 62 | filter "configurations:Release" 63 | defines { "NDEBUG" } 64 | optimize "On" 65 | 66 | filter { "platforms:x64" } 67 | architecture "x86_64" 68 | 69 | filter {} 70 | 71 | targetdir "_bin/%{cfg.buildcfg}/" 72 | 73 | startproject('rlFPCamera_sample') 74 | 75 | cdialect "C99" 76 | cppdialect "C++11" 77 | check_raylib() 78 | 79 | include ("raylib_premake5.lua") 80 | 81 | project "rlFPCamera" 82 | kind "StaticLib" 83 | 84 | location "_build" 85 | targetdir "_bin/%{cfg.buildcfg}" 86 | language "C" 87 | 88 | vpaths 89 | { 90 | ["Header Files"] = { "cameras/rlFPCamera/*.h"}, 91 | ["Source Files"] = {"cameras/rlFPCamera/*.c"}, 92 | } 93 | files {"cameras/rlFPCamera/*.c","cameras/rlFPCamera/*.h"} 94 | include_raylib() 95 | 96 | project "rlTPCamera" 97 | kind "StaticLib" 98 | 99 | location "_build" 100 | targetdir "_bin/%{cfg.buildcfg}" 101 | language "C" 102 | 103 | includedirs { "raylib/src"} 104 | vpaths 105 | { 106 | ["Header Files"] = { "cameras/rlTPCamera/*.h"}, 107 | ["Source Files"] = {"cameras/rlTPCamera/*.c"}, 108 | } 109 | files {"cameras/rlTPCamera/*.c","cameras/rlTPCamera/*.h"} 110 | include_raylib() 111 | 112 | project "path_utils" 113 | kind "StaticLib" 114 | 115 | location "_build" 116 | targetdir "_bin/%{cfg.buildcfg}" 117 | language "C" 118 | 119 | vpaths 120 | { 121 | ["Header Files"] = { "path_utils/*.h"}, 122 | ["Source Files"] = {"path_utils/*.c"}, 123 | } 124 | files {"path_utils/*.c","path_utils/*.h"} 125 | include_raylib() 126 | 127 | group "Examples" 128 | project "rlFPCamera_sample" 129 | kind "ConsoleApp" 130 | location "_build" 131 | targetdir "_bin/%{cfg.buildcfg}" 132 | language "C" 133 | 134 | vpaths 135 | { 136 | ["Header Files"] = { "cameras/rlFPCamera/samples/*.h"}, 137 | ["Source Files"] = {"cameras/rlFPCamera/samples/*.c" }, 138 | } 139 | files {"cameras/rlFPCamera/samples/*.c"} 140 | 141 | links {"rlFPCamera"} 142 | 143 | includedirs {"./", "cameras/rlFPCamera" } 144 | 145 | link_raylib(); 146 | 147 | 148 | project "rlTPCamera_sample" 149 | kind "ConsoleApp" 150 | location "_build" 151 | targetdir "_bin/%{cfg.buildcfg}" 152 | language "C" 153 | 154 | vpaths 155 | { 156 | ["Header Files"] = { "cameras/rlTPCamera/samples/*.h"}, 157 | ["Source Files"] = {"cameras/rlTPCamera/samples/*.c" }, 158 | } 159 | files {"cameras/rlTPCamera/samples/*.c"} 160 | 161 | links {"rlTPCamera"} 162 | 163 | includedirs {"./", "cameras/rlTPCamera" } 164 | 165 | link_raylib() 166 | 167 | project "application_dir_sample" 168 | kind "ConsoleApp" 169 | location "_build" 170 | targetdir "_bin/%{cfg.buildcfg}" 171 | language "C" 172 | 173 | vpaths 174 | { 175 | ["Header Files"] = { "path_utils/samples/application_dir/*.h"}, 176 | ["Source Files"] = {"path_utils/samples/application_dir/*.c" }, 177 | } 178 | files {"path_utils/samples/application_dir/*.c"} 179 | 180 | links {"path_utils"} 181 | 182 | includedirs {"path_utils" } 183 | 184 | link_raylib() 185 | -------------------------------------------------------------------------------- /premake5.osx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raylib-extras/extras-c/1091d52de0ad1b1abf5157f0e0766b51655cc006/premake5.osx -------------------------------------------------------------------------------- /ray_collision_2d.h: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************************* 3 | * 4 | * 2d ray collisions 5 | * 6 | * Copyright (c) 2022 Jeffery Myers 7 | * 8 | ********************************************************************************************/ 9 | 10 | 11 | // define RAY2D_COLLISION_IMPLEMENTATION in one and only one c/cpp files 12 | 13 | #pragma once 14 | 15 | #include "raylib.h" 16 | #include "raymath.h" 17 | #include "stdlib.h" 18 | 19 | #if defined(__cplusplus) 20 | extern "C" 21 | { 22 | #endif 23 | 24 | typedef struct 25 | { 26 | Vector2 Origin; 27 | Vector2 Direction; 28 | }Ray2d; 29 | 30 | bool CheckCollisionRay2dRay2d(Ray2d ray1, Ray2d ray2, float* length); 31 | bool CheckCollisionRay2dRect(Ray2d ray, Rectangle rect, Vector2* intersection); 32 | bool CheckCollisionRay2dCircle(Ray2d ray, Vector2 center, float radius, Vector2* intersection); 33 | bool CheckCollisionRay2dPoly(Ray2d ray, Vector2* points, int pointCount, Vector2* intersection); 34 | 35 | #ifdef RAY2D_COLLISION_IMPLEMENTATION 36 | 37 | // https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect/565282 38 | 39 | bool CheckCollisionRay2dRay2d(Ray2d ray1, Ray2d ray2, float* length) 40 | { 41 | float rXs = (ray1.Direction.x * ray2.Direction.y) - (ray1.Direction.y * ray2.Direction.x); 42 | 43 | Vector2 qp = Vector2Subtract(ray2.Origin, ray1.Origin); 44 | 45 | float qpXs = (qp.x * ray2.Direction.y) - (qp.y * ray2.Direction.x); 46 | float qpXr = (qp.x * ray1.Direction.y) - (qp.y * ray1.Direction.x); 47 | 48 | if (rXs != 0.0f) 49 | { 50 | float inverseRxS = 1.0f / rXs; 51 | 52 | float t = qpXs * inverseRxS, u = qpXr * inverseRxS; 53 | 54 | if ((t >= 0.0f && t <= 1.0f) && (u >= 0.0f && u <= 1.0f)) 55 | { 56 | if (length) 57 | { 58 | *length = t; 59 | } 60 | 61 | return true; 62 | } 63 | } 64 | else 65 | { 66 | if (qpXr != 0.0f) return false; 67 | 68 | float rDr = Vector2DotProduct(ray1.Direction, ray1.Direction); 69 | float sDr = Vector2DotProduct(ray2.Direction, ray1.Direction); 70 | 71 | float inverseRdR = 1.0f / rDr; 72 | 73 | float qpDr = Vector2DotProduct(qp, ray1.Direction); 74 | 75 | float t0 = qpDr * inverseRdR, t1 = t0 + sDr * inverseRdR; 76 | 77 | if (sDr < 0.0f) 78 | { 79 | float tmp = t0; 80 | 81 | t0 = t1, t1 = tmp; 82 | } 83 | 84 | if ((t0 < 0.0f && t1 == 0.0f) || (t0 == 1.0f && t1 > 1.0f)) 85 | { 86 | if (length) 87 | { 88 | *length = (t0 == 1.0f); 89 | } 90 | 91 | return true; 92 | } 93 | 94 | if (t1 >= 0.0f && t0 <= 1.0f) 95 | { 96 | // the rays are collinear and overlapping 97 | return false; 98 | } 99 | 100 | return false; 101 | } 102 | } 103 | 104 | // intersection using the slab method 105 | // https://tavianator.com/2011/ray_box.html#:~:text=The%20fastest%20method%20for%20performing,remains%2C%20it%20intersected%20the%20box. 106 | 107 | bool CheckCollisionRay2dRect(Ray2d ray, Rectangle rect, Vector2* intersection) 108 | { 109 | float minParam = -INFINITY, maxParam = INFINITY; 110 | 111 | if (ray.Direction.x != 0.0) 112 | { 113 | float txMin = (rect.x - ray.Origin.x) / ray.Direction.x; 114 | float txMax = ((rect.x + rect.width) - ray.Origin.x) / ray.Direction.x; 115 | 116 | minParam = fmax(minParam, fmin(txMin, txMax)); 117 | maxParam = fmin(maxParam, fmax(txMin, txMax)); 118 | } 119 | 120 | if (ray.Direction.y != 0.0) 121 | { 122 | float tyMin = (rect.y - ray.Origin.y) / ray.Direction.y; 123 | float tyMax = ((rect.y + rect.height) - ray.Origin.y) / ray.Direction.y; 124 | 125 | minParam = fmax(minParam, fmin(tyMin, tyMax)); 126 | maxParam = fmin(maxParam, fmax(tyMin, tyMax)); 127 | } 128 | 129 | // if maxParam < 0, ray is intersecting AABB, but the whole AABB is behind us 130 | if (maxParam < 0) 131 | { 132 | return false; 133 | } 134 | 135 | // if minParam > maxParam, ray doesn't intersect AABB 136 | if (minParam > maxParam) 137 | { 138 | return false; 139 | } 140 | 141 | if (intersection != NULL) 142 | { 143 | *intersection = Vector2Add(ray.Origin, Vector2Scale(ray.Direction, minParam)); 144 | } 145 | 146 | return true; 147 | } 148 | 149 | bool CheckCollisionRay2dCircle(Ray2d ray, Vector2 center, float radius, Vector2* intersection) 150 | { 151 | if (CheckCollisionPointCircle(ray.Origin, center, radius)) 152 | { 153 | if (intersection) 154 | *intersection = ray.Origin; 155 | 156 | return true; 157 | } 158 | 159 | Vector2 vecToCenter = Vector2Subtract(center, ray.Origin); 160 | float dot = Vector2DotProduct(vecToCenter, ray.Direction); 161 | 162 | Vector2 nearest = Vector2Add(ray.Origin, Vector2Scale(ray.Direction, dot)); 163 | 164 | float distSq = Vector2LengthSqr(Vector2Subtract(nearest, center)); 165 | 166 | if (distSq <= radius * radius) 167 | { 168 | if (intersection) 169 | { 170 | float nearestDist = Vector2Length(Vector2Subtract(center, nearest)); 171 | 172 | float b = sqrtf(radius * radius - nearestDist * nearestDist); 173 | 174 | *intersection = (Vector2){ ray.Origin.x + ray.Direction.x * (dot - b), ray.Origin.y + ray.Direction.y * (dot - b) }; 175 | } 176 | } 177 | 178 | return false; 179 | } 180 | 181 | bool CheckCollisionRay2dPoly(Ray2d ray, Vector2* points, int pointCount, Vector2* intersection) 182 | { 183 | if (points == NULL || pointCount < 3) 184 | { 185 | return false; 186 | } 187 | 188 | Vector2 result = { INFINITY, INFINITY }; 189 | 190 | float distSq = INFINITY; 191 | 192 | for (int j = pointCount - 1, i = 0; i < pointCount; j = i, i++) 193 | { 194 | Ray2d edgeRay = { 195 | .Origin = points[i], 196 | .Direction = Vector2Subtract(points[j], points[i]) 197 | }; 198 | 199 | float length = -INFINITY; 200 | 201 | bool intersect = CheckCollisionRay2dRay2d(ray, edgeRay, &length); 202 | 203 | Vector2 nearest = Vector2Add(ray.Origin, Vector2Scale(ray.Direction, length)); 204 | 205 | float nearestDistSq = Vector2DistanceSqr(ray.Origin, nearest); 206 | 207 | if (distSq > nearestDistSq) 208 | { 209 | result = nearest, distSq = nearestDistSq; 210 | } 211 | } 212 | 213 | if (distSq == INFINITY) 214 | { 215 | return false; 216 | } 217 | 218 | if (intersection) 219 | { 220 | *intersection = result; 221 | } 222 | 223 | return true; 224 | } 225 | 226 | #endif //RAY2D_COLLISION_IMPLEMENTATION 227 | 228 | #if defined(__cplusplus) 229 | } 230 | #endif -------------------------------------------------------------------------------- /raylib_premake5.lua: -------------------------------------------------------------------------------- 1 | 2 | function platform_defines() 3 | defines{"PLATFORM_DESKTOP"} 4 | 5 | filter {"options:graphics=opengl43"} 6 | defines{"GRAPHICS_API_OPENGL_43"} 7 | 8 | filter {"options:graphics=opengl33"} 9 | defines{"GRAPHICS_API_OPENGL_33"} 10 | 11 | filter {"options:graphics=opengl21"} 12 | defines{"GRAPHICS_API_OPENGL_21"} 13 | 14 | filter {"options:graphics=opengl11"} 15 | defines{"GRAPHICS_API_OPENGL_11"} 16 | 17 | filter {"system:macosx"} 18 | disablewarnings {"deprecated-declarations"} 19 | 20 | filter {"system:linux"} 21 | defines {"_GNU_SOURCE"} 22 | -- This is necessary, otherwise compilation will fail since 23 | -- there is no CLOCK_MONOTOMIC. raylib claims to have a workaround 24 | -- to compile under c99 without -D_GNU_SOURCE, but it didn't seem 25 | -- to work. raylib's Makefile also adds this flag, probably why it went 26 | -- unnoticed for so long. 27 | -- It compiles under c11 without -D_GNU_SOURCE, because c11 requires 28 | -- to have CLOCK_MONOTOMIC 29 | -- See: https://github.com/raysan5/raylib/issues/2729 30 | 31 | filter{} 32 | end 33 | 34 | function get_raylib_dir() 35 | if (os.isdir("raylib-master")) then 36 | return "raylib-master" 37 | end 38 | if (os.isdir("../raylib-master")) then 39 | return "raylib-master" 40 | end 41 | return "raylib" 42 | end 43 | 44 | function link_raylib() 45 | links {"raylib"} 46 | 47 | raylib_dir = get_raylib_dir(); 48 | includedirs {raylib_dir .. "/src" } 49 | includedirs {raylib_dir .."/src/external" } 50 | includedirs {raylib_dir .."/src/external/glfw/include" } 51 | platform_defines() 52 | 53 | filter "action:vs*" 54 | defines{"_WINSOCK_DEPRECATED_NO_WARNINGS", "_CRT_SECURE_NO_WARNINGS"} 55 | dependson {"raylib"} 56 | links {"raylib.lib"} 57 | characterset ("MBCS") 58 | 59 | filter "system:windows" 60 | defines{"_WIN32"} 61 | links {"winmm", "kernel32", "opengl32", "gdi32"} 62 | libdirs {"_bin/%{cfg.buildcfg}"} 63 | 64 | filter "system:linux" 65 | links {"pthread", "GL", "m", "dl", "rt", "X11"} 66 | 67 | filter "system:macosx" 68 | links {"OpenGL.framework", "Cocoa.framework", "IOKit.framework", "CoreFoundation.framework", "CoreAudio.framework", "CoreVideo.framework"} 69 | 70 | filter{} 71 | end 72 | 73 | function include_raylib() 74 | raylib_dir = get_raylib_dir(); 75 | includedirs {raylib_dir .."/src" } 76 | includedirs {raylib_dir .."/src/external" } 77 | includedirs {raylib_dir .."/src/external/glfw/include" } 78 | platform_defines() 79 | 80 | filter "action:vs*" 81 | defines{"_WINSOCK_DEPRECATED_NO_WARNINGS", "_CRT_SECURE_NO_WARNINGS"} 82 | 83 | filter{} 84 | end 85 | 86 | project "raylib" 87 | kind "StaticLib" 88 | 89 | platform_defines() 90 | 91 | location "_build" 92 | language "C" 93 | targetdir "_bin/%{cfg.buildcfg}" 94 | 95 | filter "action:vs*" 96 | defines{"_WINSOCK_DEPRECATED_NO_WARNINGS", "_CRT_SECURE_NO_WARNINGS"} 97 | characterset ("MBCS") 98 | 99 | filter{} 100 | 101 | raylib_dir = get_raylib_dir(); 102 | print ("Using raylib dir " .. raylib_dir); 103 | includedirs {raylib_dir .. "/src", raylib_dir .. "/src/external/glfw/include" } 104 | vpaths 105 | { 106 | ["Header Files"] = { raylib_dir .. "/src/**.h"}, 107 | ["Source Files/*"] = { raylib_dir .. "/src/**.c"}, 108 | } 109 | files {raylib_dir .. "/src/*.h", raylib_dir .. "/src/*.c"} 110 | 111 | removefiles {raylib_dir .. "/src/rcore_android.c", raylib_dir .. "/src/rcore_template.c", raylib_dir .. "/src/rcore_drm.c", raylib_dir .. "/src/rcore_web.c", raylib_dir .."/src/rcore_desktop.c"} 112 | 113 | filter { "system:macosx", "files:" .. raylib_dir .. "/src/rglfw.c" } 114 | compileas "Objective-C" 115 | 116 | filter{} 117 | -------------------------------------------------------------------------------- /raylib_win32.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************************** 2 | * 3 | * raylibExtras * Utilities and Shared Components for Raylib 4 | * 5 | * raylib_win32.h Utility to help include windows.h with raylibExtras 6 | * 7 | * Useage: #include "raylib_win32.h" before raylib or any library that uses windows.h 8 | * order is critical, this must be done before raylib 9 | * 10 | * LICENSE: MIT 11 | * 12 | * Copyright (c) 2024 Jeffery Myers 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in all 22 | * copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 | * SOFTWARE. 31 | * 32 | **********************************************************************************************/ 33 | 34 | #pragma once 35 | 36 | // move the windows functions to new names 37 | // note that you can't call these functions or structures from your code, but you should not neeed to 38 | #define CloseWindow CloseWindowWin32 39 | #define Rectangle RectangleWin32 40 | #define ShowCursor ShowCursorWin32 41 | #define LoadImageA LoadImageAWin32 42 | #define LoadImageW LoadImageWin32 43 | #define DrawTextA DrawTextAWin32 44 | #define DrawTextW DrawTextWin32 45 | #define DrawTextExA DrawTextExAWin32 46 | #define DrawTextExW DrawTextExWin32 47 | 48 | // include windows 49 | #define WIN32_LEAN_AND_MEAN 50 | #include 51 | 52 | // remove all our redfintions so that raylib can define them properly 53 | #undef CloseWindow 54 | #undef Rectangle 55 | #undef ShowCursor 56 | #undef LoadImage 57 | #undef LoadImageA 58 | #undef LoadImageW 59 | #undef DrawText 60 | #undef DrawTextA 61 | #undef DrawTextW 62 | #undef DrawTextEx 63 | #undef DrawTextExA 64 | #undef DrawTextExW --------------------------------------------------------------------------------