├── .gitignore ├── CMake-VS-16-2019.bat ├── CMake-VS-17-2022.bat ├── CMakeLists.txt ├── Document ├── Depth.png ├── Normal.png ├── Samples │ ├── 10-1.gif │ ├── 10-1c.gif │ ├── 10-2.gif │ ├── 11-1.gif │ ├── 11-1c.gif │ ├── 11-2.gif │ ├── 11-2c.gif │ ├── 11-3.gif │ ├── 11-3c.gif │ ├── 12-1.gif │ ├── 12-1c.gif │ ├── 12-2.gif │ ├── 12-2c.gif │ ├── 12-3.gif │ ├── 12-3c.gif │ ├── 12-4.gif │ ├── 12-4c.gif │ ├── 12-5.gif │ ├── 12-5c.gif │ ├── 13-1.gif │ ├── 13-1c.gif │ ├── 13-2.gif │ ├── 13-2c.gif │ ├── 13-3.gif │ ├── 13-3c.gif │ ├── 13-4.gif │ ├── 13-4c.gif │ ├── 13-5.gif │ ├── 13-5c.gif │ ├── 13-6.gif │ ├── 13-6c.gif │ ├── 16-1.gif │ ├── 16-1c.gif │ ├── 17-1.gif │ ├── 17-1c.gif │ ├── 17-2.gif │ ├── 17-2c.gif │ ├── 17-3.gif │ ├── 17-3c.gif │ ├── 3-1.gif │ ├── 3-1c.gif │ ├── 3-2.gif │ ├── 3-2c.gif │ ├── 4-1.gif │ ├── 4-1c.gif │ ├── 4-2.gif │ ├── 4-2c.gif │ ├── 4-3.gif │ ├── 4-3c.gif │ ├── 4-4.gif │ ├── 4-4c.gif │ ├── 4-5.gif │ ├── 4-5c.gif │ ├── 5-1.gif │ ├── 5-1c.gif │ ├── 5-2.gif │ ├── 5-2c.gif │ ├── 6-1.gif │ ├── 6-1c.gif │ ├── 7-1.gif │ ├── 7-1c.gif │ ├── 7-2.gif │ ├── 7-2c.gif │ ├── 7-3.gif │ ├── 7-3c.gif │ ├── 8-1.gif │ ├── 8-1c.gif │ ├── 8-2.gif │ ├── 8-2c.gif │ ├── 8-3.gif │ ├── 8-3c.gif │ ├── 8-3c.png │ ├── 8-4.gif │ ├── 8-4c.gif │ ├── 9-1.gif │ ├── 9-1c.gif │ ├── 9.gif │ └── main.gif ├── Wireframe1.png ├── Wireframe2.png ├── 로드맵.png └── 책그림.jpg ├── LICENSE ├── README.md ├── Resource └── CKMan.png └── Source ├── Player ├── CMakeLists.txt ├── Precompiled.cpp ├── Precompiled.h ├── Private │ ├── SystemInputManager.cpp │ └── Windows │ │ ├── Res │ │ ├── player.ico │ │ ├── player.rc │ │ ├── player_small.ico │ │ └── resource.h │ │ ├── WindowsApp.cpp │ │ ├── WindowsPlayer.h │ │ └── WindowsUtil.h ├── SoftRenderer.cpp ├── SoftRenderer.h ├── SoftRenderer2D.cpp ├── SoftRenderer3D.cpp └── SystemInputManager.h └── Runtime ├── Engine ├── CMakeLists.txt ├── Precompiled.cpp ├── Precompiled.h ├── Private │ ├── 2D │ │ ├── CameraObject.cpp │ │ ├── GameEngine.cpp │ │ ├── GameObject.cpp │ │ ├── Mesh.cpp │ │ └── TransformComponent.cpp │ ├── 3D │ │ ├── Bone.cpp │ │ ├── CameraObject.cpp │ │ ├── GameEngine.cpp │ │ ├── GameObject.cpp │ │ ├── Mesh.cpp │ │ └── TransformComponent.cpp │ ├── InputManager.cpp │ └── Texture.cpp ├── Public │ ├── 2D │ │ ├── CameraObject.h │ │ ├── GameEngine.h │ │ ├── GameObject.h │ │ ├── Mesh.h │ │ └── TransformComponent.h │ ├── 3D │ │ ├── Bone.h │ │ ├── CameraObject.h │ │ ├── GameEngine.h │ │ ├── GameObject.h │ │ ├── Mesh.h │ │ ├── Resources.h │ │ └── TransformComponent.h │ ├── EngineHeaders.h │ ├── EngineInterface.h │ ├── InputManager.h │ └── Texture.h └── ThirdParty │ └── Stb │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── github_url.txt │ ├── stb.h │ ├── stb_c_lexer.h │ ├── stb_connected_components.h │ ├── stb_divide.h │ ├── stb_ds.h │ ├── stb_dxt.h │ ├── stb_easy_font.h │ ├── stb_herringbone_wang_tile.h │ ├── stb_image.h │ ├── stb_image_resize.h │ ├── stb_image_write.h │ ├── stb_include.h │ ├── stb_leakcheck.h │ ├── stb_perlin.h │ ├── stb_rect_pack.h │ ├── stb_sprintf.h │ ├── stb_textedit.h │ ├── stb_tilemap_editor.h │ ├── stb_truetype.h │ ├── stb_vorbis.c │ ├── stb_voxel_render.h │ └── stretchy_buffer.h ├── Math ├── CMakeLists.txt ├── Precompiled.cpp ├── Precompiled.h ├── Private │ ├── Box.cpp │ ├── Circle.cpp │ ├── Color32.cpp │ ├── Frustum.cpp │ ├── LinearColor.cpp │ ├── Math.cpp │ ├── Matrix2x2.cpp │ ├── Matrix3x3.cpp │ ├── Matrix4x4.cpp │ ├── Plane.cpp │ ├── Quaternion.cpp │ ├── Rectangle.cpp │ ├── Rotator.cpp │ ├── Sphere.cpp │ ├── Transform.cpp │ ├── Vector2.cpp │ ├── Vector3.cpp │ └── Vector4.cpp └── Public │ ├── Box.h │ ├── Circle.h │ ├── Color32.h │ ├── CoreDefinition.h │ ├── Frustum.h │ ├── HSVColor.h │ ├── LinearColor.h │ ├── MathHeaders.h │ ├── MathUtil.h │ ├── Matrix2x2.h │ ├── Matrix3x3.h │ ├── Matrix4x4.h │ ├── Plane.h │ ├── Platform.h │ ├── Quaternion.h │ ├── Rectangle.h │ ├── Rotator.h │ ├── ScreenPoint.h │ ├── Sphere.h │ ├── Transform.h │ ├── Vector2.h │ ├── Vector3.h │ ├── Vector4.h │ └── Windows │ └── WindowsPlatform.h └── Renderer ├── CMakeLists.txt ├── Precompiled.cpp ├── Precompiled.h ├── Private ├── 2D │ ├── Shader.cpp │ └── Vertex.cpp ├── 3D │ ├── PerspectiveTest.cpp │ ├── Shader.cpp │ └── Vertex.cpp └── Windows │ ├── WindowsGDI.cpp │ └── WindowsRSI.cpp └── Public ├── 2D ├── Shader.h └── Vertex.h ├── 3D ├── PerspectiveTest.h ├── Shader.h └── Vertex.h ├── RendererHeaders.h ├── RendererInterface.h └── Windows ├── WindowsGDI.h └── WindowsRSI.h /.gitignore: -------------------------------------------------------------------------------- 1 | /Source/Player/Res/*.aps 2 | /Project 3 | /Output 4 | -------------------------------------------------------------------------------- /CMake-VS-16-2019.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | @echo: 4 | @echo [SoftRenderer Project Generator] 5 | @echo ------------------------------------------------- 6 | PUSHD %~dp0 7 | @echo Removing previous project folder. 8 | IF EXIST "Project" rd "Project" /s /q 9 | @echo: 10 | @echo Done! 11 | @echo: 12 | @echo ------------------------------------------------- 13 | IF NOT EXIST "Project" @echo Creating a new project folder. 14 | IF NOT EXIST "Project" md Project 15 | IF NOT EXIST "Project" @echo: 16 | cd Project 17 | @echo: 18 | @echo Done! 19 | @echo: 20 | @echo ------------------------------------------------- 21 | @echo Running CMAKE script. 22 | @echo: 23 | 24 | cmake -G "Visual Studio 16 2019" ..\ 25 | 26 | @echo: 27 | @echo Done! 28 | @echo: 29 | @echo ------------------------------------------------- 30 | @echo A new solution file is generated in %~dp0Project 31 | @echo: 32 | POPD 33 | PAUSE 34 | -------------------------------------------------------------------------------- /CMake-VS-17-2022.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | @echo: 4 | @echo [SoftRenderer Project Generator] 5 | @echo ------------------------------------------------- 6 | PUSHD %~dp0 7 | @echo Removing previous project folder. 8 | IF EXIST "Project" rd "Project" /s /q 9 | @echo: 10 | @echo Done! 11 | @echo: 12 | @echo ------------------------------------------------- 13 | IF NOT EXIST "Project" @echo Creating a new project folder. 14 | IF NOT EXIST "Project" md Project 15 | IF NOT EXIST "Project" @echo: 16 | cd Project 17 | @echo: 18 | @echo Done! 19 | @echo: 20 | @echo ------------------------------------------------- 21 | @echo Running CMAKE script. 22 | @echo: 23 | 24 | cmake -G "Visual Studio 17 2022" ..\ 25 | 26 | @echo: 27 | @echo Done! 28 | @echo: 29 | @echo ------------------------------------------------- 30 | @echo A new solution file is generated in %~dp0Project 31 | @echo: 32 | POPD 33 | PAUSE 34 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ########################################################## 2 | ## CMake Setting for SoftRenderer 3 | ########################################################## 4 | 5 | cmake_minimum_required(VERSION 3.1) 6 | 7 | set(CMAKE_CXX_STANDARD 17) 8 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 9 | 10 | include(CMakeDependentOption) 11 | set(MAIN_PROJECT_NAME SoftRenderer) 12 | 13 | project(${MAIN_PROJECT_NAME}) 14 | 15 | set(RUNTIME_MODULE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Source/Runtime) 16 | 17 | if(NOT WIN32) 18 | message(FATAL_ERROR "This project only supports windows environment currently.") 19 | endif() 20 | 21 | if(NOT MSVC) 22 | message(FATAL_ERROR "This project only supports MSVC project currently.") 23 | endif() 24 | 25 | set(PLATFORM_DEFINITION PLATFORM_GENERIC) 26 | set(PLATFORM_FOLDER Generic) 27 | 28 | option(TARGET_WINDOWS "Windows Option" ON) 29 | 30 | if(TARGET_WINDOWS) 31 | set(PLATFORM_DEFINITION PLATFORM_WINDOWS) 32 | set(PLATFORM_FOLDER Windows) 33 | endif() 34 | 35 | ################################################################################ 36 | # Sub projects 37 | ################################################################################ 38 | 39 | add_subdirectory(Source/Runtime/Math) 40 | add_subdirectory(Source/Runtime/Renderer) 41 | add_subdirectory(Source/Runtime/Engine) 42 | add_subdirectory(Source/Player) 43 | 44 | ################################################################################ 45 | # Definitions 46 | ################################################################################ 47 | target_compile_definitions(SoftRendererPlayer PUBLIC ${PLATFORM_DEFINITION} ${PLATFORM_FOLDER}) 48 | target_compile_definitions(EngineModule PUBLIC ${PLATFORM_DEFINITION} ${PLATFORM_FOLDER}) 49 | target_compile_definitions(RendererModule PUBLIC ${PLATFORM_DEFINITION} ${PLATFORM_FOLDER}) 50 | target_compile_definitions(MathModule PUBLIC ${PLATFORM_DEFINITION} ${PLATFORM_FOLDER}) 51 | 52 | ################################################################################ 53 | # Solution Setting 54 | ################################################################################ 55 | set(CMAKE_SUPPRESS_REGENERATION true) 56 | set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT SoftRendererPlayer) 57 | 58 | -------------------------------------------------------------------------------- /Document/Depth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Depth.png -------------------------------------------------------------------------------- /Document/Normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Normal.png -------------------------------------------------------------------------------- /Document/Samples/10-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/10-1.gif -------------------------------------------------------------------------------- /Document/Samples/10-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/10-1c.gif -------------------------------------------------------------------------------- /Document/Samples/10-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/10-2.gif -------------------------------------------------------------------------------- /Document/Samples/11-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/11-1.gif -------------------------------------------------------------------------------- /Document/Samples/11-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/11-1c.gif -------------------------------------------------------------------------------- /Document/Samples/11-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/11-2.gif -------------------------------------------------------------------------------- /Document/Samples/11-2c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/11-2c.gif -------------------------------------------------------------------------------- /Document/Samples/11-3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/11-3.gif -------------------------------------------------------------------------------- /Document/Samples/11-3c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/11-3c.gif -------------------------------------------------------------------------------- /Document/Samples/12-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/12-1.gif -------------------------------------------------------------------------------- /Document/Samples/12-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/12-1c.gif -------------------------------------------------------------------------------- /Document/Samples/12-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/12-2.gif -------------------------------------------------------------------------------- /Document/Samples/12-2c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/12-2c.gif -------------------------------------------------------------------------------- /Document/Samples/12-3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/12-3.gif -------------------------------------------------------------------------------- /Document/Samples/12-3c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/12-3c.gif -------------------------------------------------------------------------------- /Document/Samples/12-4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/12-4.gif -------------------------------------------------------------------------------- /Document/Samples/12-4c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/12-4c.gif -------------------------------------------------------------------------------- /Document/Samples/12-5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/12-5.gif -------------------------------------------------------------------------------- /Document/Samples/12-5c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/12-5c.gif -------------------------------------------------------------------------------- /Document/Samples/13-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-1.gif -------------------------------------------------------------------------------- /Document/Samples/13-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-1c.gif -------------------------------------------------------------------------------- /Document/Samples/13-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-2.gif -------------------------------------------------------------------------------- /Document/Samples/13-2c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-2c.gif -------------------------------------------------------------------------------- /Document/Samples/13-3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-3.gif -------------------------------------------------------------------------------- /Document/Samples/13-3c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-3c.gif -------------------------------------------------------------------------------- /Document/Samples/13-4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-4.gif -------------------------------------------------------------------------------- /Document/Samples/13-4c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-4c.gif -------------------------------------------------------------------------------- /Document/Samples/13-5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-5.gif -------------------------------------------------------------------------------- /Document/Samples/13-5c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-5c.gif -------------------------------------------------------------------------------- /Document/Samples/13-6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-6.gif -------------------------------------------------------------------------------- /Document/Samples/13-6c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/13-6c.gif -------------------------------------------------------------------------------- /Document/Samples/16-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/16-1.gif -------------------------------------------------------------------------------- /Document/Samples/16-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/16-1c.gif -------------------------------------------------------------------------------- /Document/Samples/17-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/17-1.gif -------------------------------------------------------------------------------- /Document/Samples/17-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/17-1c.gif -------------------------------------------------------------------------------- /Document/Samples/17-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/17-2.gif -------------------------------------------------------------------------------- /Document/Samples/17-2c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/17-2c.gif -------------------------------------------------------------------------------- /Document/Samples/17-3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/17-3.gif -------------------------------------------------------------------------------- /Document/Samples/17-3c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/17-3c.gif -------------------------------------------------------------------------------- /Document/Samples/3-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/3-1.gif -------------------------------------------------------------------------------- /Document/Samples/3-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/3-1c.gif -------------------------------------------------------------------------------- /Document/Samples/3-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/3-2.gif -------------------------------------------------------------------------------- /Document/Samples/3-2c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/3-2c.gif -------------------------------------------------------------------------------- /Document/Samples/4-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/4-1.gif -------------------------------------------------------------------------------- /Document/Samples/4-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/4-1c.gif -------------------------------------------------------------------------------- /Document/Samples/4-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/4-2.gif -------------------------------------------------------------------------------- /Document/Samples/4-2c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/4-2c.gif -------------------------------------------------------------------------------- /Document/Samples/4-3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/4-3.gif -------------------------------------------------------------------------------- /Document/Samples/4-3c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/4-3c.gif -------------------------------------------------------------------------------- /Document/Samples/4-4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/4-4.gif -------------------------------------------------------------------------------- /Document/Samples/4-4c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/4-4c.gif -------------------------------------------------------------------------------- /Document/Samples/4-5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/4-5.gif -------------------------------------------------------------------------------- /Document/Samples/4-5c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/4-5c.gif -------------------------------------------------------------------------------- /Document/Samples/5-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/5-1.gif -------------------------------------------------------------------------------- /Document/Samples/5-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/5-1c.gif -------------------------------------------------------------------------------- /Document/Samples/5-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/5-2.gif -------------------------------------------------------------------------------- /Document/Samples/5-2c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/5-2c.gif -------------------------------------------------------------------------------- /Document/Samples/6-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/6-1.gif -------------------------------------------------------------------------------- /Document/Samples/6-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/6-1c.gif -------------------------------------------------------------------------------- /Document/Samples/7-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/7-1.gif -------------------------------------------------------------------------------- /Document/Samples/7-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/7-1c.gif -------------------------------------------------------------------------------- /Document/Samples/7-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/7-2.gif -------------------------------------------------------------------------------- /Document/Samples/7-2c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/7-2c.gif -------------------------------------------------------------------------------- /Document/Samples/7-3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/7-3.gif -------------------------------------------------------------------------------- /Document/Samples/7-3c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/7-3c.gif -------------------------------------------------------------------------------- /Document/Samples/8-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/8-1.gif -------------------------------------------------------------------------------- /Document/Samples/8-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/8-1c.gif -------------------------------------------------------------------------------- /Document/Samples/8-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/8-2.gif -------------------------------------------------------------------------------- /Document/Samples/8-2c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/8-2c.gif -------------------------------------------------------------------------------- /Document/Samples/8-3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/8-3.gif -------------------------------------------------------------------------------- /Document/Samples/8-3c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/8-3c.gif -------------------------------------------------------------------------------- /Document/Samples/8-3c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/8-3c.png -------------------------------------------------------------------------------- /Document/Samples/8-4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/8-4.gif -------------------------------------------------------------------------------- /Document/Samples/8-4c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/8-4c.gif -------------------------------------------------------------------------------- /Document/Samples/9-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/9-1.gif -------------------------------------------------------------------------------- /Document/Samples/9-1c.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/9-1c.gif -------------------------------------------------------------------------------- /Document/Samples/9.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/9.gif -------------------------------------------------------------------------------- /Document/Samples/main.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Samples/main.gif -------------------------------------------------------------------------------- /Document/Wireframe1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Wireframe1.png -------------------------------------------------------------------------------- /Document/Wireframe2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/Wireframe2.png -------------------------------------------------------------------------------- /Document/로드맵.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/로드맵.png -------------------------------------------------------------------------------- /Document/책그림.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Document/책그림.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Dustin Lee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # <이득우의 게임 수학> 예제 2 |

3 | 4 |

5 | 6 | 이득우의 게임 수학에 사용되는 예제 CK소프트렌더러 프로젝트입니다. 7 | 브랜치를 사용해 단계별로 코드가 구현되어 있으니 책의 가이드에 따라 올바른 브랜치를 다운받기 바랍니다. 8 | 9 | ## 전체 로드맵 10 | ![로드맵](https://github.com/onlybooks/gamemath/blob/main/Document/로드맵.png "로드맵") 11 | 12 |

13 | [단계별 예제 확인하기] 14 |

15 | 16 | ## 요구사항 17 | - 비주얼 스튜디오 2019 혹은 비주얼 스튜디오 2022 18 | - CMake 3.1버젼 이상 ( https://cmake.org/download/ ) 19 | - 본 프로젝트는 윈도우만 지원합니다. 20 | 21 | ## 컴파일 방법 22 | - 소스를 다운 받은 후에 비주얼 스튜디오 2019는 CMake-VS-16-2019.bat 배치 파일을, 비주얼 스튜디오 2022는 CMake-VS-17-2022.bat 배치 파일을 실행합니다. 23 | - 배치 파일을 실행하면 소스를 푼 폴더에 Project폴더와 솔루션 파일이 생성됩니다. 24 | - 솔루션을 더블클릭해 비주얼 스튜디오를 열고 컴파일하고 실행합니다. 25 | 26 | ## 사용하는 키 27 | | 키 | 기능 | 28 | | ------------- |:-------------:| 29 | | F1 | 일반 모드 | 30 | | F2 | 와이어 프레임 모드 | 31 | | F3 | 깊이 버퍼 모드 ( 3D 전용 ) | 32 | | F10 | 2D 엔진과 3D 엔진의 변경 | 33 | | 왼쪽,오른쪽 화살표 키 | 캐릭터 좌우 회전 | 34 | | 위,아래 화살표 키 | 캐릭터 전후 이동 | 35 | | 홈(Home),엔드(End) | 카메라 FOV 조절 | 36 | 37 | ## 일반 모드 38 | 텍스쳐를 매핑해 렌더링합니다. 기즈모는 표시되나 본은 표시되지 않습니다. 39 | 40 | 구동이 느린 경우 Release 모드로 컴파일해 실행하기 바랍니다. 41 | 42 | 43 | 44 | ## 와이어프레임 모드 45 | 선을 사용해 외곽선만 렌더링합니다. 기즈모와 본을 모두 표시해줍니다. 46 | 47 | ![와이어프레임 모드](https://github.com/onlybooks/gamemath/blob/main/Document/Wireframe1.png "와이어프레임 모드") 48 | 49 | 가까이서 확대하는 경우 동차좌표계에서 삼각형이 분할되는 과정을 확인할 수 있습니다. 50 | 51 | ![와이어프레임 모드 2](https://github.com/onlybooks/gamemath/blob/main/Document/Wireframe2.png "와이어프레임 모드 2") 52 | 53 | ## 깊이 버퍼 모드 54 | 원근 투영 변환 후 깊이 값을 선형화시켜 보여줍니다. 55 | 56 | ![깊이 버퍼 모드](https://github.com/onlybooks/gamemath/blob/main/Document/Depth.png "깊이버퍼 모드") 57 | 58 | -------------------------------------------------------------------------------- /Resource/CKMan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Resource/CKMan.png -------------------------------------------------------------------------------- /Source/Player/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | project(SoftRendererPlayer) 4 | 5 | ################################################################################ 6 | # Source files 7 | ################################################################################ 8 | file(GLOB COMMON_SOURCE_FILES 9 | ${PROJECT_SOURCE_DIR}/Private/*.cpp 10 | ${PROJECT_SOURCE_DIR}/*.cpp 11 | ${PROJECT_SOURCE_DIR}/*.h 12 | ) 13 | 14 | set(ALL_FILES 15 | ${COMMON_SOURCE_FILES} 16 | ) 17 | 18 | if(TARGET_WINDOWS) 19 | 20 | file(GLOB_RECURSE WINDOWS_FILES 21 | ${PROJECT_SOURCE_DIR}/Private/${PLATFORM_FOLDER}/*.cpp 22 | ${PROJECT_SOURCE_DIR}/Private/${PLATFORM_FOLDER}/*.h 23 | ) 24 | 25 | file(GLOB WINDOWS_RESOURCE_FILES 26 | ${PROJECT_SOURCE_DIR}/Private/${PLATFORM_FOLDER}/Res/*.h 27 | ${PROJECT_SOURCE_DIR}/Private/${PLATFORM_FOLDER}/Res/*.rc 28 | ${PROJECT_SOURCE_DIR}/Private/${PLATFORM_FOLDER}/Res/*.ico 29 | ) 30 | 31 | set(ALL_FILES 32 | ${ALL_FILES} 33 | ${WINDOWS_FILES} 34 | ${WINDOWS_RESOURCE_FILES} 35 | ) 36 | 37 | endif() 38 | 39 | 40 | 41 | foreach(FILE ${ALL_FILES}) 42 | # make rel path 43 | file(RELATIVE_PATH REL_PATH "${PROJECT_SOURCE_DIR}" "${FILE}") 44 | 45 | # get the base path 46 | get_filename_component(BASE_PATH "${REL_PATH}" PATH) 47 | 48 | # changes /'s to \\'s 49 | string(REPLACE "/" "\\" GROUP "${BASE_PATH}") 50 | 51 | source_group("${GROUP}" FILES "${FILE}") 52 | endforeach() 53 | 54 | 55 | ################################################################################ 56 | # Include directory 57 | ################################################################################ 58 | include_directories( 59 | ${PROJECT_SOURCE_DIR} 60 | ${PROJECT_SOURCE_DIR}/Private/${PLATFORM_FOLDER} 61 | ${RUNTIME_MODULE_DIR}/Math/Public 62 | ${RUNTIME_MODULE_DIR}/Engine/Public 63 | ${RUNTIME_MODULE_DIR}/Renderer/Public 64 | ${RUNTIME_MODULE_DIR}/Renderer/Public/${PLATFORM_FOLDER} 65 | ) 66 | 67 | 68 | ################################################################################ 69 | # Precompiled Headers 70 | ################################################################################ 71 | set(ARG_PCH_HEADER Precompiled.h) 72 | set(ARG_PCH_SOURCE Precompiled.cpp) 73 | foreach (FILE ${ALL_FILES}) 74 | file(RELATIVE_PATH REL_PATH "${PROJECT_SOURCE_DIR}" "${FILE}") 75 | if (REL_PATH MATCHES ".*\\.(c|cpp)$") 76 | if (REL_PATH STREQUAL ${ARG_PCH_SOURCE}) 77 | set_source_files_properties(${FILE} PROPERTIES COMPILE_FLAGS "/Yc\"${ARG_PCH_HEADER}\"") 78 | else() 79 | set_source_files_properties(${FILE} PROPERTIES COMPILE_FLAGS "/Yu\"${ARG_PCH_HEADER}\"") 80 | endif() 81 | endif() 82 | endforeach(FILE) 83 | 84 | ################################################################################ 85 | # Excutable Output Setting 86 | ################################################################################ 87 | add_executable(${PROJECT_NAME} WIN32 ${ALL_FILES}) 88 | 89 | set_target_properties(${PROJECT_NAME} PROPERTIES 90 | PREFIX "" 91 | OUTPUT_NAME ${PROJECT_NAME} 92 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Output/${PLATFORM_FOLDER}/Binary 93 | VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Resource 94 | ) 95 | 96 | ################################################################################ 97 | # Import Library 98 | ################################################################################ 99 | target_link_libraries(${PROJECT_NAME} MathModule RendererModule EngineModule) 100 | 101 | 102 | -------------------------------------------------------------------------------- /Source/Player/Precompiled.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | -------------------------------------------------------------------------------- /Source/Player/Precompiled.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(PLATFORM_WINDOWS) 4 | 5 | #define WIN32_LEAN_AND_MEAN 6 | #include 7 | #include 8 | #include "Res/resource.h" 9 | 10 | #endif 11 | 12 | #include "MathHeaders.h" 13 | #include "EngineHeaders.h" 14 | #include "RendererHeaders.h" 15 | #include "SystemInputManager.h" 16 | 17 | using namespace CK; 18 | 19 | -------------------------------------------------------------------------------- /Source/Player/Private/SystemInputManager.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | 4 | bool SystemInputManager::IsPressed(SystemInputButton InSystemInputButton) const 5 | { 6 | assert(InSystemInputButton < SystemInputButton::LastButton); 7 | size_t targetIndex = static_cast(InSystemInputButton); 8 | return (!PrevButtonStatus[targetIndex] && PressedButtonMap[targetIndex]()); 9 | } 10 | 11 | bool SystemInputManager::IsPressing(SystemInputButton InSystemInputButton) const 12 | { 13 | assert(InSystemInputButton < SystemInputButton::LastButton); 14 | size_t targetIndex = static_cast(InSystemInputButton); 15 | return (PrevButtonStatus[targetIndex] && PressedButtonMap[targetIndex]()); 16 | } 17 | 18 | bool SystemInputManager::IsReleased(SystemInputButton InSystemInputButton) const 19 | { 20 | assert(InSystemInputButton < SystemInputButton::LastButton); 21 | size_t targetIndex = static_cast(InSystemInputButton); 22 | return (PrevButtonStatus[targetIndex] && !PressedButtonMap[targetIndex]()); 23 | } 24 | 25 | void SystemInputManager::SetSystemInputButton(SystemInputButton SystemInputButton, std::function InPressedFn) 26 | { 27 | assert(SystemInputButton < SystemInputButton::LastButton); 28 | PressedButtonMap[static_cast(SystemInputButton)] = InPressedFn; 29 | } 30 | 31 | void SystemInputManager::UpdateSystemInput() 32 | { 33 | size_t lastIndex = static_cast(SystemInputButton::LastButton); 34 | for (size_t bi = 0; bi < lastIndex; ++bi) 35 | { 36 | PrevButtonStatus[bi] = PressedButtonMap[bi](); 37 | } 38 | } 39 | 40 | bool SystemInputManager::IsInputReady() const 41 | { 42 | if (!PressedButtonMap[0]) 43 | { 44 | return false; 45 | } 46 | 47 | return true; 48 | } -------------------------------------------------------------------------------- /Source/Player/Private/Windows/Res/player.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Player/Private/Windows/Res/player.ico -------------------------------------------------------------------------------- /Source/Player/Private/Windows/Res/player.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Player/Private/Windows/Res/player.rc -------------------------------------------------------------------------------- /Source/Player/Private/Windows/Res/player_small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Player/Private/Windows/Res/player_small.ico -------------------------------------------------------------------------------- /Source/Player/Private/Windows/Res/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++에서 생성한 포함 파일입니다. 3 | // player.rc에서 사용되고 있습니다. 4 | // 5 | #define IDC_MYICON 2 6 | #define IDD_SOFTRENDERER_DIALOG 102 7 | #define IDS_APP_TITLE 103 8 | #define IDD_ABOUTBOX 103 9 | #define IDM_ABOUT 104 10 | #define IDS_AUTHOR 104 11 | #define IDS_DEVELOPER 104 12 | #define IDM_EXIT 105 13 | #define IDI_SOFTRENDERER 107 14 | #define IDI_SMALL 108 15 | #define IDC_SOFTRENDERER 109 16 | #define IDR_MAINFRAME 128 17 | #define IDM_2D 200 18 | #define IDM_3DPERSP 201 19 | #define IDM_3DORTHO 202 20 | #define IDC_STATIC -1 21 | 22 | // Next default values for new objects 23 | // 24 | #ifdef APSTUDIO_INVOKED 25 | #ifndef APSTUDIO_READONLY_SYMBOLS 26 | #define _APS_NO_MFC 1 27 | #define _APS_NEXT_RESOURCE_VALUE 129 28 | #define _APS_NEXT_COMMAND_VALUE 32774 29 | #define _APS_NEXT_CONTROL_VALUE 1000 30 | #define _APS_NEXT_SYMED_VALUE 110 31 | #endif 32 | #endif 33 | -------------------------------------------------------------------------------- /Source/Player/Private/Windows/WindowsApp.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | #include "SoftRenderer.h" 4 | #include "WindowsUtil.h" 5 | #include "WindowsPlayer.h" 6 | 7 | int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) 8 | { 9 | ScreenPoint defScreenSize(800, 600); 10 | SoftRenderer instance(GameEngineType::DDD, new WindowsRSI()); 11 | WindowsPlayer::gOnResizeFunc = [&instance](const ScreenPoint& InNewScreenSize) { 12 | if (InNewScreenSize.HasZero()) { 13 | return; 14 | } 15 | instance.OnResize(InNewScreenSize); 16 | }; 17 | instance._PerformanceInitFunc = WindowsUtil::GetCyclesPerMilliSeconds; 18 | instance._PerformanceMeasureFunc = WindowsUtil::GetCurrentTimeStamp; 19 | instance._InputBindingFunc = WindowsUtil::BindInput; 20 | WindowsUtil::BindSystemInput(instance.GetSystemInput()); 21 | 22 | if (!WindowsPlayer::Create(hInstance, defScreenSize)) 23 | { 24 | return -1; 25 | } 26 | 27 | WindowsUtil::Show(WindowsPlayer::gHandle); 28 | WindowsUtil::CenterWindow(WindowsPlayer::gHandle); 29 | 30 | static float previousTimer = 0.f; 31 | static float updatePeriod = 500.f; 32 | while (WindowsPlayer::Tick()) 33 | { 34 | instance.OnTick(); 35 | 36 | float currentTime = instance.GetElapsedTime(); 37 | if (currentTime - previousTimer > updatePeriod) 38 | { 39 | float frameFPS = instance.GetFrameFPS(); 40 | WindowsPlayer::SetWindowsStatTitle(frameFPS); 41 | previousTimer = currentTime; 42 | } 43 | } 44 | 45 | instance.OnShutdown(); 46 | WindowsPlayer::Destroy(); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Source/Player/Private/Windows/WindowsPlayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace WindowsPlayer 4 | { 5 | static HINSTANCE gInstance; 6 | static HWND gHandle; 7 | static std::function gOnResizeFunc; 8 | 9 | static const TCHAR *gClassName = _T("SOFTRENDERER_PLAYER"); 10 | static TCHAR gTitle[64]; 11 | static TCHAR gPlayTitle[128]; 12 | 13 | LRESULT CALLBACK WndProc(HWND hwnd, UINT32 msg, WPARAM wParam, LPARAM lParam) 14 | { 15 | switch (msg) 16 | { 17 | case WM_DISPLAYCHANGE: 18 | case WM_SIZE: 19 | { 20 | int newWidth = (lParam & 0xffff); 21 | int newHeight = ((lParam >> 16) & 0xffff); 22 | if (gOnResizeFunc) 23 | { 24 | gOnResizeFunc(ScreenPoint(newWidth, newHeight)); 25 | } 26 | break; 27 | } 28 | case WM_CLOSE: 29 | { 30 | DestroyWindow(hwnd); 31 | return 0; 32 | } 33 | case WM_DESTROY: 34 | { 35 | PostQuitMessage(0); 36 | break; 37 | } 38 | case WM_SYSCOMMAND: 39 | { 40 | if (wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER || wParam == SC_KEYMENU) 41 | { 42 | return 0; 43 | } 44 | break; 45 | } 46 | } 47 | 48 | return DefWindowProc(hwnd, msg, wParam, lParam); 49 | } 50 | 51 | bool Create(HINSTANCE InInstance, const ScreenPoint& InDefaultScreenSize) 52 | { 53 | gInstance = InInstance; 54 | 55 | #define SIZEOF(a) ((int)(sizeof(a) / sizeof((a)[0]))) 56 | ::LoadString(gInstance, IDS_APP_TITLE, gTitle, SIZEOF(gTitle)); 57 | 58 | WNDCLASSEX wcex; 59 | memset(&wcex, 0, sizeof(wcex)); 60 | wcex.cbSize = sizeof(WNDCLASSEX); 61 | wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; 62 | wcex.lpfnWndProc = WndProc; 63 | wcex.hInstance = gInstance; 64 | wcex.hIcon = LoadIcon(gInstance, MAKEINTRESOURCE(IDI_SOFTRENDERER)); 65 | wcex.hIconSm = LoadIcon(gInstance, MAKEINTRESOURCE(IDI_SMALL)); 66 | wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 67 | wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 68 | wcex.lpszMenuName = NULL; 69 | wcex.lpszClassName = gClassName; 70 | 71 | if (!::RegisterClassEx(&wcex)) 72 | { 73 | ::MessageBox(nullptr, "Window registration failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); 74 | return false; 75 | } 76 | 77 | RECT rect; 78 | rect.left = 0; 79 | rect.top = 0; 80 | rect.right = InDefaultScreenSize.X - 1; 81 | rect.bottom = InDefaultScreenSize.Y - 1; 82 | ::AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false); 83 | int WindowWidth = rect.right - rect.left + 1; 84 | int WindowHeight = rect.bottom - rect.top + 1; 85 | 86 | gHandle = ::CreateWindow(gClassName, gTitle, WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, 87 | (GetSystemMetrics(SM_CXFULLSCREEN) - WindowWidth) / 2, (GetSystemMetrics(SM_CYFULLSCREEN) - WindowHeight) / 2, WindowWidth, WindowHeight, 88 | NULL, NULL, gInstance, NULL); 89 | 90 | if (!gHandle) 91 | { 92 | ::MessageBox(nullptr, "Window creation failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); 93 | return false; 94 | } 95 | 96 | return true; 97 | } 98 | 99 | FORCEINLINE bool Tick() 100 | { 101 | MSG msg; 102 | ZeroMemory(&msg, sizeof(msg)); 103 | 104 | while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) 105 | { 106 | TranslateMessage(&msg); 107 | DispatchMessage(&msg); 108 | 109 | if (msg.message == WM_QUIT) 110 | return false; 111 | } 112 | 113 | return true; 114 | } 115 | 116 | void Destroy() 117 | { 118 | DestroyWindow(gHandle); 119 | } 120 | 121 | FORCEINLINE void SetWindowsStatTitle(float frameFPS) 122 | { 123 | _stprintf_s(gPlayTitle, "%s [%.2f fps]", gTitle, frameFPS); 124 | ::SetWindowText(gHandle, gPlayTitle); 125 | } 126 | } -------------------------------------------------------------------------------- /Source/Player/Private/Windows/WindowsUtil.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace WindowsUtil 4 | { 5 | void GetWindowSize(HWND handle, float* width, float* height) 6 | { 7 | RECT rect; 8 | ::GetClientRect(handle, &rect); 9 | *width = static_cast(rect.right - rect.left); 10 | *height = static_cast(rect.bottom - rect.top); 11 | } 12 | 13 | void Show(HWND handle) 14 | { 15 | ::ShowWindow(handle, SW_SHOW); 16 | ::SetForegroundWindow(handle); 17 | ::SetFocus(handle); 18 | } 19 | 20 | void CenterWindow(HWND handle) 21 | { 22 | // center on parent or screen 23 | RECT rc, rcOwner, rcWindow; 24 | HWND ownerHandle = GetDesktopWindow(); 25 | GetWindowRect(ownerHandle, &rcOwner); 26 | GetWindowRect(handle, &rcWindow); 27 | CopyRect(&rc, &rcOwner); 28 | 29 | OffsetRect(&rcWindow, -rcWindow.left, -rcWindow.top); 30 | OffsetRect(&rc, -rc.left, -rc.top); 31 | OffsetRect(&rc, -rcWindow.right, -rcWindow.bottom); 32 | 33 | ::SetWindowPos(handle, HWND_TOP, 34 | rcOwner.left + (rc.right / 2), 35 | rcOwner.top + (rc.bottom / 2), 36 | 0, 0, 37 | SWP_NOSIZE); 38 | } 39 | 40 | float GetCyclesPerMilliSeconds() 41 | { 42 | LARGE_INTEGER frequency; 43 | if (!QueryPerformanceFrequency(&frequency)) 44 | { 45 | return 0.f; 46 | } 47 | 48 | return (float)(frequency.QuadPart / 1000.f); 49 | } 50 | 51 | long long GetCurrentTimeStamp() 52 | { 53 | LARGE_INTEGER currentTime; 54 | QueryPerformanceCounter(¤tTime); 55 | return currentTime.QuadPart; 56 | } 57 | 58 | float GetXAxisInput() 59 | { 60 | bool isLeft = GetAsyncKeyState(VK_LEFT); 61 | bool isRight = GetAsyncKeyState(VK_RIGHT); 62 | if (isLeft ^ isRight) 63 | { 64 | return isLeft ? -1.f : 1.f; 65 | } 66 | return 0.f; 67 | } 68 | 69 | float GetYAxisInput() 70 | { 71 | bool isDown = GetAsyncKeyState(VK_DOWN); 72 | bool isUp = GetAsyncKeyState(VK_UP); 73 | if (isDown ^ isUp) 74 | { 75 | return isDown ? -1.f : 1.f; 76 | } 77 | return 0.f; 78 | } 79 | 80 | float GetZAxisInput() 81 | { 82 | bool isDown = GetAsyncKeyState(VK_NEXT); 83 | bool isUp = GetAsyncKeyState(VK_PRIOR); 84 | if (isDown ^ isUp) 85 | { 86 | return isDown ? -1.f : 1.f; 87 | } 88 | return 0.f; 89 | } 90 | 91 | float GetWAxisInput() 92 | { 93 | bool isDown = GetAsyncKeyState(VK_END); 94 | bool isUp = GetAsyncKeyState(VK_HOME); 95 | if (isDown ^ isUp) 96 | { 97 | return isDown ? -1.f : 1.f; 98 | } 99 | return 0.f; 100 | } 101 | 102 | #define ISPRESSED(KeyCode) return (::GetKeyState(KeyCode) & 0x8000) != 0 103 | 104 | void BindInput(InputManager& InInputManager) 105 | { 106 | InInputManager.SetInputAxis(InputAxis::XAxis, GetXAxisInput); 107 | InInputManager.SetInputAxis(InputAxis::YAxis, GetYAxisInput); 108 | InInputManager.SetInputAxis(InputAxis::ZAxis, GetZAxisInput); 109 | InInputManager.SetInputAxis(InputAxis::WAxis, GetWAxisInput); 110 | InInputManager.SetInputButton(InputButton::Space, []() { ISPRESSED(VK_SPACE); }); 111 | InInputManager.SetInputButton(InputButton::Z, []() { ISPRESSED(0x5A); }); 112 | InInputManager.SetInputButton(InputButton::X, []() { ISPRESSED(0x58); }); 113 | } 114 | 115 | void BindSystemInput(SystemInputManager& InSystemInputManager) 116 | { 117 | InSystemInputManager.SetSystemInputButton(SystemInputButton::F1, []() { ISPRESSED(VK_F1); }); 118 | InSystemInputManager.SetSystemInputButton(SystemInputButton::F2, []() { ISPRESSED(VK_F2); }); 119 | InSystemInputManager.SetSystemInputButton(SystemInputButton::F3, []() { ISPRESSED(VK_F3); }); 120 | InSystemInputManager.SetSystemInputButton(SystemInputButton::F4, []() { ISPRESSED(VK_F4); }); 121 | InSystemInputManager.SetSystemInputButton(SystemInputButton::F5, []() { ISPRESSED(VK_F5); }); 122 | InSystemInputManager.SetSystemInputButton(SystemInputButton::F6, []() { ISPRESSED(VK_F6); }); 123 | InSystemInputManager.SetSystemInputButton(SystemInputButton::F7, []() { ISPRESSED(VK_F7); }); 124 | InSystemInputManager.SetSystemInputButton(SystemInputButton::F8, []() { ISPRESSED(VK_F8); }); 125 | InSystemInputManager.SetSystemInputButton(SystemInputButton::F9, []() { ISPRESSED(VK_F9); }); 126 | InSystemInputManager.SetSystemInputButton(SystemInputButton::F10, []() { ISPRESSED(VK_F10); }); 127 | } 128 | } -------------------------------------------------------------------------------- /Source/Player/SoftRenderer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Player/SoftRenderer.cpp -------------------------------------------------------------------------------- /Source/Player/SoftRenderer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Player/SoftRenderer.h -------------------------------------------------------------------------------- /Source/Player/SoftRenderer2D.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Player/SoftRenderer2D.cpp -------------------------------------------------------------------------------- /Source/Player/SoftRenderer3D.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Player/SoftRenderer3D.cpp -------------------------------------------------------------------------------- /Source/Player/SystemInputManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | enum class SystemInputButton : UINT32 7 | { 8 | F1 = 0, 9 | F2, 10 | F3, 11 | F4, 12 | F5, 13 | F6, 14 | F7, 15 | F8, 16 | F9, 17 | F10, 18 | LastButton 19 | }; 20 | 21 | class SystemInputManager 22 | { 23 | public: 24 | bool IsPressed(SystemInputButton InSystemInputButton) const; 25 | bool IsPressing(SystemInputButton InSystemInputButton) const; 26 | bool IsReleased(SystemInputButton InSystemInputButton) const; 27 | bool IsInputReady() const; 28 | void SetSystemInputButton(SystemInputButton InSystemInputButton, std::function InPressedFn); 29 | void UpdateSystemInput(); 30 | 31 | private: 32 | std::array, static_cast(SystemInputButton::LastButton)> PressedButtonMap = { 0 }; 33 | std::array(SystemInputButton::LastButton)> PrevButtonStatus = { 0 }; 34 | }; 35 | 36 | } -------------------------------------------------------------------------------- /Source/Runtime/Engine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | project(EngineModule) 4 | 5 | ################################################################################ 6 | # Source files 7 | ################################################################################ 8 | file(GLOB COMMON_FILES 9 | ${PROJECT_SOURCE_DIR}/*.cpp 10 | ${PROJECT_SOURCE_DIR}/*.h) 11 | 12 | file(GLOB_RECURSE MODULE_FILES 13 | ${PROJECT_SOURCE_DIR}/Private/*.cpp 14 | ${PROJECT_SOURCE_DIR}/Public/*.h 15 | ${PROJECT_SOURCE_DIR}/Private/2D/*.cpp 16 | ${PROJECT_SOURCE_DIR}/Public/2D/*.h 17 | ${PROJECT_SOURCE_DIR}/Private/3D/*.cpp 18 | ${PROJECT_SOURCE_DIR}/Public/3D/*.h 19 | ) 20 | 21 | file(GLOB_RECURSE THIRDPARTY_FILES 22 | ${PROJECT_SOURCE_DIR}/ThirdParty/*.h 23 | ${PROJECT_SOURCE_DIR}/ThirdParty/*.cpp 24 | ) 25 | 26 | set(ALL_FILES 27 | ${COMMON_FILES} 28 | ${MODULE_FILES} 29 | ${THIRDPARTY_FILES} 30 | ) 31 | 32 | foreach(FILE ${ALL_FILES}) 33 | # make rel path 34 | file(RELATIVE_PATH REL_PATH "${PROJECT_SOURCE_DIR}" "${FILE}") 35 | set(ALL_FILES_REL ${ALL_FILES_REL} ${REL_PATH}) 36 | endforeach() 37 | 38 | set_source_files_properties(${ALL_FILES_REL} PROPERTIES HEADER_FILE_ONLY FALSE) 39 | 40 | foreach(FILE ${ALL_FILES_REL}) 41 | # get the base path 42 | get_filename_component(BASE_PATH "${FILE}" PATH) 43 | 44 | # changes /'s to \\'s 45 | string(REPLACE "/" "\\" GROUP "${BASE_PATH}") 46 | 47 | source_group("${GROUP}" FILES "${FILE}") 48 | endforeach() 49 | 50 | 51 | ################################################################################ 52 | # Include directory 53 | ################################################################################ 54 | include_directories( 55 | ${PROJECT_SOURCE_DIR} 56 | ${PROJECT_SOURCE_DIR}/Public 57 | ${PROJECT_SOURCE_DIR}/Public/2D 58 | ${PROJECT_SOURCE_DIR}/Public/3D 59 | ${PROJECT_SOURCE_DIR}/ThirdParty 60 | ${RUNTIME_MODULE_DIR}/Math/Public 61 | ${RUNTIME_MODULE_DIR}/Renderer/Public 62 | ) 63 | 64 | 65 | ################################################################################ 66 | # Precompiled Headers 67 | ################################################################################ 68 | set(ARG_PCH_HEADER Precompiled.h) 69 | set(ARG_PCH_SOURCE Precompiled.cpp) 70 | foreach (FILE ${ALL_FILES_REL}) 71 | if (FILE MATCHES ".*\\.(c|cpp)$") 72 | if (FILE STREQUAL ${ARG_PCH_SOURCE}) 73 | set_source_files_properties(${FILE} PROPERTIES COMPILE_FLAGS "/Yc\"${ARG_PCH_HEADER}\"") 74 | else() 75 | set_source_files_properties(${FILE} PROPERTIES COMPILE_FLAGS "/Yu\"${ARG_PCH_HEADER}\"") 76 | endif() 77 | endif() 78 | endforeach(FILE) 79 | 80 | 81 | ################################################################################ 82 | # Library Output Setting 83 | ################################################################################ 84 | add_library(${PROJECT_NAME} STATIC ${ALL_FILES_REL}) 85 | 86 | set_target_properties(${PROJECT_NAME} PROPERTIES 87 | PREFIX "" 88 | OUTPUT_NAME ${PROJECT_NAME} 89 | ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Output/${PLATFORM_FOLDER}/Library) 90 | 91 | 92 | ################################################################################ 93 | # Import Library 94 | ################################################################################ 95 | target_link_libraries(${PROJECT_NAME} MathModule RendererModule) 96 | 97 | 98 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Precompiled.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Precompiled.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MathHeaders.h" 4 | #include "EngineHeaders.h" 5 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/2D/CameraObject.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DD; 4 | 5 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/2D/GameEngine.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Private/2D/GameEngine.cpp -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/2D/GameObject.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DD; 4 | 5 | GameObject GameObject::Invalid(Math::InvalidHashName); 6 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/2D/Mesh.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DD; 4 | 5 | void Mesh::CalculateBounds() 6 | { 7 | _CircleBound = Circle(_Vertices); 8 | _RectBound = Rectangle(_Vertices); 9 | } 10 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/2D/TransformComponent.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DD; 4 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/3D/Bone.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DDD; 4 | 5 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/3D/CameraObject.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DDD; 4 | 5 | void CameraObject::SetLookAtRotation(const GameObject& InGameObject, const Vector3& InUp) 6 | { 7 | SetLookAtRotation(InGameObject.GetTransform().GetWorldPosition(), InUp); 8 | } 9 | 10 | void CameraObject::SetLookAtRotation(const Vector3& InTargetPosition, const Vector3& InUp) 11 | { 12 | _Transform.SetWorldRotation(Quaternion(InTargetPosition - _Transform.GetWorldPosition())); 13 | } -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/3D/GameEngine.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Private/3D/GameEngine.cpp -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/3D/GameObject.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DDD; 4 | 5 | GameObject GameObject::Invalid(Math::InvalidHashName); 6 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/3D/Mesh.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DDD; 4 | 5 | void Mesh::CalculateBounds() 6 | { 7 | _SphereBound = Sphere(_Vertices); 8 | _BoxBound = Box(_Vertices); 9 | } 10 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/3D/TransformComponent.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Private/3D/TransformComponent.cpp -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/InputManager.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | 4 | float InputManager::GetAxis(InputAxis InInputAxis) const 5 | { 6 | assert(InInputAxis < InputAxis::LastAxis); 7 | return AxisMap[static_cast(InInputAxis)](); 8 | } 9 | 10 | bool InputManager::IsPressed(InputButton InInputButton) const 11 | { 12 | assert(InInputButton < InputButton::LastButton); 13 | size_t targetIndex = static_cast(InInputButton); 14 | return (!PrevButtonStatus[targetIndex] && PressedButtonMap[targetIndex]()); 15 | } 16 | 17 | bool InputManager::IsPressing(InputButton InInputButton) const 18 | { 19 | assert(InInputButton < InputButton::LastButton); 20 | size_t targetIndex = static_cast(InInputButton); 21 | return (PrevButtonStatus[targetIndex] && PressedButtonMap[targetIndex]()); 22 | } 23 | 24 | bool InputManager::IsReleased(InputButton InInputButton) const 25 | { 26 | assert(InInputButton < InputButton::LastButton); 27 | size_t targetIndex = static_cast(InInputButton); 28 | return (PrevButtonStatus[targetIndex] && !PressedButtonMap[targetIndex]()); 29 | } 30 | 31 | bool InputManager::IsInputReady() const 32 | { 33 | if (!AxisMap[0]) 34 | { 35 | return false; 36 | } 37 | 38 | if (!PressedButtonMap[0]) 39 | { 40 | return false; 41 | } 42 | 43 | return true; 44 | } 45 | 46 | void InputManager::SetInputAxis(InputAxis InInputAxis, std::function InAxisFn) 47 | { 48 | assert(InInputAxis < InputAxis::LastAxis); 49 | AxisMap[static_cast(InInputAxis)] = InAxisFn; 50 | } 51 | 52 | void InputManager::SetInputButton(InputButton InInputButton, std::function InPressedFn) 53 | { 54 | assert(InInputButton < InputButton::LastButton); 55 | PressedButtonMap[static_cast(InInputButton)] = InPressedFn; 56 | } 57 | 58 | void InputManager::UpdateInput() 59 | { 60 | size_t lastIndex = static_cast(InputButton::LastButton); 61 | for (size_t bi = 0; bi < lastIndex; ++bi) 62 | { 63 | PrevButtonStatus[bi] = PressedButtonMap[bi](); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Private/Texture.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | #define STB_IMAGE_IMPLEMENTATION 4 | #pragma warning( push ) 5 | #pragma warning( disable : 26451 ) 6 | #include "Stb/stb_image.h" 7 | #pragma warning( pop ) 8 | 9 | Texture::Texture(std::string InFileName) 10 | { 11 | FILE* f = NULL; 12 | if (0 != fopen_s(&f, InFileName.c_str(), "rb")) 13 | { 14 | return; 15 | } 16 | LoadFromFile(f); 17 | } 18 | 19 | Texture::Texture(std::wstring InFileName) 20 | { 21 | FILE* f = NULL; 22 | if (0 != _wfopen_s(&f, InFileName.c_str(), L"rb")) 23 | { 24 | return; 25 | } 26 | LoadFromFile(f); 27 | } 28 | 29 | void Texture::LoadFromFile(FILE* InFilePtr) 30 | { 31 | if (InFilePtr == NULL) 32 | { 33 | return; 34 | } 35 | 36 | Release(); 37 | int width = 0, height = 0, channel = 0; 38 | stbi_uc* pixelsPtr = stbi_load_from_file(InFilePtr, &width, &height, &channel, STBI_rgb_alpha); 39 | if (pixelsPtr == NULL) 40 | { 41 | return; 42 | } 43 | 44 | _Width = static_cast(width); 45 | _Height = static_cast(height); 46 | size_t pixelNumbers = static_cast(_Width) * static_cast(_Height); 47 | _Buffer.reserve(pixelNumbers); 48 | for (size_t j = 0; j < _Height; j++) 49 | { 50 | for (size_t i = 0; i < _Width; i++) 51 | { 52 | size_t ix = (j * _Width + i) * 4; 53 | Color32 c(pixelsPtr[ix], pixelsPtr[ix + 1], pixelsPtr[ix + 2], pixelsPtr[ix + 3]); 54 | _Buffer.push_back(LinearColor(c)); 55 | } 56 | } 57 | 58 | return; 59 | } 60 | 61 | void Texture::Release() 62 | { 63 | _Width = 0; 64 | _Height = 0; 65 | _Buffer.clear(); 66 | } 67 | 68 | LinearColor Texture::GetSample(Vector2 InUV) const 69 | { 70 | if (!IsIntialized()) 71 | { 72 | return LinearColor::Error; 73 | } 74 | 75 | int x = Math::FloorToInt(InUV.X * _Width) % _Width; 76 | int y = Math::FloorToInt(InUV.Y * _Height) % _Height; 77 | int index = _Width * (_Height - (1 + y)) + x; 78 | if (index >= _Buffer.size()) 79 | { 80 | return LinearColor::Error; 81 | } 82 | 83 | return _Buffer[index]; 84 | } -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/2D/CameraObject.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/2D/CameraObject.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/2D/GameEngine.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/2D/GameEngine.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/2D/GameObject.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/2D/GameObject.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/2D/Mesh.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/2D/Mesh.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/2D/TransformComponent.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/2D/TransformComponent.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/3D/Bone.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/3D/Bone.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/3D/CameraObject.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/3D/CameraObject.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/3D/GameEngine.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/3D/GameEngine.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/3D/GameObject.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/3D/GameObject.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/3D/Mesh.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/3D/Mesh.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/3D/Resources.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/3D/Resources.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/3D/TransformComponent.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Engine/Public/3D/TransformComponent.h -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/EngineHeaders.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "InputManager.h" 7 | #include "EngineInterface.h" 8 | 9 | #include "Texture.h" 10 | 11 | #include "2D/Mesh.h" 12 | #include "2D/TransformComponent.h" 13 | #include "2D/GameObject.h" 14 | #include "2D/CameraObject.h" 15 | #include "2D/GameEngine.h" 16 | 17 | #include "3D/Resources.h" 18 | #include "3D/TransformComponent.h" 19 | #include "3D/Bone.h" 20 | #include "3D/Mesh.h" 21 | #include "3D/GameObject.h" 22 | #include "3D/CameraObject.h" 23 | #include "3D/GameEngine.h" 24 | 25 | using namespace CK; 26 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/EngineInterface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | enum class GameObjectType : UINT32 7 | { 8 | Normal = 0, 9 | Gizmo 10 | }; 11 | 12 | enum class MeshType : UINT32 13 | { 14 | Normal = 0, 15 | Skinned 16 | }; 17 | 18 | enum class TextureFilterMode : UINT32 19 | { 20 | Nearest = 0, 21 | Linear, 22 | Cubic 23 | }; 24 | 25 | enum class TextureAddressMode : UINT32 26 | { 27 | Repeat = 0, 28 | Clamp 29 | }; 30 | 31 | class EngineInterface 32 | { 33 | public: 34 | virtual bool Init() = 0; 35 | virtual bool IsInitialized() = 0; 36 | virtual void OnScreenResize(const ScreenPoint& InScreenSize) = 0; 37 | virtual InputManager& GetInputManager() = 0; 38 | }; 39 | 40 | } -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/InputManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | enum class InputAxis : UINT32 7 | { 8 | XAxis = 0, 9 | YAxis, 10 | ZAxis, 11 | WAxis, 12 | LastAxis 13 | }; 14 | 15 | enum class InputButton : UINT32 16 | { 17 | Space = 0, 18 | Z, 19 | X, 20 | LastButton 21 | }; 22 | 23 | class InputManager 24 | { 25 | public: 26 | float GetAxis(InputAxis InInputAxis) const; 27 | bool IsPressed(InputButton InInputButton) const; 28 | bool IsPressing(InputButton InInputButton) const; 29 | bool IsReleased(InputButton InInputButton) const; 30 | bool IsInputReady() const; 31 | void SetInputAxis(InputAxis InInputAxis, std::function InAxisFn); 32 | void SetInputButton(InputButton InInputButton, std::function InPressedFn); 33 | void UpdateInput(); 34 | 35 | private: 36 | std::array, static_cast(InputAxis::LastAxis)> AxisMap = { 0 }; 37 | std::array, static_cast(InputButton::LastButton)> PressedButtonMap = { 0 }; 38 | std::array(InputButton::LastButton)> PrevButtonStatus = { 0 }; 39 | }; 40 | 41 | } -------------------------------------------------------------------------------- /Source/Runtime/Engine/Public/Texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | class Texture 7 | { 8 | public: 9 | Texture() = default; 10 | Texture(std::string InFileName); 11 | Texture(std::wstring InFileName); 12 | ~Texture() { } 13 | 14 | public: 15 | void Release(); 16 | bool IsIntialized() const { return (_Buffer.size() > 0); } 17 | UINT32 GetWidth() const { return _Width; } 18 | UINT32 GetHeight() const { return _Height; } 19 | UINT32 GetSize() const { return _Width * _Height; } 20 | LinearColor GetSample(Vector2 InUV) const; 21 | TextureFilterMode GetMagFilterMode() const { return _MagFilter; } 22 | TextureFilterMode GetMinFilterMode() const { return _MinFilter; } 23 | TextureAddressMode GetAddressMode() const { return _AddressMode; } 24 | bool IsAnisotropyEnabled() const { return _AnisotropyEnable; } 25 | float GetMaxAnisotropy() const { return _MaxAnisotropy; } 26 | 27 | private: 28 | void LoadFromFile(FILE* f); 29 | 30 | private: 31 | static constexpr BYTE _Channel = 4; 32 | std::vector _Buffer; 33 | UINT32 _Width = 0; 34 | UINT32 _Height = 0; 35 | 36 | TextureFilterMode _MagFilter = TextureFilterMode::Nearest; 37 | TextureFilterMode _MinFilter = TextureFilterMode::Nearest; 38 | TextureAddressMode _AddressMode = TextureAddressMode::Repeat; 39 | bool _AnisotropyEnable = false; 40 | float _MaxAnisotropy = 16.0f; 41 | }; 42 | 43 | } -------------------------------------------------------------------------------- /Source/Runtime/Engine/ThirdParty/Stb/.travis.yml: -------------------------------------------------------------------------------- 1 | language: C 2 | install: true 3 | script: 4 | - cd tests 5 | - make all 6 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/ThirdParty/Stb/LICENSE: -------------------------------------------------------------------------------- 1 | This software is available under 2 licenses -- choose whichever you prefer. 2 | ------------------------------------------------------------------------------ 3 | ALTERNATIVE A - MIT License 4 | Copyright (c) 2017 Sean Barrett 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | ------------------------------------------------------------------------------ 21 | ALTERNATIVE B - Public Domain (www.unlicense.org) 22 | This is free and unencumbered software released into the public domain. 23 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 24 | software, either in source code form or as a compiled binary, for any purpose, 25 | commercial or non-commercial, and by any means. 26 | In jurisdictions that recognize copyright laws, the author or authors of this 27 | software dedicate any and all copyright interest in the software to the public 28 | domain. We make this dedication for the benefit of the public at large and to 29 | the detriment of our heirs and successors. We intend this dedication to be an 30 | overt act of relinquishment in perpetuity of all present and future rights to 31 | this software under copyright law. 32 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 35 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 36 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 37 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 38 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/ThirdParty/Stb/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | stb 4 | === 5 | 6 | single-file public domain (or MIT licensed) libraries for C/C++ 7 | 8 | Noteworthy: 9 | 10 | * image loader: [stb_image.h](stb_image.h) 11 | * image writer: [stb_image_write.h](stb_image_write.h) 12 | * image resizer: [stb_image_resize.h](stb_image_resize.h) 13 | * font text rasterizer: [stb_truetype.h](stb_truetype.h) 14 | * typesafe containers: [stb_ds.h](stb_ds.h) 15 | 16 | Most libraries by stb, except: stb_dxt by Fabian "ryg" Giesen, stb_image_resize 17 | by Jorge L. "VinoBS" Rodriguez, and stb_sprintf by Jeff Roberts. 18 | 19 | 20 | 21 | library | lastest version | category | LoC | description 22 | --------------------- | ---- | -------- | --- | -------------------------------- 23 | **[stb_vorbis.c](stb_vorbis.c)** | 1.20 | audio | 5563 | decode ogg vorbis files from file/memory to float/16-bit signed output 24 | **[stb_image.h](stb_image.h)** | 2.26 | graphics | 7762 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC 25 | **[stb_truetype.h](stb_truetype.h)** | 1.24 | graphics | 5011 | parse, decode, and rasterize characters from truetype fonts 26 | **[stb_image_write.h](stb_image_write.h)** | 1.15 | graphics | 1690 | image writing to disk: PNG, TGA, BMP 27 | **[stb_image_resize.h](stb_image_resize.h)** | 0.96 | graphics | 2631 | resize images larger/smaller with good quality 28 | **[stb_rect_pack.h](stb_rect_pack.h)** | 1.00 | graphics | 628 | simple 2D rectangle packer with decent quality 29 | **[stb_ds.h](stb_ds.h)** | 0.65 | utility | 1880 | typesafe dynamic array and hash tables for C, will compile in C++ 30 | **[stb_sprintf.h](stb_sprintf.h)** | 1.09 | utility | 1879 | fast sprintf, snprintf for C/C++ 31 | **[stretchy_buffer.h](stretchy_buffer.h)** | 1.04 | utility | 263 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ 32 | **[stb_textedit.h](stb_textedit.h)** | 1.13 | user interface | 1404 | guts of a text editor for games etc implementing them from scratch 33 | **[stb_voxel_render.h](stb_voxel_render.h)** | 0.89 | 3D graphics | 3807 | Minecraft-esque voxel rendering "engine" with many more features 34 | **[stb_dxt.h](stb_dxt.h)** | 1.10 | 3D graphics | 753 | Fabian "ryg" Giesen's real-time DXT compressor 35 | **[stb_perlin.h](stb_perlin.h)** | 0.5 | 3D graphics | 428 | revised Perlin noise (3D input, 1D output) 36 | **[stb_easy_font.h](stb_easy_font.h)** | 1.1 | 3D graphics | 305 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc 37 | **[stb_tilemap_editor.h](stb_tilemap_editor.h)** | 0.41 | game dev | 4161 | embeddable tilemap editor 38 | **[stb_herringbone_wa...](stb_herringbone_wang_tile.h)** | 0.7 | game dev | 1221 | herringbone Wang tile map generator 39 | **[stb_c_lexer.h](stb_c_lexer.h)** | 0.11 | parsing | 966 | simplify writing parsers for C-like languages 40 | **[stb_divide.h](stb_divide.h)** | 0.93 | math | 430 | more useful 32-bit modulus e.g. "euclidean divide" 41 | **[stb_connected_comp...](stb_connected_components.h)** | 0.96 | misc | 1049 | incrementally compute reachability on grids 42 | **[stb.h](stb.h)** | 2.37 | misc | 14454 | helper functions for C, mostly redundant in C++; basically author's personal stuff 43 | **[stb_leakcheck.h](stb_leakcheck.h)** | 0.6 | misc | 194 | quick-and-dirty malloc/free leak-checking 44 | **[stb_include.h](stb_include.h)** | 0.02 | misc | 295 | implement recursive #include support, particularly for GLSL 45 | 46 | Total libraries: 22 47 | Total lines of C code: 56774 48 | 49 | 50 | FAQ 51 | --- 52 | 53 | #### What's the license? 54 | 55 | These libraries are in the public domain. You can do anything you 56 | want with them. You have no legal obligation 57 | to do anything else, although I appreciate attribution. 58 | 59 | They are also licensed under the MIT open source license, if you have lawyers 60 | who are unhappy with public domain. Every source file includes an explicit 61 | dual-license for you to choose from. 62 | 63 | #### Are there other single-file public-domain/open source libraries with minimal dependencies out there? 64 | 65 | [Yes.](https://github.com/nothings/single_file_libs) 66 | 67 | #### If I wrap an stb library in a new library, does the new library have to be public domain/MIT? 68 | 69 | No, because it's public domain you can freely relicense it to whatever license your new 70 | library wants to be. 71 | 72 | #### What's the deal with SSE support in GCC-based compilers? 73 | 74 | stb_image will either use SSE2 (if you compile with -msse2) or 75 | will not use any SIMD at all, rather than trying to detect the 76 | processor at runtime and handle it correctly. As I understand it, 77 | the approved path in GCC for runtime-detection require 78 | you to use multiple source files, one for each CPU configuration. 79 | Because stb_image is a header-file library that compiles in only 80 | one source file, there's no approved way to build both an 81 | SSE-enabled and a non-SSE-enabled variation. 82 | 83 | While we've tried to work around it, we've had multiple issues over 84 | the years due to specific versions of gcc breaking what we're doing, 85 | so we've given up on it. See https://github.com/nothings/stb/issues/280 86 | and https://github.com/nothings/stb/issues/410 for examples. 87 | 88 | #### Some of these libraries seem redundant to existing open source libraries. Are they better somehow? 89 | 90 | Generally they're only better in that they're easier to integrate, 91 | easier to use, and easier to release (single file; good API; no 92 | attribution requirement). They may be less featureful, slower, 93 | and/or use more memory. If you're already using an equivalent 94 | library, there's probably no good reason to switch. 95 | 96 | #### Can I link directly to the table of stb libraries? 97 | 98 | You can use [this URL](https://github.com/nothings/stb#stb_libs) to link directly to that list. 99 | 100 | #### Why do you list "lines of code"? It's a terrible metric. 101 | 102 | Just to give you some idea of the internal complexity of the library, 103 | to help you manage your expectations, or to let you know what you're 104 | getting into. While not all the libraries are written in the same 105 | style, they're certainly similar styles, and so comparisons between 106 | the libraries are probably still meaningful. 107 | 108 | Note though that the lines do include both the implementation, the 109 | part that corresponds to a header file, and the documentation. 110 | 111 | #### Why single-file headers? 112 | 113 | Windows doesn't have standard directories where libraries 114 | live. That makes deploying libraries in Windows a lot more 115 | painful than open source developers on Unix-derivates generally 116 | realize. (It also makes library dependencies a lot worse in Windows.) 117 | 118 | There's also a common problem in Windows where a library was built 119 | against a different version of the runtime library, which causes 120 | link conflicts and confusion. Shipping the libs as headers means 121 | you normally just compile them straight into your project without 122 | making libraries, thus sidestepping that problem. 123 | 124 | Making them a single file makes it very easy to just 125 | drop them into a project that needs them. (Of course you can 126 | still put them in a proper shared library tree if you want.) 127 | 128 | Why not two files, one a header and one an implementation? 129 | The difference between 10 files and 9 files is not a big deal, 130 | but the difference between 2 files and 1 file is a big deal. 131 | You don't need to zip or tar the files up, you don't have to 132 | remember to attach *two* files, etc. 133 | 134 | #### Why "stb"? Is this something to do with Set-Top Boxes? 135 | 136 | No, they are just the initials for my name, Sean T. Barrett. 137 | This was not chosen out of egomania, but as a moderately sane 138 | way of namespacing the filenames and source function names. 139 | 140 | #### Will you add more image types to stb_image.h? 141 | 142 | No. As stb_image use has grown, it has become more important 143 | for us to focus on security of the codebase. Adding new image 144 | formats increases the amount of code we need to secure, so it 145 | is no longer worth adding new formats. 146 | 147 | #### Do you have any advice on how to create my own single-file library? 148 | 149 | Yes. https://github.com/nothings/stb/blob/master/docs/stb_howto.txt 150 | 151 | #### Why public domain? 152 | 153 | I prefer it over GPL, LGPL, BSD, zlib, etc. for many reasons. 154 | Some of them are listed here: 155 | https://github.com/nothings/stb/blob/master/docs/why_public_domain.md 156 | 157 | #### Why C? 158 | 159 | Primarily, because I use C, not C++. But it does also make it easier 160 | for other people to use them from other languages. 161 | 162 | #### Why not C99? stdint.h, declare-anywhere, etc. 163 | 164 | I still use MSVC 6 (1998) as my IDE because it has better human factors 165 | for me than later versions of MSVC. 166 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/ThirdParty/Stb/github_url.txt: -------------------------------------------------------------------------------- 1 | https://github.com/nothings/stb -------------------------------------------------------------------------------- /Source/Runtime/Engine/ThirdParty/Stb/stb_divide.h: -------------------------------------------------------------------------------- 1 | // stb_divide.h - v0.93 - public domain - Sean Barrett, Feb 2010 2 | // Three kinds of divide/modulus of signed integers. 3 | // 4 | // HISTORY 5 | // 6 | // v0.93 2020-02-02 Write useful exit() value from main() 7 | // v0.92 2019-02-25 Fix warning 8 | // v0.91 2010-02-27 Fix euclidean division by INT_MIN for non-truncating C 9 | // Check result with 64-bit math to catch such cases 10 | // v0.90 2010-02-24 First public release 11 | // 12 | // USAGE 13 | // 14 | // In *ONE* source file, put: 15 | // 16 | // #define STB_DIVIDE_IMPLEMENTATION 17 | // // #define C_INTEGER_DIVISION_TRUNCATES // see Note 1 18 | // // #define C_INTEGER_DIVISION_FLOORS // see Note 2 19 | // #include "stb_divide.h" 20 | // 21 | // Other source files should just include stb_divide.h 22 | // 23 | // Note 1: On platforms/compilers that you know signed C division 24 | // truncates, you can #define C_INTEGER_DIVISION_TRUNCATES. 25 | // 26 | // Note 2: On platforms/compilers that you know signed C division 27 | // floors (rounds to negative infinity), you can #define 28 | // C_INTEGER_DIVISION_FLOORS. 29 | // 30 | // You can #define STB_DIVIDE_TEST in which case the implementation 31 | // will generate a main() and compiling the result will create a 32 | // program that tests the implementation. Run it with no arguments 33 | // and any output indicates an error; run it with any argument and 34 | // it will also print the test results. Define STB_DIVIDE_TEST_64 35 | // to a 64-bit integer type to avoid overflows in the result-checking 36 | // which give false negatives. 37 | // 38 | // ABOUT 39 | // 40 | // This file provides three different consistent divide/mod pairs 41 | // implemented on top of arbitrary C/C++ division, including correct 42 | // handling of overflow of intermediate calculations: 43 | // 44 | // trunc: a/b truncates to 0, a%b has same sign as a 45 | // floor: a/b truncates to -inf, a%b has same sign as b 46 | // eucl: a/b truncates to sign(b)*inf, a%b is non-negative 47 | // 48 | // Not necessarily optimal; I tried to keep it generally efficient, 49 | // but there may be better ways. 50 | // 51 | // Briefly, for those who are not familiar with the problem, we note 52 | // the reason these divides exist and are interesting: 53 | // 54 | // 'trunc' is easy to implement in hardware (strip the signs, 55 | // compute, reapply the signs), thus is commonly defined 56 | // by many languages (including C99) 57 | // 58 | // 'floor' is simple to define and better behaved than trunc; 59 | // for example it divides integers into fixed-size buckets 60 | // without an extra-wide bucket at 0, and for a fixed 61 | // divisor N there are only |N| possible moduli. 62 | // 63 | // 'eucl' guarantees fixed-sized buckets *and* a non-negative 64 | // modulus and defines division to be whatever is needed 65 | // to achieve that result. 66 | // 67 | // See "The Euclidean definition of the functions div and mod" 68 | // by Raymond Boute (1992), or "Division and Modulus for Computer 69 | // Scientists" by Daan Leijen (2001) 70 | // 71 | // We assume of the built-in C division: 72 | // (a) modulus is the remainder for the corresponding division 73 | // (b) a/b truncates if a and b are the same sign 74 | // 75 | // Property (a) requires (a/b)*b + (a%b)==a, and is required by C. 76 | // Property (b) seems to be true of all hardware but is *not* satisfied 77 | // by the euclidean division operator we define, so it's possibly not 78 | // always true. If any such platform turns up, we can add more cases. 79 | // (Possibly only stb_div_trunc currently relies on property (b).) 80 | // 81 | // LICENSE 82 | // 83 | // See end of file for license information. 84 | 85 | 86 | #ifndef INCLUDE_STB_DIVIDE_H 87 | #define INCLUDE_STB_DIVIDE_H 88 | 89 | #ifdef __cplusplus 90 | extern "C" { 91 | #endif 92 | 93 | extern int stb_div_trunc(int value_to_be_divided, int value_to_divide_by); 94 | extern int stb_div_floor(int value_to_be_divided, int value_to_divide_by); 95 | extern int stb_div_eucl (int value_to_be_divided, int value_to_divide_by); 96 | extern int stb_mod_trunc(int value_to_be_divided, int value_to_divide_by); 97 | extern int stb_mod_floor(int value_to_be_divided, int value_to_divide_by); 98 | extern int stb_mod_eucl (int value_to_be_divided, int value_to_divide_by); 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #ifdef STB_DIVIDE_IMPLEMENTATION 105 | 106 | #if defined(__STDC_VERSION) && __STDC_VERSION__ >= 19901 107 | #ifndef C_INTEGER_DIVISION_TRUNCATES 108 | #define C_INTEGER_DIVISION_TRUNCATES 109 | #endif 110 | #endif 111 | 112 | #ifndef INT_MIN 113 | #include // if you have no limits.h, #define INT_MIN yourself 114 | #endif 115 | 116 | // the following macros are designed to allow testing 117 | // other platforms by simulating them 118 | #ifndef STB_DIVIDE_TEST_FLOOR 119 | #define stb__div(a,b) ((a)/(b)) 120 | #define stb__mod(a,b) ((a)%(b)) 121 | #else 122 | // implement floor-style divide on trunc platform 123 | #ifndef C_INTEGER_DIVISION_TRUNCATES 124 | #error "floor test requires truncating division" 125 | #endif 126 | #undef C_INTEGER_DIVISION_TRUNCATES 127 | int stb__div(int v1, int v2) 128 | { 129 | int q = v1/v2, r = v1%v2; 130 | if ((r > 0 && v2 < 0) || (r < 0 && v2 > 0)) 131 | return q-1; 132 | else 133 | return q; 134 | } 135 | 136 | int stb__mod(int v1, int v2) 137 | { 138 | int r = v1%v2; 139 | if ((r > 0 && v2 < 0) || (r < 0 && v2 > 0)) 140 | return r+v2; 141 | else 142 | return r; 143 | } 144 | #endif 145 | 146 | int stb_div_trunc(int v1, int v2) 147 | { 148 | #ifdef C_INTEGER_DIVISION_TRUNCATES 149 | return v1/v2; 150 | #else 151 | if (v1 >= 0 && v2 <= 0) 152 | return -stb__div(-v1,v2); // both negative to avoid overflow 153 | if (v1 <= 0 && v2 >= 0) 154 | if (v1 != INT_MIN) 155 | return -stb__div(v1,-v2); // both negative to avoid overflow 156 | else 157 | return -stb__div(v1+v2,-v2)-1; // push v1 away from wrap point 158 | else 159 | return v1/v2; // same sign, so expect truncation 160 | #endif 161 | } 162 | 163 | int stb_div_floor(int v1, int v2) 164 | { 165 | #ifdef C_INTEGER_DIVISION_FLOORS 166 | return v1/v2; 167 | #else 168 | if (v1 >= 0 && v2 < 0) { 169 | if ((-v1)+v2+1 < 0) // check if increasing v1's magnitude overflows 170 | return -stb__div(-v1+v2+1,v2); // nope, so just compute it 171 | else 172 | return -stb__div(-v1,v2) + ((-v1)%v2 ? -1 : 0); 173 | } 174 | if (v1 < 0 && v2 >= 0) { 175 | if (v1 != INT_MIN) { 176 | if (v1-v2+1 < 0) // check if increasing v1's magnitude overflows 177 | return -stb__div(v1-v2+1,-v2); // nope, so just compute it 178 | else 179 | return -stb__div(-v1,v2) + (stb__mod(v1,-v2) ? -1 : 0); 180 | } else // it must be possible to compute -(v1+v2) without overflowing 181 | return -stb__div(-(v1+v2),v2) + (stb__mod(-(v1+v2),v2) ? -2 : -1); 182 | } else 183 | return v1/v2; // same sign, so expect truncation 184 | #endif 185 | } 186 | 187 | int stb_div_eucl(int v1, int v2) 188 | { 189 | int q,r; 190 | #ifdef C_INTEGER_DIVISION_TRUNCATES 191 | q = v1/v2; 192 | r = v1%v2; 193 | #else 194 | // handle every quadrant separately, since we can't rely on q and r flor 195 | if (v1 >= 0) 196 | if (v2 >= 0) 197 | return stb__div(v1,v2); 198 | else if (v2 != INT_MIN) 199 | q = -stb__div(v1,-v2), r = stb__mod(v1,-v2); 200 | else 201 | q = 0, r = v1; 202 | else if (v1 != INT_MIN) 203 | if (v2 >= 0) 204 | q = -stb__div(-v1,v2), r = -stb__mod(-v1,v2); 205 | else if (v2 != INT_MIN) 206 | q = stb__div(-v1,-v2), r = -stb__mod(-v1,-v2); 207 | else // if v2 is INT_MIN, then we can't use -v2, but we can't divide by v2 208 | q = 1, r = v1-q*v2; 209 | else // if v1 is INT_MIN, we have to move away from overflow place 210 | if (v2 >= 0) 211 | q = -stb__div(-(v1+v2),v2)-1, r = -stb__mod(-(v1+v2),v2); 212 | else 213 | q = stb__div(-(v1-v2),-v2)+1, r = -stb__mod(-(v1-v2),-v2); 214 | #endif 215 | if (r >= 0) 216 | return q; 217 | else 218 | return q + (v2 > 0 ? -1 : 1); 219 | } 220 | 221 | int stb_mod_trunc(int v1, int v2) 222 | { 223 | #ifdef C_INTEGER_DIVISION_TRUNCATES 224 | return v1%v2; 225 | #else 226 | if (v1 >= 0) { // modulus result should always be positive 227 | int r = stb__mod(v1,v2); 228 | if (r >= 0) 229 | return r; 230 | else 231 | return r + (v2 > 0 ? v2 : -v2); 232 | } else { // modulus result should always be negative 233 | int r = stb__mod(v1,v2); 234 | if (r <= 0) 235 | return r; 236 | else 237 | return r - (v2 > 0 ? v2 : -v2); 238 | } 239 | #endif 240 | } 241 | 242 | int stb_mod_floor(int v1, int v2) 243 | { 244 | #ifdef C_INTEGER_DIVISION_FLOORS 245 | return v1%v2; 246 | #else 247 | if (v2 >= 0) { // result should always be positive 248 | int r = stb__mod(v1,v2); 249 | if (r >= 0) 250 | return r; 251 | else 252 | return r + v2; 253 | } else { // result should always be negative 254 | int r = stb__mod(v1,v2); 255 | if (r <= 0) 256 | return r; 257 | else 258 | return r + v2; 259 | } 260 | #endif 261 | } 262 | 263 | int stb_mod_eucl(int v1, int v2) 264 | { 265 | int r = stb__mod(v1,v2); 266 | 267 | if (r >= 0) 268 | return r; 269 | else 270 | return r + (v2 > 0 ? v2 : -v2); // abs() 271 | } 272 | 273 | #ifdef STB_DIVIDE_TEST 274 | #include 275 | #include 276 | #include 277 | 278 | int show=0; 279 | int err=0; 280 | 281 | void stbdiv_check(int q, int r, int a, int b, char *type, int dir) 282 | { 283 | if ((dir > 0 && r < 0) || (dir < 0 && r > 0)) { 284 | fprintf(stderr, "FAILED: %s(%d,%d) remainder %d in wrong direction\n", type,a,b,r); 285 | err++; 286 | } else 287 | if (b != INT_MIN) // can't compute abs(), but if b==INT_MIN all remainders are valid 288 | if (r <= -abs(b) || r >= abs(b)) { 289 | fprintf(stderr, "FAILED: %s(%d,%d) remainder %d out of range\n", type,a,b,r); 290 | err++; 291 | } 292 | #ifdef STB_DIVIDE_TEST_64 293 | { 294 | STB_DIVIDE_TEST_64 q64 = q, r64=r, a64=a, b64=b; 295 | if (q64*b64+r64 != a64) { 296 | fprintf(stderr, "FAILED: %s(%d,%d) remainder %d doesn't match quotient %d\n", type,a,b,r,q); 297 | err++; 298 | } 299 | } 300 | #else 301 | if (q*b+r != a) { 302 | fprintf(stderr, "FAILED: %s(%d,%d) remainder %d doesn't match quotient %d\n", type,a,b,r,q); 303 | err++; 304 | } 305 | #endif 306 | } 307 | 308 | void test(int a, int b) 309 | { 310 | int q,r; 311 | if (show) printf("(%+11d,%+d) | ", a,b); 312 | q = stb_div_trunc(a,b), r = stb_mod_trunc(a,b); 313 | if (show) printf("(%+11d,%+2d) ", q,r); stbdiv_check(q,r,a,b, "trunc",a); 314 | q = stb_div_floor(a,b), r = stb_mod_floor(a,b); 315 | if (show) printf("(%+11d,%+2d) ", q,r); stbdiv_check(q,r,a,b, "floor",b); 316 | q = stb_div_eucl (a,b), r = stb_mod_eucl (a,b); 317 | if (show) printf("(%+11d,%+2d)\n", q,r); stbdiv_check(q,r,a,b, "euclidean",1); 318 | } 319 | 320 | void testh(int a, int b) 321 | { 322 | int q,r; 323 | if (show) printf("(%08x,%08x) |\n", a,b); 324 | q = stb_div_trunc(a,b), r = stb_mod_trunc(a,b); stbdiv_check(q,r,a,b, "trunc",a); 325 | if (show) printf(" (%08x,%08x)", q,r); 326 | q = stb_div_floor(a,b), r = stb_mod_floor(a,b); stbdiv_check(q,r,a,b, "floor",b); 327 | if (show) printf(" (%08x,%08x)", q,r); 328 | q = stb_div_eucl (a,b), r = stb_mod_eucl (a,b); stbdiv_check(q,r,a,b, "euclidean",1); 329 | if (show) printf(" (%08x,%08x)\n ", q,r); 330 | } 331 | 332 | int main(int argc, char **argv) 333 | { 334 | if (argc > 1) show=1; 335 | 336 | test(8,3); 337 | test(8,-3); 338 | test(-8,3); 339 | test(-8,-3); 340 | test(1,2); 341 | test(1,-2); 342 | test(-1,2); 343 | test(-1,-2); 344 | test(8,4); 345 | test(8,-4); 346 | test(-8,4); 347 | test(-8,-4); 348 | 349 | test(INT_MAX,1); 350 | test(INT_MIN,1); 351 | test(INT_MIN+1,1); 352 | test(INT_MAX,-1); 353 | //test(INT_MIN,-1); // this traps in MSVC, so we leave it untested 354 | test(INT_MIN+1,-1); 355 | test(INT_MIN,-2); 356 | test(INT_MIN+1,2); 357 | test(INT_MIN+1,-2); 358 | test(INT_MAX,2); 359 | test(INT_MAX,-2); 360 | test(INT_MIN+1,2); 361 | test(INT_MIN+1,-2); 362 | test(INT_MIN,2); 363 | test(INT_MIN,-2); 364 | test(INT_MIN,7); 365 | test(INT_MIN,-7); 366 | test(INT_MIN+1,4); 367 | test(INT_MIN+1,-4); 368 | 369 | testh(-7, INT_MIN); 370 | testh(-1, INT_MIN); 371 | testh(1, INT_MIN); 372 | testh(7, INT_MIN); 373 | 374 | testh(INT_MAX-1, INT_MIN); 375 | testh(INT_MAX, INT_MIN); 376 | testh(INT_MIN, INT_MIN); 377 | testh(INT_MIN+1, INT_MIN); 378 | 379 | testh(INT_MAX-1, INT_MAX); 380 | testh(INT_MAX , INT_MAX); 381 | testh(INT_MIN , INT_MAX); 382 | testh(INT_MIN+1, INT_MAX); 383 | 384 | return err > 0 ? 1 : 0; 385 | } 386 | #endif // STB_DIVIDE_TEST 387 | #endif // STB_DIVIDE_IMPLEMENTATION 388 | #endif // INCLUDE_STB_DIVIDE_H 389 | 390 | /* 391 | ------------------------------------------------------------------------------ 392 | This software is available under 2 licenses -- choose whichever you prefer. 393 | ------------------------------------------------------------------------------ 394 | ALTERNATIVE A - MIT License 395 | Copyright (c) 2017 Sean Barrett 396 | Permission is hereby granted, free of charge, to any person obtaining a copy of 397 | this software and associated documentation files (the "Software"), to deal in 398 | the Software without restriction, including without limitation the rights to 399 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 400 | of the Software, and to permit persons to whom the Software is furnished to do 401 | so, subject to the following conditions: 402 | The above copyright notice and this permission notice shall be included in all 403 | copies or substantial portions of the Software. 404 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 405 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 406 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 407 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 408 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 409 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 410 | SOFTWARE. 411 | ------------------------------------------------------------------------------ 412 | ALTERNATIVE B - Public Domain (www.unlicense.org) 413 | This is free and unencumbered software released into the public domain. 414 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 415 | software, either in source code form or as a compiled binary, for any purpose, 416 | commercial or non-commercial, and by any means. 417 | In jurisdictions that recognize copyright laws, the author or authors of this 418 | software dedicate any and all copyright interest in the software to the public 419 | domain. We make this dedication for the benefit of the public at large and to 420 | the detriment of our heirs and successors. We intend this dedication to be an 421 | overt act of relinquishment in perpetuity of all present and future rights to 422 | this software under copyright law. 423 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 424 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 425 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 426 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 427 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 428 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 429 | ------------------------------------------------------------------------------ 430 | */ 431 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/ThirdParty/Stb/stb_easy_font.h: -------------------------------------------------------------------------------- 1 | // stb_easy_font.h - v1.1 - bitmap font for 3D rendering - public domain 2 | // Sean Barrett, Feb 2015 3 | // 4 | // Easy-to-deploy, 5 | // reasonably compact, 6 | // extremely inefficient performance-wise, 7 | // crappy-looking, 8 | // ASCII-only, 9 | // bitmap font for use in 3D APIs. 10 | // 11 | // Intended for when you just want to get some text displaying 12 | // in a 3D app as quickly as possible. 13 | // 14 | // Doesn't use any textures, instead builds characters out of quads. 15 | // 16 | // DOCUMENTATION: 17 | // 18 | // int stb_easy_font_width(char *text) 19 | // int stb_easy_font_height(char *text) 20 | // 21 | // Takes a string and returns the horizontal size and the 22 | // vertical size (which can vary if 'text' has newlines). 23 | // 24 | // int stb_easy_font_print(float x, float y, 25 | // char *text, unsigned char color[4], 26 | // void *vertex_buffer, int vbuf_size) 27 | // 28 | // Takes a string (which can contain '\n') and fills out a 29 | // vertex buffer with renderable data to draw the string. 30 | // Output data assumes increasing x is rightwards, increasing y 31 | // is downwards. 32 | // 33 | // The vertex data is divided into quads, i.e. there are four 34 | // vertices in the vertex buffer for each quad. 35 | // 36 | // The vertices are stored in an interleaved format: 37 | // 38 | // x:float 39 | // y:float 40 | // z:float 41 | // color:uint8[4] 42 | // 43 | // You can ignore z and color if you get them from elsewhere 44 | // This format was chosen in the hopes it would make it 45 | // easier for you to reuse existing vertex-buffer-drawing code. 46 | // 47 | // If you pass in NULL for color, it becomes 255,255,255,255. 48 | // 49 | // Returns the number of quads. 50 | // 51 | // If the buffer isn't large enough, it will truncate. 52 | // Expect it to use an average of ~270 bytes per character. 53 | // 54 | // If your API doesn't draw quads, build a reusable index 55 | // list that allows you to render quads as indexed triangles. 56 | // 57 | // void stb_easy_font_spacing(float spacing) 58 | // 59 | // Use positive values to expand the space between characters, 60 | // and small negative values (no smaller than -1.5) to contract 61 | // the space between characters. 62 | // 63 | // E.g. spacing = 1 adds one "pixel" of spacing between the 64 | // characters. spacing = -1 is reasonable but feels a bit too 65 | // compact to me; -0.5 is a reasonable compromise as long as 66 | // you're scaling the font up. 67 | // 68 | // LICENSE 69 | // 70 | // See end of file for license information. 71 | // 72 | // VERSION HISTORY 73 | // 74 | // (2020-02-02) 1.1 make everything static so can compile it in more than one src file 75 | // (2017-01-15) 1.0 space character takes same space as numbers; fix bad spacing of 'f' 76 | // (2016-01-22) 0.7 width() supports multiline text; add height() 77 | // (2015-09-13) 0.6 #include ; updated license 78 | // (2015-02-01) 0.5 First release 79 | // 80 | // CONTRIBUTORS 81 | // 82 | // github:vassvik -- bug report 83 | // github:podsvirov -- fix multiple definition errors 84 | 85 | #if 0 86 | // SAMPLE CODE: 87 | // 88 | // Here's sample code for old OpenGL; it's a lot more complicated 89 | // to make work on modern APIs, and that's your problem. 90 | // 91 | void print_string(float x, float y, char *text, float r, float g, float b) 92 | { 93 | static char buffer[99999]; // ~500 chars 94 | int num_quads; 95 | 96 | num_quads = stb_easy_font_print(x, y, text, NULL, buffer, sizeof(buffer)); 97 | 98 | glColor3f(r,g,b); 99 | glEnableClientState(GL_VERTEX_ARRAY); 100 | glVertexPointer(2, GL_FLOAT, 16, buffer); 101 | glDrawArrays(GL_QUADS, 0, num_quads*4); 102 | glDisableClientState(GL_VERTEX_ARRAY); 103 | } 104 | #endif 105 | 106 | #ifndef INCLUDE_STB_EASY_FONT_H 107 | #define INCLUDE_STB_EASY_FONT_H 108 | 109 | #include 110 | #include 111 | 112 | static struct stb_easy_font_info_struct { 113 | unsigned char advance; 114 | unsigned char h_seg; 115 | unsigned char v_seg; 116 | } stb_easy_font_charinfo[96] = { 117 | { 6, 0, 0 }, { 3, 0, 0 }, { 5, 1, 1 }, { 7, 1, 4 }, 118 | { 7, 3, 7 }, { 7, 6, 12 }, { 7, 8, 19 }, { 4, 16, 21 }, 119 | { 4, 17, 22 }, { 4, 19, 23 }, { 23, 21, 24 }, { 23, 22, 31 }, 120 | { 20, 23, 34 }, { 22, 23, 36 }, { 19, 24, 36 }, { 21, 25, 36 }, 121 | { 6, 25, 39 }, { 6, 27, 43 }, { 6, 28, 45 }, { 6, 30, 49 }, 122 | { 6, 33, 53 }, { 6, 34, 57 }, { 6, 40, 58 }, { 6, 46, 59 }, 123 | { 6, 47, 62 }, { 6, 55, 64 }, { 19, 57, 68 }, { 20, 59, 68 }, 124 | { 21, 61, 69 }, { 22, 66, 69 }, { 21, 68, 69 }, { 7, 73, 69 }, 125 | { 9, 75, 74 }, { 6, 78, 81 }, { 6, 80, 85 }, { 6, 83, 90 }, 126 | { 6, 85, 91 }, { 6, 87, 95 }, { 6, 90, 96 }, { 7, 92, 97 }, 127 | { 6, 96,102 }, { 5, 97,106 }, { 6, 99,107 }, { 6,100,110 }, 128 | { 6,100,115 }, { 7,101,116 }, { 6,101,121 }, { 6,101,125 }, 129 | { 6,102,129 }, { 7,103,133 }, { 6,104,140 }, { 6,105,145 }, 130 | { 7,107,149 }, { 6,108,151 }, { 7,109,155 }, { 7,109,160 }, 131 | { 7,109,165 }, { 7,118,167 }, { 6,118,172 }, { 4,120,176 }, 132 | { 6,122,177 }, { 4,122,181 }, { 23,124,182 }, { 22,129,182 }, 133 | { 4,130,182 }, { 22,131,183 }, { 6,133,187 }, { 22,135,191 }, 134 | { 6,137,192 }, { 22,139,196 }, { 6,144,197 }, { 22,147,198 }, 135 | { 6,150,202 }, { 19,151,206 }, { 21,152,207 }, { 6,155,209 }, 136 | { 3,160,210 }, { 23,160,211 }, { 22,164,216 }, { 22,165,220 }, 137 | { 22,167,224 }, { 22,169,228 }, { 21,171,232 }, { 21,173,233 }, 138 | { 5,178,233 }, { 22,179,234 }, { 23,180,238 }, { 23,180,243 }, 139 | { 23,180,248 }, { 22,189,248 }, { 22,191,252 }, { 5,196,252 }, 140 | { 3,203,252 }, { 5,203,253 }, { 22,210,253 }, { 0,214,253 }, 141 | }; 142 | 143 | static unsigned char stb_easy_font_hseg[214] = { 144 | 97,37,69,84,28,51,2,18,10,49,98,41,65,25,81,105,33,9,97,1,97,37,37,36, 145 | 81,10,98,107,3,100,3,99,58,51,4,99,58,8,73,81,10,50,98,8,73,81,4,10,50, 146 | 98,8,25,33,65,81,10,50,17,65,97,25,33,25,49,9,65,20,68,1,65,25,49,41, 147 | 11,105,13,101,76,10,50,10,50,98,11,99,10,98,11,50,99,11,50,11,99,8,57, 148 | 58,3,99,99,107,10,10,11,10,99,11,5,100,41,65,57,41,65,9,17,81,97,3,107, 149 | 9,97,1,97,33,25,9,25,41,100,41,26,82,42,98,27,83,42,98,26,51,82,8,41, 150 | 35,8,10,26,82,114,42,1,114,8,9,73,57,81,41,97,18,8,8,25,26,26,82,26,82, 151 | 26,82,41,25,33,82,26,49,73,35,90,17,81,41,65,57,41,65,25,81,90,114,20, 152 | 84,73,57,41,49,25,33,65,81,9,97,1,97,25,33,65,81,57,33,25,41,25, 153 | }; 154 | 155 | static unsigned char stb_easy_font_vseg[253] = { 156 | 4,2,8,10,15,8,15,33,8,15,8,73,82,73,57,41,82,10,82,18,66,10,21,29,1,65, 157 | 27,8,27,9,65,8,10,50,97,74,66,42,10,21,57,41,29,25,14,81,73,57,26,8,8, 158 | 26,66,3,8,8,15,19,21,90,58,26,18,66,18,105,89,28,74,17,8,73,57,26,21, 159 | 8,42,41,42,8,28,22,8,8,30,7,8,8,26,66,21,7,8,8,29,7,7,21,8,8,8,59,7,8, 160 | 8,15,29,8,8,14,7,57,43,10,82,7,7,25,42,25,15,7,25,41,15,21,105,105,29, 161 | 7,57,57,26,21,105,73,97,89,28,97,7,57,58,26,82,18,57,57,74,8,30,6,8,8, 162 | 14,3,58,90,58,11,7,74,43,74,15,2,82,2,42,75,42,10,67,57,41,10,7,2,42, 163 | 74,106,15,2,35,8,8,29,7,8,8,59,35,51,8,8,15,35,30,35,8,8,30,7,8,8,60, 164 | 36,8,45,7,7,36,8,43,8,44,21,8,8,44,35,8,8,43,23,8,8,43,35,8,8,31,21,15, 165 | 20,8,8,28,18,58,89,58,26,21,89,73,89,29,20,8,8,30,7, 166 | }; 167 | 168 | typedef struct 169 | { 170 | unsigned char c[4]; 171 | } stb_easy_font_color; 172 | 173 | static int stb_easy_font_draw_segs(float x, float y, unsigned char *segs, int num_segs, int vertical, stb_easy_font_color c, char *vbuf, int vbuf_size, int offset) 174 | { 175 | int i,j; 176 | for (i=0; i < num_segs; ++i) { 177 | int len = segs[i] & 7; 178 | x += (float) ((segs[i] >> 3) & 1); 179 | if (len && offset+64 <= vbuf_size) { 180 | float y0 = y + (float) (segs[i]>>4); 181 | for (j=0; j < 4; ++j) { 182 | * (float *) (vbuf+offset+0) = x + (j==1 || j==2 ? (vertical ? 1 : len) : 0); 183 | * (float *) (vbuf+offset+4) = y0 + ( j >= 2 ? (vertical ? len : 1) : 0); 184 | * (float *) (vbuf+offset+8) = 0.f; 185 | * (stb_easy_font_color *) (vbuf+offset+12) = c; 186 | offset += 16; 187 | } 188 | } 189 | } 190 | return offset; 191 | } 192 | 193 | static float stb_easy_font_spacing_val = 0; 194 | static void stb_easy_font_spacing(float spacing) 195 | { 196 | stb_easy_font_spacing_val = spacing; 197 | } 198 | 199 | static int stb_easy_font_print(float x, float y, char *text, unsigned char color[4], void *vertex_buffer, int vbuf_size) 200 | { 201 | char *vbuf = (char *) vertex_buffer; 202 | float start_x = x; 203 | int offset = 0; 204 | 205 | stb_easy_font_color c = { 255,255,255,255 }; // use structure copying to avoid needing depending on memcpy() 206 | if (color) { c.c[0] = color[0]; c.c[1] = color[1]; c.c[2] = color[2]; c.c[3] = color[3]; } 207 | 208 | while (*text && offset < vbuf_size) { 209 | if (*text == '\n') { 210 | y += 12; 211 | x = start_x; 212 | } else { 213 | unsigned char advance = stb_easy_font_charinfo[*text-32].advance; 214 | float y_ch = advance & 16 ? y+1 : y; 215 | int h_seg, v_seg, num_h, num_v; 216 | h_seg = stb_easy_font_charinfo[*text-32 ].h_seg; 217 | v_seg = stb_easy_font_charinfo[*text-32 ].v_seg; 218 | num_h = stb_easy_font_charinfo[*text-32+1].h_seg - h_seg; 219 | num_v = stb_easy_font_charinfo[*text-32+1].v_seg - v_seg; 220 | offset = stb_easy_font_draw_segs(x, y_ch, &stb_easy_font_hseg[h_seg], num_h, 0, c, vbuf, vbuf_size, offset); 221 | offset = stb_easy_font_draw_segs(x, y_ch, &stb_easy_font_vseg[v_seg], num_v, 1, c, vbuf, vbuf_size, offset); 222 | x += advance & 15; 223 | x += stb_easy_font_spacing_val; 224 | } 225 | ++text; 226 | } 227 | return (unsigned) offset/64; 228 | } 229 | 230 | static int stb_easy_font_width(char *text) 231 | { 232 | float len = 0; 233 | float max_len = 0; 234 | while (*text) { 235 | if (*text == '\n') { 236 | if (len > max_len) max_len = len; 237 | len = 0; 238 | } else { 239 | len += stb_easy_font_charinfo[*text-32].advance & 15; 240 | len += stb_easy_font_spacing_val; 241 | } 242 | ++text; 243 | } 244 | if (len > max_len) max_len = len; 245 | return (int) ceil(max_len); 246 | } 247 | 248 | static int stb_easy_font_height(char *text) 249 | { 250 | float y = 0; 251 | int nonempty_line=0; 252 | while (*text) { 253 | if (*text == '\n') { 254 | y += 12; 255 | nonempty_line = 0; 256 | } else { 257 | nonempty_line = 1; 258 | } 259 | ++text; 260 | } 261 | return (int) ceil(y + (nonempty_line ? 12 : 0)); 262 | } 263 | #endif 264 | 265 | /* 266 | ------------------------------------------------------------------------------ 267 | This software is available under 2 licenses -- choose whichever you prefer. 268 | ------------------------------------------------------------------------------ 269 | ALTERNATIVE A - MIT License 270 | Copyright (c) 2017 Sean Barrett 271 | Permission is hereby granted, free of charge, to any person obtaining a copy of 272 | this software and associated documentation files (the "Software"), to deal in 273 | the Software without restriction, including without limitation the rights to 274 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 275 | of the Software, and to permit persons to whom the Software is furnished to do 276 | so, subject to the following conditions: 277 | The above copyright notice and this permission notice shall be included in all 278 | copies or substantial portions of the Software. 279 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 280 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 281 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 282 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 283 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 284 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 285 | SOFTWARE. 286 | ------------------------------------------------------------------------------ 287 | ALTERNATIVE B - Public Domain (www.unlicense.org) 288 | This is free and unencumbered software released into the public domain. 289 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 290 | software, either in source code form or as a compiled binary, for any purpose, 291 | commercial or non-commercial, and by any means. 292 | In jurisdictions that recognize copyright laws, the author or authors of this 293 | software dedicate any and all copyright interest in the software to the public 294 | domain. We make this dedication for the benefit of the public at large and to 295 | the detriment of our heirs and successors. We intend this dedication to be an 296 | overt act of relinquishment in perpetuity of all present and future rights to 297 | this software under copyright law. 298 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 299 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 300 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 301 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 302 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 303 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 304 | ------------------------------------------------------------------------------ 305 | */ 306 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/ThirdParty/Stb/stb_include.h: -------------------------------------------------------------------------------- 1 | // stb_include.h - v0.02 - parse and process #include directives - public domain 2 | // 3 | // To build this, in one source file that includes this file do 4 | // #define STB_INCLUDE_IMPLEMENTATION 5 | // 6 | // This program parses a string and replaces lines of the form 7 | // #include "foo" 8 | // with the contents of a file named "foo". It also embeds the 9 | // appropriate #line directives. Note that all include files must 10 | // reside in the location specified in the path passed to the API; 11 | // it does not check multiple directories. 12 | // 13 | // If the string contains a line of the form 14 | // #inject 15 | // then it will be replaced with the contents of the string 'inject' passed to the API. 16 | // 17 | // Options: 18 | // 19 | // Define STB_INCLUDE_LINE_GLSL to get GLSL-style #line directives 20 | // which use numbers instead of filenames. 21 | // 22 | // Define STB_INCLUDE_LINE_NONE to disable output of #line directives. 23 | // 24 | // Standard libraries: 25 | // 26 | // stdio.h FILE, fopen, fclose, fseek, ftell 27 | // stdlib.h malloc, realloc, free 28 | // string.h strcpy, strncmp, memcpy 29 | // 30 | // Credits: 31 | // 32 | // Written by Sean Barrett. 33 | // 34 | // Fixes: 35 | // Michal Klos 36 | 37 | #ifndef STB_INCLUDE_STB_INCLUDE_H 38 | #define STB_INCLUDE_STB_INCLUDE_H 39 | 40 | // Do include-processing on the string 'str'. To free the return value, pass it to free() 41 | char *stb_include_string(char *str, char *inject, char *path_to_includes, char *filename_for_line_directive, char error[256]); 42 | 43 | // Concatenate the strings 'strs' and do include-processing on the result. To free the return value, pass it to free() 44 | char *stb_include_strings(char **strs, int count, char *inject, char *path_to_includes, char *filename_for_line_directive, char error[256]); 45 | 46 | // Load the file 'filename' and do include-processing on the string therein. note that 47 | // 'filename' is opened directly; 'path_to_includes' is not used. To free the return value, pass it to free() 48 | char *stb_include_file(char *filename, char *inject, char *path_to_includes, char error[256]); 49 | 50 | #endif 51 | 52 | 53 | #ifdef STB_INCLUDE_IMPLEMENTATION 54 | 55 | #include 56 | #include 57 | #include 58 | 59 | static char *stb_include_load_file(char *filename, size_t *plen) 60 | { 61 | char *text; 62 | size_t len; 63 | FILE *f = fopen(filename, "rb"); 64 | if (f == 0) return 0; 65 | fseek(f, 0, SEEK_END); 66 | len = (size_t) ftell(f); 67 | if (plen) *plen = len; 68 | text = (char *) malloc(len+1); 69 | if (text == 0) return 0; 70 | fseek(f, 0, SEEK_SET); 71 | fread(text, 1, len, f); 72 | fclose(f); 73 | text[len] = 0; 74 | return text; 75 | } 76 | 77 | typedef struct 78 | { 79 | int offset; 80 | int end; 81 | char *filename; 82 | int next_line_after; 83 | } include_info; 84 | 85 | static include_info *stb_include_append_include(include_info *array, int len, int offset, int end, char *filename, int next_line) 86 | { 87 | include_info *z = (include_info *) realloc(array, sizeof(*z) * (len+1)); 88 | z[len].offset = offset; 89 | z[len].end = end; 90 | z[len].filename = filename; 91 | z[len].next_line_after = next_line; 92 | return z; 93 | } 94 | 95 | static void stb_include_free_includes(include_info *array, int len) 96 | { 97 | int i; 98 | for (i=0; i < len; ++i) 99 | free(array[i].filename); 100 | free(array); 101 | } 102 | 103 | static int stb_include_isspace(int ch) 104 | { 105 | return (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'); 106 | } 107 | 108 | // find location of all #include and #inject 109 | static int stb_include_find_includes(char *text, include_info **plist) 110 | { 111 | int line_count = 1; 112 | int inc_count = 0; 113 | char *s = text, *start; 114 | include_info *list = NULL; 115 | while (*s) { 116 | // parse is always at start of line when we reach here 117 | start = s; 118 | while (*s == ' ' || *s == '\t') 119 | ++s; 120 | if (*s == '#') { 121 | ++s; 122 | while (*s == ' ' || *s == '\t') 123 | ++s; 124 | if (0==strncmp(s, "include", 7) && stb_include_isspace(s[7])) { 125 | s += 7; 126 | while (*s == ' ' || *s == '\t') 127 | ++s; 128 | if (*s == '"') { 129 | char *t = ++s; 130 | while (*t != '"' && *t != '\n' && *t != '\r' && *t != 0) 131 | ++t; 132 | if (*t == '"') { 133 | char *filename = (char *) malloc(t-s+1); 134 | memcpy(filename, s, t-s); 135 | filename[t-s] = 0; 136 | s=t; 137 | while (*s != '\r' && *s != '\n' && *s != 0) 138 | ++s; 139 | // s points to the newline, so s-start is everything except the newline 140 | list = stb_include_append_include(list, inc_count++, start-text, s-text, filename, line_count+1); 141 | } 142 | } 143 | } else if (0==strncmp(s, "inject", 6) && (stb_include_isspace(s[6]) || s[6]==0)) { 144 | while (*s != '\r' && *s != '\n' && *s != 0) 145 | ++s; 146 | list = stb_include_append_include(list, inc_count++, start-text, s-text, NULL, line_count+1); 147 | } 148 | } 149 | while (*s != '\r' && *s != '\n' && *s != 0) 150 | ++s; 151 | if (*s == '\r' || *s == '\n') { 152 | s = s + (s[0] + s[1] == '\r' + '\n' ? 2 : 1); 153 | } 154 | ++line_count; 155 | } 156 | *plist = list; 157 | return inc_count; 158 | } 159 | 160 | // avoid dependency on sprintf() 161 | static void stb_include_itoa(char str[9], int n) 162 | { 163 | int i; 164 | for (i=0; i < 8; ++i) 165 | str[i] = ' '; 166 | str[i] = 0; 167 | 168 | for (i=1; i < 8; ++i) { 169 | str[7-i] = '0' + (n % 10); 170 | n /= 10; 171 | if (n == 0) 172 | break; 173 | } 174 | } 175 | 176 | static char *stb_include_append(char *str, size_t *curlen, char *addstr, size_t addlen) 177 | { 178 | str = (char *) realloc(str, *curlen + addlen); 179 | memcpy(str + *curlen, addstr, addlen); 180 | *curlen += addlen; 181 | return str; 182 | } 183 | 184 | char *stb_include_string(char *str, char *inject, char *path_to_includes, char *filename, char error[256]) 185 | { 186 | char temp[4096]; 187 | include_info *inc_list; 188 | int i, num = stb_include_find_includes(str, &inc_list); 189 | size_t source_len = strlen(str); 190 | char *text=0; 191 | size_t textlen=0, last=0; 192 | for (i=0; i < num; ++i) { 193 | text = stb_include_append(text, &textlen, str+last, inc_list[i].offset - last); 194 | // write out line directive for the include 195 | #ifndef STB_INCLUDE_LINE_NONE 196 | #ifdef STB_INCLUDE_LINE_GLSL 197 | if (textlen != 0) // GLSL #version must appear first, so don't put a #line at the top 198 | #endif 199 | { 200 | strcpy(temp, "#line "); 201 | stb_include_itoa(temp+6, 1); 202 | strcat(temp, " "); 203 | #ifdef STB_INCLUDE_LINE_GLSL 204 | stb_include_itoa(temp+15, i+1); 205 | #else 206 | strcat(temp, "\""); 207 | if (inc_list[i].filename == 0) 208 | strcmp(temp, "INJECT"); 209 | else 210 | strcat(temp, inc_list[i].filename); 211 | strcat(temp, "\""); 212 | #endif 213 | strcat(temp, "\n"); 214 | text = stb_include_append(text, &textlen, temp, strlen(temp)); 215 | } 216 | #endif 217 | if (inc_list[i].filename == 0) { 218 | if (inject != 0) 219 | text = stb_include_append(text, &textlen, inject, strlen(inject)); 220 | } else { 221 | char *inc; 222 | strcpy(temp, path_to_includes); 223 | strcat(temp, "/"); 224 | strcat(temp, inc_list[i].filename); 225 | inc = stb_include_file(temp, inject, path_to_includes, error); 226 | if (inc == NULL) { 227 | stb_include_free_includes(inc_list, num); 228 | return NULL; 229 | } 230 | text = stb_include_append(text, &textlen, inc, strlen(inc)); 231 | free(inc); 232 | } 233 | // write out line directive 234 | #ifndef STB_INCLUDE_LINE_NONE 235 | strcpy(temp, "\n#line "); 236 | stb_include_itoa(temp+6, inc_list[i].next_line_after); 237 | strcat(temp, " "); 238 | #ifdef STB_INCLUDE_LINE_GLSL 239 | stb_include_itoa(temp+15, 0); 240 | #else 241 | strcat(temp, filename != 0 ? filename : "source-file"); 242 | #endif 243 | text = stb_include_append(text, &textlen, temp, strlen(temp)); 244 | // no newlines, because we kept the #include newlines, which will get appended next 245 | #endif 246 | last = inc_list[i].end; 247 | } 248 | text = stb_include_append(text, &textlen, str+last, source_len - last + 1); // append '\0' 249 | stb_include_free_includes(inc_list, num); 250 | return text; 251 | } 252 | 253 | char *stb_include_strings(char **strs, int count, char *inject, char *path_to_includes, char *filename, char error[256]) 254 | { 255 | char *text; 256 | char *result; 257 | int i; 258 | size_t length=0; 259 | for (i=0; i < count; ++i) 260 | length += strlen(strs[i]); 261 | text = (char *) malloc(length+1); 262 | length = 0; 263 | for (i=0; i < count; ++i) { 264 | strcpy(text + length, strs[i]); 265 | length += strlen(strs[i]); 266 | } 267 | result = stb_include_string(text, inject, path_to_includes, filename, error); 268 | free(text); 269 | return result; 270 | } 271 | 272 | char *stb_include_file(char *filename, char *inject, char *path_to_includes, char error[256]) 273 | { 274 | size_t len; 275 | char *result; 276 | char *text = stb_include_load_file(filename, &len); 277 | if (text == NULL) { 278 | strcpy(error, "Error: couldn't load '"); 279 | strcat(error, filename); 280 | strcat(error, "'"); 281 | return 0; 282 | } 283 | result = stb_include_string(text, inject, path_to_includes, filename, error); 284 | free(text); 285 | return result; 286 | } 287 | 288 | #if 0 // @TODO, GL_ARB_shader_language_include-style system that doesn't touch filesystem 289 | char *stb_include_preloaded(char *str, char *inject, char *includes[][2], char error[256]) 290 | { 291 | 292 | } 293 | #endif 294 | 295 | #endif // STB_INCLUDE_IMPLEMENTATION 296 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/ThirdParty/Stb/stb_leakcheck.h: -------------------------------------------------------------------------------- 1 | // stb_leakcheck.h - v0.6 - quick & dirty malloc leak-checking - public domain 2 | // LICENSE 3 | // 4 | // See end of file. 5 | 6 | #ifdef STB_LEAKCHECK_IMPLEMENTATION 7 | #undef STB_LEAKCHECK_IMPLEMENTATION // don't implement more than once 8 | 9 | // if we've already included leakcheck before, undefine the macros 10 | #ifdef malloc 11 | #undef malloc 12 | #undef free 13 | #undef realloc 14 | #endif 15 | 16 | #ifndef STB_LEAKCHECK_OUTPUT_PIPE 17 | #define STB_LEAKCHECK_OUTPUT_PIPE stdout 18 | #endif 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | typedef struct malloc_info stb_leakcheck_malloc_info; 26 | 27 | struct malloc_info 28 | { 29 | const char *file; 30 | int line; 31 | size_t size; 32 | stb_leakcheck_malloc_info *next,*prev; 33 | }; 34 | 35 | static stb_leakcheck_malloc_info *mi_head; 36 | 37 | void *stb_leakcheck_malloc(size_t sz, const char *file, int line) 38 | { 39 | stb_leakcheck_malloc_info *mi = (stb_leakcheck_malloc_info *) malloc(sz + sizeof(*mi)); 40 | if (mi == NULL) return mi; 41 | mi->file = file; 42 | mi->line = line; 43 | mi->next = mi_head; 44 | if (mi_head) 45 | mi->next->prev = mi; 46 | mi->prev = NULL; 47 | mi->size = (int) sz; 48 | mi_head = mi; 49 | return mi+1; 50 | } 51 | 52 | void stb_leakcheck_free(void *ptr) 53 | { 54 | if (ptr != NULL) { 55 | stb_leakcheck_malloc_info *mi = (stb_leakcheck_malloc_info *) ptr - 1; 56 | mi->size = ~mi->size; 57 | #ifndef STB_LEAKCHECK_SHOWALL 58 | if (mi->prev == NULL) { 59 | assert(mi_head == mi); 60 | mi_head = mi->next; 61 | } else 62 | mi->prev->next = mi->next; 63 | if (mi->next) 64 | mi->next->prev = mi->prev; 65 | free(mi); 66 | #endif 67 | } 68 | } 69 | 70 | void *stb_leakcheck_realloc(void *ptr, size_t sz, const char *file, int line) 71 | { 72 | if (ptr == NULL) { 73 | return stb_leakcheck_malloc(sz, file, line); 74 | } else if (sz == 0) { 75 | stb_leakcheck_free(ptr); 76 | return NULL; 77 | } else { 78 | stb_leakcheck_malloc_info *mi = (stb_leakcheck_malloc_info *) ptr - 1; 79 | if (sz <= mi->size) 80 | return ptr; 81 | else { 82 | #ifdef STB_LEAKCHECK_REALLOC_PRESERVE_MALLOC_FILELINE 83 | void *q = stb_leakcheck_malloc(sz, mi->file, mi->line); 84 | #else 85 | void *q = stb_leakcheck_malloc(sz, file, line); 86 | #endif 87 | if (q) { 88 | memcpy(q, ptr, mi->size); 89 | stb_leakcheck_free(ptr); 90 | } 91 | return q; 92 | } 93 | } 94 | } 95 | 96 | static void stblkck_internal_print(const char *reason, stb_leakcheck_malloc_info *mi) 97 | { 98 | #if defined(_MSC_VER) && _MSC_VER < 1900 // 1900=VS 2015 99 | // Compilers that use the old MS C runtime library don't have %zd 100 | // and the older ones don't even have %lld either... however, the old compilers 101 | // without "long long" don't support 64-bit targets either, so here's the 102 | // compromise: 103 | #if _MSC_VER < 1400 // before VS 2005 104 | fprintf(STB_LEAKCHECK_OUTPUT_PIPE, "%s: %s (%4d): %8d bytes at %p\n", reason, mi->file, mi->line, (int)mi->size, (void*)(mi+1)); 105 | #else 106 | fprintf(STB_LEAKCHECK_OUTPUT_PIPE, "%s: %s (%4d): %16lld bytes at %p\n", reason, mi->file, mi->line, (long long)mi->size, (void*)(mi+1)); 107 | #endif 108 | #else 109 | // Assume we have %zd on other targets. 110 | #ifdef __MINGW32__ 111 | __mingw_fprintf(STB_LEAKCHECK_OUTPUT_PIPE, "%s: %s (%4d): %zd bytes at %p\n", reason, mi->file, mi->line, mi->size, (void*)(mi+1)); 112 | #else 113 | fprintf(STB_LEAKCHECK_OUTPUT_PIPE, "%s: %s (%4d): %zd bytes at %p\n", reason, mi->file, mi->line, mi->size, (void*)(mi+1)); 114 | #endif 115 | #endif 116 | } 117 | 118 | void stb_leakcheck_dumpmem(void) 119 | { 120 | stb_leakcheck_malloc_info *mi = mi_head; 121 | while (mi) { 122 | if ((ptrdiff_t) mi->size >= 0) 123 | stblkck_internal_print("LEAKED", mi); 124 | mi = mi->next; 125 | } 126 | #ifdef STB_LEAKCHECK_SHOWALL 127 | mi = mi_head; 128 | while (mi) { 129 | if ((ptrdiff_t) mi->size < 0) 130 | stblkck_internal_print("FREED ", mi); 131 | mi = mi->next; 132 | } 133 | #endif 134 | } 135 | #endif // STB_LEAKCHECK_IMPLEMENTATION 136 | 137 | #if !defined(INCLUDE_STB_LEAKCHECK_H) || !defined(malloc) 138 | #define INCLUDE_STB_LEAKCHECK_H 139 | 140 | #include // we want to define the macros *after* stdlib to avoid a slew of errors 141 | 142 | #define malloc(sz) stb_leakcheck_malloc(sz, __FILE__, __LINE__) 143 | #define free(p) stb_leakcheck_free(p) 144 | #define realloc(p,sz) stb_leakcheck_realloc(p,sz, __FILE__, __LINE__) 145 | 146 | extern void * stb_leakcheck_malloc(size_t sz, const char *file, int line); 147 | extern void * stb_leakcheck_realloc(void *ptr, size_t sz, const char *file, int line); 148 | extern void stb_leakcheck_free(void *ptr); 149 | extern void stb_leakcheck_dumpmem(void); 150 | 151 | #endif // INCLUDE_STB_LEAKCHECK_H 152 | 153 | 154 | /* 155 | ------------------------------------------------------------------------------ 156 | This software is available under 2 licenses -- choose whichever you prefer. 157 | ------------------------------------------------------------------------------ 158 | ALTERNATIVE A - MIT License 159 | Copyright (c) 2017 Sean Barrett 160 | Permission is hereby granted, free of charge, to any person obtaining a copy of 161 | this software and associated documentation files (the "Software"), to deal in 162 | the Software without restriction, including without limitation the rights to 163 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 164 | of the Software, and to permit persons to whom the Software is furnished to do 165 | so, subject to the following conditions: 166 | The above copyright notice and this permission notice shall be included in all 167 | copies or substantial portions of the Software. 168 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 169 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 170 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 171 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 172 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 173 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 174 | SOFTWARE. 175 | ------------------------------------------------------------------------------ 176 | ALTERNATIVE B - Public Domain (www.unlicense.org) 177 | This is free and unencumbered software released into the public domain. 178 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 179 | software, either in source code form or as a compiled binary, for any purpose, 180 | commercial or non-commercial, and by any means. 181 | In jurisdictions that recognize copyright laws, the author or authors of this 182 | software dedicate any and all copyright interest in the software to the public 183 | domain. We make this dedication for the benefit of the public at large and to 184 | the detriment of our heirs and successors. We intend this dedication to be an 185 | overt act of relinquishment in perpetuity of all present and future rights to 186 | this software under copyright law. 187 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 188 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 189 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 190 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 191 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 192 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 193 | ------------------------------------------------------------------------------ 194 | */ 195 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/ThirdParty/Stb/stb_perlin.h: -------------------------------------------------------------------------------- 1 | // stb_perlin.h - v0.5 - perlin noise 2 | // public domain single-file C implementation by Sean Barrett 3 | // 4 | // LICENSE 5 | // 6 | // See end of file. 7 | // 8 | // 9 | // to create the implementation, 10 | // #define STB_PERLIN_IMPLEMENTATION 11 | // in *one* C/CPP file that includes this file. 12 | // 13 | // 14 | // Documentation: 15 | // 16 | // float stb_perlin_noise3( float x, 17 | // float y, 18 | // float z, 19 | // int x_wrap=0, 20 | // int y_wrap=0, 21 | // int z_wrap=0) 22 | // 23 | // This function computes a random value at the coordinate (x,y,z). 24 | // Adjacent random values are continuous but the noise fluctuates 25 | // its randomness with period 1, i.e. takes on wholly unrelated values 26 | // at integer points. Specifically, this implements Ken Perlin's 27 | // revised noise function from 2002. 28 | // 29 | // The "wrap" parameters can be used to create wraparound noise that 30 | // wraps at powers of two. The numbers MUST be powers of two. Specify 31 | // 0 to mean "don't care". (The noise always wraps every 256 due 32 | // details of the implementation, even if you ask for larger or no 33 | // wrapping.) 34 | // 35 | // float stb_perlin_noise3_seed( float x, 36 | // float y, 37 | // float z, 38 | // int x_wrap=0, 39 | // int y_wrap=0, 40 | // int z_wrap=0, 41 | // int seed) 42 | // 43 | // As above, but 'seed' selects from multiple different variations of the 44 | // noise function. The current implementation only uses the bottom 8 bits 45 | // of 'seed', but possibly in the future more bits will be used. 46 | // 47 | // 48 | // Fractal Noise: 49 | // 50 | // Three common fractal noise functions are included, which produce 51 | // a wide variety of nice effects depending on the parameters 52 | // provided. Note that each function will call stb_perlin_noise3 53 | // 'octaves' times, so this parameter will affect runtime. 54 | // 55 | // float stb_perlin_ridge_noise3(float x, float y, float z, 56 | // float lacunarity, float gain, float offset, int octaves) 57 | // 58 | // float stb_perlin_fbm_noise3(float x, float y, float z, 59 | // float lacunarity, float gain, int octaves) 60 | // 61 | // float stb_perlin_turbulence_noise3(float x, float y, float z, 62 | // float lacunarity, float gain, int octaves) 63 | // 64 | // Typical values to start playing with: 65 | // octaves = 6 -- number of "octaves" of noise3() to sum 66 | // lacunarity = ~ 2.0 -- spacing between successive octaves (use exactly 2.0 for wrapping output) 67 | // gain = 0.5 -- relative weighting applied to each successive octave 68 | // offset = 1.0? -- used to invert the ridges, may need to be larger, not sure 69 | // 70 | // 71 | // Contributors: 72 | // Jack Mott - additional noise functions 73 | // Jordan Peck - seeded noise 74 | // 75 | 76 | 77 | #ifdef __cplusplus 78 | extern "C" { 79 | #endif 80 | extern float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap); 81 | extern float stb_perlin_noise3_seed(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, int seed); 82 | extern float stb_perlin_ridge_noise3(float x, float y, float z, float lacunarity, float gain, float offset, int octaves); 83 | extern float stb_perlin_fbm_noise3(float x, float y, float z, float lacunarity, float gain, int octaves); 84 | extern float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves); 85 | extern float stb_perlin_noise3_wrap_nonpow2(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, unsigned char seed); 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #ifdef STB_PERLIN_IMPLEMENTATION 91 | 92 | #include // fabs() 93 | 94 | // not same permutation table as Perlin's reference to avoid copyright issues; 95 | // Perlin's table can be found at http://mrl.nyu.edu/~perlin/noise/ 96 | static unsigned char stb__perlin_randtab[512] = 97 | { 98 | 23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123, 99 | 152, 238, 145, 45, 171, 114, 253, 10, 192, 136, 4, 157, 249, 30, 35, 72, 100 | 175, 63, 77, 90, 181, 16, 96, 111, 133, 104, 75, 162, 93, 56, 66, 240, 101 | 8, 50, 84, 229, 49, 210, 173, 239, 141, 1, 87, 18, 2, 198, 143, 57, 102 | 225, 160, 58, 217, 168, 206, 245, 204, 199, 6, 73, 60, 20, 230, 211, 233, 103 | 94, 200, 88, 9, 74, 155, 33, 15, 219, 130, 226, 202, 83, 236, 42, 172, 104 | 165, 218, 55, 222, 46, 107, 98, 154, 109, 67, 196, 178, 127, 158, 13, 243, 105 | 65, 79, 166, 248, 25, 224, 115, 80, 68, 51, 184, 128, 232, 208, 151, 122, 106 | 26, 212, 105, 43, 179, 213, 235, 148, 146, 89, 14, 195, 28, 78, 112, 76, 107 | 250, 47, 24, 251, 140, 108, 186, 190, 228, 170, 183, 139, 39, 188, 244, 246, 108 | 132, 48, 119, 144, 180, 138, 134, 193, 82, 182, 120, 121, 86, 220, 209, 3, 109 | 91, 241, 149, 85, 205, 150, 113, 216, 31, 100, 41, 164, 177, 214, 153, 231, 110 | 38, 71, 185, 174, 97, 201, 29, 95, 7, 92, 54, 254, 191, 118, 34, 221, 111 | 131, 11, 163, 99, 234, 81, 227, 147, 156, 176, 17, 142, 69, 12, 110, 62, 112 | 27, 255, 0, 194, 59, 116, 242, 252, 19, 21, 187, 53, 207, 129, 64, 135, 113 | 61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5, 114 | 115 | // and a second copy so we don't need an extra mask or static initializer 116 | 23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123, 117 | 152, 238, 145, 45, 171, 114, 253, 10, 192, 136, 4, 157, 249, 30, 35, 72, 118 | 175, 63, 77, 90, 181, 16, 96, 111, 133, 104, 75, 162, 93, 56, 66, 240, 119 | 8, 50, 84, 229, 49, 210, 173, 239, 141, 1, 87, 18, 2, 198, 143, 57, 120 | 225, 160, 58, 217, 168, 206, 245, 204, 199, 6, 73, 60, 20, 230, 211, 233, 121 | 94, 200, 88, 9, 74, 155, 33, 15, 219, 130, 226, 202, 83, 236, 42, 172, 122 | 165, 218, 55, 222, 46, 107, 98, 154, 109, 67, 196, 178, 127, 158, 13, 243, 123 | 65, 79, 166, 248, 25, 224, 115, 80, 68, 51, 184, 128, 232, 208, 151, 122, 124 | 26, 212, 105, 43, 179, 213, 235, 148, 146, 89, 14, 195, 28, 78, 112, 76, 125 | 250, 47, 24, 251, 140, 108, 186, 190, 228, 170, 183, 139, 39, 188, 244, 246, 126 | 132, 48, 119, 144, 180, 138, 134, 193, 82, 182, 120, 121, 86, 220, 209, 3, 127 | 91, 241, 149, 85, 205, 150, 113, 216, 31, 100, 41, 164, 177, 214, 153, 231, 128 | 38, 71, 185, 174, 97, 201, 29, 95, 7, 92, 54, 254, 191, 118, 34, 221, 129 | 131, 11, 163, 99, 234, 81, 227, 147, 156, 176, 17, 142, 69, 12, 110, 62, 130 | 27, 255, 0, 194, 59, 116, 242, 252, 19, 21, 187, 53, 207, 129, 64, 135, 131 | 61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5, 132 | }; 133 | 134 | 135 | // perlin's gradient has 12 cases so some get used 1/16th of the time 136 | // and some 2/16ths. We reduce bias by changing those fractions 137 | // to 5/64ths and 6/64ths 138 | 139 | // this array is designed to match the previous implementation 140 | // of gradient hash: indices[stb__perlin_randtab[i]&63] 141 | static unsigned char stb__perlin_randtab_grad_idx[512] = 142 | { 143 | 7, 9, 5, 0, 11, 1, 6, 9, 3, 9, 11, 1, 8, 10, 4, 7, 144 | 8, 6, 1, 5, 3, 10, 9, 10, 0, 8, 4, 1, 5, 2, 7, 8, 145 | 7, 11, 9, 10, 1, 0, 4, 7, 5, 0, 11, 6, 1, 4, 2, 8, 146 | 8, 10, 4, 9, 9, 2, 5, 7, 9, 1, 7, 2, 2, 6, 11, 5, 147 | 5, 4, 6, 9, 0, 1, 1, 0, 7, 6, 9, 8, 4, 10, 3, 1, 148 | 2, 8, 8, 9, 10, 11, 5, 11, 11, 2, 6, 10, 3, 4, 2, 4, 149 | 9, 10, 3, 2, 6, 3, 6, 10, 5, 3, 4, 10, 11, 2, 9, 11, 150 | 1, 11, 10, 4, 9, 4, 11, 0, 4, 11, 4, 0, 0, 0, 7, 6, 151 | 10, 4, 1, 3, 11, 5, 3, 4, 2, 9, 1, 3, 0, 1, 8, 0, 152 | 6, 7, 8, 7, 0, 4, 6, 10, 8, 2, 3, 11, 11, 8, 0, 2, 153 | 4, 8, 3, 0, 0, 10, 6, 1, 2, 2, 4, 5, 6, 0, 1, 3, 154 | 11, 9, 5, 5, 9, 6, 9, 8, 3, 8, 1, 8, 9, 6, 9, 11, 155 | 10, 7, 5, 6, 5, 9, 1, 3, 7, 0, 2, 10, 11, 2, 6, 1, 156 | 3, 11, 7, 7, 2, 1, 7, 3, 0, 8, 1, 1, 5, 0, 6, 10, 157 | 11, 11, 0, 2, 7, 0, 10, 8, 3, 5, 7, 1, 11, 1, 0, 7, 158 | 9, 0, 11, 5, 10, 3, 2, 3, 5, 9, 7, 9, 8, 4, 6, 5, 159 | 160 | // and a second copy so we don't need an extra mask or static initializer 161 | 7, 9, 5, 0, 11, 1, 6, 9, 3, 9, 11, 1, 8, 10, 4, 7, 162 | 8, 6, 1, 5, 3, 10, 9, 10, 0, 8, 4, 1, 5, 2, 7, 8, 163 | 7, 11, 9, 10, 1, 0, 4, 7, 5, 0, 11, 6, 1, 4, 2, 8, 164 | 8, 10, 4, 9, 9, 2, 5, 7, 9, 1, 7, 2, 2, 6, 11, 5, 165 | 5, 4, 6, 9, 0, 1, 1, 0, 7, 6, 9, 8, 4, 10, 3, 1, 166 | 2, 8, 8, 9, 10, 11, 5, 11, 11, 2, 6, 10, 3, 4, 2, 4, 167 | 9, 10, 3, 2, 6, 3, 6, 10, 5, 3, 4, 10, 11, 2, 9, 11, 168 | 1, 11, 10, 4, 9, 4, 11, 0, 4, 11, 4, 0, 0, 0, 7, 6, 169 | 10, 4, 1, 3, 11, 5, 3, 4, 2, 9, 1, 3, 0, 1, 8, 0, 170 | 6, 7, 8, 7, 0, 4, 6, 10, 8, 2, 3, 11, 11, 8, 0, 2, 171 | 4, 8, 3, 0, 0, 10, 6, 1, 2, 2, 4, 5, 6, 0, 1, 3, 172 | 11, 9, 5, 5, 9, 6, 9, 8, 3, 8, 1, 8, 9, 6, 9, 11, 173 | 10, 7, 5, 6, 5, 9, 1, 3, 7, 0, 2, 10, 11, 2, 6, 1, 174 | 3, 11, 7, 7, 2, 1, 7, 3, 0, 8, 1, 1, 5, 0, 6, 10, 175 | 11, 11, 0, 2, 7, 0, 10, 8, 3, 5, 7, 1, 11, 1, 0, 7, 176 | 9, 0, 11, 5, 10, 3, 2, 3, 5, 9, 7, 9, 8, 4, 6, 5, 177 | }; 178 | 179 | static float stb__perlin_lerp(float a, float b, float t) 180 | { 181 | return a + (b-a) * t; 182 | } 183 | 184 | static int stb__perlin_fastfloor(float a) 185 | { 186 | int ai = (int) a; 187 | return (a < ai) ? ai-1 : ai; 188 | } 189 | 190 | // different grad function from Perlin's, but easy to modify to match reference 191 | static float stb__perlin_grad(int grad_idx, float x, float y, float z) 192 | { 193 | static float basis[12][4] = 194 | { 195 | { 1, 1, 0 }, 196 | { -1, 1, 0 }, 197 | { 1,-1, 0 }, 198 | { -1,-1, 0 }, 199 | { 1, 0, 1 }, 200 | { -1, 0, 1 }, 201 | { 1, 0,-1 }, 202 | { -1, 0,-1 }, 203 | { 0, 1, 1 }, 204 | { 0,-1, 1 }, 205 | { 0, 1,-1 }, 206 | { 0,-1,-1 }, 207 | }; 208 | 209 | float *grad = basis[grad_idx]; 210 | return grad[0]*x + grad[1]*y + grad[2]*z; 211 | } 212 | 213 | float stb_perlin_noise3_internal(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, unsigned char seed) 214 | { 215 | float u,v,w; 216 | float n000,n001,n010,n011,n100,n101,n110,n111; 217 | float n00,n01,n10,n11; 218 | float n0,n1; 219 | 220 | unsigned int x_mask = (x_wrap-1) & 255; 221 | unsigned int y_mask = (y_wrap-1) & 255; 222 | unsigned int z_mask = (z_wrap-1) & 255; 223 | int px = stb__perlin_fastfloor(x); 224 | int py = stb__perlin_fastfloor(y); 225 | int pz = stb__perlin_fastfloor(z); 226 | int x0 = px & x_mask, x1 = (px+1) & x_mask; 227 | int y0 = py & y_mask, y1 = (py+1) & y_mask; 228 | int z0 = pz & z_mask, z1 = (pz+1) & z_mask; 229 | int r0,r1, r00,r01,r10,r11; 230 | 231 | #define stb__perlin_ease(a) (((a*6-15)*a + 10) * a * a * a) 232 | 233 | x -= px; u = stb__perlin_ease(x); 234 | y -= py; v = stb__perlin_ease(y); 235 | z -= pz; w = stb__perlin_ease(z); 236 | 237 | r0 = stb__perlin_randtab[x0+seed]; 238 | r1 = stb__perlin_randtab[x1+seed]; 239 | 240 | r00 = stb__perlin_randtab[r0+y0]; 241 | r01 = stb__perlin_randtab[r0+y1]; 242 | r10 = stb__perlin_randtab[r1+y0]; 243 | r11 = stb__perlin_randtab[r1+y1]; 244 | 245 | n000 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z0], x , y , z ); 246 | n001 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z1], x , y , z-1 ); 247 | n010 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z0], x , y-1, z ); 248 | n011 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z1], x , y-1, z-1 ); 249 | n100 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z0], x-1, y , z ); 250 | n101 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z1], x-1, y , z-1 ); 251 | n110 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z0], x-1, y-1, z ); 252 | n111 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z1], x-1, y-1, z-1 ); 253 | 254 | n00 = stb__perlin_lerp(n000,n001,w); 255 | n01 = stb__perlin_lerp(n010,n011,w); 256 | n10 = stb__perlin_lerp(n100,n101,w); 257 | n11 = stb__perlin_lerp(n110,n111,w); 258 | 259 | n0 = stb__perlin_lerp(n00,n01,v); 260 | n1 = stb__perlin_lerp(n10,n11,v); 261 | 262 | return stb__perlin_lerp(n0,n1,u); 263 | } 264 | 265 | float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap) 266 | { 267 | return stb_perlin_noise3_internal(x,y,z,x_wrap,y_wrap,z_wrap,0); 268 | } 269 | 270 | float stb_perlin_noise3_seed(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, int seed) 271 | { 272 | return stb_perlin_noise3_internal(x,y,z,x_wrap,y_wrap,z_wrap, (unsigned char) seed); 273 | } 274 | 275 | float stb_perlin_ridge_noise3(float x, float y, float z, float lacunarity, float gain, float offset, int octaves) 276 | { 277 | int i; 278 | float frequency = 1.0f; 279 | float prev = 1.0f; 280 | float amplitude = 0.5f; 281 | float sum = 0.0f; 282 | 283 | for (i = 0; i < octaves; i++) { 284 | float r = stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i); 285 | r = offset - (float) fabs(r); 286 | r = r*r; 287 | sum += r*amplitude*prev; 288 | prev = r; 289 | frequency *= lacunarity; 290 | amplitude *= gain; 291 | } 292 | return sum; 293 | } 294 | 295 | float stb_perlin_fbm_noise3(float x, float y, float z, float lacunarity, float gain, int octaves) 296 | { 297 | int i; 298 | float frequency = 1.0f; 299 | float amplitude = 1.0f; 300 | float sum = 0.0f; 301 | 302 | for (i = 0; i < octaves; i++) { 303 | sum += stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i)*amplitude; 304 | frequency *= lacunarity; 305 | amplitude *= gain; 306 | } 307 | return sum; 308 | } 309 | 310 | float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves) 311 | { 312 | int i; 313 | float frequency = 1.0f; 314 | float amplitude = 1.0f; 315 | float sum = 0.0f; 316 | 317 | for (i = 0; i < octaves; i++) { 318 | float r = stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i)*amplitude; 319 | sum += (float) fabs(r); 320 | frequency *= lacunarity; 321 | amplitude *= gain; 322 | } 323 | return sum; 324 | } 325 | 326 | float stb_perlin_noise3_wrap_nonpow2(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, unsigned char seed) 327 | { 328 | float u,v,w; 329 | float n000,n001,n010,n011,n100,n101,n110,n111; 330 | float n00,n01,n10,n11; 331 | float n0,n1; 332 | 333 | int px = stb__perlin_fastfloor(x); 334 | int py = stb__perlin_fastfloor(y); 335 | int pz = stb__perlin_fastfloor(z); 336 | int x_wrap2 = (x_wrap ? x_wrap : 256); 337 | int y_wrap2 = (y_wrap ? y_wrap : 256); 338 | int z_wrap2 = (z_wrap ? z_wrap : 256); 339 | int x0 = px % x_wrap2, x1; 340 | int y0 = py % y_wrap2, y1; 341 | int z0 = pz % z_wrap2, z1; 342 | int r0,r1, r00,r01,r10,r11; 343 | 344 | if (x0 < 0) x0 += x_wrap2; 345 | if (y0 < 0) y0 += y_wrap2; 346 | if (z0 < 0) z0 += z_wrap2; 347 | x1 = (x0+1) % x_wrap2; 348 | y1 = (y0+1) % y_wrap2; 349 | z1 = (z0+1) % z_wrap2; 350 | 351 | #define stb__perlin_ease(a) (((a*6-15)*a + 10) * a * a * a) 352 | 353 | x -= px; u = stb__perlin_ease(x); 354 | y -= py; v = stb__perlin_ease(y); 355 | z -= pz; w = stb__perlin_ease(z); 356 | 357 | r0 = stb__perlin_randtab[x0]; 358 | r0 = stb__perlin_randtab[r0+seed]; 359 | r1 = stb__perlin_randtab[x1]; 360 | r1 = stb__perlin_randtab[r1+seed]; 361 | 362 | r00 = stb__perlin_randtab[r0+y0]; 363 | r01 = stb__perlin_randtab[r0+y1]; 364 | r10 = stb__perlin_randtab[r1+y0]; 365 | r11 = stb__perlin_randtab[r1+y1]; 366 | 367 | n000 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z0], x , y , z ); 368 | n001 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z1], x , y , z-1 ); 369 | n010 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z0], x , y-1, z ); 370 | n011 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z1], x , y-1, z-1 ); 371 | n100 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z0], x-1, y , z ); 372 | n101 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z1], x-1, y , z-1 ); 373 | n110 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z0], x-1, y-1, z ); 374 | n111 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z1], x-1, y-1, z-1 ); 375 | 376 | n00 = stb__perlin_lerp(n000,n001,w); 377 | n01 = stb__perlin_lerp(n010,n011,w); 378 | n10 = stb__perlin_lerp(n100,n101,w); 379 | n11 = stb__perlin_lerp(n110,n111,w); 380 | 381 | n0 = stb__perlin_lerp(n00,n01,v); 382 | n1 = stb__perlin_lerp(n10,n11,v); 383 | 384 | return stb__perlin_lerp(n0,n1,u); 385 | } 386 | #endif // STB_PERLIN_IMPLEMENTATION 387 | 388 | /* 389 | ------------------------------------------------------------------------------ 390 | This software is available under 2 licenses -- choose whichever you prefer. 391 | ------------------------------------------------------------------------------ 392 | ALTERNATIVE A - MIT License 393 | Copyright (c) 2017 Sean Barrett 394 | Permission is hereby granted, free of charge, to any person obtaining a copy of 395 | this software and associated documentation files (the "Software"), to deal in 396 | the Software without restriction, including without limitation the rights to 397 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 398 | of the Software, and to permit persons to whom the Software is furnished to do 399 | so, subject to the following conditions: 400 | The above copyright notice and this permission notice shall be included in all 401 | copies or substantial portions of the Software. 402 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 403 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 404 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 405 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 406 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 407 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 408 | SOFTWARE. 409 | ------------------------------------------------------------------------------ 410 | ALTERNATIVE B - Public Domain (www.unlicense.org) 411 | This is free and unencumbered software released into the public domain. 412 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 413 | software, either in source code form or as a compiled binary, for any purpose, 414 | commercial or non-commercial, and by any means. 415 | In jurisdictions that recognize copyright laws, the author or authors of this 416 | software dedicate any and all copyright interest in the software to the public 417 | domain. We make this dedication for the benefit of the public at large and to 418 | the detriment of our heirs and successors. We intend this dedication to be an 419 | overt act of relinquishment in perpetuity of all present and future rights to 420 | this software under copyright law. 421 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 422 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 423 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 424 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 425 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 426 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 427 | ------------------------------------------------------------------------------ 428 | */ 429 | -------------------------------------------------------------------------------- /Source/Runtime/Engine/ThirdParty/Stb/stretchy_buffer.h: -------------------------------------------------------------------------------- 1 | // stretchy_buffer.h - v1.04 - public domain - nothings.org/stb 2 | // a vector<>-like dynamic array for C 3 | // 4 | // version history: 5 | // 1.04 - fix warning 6 | // 1.03 - compile as C++ maybe 7 | // 1.02 - tweaks to syntax for no good reason 8 | // 1.01 - added a "common uses" documentation section 9 | // 1.0 - fixed bug in the version I posted prematurely 10 | // 0.9 - rewrite to try to avoid strict-aliasing optimization 11 | // issues, but won't compile as C++ 12 | // 13 | // Will probably not work correctly with strict-aliasing optimizations. 14 | // 15 | // The idea: 16 | // 17 | // This implements an approximation to C++ vector<> for C, in that it 18 | // provides a generic definition for dynamic arrays which you can 19 | // still access in a typesafe way using arr[i] or *(arr+i). However, 20 | // it is simply a convenience wrapper around the common idiom of 21 | // of keeping a set of variables (in a struct or globals) which store 22 | // - pointer to array 23 | // - the length of the "in-use" part of the array 24 | // - the current size of the allocated array 25 | // 26 | // I find it to be the single most useful non-built-in-structure when 27 | // programming in C (hash tables a close second), but to be clear 28 | // it lacks many of the capabilities of C++ vector<>: there is no 29 | // range checking, the object address isn't stable (see next section 30 | // for details), the set of methods available is small (although 31 | // the file stb.h has another implementation of stretchy buffers 32 | // called 'stb_arr' which provides more methods, e.g. for insertion 33 | // and deletion). 34 | // 35 | // How to use: 36 | // 37 | // Unlike other stb header file libraries, there is no need to 38 | // define an _IMPLEMENTATION symbol. Every #include creates as 39 | // much implementation is needed. 40 | // 41 | // stretchy_buffer.h does not define any types, so you do not 42 | // need to #include it to before defining data types that are 43 | // stretchy buffers, only in files that *manipulate* stretchy 44 | // buffers. 45 | // 46 | // If you want a stretchy buffer aka dynamic array containing 47 | // objects of TYPE, declare such an array as: 48 | // 49 | // TYPE *myarray = NULL; 50 | // 51 | // (There is no typesafe way to distinguish between stretchy 52 | // buffers and regular arrays/pointers; this is necessary to 53 | // make ordinary array indexing work on these objects.) 54 | // 55 | // Unlike C++ vector<>, the stretchy_buffer has the same 56 | // semantics as an object that you manually malloc and realloc. 57 | // The pointer may relocate every time you add a new object 58 | // to it, so you: 59 | // 60 | // 1. can't take long-term pointers to elements of the array 61 | // 2. have to return the pointer from functions which might expand it 62 | // (either as a return value or by storing it to a ptr-to-ptr) 63 | // 64 | // Now you can do the following things with this array: 65 | // 66 | // sb_free(TYPE *a) free the array 67 | // sb_count(TYPE *a) the number of elements in the array 68 | // sb_push(TYPE *a, TYPE v) adds v on the end of the array, a la push_back 69 | // sb_add(TYPE *a, int n) adds n uninitialized elements at end of array & returns pointer to first added 70 | // sb_last(TYPE *a) returns an lvalue of the last item in the array 71 | // a[n] access the nth (counting from 0) element of the array 72 | // 73 | // #define STRETCHY_BUFFER_NO_SHORT_NAMES to only export 74 | // names of the form 'stb_sb_' if you have a name that would 75 | // otherwise collide. 76 | // 77 | // Note that these are all macros and many of them evaluate 78 | // their arguments more than once, so the arguments should 79 | // be side-effect-free. 80 | // 81 | // Note that 'TYPE *a' in sb_push and sb_add must be lvalues 82 | // so that the library can overwrite the existing pointer if 83 | // the object has to be reallocated. 84 | // 85 | // In an out-of-memory condition, the code will try to 86 | // set up a null-pointer or otherwise-invalid-pointer 87 | // exception to happen later. It's possible optimizing 88 | // compilers could detect this write-to-null statically 89 | // and optimize away some of the code, but it should only 90 | // be along the failure path. Nevertheless, for more security 91 | // in the face of such compilers, #define STRETCHY_BUFFER_OUT_OF_MEMORY 92 | // to a statement such as assert(0) or exit(1) or something 93 | // to force a failure when out-of-memory occurs. 94 | // 95 | // Common use: 96 | // 97 | // The main application for this is when building a list of 98 | // things with an unknown quantity, either due to loading from 99 | // a file or through a process which produces an unpredictable 100 | // number. 101 | // 102 | // My most common idiom is something like: 103 | // 104 | // SomeStruct *arr = NULL; 105 | // while (something) 106 | // { 107 | // SomeStruct new_one; 108 | // new_one.whatever = whatever; 109 | // new_one.whatup = whatup; 110 | // new_one.foobar = barfoo; 111 | // sb_push(arr, new_one); 112 | // } 113 | // 114 | // and various closely-related factorings of that. For example, 115 | // you might have several functions to create/init new SomeStructs, 116 | // and if you use the above idiom, you might prefer to make them 117 | // return structs rather than take non-const-pointers-to-structs, 118 | // so you can do things like: 119 | // 120 | // SomeStruct *arr = NULL; 121 | // while (something) 122 | // { 123 | // if (case_A) { 124 | // sb_push(arr, some_func1()); 125 | // } else if (case_B) { 126 | // sb_push(arr, some_func2()); 127 | // } else { 128 | // sb_push(arr, some_func3()); 129 | // } 130 | // } 131 | // 132 | // Note that the above relies on the fact that sb_push doesn't 133 | // evaluate its second argument more than once. The macros do 134 | // evaluate the *array* argument multiple times, and numeric 135 | // arguments may be evaluated multiple times, but you can rely 136 | // on the second argument of sb_push being evaluated only once. 137 | // 138 | // Of course, you don't have to store bare objects in the array; 139 | // if you need the objects to have stable pointers, store an array 140 | // of pointers instead: 141 | // 142 | // SomeStruct **arr = NULL; 143 | // while (something) 144 | // { 145 | // SomeStruct *new_one = malloc(sizeof(*new_one)); 146 | // new_one->whatever = whatever; 147 | // new_one->whatup = whatup; 148 | // new_one->foobar = barfoo; 149 | // sb_push(arr, new_one); 150 | // } 151 | // 152 | // How it works: 153 | // 154 | // A long-standing tradition in things like malloc implementations 155 | // is to store extra data before the beginning of the block returned 156 | // to the user. The stretchy buffer implementation here uses the 157 | // same trick; the current-count and current-allocation-size are 158 | // stored before the beginning of the array returned to the user. 159 | // (This means you can't directly free() the pointer, because the 160 | // allocated pointer is different from the type-safe pointer provided 161 | // to the user.) 162 | // 163 | // The details are trivial and implementation is straightforward; 164 | // the main trick is in realizing in the first place that it's 165 | // possible to do this in a generic, type-safe way in C. 166 | // 167 | // Contributors: 168 | // 169 | // Timothy Wright (github:ZenToad) 170 | // 171 | // LICENSE 172 | // 173 | // See end of file for license information. 174 | 175 | #ifndef STB_STRETCHY_BUFFER_H_INCLUDED 176 | #define STB_STRETCHY_BUFFER_H_INCLUDED 177 | 178 | #ifndef NO_STRETCHY_BUFFER_SHORT_NAMES 179 | #define sb_free stb_sb_free 180 | #define sb_push stb_sb_push 181 | #define sb_count stb_sb_count 182 | #define sb_add stb_sb_add 183 | #define sb_last stb_sb_last 184 | #endif 185 | 186 | #define stb_sb_free(a) ((a) ? free(stb__sbraw(a)),0 : 0) 187 | #define stb_sb_push(a,v) (stb__sbmaybegrow(a,1), (a)[stb__sbn(a)++] = (v)) 188 | #define stb_sb_count(a) ((a) ? stb__sbn(a) : 0) 189 | #define stb_sb_add(a,n) (stb__sbmaybegrow(a,n), stb__sbn(a)+=(n), &(a)[stb__sbn(a)-(n)]) 190 | #define stb_sb_last(a) ((a)[stb__sbn(a)-1]) 191 | 192 | #define stb__sbraw(a) ((int *) (void *) (a) - 2) 193 | #define stb__sbm(a) stb__sbraw(a)[0] 194 | #define stb__sbn(a) stb__sbraw(a)[1] 195 | 196 | #define stb__sbneedgrow(a,n) ((a)==0 || stb__sbn(a)+(n) >= stb__sbm(a)) 197 | #define stb__sbmaybegrow(a,n) (stb__sbneedgrow(a,(n)) ? stb__sbgrow(a,n) : 0) 198 | #define stb__sbgrow(a,n) (*((void **)&(a)) = stb__sbgrowf((a), (n), sizeof(*(a)))) 199 | 200 | #include 201 | 202 | static void * stb__sbgrowf(void *arr, int increment, int itemsize) 203 | { 204 | int dbl_cur = arr ? 2*stb__sbm(arr) : 0; 205 | int min_needed = stb_sb_count(arr) + increment; 206 | int m = dbl_cur > min_needed ? dbl_cur : min_needed; 207 | int *p = (int *) realloc(arr ? stb__sbraw(arr) : 0, itemsize * m + sizeof(int)*2); 208 | if (p) { 209 | if (!arr) 210 | p[1] = 0; 211 | p[0] = m; 212 | return p+2; 213 | } else { 214 | #ifdef STRETCHY_BUFFER_OUT_OF_MEMORY 215 | STRETCHY_BUFFER_OUT_OF_MEMORY ; 216 | #endif 217 | return (void *) (2*sizeof(int)); // try to force a NULL pointer exception later 218 | } 219 | } 220 | #endif // STB_STRETCHY_BUFFER_H_INCLUDED 221 | 222 | 223 | /* 224 | ------------------------------------------------------------------------------ 225 | This software is available under 2 licenses -- choose whichever you prefer. 226 | ------------------------------------------------------------------------------ 227 | ALTERNATIVE A - MIT License 228 | Copyright (c) 2017 Sean Barrett 229 | Permission is hereby granted, free of charge, to any person obtaining a copy of 230 | this software and associated documentation files (the "Software"), to deal in 231 | the Software without restriction, including without limitation the rights to 232 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 233 | of the Software, and to permit persons to whom the Software is furnished to do 234 | so, subject to the following conditions: 235 | The above copyright notice and this permission notice shall be included in all 236 | copies or substantial portions of the Software. 237 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 238 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 239 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 240 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 241 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 242 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 243 | SOFTWARE. 244 | ------------------------------------------------------------------------------ 245 | ALTERNATIVE B - Public Domain (www.unlicense.org) 246 | This is free and unencumbered software released into the public domain. 247 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 248 | software, either in source code form or as a compiled binary, for any purpose, 249 | commercial or non-commercial, and by any means. 250 | In jurisdictions that recognize copyright laws, the author or authors of this 251 | software dedicate any and all copyright interest in the software to the public 252 | domain. We make this dedication for the benefit of the public at large and to 253 | the detriment of our heirs and successors. We intend this dedication to be an 254 | overt act of relinquishment in perpetuity of all present and future rights to 255 | this software under copyright law. 256 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 257 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 258 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 259 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 260 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 261 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 262 | ------------------------------------------------------------------------------ 263 | */ 264 | -------------------------------------------------------------------------------- /Source/Runtime/Math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | project(MathModule) 4 | 5 | ################################################################################ 6 | # Source files 7 | ################################################################################ 8 | file(GLOB COMMON_FILES 9 | ${PROJECT_SOURCE_DIR}/*.cpp 10 | ${PROJECT_SOURCE_DIR}/*.h) 11 | 12 | file(GLOB_RECURSE MODULE_FILES 13 | ${PROJECT_SOURCE_DIR}/Private/*.cpp 14 | ${PROJECT_SOURCE_DIR}/Public/*.h 15 | ) 16 | 17 | file(GLOB_RECURSE THIRDPARTY_FILES 18 | ${PROJECT_SOURCE_DIR}/ThirdParty/*.h 19 | ${PROJECT_SOURCE_DIR}/ThirdParty/*.cpp 20 | ) 21 | 22 | set(ALL_FILES 23 | ${COMMON_FILES} 24 | ${MODULE_FILES} 25 | ${THIRDPARTY_FILES} 26 | ) 27 | 28 | if(TARGET_WINDOWS) 29 | 30 | file(GLOB_RECURSE WINDOWS_FILES 31 | ${PROJECT_SOURCE_DIR}/Public/${PLATFORM_FOLDER}/*.h 32 | ) 33 | 34 | set(ALL_FILES 35 | ${ALL_FILES} 36 | ${WINDOWS_FILES} 37 | ) 38 | 39 | endif() 40 | 41 | foreach(FILE ${ALL_FILES}) 42 | # make rel path 43 | file(RELATIVE_PATH REL_PATH "${PROJECT_SOURCE_DIR}" "${FILE}") 44 | set(ALL_FILES_REL ${ALL_FILES_REL} ${REL_PATH}) 45 | endforeach() 46 | 47 | set_source_files_properties(${ALL_FILES_REL} PROPERTIES HEADER_FILE_ONLY FALSE) 48 | 49 | foreach(FILE ${ALL_FILES_REL}) 50 | # get the base path 51 | get_filename_component(BASE_PATH "${FILE}" PATH) 52 | 53 | # changes /'s to \\'s 54 | string(REPLACE "/" "\\" GROUP "${BASE_PATH}") 55 | 56 | source_group("${GROUP}" FILES "${FILE}") 57 | endforeach() 58 | 59 | 60 | ################################################################################ 61 | # Include directory 62 | ################################################################################ 63 | include_directories( 64 | ${PROJECT_SOURCE_DIR} 65 | ${PROJECT_SOURCE_DIR}/Public 66 | ${PROJECT_SOURCE_DIR}/ThirdParty 67 | ) 68 | 69 | 70 | ################################################################################ 71 | # Precompiled Headers 72 | ################################################################################ 73 | set(ARG_PCH_HEADER Precompiled.h) 74 | set(ARG_PCH_SOURCE Precompiled.cpp) 75 | foreach (FILE ${ALL_FILES_REL}) 76 | if (FILE MATCHES ".*\\.(c|cpp)$") 77 | if (FILE STREQUAL ${ARG_PCH_SOURCE}) 78 | set_source_files_properties(${FILE} PROPERTIES COMPILE_FLAGS "/Yc\"${ARG_PCH_HEADER}\"") 79 | else() 80 | set_source_files_properties(${FILE} PROPERTIES COMPILE_FLAGS "/Yu\"${ARG_PCH_HEADER}\"") 81 | endif() 82 | endif() 83 | endforeach(FILE) 84 | 85 | ################################################################################ 86 | # Library Output Setting 87 | ################################################################################ 88 | add_library(${PROJECT_NAME} STATIC ${ALL_FILES_REL}) 89 | 90 | set_target_properties(${PROJECT_NAME} PROPERTIES 91 | PREFIX "" 92 | OUTPUT_NAME ${PROJECT_NAME} 93 | ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Output/${PLATFORM_FOLDER}/Library) 94 | 95 | 96 | ################################################################################ 97 | # Import Library 98 | ################################################################################ 99 | #target_link_libraries(${PROJECT_NAME} ) 100 | 101 | 102 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Precompiled.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Precompiled.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MathHeaders.h" 4 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Box.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | Box::Box(const std::vector InVertices) 6 | { 7 | for (const auto& v : InVertices) 8 | { 9 | *this += v; 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Circle.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | Circle::Circle(const std::vector InVertices) 6 | { 7 | size_t cnt = InVertices.size(); 8 | if (cnt == 0) 9 | { 10 | return; 11 | } 12 | 13 | Vector2 sum; 14 | for (const auto& v : InVertices) 15 | { 16 | sum += v; 17 | } 18 | 19 | Center = sum / (float)cnt; 20 | Radius = (*std::max_element(InVertices.begin(), InVertices.end(), 21 | [&](Vector2 const& lhs, Vector2 const& rhs) 22 | { 23 | return (Center - lhs).SizeSquared() < (Center - rhs).SizeSquared(); 24 | })).Size(); 25 | } 26 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Color32.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | const Color32 Color32::Error(255, 0, 255, 255); 6 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Frustum.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/LinearColor.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | const LinearColor LinearColor::Error(1.f, 0.f, 1.f, 1.f); 6 | const LinearColor LinearColor::White(1.f, 1.f, 1.f, 1.f); 7 | const LinearColor LinearColor::Black(0.f, 0.f, 0.f, 1.f); 8 | const LinearColor LinearColor::Gray(0.5f, 0.5f, 0.5f, 1.f); 9 | const LinearColor LinearColor::Silver(0.4f, 0.4f, 0.4f, 1.f); 10 | const LinearColor LinearColor::WhiteSmoke(0.96f, 0.96f, 0.96f, 1.f); 11 | const LinearColor LinearColor::LightGray(0.83f, 0.83f, 0.83f, 1.f); 12 | const LinearColor LinearColor::DimGray(0.41f, 0.41f, 0.41f, 1.f); 13 | const LinearColor LinearColor::Red(1.f, 0.f, 0.f, 1.f); 14 | const LinearColor LinearColor::Green(0.f, 1.f, 0.f, 1.f); 15 | const LinearColor LinearColor::Blue(0.f, 0.f, 1.f, 1.f); 16 | const LinearColor LinearColor::Yellow(1.f, 1.f, 0.f, 1.f); 17 | const LinearColor LinearColor::Cyan(0.f, 1.f, 1.f, 1.f); 18 | const LinearColor LinearColor::Magenta(1.f, 0.f, 1.f, 1.f); 19 | 20 | 21 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Math.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | //const float Math::PI = 3.14159265358979323846f; 6 | //const float Math::TwoPI = 2.f * PI; 7 | //const float Math::HalfPI = 1.57079632679f; 8 | //const float Math::InvPI = 0.31830988618f; 9 | //const int Math::IntMin = (-2147483647 - 1); 10 | //const int Math::IntMax = 2147483647; 11 | // 12 | //const std::string Math::InvalidHashName("!@CK_INVALIDHASH#$"); 13 | const std::size_t Math::InvalidHash = std::hash()(InvalidHashName); 14 | 15 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Matrix2x2.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | const Matrix2x2 Matrix2x2::Identity(Vector2(1.f, 0.f), Vector2(0.f, 1.f)); 6 | 7 | std::vector Matrix2x2::ToStrings() const 8 | { 9 | std::vector result; 10 | 11 | Matrix2x2 trMatrix = this->Transpose(); 12 | for (BYTE i = 0; i < Rank; ++i) 13 | { 14 | char row[64]; 15 | std::snprintf(row, sizeof(row), "| %.3f , %.3f |", trMatrix.Cols[i].X, trMatrix.Cols[i].Y); 16 | result.emplace_back(row); 17 | } 18 | return result; 19 | } -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Matrix3x3.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | const Matrix3x3 Matrix3x3::Identity(Vector3(1.f, 0.f, 0.f), Vector3(0.f, 1.f, 0.f), Vector3(0.f, 0.f, 1.f)); 6 | 7 | std::vector Matrix3x3::ToStrings() const 8 | { 9 | std::vector result; 10 | 11 | Matrix3x3 trMatrix = this->Transpose(); 12 | for (BYTE i = 0; i < Rank; ++i) 13 | { 14 | char row[64]; 15 | std::snprintf(row, sizeof(row), "| %.3f , %.3f , %.3f |", trMatrix.Cols[i].X, trMatrix.Cols[i].Y, trMatrix.Cols[i].Z); 16 | result.emplace_back(row); 17 | } 18 | return result; 19 | } -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Matrix4x4.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | const Matrix4x4 Matrix4x4::Identity(Vector4(1.f, 0.f, 0.f, 0.f), Vector4(0.f, 1.f, 0.f, 0.f), Vector4(0.f, 0.f, 1.f, 0.f), Vector4(0.f, 0.f, 0.f, 1.f)); 6 | 7 | std::vector Matrix4x4::ToStrings() const 8 | { 9 | std::vector result; 10 | 11 | Matrix4x4 trMatrix = this->Transpose(); 12 | for (BYTE i = 0; i < Rank; ++i) 13 | { 14 | char row[64]; 15 | std::snprintf(row, sizeof(row), "| %.3f , %.3f , %.3f, %.3f |", trMatrix.Cols[i].X, trMatrix.Cols[i].Y, trMatrix.Cols[i].Z, trMatrix.Cols[i].W); 16 | result.emplace_back(row); 17 | } 18 | return result; 19 | } 20 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Plane.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | Plane::Plane(const Vector3& InPoint1, const Vector3& InPoint2, const Vector3& InPoint3) 6 | { 7 | Vector3 v1 = InPoint2 - InPoint1; 8 | Vector3 v2 = InPoint3 - InPoint1; 9 | 10 | Normal = v1.Cross(v2).GetNormalize(); 11 | D = -Normal.Dot(InPoint1); 12 | } 13 | 14 | Plane::Plane(const Vector4& InVector4) 15 | { 16 | Normal = InVector4.ToVector3(); 17 | D = InVector4.W; 18 | Normalize(); 19 | } 20 | 21 | void Plane::Normalize() 22 | { 23 | float squaredSize = Normal.SizeSquared(); 24 | if (Math::EqualsInTolerance(squaredSize, 1.f)) 25 | { 26 | return; 27 | } 28 | 29 | float invLength = Math::InvSqrt(squaredSize); 30 | Normal *= invLength; 31 | D *= invLength; 32 | } 33 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Quaternion.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | const Quaternion Quaternion::Identity(0.f, 0.f, 0.f, 1.f); 6 | 7 | std::string Quaternion::ToString() const 8 | { 9 | return ToRotator().ToString(); 10 | } -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Rectangle.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | Rectangle::Rectangle(const std::vector InVertices) 6 | { 7 | for(const auto& v : InVertices) 8 | { 9 | *this += v; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Rotator.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | const Rotator Rotator::Identity(0.f, 0.f, 0.f); 6 | 7 | std::string Rotator::ToString() const 8 | { 9 | char result[64]; 10 | std::snprintf(result, sizeof(result), "(Y : %.1f, R: %.1f, P : %.1f)", Yaw, Roll, Pitch); 11 | return result; 12 | } -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Sphere.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | Sphere::Sphere(const std::vector& InVertices) 6 | { 7 | size_t cnt = InVertices.size(); 8 | if (cnt == 0) 9 | { 10 | return; 11 | } 12 | 13 | Vector3 sum; 14 | for (const auto& v : InVertices) 15 | { 16 | sum += v; 17 | } 18 | 19 | Center = sum / (float)cnt; 20 | Vector3 farthestPoint = (*std::max_element(InVertices.begin(), InVertices.end(), 21 | [&](Vector3 const& lhs, Vector3 const& rhs) 22 | { 23 | return (Center - lhs).SizeSquared() < (Center - rhs).SizeSquared(); 24 | })); 25 | Radius = (farthestPoint - Center).Size(); 26 | } 27 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Transform.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Private/Transform.cpp -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Vector2.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | const Vector2 Vector2::UnitX(1.f, 0.f); 6 | const Vector2 Vector2::UnitY(0.f, 1.f); 7 | const Vector2 Vector2::Zero(0.f, 0.f); 8 | const Vector2 Vector2::One(1.f, 1.f); 9 | 10 | std::string Vector2::ToString() const 11 | { 12 | char result[64]; 13 | std::snprintf(result, sizeof(result), "(%.3f, %.3f)", X, Y); 14 | return result; 15 | } 16 | 17 | Vector2 Vector2::GetNormalize() const 18 | { 19 | float squareSum = SizeSquared(); 20 | if (squareSum == 1.f) 21 | { 22 | return *this; 23 | } 24 | else if (squareSum == 0.f) 25 | { 26 | return Vector2::Zero; 27 | } 28 | 29 | float invLength = Math::InvSqrt(squareSum); 30 | return Vector2(X, Y) * invLength; 31 | } -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Vector3.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | const Vector3 Vector3::UnitX(1.f, 0.f, 0.f); 6 | const Vector3 Vector3::UnitY(0.f, 1.f, 0.f); 7 | const Vector3 Vector3::UnitZ(0.f, 0.f, 1.f); 8 | const Vector3 Vector3::Zero(0.f, 0.f, 0.f); 9 | const Vector3 Vector3::One(1.f, 1.f, 1.f); 10 | 11 | std::string Vector3::ToString() const 12 | { 13 | char result[64]; 14 | std::snprintf(result, sizeof(result), "(%.3f, %.3f, %.3f)", X, Y, Z); 15 | return result; 16 | } 17 | 18 | Vector3 Vector3::GetNormalize() const 19 | { 20 | float squareSum = SizeSquared(); 21 | if (squareSum == 1.f) 22 | { 23 | return *this; 24 | } 25 | else if (squareSum == 0.f) 26 | { 27 | return Vector3::Zero; 28 | } 29 | 30 | float invLength = Math::InvSqrt(squareSum); 31 | return Vector3(X * invLength, Y * invLength, Z * invLength); 32 | } -------------------------------------------------------------------------------- /Source/Runtime/Math/Private/Vector4.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK; 4 | 5 | const Vector4 Vector4::UnitX(1.f, 0.f, 0.f, 0.f); 6 | const Vector4 Vector4::UnitY(0.f, 1.f, 0.f, 0.f); 7 | const Vector4 Vector4::UnitZ(0.f, 0.f, 1.f, 0.f); 8 | const Vector4 Vector4::UnitW(0.f, 0.f, 0.f, 1.f); 9 | const Vector4 Vector4::Zero(0.f, 0.f, 0.f, 0.f); 10 | const Vector4 Vector4::One(1.f, 1.f, 1.f, 1.f); 11 | 12 | std::string Vector4::ToString() const 13 | { 14 | char result[64]; 15 | std::snprintf(result, sizeof(result), "(%.3f, %.3f, %.3f, %.3f)", X, Y, Z, W); 16 | return result; 17 | } 18 | 19 | Vector4 Vector4::GetNormalize() const 20 | { 21 | float squareSum = SizeSquared(); 22 | if (squareSum == 1.f) 23 | { 24 | return *this; 25 | } 26 | else if (squareSum == 0.f) 27 | { 28 | return Vector4::Zero; 29 | } 30 | 31 | float invLength = Math::InvSqrt(squareSum); 32 | return Vector4(X * invLength, Y * invLength, Z * invLength, W * invLength); 33 | } 34 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Box.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | struct Box 7 | { 8 | public: 9 | FORCEINLINE constexpr Box() = default; 10 | FORCEINLINE constexpr Box(const Box& InBox) : Min(InBox.Min), Max(InBox.Max) { } 11 | FORCEINLINE constexpr Box(const Vector3& InMinVector, const Vector3& InMaxVector) : Min(InMinVector), Max(InMaxVector) { } 12 | Box(const std::vector InVertices); 13 | 14 | FORCEINLINE constexpr bool Intersect(const Box& InBox) const; 15 | FORCEINLINE constexpr bool IsInside(const Box& InBox) const; 16 | FORCEINLINE constexpr bool IsInside(const Vector3& InVector) const; 17 | 18 | FORCEINLINE constexpr Box operator+=(const Vector3& InVector); 19 | FORCEINLINE constexpr Box operator+=(const Box& InBox); 20 | 21 | FORCEINLINE constexpr Vector3 GetSize() const; 22 | FORCEINLINE constexpr Vector3 GetExtent() const; 23 | FORCEINLINE constexpr void GetCenterAndExtent(Vector3& OutCenter, Vector3& OutExtent) const; 24 | 25 | public: 26 | Vector3 Min; 27 | Vector3 Max; 28 | }; 29 | 30 | FORCEINLINE constexpr bool Box::Intersect(const Box& InBox) const 31 | { 32 | if ((Min.X > InBox.Max.X) || (InBox.Min.X > Max.X)) 33 | { 34 | return false; 35 | } 36 | 37 | if ((Min.Y > InBox.Max.Y) || (InBox.Min.Y > Max.Y)) 38 | { 39 | return false; 40 | } 41 | 42 | if ((Min.Z > InBox.Max.Z) || (InBox.Min.Z > Max.Z)) 43 | { 44 | return false; 45 | } 46 | 47 | return true; 48 | } 49 | 50 | FORCEINLINE constexpr bool Box::IsInside(const Box& InBox) const 51 | { 52 | return (IsInside(InBox.Min) && IsInside(InBox.Max)); 53 | } 54 | 55 | FORCEINLINE constexpr bool Box::IsInside(const Vector3& InVector) const 56 | { 57 | return ((InVector.X >= Min.X) && (InVector.X <= Max.X) && (InVector.Y >= Min.Y) && (InVector.Y <= Max.Y) && (InVector.Z >= Min.Z) && (InVector.Z <= Max.Z)); 58 | } 59 | 60 | FORCEINLINE constexpr Box Box::operator+=(const Vector3& InVector) 61 | { 62 | Min.X = Math::Min(Min.X, InVector.X); 63 | Min.Y = Math::Min(Min.Y, InVector.Y); 64 | Min.Z = Math::Min(Min.Z, InVector.Z); 65 | 66 | Max.X = Math::Max(Max.X, InVector.X); 67 | Max.Y = Math::Max(Max.Y, InVector.Y); 68 | Max.Z = Math::Max(Max.Z, InVector.Z); 69 | 70 | return *this; 71 | } 72 | 73 | FORCEINLINE constexpr Box Box::operator+=(const Box& InBox) 74 | { 75 | Min.X = Math::Min(Min.X, InBox.Min.X); 76 | Min.Y = Math::Min(Min.Y, InBox.Min.Y); 77 | Min.Z = Math::Min(Min.Z, InBox.Min.Z); 78 | 79 | Max.X = Math::Max(Max.X, InBox.Max.X); 80 | Max.Y = Math::Max(Max.Y, InBox.Max.Y); 81 | Max.Z = Math::Max(Max.Z, InBox.Max.Z); 82 | return *this; 83 | } 84 | 85 | FORCEINLINE constexpr Vector3 Box::GetSize() const 86 | { 87 | return (Max - Min); 88 | } 89 | 90 | FORCEINLINE constexpr Vector3 Box::GetExtent() const 91 | { 92 | return GetSize() * 0.5f; 93 | } 94 | 95 | FORCEINLINE constexpr void Box::GetCenterAndExtent(Vector3 & OutCenter, Vector3 & OutExtent) const 96 | { 97 | OutExtent = GetExtent(); 98 | OutCenter = Min + OutExtent; 99 | } 100 | 101 | } 102 | 103 | 104 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Circle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | struct Circle 7 | { 8 | public: 9 | FORCEINLINE constexpr Circle() = default; 10 | FORCEINLINE constexpr Circle(const Circle& InCircle) : Center(InCircle.Center), Radius(InCircle.Radius) {}; 11 | Circle(const std::vector InVertices); 12 | 13 | FORCEINLINE constexpr bool IsInside(const Vector2& InVector) const; 14 | FORCEINLINE constexpr bool Intersect(const Circle& InCircle) const; 15 | 16 | public: 17 | Vector2 Center = Vector2::Zero; 18 | float Radius = 0.f; 19 | }; 20 | 21 | FORCEINLINE constexpr bool Circle::IsInside(const Vector2& InVector) const 22 | { 23 | return ((Center - InVector).SizeSquared() <= (Radius * Radius)); 24 | } 25 | 26 | FORCEINLINE constexpr bool Circle::Intersect(const Circle& InCircle) const 27 | { 28 | float twoRadiusSum = Radius + InCircle.Radius; 29 | return (Center - InCircle.Center).SizeSquared() <= (twoRadiusSum * twoRadiusSum); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Color32.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | struct Color32 7 | { 8 | public: 9 | FORCEINLINE constexpr Color32() : R(0), G(0), B(0), A(0) { } 10 | FORCEINLINE explicit constexpr Color32(BYTE InR, BYTE InG, BYTE InB, BYTE InA = 255) : B(InB), G(InG), R(InR), A(InA) { } 11 | FORCEINLINE explicit constexpr Color32(UINT32 InColor) : ColorValue(InColor) { } 12 | 13 | FORCEINLINE constexpr const UINT32& GetColorRef() const { return ColorValue; } 14 | FORCEINLINE constexpr UINT32& GetColorRef() { return ColorValue; } 15 | 16 | FORCEINLINE constexpr bool operator==(const Color32& InC) const; 17 | FORCEINLINE constexpr bool operator!=(const Color32& InC) const; 18 | FORCEINLINE constexpr void operator+=(const Color32& InC); 19 | 20 | static const Color32 Error; 21 | 22 | public: 23 | union 24 | { 25 | struct 26 | { 27 | BYTE B, G, R, A; 28 | }; 29 | 30 | UINT32 ColorValue; 31 | }; 32 | }; 33 | 34 | FORCEINLINE constexpr bool Color32::operator==(const Color32& InC) const 35 | { 36 | return GetColorRef() == InC.GetColorRef(); 37 | } 38 | 39 | FORCEINLINE constexpr bool Color32::operator!=(const Color32& InC) const 40 | { 41 | return GetColorRef() != InC.GetColorRef(); 42 | } 43 | 44 | FORCEINLINE constexpr void Color32::operator+=(const Color32& InC) 45 | { 46 | R = (BYTE)Math::Clamp((BYTE)R + (BYTE)InC.R, 0, 255); 47 | G = (BYTE)Math::Clamp((BYTE)G + (BYTE)InC.G, 0, 255); 48 | B = (BYTE)Math::Clamp((BYTE)B + (BYTE)InC.B, 0, 255); 49 | A = (BYTE)Math::Clamp((BYTE)A + (BYTE)InC.A, 0, 255); 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/CoreDefinition.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/CoreDefinition.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Frustum.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/Frustum.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/HSVColor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | struct HSVColor 7 | { 8 | public: 9 | FORCEINLINE constexpr HSVColor() = default; 10 | FORCEINLINE constexpr HSVColor(float InH, float InS, float InV) : H(InH), S(InS), V(InV) {} 11 | FORCEINLINE constexpr LinearColor ToLinearColor() const 12 | { 13 | float r = 0.f, g = 0.f, b = 0.f; 14 | 15 | int i = Math::FloorToInt(H * 6.f); 16 | float f = H * 6.f - i; 17 | float p = V * (1.f - S); 18 | float q = V * (1 - f * S); 19 | float t = V * (1 - (1 - f) * S); 20 | 21 | switch (i % 6) { 22 | case 0: r = V, g = t, b = p; break; 23 | case 1: r = q, g = V, b = p; break; 24 | case 2: r = p, g = V, b = t; break; 25 | case 3: r = p, g = q, b = V; break; 26 | case 4: r = t, g = p, b = V; break; 27 | case 5: r = V, g = p, b = q; break; 28 | } 29 | 30 | return LinearColor(r, g, b); 31 | } 32 | 33 | public: 34 | float H = 0.f; 35 | float S = 1.f; 36 | float V = 1.f; 37 | }; 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/LinearColor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | struct LinearColor 7 | { 8 | public: 9 | FORCEINLINE constexpr LinearColor() = default; 10 | FORCEINLINE explicit constexpr LinearColor(float InR, float InG, float InB, float InA = 1.f) : R(InR), G(InG), B(InB), A(InA) {} 11 | FORCEINLINE explicit constexpr LinearColor(const Color32& InColor32) 12 | { 13 | R = float(InColor32.R) * OneOver255; 14 | G = float(InColor32.G) * OneOver255; 15 | B = float(InColor32.B) * OneOver255; 16 | A = float(InColor32.A) * OneOver255; 17 | } 18 | 19 | FORCEINLINE constexpr Color32 ToColor32(const bool bSRGB = false) const; 20 | 21 | FORCEINLINE constexpr LinearColor operator+(const LinearColor& InColor) const; 22 | FORCEINLINE constexpr LinearColor operator-(const LinearColor& InColor) const; 23 | FORCEINLINE constexpr LinearColor operator*(const LinearColor& InColor) const; 24 | FORCEINLINE constexpr LinearColor operator*(float InScalar) const; 25 | FORCEINLINE constexpr LinearColor& operator*=(float InScale); 26 | FORCEINLINE constexpr LinearColor& operator/=(float InScale); 27 | FORCEINLINE constexpr LinearColor& operator+=(const LinearColor& InColor); 28 | FORCEINLINE constexpr LinearColor& operator-=(const LinearColor& InColor); 29 | 30 | FORCEINLINE constexpr bool operator==(const LinearColor& InColor) const; 31 | FORCEINLINE constexpr bool operator!=(const LinearColor& InColor) const; 32 | 33 | FORCEINLINE constexpr bool EqualsInRange(const LinearColor& InColor, float InTolerance = SMALL_NUMBER) const; 34 | 35 | static constexpr float OneOver255 = { 1.f / 255.f }; 36 | static const LinearColor Error; 37 | static const LinearColor White; 38 | static const LinearColor Black; 39 | static const LinearColor Gray; 40 | static const LinearColor Silver; 41 | static const LinearColor WhiteSmoke; 42 | static const LinearColor LightGray; 43 | static const LinearColor DimGray; 44 | static const LinearColor Red; 45 | static const LinearColor Green; 46 | static const LinearColor Blue; 47 | static const LinearColor Yellow; 48 | static const LinearColor Cyan; 49 | static const LinearColor Magenta; 50 | 51 | public: 52 | float R = 0.f; 53 | float G = 0.f; 54 | float B = 0.f; 55 | float A = 1.f; 56 | }; 57 | 58 | FORCEINLINE constexpr Color32 LinearColor::ToColor32(const bool bSRGB) const 59 | { 60 | float FloatR = Math::Clamp(R, 0.f, 1.f); 61 | float FloatG = Math::Clamp(G, 0.f, 1.f); 62 | float FloatB = Math::Clamp(B, 0.f, 1.f); 63 | float FloatA = Math::Clamp(A, 0.f, 1.f); 64 | 65 | return Color32( 66 | (int)(FloatR * 255.999f), 67 | (int)(FloatG * 255.999f), 68 | (int)(FloatB * 255.999f), 69 | (int)(FloatA * 255.999f) 70 | ); 71 | } 72 | 73 | FORCEINLINE constexpr LinearColor LinearColor::operator+(const LinearColor& InColor) const 74 | { 75 | return LinearColor( 76 | R + InColor.R, 77 | G + InColor.G, 78 | B + InColor.B, 79 | A + InColor.A 80 | ); 81 | } 82 | 83 | FORCEINLINE constexpr LinearColor LinearColor::operator-(const LinearColor& InColor) const 84 | { 85 | return LinearColor( 86 | R - InColor.R, 87 | G - InColor.G, 88 | B - InColor.B, 89 | A - InColor.A 90 | ); 91 | } 92 | 93 | FORCEINLINE constexpr LinearColor LinearColor::operator*(const LinearColor& InColor) const 94 | { 95 | return LinearColor( 96 | R * InColor.R, 97 | G * InColor.G, 98 | B * InColor.B, 99 | A * InColor.A 100 | ); 101 | } 102 | 103 | FORCEINLINE constexpr LinearColor LinearColor::operator*(float InScalar) const 104 | { 105 | return LinearColor( 106 | R * InScalar, 107 | G * InScalar, 108 | B * InScalar, 109 | A * InScalar 110 | ); 111 | } 112 | 113 | FORCEINLINE constexpr LinearColor& LinearColor::operator*=(float InScale) 114 | { 115 | R *= InScale; 116 | G *= InScale; 117 | B *= InScale; 118 | A *= InScale; 119 | return *this; 120 | } 121 | 122 | FORCEINLINE constexpr LinearColor& LinearColor::operator/=(float InScale) 123 | { 124 | R /= InScale; 125 | G /= InScale; 126 | B /= InScale; 127 | A /= InScale; 128 | return *this; 129 | } 130 | 131 | FORCEINLINE constexpr LinearColor& LinearColor::operator+=(const LinearColor& InColor) 132 | { 133 | R += InColor.R; 134 | G += InColor.G; 135 | B += InColor.B; 136 | A += InColor.A; 137 | return *this; 138 | } 139 | 140 | FORCEINLINE constexpr LinearColor& LinearColor::operator-=(const LinearColor& InColor) 141 | { 142 | R -= InColor.R; 143 | G -= InColor.G; 144 | B -= InColor.B; 145 | A -= InColor.A; 146 | return *this; 147 | } 148 | 149 | FORCEINLINE constexpr bool LinearColor::operator==(const LinearColor& InColor) const 150 | { 151 | return this->R == InColor.R && this->G == InColor.G && this->B == InColor.B && this->A == InColor.A; 152 | } 153 | 154 | FORCEINLINE constexpr bool LinearColor::operator!=(const LinearColor& InColor) const 155 | { 156 | return this->R != InColor.R || this->G != InColor.G || this->B != InColor.B || this->A != InColor.A; 157 | } 158 | 159 | FORCEINLINE constexpr bool LinearColor::EqualsInRange(const LinearColor& InColor, float InTolerance) const 160 | { 161 | return (Math::Abs(this->R - InColor.R) < InTolerance) && 162 | (Math::Abs(this->G - InColor.G) < InTolerance) && 163 | (Math::Abs(this->B - InColor.B) < InTolerance) && 164 | (Math::Abs(this->A - InColor.A) < InTolerance); 165 | } 166 | 167 | } 168 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/MathHeaders.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | #include "Platform.h" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "MathUtil.h" 17 | #include "Vector2.h" 18 | #include "Vector3.h" 19 | #include "Vector4.h" 20 | 21 | #include "Matrix2x2.h" 22 | #include "Matrix3x3.h" 23 | #include "Matrix4x4.h" 24 | 25 | #include "ScreenPoint.h" 26 | 27 | #include "Color32.h" 28 | #include "LinearColor.h" 29 | #include "HSVColor.h" 30 | 31 | #include "Rotator.h" 32 | 33 | #include "Quaternion.h" 34 | 35 | #include "Transform.h" 36 | 37 | #include "Plane.h" 38 | 39 | #include "Circle.h" 40 | #include "Rectangle.h" 41 | #include "Sphere.h" 42 | #include "Box.h" 43 | 44 | #include "Frustum.h" 45 | 46 | using namespace CK; 47 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/MathUtil.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/MathUtil.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Matrix2x2.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/Matrix2x2.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Matrix3x3.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/Matrix3x3.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Matrix4x4.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/Matrix4x4.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Plane.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/Plane.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Platform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CoreDefinition.h" 4 | 5 | #if defined(PLATFORM_WINDOWS) 6 | #include "Windows/WindowsPlatform.h" 7 | #endif 8 | 9 | #if !defined(FORCEINLINE) 10 | #define FORCEINLINE inline 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Quaternion.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/Quaternion.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Rectangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | struct Rectangle 7 | { 8 | public: 9 | FORCEINLINE constexpr Rectangle() = default; 10 | FORCEINLINE constexpr Rectangle(const Rectangle& InRectangle) : Min(InRectangle.Min), Max(InRectangle.Max) { } 11 | FORCEINLINE constexpr Rectangle(const Vector2& InMinVector, const Vector2& InMaxVector) : Min(InMinVector), Max(InMaxVector) { } 12 | Rectangle(const std::vector InVertices); 13 | 14 | FORCEINLINE constexpr bool Intersect(const Rectangle& InRectangle) const; 15 | FORCEINLINE constexpr bool IsInside(const Rectangle& InRectangle) const; 16 | FORCEINLINE constexpr bool IsInside(const Vector2& InVector) const; 17 | 18 | FORCEINLINE constexpr Rectangle operator+=(const Vector2& InVector); 19 | FORCEINLINE constexpr Rectangle operator+=(const Rectangle& InRectangle); 20 | 21 | FORCEINLINE constexpr Vector2 GetSize() const; 22 | FORCEINLINE constexpr Vector2 GetExtent() const; 23 | FORCEINLINE constexpr void GetCenterAndExtent(Vector2& OutCenter, Vector2& OutExtent) const; 24 | 25 | public: 26 | Vector2 Min; 27 | Vector2 Max; 28 | }; 29 | 30 | FORCEINLINE constexpr bool Rectangle::Intersect(const Rectangle& InRectangle) const 31 | { 32 | if ((Min.X > InRectangle.Max.X) || (InRectangle.Min.X > Max.X)) 33 | { 34 | return false; 35 | } 36 | 37 | if ((Min.Y > InRectangle.Max.Y) || (InRectangle.Min.Y > Max.Y)) 38 | { 39 | return false; 40 | } 41 | 42 | return true; 43 | } 44 | 45 | FORCEINLINE constexpr bool Rectangle::IsInside(const Rectangle& InRectangle) const 46 | { 47 | return (IsInside(InRectangle.Min) && IsInside(InRectangle.Max)); 48 | } 49 | 50 | FORCEINLINE constexpr bool Rectangle::IsInside(const Vector2& InVector) const 51 | { 52 | return ((InVector.X >= Min.X) && (InVector.X <= Max.X) && (InVector.Y >= Min.Y) && (InVector.Y <= Max.Y)); 53 | } 54 | 55 | FORCEINLINE constexpr Rectangle Rectangle::operator+=(const Vector2& InVector) 56 | { 57 | Min.X = Math::Min(Min.X, InVector.X); 58 | Min.Y = Math::Min(Min.Y, InVector.Y); 59 | 60 | Max.X = Math::Max(Max.X, InVector.X); 61 | Max.Y = Math::Max(Max.Y, InVector.Y); 62 | return *this; 63 | } 64 | 65 | FORCEINLINE constexpr Rectangle Rectangle::operator+=(const Rectangle& InRectangle) 66 | { 67 | Min.X = Math::Min(Min.X, InRectangle.Min.X); 68 | Min.Y = Math::Min(Min.Y, InRectangle.Min.Y); 69 | 70 | Max.X = Math::Max(Max.X, InRectangle.Max.X); 71 | Max.Y = Math::Max(Max.Y, InRectangle.Max.Y); 72 | return *this; 73 | } 74 | 75 | FORCEINLINE constexpr Vector2 Rectangle::GetSize() const 76 | { 77 | return (Max - Min); 78 | } 79 | 80 | FORCEINLINE constexpr Vector2 Rectangle::GetExtent() const 81 | { 82 | return GetSize() * 0.5f; 83 | } 84 | 85 | FORCEINLINE constexpr void Rectangle::GetCenterAndExtent(Vector2 & OutCenter, Vector2 & OutExtent) const 86 | { 87 | OutExtent = GetExtent(); 88 | OutCenter = Min + OutExtent; 89 | } 90 | 91 | } -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Rotator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | struct Rotator 7 | { 8 | public: 9 | FORCEINLINE constexpr Rotator() = default; 10 | FORCEINLINE constexpr Rotator(float InYaw, float InRoll, float InPitch) : Yaw(InYaw), Roll(InRoll), Pitch(InPitch) { } 11 | FORCEINLINE void Clamp() 12 | { 13 | Yaw = GetAxisClampedValue(Yaw); 14 | Roll = GetAxisClampedValue(Roll); 15 | Pitch = GetAxisClampedValue(Pitch); 16 | } 17 | 18 | FORCEINLINE float GetAxisClampedValue(float InRotatorValue) 19 | { 20 | float angle = Math::FMod(InRotatorValue, 360.f); 21 | if (angle < 0.f) 22 | { 23 | angle += 360.f; 24 | } 25 | 26 | return angle; 27 | } 28 | 29 | FORCEINLINE void GetLocalAxes(Vector3& OutRight, Vector3& OutUp, Vector3& OutForward) 30 | { 31 | float cy = 0.f, sy = 0.f, cp = 0.f, sp = 0.f, cr = 0.f, sr = 0.f; 32 | Math::GetSinCos(sy, cy, Yaw); 33 | Math::GetSinCos(sp, cp, Pitch); 34 | Math::GetSinCos(sr, cr, Roll); 35 | 36 | OutRight = Vector3(cy * cr + sy * sp * sr, cp * sr, -sy * cr + cy * sp * sr); 37 | OutUp = Vector3(-cy * sr + sy * sp * cr, cp * cr, sy * sr + cy * sp * cr); 38 | OutForward = Vector3(sy * cp, -sp, cy * cp); 39 | } 40 | 41 | std::string ToString() const; 42 | static const Rotator Identity; 43 | 44 | public: 45 | float Yaw = 0.f; 46 | float Roll = 0.f; 47 | float Pitch = 0.f; 48 | }; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/ScreenPoint.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/ScreenPoint.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Sphere.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CK 4 | { 5 | 6 | struct Sphere 7 | { 8 | public: 9 | FORCEINLINE constexpr Sphere() = default; 10 | FORCEINLINE constexpr Sphere(const Circle& InCircle) : Center(InCircle.Center), Radius(InCircle.Radius) {}; 11 | Sphere(const std::vector& InVertices); 12 | 13 | FORCEINLINE constexpr bool IsInside(const Vector3& InVector) const; 14 | FORCEINLINE constexpr bool Intersect(const Sphere& InCircle) const; 15 | 16 | public: 17 | Vector3 Center = Vector3::Zero; 18 | float Radius = 0.f; 19 | }; 20 | 21 | FORCEINLINE constexpr bool Sphere::IsInside(const Vector3& InVector) const 22 | { 23 | return ((Center - InVector).SizeSquared() <= (Radius * Radius)); 24 | } 25 | 26 | FORCEINLINE constexpr bool Sphere::Intersect(const Sphere& InCircle) const 27 | { 28 | float radiusSum = Radius + InCircle.Radius; 29 | return (Center - InCircle.Center).SizeSquared() <= (radiusSum * radiusSum); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Transform.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/Transform.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Vector2.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/Vector2.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Vector3.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/Vector3.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Vector4.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Math/Public/Vector4.h -------------------------------------------------------------------------------- /Source/Runtime/Math/Public/Windows/WindowsPlatform.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #define FORCEINLINE __forceinline 5 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | project(RendererModule) 4 | 5 | ################################################################################ 6 | # Source files 7 | ################################################################################ 8 | file(GLOB COMMON_FILES 9 | ${PROJECT_SOURCE_DIR}/*.cpp 10 | ${PROJECT_SOURCE_DIR}/*.h) 11 | 12 | file(GLOB_RECURSE MODULE_FILES 13 | ${PROJECT_SOURCE_DIR}/Public/*.h 14 | ${PROJECT_SOURCE_DIR}/Public/2D/*.h 15 | ${PROJECT_SOURCE_DIR}/Public/3D/*.h 16 | ${PROJECT_SOURCE_DIR}/Private/2D/*.cpp 17 | ${PROJECT_SOURCE_DIR}/Private/3D/*.cpp 18 | ) 19 | 20 | file(GLOB_RECURSE THIRDPARTY_FILES 21 | ${PROJECT_SOURCE_DIR}/ThirdParty/*.h 22 | ${PROJECT_SOURCE_DIR}/ThirdParty/*.cpp 23 | ) 24 | 25 | set(ALL_FILES 26 | ${COMMON_FILES} 27 | ${MODULE_FILES} 28 | ${THIRDPARTY_FILES} 29 | ) 30 | 31 | if(TARGET_WINDOWS) 32 | 33 | file(GLOB_RECURSE WINDOWS_FILES 34 | ${PROJECT_SOURCE_DIR}/Public/${PLATFORM_FOLDER}/*.h 35 | ${PROJECT_SOURCE_DIR}/Private/${PLATFORM_FOLDER}/*.h 36 | ${PROJECT_SOURCE_DIR}/Private/${PLATFORM_FOLDER}/*.cpp 37 | ) 38 | 39 | set(ALL_FILES 40 | ${ALL_FILES} 41 | ${WINDOWS_FILES} 42 | ) 43 | 44 | endif() 45 | 46 | foreach(FILE ${ALL_FILES}) 47 | # make rel path 48 | file(RELATIVE_PATH REL_PATH "${PROJECT_SOURCE_DIR}" "${FILE}") 49 | set(ALL_FILES_REL ${ALL_FILES_REL} ${REL_PATH}) 50 | endforeach() 51 | 52 | set_source_files_properties(${ALL_FILES_REL} PROPERTIES HEADER_FILE_ONLY FALSE) 53 | 54 | foreach(FILE ${ALL_FILES_REL}) 55 | # get the base path 56 | get_filename_component(BASE_PATH "${FILE}" PATH) 57 | 58 | # changes /'s to \\'s 59 | string(REPLACE "/" "\\" GROUP "${BASE_PATH}") 60 | 61 | source_group("${GROUP}" FILES "${FILE}") 62 | endforeach() 63 | 64 | 65 | ################################################################################ 66 | # Include directory 67 | ################################################################################ 68 | include_directories( 69 | ${PROJECT_SOURCE_DIR} 70 | ${PROJECT_SOURCE_DIR}/Public 71 | ${PROJECT_SOURCE_DIR}/ThirdParty 72 | ${RUNTIME_MODULE_DIR}/Math/Public 73 | ) 74 | 75 | 76 | ################################################################################ 77 | # Precompiled Headers 78 | ################################################################################ 79 | set(ARG_PCH_HEADER Precompiled.h) 80 | set(ARG_PCH_SOURCE Precompiled.cpp) 81 | foreach (FILE ${ALL_FILES_REL}) 82 | if (FILE MATCHES ".*\\.(c|cpp)$") 83 | if (FILE STREQUAL ${ARG_PCH_SOURCE}) 84 | set_source_files_properties(${FILE} PROPERTIES COMPILE_FLAGS "/Yc\"${ARG_PCH_HEADER}\"") 85 | else() 86 | set_source_files_properties(${FILE} PROPERTIES COMPILE_FLAGS "/Yu\"${ARG_PCH_HEADER}\"") 87 | endif() 88 | endif() 89 | endforeach(FILE) 90 | 91 | 92 | ################################################################################ 93 | # Library Output Setting 94 | ################################################################################ 95 | add_library(${PROJECT_NAME} STATIC ${ALL_FILES_REL}) 96 | 97 | set_target_properties(${PROJECT_NAME} PROPERTIES 98 | PREFIX "" 99 | OUTPUT_NAME ${PROJECT_NAME} 100 | ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Output/${PLATFORM_FOLDER}/Library) 101 | 102 | 103 | ################################################################################ 104 | # Import Library 105 | ################################################################################ 106 | target_link_libraries(${PROJECT_NAME} MathModule) 107 | 108 | 109 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Precompiled.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Precompiled.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MathHeaders.h" 4 | #include "RendererHeaders.h" 5 | 6 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Private/2D/Shader.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DD; 4 | 5 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Private/2D/Vertex.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DD; 4 | 5 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Private/3D/PerspectiveTest.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DDD; 4 | 5 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Private/3D/Shader.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DDD; 4 | 5 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Private/3D/Vertex.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | using namespace CK::DDD; 4 | 5 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Private/Windows/WindowsGDI.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Precompiled.h" 3 | 4 | WindowsGDI::~WindowsGDI() 5 | { 6 | } 7 | 8 | bool WindowsGDI::InitializeGDI(const ScreenPoint& InScreenSize) 9 | { 10 | ReleaseGDI(); 11 | 12 | if (_Handle == 0) 13 | { 14 | _Handle = ::GetActiveWindow(); 15 | if (_Handle == 0) 16 | { 17 | return false; 18 | } 19 | } 20 | 21 | if (_GDIInitialized) 22 | { 23 | DeleteObject(_DefaultBitmap); 24 | DeleteObject(DIBitmap); 25 | ReleaseDC(_Handle, _ScreenDC); 26 | ReleaseDC(_Handle, _MemoryDC); 27 | } 28 | 29 | _ScreenDC = GetDC(_Handle); 30 | if (_ScreenDC == NULL) 31 | { 32 | return false; 33 | } 34 | 35 | _MemoryDC = CreateCompatibleDC(_ScreenDC); 36 | if (_MemoryDC == NULL) 37 | { 38 | return false; 39 | } 40 | 41 | _ScreenSize = InScreenSize; 42 | 43 | // Color & Bitmap Setting 44 | BITMAPINFO bmi; 45 | memset(&bmi, 0, sizeof(BITMAPINFO)); 46 | bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 47 | bmi.bmiHeader.biWidth = _ScreenSize.X; 48 | bmi.bmiHeader.biHeight = -_ScreenSize.Y; 49 | bmi.bmiHeader.biPlanes = 1; 50 | bmi.bmiHeader.biBitCount = 32; 51 | bmi.bmiHeader.biCompression = BI_RGB; 52 | 53 | DIBitmap = CreateDIBSection(_MemoryDC, &bmi, DIB_RGB_COLORS, (void**)&_ScreenBuffer, NULL, 0); 54 | if (DIBitmap == NULL) 55 | { 56 | return false; 57 | } 58 | 59 | _DefaultBitmap = (HBITMAP)SelectObject(_MemoryDC, DIBitmap); 60 | if (_DefaultBitmap == NULL) 61 | { 62 | return false; 63 | } 64 | 65 | // Create Depth Buffer 66 | CreateDepthBuffer(); 67 | 68 | _GDIInitialized = true; 69 | return true; 70 | } 71 | 72 | void WindowsGDI::ReleaseGDI() 73 | { 74 | if (_GDIInitialized) 75 | { 76 | DeleteObject(_DefaultBitmap); 77 | DeleteObject(DIBitmap); 78 | ReleaseDC(_Handle, _ScreenDC); 79 | ReleaseDC(_Handle, _MemoryDC); 80 | } 81 | 82 | if (_DepthBuffer != nullptr) 83 | { 84 | delete[] _DepthBuffer; 85 | _DepthBuffer = nullptr; 86 | } 87 | 88 | _GDIInitialized = false; 89 | } 90 | 91 | 92 | void WindowsGDI::FillBuffer(Color32 InColor) 93 | { 94 | if (!_GDIInitialized || (_ScreenBuffer == NULL)) 95 | { 96 | return; 97 | } 98 | 99 | Color32* dest = _ScreenBuffer; 100 | UINT32 totalCount = _ScreenSize.X * _ScreenSize.Y; 101 | CopyBuffer(_ScreenBuffer, &InColor, totalCount); 102 | return; 103 | } 104 | 105 | template 106 | T* WindowsGDI::CopyBuffer(T* InDst, T* InSrc, int InCount) 107 | { 108 | if (InCount == 0) 109 | { 110 | return NULL; 111 | } 112 | 113 | if (InCount == 1) 114 | { 115 | memcpy(InDst, InSrc, sizeof(T)); 116 | } 117 | else 118 | { 119 | int half = Math::FloorToInt(InCount * 0.5f); 120 | CopyBuffer(InDst, InSrc, half); 121 | memcpy(InDst + half, InDst, half * sizeof(T)); 122 | 123 | if (InCount % 2) 124 | { 125 | memcpy(InDst + (InCount - 1), InSrc, sizeof(T)); 126 | } 127 | } 128 | 129 | return InDst; 130 | } 131 | 132 | Color32* WindowsGDI::GetScreenBuffer() const 133 | { 134 | return _ScreenBuffer; 135 | } 136 | 137 | void WindowsGDI::DrawStatisticTexts() 138 | { 139 | if (_StatisticTexts.size() == 0) 140 | { 141 | return; 142 | } 143 | 144 | HFONT hFont, hOldFont; 145 | hFont = (HFONT)GetStockObject(ANSI_VAR_FONT); 146 | if (hOldFont = (HFONT)SelectObject(_MemoryDC, hFont)) 147 | { 148 | static const int leftPosition = 600; 149 | static const int topPosition = 10; 150 | static const int rowHeight = 20; 151 | int currentPosition = topPosition; 152 | for (std::vector::const_iterator it = _StatisticTexts.begin(); it != _StatisticTexts.end(); ++it) 153 | { 154 | TextOut(_MemoryDC, leftPosition, currentPosition, (*it).c_str(), (int)((*it).length())); 155 | currentPosition += rowHeight; 156 | } 157 | 158 | SelectObject(_MemoryDC, hOldFont); 159 | } 160 | } 161 | 162 | void WindowsGDI::SwapBuffer() 163 | { 164 | if (!_GDIInitialized) 165 | { 166 | return; 167 | } 168 | 169 | DrawStatisticTexts(); 170 | BitBlt(_ScreenDC, 0, 0, _ScreenSize.X, _ScreenSize.Y, _MemoryDC, 0, 0, SRCCOPY); 171 | 172 | _StatisticTexts.clear(); 173 | } 174 | 175 | void WindowsGDI::CreateDepthBuffer() 176 | { 177 | _DepthBuffer = new float[_ScreenSize.X * _ScreenSize.Y]; 178 | } 179 | 180 | void WindowsGDI::ClearDepthBuffer() 181 | { 182 | if (_DepthBuffer != nullptr) 183 | { 184 | float* dest = _DepthBuffer; 185 | static float defValue = INFINITY; 186 | UINT32 totalCount = _ScreenSize.X * _ScreenSize.Y; 187 | CopyBuffer(_DepthBuffer, &defValue, totalCount); 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Private/Windows/WindowsRSI.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Renderer/Private/Windows/WindowsRSI.cpp -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Public/2D/Shader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Renderer/Public/2D/Shader.h -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Public/2D/Vertex.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | namespace CK 5 | { 6 | namespace DD 7 | { 8 | 9 | struct Vertex2D 10 | { 11 | public: 12 | constexpr Vertex2D() = default; 13 | constexpr Vertex2D(const Vector2& InPosition) : Position(InPosition) { } 14 | constexpr Vertex2D(const Vector2& InPosition, const LinearColor& InColor) : Position(InPosition), Color(InColor) { } 15 | constexpr Vertex2D(const Vector2& InPosition, const LinearColor& InColor, const Vector2& InUV) : Position(InPosition), Color(InColor), UV(InUV) { } 16 | 17 | constexpr Vertex2D operator*(float InScalar) const 18 | { 19 | return Vertex2D( 20 | Position * InScalar, 21 | Color * InScalar, 22 | UV * InScalar 23 | ); 24 | } 25 | 26 | constexpr Vertex2D operator+(const Vertex2D& InVector) const 27 | { 28 | return Vertex2D( 29 | Position + InVector.Position, 30 | Color + InVector.Color, 31 | UV + InVector.UV 32 | ); 33 | } 34 | 35 | Vector2 Position; 36 | LinearColor Color; 37 | Vector2 UV; 38 | }; 39 | 40 | } 41 | } -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Public/3D/PerspectiveTest.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Renderer/Public/3D/PerspectiveTest.h -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Public/3D/Shader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/gamemath/6612cf6982f5298b9beb6651cb2c5da34109f42d/Source/Runtime/Renderer/Public/3D/Shader.h -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Public/3D/Vertex.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | namespace CK 5 | { 6 | namespace DDD 7 | { 8 | 9 | struct Vertex3D 10 | { 11 | public: 12 | constexpr Vertex3D() = default; 13 | constexpr Vertex3D(const Vector4& InPosition) : Position(InPosition) { } 14 | constexpr Vertex3D(const Vector4& InPosition, const LinearColor& InColor) : Position(InPosition), Color(InColor) { } 15 | constexpr Vertex3D(const Vector4& InPosition, const LinearColor& InColor, const Vector2& InUV) : Position(InPosition), Color(InColor), UV(InUV) { } 16 | 17 | constexpr Vertex3D operator*(float InScalar) const 18 | { 19 | return Vertex3D( 20 | Position * InScalar, 21 | Color * InScalar, 22 | UV * InScalar 23 | ); 24 | } 25 | 26 | constexpr Vertex3D operator+(const Vertex3D& InVector) const 27 | { 28 | return Vertex3D( 29 | Position + InVector.Position, 30 | Color + InVector.Color, 31 | UV + InVector.UV 32 | ); 33 | } 34 | 35 | Vector4 Position; 36 | LinearColor Color; 37 | Vector2 UV; 38 | }; 39 | 40 | } 41 | } -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Public/RendererHeaders.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "2D/Vertex.h" 6 | #include "2D/Shader.h" 7 | #include "3D/Vertex.h" 8 | #include "3D/Shader.h" 9 | #include "3D/PerspectiveTest.h" 10 | 11 | #include "RendererInterface.h" 12 | 13 | #if defined(PLATFORM_WINDOWS) 14 | #include 15 | #include "Windows/WindowsGDI.h" 16 | #include "Windows/WindowsRSI.h" 17 | #endif 18 | 19 | using namespace CK; 20 | -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Public/RendererInterface.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | namespace CK 5 | { 6 | 7 | class RendererInterface 8 | { 9 | public: 10 | virtual bool Init(const ScreenPoint& InSize) = 0; 11 | virtual void Shutdown() = 0; 12 | virtual bool IsInitialized() const = 0; 13 | 14 | virtual void Clear(const LinearColor& InClearColor) = 0; 15 | virtual void BeginFrame() = 0; 16 | virtual void EndFrame() = 0; 17 | 18 | virtual void DrawPoint(const Vector2& InVectorPos, const LinearColor& InColor) = 0; 19 | virtual void DrawPoint(const ScreenPoint& InScreenPos, const LinearColor& InColor) = 0; 20 | virtual void DrawLine(const Vector2& InStartPos, const Vector2& InEndPos, const LinearColor& InColor) = 0; 21 | virtual void DrawLine(const Vector4& InStartPos, const Vector4& InEndPos, const LinearColor& InColor) = 0; 22 | 23 | virtual float GetDepthBufferValue(const ScreenPoint& InScreenPos) const = 0; 24 | virtual void SetDepthBufferValue(const ScreenPoint& InScreenPos, float InDepthValue) = 0; 25 | 26 | virtual void DrawFullVerticalLine(int InX, const LinearColor& InColor) = 0; 27 | virtual void DrawFullHorizontalLine(int InY, const LinearColor& InColor) = 0; 28 | 29 | virtual void PushStatisticText(std::string && InText) = 0; 30 | virtual void PushStatisticTexts(std::vector && InTexts) = 0; 31 | }; 32 | 33 | } -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Public/Windows/WindowsGDI.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | namespace CK 5 | { 6 | 7 | class WindowsGDI 8 | { 9 | public: 10 | WindowsGDI() = default; 11 | ~WindowsGDI(); 12 | 13 | public: 14 | bool InitializeGDI(const ScreenPoint& InScreenSize); 15 | void ReleaseGDI(); 16 | 17 | void FillBuffer(Color32 InColor); 18 | 19 | FORCEINLINE LinearColor GetPixel(const ScreenPoint& InPos); 20 | FORCEINLINE void SetPixelOpaque(const ScreenPoint& InPos, const LinearColor& InColor); 21 | FORCEINLINE void SetPixelAlphaBlending(const ScreenPoint& InPos, const LinearColor& InColor); 22 | 23 | void CreateDepthBuffer(); 24 | void ClearDepthBuffer(); 25 | 26 | Color32* GetScreenBuffer() const; 27 | 28 | void DrawStatisticTexts(); 29 | 30 | void SwapBuffer(); 31 | 32 | protected: 33 | FORCEINLINE bool IsInScreen(const ScreenPoint& InPos) const; 34 | int GetScreenBufferIndex(const ScreenPoint& InPos) const; 35 | 36 | template 37 | T* CopyBuffer(T* InDst, T* InSrc, int InCount); 38 | 39 | protected: 40 | bool _GDIInitialized = false; 41 | 42 | HWND _Handle = 0; 43 | HDC _ScreenDC = 0, _MemoryDC = 0; 44 | HBITMAP _DefaultBitmap = 0, DIBitmap = 0; 45 | 46 | Color32* _ScreenBuffer = nullptr; 47 | float* _DepthBuffer = nullptr; 48 | 49 | ScreenPoint _ScreenSize; 50 | std::vector _StatisticTexts; 51 | }; 52 | 53 | FORCEINLINE void WindowsGDI::SetPixelOpaque(const ScreenPoint& InPos, const LinearColor& InColor) 54 | { 55 | if (!IsInScreen(InPos)) 56 | { 57 | return; 58 | } 59 | 60 | Color32* dest = _ScreenBuffer; 61 | *(dest + GetScreenBufferIndex(InPos)) = InColor.ToColor32(); 62 | return; 63 | } 64 | 65 | FORCEINLINE void WindowsGDI::SetPixelAlphaBlending(const ScreenPoint & InPos, const LinearColor & InColor) 66 | { 67 | LinearColor bufferColor = GetPixel(InPos); 68 | if (!IsInScreen(InPos)) 69 | { 70 | return; 71 | } 72 | 73 | Color32* dest = _ScreenBuffer; 74 | *(dest + GetScreenBufferIndex(InPos)) = (InColor * InColor.A + bufferColor * (1.f - InColor.A)).ToColor32(); 75 | } 76 | 77 | FORCEINLINE bool WindowsGDI::IsInScreen(const ScreenPoint& InPos) const 78 | { 79 | if ((InPos.X < 0 || InPos.X >= _ScreenSize.X) || (InPos.Y < 0 || InPos.Y >= _ScreenSize.Y)) 80 | { 81 | return false; 82 | } 83 | 84 | return true; 85 | } 86 | 87 | FORCEINLINE int WindowsGDI::GetScreenBufferIndex(const ScreenPoint& InPos) const 88 | { 89 | return InPos.Y * _ScreenSize.X + InPos.X; 90 | } 91 | 92 | FORCEINLINE LinearColor WindowsGDI::GetPixel(const ScreenPoint& InPos) 93 | { 94 | if (!IsInScreen(InPos)) 95 | { 96 | return LinearColor::Error; 97 | } 98 | 99 | Color32* dest = _ScreenBuffer; 100 | Color32 bufferColor = *(dest + GetScreenBufferIndex(InPos)); 101 | return LinearColor(bufferColor); 102 | } 103 | 104 | } -------------------------------------------------------------------------------- /Source/Runtime/Renderer/Public/Windows/WindowsRSI.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | namespace CK 5 | { 6 | 7 | class WindowsRSI : public WindowsGDI, public RendererInterface 8 | { 9 | public: 10 | WindowsRSI() = default; 11 | ~WindowsRSI(); 12 | 13 | public: 14 | virtual bool Init(const ScreenPoint& InScreenSize) override; 15 | virtual void Shutdown() override; 16 | virtual bool IsInitialized() const { return _GDIInitialized; } 17 | 18 | virtual void Clear(const LinearColor& InClearColor) override; 19 | virtual void BeginFrame() override; 20 | virtual void EndFrame() override; 21 | 22 | virtual void DrawPoint(const Vector2& InVectorPos, const LinearColor& InColor) override; 23 | virtual void DrawPoint(const ScreenPoint& InScreenPos, const LinearColor& InColor) override; 24 | virtual void DrawLine(const Vector2& InStartPos, const Vector2& InEndPos, const LinearColor& InColor) override; 25 | virtual void DrawLine(const Vector4& InStartPos, const Vector4& InEndPos, const LinearColor& InColor) override; 26 | 27 | virtual float GetDepthBufferValue(const ScreenPoint& InPos) const override; 28 | virtual void SetDepthBufferValue(const ScreenPoint& InPos, float InDepthValue) override; 29 | 30 | virtual void DrawFullVerticalLine(int InX, const LinearColor& InColor) override; 31 | virtual void DrawFullHorizontalLine(int InY, const LinearColor& InColor) override; 32 | 33 | virtual void PushStatisticText(std::string && InText) override; 34 | virtual void PushStatisticTexts(std::vector && InTexts) override; 35 | 36 | private: 37 | int TestRegion(const Vector2& InVectorPos, const Vector2& InMinPos, const Vector2& InMaxPos); 38 | bool CohenSutherlandLineClip(Vector2& InOutStartPos, Vector2& InOutEndPos, const Vector2& InMinPos, const Vector2& InMaxPos); 39 | 40 | FORCEINLINE void SetPixel(const ScreenPoint& InPos, const LinearColor& InColor); 41 | }; 42 | 43 | FORCEINLINE void WindowsRSI::SetPixel(const ScreenPoint& InPos, const LinearColor& InColor) 44 | { 45 | SetPixelOpaque(InPos, InColor); 46 | } 47 | 48 | } --------------------------------------------------------------------------------