├── Build_VS2013_Win32_Debug.bat ├── Build_VS2013_Win32_Release.bat ├── Build_VS2013_x64_Debug.bat ├── Build_VS2013_x64_Release.bat ├── Build_VS2015_Win32_Debug.bat ├── Build_VS2015_Win32_Release.bat ├── Build_VS2015_x64_Debug.bat ├── Build_VS2015_x64_Release.bat ├── CMakeLists.txt ├── Readme.md ├── conanfile.py ├── copyright.txt ├── external └── Irrlicht-math │ ├── LICENSE │ ├── README.md │ └── include │ ├── IrrCompileConfig.h │ ├── irrMath.h │ ├── irrTypes.h │ ├── irrlicht.h │ ├── matrix4.h │ ├── quaternion.h │ ├── vector2.h │ └── vector3.h └── src ├── AbstractInputProcessor.cpp ├── AbstractInputProcessor.h ├── CMakeLists.txt ├── DualQuat.h ├── IMURotationModel.cpp ├── IMURotationModel.h ├── InternalVariables.cpp ├── InternalVariables.h ├── LHTrackingAlgorithm.cpp ├── LHTrackingAlgorithm.h ├── LightHouseData.h ├── LighthouseInputProcessor.cpp ├── LighthouseInputProcessor.h ├── MoveDetector.cpp ├── MoveDetector.h ├── PresampleDataLoader.cpp ├── PresampleDataLoader.h ├── RingBufferDataLoader.cpp ├── RingBufferDataLoader.h ├── SafeFlag.hpp ├── SensorDataInterpretor.cpp ├── SensorDataInterpretor.h ├── TO_HMD.cpp ├── TO_HMD.h ├── TimeManager.cpp ├── TimeManager.h ├── TrackObject.cpp ├── TrackObject.h ├── TrackObjectManager.cpp ├── TrackObjectManager.h ├── TrackingDataLoader.cpp ├── TrackingDataLoader.h ├── internal.h ├── resource.h ├── ringbuffer.h ├── stdafx.cpp ├── stdafx.h ├── targetver.h ├── types.h ├── version.aps └── version.rc /Build_VS2013_Win32_Debug.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set "sourceDir=%~dp0" 3 | set "currentDir=%cd%" 4 | set "scriptDir=%sourceDir%scripts\python" 5 | :build 6 | echo Build start. 7 | cd "%sourceDir%" 8 | conan install -u -s arch="x86" -s build_type="Debug" -s compiler="Visual Studio" -s compiler.runtime="MDd" -s compiler.version="12" -o build_develop=True 9 | conan build 10 | cd "%currentDir%" 11 | echo Build done. 12 | pause -------------------------------------------------------------------------------- /Build_VS2013_Win32_Release.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set "sourceDir=%~dp0" 3 | set "currentDir=%cd%" 4 | set "scriptDir=%sourceDir%scripts\python" 5 | :build 6 | echo Build start. 7 | cd "%sourceDir%" 8 | conan install -u -s arch="x86" -s build_type="Release" -s compiler="Visual Studio" -s compiler.runtime="MD" -s compiler.version="12" -o build_develop=True 9 | conan build 10 | cd "%currentDir%" 11 | echo Build done. 12 | pause -------------------------------------------------------------------------------- /Build_VS2013_x64_Debug.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set "sourceDir=%~dp0" 3 | set "currentDir=%cd%" 4 | set "scriptDir=%sourceDir%scripts\python" 5 | :build 6 | echo Build start. 7 | cd "%sourceDir%" 8 | conan install -u -s arch="x86_64" -s build_type="Debug" -s compiler="Visual Studio" -s compiler.runtime="MDd" -s compiler.version="12" -o build_develop=True 9 | conan build 10 | cd "%currentDir%" 11 | echo Build done. 12 | pause -------------------------------------------------------------------------------- /Build_VS2013_x64_Release.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set "sourceDir=%~dp0" 3 | set "currentDir=%cd%" 4 | set "scriptDir=%sourceDir%scripts\python" 5 | :build 6 | echo Build start. 7 | cd "%sourceDir%" 8 | conan install -u -s arch="x86_64" -s build_type="Release" -s compiler="Visual Studio" -s compiler.runtime="MD" -s compiler.version="12" -o build_develop=True 9 | conan build 10 | cd "%currentDir%" 11 | echo Build done. 12 | pause -------------------------------------------------------------------------------- /Build_VS2015_Win32_Debug.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set "sourceDir=%~dp0" 3 | set "currentDir=%cd%" 4 | set "scriptDir=%sourceDir%scripts\python" 5 | :build 6 | echo Build start. 7 | cd "%sourceDir%" 8 | conan install -u -s arch="x86" -s build_type="Debug" -s compiler="Visual Studio" -s compiler.runtime="MDd" -s compiler.version="14" -o build_develop=True 9 | conan build 10 | cd "%currentDir%" 11 | echo Build done. 12 | pause -------------------------------------------------------------------------------- /Build_VS2015_Win32_Release.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set "sourceDir=%~dp0" 3 | set "currentDir=%cd%" 4 | set "scriptDir=%sourceDir%scripts\python" 5 | :build 6 | echo Build start. 7 | cd "%sourceDir%" 8 | conan install -u -s arch="x86" -s build_type="Release" -s compiler="Visual Studio" -s compiler.runtime="MD" -s compiler.version="14" -o build_develop=True 9 | conan build 10 | cd "%currentDir%" 11 | echo Build done. 12 | pause -------------------------------------------------------------------------------- /Build_VS2015_x64_Debug.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set "sourceDir=%~dp0" 3 | set "currentDir=%cd%" 4 | set "scriptDir=%sourceDir%scripts\python" 5 | :build 6 | echo Build start. 7 | cd "%sourceDir%" 8 | conan install -u -s arch="x86_64" -s build_type="Debug" -s compiler="Visual Studio" -s compiler.runtime="MDd" -s compiler.version="14" -o build_develop=True 9 | conan build 10 | cd "%currentDir%" 11 | echo Build done. 12 | pause -------------------------------------------------------------------------------- /Build_VS2015_x64_Release.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set "sourceDir=%~dp0" 3 | set "currentDir=%cd%" 4 | set "scriptDir=%sourceDir%scripts\python" 5 | :build 6 | echo Build start. 7 | cd "%sourceDir%" 8 | conan install -u -s arch="x86_64" -s build_type="Release" -s compiler="Visual Studio" -s compiler.runtime="MD" -s compiler.version="14" -o build_develop=True 9 | conan build 10 | cd "%currentDir%" 11 | echo Build done. 12 | pause -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(AlgorithmSDK) 2 | CMAKE_MINIMUM_REQUIRED(VERSION 3.5) 3 | MESSAGE(STATUS "Make AlgorithmSDK start") 4 | SET(CMAKE_SUPPRESS_REGENERATION TRUE) 5 | OPTION(ALGORITHMDLL_PRERELEASE "Build the AlgorithmSDK with pre-release features and APIs." OFF) 6 | IF(ALGORITHMDLL_PRERELEASE) 7 | ADD_DEFINITIONS("-DALGORITHMDLL_PRERELEASE") 8 | ENDIF() 9 | IF(NOT CONAN_BUILD_INFO_LOADED) 10 | INCLUDE(conanbuildinfo.cmake) 11 | # Remove Qt5Ax* lib. For Unit test raised a linking error. 12 | LIST(REMOVE_ITEM CONAN_LIBS Qt5AxBased Qt5AxContainerd Qt5AxServerd Qt5AxBase Qt5AxContainer Qt5AxServer) 13 | CONAN_BASIC_SETUP() 14 | SET(CONAN_BUILD_INFO_LOADED "True") 15 | ENDIF() 16 | IF(NOT LIBRARY_OUTPUT_PATH) 17 | MESSAGE(STATUS "Set LIBRARY_OUTPUT_PATH: ${PROJECT_BINARY_DIR}.") 18 | SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 19 | ENDIF() 20 | IF(NOT EXECUTABLE_OUTPUT_PATH) 21 | MESSAGE(STATUS "Set EXECUTABLE_OUTPUT_PATH: ${PROJECT_BINARY_DIR}") 22 | SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 23 | ENDIF() 24 | SET(ALGORITHM_ROOT_DIR ${PROJECT_SOURCE_DIR}) 25 | SET(ALGORITHM_SRC_DIR ${PROJECT_SOURCE_DIR}/src) 26 | SET(EXTERNAL_ROOT_DIR ${PROJECT_SOURCE_DIR}/external) 27 | SET(HVR_LOGGER_ROOT_DIR ${EXTERNAL_ROOT_DIR}/HVR_Logger) 28 | SET(LIB_ROOT_DIR ${EXTERNAL_ROOT_DIR}/lib) 29 | SET(CameraDriver_ROOT_DIR ${PROJECT_SOURCE_DIR}/CameraDriver) 30 | SET(ImageProcessor_ROOT_DIR ${PROJECT_SOURCE_DIR}/ImageProcessor) 31 | 32 | IF(${CMAKE_VS_PLATFORM_NAME} STREQUAL "Win32") 33 | MESSAGE(STATUS "Build AlgorithmSDK with Win32") 34 | SET(LIB_SOURCE_LIB 35 | debug "setupapi.lib" 36 | optimized "setupapi.lib" 37 | ) 38 | ELSEIF(${CMAKE_VS_PLATFORM_NAME} STREQUAL "x64") 39 | MESSAGE(STATUS "Build AlgorithmSDK with x64") 40 | SET(LIB_SOURCE_LIB 41 | debug "setupapi.lib" 42 | optimized "setupapi.lib" 43 | ) 44 | ELSE() 45 | MESSAGE(FATAL_ERROR "Please build this project with Visual Studio") 46 | ENDIF() 47 | 48 | INCLUDE_DIRECTORIES(${EXTERNAL_ROOT_DIR}/include ${HVR_LOGGER_ROOT_DIR}/include) 49 | ADD_SUBDIRECTORY(src) 50 | MESSAGE(STATUS "Make AlgorithmSDK done") 51 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # AlgorithmSDK 2 | 3 | This project is the core module of tracking. Provided lighthouses' data and IMU data, the module calculates the track object's 6 DOFs as its output. 4 | 5 | ## Requirements 6 | Building this module requires [Conan](https://www.conan.io/) as build system. The project specfies its dependencies and download them via Conan. 7 | 8 | For more information, please refere [Conan's documentation](http://docs.conan.io/en/latest/). 9 | 10 | ### Install Conan 11 | Install _*Python 2.7 64bit*_, and run: 12 | ``` 13 | pip install conan 14 | ``` 15 | -------------------------------------------------------------------------------- /conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake 2 | import os 3 | 4 | 5 | class AlgorithmSDKConan(ConanFile): 6 | name = "AlgorithmSDK" 7 | version = "0.0.1" 8 | settings = {"os": ["Windows"], 9 | "compiler": {"Visual Studio": {"version": ['12', "14"]}}, 10 | "arch": ['x86', 'x86_64'], 11 | "build_type": ['Release', 'Debug']} 12 | requires = ( 13 | "CommonUtils/0.0.1@oslh/stable", 14 | "gtest/1.8.0@lasote/stable", 15 | "HVRLogger/0.1.5.0@oslh/stable", 16 | "OpenCV/3.1.0@oslh/stable", 17 | "VRTrackDevHAL/0.0.1@oslh/stable", 18 | "Clapack/0.0.1@oslh/stable", 19 | ) 20 | generators = "cmake" 21 | exports = "CMakeLists.txt" 22 | options = {"build_develop": [True, False], "algorithmdll_prerelease": [True, False]} 23 | default_options = "build_develop=False", "algorithmdll_prerelease=True" 24 | 25 | def config_options(self): 26 | pass 27 | 28 | def build(self): 29 | version = "vs2013" if self.settings.compiler['Visual Studio'].version == 12 else "vs2015" 30 | target_directory = os.sep.join(["_build", version, str(self.settings.arch), str(self.settings.build_type), ]) 31 | if self.settings.os == "Windows": 32 | self.run("IF not exist " + target_directory + " mkdir " + target_directory) 33 | cmake = CMake(self.settings) 34 | 35 | build_develop = "-DBUILD_DEVELOP=" + ("ON" if self.options.build_develop else "OFF") 36 | prerelease = "-DALGORITHMDLL_PRERELEASE=" + ("ON " if self.options.algorithmdll_prerelease else "OFF") 37 | cmake_flags = "%s %s" % (build_develop, prerelease) 38 | cd_build = "cd " + target_directory 39 | self.run( 40 | '%s && cmake %s %s %s' % (cd_build, cmake.command_line, os.sep.join(["..", "..", "..", "..", ]), cmake_flags)) 41 | self.run("%s && cmake --build . %s -- /maxcpucount" % (cd_build, cmake.build_config)) 42 | 43 | def imports(self): 44 | version = "vs2013" if self.settings.compiler['Visual Studio'].version == 12 else "vs2015" 45 | target_directory = os.sep.join(["_build", version, str(self.settings.arch), str(self.settings.build_type), ]) 46 | self.copy(pattern="*.dll", dst=os.sep.join([target_directory, "bin", ]), src="bin") # From bin to bin 47 | self.copy(pattern="*.*", dst=os.sep.join([target_directory, "bin/platforms", ]), 48 | src="plugins/platforms") # From plugins/platforms 49 | self.copy(pattern="*.dylib*", dst=os.sep.join([target_directory, "bin", ]), src="lib") # From lib to bin 50 | 51 | def package(self): 52 | self.copy(pattern="*.hpp", dst="include", src="AlgorithmSDK/include", keep_path=True) 53 | self.copy(pattern="*.hpp", dst="include", src=".", keep_path=False) 54 | self.copy(pattern="*.h", dst="include", src="AlgorithmSDK/include", keep_path=True) 55 | self.copy(pattern="*.h", dst="include", src=".", keep_path=False) 56 | self.copy(pattern="*.lib", dst="lib", src=".", keep_path=False) 57 | self.copy(pattern="*.dll", dst="bin", src=".", keep_path=False) 58 | self.copy(pattern="*.so*", dst="lib", src=".", keep_path=False) 59 | self.copy(pattern="*.dylib*", dst="lib", src=".", keep_path=False) 60 | 61 | def package_info(self): 62 | self.cpp_info.libs = ["algorithmSDK"] 63 | -------------------------------------------------------------------------------- /copyright.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/copyright.txt -------------------------------------------------------------------------------- /external/Irrlicht-math/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 laohyx 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 | 23 | 24 | The Irrlicht Engine License 25 | =========================== 26 | 27 | Copyright (C) 2002-2012 Nikolaus Gebhardt 28 | 29 | This software is provided 'as-is', without any express or implied 30 | warranty. In no event will the authors be held liable for any damages 31 | arising from the use of this software. 32 | 33 | Permission is granted to anyone to use this software for any purpose, 34 | including commercial applications, and to alter it and redistribute it 35 | freely, subject to the following restrictions: 36 | 37 | 1. The origin of this software must not be misrepresented; you must not 38 | claim that you wrote the original software. If you use this software 39 | in a product, an acknowledgement in the product documentation would be 40 | appreciated but is not required. 41 | 2. Altered source versions must be clearly marked as such, and must not be 42 | misrepresented as being the original software. 43 | 3. This notice may not be removed or altered from any source distribution. 44 | 45 | -------------------------------------------------------------------------------- /external/Irrlicht-math/README.md: -------------------------------------------------------------------------------- 1 | # Irrlicht-math 2 | Math library of Irrlicht Engine. 3 | 4 | This library exported [Irrlicht Engine](http://irrlicht.sourceforge.net/)'s math libraries, e.g. quaternion, vector and matrix. 5 | 6 | And changed some types to align with personal style. 7 | 8 | The copyright of original code belongs to `Irrlicht Engine`'s author, Nikolaus Gebhardt. 9 | 10 | Thanks to Nikolaus Gebhardt, giving us such a wonderful tool! 11 | 12 | 13 | > The Irrlicht Engine License 14 | > =========================== 15 | > 16 | > Copyright (C) 2002-2012 Nikolaus Gebhardt 17 | > 18 | > This software is provided 'as-is', without any express or implied 19 | > warranty. In no event will the authors be held liable for any damages 20 | > arising from the use of this software. 21 | > 22 | > Permission is granted to anyone to use this software for any purpose, 23 | > including commercial applications, and to alter it and redistribute it 24 | > freely, subject to the following restrictions: 25 | > 26 | > 1. The origin of this software must not be misrepresented; you must not 27 | > claim that you wrote the original software. If you use this software 28 | > in a product, an acknowledgement in the product documentation would be 29 | > appreciated but is not required. 30 | > 2. Altered source versions must be clearly marked as such, and must not be 31 | > misrepresented as being the original software. 32 | > 3. This notice may not be removed or altered from any source distribution. 33 | 34 | -------------------------------------------------------------------------------- /external/Irrlicht-math/include/IrrCompileConfig.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt 2 | // This file is part of the "Irrlicht Engine". 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h 4 | 5 | #ifndef __IRR_COMPILE_CONFIG_H_INCLUDED__ 6 | #define __IRR_COMPILE_CONFIG_H_INCLUDED__ 7 | 8 | //! Irrlicht SDK Version 9 | #define IRRLICHT_VERSION_MAJOR 1 10 | #define IRRLICHT_VERSION_MINOR 8 11 | #define IRRLICHT_VERSION_REVISION 4 12 | // This flag will be defined only in SVN, the official release code will have 13 | // it undefined 14 | //#define IRRLICHT_VERSION_SVN -alpha 15 | #define IRRLICHT_SDK_VERSION "1.8.4" 16 | 17 | #include // TODO: Although included elsewhere this is required at least for mingw 18 | 19 | //! The defines for different operating system are: 20 | //! _IRR_XBOX_PLATFORM_ for XBox 21 | //! _IRR_WINDOWS_ for all irrlicht supported Windows versions 22 | //! _IRR_WINDOWS_CE_PLATFORM_ for Windows CE 23 | //! _IRR_WINDOWS_API_ for Windows or XBox 24 | //! _IRR_LINUX_PLATFORM_ for Linux (it is defined here if no other os is defined) 25 | //! _IRR_SOLARIS_PLATFORM_ for Solaris 26 | //! _IRR_OSX_PLATFORM_ for Apple systems running OSX 27 | //! _IRR_POSIX_API_ for Posix compatible systems 28 | //! Note: PLATFORM defines the OS specific layer, API can group several platforms 29 | 30 | //! DEVICE is the windowing system used, several PLATFORMs support more than one DEVICE 31 | //! Irrlicht can be compiled with more than one device 32 | //! _IRR_COMPILE_WITH_WINDOWS_DEVICE_ for Windows API based device 33 | //! _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ for Windows CE API based device 34 | //! _IRR_COMPILE_WITH_OSX_DEVICE_ for Cocoa native windowing on OSX 35 | //! _IRR_COMPILE_WITH_X11_DEVICE_ for Linux X11 based device 36 | //! _IRR_COMPILE_WITH_SDL_DEVICE_ for platform independent SDL framework 37 | //! _IRR_COMPILE_WITH_CONSOLE_DEVICE_ for no windowing system, used as a fallback 38 | //! _IRR_COMPILE_WITH_FB_DEVICE_ for framebuffer systems 39 | 40 | //! Passing defines to the compiler which have NO in front of the _IRR definename is an alternative 41 | //! way which can be used to disable defines (instead of outcommenting them in this header). 42 | //! So defines can be controlled from Makefiles or Projectfiles which allows building 43 | //! different library versions without having to change the sources. 44 | //! Example: NO_IRR_COMPILE_WITH_X11_ would disable X11 45 | 46 | 47 | //! Uncomment this line to compile with the SDL device 48 | //#define _IRR_COMPILE_WITH_SDL_DEVICE_ 49 | #ifdef NO_IRR_COMPILE_WITH_SDL_DEVICE_ 50 | #undef _IRR_COMPILE_WITH_SDL_DEVICE_ 51 | #endif 52 | 53 | //! Comment this line to compile without the fallback console device. 54 | #define _IRR_COMPILE_WITH_CONSOLE_DEVICE_ 55 | #ifdef NO_IRR_COMPILE_WITH_CONSOLE_DEVICE_ 56 | #undef _IRR_COMPILE_WITH_CONSOLE_DEVICE_ 57 | #endif 58 | 59 | //! WIN32 for Windows32 60 | //! WIN64 for Windows64 61 | // The windows platform and API support SDL and WINDOW device 62 | #if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64) 63 | #define _IRR_WINDOWS_ 64 | #define _IRR_WINDOWS_API_ 65 | #define _IRR_COMPILE_WITH_WINDOWS_DEVICE_ 66 | #endif 67 | 68 | //! WINCE is a very restricted environment for mobile devices 69 | #if defined(_WIN32_WCE) 70 | #define _IRR_WINDOWS_ 71 | #define _IRR_WINDOWS_API_ 72 | #define _IRR_WINDOWS_CE_PLATFORM_ 73 | #define _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ 74 | #endif 75 | 76 | #if defined(_MSC_VER) && (_MSC_VER < 1300) 77 | # error "Only Microsoft Visual Studio 7.0 and later are supported." 78 | #endif 79 | 80 | // XBox only suppots the native Window stuff 81 | #if defined(_XBOX) 82 | #undef _IRR_WINDOWS_ 83 | #define _IRR_XBOX_PLATFORM_ 84 | #define _IRR_WINDOWS_API_ 85 | //#define _IRR_COMPILE_WITH_WINDOWS_DEVICE_ 86 | #undef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ 87 | //#define _IRR_COMPILE_WITH_SDL_DEVICE_ 88 | 89 | #include 90 | #endif 91 | 92 | #if defined(__APPLE__) || defined(MACOSX) 93 | #if !defined(MACOSX) 94 | #define MACOSX // legacy support 95 | #endif 96 | #define _IRR_OSX_PLATFORM_ 97 | #define _IRR_COMPILE_WITH_OSX_DEVICE_ 98 | #endif 99 | 100 | #if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_) 101 | #ifndef _IRR_SOLARIS_PLATFORM_ 102 | #define _IRR_LINUX_PLATFORM_ 103 | #endif 104 | #define _IRR_POSIX_API_ 105 | #define _IRR_COMPILE_WITH_X11_DEVICE_ 106 | #endif 107 | 108 | 109 | //! Define _IRR_COMPILE_WITH_JOYSTICK_SUPPORT_ if you want joystick events. 110 | #define _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ 111 | #ifdef NO_IRR_COMPILE_WITH_JOYSTICK_EVENTS_ 112 | #undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ 113 | #endif 114 | 115 | 116 | //! Maximum number of texture an SMaterial can have, up to 8 are supported by Irrlicht. 117 | #define _IRR_MATERIAL_MAX_TEXTURES_ 4 118 | 119 | //! Define _IRR_COMPILE_WITH_DIRECT3D_8_ and _IRR_COMPILE_WITH_DIRECT3D_9_ to 120 | //! compile the Irrlicht engine with Direct3D8 and/or DIRECT3D9. 121 | /** If you only want to use the software device or opengl you can disable those defines. 122 | This switch is mostly disabled because people do not get the g++ compiler compile 123 | directX header files, and directX is only available on Windows platforms. If you 124 | are using Dev-Cpp, and want to compile this using a DX dev pack, you can define 125 | _IRR_COMPILE_WITH_DX9_DEV_PACK_. So you simply need to add something like this 126 | to the compiler settings: -DIRR_COMPILE_WITH_DX9_DEV_PACK 127 | and this to the linker settings: -ld3dx9 -ld3dx8 128 | 129 | Microsoft have chosen to remove D3D8 headers from their recent DXSDKs, and 130 | so D3D8 support is now disabled by default. If you really want to build 131 | with D3D8 support, then you will have to source a DXSDK with the appropriate 132 | headers, e.g. Summer 2004. This is a Microsoft issue, not an Irrlicht one. 133 | */ 134 | #if defined(_IRR_WINDOWS_API_) && (!defined(__GNUC__) || defined(IRR_COMPILE_WITH_DX9_DEV_PACK)) 135 | 136 | //! Define _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ if you want to use DirectInput for joystick handling. 137 | /** This only applies to Windows devices, currently only supported under Win32 device. 138 | If not defined, Windows Multimedia library is used, which offers also broad support for joystick devices. */ 139 | #define _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ 140 | #ifdef NO_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ 141 | #undef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ 142 | #endif 143 | // can't get this to compile currently under borland, can be removed if someone has a better solution 144 | #if defined(__BORLANDC__) 145 | #undef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ 146 | #endif 147 | 148 | //! Only define _IRR_COMPILE_WITH_DIRECT3D_8_ if you have an appropriate DXSDK, e.g. Summer 2004 149 | // #define _IRR_COMPILE_WITH_DIRECT3D_8_ 150 | #define _IRR_COMPILE_WITH_DIRECT3D_9_ 151 | 152 | #ifdef NO_IRR_COMPILE_WITH_DIRECT3D_8_ 153 | #undef _IRR_COMPILE_WITH_DIRECT3D_8_ 154 | #endif 155 | #ifdef NO_IRR_COMPILE_WITH_DIRECT3D_9_ 156 | #undef _IRR_COMPILE_WITH_DIRECT3D_9_ 157 | #endif 158 | 159 | #endif 160 | 161 | //! Define _IRR_COMPILE_WITH_OPENGL_ to compile the Irrlicht engine with OpenGL. 162 | /** If you do not wish the engine to be compiled with OpenGL, comment this 163 | define out. */ 164 | #define _IRR_COMPILE_WITH_OPENGL_ 165 | #ifdef NO_IRR_COMPILE_WITH_OPENGL_ 166 | #undef _IRR_COMPILE_WITH_OPENGL_ 167 | #endif 168 | 169 | //! Define _IRR_COMPILE_WITH_SOFTWARE_ to compile the Irrlicht engine with software driver 170 | /** If you do not need the software driver, or want to use Burning's Video instead, 171 | comment this define out */ 172 | #define _IRR_COMPILE_WITH_SOFTWARE_ 173 | #ifdef NO_IRR_COMPILE_WITH_SOFTWARE_ 174 | #undef _IRR_COMPILE_WITH_SOFTWARE_ 175 | #endif 176 | 177 | //! Define _IRR_COMPILE_WITH_BURNINGSVIDEO_ to compile the Irrlicht engine with Burning's video driver 178 | /** If you do not need this software driver, you can comment this define out. */ 179 | #define _IRR_COMPILE_WITH_BURNINGSVIDEO_ 180 | #ifdef NO_IRR_COMPILE_WITH_BURNINGSVIDEO_ 181 | #undef _IRR_COMPILE_WITH_BURNINGSVIDEO_ 182 | #endif 183 | 184 | //! Define _IRR_COMPILE_WITH_X11_ to compile the Irrlicht engine with X11 support. 185 | /** If you do not wish the engine to be compiled with X11, comment this 186 | define out. */ 187 | // Only used in LinuxDevice. 188 | #define _IRR_COMPILE_WITH_X11_ 189 | #ifdef NO_IRR_COMPILE_WITH_X11_ 190 | #undef _IRR_COMPILE_WITH_X11_ 191 | #endif 192 | 193 | //! Define _IRR_OPENGL_USE_EXTPOINTER_ if the OpenGL renderer should use OpenGL extensions via function pointers. 194 | /** On some systems there is no support for the dynamic extension of OpenGL 195 | via function pointers such that this has to be undef'ed. */ 196 | #if !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_SOLARIS_PLATFORM_) 197 | #define _IRR_OPENGL_USE_EXTPOINTER_ 198 | #endif 199 | 200 | //! On some Linux systems the XF86 vidmode extension or X11 RandR are missing. Use these flags 201 | //! to remove the dependencies such that Irrlicht will compile on those systems, too. 202 | //! If you don't need colored cursors you can also disable the Xcursor extension 203 | #if defined(_IRR_LINUX_PLATFORM_) && defined(_IRR_COMPILE_WITH_X11_) 204 | #define _IRR_LINUX_X11_VIDMODE_ 205 | //#define _IRR_LINUX_X11_RANDR_ 206 | #ifdef NO_IRR_LINUX_X11_VIDMODE_ 207 | #undef _IRR_LINUX_X11_VIDMODE_ 208 | #endif 209 | #ifdef NO_IRR_LINUX_X11_RANDR_ 210 | #undef _IRR_LINUX_X11_RANDR_ 211 | #endif 212 | 213 | //! X11 has by default only monochrome cursors, but using the Xcursor library we can also get color cursor support. 214 | //! If you have the need for custom color cursors on X11 then enable this and make sure you also link 215 | //! to the Xcursor library in your Makefile/Projectfile. 216 | //#define _IRR_LINUX_XCURSOR_ 217 | #ifdef NO_IRR_LINUX_XCURSOR_ 218 | #undef _IRR_LINUX_XCURSOR_ 219 | #endif 220 | 221 | #endif 222 | 223 | //! Define _IRR_COMPILE_WITH_GUI_ to compile the engine with the built-in GUI 224 | /** Disable this if you are using an external library to draw the GUI. If you disable this then 225 | you will not be able to use anything provided by the GUI Environment, including loading fonts. */ 226 | #define _IRR_COMPILE_WITH_GUI_ 227 | #ifdef NO_IRR_COMPILE_WITH_GUI_ 228 | #undef _IRR_COMPILE_WITH_GUI_ 229 | #endif 230 | 231 | //! Define _IRR_WCHAR_FILESYSTEM to enable unicode filesystem support for the engine. 232 | /** This enables the engine to read/write from unicode filesystem. If you 233 | disable this feature, the engine behave as before (ansi). This is currently only supported 234 | for Windows based systems. You also have to set #define UNICODE for this to compile. 235 | */ 236 | //#define _IRR_WCHAR_FILESYSTEM 237 | #ifdef NO_IRR_WCHAR_FILESYSTEM 238 | #undef _IRR_WCHAR_FILESYSTEM 239 | #endif 240 | 241 | //! Define _IRR_COMPILE_WITH_JPEGLIB_ to enable compiling the engine using libjpeg. 242 | /** This enables the engine to read jpeg images. If you comment this out, 243 | the engine will no longer read .jpeg images. */ 244 | #define _IRR_COMPILE_WITH_LIBJPEG_ 245 | #ifdef NO_IRR_COMPILE_WITH_LIBJPEG_ 246 | #undef _IRR_COMPILE_WITH_LIBJPEG_ 247 | #endif 248 | 249 | //! Define _IRR_USE_NON_SYSTEM_JPEG_LIB_ to let irrlicht use the jpeglib which comes with irrlicht. 250 | /** If this is commented out, Irrlicht will try to compile using the jpeg lib installed in the system. 251 | This is only used when _IRR_COMPILE_WITH_LIBJPEG_ is defined. */ 252 | #define _IRR_USE_NON_SYSTEM_JPEG_LIB_ 253 | #ifdef NO_IRR_USE_NON_SYSTEM_JPEG_LIB_ 254 | #undef _IRR_USE_NON_SYSTEM_JPEG_LIB_ 255 | #endif 256 | 257 | //! Define _IRR_COMPILE_WITH_LIBPNG_ to enable compiling the engine using libpng. 258 | /** This enables the engine to read png images. If you comment this out, 259 | the engine will no longer read .png images. */ 260 | #define _IRR_COMPILE_WITH_LIBPNG_ 261 | #ifdef NO_IRR_COMPILE_WITH_LIBPNG_ 262 | #undef _IRR_COMPILE_WITH_LIBPNG_ 263 | #endif 264 | 265 | //! Define _IRR_USE_NON_SYSTEM_LIBPNG_ to let irrlicht use the libpng which comes with irrlicht. 266 | /** If this is commented out, Irrlicht will try to compile using the libpng installed in the system. 267 | This is only used when _IRR_COMPILE_WITH_LIBPNG_ is defined. */ 268 | #define _IRR_USE_NON_SYSTEM_LIB_PNG_ 269 | #ifdef NO_IRR_USE_NON_SYSTEM_LIB_PNG_ 270 | #undef _IRR_USE_NON_SYSTEM_LIB_PNG_ 271 | #endif 272 | 273 | //! Define _IRR_D3D_NO_SHADER_DEBUGGING to disable shader debugging in D3D9 274 | /** If _IRR_D3D_NO_SHADER_DEBUGGING is undefined in IrrCompileConfig.h, 275 | it is possible to debug all D3D9 shaders in VisualStudio. All shaders 276 | (which have been generated in memory or read from archives for example) will be emitted 277 | into a temporary file at runtime for this purpose. To debug your shaders, choose 278 | Debug->Direct3D->StartWithDirect3DDebugging in Visual Studio, and for every shader a 279 | file named 'irr_dbg_shader_%%.vsh' or 'irr_dbg_shader_%%.psh' will be created. Drag'n'drop 280 | the file you want to debug into visual studio. That's it. You can now set breakpoints and 281 | watch registers, variables etc. This works with ASM, HLSL, and both with pixel and vertex shaders. 282 | Note that the engine will run in D3D REF for this, which is a lot slower than HAL. */ 283 | #define _IRR_D3D_NO_SHADER_DEBUGGING 284 | #ifdef NO_IRR_D3D_NO_SHADER_DEBUGGING 285 | #undef _IRR_D3D_NO_SHADER_DEBUGGING 286 | #endif 287 | 288 | //! Define _IRR_D3D_USE_LEGACY_HLSL_COMPILER to enable the old HLSL compiler in recent DX SDKs 289 | /** This enables support for ps_1_x shaders for recent DX SDKs. Otherwise, support 290 | for this shader model is not available anymore in SDKs after Oct2006. You need to 291 | distribute the OCT2006_d3dx9_31_x86.cab or OCT2006_d3dx9_31_x64.cab though, in order 292 | to provide the user with the proper DLL. That's why it's disabled by default. */ 293 | //#define _IRR_D3D_USE_LEGACY_HLSL_COMPILER 294 | #ifdef NO_IRR_D3D_USE_LEGACY_HLSL_COMPILER 295 | #undef _IRR_D3D_USE_LEGACY_HLSL_COMPILER 296 | #endif 297 | 298 | //! Define _IRR_COMPILE_WITH_CG_ to enable Cg Shading Language support 299 | //#define _IRR_COMPILE_WITH_CG_ 300 | #ifdef NO_IRR_COMPILE_WITH_CG_ 301 | #undef _IRR_COMPILE_WITH_CG_ 302 | #endif 303 | #if !defined(_IRR_COMPILE_WITH_OPENGL_) && !defined(_IRR_COMPILE_WITH_DIRECT3D_9_) 304 | #undef _IRR_COMPILE_WITH_CG_ 305 | #endif 306 | 307 | //! Define _IRR_USE_NVIDIA_PERFHUD_ to opt-in to using the nVidia PerHUD tool 308 | /** Enable, by opting-in, to use the nVidia PerfHUD performance analysis driver 309 | tool . */ 310 | #undef _IRR_USE_NVIDIA_PERFHUD_ 311 | 312 | //! Define one of the three setting for Burning's Video Software Rasterizer 313 | /** So if we were marketing guys we could say Irrlicht has 4 Software-Rasterizers. 314 | In a Nutshell: 315 | All Burnings Rasterizers use 32 Bit Backbuffer, 32Bit Texture & 32 Bit Z or WBuffer, 316 | 16 Bit/32 Bit can be adjusted on a global flag. 317 | 318 | BURNINGVIDEO_RENDERER_BEAUTIFUL 319 | 32 Bit + Vertexcolor + Lighting + Per Pixel Perspective Correct + SubPixel/SubTexel Correct + 320 | Bilinear Texturefiltering + WBuffer 321 | 322 | BURNINGVIDEO_RENDERER_FAST 323 | 32 Bit + Per Pixel Perspective Correct + SubPixel/SubTexel Correct + WBuffer + 324 | Bilinear Dithering TextureFiltering + WBuffer 325 | 326 | BURNINGVIDEO_RENDERER_ULTRA_FAST 327 | 16Bit + SubPixel/SubTexel Correct + ZBuffer 328 | */ 329 | 330 | #define BURNINGVIDEO_RENDERER_BEAUTIFUL 331 | //#define BURNINGVIDEO_RENDERER_FAST 332 | //#define BURNINGVIDEO_RENDERER_ULTRA_FAST 333 | //#define BURNINGVIDEO_RENDERER_CE 334 | 335 | //! Uncomment the following line if you want to ignore the deprecated warnings 336 | //#define IGNORE_DEPRECATED_WARNING 337 | 338 | //! Define _IRR_COMPILE_WITH_IRR_SCENE_LOADER_ if you want to be able to load 339 | /** .irr scenes using ISceneManager::loadScene */ 340 | #define _IRR_COMPILE_WITH_IRR_SCENE_LOADER_ 341 | #ifdef NO_IRR_COMPILE_WITH_IRR_SCENE_LOADER_ 342 | #undef _IRR_COMPILE_WITH_IRR_SCENE_LOADER_ 343 | #endif 344 | 345 | //! Define _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ if you want to use bone based 346 | /** animated meshes. If you compile without this, you will be unable to load 347 | B3D, MS3D or X meshes */ 348 | #define _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ 349 | #ifdef NO_IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ 350 | #undef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ 351 | #endif 352 | 353 | #ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ 354 | //! Define _IRR_COMPILE_WITH_B3D_LOADER_ if you want to use Blitz3D files 355 | #define _IRR_COMPILE_WITH_B3D_LOADER_ 356 | #ifdef NO_IRR_COMPILE_WITH_B3D_LOADER_ 357 | #undef _IRR_COMPILE_WITH_B3D_LOADER_ 358 | #endif 359 | //! Define _IRR_COMPILE_WITH_MS3D_LOADER_ if you want to Milkshape files 360 | #define _IRR_COMPILE_WITH_MS3D_LOADER_ 361 | #ifdef NO_IRR_COMPILE_WITH_MS3D_LOADER_ 362 | #undef _IRR_COMPILE_WITH_MS3D_LOADER_ 363 | #endif 364 | //! Define _IRR_COMPILE_WITH_X_LOADER_ if you want to use Microsoft X files 365 | #define _IRR_COMPILE_WITH_X_LOADER_ 366 | #ifdef NO_IRR_COMPILE_WITH_X_LOADER_ 367 | #undef _IRR_COMPILE_WITH_X_LOADER_ 368 | #endif 369 | //! Define _IRR_COMPILE_WITH_OGRE_LOADER_ if you want to load Ogre 3D files 370 | #define _IRR_COMPILE_WITH_OGRE_LOADER_ 371 | #ifdef NO_IRR_COMPILE_WITH_OGRE_LOADER_ 372 | #undef _IRR_COMPILE_WITH_OGRE_LOADER_ 373 | #endif 374 | #endif // _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ 375 | 376 | //! Define _IRR_COMPILE_WITH_IRR_MESH_LOADER_ if you want to load Irrlicht Engine .irrmesh files 377 | #define _IRR_COMPILE_WITH_IRR_MESH_LOADER_ 378 | #ifdef NO_IRR_COMPILE_WITH_IRR_MESH_LOADER_ 379 | #undef _IRR_COMPILE_WITH_IRR_MESH_LOADER_ 380 | #endif 381 | //! Define _IRR_COMPILE_WITH_HALFLIFE_LOADER_ if you want to load Halflife animated files 382 | #define _IRR_COMPILE_WITH_HALFLIFE_LOADER_ 383 | #ifdef NO_IRR_COMPILE_WITH_HALFLIFE_LOADER_ 384 | #undef _IRR_COMPILE_WITH_HALFLIFE_LOADER_ 385 | #endif 386 | //! Define _IRR_COMPILE_WITH_MD2_LOADER_ if you want to load Quake 2 animated files 387 | #define _IRR_COMPILE_WITH_MD2_LOADER_ 388 | #ifdef NO_IRR_COMPILE_WITH_MD2_LOADER_ 389 | #undef _IRR_COMPILE_WITH_MD2_LOADER_ 390 | #endif 391 | //! Define _IRR_COMPILE_WITH_MD3_LOADER_ if you want to load Quake 3 animated files 392 | #define _IRR_COMPILE_WITH_MD3_LOADER_ 393 | #ifdef NO_IRR_COMPILE_WITH_MD3_LOADER_ 394 | #undef _IRR_COMPILE_WITH_MD3_LOADER_ 395 | #endif 396 | //! Define _IRR_COMPILE_WITH_3DS_LOADER_ if you want to load 3D Studio Max files 397 | #define _IRR_COMPILE_WITH_3DS_LOADER_ 398 | #ifdef NO_IRR_COMPILE_WITH_3DS_LOADER_ 399 | #undef _IRR_COMPILE_WITH_3DS_LOADER_ 400 | #endif 401 | //! Define _IRR_COMPILE_WITH_COLLADA_LOADER_ if you want to load Collada files 402 | #define _IRR_COMPILE_WITH_COLLADA_LOADER_ 403 | #ifdef NO_IRR_COMPILE_WITH_COLLADA_LOADER_ 404 | #undef _IRR_COMPILE_WITH_COLLADA_LOADER_ 405 | #endif 406 | //! Define _IRR_COMPILE_WITH_CSM_LOADER_ if you want to load Cartography Shop files 407 | #define _IRR_COMPILE_WITH_CSM_LOADER_ 408 | #ifdef NO_IRR_COMPILE_WITH_CSM_LOADER_ 409 | #undef _IRR_COMPILE_WITH_CSM_LOADER_ 410 | #endif 411 | //! Define _IRR_COMPILE_WITH_BSP_LOADER_ if you want to load Quake 3 BSP files 412 | #define _IRR_COMPILE_WITH_BSP_LOADER_ 413 | #ifdef NO_IRR_COMPILE_WITH_BSP_LOADER_ 414 | #undef _IRR_COMPILE_WITH_BSP_LOADER_ 415 | #endif 416 | //! Define _IRR_COMPILE_WITH_DMF_LOADER_ if you want to load DeleD files 417 | #define _IRR_COMPILE_WITH_DMF_LOADER_ 418 | #ifdef NO_IRR_COMPILE_WITH_DMF_LOADER_ 419 | #undef _IRR_COMPILE_WITH_DMF_LOADER_ 420 | #endif 421 | //! Define _IRR_COMPILE_WITH_LMTS_LOADER_ if you want to load LMTools files 422 | #define _IRR_COMPILE_WITH_LMTS_LOADER_ 423 | #ifdef NO_IRR_COMPILE_WITH_LMTS_LOADER_ 424 | #undef _IRR_COMPILE_WITH_LMTS_LOADER_ 425 | #endif 426 | //! Define _IRR_COMPILE_WITH_MY3D_LOADER_ if you want to load MY3D files 427 | #define _IRR_COMPILE_WITH_MY3D_LOADER_ 428 | #ifdef NO_IRR_COMPILE_WITH_MY3D_LOADER_ 429 | #undef _IRR_COMPILE_WITH_MY3D_LOADER_ 430 | #endif 431 | //! Define _IRR_COMPILE_WITH_OBJ_LOADER_ if you want to load Wavefront OBJ files 432 | #define _IRR_COMPILE_WITH_OBJ_LOADER_ 433 | #ifdef NO_IRR_COMPILE_WITH_OBJ_LOADER_ 434 | #undef _IRR_COMPILE_WITH_OBJ_LOADER_ 435 | #endif 436 | //! Define _IRR_COMPILE_WITH_OCT_LOADER_ if you want to load FSRad OCT files 437 | #define _IRR_COMPILE_WITH_OCT_LOADER_ 438 | #ifdef NO_IRR_COMPILE_WITH_OCT_LOADER_ 439 | #undef _IRR_COMPILE_WITH_OCT_LOADER_ 440 | #endif 441 | //! Define _IRR_COMPILE_WITH_LWO_LOADER_ if you want to load Lightwave3D files 442 | #define _IRR_COMPILE_WITH_LWO_LOADER_ 443 | #ifdef NO_IRR_COMPILE_WITH_LWO_LOADER_ 444 | #undef _IRR_COMPILE_WITH_LWO_LOADER_ 445 | #endif 446 | //! Define _IRR_COMPILE_WITH_STL_LOADER_ if you want to load stereolithography files 447 | #define _IRR_COMPILE_WITH_STL_LOADER_ 448 | #ifdef NO_IRR_COMPILE_WITH_STL_LOADER_ 449 | #undef _IRR_COMPILE_WITH_STL_LOADER_ 450 | #endif 451 | //! Define _IRR_COMPILE_WITH_PLY_LOADER_ if you want to load Polygon (Stanford Triangle) files 452 | #define _IRR_COMPILE_WITH_PLY_LOADER_ 453 | #ifdef NO_IRR_COMPILE_WITH_PLY_LOADER_ 454 | #undef _IRR_COMPILE_WITH_PLY_LOADER_ 455 | #endif 456 | //! Define _IRR_COMPILE_WITH_SMF_LOADER_ if you want to load 3D World Studio mesh files 457 | #define _IRR_COMPILE_WITH_SMF_LOADER_ 458 | #ifdef NO_IRR_COMPILE_WITH_SMF_LOADER_ 459 | #undef _IRR_COMPILE_WITH_SMF_LOADER_ 460 | #endif 461 | 462 | //! Define _IRR_COMPILE_WITH_IRR_WRITER_ if you want to write static .irrMesh files 463 | #define _IRR_COMPILE_WITH_IRR_WRITER_ 464 | #ifdef NO_IRR_COMPILE_WITH_IRR_WRITER_ 465 | #undef _IRR_COMPILE_WITH_IRR_WRITER_ 466 | #endif 467 | //! Define _IRR_COMPILE_WITH_COLLADA_WRITER_ if you want to write Collada files 468 | #define _IRR_COMPILE_WITH_COLLADA_WRITER_ 469 | #ifdef NO_IRR_COMPILE_WITH_COLLADA_WRITER_ 470 | #undef _IRR_COMPILE_WITH_COLLADA_WRITER_ 471 | #endif 472 | //! Define _IRR_COMPILE_WITH_STL_WRITER_ if you want to write .stl files 473 | #define _IRR_COMPILE_WITH_STL_WRITER_ 474 | #ifdef NO_IRR_COMPILE_WITH_STL_WRITER_ 475 | #undef _IRR_COMPILE_WITH_STL_WRITER_ 476 | #endif 477 | //! Define _IRR_COMPILE_WITH_OBJ_WRITER_ if you want to write .obj files 478 | #define _IRR_COMPILE_WITH_OBJ_WRITER_ 479 | #ifdef NO_IRR_COMPILE_WITH_OBJ_WRITER_ 480 | #undef _IRR_COMPILE_WITH_OBJ_WRITER_ 481 | #endif 482 | //! Define _IRR_COMPILE_WITH_PLY_WRITER_ if you want to write .ply files 483 | #define _IRR_COMPILE_WITH_PLY_WRITER_ 484 | #ifdef NO_IRR_COMPILE_WITH_PLY_WRITER_ 485 | #undef _IRR_COMPILE_WITH_PLY_WRITER_ 486 | #endif 487 | 488 | //! Define _IRR_COMPILE_WITH_BMP_LOADER_ if you want to load .bmp files 489 | //! Disabling this loader will also disable the built-in font 490 | #define _IRR_COMPILE_WITH_BMP_LOADER_ 491 | #ifdef NO_IRR_COMPILE_WITH_BMP_LOADER_ 492 | #undef _IRR_COMPILE_WITH_BMP_LOADER_ 493 | #endif 494 | //! Define _IRR_COMPILE_WITH_JPG_LOADER_ if you want to load .jpg files 495 | #define _IRR_COMPILE_WITH_JPG_LOADER_ 496 | #ifdef NO_IRR_COMPILE_WITH_JPG_LOADER_ 497 | #undef _IRR_COMPILE_WITH_JPG_LOADER_ 498 | #endif 499 | //! Define _IRR_COMPILE_WITH_PCX_LOADER_ if you want to load .pcx files 500 | #define _IRR_COMPILE_WITH_PCX_LOADER_ 501 | #ifdef NO_IRR_COMPILE_WITH_PCX_LOADER_ 502 | #undef _IRR_COMPILE_WITH_PCX_LOADER_ 503 | #endif 504 | //! Define _IRR_COMPILE_WITH_PNG_LOADER_ if you want to load .png files 505 | #define _IRR_COMPILE_WITH_PNG_LOADER_ 506 | #ifdef NO_IRR_COMPILE_WITH_PNG_LOADER_ 507 | #undef _IRR_COMPILE_WITH_PNG_LOADER_ 508 | #endif 509 | //! Define _IRR_COMPILE_WITH_PPM_LOADER_ if you want to load .ppm/.pgm/.pbm files 510 | #define _IRR_COMPILE_WITH_PPM_LOADER_ 511 | #ifdef NO_IRR_COMPILE_WITH_PPM_LOADER_ 512 | #undef _IRR_COMPILE_WITH_PPM_LOADER_ 513 | #endif 514 | //! Define _IRR_COMPILE_WITH_PSD_LOADER_ if you want to load .psd files 515 | #define _IRR_COMPILE_WITH_PSD_LOADER_ 516 | #ifdef NO_IRR_COMPILE_WITH_PSD_LOADER_ 517 | #undef _IRR_COMPILE_WITH_PSD_LOADER_ 518 | #endif 519 | //! Define _IRR_COMPILE_WITH_DDS_LOADER_ if you want to load .dds files 520 | // Outcommented because 521 | // a) it doesn't compile on 64-bit currently 522 | // b) anyone enabling it should be aware that S3TC compression algorithm which might be used in that loader 523 | // is patented in the US by S3 and they do collect license fees when it's used in applications. 524 | // So if you are unfortunate enough to develop applications for US market and their broken patent system be careful. 525 | // #define _IRR_COMPILE_WITH_DDS_LOADER_ 526 | #ifdef NO_IRR_COMPILE_WITH_DDS_LOADER_ 527 | #undef _IRR_COMPILE_WITH_DDS_LOADER_ 528 | #endif 529 | //! Define _IRR_COMPILE_WITH_TGA_LOADER_ if you want to load .tga files 530 | #define _IRR_COMPILE_WITH_TGA_LOADER_ 531 | #ifdef NO_IRR_COMPILE_WITH_TGA_LOADER_ 532 | #undef _IRR_COMPILE_WITH_TGA_LOADER_ 533 | #endif 534 | //! Define _IRR_COMPILE_WITH_WAL_LOADER_ if you want to load .wal files 535 | #define _IRR_COMPILE_WITH_WAL_LOADER_ 536 | #ifdef NO_IRR_COMPILE_WITH_WAL_LOADER_ 537 | #undef _IRR_COMPILE_WITH_WAL_LOADER_ 538 | #endif 539 | //! Define _IRR_COMPILE_WITH_LMP_LOADER_ if you want to load .lmp files 540 | #define _IRR_COMPILE_WITH_LMP_LOADER_ 541 | #ifdef NO_IRR_COMPILE_WITH_LMP_LOADER_ 542 | #undef _IRR_COMPILE_WITH_LMP_LOADER_ 543 | #endif 544 | //! Define _IRR_COMPILE_WITH_RGB_LOADER_ if you want to load Silicon Graphics .rgb/.rgba/.sgi/.int/.inta/.bw files 545 | #define _IRR_COMPILE_WITH_RGB_LOADER_ 546 | #ifdef NO_IRR_COMPILE_WITH_RGB_LOADER_ 547 | #undef _IRR_COMPILE_WITH_RGB_LOADER_ 548 | #endif 549 | 550 | //! Define _IRR_COMPILE_WITH_BMP_WRITER_ if you want to write .bmp files 551 | #define _IRR_COMPILE_WITH_BMP_WRITER_ 552 | #ifdef NO_IRR_COMPILE_WITH_BMP_WRITER_ 553 | #undef _IRR_COMPILE_WITH_BMP_WRITER_ 554 | #endif 555 | //! Define _IRR_COMPILE_WITH_JPG_WRITER_ if you want to write .jpg files 556 | #define _IRR_COMPILE_WITH_JPG_WRITER_ 557 | #ifdef NO_IRR_COMPILE_WITH_JPG_WRITER_ 558 | #undef _IRR_COMPILE_WITH_JPG_WRITER_ 559 | #endif 560 | //! Define _IRR_COMPILE_WITH_PCX_WRITER_ if you want to write .pcx files 561 | #define _IRR_COMPILE_WITH_PCX_WRITER_ 562 | #ifdef NO_IRR_COMPILE_WITH_PCX_WRITER_ 563 | #undef _IRR_COMPILE_WITH_PCX_WRITER_ 564 | #endif 565 | //! Define _IRR_COMPILE_WITH_PNG_WRITER_ if you want to write .png files 566 | #define _IRR_COMPILE_WITH_PNG_WRITER_ 567 | #ifdef NO_IRR_COMPILE_WITH_PNG_WRITER_ 568 | #undef _IRR_COMPILE_WITH_PNG_WRITER_ 569 | #endif 570 | //! Define _IRR_COMPILE_WITH_PPM_WRITER_ if you want to write .ppm files 571 | #define _IRR_COMPILE_WITH_PPM_WRITER_ 572 | #ifdef NO_IRR_COMPILE_WITH_PPM_WRITER_ 573 | #undef _IRR_COMPILE_WITH_PPM_WRITER_ 574 | #endif 575 | //! Define _IRR_COMPILE_WITH_PSD_WRITER_ if you want to write .psd files 576 | #define _IRR_COMPILE_WITH_PSD_WRITER_ 577 | #ifdef NO_IRR_COMPILE_WITH_PSD_WRITER_ 578 | #undef _IRR_COMPILE_WITH_PSD_WRITER_ 579 | #endif 580 | //! Define _IRR_COMPILE_WITH_TGA_WRITER_ if you want to write .tga files 581 | #define _IRR_COMPILE_WITH_TGA_WRITER_ 582 | #ifdef NO_IRR_COMPILE_WITH_TGA_WRITER_ 583 | #undef _IRR_COMPILE_WITH_TGA_WRITER_ 584 | #endif 585 | 586 | //! Define __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ if you want to open ZIP and GZIP archives 587 | /** ZIP reading has several more options below to configure. */ 588 | #define __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ 589 | #ifdef NO__IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ 590 | #undef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ 591 | #endif 592 | #ifdef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ 593 | //! Define _IRR_COMPILE_WITH_ZLIB_ to enable compiling the engine using zlib. 594 | /** This enables the engine to read from compressed .zip archives. If you 595 | disable this feature, the engine can still read archives, but only uncompressed 596 | ones. */ 597 | #define _IRR_COMPILE_WITH_ZLIB_ 598 | #ifdef NO_IRR_COMPILE_WITH_ZLIB_ 599 | #undef _IRR_COMPILE_WITH_ZLIB_ 600 | #endif 601 | //! Define _IRR_USE_NON_SYSTEM_ZLIB_ to let irrlicht use the zlib which comes with irrlicht. 602 | /** If this is commented out, Irrlicht will try to compile using the zlib 603 | installed on the system. This is only used when _IRR_COMPILE_WITH_ZLIB_ is 604 | defined. */ 605 | #define _IRR_USE_NON_SYSTEM_ZLIB_ 606 | #ifdef NO_IRR_USE_NON_SYSTEM_ZLIB_ 607 | #undef _IRR_USE_NON_SYSTEM_ZLIB_ 608 | #endif 609 | //! Define _IRR_COMPILE_WITH_ZIP_ENCRYPTION_ if you want to read AES-encrypted ZIP archives 610 | #define _IRR_COMPILE_WITH_ZIP_ENCRYPTION_ 611 | #ifdef NO_IRR_COMPILE_WITH_ZIP_ENCRYPTION_ 612 | #undef _IRR_COMPILE_WITH_ZIP_ENCRYPTION_ 613 | #endif 614 | //! Define _IRR_COMPILE_WITH_BZIP2_ if you want to support bzip2 compressed zip archives 615 | /** bzip2 is superior to the original zip file compression modes, but requires 616 | a certain amount of memory for decompression and adds several files to the 617 | library. */ 618 | #define _IRR_COMPILE_WITH_BZIP2_ 619 | #ifdef NO_IRR_COMPILE_WITH_BZIP2_ 620 | #undef _IRR_COMPILE_WITH_BZIP2_ 621 | #endif 622 | //! Define _IRR_USE_NON_SYSTEM_BZLIB_ to let irrlicht use the bzlib which comes with irrlicht. 623 | /** If this is commented out, Irrlicht will try to compile using the bzlib 624 | installed on the system. This is only used when _IRR_COMPILE_WITH_BZLIB_ is 625 | defined. */ 626 | #define _IRR_USE_NON_SYSTEM_BZLIB_ 627 | #ifdef NO_IRR_USE_NON_SYSTEM_BZLIB_ 628 | #undef _IRR_USE_NON_SYSTEM_BZLIB_ 629 | #endif 630 | //! Define _IRR_COMPILE_WITH_LZMA_ if you want to use LZMA compressed zip files. 631 | /** LZMA is a very efficient compression code, known from 7zip. Irrlicht 632 | currently only supports zip archives, though. */ 633 | #define _IRR_COMPILE_WITH_LZMA_ 634 | #ifdef NO_IRR_COMPILE_WITH_LZMA_ 635 | #undef _IRR_COMPILE_WITH_LZMA_ 636 | #endif 637 | #endif 638 | 639 | //! Define __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ if you want to mount folders as archives 640 | #define __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ 641 | #ifdef NO__IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ 642 | #undef __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ 643 | #endif 644 | //! Define __IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_ if you want to open ID software PAK archives 645 | #define __IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_ 646 | #ifdef NO__IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_ 647 | #undef __IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_ 648 | #endif 649 | //! Define __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_ if you want to open Nebula Device NPK archives 650 | #define __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_ 651 | #ifdef NO__IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_ 652 | #undef __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_ 653 | #endif 654 | //! Define __IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_ if you want to open TAR archives 655 | #define __IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_ 656 | #ifdef NO__IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_ 657 | #undef __IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_ 658 | #endif 659 | //! Define __IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_ if you want to open WAD archives 660 | #define __IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_ 661 | #ifdef NO__IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_ 662 | #undef __IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_ 663 | #endif 664 | 665 | //! Set FPU settings 666 | /** Irrlicht should use approximate float and integer fpu techniques 667 | precision will be lower but speed higher. currently X86 only 668 | */ 669 | #if !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_SOLARIS_PLATFORM_) 670 | //#define IRRLICHT_FAST_MATH 671 | #ifdef NO_IRRLICHT_FAST_MATH 672 | #undef IRRLICHT_FAST_MATH 673 | #endif 674 | #endif 675 | 676 | // Some cleanup and standard stuff 677 | 678 | #ifdef _IRR_WINDOWS_API_ 679 | 680 | // To build Irrlicht as a static library, you must define _IRR_STATIC_LIB_ in both the 681 | // Irrlicht build, *and* in the user application, before #including 682 | #ifndef _IRR_STATIC_LIB_ 683 | #ifdef IRRLICHT_EXPORTS 684 | #define IRRLICHT_API __declspec(dllexport) 685 | #else 686 | #define IRRLICHT_API __declspec(dllimport) 687 | #endif // IRRLICHT_EXPORT 688 | #else 689 | #define IRRLICHT_API 690 | #endif // _IRR_STATIC_LIB_ 691 | 692 | // Declare the calling convention. 693 | #if defined(_STDCALL_SUPPORTED) 694 | #define IRRCALLCONV __stdcall 695 | #else 696 | #define IRRCALLCONV __cdecl 697 | #endif // STDCALL_SUPPORTED 698 | 699 | #else // _IRR_WINDOWS_API_ 700 | 701 | // Force symbol export in shared libraries built with gcc. 702 | #if (__GNUC__ >= 4) && !defined(_IRR_STATIC_LIB_) && defined(IRRLICHT_EXPORTS) 703 | #define IRRLICHT_API __attribute__ ((visibility("default"))) 704 | #else 705 | #define IRRLICHT_API 706 | #endif 707 | 708 | #define IRRCALLCONV 709 | 710 | #endif // _IRR_WINDOWS_API_ 711 | 712 | // We need to disable DIRECT3D9 support for Visual Studio 6.0 because 713 | // those $%&$!! disabled support for it since Dec. 2004 and users are complaining 714 | // about linker errors. Comment this out only if you are knowing what you are 715 | // doing. (Which means you have an old DX9 SDK and VisualStudio6). 716 | #ifdef _MSC_VER 717 | #if (_MSC_VER < 1300 && !defined(__GNUC__)) 718 | #undef _IRR_COMPILE_WITH_DIRECT3D_9_ 719 | #pragma message("Compiling Irrlicht with Visual Studio 6.0, support for DX9 is disabled.") 720 | #endif 721 | #endif 722 | 723 | // XBox does not have OpenGL or DirectX9 724 | #if defined(_IRR_XBOX_PLATFORM_) 725 | #undef _IRR_COMPILE_WITH_OPENGL_ 726 | #undef _IRR_COMPILE_WITH_DIRECT3D_9_ 727 | #endif 728 | 729 | //! WinCE does not have OpenGL or DirectX9. use minimal loaders 730 | #if defined(_WIN32_WCE) 731 | #undef _IRR_COMPILE_WITH_OPENGL_ 732 | #undef _IRR_COMPILE_WITH_DIRECT3D_8_ 733 | #undef _IRR_COMPILE_WITH_DIRECT3D_9_ 734 | 735 | #undef BURNINGVIDEO_RENDERER_BEAUTIFUL 736 | #undef BURNINGVIDEO_RENDERER_FAST 737 | #undef BURNINGVIDEO_RENDERER_ULTRA_FAST 738 | #define BURNINGVIDEO_RENDERER_CE 739 | 740 | #undef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ 741 | #define _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ 742 | //#define _IRR_WCHAR_FILESYSTEM 743 | 744 | #undef _IRR_COMPILE_WITH_IRR_MESH_LOADER_ 745 | //#undef _IRR_COMPILE_WITH_MD2_LOADER_ 746 | #undef _IRR_COMPILE_WITH_MD3_LOADER_ 747 | #undef _IRR_COMPILE_WITH_3DS_LOADER_ 748 | #undef _IRR_COMPILE_WITH_COLLADA_LOADER_ 749 | #undef _IRR_COMPILE_WITH_CSM_LOADER_ 750 | #undef _IRR_COMPILE_WITH_BSP_LOADER_ 751 | #undef _IRR_COMPILE_WITH_DMF_LOADER_ 752 | #undef _IRR_COMPILE_WITH_LMTS_LOADER_ 753 | #undef _IRR_COMPILE_WITH_MY3D_LOADER_ 754 | #undef _IRR_COMPILE_WITH_OBJ_LOADER_ 755 | #undef _IRR_COMPILE_WITH_OCT_LOADER_ 756 | #undef _IRR_COMPILE_WITH_OGRE_LOADER_ 757 | #undef _IRR_COMPILE_WITH_LWO_LOADER_ 758 | #undef _IRR_COMPILE_WITH_STL_LOADER_ 759 | #undef _IRR_COMPILE_WITH_IRR_WRITER_ 760 | #undef _IRR_COMPILE_WITH_COLLADA_WRITER_ 761 | #undef _IRR_COMPILE_WITH_STL_WRITER_ 762 | #undef _IRR_COMPILE_WITH_OBJ_WRITER_ 763 | //#undef _IRR_COMPILE_WITH_BMP_LOADER_ 764 | //#undef _IRR_COMPILE_WITH_JPG_LOADER_ 765 | #undef _IRR_COMPILE_WITH_PCX_LOADER_ 766 | //#undef _IRR_COMPILE_WITH_PNG_LOADER_ 767 | #undef _IRR_COMPILE_WITH_PPM_LOADER_ 768 | #undef _IRR_COMPILE_WITH_PSD_LOADER_ 769 | //#undef _IRR_COMPILE_WITH_TGA_LOADER_ 770 | #undef _IRR_COMPILE_WITH_WAL_LOADER_ 771 | #undef _IRR_COMPILE_WITH_BMP_WRITER_ 772 | #undef _IRR_COMPILE_WITH_JPG_WRITER_ 773 | #undef _IRR_COMPILE_WITH_PCX_WRITER_ 774 | #undef _IRR_COMPILE_WITH_PNG_WRITER_ 775 | #undef _IRR_COMPILE_WITH_PPM_WRITER_ 776 | #undef _IRR_COMPILE_WITH_PSD_WRITER_ 777 | #undef _IRR_COMPILE_WITH_TGA_WRITER_ 778 | 779 | #endif 780 | 781 | #ifndef _IRR_WINDOWS_API_ 782 | #undef _IRR_WCHAR_FILESYSTEM 783 | #endif 784 | 785 | #if defined(__sparc__) || defined(__sun__) 786 | #define __BIG_ENDIAN__ 787 | #endif 788 | 789 | #if defined(_IRR_SOLARIS_PLATFORM_) 790 | #undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ 791 | #endif 792 | 793 | //! Define __IRR_HAS_S64 if the irr::s64 type should be enable (needs long long, available on most platforms, but not part of ISO C++ 98) 794 | #define __IRR_HAS_S64 795 | #ifdef NO__IRR_HAS_S64 796 | #undef __IRR_HAS_S64 797 | #endif 798 | 799 | #if defined(__BORLANDC__) 800 | #include 801 | 802 | // Borland 5.5.1 does not have _strcmpi defined 803 | #if __BORLANDC__ == 0x551 804 | // #define _strcmpi strcmpi 805 | #undef _tfinddata_t 806 | #undef _tfindfirst 807 | #undef _tfindnext 808 | 809 | #define _tfinddata_t __tfinddata_t 810 | #define _tfindfirst __tfindfirst 811 | #define _tfindnext __tfindnext 812 | typedef long intptr_t; 813 | #endif 814 | 815 | #endif 816 | 817 | #ifdef _DEBUG 818 | //! A few attributes are written in CSceneManager when _IRR_SCENEMANAGER_DEBUG is enabled 819 | // NOTE: Those attributes were used always until 1.8.0 and became a global define for 1.8.1 820 | // which is only enabled in debug because it had a large (sometimes >5%) impact on speed. 821 | // A better solution in the long run is to break the interface and remove _all_ attribute 822 | // access in functions like CSceneManager::drawAll and instead put that information in some 823 | // own struct/class or in CSceneManager. 824 | // See http://irrlicht.sourceforge.net/forum/viewtopic.php?f=2&t=48211 for the discussion. 825 | #define _IRR_SCENEMANAGER_DEBUG 826 | #ifdef NO_IRR_SCENEMANAGER_DEBUG 827 | #undef _IRR_SCENEMANAGER_DEBUG 828 | #endif 829 | #endif 830 | 831 | #endif // __IRR_COMPILE_CONFIG_H_INCLUDED__ 832 | 833 | -------------------------------------------------------------------------------- /external/Irrlicht-math/include/irrMath.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt 2 | // This file is part of the "Irrlicht Engine". 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h 4 | 5 | #ifndef __IRR_MATH_H_INCLUDED__ 6 | #define __IRR_MATH_H_INCLUDED__ 7 | 8 | #include "IrrCompileConfig.h" 9 | #include "irrTypes.h" 10 | #include 11 | #include 12 | #include // for abs() etc. 13 | #include // For INT_MAX / UINT_MAX 14 | 15 | #if defined(_IRR_SOLARIS_PLATFORM_) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) || defined (_WIN32_WCE) 16 | #define sqrtf(X) (irr::f32)sqrt((irr::f64)(X)) 17 | #define sinf(X) (irr::f32)sin((irr::f64)(X)) 18 | #define cosf(X) (irr::f32)cos((irr::f64)(X)) 19 | #define asinf(X) (irr::f32)asin((irr::f64)(X)) 20 | #define acosf(X) (irr::f32)acos((irr::f64)(X)) 21 | #define atan2f(X,Y) (irr::f32)atan2((irr::f64)(X),(irr::f64)(Y)) 22 | #define ceilf(X) (irr::f32)ceil((irr::f64)(X)) 23 | #define floorf(X) (irr::f32)floor((irr::f64)(X)) 24 | #define powf(X,Y) (irr::f32)pow((irr::f64)(X),(irr::f64)(Y)) 25 | #define fmodf(X,Y) (irr::f32)fmod((irr::f64)(X),(irr::f64)(Y)) 26 | #define fabsf(X) (irr::f32)fabs((irr::f64)(X)) 27 | #define logf(X) (irr::f32)log((irr::f64)(X)) 28 | #endif 29 | 30 | #ifndef FLT_MAX 31 | #define FLT_MAX 3.402823466E+38F 32 | #endif 33 | 34 | #ifndef FLT_MIN 35 | #define FLT_MIN 1.17549435e-38F 36 | #endif 37 | 38 | namespace irr 39 | { 40 | namespace core 41 | { 42 | 43 | //! Rounding error constant often used when comparing f32 values. 44 | 45 | const s32 ROUNDING_ERROR_S32 = 0; 46 | #ifdef __IRR_HAS_S64 47 | const s64 ROUNDING_ERROR_S64 = 0; 48 | #endif 49 | const f32 ROUNDING_ERROR_f32 = 0.000001f; 50 | const f64 ROUNDING_ERROR_f64 = 0.00000001; 51 | 52 | #ifdef PI // make sure we don't collide with a define 53 | #undef PI 54 | #endif 55 | //! Constant for PI. 56 | const f32 PI = 3.14159265359f; 57 | 58 | //! Constant for reciprocal of PI. 59 | const f32 RECIPROCAL_PI = 1.0f/PI; 60 | 61 | //! Constant for half of PI. 62 | const f32 HALF_PI = PI/2.0f; 63 | 64 | #ifdef PI64 // make sure we don't collide with a define 65 | #undef PI64 66 | #endif 67 | //! Constant for 64bit PI. 68 | const f64 PI64 = 3.1415926535897932384626433832795028841971693993751; 69 | 70 | //! Constant for 64bit reciprocal of PI. 71 | const f64 RECIPROCAL_PI64 = 1.0/PI64; 72 | 73 | //! 32bit Constant for converting from degrees to radians 74 | const f32 DEGTORAD = PI / 180.0f; 75 | 76 | //! 32bit constant for converting from radians to degrees (formally known as GRAD_PI) 77 | const f32 RADTODEG = 180.0f / PI; 78 | 79 | //! 64bit constant for converting from degrees to radians (formally known as GRAD_PI2) 80 | const f64 DEGTORAD64 = PI64 / 180.0; 81 | 82 | //! 64bit constant for converting from radians to degrees 83 | const f64 RADTODEG64 = 180.0 / PI64; 84 | 85 | //! Utility function to convert a radian value to degrees 86 | /** Provided as it can be clearer to write radToDeg(X) than RADTODEG * X 87 | \param radians The radians value to convert to degrees. 88 | */ 89 | inline f32 radToDeg(f32 radians) 90 | { 91 | return RADTODEG * radians; 92 | } 93 | 94 | //! Utility function to convert a radian value to degrees 95 | /** Provided as it can be clearer to write radToDeg(X) than RADTODEG * X 96 | \param radians The radians value to convert to degrees. 97 | */ 98 | inline f64 radToDeg(f64 radians) 99 | { 100 | return RADTODEG64 * radians; 101 | } 102 | 103 | //! Utility function to convert a degrees value to radians 104 | /** Provided as it can be clearer to write degToRad(X) than DEGTORAD * X 105 | \param degrees The degrees value to convert to radians. 106 | */ 107 | inline f32 degToRad(f32 degrees) 108 | { 109 | return DEGTORAD * degrees; 110 | } 111 | 112 | //! Utility function to convert a degrees value to radians 113 | /** Provided as it can be clearer to write degToRad(X) than DEGTORAD * X 114 | \param degrees The degrees value to convert to radians. 115 | */ 116 | inline f64 degToRad(f64 degrees) 117 | { 118 | return DEGTORAD64 * degrees; 119 | } 120 | 121 | //! returns minimum of two values. Own implementation to get rid of the STL (VS6 problems) 122 | template 123 | inline const T& min_(const T& a, const T& b) 124 | { 125 | return a < b ? a : b; 126 | } 127 | 128 | //! returns minimum of three values. Own implementation to get rid of the STL (VS6 problems) 129 | template 130 | inline const T& min_(const T& a, const T& b, const T& c) 131 | { 132 | return a < b ? min_(a, c) : min_(b, c); 133 | } 134 | 135 | //! returns maximum of two values. Own implementation to get rid of the STL (VS6 problems) 136 | template 137 | inline const T& max_(const T& a, const T& b) 138 | { 139 | return a < b ? b : a; 140 | } 141 | 142 | //! returns maximum of three values. Own implementation to get rid of the STL (VS6 problems) 143 | template 144 | inline const T& max_(const T& a, const T& b, const T& c) 145 | { 146 | return a < b ? max_(b, c) : max_(a, c); 147 | } 148 | 149 | //! returns abs of two values. Own implementation to get rid of STL (VS6 problems) 150 | template 151 | inline T abs_(const T& a) 152 | { 153 | return a < (T)0 ? -a : a; 154 | } 155 | 156 | //! returns linear interpolation of a and b with ratio t 157 | //! \return: a if t==0, b if t==1, and the linear interpolation else 158 | template 159 | inline T lerp(const T& a, const T& b, const f32 t) 160 | { 161 | return (T)(a*(1.f-t)) + (b*t); 162 | } 163 | 164 | //! clamps a value between low and high 165 | template 166 | inline const T clamp (const T& value, const T& low, const T& high) 167 | { 168 | return min_ (max_(value,low), high); 169 | } 170 | 171 | //! swaps the content of the passed parameters 172 | // Note: We use the same trick as boost and use two template arguments to 173 | // avoid ambiguity when swapping objects of an Irrlicht type that has not 174 | // it's own swap overload. Otherwise we get conflicts with some compilers 175 | // in combination with stl. 176 | template 177 | inline void swap(T1& a, T2& b) 178 | { 179 | T1 c(a); 180 | a = b; 181 | b = c; 182 | } 183 | 184 | //! returns if a equals b, taking possible rounding errors into account 185 | inline bool equals(const f64 a, const f64 b, const f64 tolerance = ROUNDING_ERROR_f64) 186 | { 187 | return (a + tolerance >= b) && (a - tolerance <= b); 188 | } 189 | 190 | //! returns if a equals b, taking possible rounding errors into account 191 | inline bool equals(const f32 a, const f32 b, const f32 tolerance = ROUNDING_ERROR_f32) 192 | { 193 | return (a + tolerance >= b) && (a - tolerance <= b); 194 | } 195 | 196 | union FloatIntUnion32 197 | { 198 | FloatIntUnion32(float f1 = 0.0f) : f(f1) {} 199 | // Portable sign-extraction 200 | bool sign() const { return (i >> 31) != 0; } 201 | 202 | irr::s32 i; 203 | irr::f32 f; 204 | }; 205 | 206 | //! We compare the difference in ULP's (spacing between floating-point numbers, aka ULP=1 means there exists no float between). 207 | //\result true when numbers have a ULP <= maxUlpDiff AND have the same sign. 208 | inline bool equalsByUlp(f32 a, f32 b, int maxUlpDiff) 209 | { 210 | // Based on the ideas and code from Bruce Dawson on 211 | // http://www.altdevblogaday.com/2012/02/22/comparing-floating-point-numbers-2012-edition/ 212 | // When floats are interpreted as integers the two nearest possible float numbers differ just 213 | // by one integer number. Also works the other way round, an integer of 1 interpreted as float 214 | // is for example the smallest possible float number. 215 | 216 | FloatIntUnion32 fa(a); 217 | FloatIntUnion32 fb(b); 218 | 219 | // Different signs, we could maybe get difference to 0, but so close to 0 using epsilons is better. 220 | if ( fa.sign() != fb.sign() ) 221 | { 222 | // Check for equality to make sure +0==-0 223 | if (fa.i == fb.i) 224 | return true; 225 | return false; 226 | } 227 | 228 | // Find the difference in ULPs. 229 | int ulpsDiff = abs_(fa.i- fb.i); 230 | if (ulpsDiff <= maxUlpDiff) 231 | return true; 232 | 233 | return false; 234 | } 235 | 236 | #if 0 237 | //! returns if a equals b, not using any rounding tolerance 238 | inline bool equals(const s32 a, const s32 b) 239 | { 240 | return (a == b); 241 | } 242 | 243 | //! returns if a equals b, not using any rounding tolerance 244 | inline bool equals(const u32 a, const u32 b) 245 | { 246 | return (a == b); 247 | } 248 | #endif 249 | //! returns if a equals b, taking an explicit rounding tolerance into account 250 | inline bool equals(const s32 a, const s32 b, const s32 tolerance = ROUNDING_ERROR_S32) 251 | { 252 | return (a + tolerance >= b) && (a - tolerance <= b); 253 | } 254 | 255 | //! returns if a equals b, taking an explicit rounding tolerance into account 256 | inline bool equals(const u32 a, const u32 b, const s32 tolerance = ROUNDING_ERROR_S32) 257 | { 258 | return (a + tolerance >= b) && (a - tolerance <= b); 259 | } 260 | 261 | #ifdef __IRR_HAS_S64 262 | //! returns if a equals b, taking an explicit rounding tolerance into account 263 | inline bool equals(const s64 a, const s64 b, const s64 tolerance = ROUNDING_ERROR_S64) 264 | { 265 | return (a + tolerance >= b) && (a - tolerance <= b); 266 | } 267 | #endif 268 | 269 | //! returns if a equals zero, taking rounding errors into account 270 | inline bool iszero(const f64 a, const f64 tolerance = ROUNDING_ERROR_f64) 271 | { 272 | return fabs(a) <= tolerance; 273 | } 274 | 275 | //! returns if a equals zero, taking rounding errors into account 276 | inline bool iszero(const f32 a, const f32 tolerance = ROUNDING_ERROR_f32) 277 | { 278 | return fabsf(a) <= tolerance; 279 | } 280 | 281 | //! returns if a equals not zero, taking rounding errors into account 282 | inline bool isnotzero(const f32 a, const f32 tolerance = ROUNDING_ERROR_f32) 283 | { 284 | return fabsf(a) > tolerance; 285 | } 286 | 287 | //! returns if a equals zero, taking rounding errors into account 288 | inline bool iszero(const s32 a, const s32 tolerance = 0) 289 | { 290 | return ( a & 0x7ffffff ) <= tolerance; 291 | } 292 | 293 | //! returns if a equals zero, taking rounding errors into account 294 | inline bool iszero(const u32 a, const u32 tolerance = 0) 295 | { 296 | return a <= tolerance; 297 | } 298 | 299 | #ifdef __IRR_HAS_S64 300 | //! returns if a equals zero, taking rounding errors into account 301 | inline bool iszero(const s64 a, const s64 tolerance = 0) 302 | { 303 | return abs_(a) <= tolerance; 304 | } 305 | #endif 306 | 307 | inline s32 s32_min(s32 a, s32 b) 308 | { 309 | const s32 mask = (a - b) >> 31; 310 | return (a & mask) | (b & ~mask); 311 | } 312 | 313 | inline s32 s32_max(s32 a, s32 b) 314 | { 315 | const s32 mask = (a - b) >> 31; 316 | return (b & mask) | (a & ~mask); 317 | } 318 | 319 | inline s32 s32_clamp (s32 value, s32 low, s32 high) 320 | { 321 | return s32_min(s32_max(value,low), high); 322 | } 323 | 324 | /* 325 | float IEEE-754 bit represenation 326 | 327 | 0 0x00000000 328 | 1.0 0x3f800000 329 | 0.5 0x3f000000 330 | 3 0x40400000 331 | +inf 0x7f800000 332 | -inf 0xff800000 333 | +NaN 0x7fc00000 or 0x7ff00000 334 | in general: number = (sign ? -1:1) * 2^(exponent) * 1.(mantissa bits) 335 | */ 336 | 337 | typedef union { u32 u; s32 s; f32 f; } inttofloat; 338 | 339 | #define F32_AS_S32(f) (*((s32 *) &(f))) 340 | #define F32_AS_U32(f) (*((u32 *) &(f))) 341 | #define F32_AS_U32_POINTER(f) ( ((u32 *) &(f))) 342 | 343 | #define F32_VALUE_0 0x00000000 344 | #define F32_VALUE_1 0x3f800000 345 | #define F32_SIGN_BIT 0x80000000U 346 | #define F32_EXPON_MANTISSA 0x7FFFFFFFU 347 | 348 | //! code is taken from IceFPU 349 | //! Integer representation of a floating-point value. 350 | #ifdef IRRLICHT_FAST_MATH 351 | #define IR(x) ((u32&)(x)) 352 | #else 353 | inline u32 IR(f32 x) {inttofloat tmp; tmp.f=x; return tmp.u;} 354 | #endif 355 | 356 | //! Absolute integer representation of a floating-point value 357 | #define AIR(x) (IR(x)&0x7fffffff) 358 | 359 | //! Floating-point representation of an integer value. 360 | #ifdef IRRLICHT_FAST_MATH 361 | #define FR(x) ((f32&)(x)) 362 | #else 363 | inline f32 FR(u32 x) {inttofloat tmp; tmp.u=x; return tmp.f;} 364 | inline f32 FR(s32 x) {inttofloat tmp; tmp.s=x; return tmp.f;} 365 | #endif 366 | 367 | //! integer representation of 1.0 368 | #define IEEE_1_0 0x3f800000 369 | //! integer representation of 255.0 370 | #define IEEE_255_0 0x437f0000 371 | 372 | #ifdef IRRLICHT_FAST_MATH 373 | #define F32_LOWER_0(f) (F32_AS_U32(f) > F32_SIGN_BIT) 374 | #define F32_LOWER_EQUAL_0(f) (F32_AS_S32(f) <= F32_VALUE_0) 375 | #define F32_GREATER_0(f) (F32_AS_S32(f) > F32_VALUE_0) 376 | #define F32_GREATER_EQUAL_0(f) (F32_AS_U32(f) <= F32_SIGN_BIT) 377 | #define F32_EQUAL_1(f) (F32_AS_U32(f) == F32_VALUE_1) 378 | #define F32_EQUAL_0(f) ( (F32_AS_U32(f) & F32_EXPON_MANTISSA ) == F32_VALUE_0) 379 | 380 | // only same sign 381 | #define F32_A_GREATER_B(a,b) (F32_AS_S32((a)) > F32_AS_S32((b))) 382 | 383 | #else 384 | 385 | #define F32_LOWER_0(n) ((n) < 0.0f) 386 | #define F32_LOWER_EQUAL_0(n) ((n) <= 0.0f) 387 | #define F32_GREATER_0(n) ((n) > 0.0f) 388 | #define F32_GREATER_EQUAL_0(n) ((n) >= 0.0f) 389 | #define F32_EQUAL_1(n) ((n) == 1.0f) 390 | #define F32_EQUAL_0(n) ((n) == 0.0f) 391 | #define F32_A_GREATER_B(a,b) ((a) > (b)) 392 | #endif 393 | 394 | 395 | #ifndef REALINLINE 396 | #ifdef _MSC_VER 397 | #define REALINLINE __forceinline 398 | #else 399 | #define REALINLINE inline 400 | #endif 401 | #endif 402 | 403 | #if defined(__BORLANDC__) || defined (__BCPLUSPLUS__) 404 | 405 | // 8-bit bools in borland builder 406 | 407 | //! conditional set based on mask and arithmetic shift 408 | REALINLINE u32 if_c_a_else_b ( const c8 condition, const u32 a, const u32 b ) 409 | { 410 | return ( ( -condition >> 7 ) & ( a ^ b ) ) ^ b; 411 | } 412 | 413 | //! conditional set based on mask and arithmetic shift 414 | REALINLINE u32 if_c_a_else_0 ( const c8 condition, const u32 a ) 415 | { 416 | return ( -condition >> 31 ) & a; 417 | } 418 | #else 419 | 420 | //! conditional set based on mask and arithmetic shift 421 | REALINLINE u32 if_c_a_else_b ( const s32 condition, const u32 a, const u32 b ) 422 | { 423 | return ( ( -condition >> 31 ) & ( a ^ b ) ) ^ b; 424 | } 425 | 426 | //! conditional set based on mask and arithmetic shift 427 | REALINLINE u16 if_c_a_else_b ( const s16 condition, const u16 a, const u16 b ) 428 | { 429 | return ( ( -condition >> 15 ) & ( a ^ b ) ) ^ b; 430 | } 431 | 432 | //! conditional set based on mask and arithmetic shift 433 | REALINLINE u32 if_c_a_else_0 ( const s32 condition, const u32 a ) 434 | { 435 | return ( -condition >> 31 ) & a; 436 | } 437 | #endif 438 | 439 | /* 440 | if (condition) state |= m; else state &= ~m; 441 | */ 442 | REALINLINE void setbit_cond ( u32 &state, s32 condition, u32 mask ) 443 | { 444 | // 0, or any postive to mask 445 | //s32 conmask = -condition >> 31; 446 | state ^= ( ( -condition >> 31 ) ^ state ) & mask; 447 | } 448 | 449 | inline f32 round_( f32 x ) 450 | { 451 | return floorf( x + 0.5f ); 452 | } 453 | 454 | REALINLINE void clearFPUException () 455 | { 456 | #ifdef IRRLICHT_FAST_MATH 457 | return; 458 | #ifdef feclearexcept 459 | feclearexcept(FE_ALL_EXCEPT); 460 | #elif defined(_MSC_VER) 461 | __asm fnclex; 462 | #elif defined(__GNUC__) && defined(__x86__) 463 | __asm__ __volatile__ ("fclex \n\t"); 464 | #else 465 | # warn clearFPUException not supported. 466 | #endif 467 | #endif 468 | } 469 | 470 | // calculate: sqrt ( x ) 471 | REALINLINE f32 squareroot(const f32 f) 472 | { 473 | return sqrtf(f); 474 | } 475 | 476 | // calculate: sqrt ( x ) 477 | REALINLINE f64 squareroot(const f64 f) 478 | { 479 | return sqrt(f); 480 | } 481 | 482 | // calculate: sqrt ( x ) 483 | REALINLINE s32 squareroot(const s32 f) 484 | { 485 | return static_cast(squareroot(static_cast(f))); 486 | } 487 | 488 | #ifdef __IRR_HAS_S64 489 | // calculate: sqrt ( x ) 490 | REALINLINE s64 squareroot(const s64 f) 491 | { 492 | return static_cast(squareroot(static_cast(f))); 493 | } 494 | #endif 495 | 496 | // calculate: 1 / sqrt ( x ) 497 | REALINLINE f64 reciprocal_squareroot(const f64 x) 498 | { 499 | return 1.0 / sqrt(x); 500 | } 501 | 502 | // calculate: 1 / sqrtf ( x ) 503 | REALINLINE f32 reciprocal_squareroot(const f32 f) 504 | { 505 | #if defined ( IRRLICHT_FAST_MATH ) 506 | #if defined(_MSC_VER) 507 | // SSE reciprocal square root estimate, accurate to 12 significant 508 | // bits of the mantissa 509 | f32 recsqrt; 510 | __asm rsqrtss xmm0, f // xmm0 = rsqrtss(f) 511 | __asm movss recsqrt, xmm0 // return xmm0 512 | return recsqrt; 513 | 514 | /* 515 | // comes from Nvidia 516 | u32 tmp = (u32(IEEE_1_0 << 1) + IEEE_1_0 - *(u32*)&x) >> 1; 517 | f32 y = *(f32*)&tmp; 518 | return y * (1.47f - 0.47f * x * y * y); 519 | */ 520 | #else 521 | return 1.f / sqrtf(f); 522 | #endif 523 | #else // no fast math 524 | return 1.f / sqrtf(f); 525 | #endif 526 | } 527 | 528 | // calculate: 1 / sqrtf( x ) 529 | REALINLINE s32 reciprocal_squareroot(const s32 x) 530 | { 531 | return static_cast(reciprocal_squareroot(static_cast(x))); 532 | } 533 | 534 | // calculate: 1 / x 535 | REALINLINE f32 reciprocal( const f32 f ) 536 | { 537 | #if defined (IRRLICHT_FAST_MATH) 538 | 539 | // SSE Newton-Raphson reciprocal estimate, accurate to 23 significant 540 | // bi ts of the mantissa 541 | // One Newtown-Raphson Iteration: 542 | // f(i+1) = 2 * rcpss(f) - f * rcpss(f) * rcpss(f) 543 | f32 rec; 544 | __asm rcpss xmm0, f // xmm0 = rcpss(f) 545 | __asm movss xmm1, f // xmm1 = f 546 | __asm mulss xmm1, xmm0 // xmm1 = f * rcpss(f) 547 | __asm mulss xmm1, xmm0 // xmm2 = f * rcpss(f) * rcpss(f) 548 | __asm addss xmm0, xmm0 // xmm0 = 2 * rcpss(f) 549 | __asm subss xmm0, xmm1 // xmm0 = 2 * rcpss(f) 550 | // - f * rcpss(f) * rcpss(f) 551 | __asm movss rec, xmm0 // return xmm0 552 | return rec; 553 | 554 | 555 | //! i do not divide through 0.. (fpu expection) 556 | // instead set f to a high value to get a return value near zero.. 557 | // -1000000000000.f.. is use minus to stay negative.. 558 | // must test's here (plane.normal dot anything ) checks on <= 0.f 559 | //u32 x = (-(AIR(f) != 0 ) >> 31 ) & ( IR(f) ^ 0xd368d4a5 ) ^ 0xd368d4a5; 560 | //return 1.f / FR ( x ); 561 | 562 | #else // no fast math 563 | return 1.f / f; 564 | #endif 565 | } 566 | 567 | // calculate: 1 / x 568 | REALINLINE f64 reciprocal ( const f64 f ) 569 | { 570 | return 1.0 / f; 571 | } 572 | 573 | 574 | // calculate: 1 / x, low precision allowed 575 | REALINLINE f32 reciprocal_approxim ( const f32 f ) 576 | { 577 | #if defined( IRRLICHT_FAST_MATH) 578 | 579 | // SSE Newton-Raphson reciprocal estimate, accurate to 23 significant 580 | // bi ts of the mantissa 581 | // One Newtown-Raphson Iteration: 582 | // f(i+1) = 2 * rcpss(f) - f * rcpss(f) * rcpss(f) 583 | f32 rec; 584 | __asm rcpss xmm0, f // xmm0 = rcpss(f) 585 | __asm movss xmm1, f // xmm1 = f 586 | __asm mulss xmm1, xmm0 // xmm1 = f * rcpss(f) 587 | __asm mulss xmm1, xmm0 // xmm2 = f * rcpss(f) * rcpss(f) 588 | __asm addss xmm0, xmm0 // xmm0 = 2 * rcpss(f) 589 | __asm subss xmm0, xmm1 // xmm0 = 2 * rcpss(f) 590 | // - f * rcpss(f) * rcpss(f) 591 | __asm movss rec, xmm0 // return xmm0 592 | return rec; 593 | 594 | 595 | /* 596 | // SSE reciprocal estimate, accurate to 12 significant bits of 597 | f32 rec; 598 | __asm rcpss xmm0, f // xmm0 = rcpss(f) 599 | __asm movss rec , xmm0 // return xmm0 600 | return rec; 601 | */ 602 | /* 603 | register u32 x = 0x7F000000 - IR ( p ); 604 | const f32 r = FR ( x ); 605 | return r * (2.0f - p * r); 606 | */ 607 | #else // no fast math 608 | return 1.f / f; 609 | #endif 610 | } 611 | 612 | 613 | REALINLINE s32 floor32(f32 x) 614 | { 615 | #ifdef IRRLICHT_FAST_MATH 616 | const f32 h = 0.5f; 617 | 618 | s32 t; 619 | 620 | #if defined(_MSC_VER) 621 | __asm 622 | { 623 | fld x 624 | fsub h 625 | fistp t 626 | } 627 | #elif defined(__GNUC__) 628 | __asm__ __volatile__ ( 629 | "fsub %2 \n\t" 630 | "fistpl %0" 631 | : "=m" (t) 632 | : "t" (x), "f" (h) 633 | : "st" 634 | ); 635 | #else 636 | # warn IRRLICHT_FAST_MATH not supported. 637 | return (s32) floorf ( x ); 638 | #endif 639 | return t; 640 | #else // no fast math 641 | return (s32) floorf ( x ); 642 | #endif 643 | } 644 | 645 | 646 | REALINLINE s32 ceil32 ( f32 x ) 647 | { 648 | #ifdef IRRLICHT_FAST_MATH 649 | const f32 h = 0.5f; 650 | 651 | s32 t; 652 | 653 | #if defined(_MSC_VER) 654 | __asm 655 | { 656 | fld x 657 | fadd h 658 | fistp t 659 | } 660 | #elif defined(__GNUC__) 661 | __asm__ __volatile__ ( 662 | "fadd %2 \n\t" 663 | "fistpl %0 \n\t" 664 | : "=m"(t) 665 | : "t"(x), "f"(h) 666 | : "st" 667 | ); 668 | #else 669 | # warn IRRLICHT_FAST_MATH not supported. 670 | return (s32) ceilf ( x ); 671 | #endif 672 | return t; 673 | #else // not fast math 674 | return (s32) ceilf ( x ); 675 | #endif 676 | } 677 | 678 | 679 | 680 | REALINLINE s32 round32(f32 x) 681 | { 682 | #if defined(IRRLICHT_FAST_MATH) 683 | s32 t; 684 | 685 | #if defined(_MSC_VER) 686 | __asm 687 | { 688 | fld x 689 | fistp t 690 | } 691 | #elif defined(__GNUC__) 692 | __asm__ __volatile__ ( 693 | "fistpl %0 \n\t" 694 | : "=m"(t) 695 | : "t"(x) 696 | : "st" 697 | ); 698 | #else 699 | # warn IRRLICHT_FAST_MATH not supported. 700 | return (s32) round_(x); 701 | #endif 702 | return t; 703 | #else // no fast math 704 | return (s32) round_(x); 705 | #endif 706 | } 707 | 708 | inline f32 f32_max3(const f32 a, const f32 b, const f32 c) 709 | { 710 | return a > b ? (a > c ? a : c) : (b > c ? b : c); 711 | } 712 | 713 | inline f32 f32_min3(const f32 a, const f32 b, const f32 c) 714 | { 715 | return a < b ? (a < c ? a : c) : (b < c ? b : c); 716 | } 717 | 718 | inline f32 fract ( f32 x ) 719 | { 720 | return x - floorf ( x ); 721 | } 722 | 723 | } // end namespace core 724 | } // end namespace irr 725 | 726 | #ifndef IRRLICHT_FAST_MATH 727 | using irr::core::IR; 728 | using irr::core::FR; 729 | #endif 730 | 731 | #endif 732 | 733 | namespace irrmath = irr::core; 734 | 735 | -------------------------------------------------------------------------------- /external/Irrlicht-math/include/irrTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt 2 | // This file is part of the "Irrlicht Engine". 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h 4 | 5 | #ifndef __IRR_TYPES_H_INCLUDED__ 6 | #define __IRR_TYPES_H_INCLUDED__ 7 | 8 | #include "IrrCompileConfig.h" 9 | 10 | namespace irr 11 | { 12 | 13 | //! 8 bit unsigned variable. 14 | /** This is a typedef for unsigned char, it ensures portability of the engine. */ 15 | #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__)) 16 | typedef unsigned __int8 u8; 17 | #else 18 | typedef unsigned char u8; 19 | #endif 20 | 21 | //! 8 bit signed variable. 22 | /** This is a typedef for signed char, it ensures portability of the engine. */ 23 | #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__)) 24 | typedef __int8 s8; 25 | #else 26 | typedef signed char s8; 27 | #endif 28 | 29 | //! 8 bit character variable. 30 | /** This is a typedef for char, it ensures portability of the engine. */ 31 | typedef char c8; 32 | 33 | 34 | 35 | //! 16 bit unsigned variable. 36 | /** This is a typedef for unsigned short, it ensures portability of the engine. */ 37 | #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__)) 38 | typedef unsigned __int16 u16; 39 | #else 40 | typedef unsigned short u16; 41 | #endif 42 | 43 | //! 16 bit signed variable. 44 | /** This is a typedef for signed short, it ensures portability of the engine. */ 45 | #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__)) 46 | typedef __int16 s16; 47 | #else 48 | typedef signed short s16; 49 | #endif 50 | 51 | 52 | 53 | //! 32 bit unsigned variable. 54 | /** This is a typedef for unsigned int, it ensures portability of the engine. */ 55 | #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__)) 56 | typedef unsigned __int32 u32; 57 | #else 58 | typedef unsigned int u32; 59 | #endif 60 | 61 | //! 32 bit signed variable. 62 | /** This is a typedef for signed int, it ensures portability of the engine. */ 63 | #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__)) 64 | typedef __int32 s32; 65 | #else 66 | typedef signed int s32; 67 | #endif 68 | 69 | 70 | #ifdef __IRR_HAS_S64 71 | //! 64 bit unsigned variable. 72 | /** This is a typedef for 64bit uint, it ensures portability of the engine. */ 73 | #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__)) 74 | typedef unsigned __int64 u64; 75 | #elif __GNUC__ 76 | #if __WORDSIZE == 64 77 | typedef unsigned long int u64; 78 | #else 79 | __extension__ typedef unsigned long long u64; 80 | #endif 81 | #else 82 | typedef unsigned long long u64; 83 | #endif 84 | 85 | //! 64 bit signed variable. 86 | /** This is a typedef for 64bit int, it ensures portability of the engine. */ 87 | #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__)) 88 | typedef __int64 s64; 89 | #elif __GNUC__ 90 | #if __WORDSIZE == 64 91 | typedef long int s64; 92 | #else 93 | __extension__ typedef long long s64; 94 | #endif 95 | #else 96 | typedef long long s64; 97 | #endif 98 | #endif // __IRR_HAS_S64 99 | 100 | 101 | 102 | //! 32 bit floating point variable. 103 | /** This is a typedef for float, it ensures portability of the engine. */ 104 | typedef float f32; 105 | 106 | //! 64 bit floating point variable. 107 | /** This is a typedef for double, it ensures portability of the engine. */ 108 | typedef double f64; 109 | 110 | 111 | } // end namespace irr 112 | 113 | 114 | #include 115 | #ifdef _IRR_WINDOWS_API_ 116 | //! Defines for s{w,n}printf because these methods do not match the ISO C 117 | //! standard on Windows platforms, but it does on all others. 118 | //! These should be int snprintf(char *str, size_t size, const char *format, ...); 119 | //! and int swprintf(wchar_t *wcs, size_t maxlen, const wchar_t *format, ...); 120 | #if defined(_MSC_VER) && _MSC_VER > 1310 && !defined (_WIN32_WCE) 121 | #define swprintf swprintf_s 122 | #define snprintf sprintf_s 123 | #elif !defined(__CYGWIN__) 124 | #define swprintf _snwprintf 125 | #define snprintf _snprintf 126 | #endif 127 | 128 | // define the wchar_t type if not already built in. 129 | #ifdef _MSC_VER 130 | #ifndef _WCHAR_T_DEFINED 131 | //! A 16 bit wide character type. 132 | /** 133 | Defines the wchar_t-type. 134 | In VS6, its not possible to tell 135 | the standard compiler to treat wchar_t as a built-in type, and 136 | sometimes we just don't want to include the huge stdlib.h or wchar.h, 137 | so we'll use this. 138 | */ 139 | typedef unsigned short wchar_t; 140 | #define _WCHAR_T_DEFINED 141 | #endif // wchar is not defined 142 | #endif // microsoft compiler 143 | #endif // _IRR_WINDOWS_API_ 144 | 145 | namespace irr 146 | { 147 | 148 | //! Type name for character type used by the file system. 149 | /** Should the wide character version of the FileSystem be used it is a 150 | 16 bit character variable. Used for unicode Filesystem and unicode strings. 151 | Else it is a 8 bit character variable. Used for ansi Filesystem and non-unicode 152 | strings 153 | */ 154 | #if defined(_IRR_WCHAR_FILESYSTEM) 155 | typedef wchar_t fschar_t; 156 | #define _IRR_TEXT(X) L##X 157 | #else 158 | typedef char fschar_t; 159 | #define _IRR_TEXT(X) X 160 | #endif 161 | 162 | } // end namespace irr 163 | 164 | //! define a break macro for debugging. 165 | #if defined(_DEBUG) 166 | #if defined(_IRR_WINDOWS_API_) && defined(_MSC_VER) && !defined (_WIN32_WCE) 167 | #if defined(WIN64) || defined(_WIN64) // using portable common solution for x64 configuration 168 | #include 169 | #define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) if (_CONDITION_) {_CrtDbgBreak();} 170 | #else 171 | #define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) if (_CONDITION_) {_asm int 3} 172 | #endif 173 | #else 174 | #include "assert.h" 175 | #define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) assert( !(_CONDITION_) ); 176 | #endif 177 | #else 178 | #define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) 179 | #endif 180 | 181 | //! Defines a deprecated macro which generates a warning at compile time 182 | /** The usage is simple 183 | For typedef: typedef _IRR_DEPRECATED_ int test1; 184 | For classes/structs: class _IRR_DEPRECATED_ test2 { ... }; 185 | For methods: class test3 { _IRR_DEPRECATED_ virtual void foo() {} }; 186 | For functions: template _IRR_DEPRECATED_ void test4(void) {} 187 | **/ 188 | #if defined(IGNORE_DEPRECATED_WARNING) 189 | #define _IRR_DEPRECATED_ 190 | #elif _MSC_VER >= 1310 //vs 2003 or higher 191 | #define _IRR_DEPRECATED_ __declspec(deprecated) 192 | #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) // all versions above 3.0 should support this feature 193 | #define _IRR_DEPRECATED_ __attribute__ ((deprecated)) 194 | #else 195 | #define _IRR_DEPRECATED_ 196 | #endif 197 | 198 | //! Defines a small statement to work around a microsoft compiler bug. 199 | /** The microsoft compiler 7.0 - 7.1 has a bug: 200 | When you call unmanaged code that returns a bool type value of false from managed code, 201 | the return value may appear as true. See 202 | http://support.microsoft.com/default.aspx?kbid=823071 for details. 203 | Compiler version defines: VC6.0 : 1200, VC7.0 : 1300, VC7.1 : 1310, VC8.0 : 1400*/ 204 | #if defined(_IRR_WINDOWS_API_) && defined(_MSC_VER) && (_MSC_VER > 1299) && (_MSC_VER < 1400) 205 | #define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX __asm mov eax,100 206 | #else 207 | #define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX 208 | #endif // _IRR_MANAGED_MARSHALLING_BUGFIX 209 | 210 | 211 | // memory debugging 212 | #if defined(_DEBUG) && defined(IRRLICHT_EXPORTS) && defined(_MSC_VER) && \ 213 | (_MSC_VER > 1299) && !defined(_IRR_DONT_DO_MEMORY_DEBUGGING_HERE) && !defined(_WIN32_WCE) 214 | 215 | #define CRTDBG_MAP_ALLOC 216 | #define _CRTDBG_MAP_ALLOC 217 | #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) 218 | #include 219 | #include 220 | #define new DEBUG_CLIENTBLOCK 221 | #endif 222 | 223 | // disable truncated debug information warning in visual studio 6 by default 224 | #if defined(_MSC_VER) && (_MSC_VER < 1300 ) 225 | #pragma warning( disable: 4786) 226 | #endif // _MSC 227 | 228 | 229 | //! ignore VC8 warning deprecated 230 | /** The microsoft compiler */ 231 | #if defined(_IRR_WINDOWS_API_) && defined(_MSC_VER) && (_MSC_VER >= 1400) 232 | //#pragma warning( disable: 4996) 233 | //#define _CRT_SECURE_NO_DEPRECATE 1 234 | //#define _CRT_NONSTDC_NO_DEPRECATE 1 235 | #endif 236 | 237 | 238 | //! creates four CC codes used in Irrlicht for simple ids 239 | /** some compilers can create those by directly writing the 240 | code like 'code', but some generate warnings so we use this macro here */ 241 | #define MAKE_IRR_ID(c0, c1, c2, c3) \ 242 | ((irr::u32)(irr::u8)(c0) | ((irr::u32)(irr::u8)(c1) << 8) | \ 243 | ((irr::u32)(irr::u8)(c2) << 16) | ((irr::u32)(irr::u8)(c3) << 24 )) 244 | 245 | #if defined(__BORLANDC__) || defined (__BCPLUSPLUS__) 246 | #define _strcmpi(a,b) strcmpi(a,b) 247 | #endif 248 | 249 | #endif // __IRR_TYPES_H_INCLUDED__ 250 | 251 | -------------------------------------------------------------------------------- /external/Irrlicht-math/include/irrlicht.h: -------------------------------------------------------------------------------- 1 | /* irrlicht.h -- interface of the 'Irrlicht Engine' 2 | 3 | Copyright (C) 2002-2012 Nikolaus Gebhardt 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | 21 | Please note that the Irrlicht Engine is based in part on the work of the 22 | Independent JPEG Group, the zlib and the libPng. This means that if you use 23 | the Irrlicht Engine in your product, you must acknowledge somewhere in your 24 | documentation that you've used the IJG code. It would also be nice to mention 25 | that you use the Irrlicht Engine, the zlib and libPng. See the README files 26 | in the jpeglib, the zlib and libPng for further informations. 27 | */ 28 | 29 | #ifndef __IRRLICHT_H_INCLUDED__ 30 | #define __IRRLICHT_H_INCLUDED__ 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /external/Irrlicht-math/include/quaternion.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt 2 | // This file is part of the "Irrlicht Engine". 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h 4 | 5 | #ifndef __IRR_QUATERNION_H_INCLUDED__ 6 | #define __IRR_QUATERNION_H_INCLUDED__ 7 | 8 | #include "irrTypes.h" 9 | #include "irrMath.h" 10 | #include "matrix4.h" 11 | #include "vector3.h" 12 | 13 | // Between Irrlicht 1.7 and Irrlicht 1.8 the quaternion-matrix conversions got fixed. 14 | // This define disables all involved functions completely to allow finding all places 15 | // where the wrong conversions had been in use. 16 | #define IRR_TEST_BROKEN_QUATERNION_USE 0 17 | 18 | namespace irr 19 | { 20 | namespace core 21 | { 22 | 23 | //! Quaternion class for representing rotations. 24 | /** It provides cheap combinations and avoids gimbal locks. 25 | Also useful for interpolations. */ 26 | template 27 | class quaternion 28 | { 29 | public: 30 | 31 | //! Default Constructor 32 | quaternion() : x(0.0), y(0.0), z(0.0), w(1.0) {} 33 | 34 | //! Constructor 35 | quaternion(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) { } 36 | 37 | //! Constructor which converts euler angles (radians) to a quaternion 38 | quaternion(T x, T y, T z); 39 | 40 | //! Constructor which converts euler angles (radians) to a quaternion 41 | quaternion(const vector3& vec); 42 | 43 | #if !IRR_TEST_BROKEN_QUATERNION_USE 44 | //! Constructor which converts a matrix to a quaternion 45 | quaternion(const matrix4& mat); 46 | #endif 47 | 48 | //! Equalilty operator 49 | bool operator==(const quaternion& other) const; 50 | 51 | //! inequality operator 52 | bool operator!=(const quaternion& other) const; 53 | 54 | //! Assignment operator 55 | inline quaternion& operator=(const quaternion& other); 56 | 57 | #if !IRR_TEST_BROKEN_QUATERNION_USE 58 | //! Matrix assignment operator 59 | inline quaternion& operator=(const matrix4& other); 60 | #endif 61 | 62 | //! Add operator 63 | quaternion operator+(const quaternion& other) const; 64 | 65 | //! Multiplication operator () 66 | quaternion operator*(const quaternion& other) const; 67 | 68 | //! Multiplication operator with scalar 69 | quaternion operator*(T s) const; 70 | 71 | //! Multiplication operator with scalar 72 | quaternion& operator*=(T s); 73 | 74 | //! Multiplication operator 75 | vector3 operator*(const vector3& v) const; 76 | 77 | //! Multiplication operator XXX(maxhe): changed to right side first. 78 | quaternion& operator*=(const quaternion& other); 79 | 80 | //! Calculates the dot product 81 | inline T dotProduct(const quaternion& other) const; 82 | 83 | //! Sets new quaternion 84 | inline quaternion& set(T x, T y, T z, T w); 85 | 86 | //! Sets new quaternion based on euler angles (radians) 87 | inline quaternion& set(T x, T y, T z); 88 | 89 | //! Sets new quaternion based on euler angles (radians) 90 | inline quaternion& set(const core::vector3& vec); 91 | 92 | //! Sets new quaternion from other quaternion 93 | inline quaternion& set(const core::quaternion& quat); 94 | 95 | //! returns if this quaternion equals the other one, taking floating point rounding errors into account 96 | inline bool equals(const quaternion& other, 97 | const T tolerance = ROUNDING_ERROR_f64 ) const; 98 | 99 | //! Normalizes the quaternion 100 | inline quaternion& normalize(); 101 | 102 | #if !IRR_TEST_BROKEN_QUATERNION_USE 103 | //! Creates a matrix from this quaternion 104 | matrix4 getMatrix() const; 105 | #endif 106 | 107 | //! Creates a matrix from this quaternion 108 | void getMatrix( matrix4 &dest, const core::vector3 &translation=core::vector3() ) const; 109 | 110 | /*! 111 | Creates a matrix from this quaternion 112 | Rotate about a center point 113 | shortcut for 114 | core::quaternion q; 115 | q.rotationFromTo ( vin[i].Normal, forward ); 116 | q.getMatrixCenter ( lookat, center, newPos ); 117 | 118 | core::matrix4 m2; 119 | m2.setInverseTranslation ( center ); 120 | lookat *= m2; 121 | 122 | core::matrix4 m3; 123 | m2.setTranslation ( newPos ); 124 | lookat *= m3; 125 | 126 | */ 127 | void getMatrixCenter( matrix4 &dest, const core::vector3 ¢er, const core::vector3 &translation ) const; 128 | 129 | //! Creates a matrix from this quaternion 130 | inline void getMatrix_transposed( matrix4 &dest ) const; 131 | 132 | //! Inverts this quaternion 133 | quaternion& makeInverse(); 134 | 135 | quaternion inversed() const; 136 | 137 | //! Set this quaternion to the linear interpolation between two quaternions 138 | /** \param q1 First quaternion to be interpolated. 139 | \param q2 Second quaternion to be interpolated. 140 | \param time Progress of interpolation. For time=0 the result is 141 | q1, for time=1 the result is q2. Otherwise interpolation 142 | between q1 and q2. 143 | */ 144 | quaternion& lerp(quaternion q1, quaternion q2, T time); 145 | 146 | //! Set this quaternion to the result of the spherical interpolation between two quaternions 147 | /** \param q1 First quaternion to be interpolated. 148 | \param q2 Second quaternion to be interpolated. 149 | \param time Progress of interpolation. For time=0 the result is 150 | q1, for time=1 the result is q2. Otherwise interpolation 151 | between q1 and q2. 152 | \param threshold To avoid inaccuracies at the end (time=1) the 153 | interpolation switches to linear interpolation at some point. 154 | This value defines how much of the remaining interpolation will 155 | be calculated with lerp. Everything from 1-threshold up will be 156 | linear interpolation. 157 | */ 158 | quaternion& slerp(quaternion q1, quaternion q2, 159 | T time, T threshold=.05f); 160 | 161 | //! Create quaternion from rotation angle and rotation axis. 162 | /** Axis must be unit length. 163 | The quaternion representing the rotation is 164 | q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k). 165 | \param angle Rotation Angle in radians. 166 | \param axis Rotation axis. */ 167 | quaternion& fromAngleAxis (T angle, const vector3& axis); 168 | 169 | //! Create quaternion from unitRotationAxis * angle 170 | quaternion& fromRotationVector(const vector3& axis); 171 | 172 | //! Fills an angle (radians) around an axis (unit vector) 173 | void toAngleAxis (T &angle, core::vector3& axis) const; 174 | 175 | //! Fills an vector, which equals angle (radians) * axis (unit vector) 176 | void toRotationVector(core::vector3& axis) const; 177 | 178 | //! Output this quaternion to an euler angle (radians) 179 | void toEuler(vector3& euler) const; 180 | 181 | //! Set quaternion to identity 182 | quaternion& makeIdentity(); 183 | 184 | //! Set quaternion to represent a rotation from one vector to another. 185 | quaternion& rotationFromTo(const vector3& from, const vector3& to); 186 | 187 | //! Make the quaternion is on the same hemisphere of the other. 188 | inline void ensureSameHemisphere(const quaternion& o) 189 | { 190 | if (dotProduct(o) < 0) 191 | { 192 | x = -x; 193 | y = -y; 194 | z = -z; 195 | w = -w; 196 | } 197 | } 198 | 199 | //! Get two quaternion's difference in radians. 200 | inline T getDiffAngle(const quaternion& q) const 201 | { 202 | return 2 * acos(abs(dotProduct(q))); 203 | } 204 | 205 | 206 | //! Quaternion elements. 207 | T x; // vectorial (imaginary) part 208 | T y; 209 | T z; 210 | T w; // real part 211 | }; 212 | 213 | 214 | // Constructor which converts euler angles to a quaternion 215 | template 216 | inline quaternion::quaternion(T x, T y, T z) 217 | { 218 | set(x,y,z); 219 | } 220 | 221 | 222 | // Constructor which converts euler angles to a quaternion 223 | template 224 | inline quaternion::quaternion(const vector3& vec) 225 | { 226 | set(vec.x,vec.y,vec.z); 227 | } 228 | 229 | #if !IRR_TEST_BROKEN_QUATERNION_USE 230 | // Constructor which converts a matrix to a quaternion 231 | template 232 | inline quaternion::quaternion(const matrix4& mat) 233 | { 234 | (*this) = mat; 235 | } 236 | #endif 237 | 238 | // equal operator 239 | template 240 | inline bool quaternion::operator==(const quaternion& other) const 241 | { 242 | return ((x == other.x) && 243 | (y == other.y) && 244 | (z == other.z) && 245 | (w == other.w)); 246 | } 247 | 248 | // inequality operator 249 | template 250 | inline bool quaternion::operator!=(const quaternion& other) const 251 | { 252 | return !(*this == other); 253 | } 254 | 255 | // assignment operator 256 | template 257 | inline quaternion& quaternion::operator=(const quaternion& other) 258 | { 259 | x = other.x; 260 | y = other.y; 261 | z = other.z; 262 | w = other.w; 263 | return *this; 264 | } 265 | 266 | #if !IRR_TEST_BROKEN_QUATERNION_USE 267 | // matrix assignment operator 268 | template 269 | inline quaternion& quaternion::operator=(const matrix4& m) 270 | { 271 | const T diag = m[0] + m[5] + m[10] + 1; 272 | 273 | if( diag > 0.0 ) 274 | { 275 | const T scale = sqrt(diag) * 2.0; // get scale from diagonal 276 | 277 | // TODO: speed this up 278 | x = (m[6] - m[9]) / scale; 279 | y = (m[8] - m[2]) / scale; 280 | z = (m[1] - m[4]) / scale; 281 | w = 0.25f * scale; 282 | } 283 | else 284 | { 285 | if (m[0]>m[5] && m[0]>m[10]) 286 | { 287 | // 1st element of diag is greatest value 288 | // find scale according to 1st element, and double it 289 | const T scale = sqrt(1.0 + m[0] - m[5] - m[10]) * 2.0; 290 | 291 | // TODO: speed this up 292 | x = 0.25f * scale; 293 | y = (m[4] + m[1]) / scale; 294 | z = (m[2] + m[8]) / scale; 295 | w = (m[6] - m[9]) / scale; 296 | } 297 | else if (m[5]>m[10]) 298 | { 299 | // 2nd element of diag is greatest value 300 | // find scale according to 2nd element, and double it 301 | const T scale = sqrt(1.0 + m[5] - m[0] - m[10]) * 2.0; 302 | 303 | // TODO: speed this up 304 | x = (m[4] + m[1]) / scale; 305 | y = 0.25f * scale; 306 | z = (m[9] + m[6]) / scale; 307 | w = (m[8] - m[2]) / scale; 308 | } 309 | else 310 | { 311 | // 3rd element of diag is greatest value 312 | // find scale according to 3rd element, and double it 313 | const T scale = sqrt(1.0 + m[10] - m[0] - m[5]) * 2.0; 314 | 315 | // TODO: speed this up 316 | x = (m[8] + m[2]) / scale; 317 | y = (m[9] + m[6]) / scale; 318 | z = 0.25f * scale; 319 | w = (m[1] - m[4]) / scale; 320 | } 321 | } 322 | 323 | return normalize(); 324 | } 325 | #endif 326 | 327 | 328 | // multiplication operator (right side first) 329 | template 330 | inline quaternion quaternion::operator*(const quaternion& other) const 331 | { 332 | quaternion tmp; 333 | 334 | tmp.x = (w * other.x) + (x * other.w) + (y * other.z) - (z * other.y); 335 | tmp.y = (w * other.y) + (y * other.w) + (z * other.x) - (x * other.z); 336 | tmp.z = (w * other.z) + (z * other.w) + (x * other.y) - (y * other.x); 337 | tmp.w = (w * other.w) - (x * other.x) - (y * other.y) - (z * other.z); 338 | return tmp; 339 | } 340 | 341 | 342 | // multiplication operator 343 | template 344 | inline quaternion quaternion::operator*(T s) const 345 | { 346 | return quaternion(s*x, s*y, s*z, s*w); 347 | } 348 | 349 | 350 | // multiplication operator 351 | template 352 | inline quaternion& quaternion::operator*=(T s) 353 | { 354 | x*=s; 355 | y*=s; 356 | z*=s; 357 | w*=s; 358 | return *this; 359 | } 360 | 361 | // multiplication operator 362 | template 363 | inline quaternion& quaternion::operator*=(const quaternion& other) 364 | { 365 | return (*this = other * (*this)); 366 | } 367 | 368 | // add operator 369 | template 370 | inline quaternion quaternion::operator+(const quaternion& b) const 371 | { 372 | return quaternion(x+b.x, y+b.y, z+b.z, w+b.w); 373 | } 374 | 375 | #if !IRR_TEST_BROKEN_QUATERNION_USE 376 | // Creates a matrix from this quaternion 377 | template 378 | inline matrix4 quaternion::getMatrix() const 379 | { 380 | core::matrix4 m; 381 | getMatrix(m); 382 | return m; 383 | } 384 | #endif 385 | 386 | /*! 387 | Creates a matrix from this quaternion 388 | */ 389 | template 390 | inline void quaternion::getMatrix(matrix4 &dest, 391 | const core::vector3 ¢er) const 392 | { 393 | dest[0] = 1.0 - 2.0*y*y - 2.0*z*z; 394 | dest[1] = 2.0*x*y + 2.0*z*w; 395 | dest[2] = 2.0*x*z - 2.0*y*w; 396 | dest[3] = 0.0; 397 | 398 | dest[4] = 2.0*x*y - 2.0*z*w; 399 | dest[5] = 1.0 - 2.0*x*x - 2.0*z*z; 400 | dest[6] = 2.0*z*y + 2.0*x*w; 401 | dest[7] = 0.0; 402 | 403 | dest[8] = 2.0*x*z + 2.0*y*w; 404 | dest[9] = 2.0*z*y - 2.0*x*w; 405 | dest[10] = 1.0 - 2.0*x*x - 2.0*y*y; 406 | dest[11] = 0.0; 407 | 408 | dest[12] = center.x; 409 | dest[13] = center.y; 410 | dest[14] = center.z; 411 | dest[15] = 1.0; 412 | 413 | dest.setDefinitelyIdentityMatrix ( false ); 414 | } 415 | 416 | 417 | /*! 418 | Creates a matrix from this quaternion 419 | Rotate about a center point 420 | shortcut for 421 | core::quaternion q; 422 | q.rotationFromTo(vin[i].Normal, forward); 423 | q.getMatrix(lookat, center); 424 | 425 | core::matrix4 m2; 426 | m2.setInverseTranslation(center); 427 | lookat *= m2; 428 | */ 429 | template 430 | inline void quaternion::getMatrixCenter(matrix4 &dest, 431 | const core::vector3 ¢er, 432 | const core::vector3 &translation) const 433 | { 434 | dest[0] = 1.0 - 2.0*y*y - 2.0*z*z; 435 | dest[1] = 2.0*x*y + 2.0*z*w; 436 | dest[2] = 2.0*x*z - 2.0*y*w; 437 | dest[3] = 0.0; 438 | 439 | dest[4] = 2.0*x*y - 2.0*z*w; 440 | dest[5] = 1.0 - 2.0*x*x - 2.0*z*z; 441 | dest[6] = 2.0*z*y + 2.0*x*w; 442 | dest[7] = 0.0; 443 | 444 | dest[8] = 2.0*x*z + 2.0*y*w; 445 | dest[9] = 2.0*z*y - 2.0*x*w; 446 | dest[10] = 1.0 - 2.0*x*x - 2.0*y*y; 447 | dest[11] = 0.0; 448 | 449 | dest.setRotationCenter ( center, translation ); 450 | } 451 | 452 | // Creates a matrix from this quaternion 453 | template 454 | inline void quaternion::getMatrix_transposed(matrix4 &dest) const 455 | { 456 | dest[0] = 1.0 - 2.0*y*y - 2.0*z*z; 457 | dest[4] = 2.0*x*y + 2.0*z*w; 458 | dest[8] = 2.0*x*z - 2.0*y*w; 459 | dest[12] = 0.0; 460 | 461 | dest[1] = 2.0*x*y - 2.0*z*w; 462 | dest[5] = 1.0 - 2.0*x*x - 2.0*z*z; 463 | dest[9] = 2.0*z*y + 2.0*x*w; 464 | dest[13] = 0.0; 465 | 466 | dest[2] = 2.0*x*z + 2.0*y*w; 467 | dest[6] = 2.0*z*y - 2.0*x*w; 468 | dest[10] = 1.0 - 2.0*x*x - 2.0*y*y; 469 | dest[14] = 0.0; 470 | 471 | dest[3] = 0.0; 472 | dest[7] = 0.0; 473 | dest[11] = 0.0; 474 | dest[15] = 1.0; 475 | 476 | dest.setDefinitelyIdentityMatrix(false); 477 | } 478 | 479 | 480 | // Inverts this quaternion 481 | template 482 | inline quaternion& quaternion::makeInverse() 483 | { 484 | x = -x; y = -y; z = -z; 485 | return *this; 486 | } 487 | 488 | // Returns a new quaternion, which is inversed. 489 | template 490 | inline quaternion quaternion::inversed() const 491 | { 492 | quaternion q(*this); 493 | q.makeInverse(); 494 | return q; 495 | } 496 | 497 | // sets new quaternion 498 | template 499 | inline quaternion& quaternion::set(T x, T y, T z, T w) 500 | { 501 | x = x; 502 | y = y; 503 | z = z; 504 | w = w; 505 | return *this; 506 | } 507 | 508 | 509 | // sets new quaternion based on euler angles 510 | template 511 | inline quaternion& quaternion::set(T x, T y, T z) 512 | { 513 | f64 angle; 514 | 515 | angle = x * 0.5; 516 | const f64 sr = sin(angle); 517 | const f64 cr = cos(angle); 518 | 519 | angle = y * 0.5; 520 | const f64 sp = sin(angle); 521 | const f64 cp = cos(angle); 522 | 523 | angle = z * 0.5; 524 | const f64 sy = sin(angle); 525 | const f64 cy = cos(angle); 526 | 527 | const f64 cpcy = cp * cy; 528 | const f64 spcy = sp * cy; 529 | const f64 cpsy = cp * sy; 530 | const f64 spsy = sp * sy; 531 | 532 | x = (T)(sr * cpcy - cr * spsy); 533 | y = (T)(cr * spcy + sr * cpsy); 534 | z = (T)(cr * cpsy - sr * spcy); 535 | w = (T)(cr * cpcy + sr * spsy); 536 | 537 | return normalize(); 538 | } 539 | 540 | // sets new quaternion based on euler angles 541 | template 542 | inline quaternion& quaternion::set(const core::vector3& vec) 543 | { 544 | return set(vec.x, vec.y, vec.z); 545 | } 546 | 547 | // sets new quaternion based on other quaternion 548 | template 549 | inline quaternion& quaternion::set(const core::quaternion& quat) 550 | { 551 | return (*this=quat); 552 | } 553 | 554 | 555 | //! returns if this quaternion equals the other one, taking floating point rounding errors into account 556 | template 557 | inline bool quaternion::equals(const quaternion& other, const T tolerance) const 558 | { 559 | return core::equals(x, other.x, tolerance) && 560 | core::equals(y, other.y, tolerance) && 561 | core::equals(z, other.z, tolerance) && 562 | core::equals(w, other.w, tolerance); 563 | } 564 | 565 | 566 | // normalizes the quaternion 567 | template 568 | inline quaternion& quaternion::normalize() 569 | { 570 | const T n = x*x + y*y + z*z + w*w; 571 | 572 | if (n == 1) 573 | return *this; 574 | 575 | //n = 1.0 / sqrt(n); 576 | return (*this *= reciprocal_squareroot ( n )); 577 | } 578 | 579 | 580 | // set this quaternion to the result of the linear interpolation between two quaternions 581 | template 582 | inline quaternion& quaternion::lerp(quaternion q1, quaternion q2, T time) 583 | { 584 | const T scale = 1.0 - time; 585 | *this = (q1*scale) + (q2*time); 586 | this->normalize(); 587 | return *this; 588 | } 589 | 590 | 591 | // set this quaternion to the result of the interpolation between two quaternions 592 | template 593 | inline quaternion& quaternion::slerp(quaternion q1, quaternion q2, T time, T threshold) 594 | { 595 | T angle = q1.dotProduct(q2); 596 | 597 | // make sure we use the short rotation 598 | if (angle < 0.0) 599 | { 600 | q1 *= -1.0; 601 | angle *= -1.0; 602 | } 603 | 604 | if (angle <= (1-threshold)) // spherical interpolation 605 | { 606 | const T theta = acos(angle); 607 | const T invsintheta = reciprocal((T)sin(theta)); 608 | const T scale = (T)sin(theta * (1.0-time)) * invsintheta; 609 | const T invscale = (T)sin(theta * time) * invsintheta; 610 | return (*this = (q1*scale) + (q2*invscale)); 611 | } 612 | else // linear interploation 613 | return lerp(q1,q2,time); 614 | } 615 | 616 | 617 | // calculates the dot product 618 | template 619 | inline T quaternion::dotProduct(const quaternion& q2) const 620 | { 621 | return (x * q2.x) + (y * q2.y) + (z * q2.z) + (w * q2.w); 622 | } 623 | 624 | 625 | //! axis could be any length, angle in radians 626 | template 627 | inline quaternion& quaternion::fromAngleAxis(T angle, const vector3& axis) 628 | { 629 | vector3 normalizedAxis = axis.normalized(); 630 | const T fHalfAngle = 0.5f*angle; 631 | const T fSin = (T)sin(fHalfAngle); 632 | w = (T)cos(fHalfAngle); 633 | x = fSin*normalizedAxis.x; 634 | y = fSin*normalizedAxis.y; 635 | z = fSin*normalizedAxis.z; 636 | return *this; 637 | } 638 | 639 | template 640 | inline quaternion& quaternion::fromRotationVector(const vector3& axis) 641 | { 642 | return fromAngleAxis(axis.getLength(), axis); 643 | } 644 | 645 | template 646 | inline void quaternion::toAngleAxis(T &angle, core::vector3 &axis) const 647 | { 648 | const T scale = sqrt(x*x + y*y + z*z); 649 | 650 | if (core::iszero(scale) || w > 1.0 || w < -1.0) 651 | { 652 | angle = 0.0; 653 | axis.x = 0.0; 654 | axis.y = 1.0; 655 | axis.z = 0.0; 656 | } 657 | else 658 | { 659 | const T invscale = reciprocal(scale); 660 | angle = 2.0 * acos(w); 661 | axis.x = x * invscale; 662 | axis.y = y * invscale; 663 | axis.z = z * invscale; 664 | } 665 | } 666 | 667 | template 668 | inline void quaternion::toRotationVector(core::vector3& axis) const 669 | { 670 | double angle; 671 | toAngleAxis(angle, axis); 672 | axis *= angle; 673 | } 674 | 675 | template 676 | inline void quaternion::toEuler(vector3& euler) const 677 | { 678 | // XXX(maxhe): To get yaw pitch roll. 679 | T X = this->y; 680 | T Y = this->x; 681 | T Z = this->z; 682 | T W = this->w; 683 | 684 | const f64 sqw = W*W; 685 | const f64 sqx = X*X; 686 | const f64 sqy = Y*Y; 687 | const f64 sqz = Z*Z; 688 | const f64 test = 2.0 * (Y*W - X*Z); 689 | 690 | if (core::equals(test, 1.0, 0.000001)) 691 | { 692 | // heading = rotation about z-axis 693 | euler.z = (T) (-2.0*atan2(X, W)); 694 | // bank = rotation about x-axis 695 | euler.x = 0; 696 | // attitude = rotation about y-axis 697 | euler.y = (T) (core::PI64/2.0); 698 | } 699 | else if (core::equals(test, -1.0, 0.000001)) 700 | { 701 | // heading = rotation about z-axis 702 | euler.z = (T) (2.0*atan2(X, W)); 703 | // bank = rotation about x-axis 704 | euler.x = 0; 705 | // attitude = rotation about y-axis 706 | euler.y = (T) (core::PI64/-2.0); 707 | } 708 | else 709 | { 710 | // heading = rotation about z-axis 711 | euler.z = (T) atan2(2.0 * (X*Y +Z*W),(sqx - sqy - sqz + sqw)); 712 | // bank = rotation about x-axis 713 | euler.x = (T) atan2(2.0 * (Y*Z +X*W),(-sqx - sqy + sqz + sqw)); 714 | // attitude = rotation about y-axis 715 | euler.y = (T) asin( clamp(test, -1.0, 1.0) ); 716 | } 717 | } 718 | 719 | 720 | template 721 | inline vector3 quaternion::operator* (const vector3& v) const 722 | { 723 | // nVidia SDK implementation 724 | 725 | vector3 uv, uuv; 726 | vector3 qvec(x, y, z); 727 | uv = qvec.crossProduct(v); 728 | uuv = qvec.crossProduct(uv); 729 | uv *= (2.0 * w); 730 | uuv *= 2.0; 731 | 732 | return v + uv + uuv; 733 | } 734 | 735 | // set quaternion to identity 736 | template 737 | inline core::quaternion& quaternion::makeIdentity() 738 | { 739 | w = 1.0; 740 | x = 0.0; 741 | y = 0.0; 742 | z = 0.0; 743 | return *this; 744 | } 745 | 746 | template 747 | inline core::quaternion& quaternion::rotationFromTo(const vector3& from, const vector3& to) 748 | { 749 | // Based on Stan Melax's article in Game Programming Gems 750 | // Copy, since cannot modify local 751 | vector3 v0 = from; 752 | vector3 v1 = to; 753 | v0.normalize(); 754 | v1.normalize(); 755 | 756 | const T d = v0.dotProduct(v1); 757 | if (d >= 1.0) // If dot == 1, vectors are the same 758 | { 759 | return makeIdentity(); 760 | } 761 | else if (d <= -1.0) // exactly opposite 762 | { 763 | core::vector3 axis(1.0, 0.0, 0.0); 764 | axis = axis.crossProduct(v0); 765 | if (axis.getLength()==0) 766 | { 767 | axis.set(0.0,1.0,0.0); 768 | axis = axis.crossProduct(v0); 769 | } 770 | // same as fromAngleAxis(core::PI, axis).normalize(); 771 | return set(axis.x, axis.y, axis.z, 0).normalize(); 772 | } 773 | 774 | const T s = sqrt( (1+d)*2 ); // optimize inv_sqrt 775 | const T invs = 1.0 / s; 776 | const vector3 c = v0.crossProduct(v1)*invs; 777 | return set(c.x, c.y, c.z, s * 0.5f).normalize(); 778 | } 779 | 780 | template 781 | using Quat = quaternion; 782 | typedef Quat Quatf; 783 | typedef Quat Quatd; 784 | 785 | 786 | } // end namespace core 787 | } // end namespace irr 788 | 789 | #endif 790 | 791 | -------------------------------------------------------------------------------- /external/Irrlicht-math/include/vector2.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt 2 | // This file is part of the "Irrlicht Engine". 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h 4 | 5 | #ifndef __IRR_POINT_2D_H_INCLUDED__ 6 | #define __IRR_POINT_2D_H_INCLUDED__ 7 | 8 | #include "irrMath.h" 9 | 10 | namespace irr 11 | { 12 | namespace core 13 | { 14 | 15 | 16 | //! 2d vector template class with lots of operators and methods. 17 | /** As of Irrlicht 1.6, this class supercedes position2d, which should 18 | be considered deprecated. */ 19 | template 20 | class vector2 21 | { 22 | public: 23 | //! Default constructor (null vector) 24 | vector2() : X(0), Y(0) {} 25 | //! Constructor with two different values 26 | vector2(T nx, T ny) : X(nx), Y(ny) {} 27 | //! Constructor with the same value for both members 28 | explicit vector2(T n) : X(n), Y(n) {} 29 | //! Copy constructor 30 | vector2(const vector2& other) : X(other.X), Y(other.Y) {} 31 | 32 | // operators 33 | 34 | vector2 operator-() const { return vector2(-X, -Y); } 35 | 36 | vector2& operator=(const vector2& other) { X = other.X; Y = other.Y; return *this; } 37 | 38 | 39 | vector2 operator+(const vector2& other) const { return vector2(X + other.X, Y + other.Y); } 40 | vector2& operator+=(const vector2& other) { X+=other.X; Y+=other.Y; return *this; } 41 | vector2 operator+(const T v) const { return vector2(X + v, Y + v); } 42 | vector2& operator+=(const T v) { X+=v; Y+=v; return *this; } 43 | 44 | vector2 operator-(const vector2& other) const { return vector2(X - other.X, Y - other.Y); } 45 | vector2& operator-=(const vector2& other) { X-=other.X; Y-=other.Y; return *this; } 46 | vector2 operator-(const T v) const { return vector2(X - v, Y - v); } 47 | vector2& operator-=(const T v) { X-=v; Y-=v; return *this; } 48 | 49 | vector2 operator*(const vector2& other) const { return vector2(X * other.X, Y * other.Y); } 50 | vector2& operator*=(const vector2& other) { X*=other.X; Y*=other.Y; return *this; } 51 | vector2 operator*(const T v) const { return vector2(X * v, Y * v); } 52 | vector2& operator*=(const T v) { X*=v; Y*=v; return *this; } 53 | 54 | vector2 operator/(const vector2& other) const { return vector2(X / other.X, Y / other.Y); } 55 | vector2& operator/=(const vector2& other) { X/=other.X; Y/=other.Y; return *this; } 56 | vector2 operator/(const T v) const { return vector2(X / v, Y / v); } 57 | vector2& operator/=(const T v) { X/=v; Y/=v; return *this; } 58 | 59 | //! sort in order X, Y. Equality with rounding tolerance. 60 | bool operator<=(const vector2&other) const 61 | { 62 | return (X=(const vector2&other) const 68 | { 69 | return (X>other.X || core::equals(X, other.X)) || 70 | (core::equals(X, other.X) && (Y>other.Y || core::equals(Y, other.Y))); 71 | } 72 | 73 | //! sort in order X, Y. Difference must be above rounding tolerance. 74 | bool operator<(const vector2&other) const 75 | { 76 | return (X(const vector2&other) const 82 | { 83 | return (X>other.X && !core::equals(X, other.X)) || 84 | (core::equals(X, other.X) && Y>other.Y && !core::equals(Y, other.Y)); 85 | } 86 | 87 | bool operator==(const vector2& other) const { return equals(other); } 88 | bool operator!=(const vector2& other) const { return !equals(other); } 89 | 90 | // functions 91 | 92 | //! Checks if this vector equals the other one. 93 | /** Takes floating point rounding errors into account. 94 | \param other Vector to compare with. 95 | \return True if the two vector are (almost) equal, else false. */ 96 | bool equals(const vector2& other) const 97 | { 98 | return core::equals(X, other.X) && core::equals(Y, other.Y); 99 | } 100 | 101 | vector2& set(T nx, T ny) {X=nx; Y=ny; return *this; } 102 | vector2& set(const vector2& p) { X=p.X; Y=p.Y; return *this; } 103 | 104 | //! Gets the length of the vector. 105 | /** \return The length of the vector. */ 106 | T getLength() const { return core::squareroot( X*X + Y*Y ); } 107 | 108 | //! Get the squared length of this vector 109 | /** This is useful because it is much faster than getLength(). 110 | \return The squared length of the vector. */ 111 | T getLengthSQ() const { return X*X + Y*Y; } 112 | 113 | //! Get the dot product of this vector with another. 114 | /** \param other Other vector to take dot product with. 115 | \return The dot product of the two vectors. */ 116 | T dotProduct(const vector2& other) const 117 | { 118 | return X*other.X + Y*other.Y; 119 | } 120 | 121 | //! Gets distance from another point. 122 | /** Here, the vector is interpreted as a point in 2-dimensional space. 123 | \param other Other vector to measure from. 124 | \return Distance from other point. */ 125 | T getDistanceFrom(const vector2& other) const 126 | { 127 | return vector2(X - other.X, Y - other.Y).getLength(); 128 | } 129 | 130 | //! Returns squared distance from another point. 131 | /** Here, the vector is interpreted as a point in 2-dimensional space. 132 | \param other Other vector to measure from. 133 | \return Squared distance from other point. */ 134 | T getDistanceFromSQ(const vector2& other) const 135 | { 136 | return vector2(X - other.X, Y - other.Y).getLengthSQ(); 137 | } 138 | 139 | //! rotates the point anticlockwise around a center by an amount of degrees. 140 | /** \param degrees Amount of degrees to rotate by, anticlockwise. 141 | \param center Rotation center. 142 | \return This vector after transformation. */ 143 | vector2& rotateBy(f64 degrees, const vector2& center=vector2()) 144 | { 145 | degrees *= DEGTORAD64; 146 | const f64 cs = cos(degrees); 147 | const f64 sn = sin(degrees); 148 | 149 | X -= center.X; 150 | Y -= center.Y; 151 | 152 | set((T)(X*cs - Y*sn), (T)(X*sn + Y*cs)); 153 | 154 | X += center.X; 155 | Y += center.Y; 156 | return *this; 157 | } 158 | 159 | //! Normalize the vector. 160 | /** The null vector is left untouched. 161 | \return Reference to this vector, after normalization. */ 162 | vector2& normalize() 163 | { 164 | f32 length = (f32)(X*X + Y*Y); 165 | if ( length == 0 ) 166 | return *this; 167 | length = core::reciprocal_squareroot ( length ); 168 | X = (T)(X * length); 169 | Y = (T)(Y * length); 170 | return *this; 171 | } 172 | 173 | //! Calculates the angle of this vector in degrees in the trigonometric sense. 174 | /** 0 is to the right (3 o'clock), values increase counter-clockwise. 175 | This method has been suggested by Pr3t3nd3r. 176 | \return Returns a value between 0 and 360. */ 177 | f64 getAngleTrig() const 178 | { 179 | if (Y == 0) 180 | return X < 0 ? 180 : 0; 181 | else 182 | if (X == 0) 183 | return Y < 0 ? 270 : 90; 184 | 185 | if ( Y > 0) 186 | if (X > 0) 187 | return atan((irr::f64)Y/(irr::f64)X) * RADTODEG64; 188 | else 189 | return 180.0-atan((irr::f64)Y/-(irr::f64)X) * RADTODEG64; 190 | else 191 | if (X > 0) 192 | return 360.0-atan(-(irr::f64)Y/(irr::f64)X) * RADTODEG64; 193 | else 194 | return 180.0+atan(-(irr::f64)Y/-(irr::f64)X) * RADTODEG64; 195 | } 196 | 197 | //! Calculates the angle of this vector in degrees in the counter trigonometric sense. 198 | /** 0 is to the right (3 o'clock), values increase clockwise. 199 | \return Returns a value between 0 and 360. */ 200 | inline f64 getAngle() const 201 | { 202 | if (Y == 0) // corrected thanks to a suggestion by Jox 203 | return X < 0 ? 180 : 0; 204 | else if (X == 0) 205 | return Y < 0 ? 90 : 270; 206 | 207 | // don't use getLength here to avoid precision loss with s32 vectors 208 | // avoid floating-point trouble as sqrt(y*y) is occasionally larger than y, so clamp 209 | const f64 tmp = core::clamp(Y / sqrt((f64)(X*X + Y*Y)), -1.0, 1.0); 210 | const f64 angle = atan( core::squareroot(1 - tmp*tmp) / tmp) * RADTODEG64; 211 | 212 | if (X>0 && Y>0) 213 | return angle + 270; 214 | else 215 | if (X>0 && Y<0) 216 | return angle + 90; 217 | else 218 | if (X<0 && Y<0) 219 | return 90 - angle; 220 | else 221 | if (X<0 && Y>0) 222 | return 270 - angle; 223 | 224 | return angle; 225 | } 226 | 227 | //! Calculates the angle between this vector and another one in degree. 228 | /** \param b Other vector to test with. 229 | \return Returns a value between 0 and 90. */ 230 | inline f64 getAngleWith(const vector2& b) const 231 | { 232 | f64 tmp = (f64)(X*b.X + Y*b.Y); 233 | 234 | if (tmp == 0.0) 235 | return 90.0; 236 | 237 | tmp = tmp / core::squareroot((f64)((X*X + Y*Y) * (b.X*b.X + b.Y*b.Y))); 238 | if (tmp < 0.0) 239 | tmp = -tmp; 240 | if ( tmp > 1.0 ) // avoid floating-point trouble 241 | tmp = 1.0; 242 | 243 | return atan(sqrt(1 - tmp*tmp) / tmp) * RADTODEG64; 244 | } 245 | 246 | //! Returns if this vector interpreted as a point is on a line between two other points. 247 | /** It is assumed that the point is on the line. 248 | \param begin Beginning vector to compare between. 249 | \param end Ending vector to compare between. 250 | \return True if this vector is between begin and end, false if not. */ 251 | bool isBetweenPoints(const vector2& begin, const vector2& end) const 252 | { 253 | if (begin.X != end.X) 254 | { 255 | return ((begin.X <= X && X <= end.X) || 256 | (begin.X >= X && X >= end.X)); 257 | } 258 | else 259 | { 260 | return ((begin.Y <= Y && Y <= end.Y) || 261 | (begin.Y >= Y && Y >= end.Y)); 262 | } 263 | } 264 | 265 | //! Creates an interpolated vector between this vector and another vector. 266 | /** \param other The other vector to interpolate with. 267 | \param d Interpolation value between 0.0f (all the other vector) and 1.0f (all this vector). 268 | Note that this is the opposite direction of interpolation to getInterpolated_quadratic() 269 | \return An interpolated vector. This vector is not modified. */ 270 | vector2 getInterpolated(const vector2& other, f64 d) const 271 | { 272 | f64 inv = 1.0f - d; 273 | return vector2((T)(other.X*inv + X*d), (T)(other.Y*inv + Y*d)); 274 | } 275 | 276 | //! Creates a quadratically interpolated vector between this and two other vectors. 277 | /** \param v2 Second vector to interpolate with. 278 | \param v3 Third vector to interpolate with (maximum at 1.0f) 279 | \param d Interpolation value between 0.0f (all this vector) and 1.0f (all the 3rd vector). 280 | Note that this is the opposite direction of interpolation to getInterpolated() and interpolate() 281 | \return An interpolated vector. This vector is not modified. */ 282 | vector2 getInterpolated_quadratic(const vector2& v2, const vector2& v3, f64 d) const 283 | { 284 | // this*(1-d)*(1-d) + 2 * v2 * (1-d) + v3 * d * d; 285 | const f64 inv = 1.0f - d; 286 | const f64 mul0 = inv * inv; 287 | const f64 mul1 = 2.0f * d * inv; 288 | const f64 mul2 = d * d; 289 | 290 | return vector2 ( (T)(X * mul0 + v2.X * mul1 + v3.X * mul2), 291 | (T)(Y * mul0 + v2.Y * mul1 + v3.Y * mul2)); 292 | } 293 | 294 | //! Sets this vector to the linearly interpolated vector between a and b. 295 | /** \param a first vector to interpolate with, maximum at 1.0f 296 | \param b second vector to interpolate with, maximum at 0.0f 297 | \param d Interpolation value between 0.0f (all vector b) and 1.0f (all vector a) 298 | Note that this is the opposite direction of interpolation to getInterpolated_quadratic() 299 | */ 300 | vector2& interpolate(const vector2& a, const vector2& b, f64 d) 301 | { 302 | X = (T)((f64)b.X + ( ( a.X - b.X ) * d )); 303 | Y = (T)((f64)b.Y + ( ( a.Y - b.Y ) * d )); 304 | return *this; 305 | } 306 | 307 | //! X coordinate of vector. 308 | T X; 309 | 310 | //! Y coordinate of vector. 311 | T Y; 312 | }; 313 | 314 | //! Typedef for f32 2d vector. 315 | typedef vector2 vector2f; 316 | 317 | //! Typedef for integer 2d vector. 318 | typedef vector2 vector2i; 319 | 320 | template 321 | vector2 operator*(const S scalar, const vector2& vector) { return vector*scalar; } 322 | 323 | } // end namespace core 324 | } // end namespace irr 325 | 326 | #endif 327 | 328 | -------------------------------------------------------------------------------- /external/Irrlicht-math/include/vector3.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt 2 | // This file is part of the "Irrlicht Engine". 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h 4 | 5 | #ifndef __IRR_POINT_3D_H_INCLUDED__ 6 | #define __IRR_POINT_3D_H_INCLUDED__ 7 | 8 | #include 9 | #include "irrMath.h" 10 | 11 | namespace irr 12 | { 13 | namespace core 14 | { 15 | 16 | //! 3d vector template class with lots of operators and methods. 17 | /** The vector3 class is used in Irrlicht for three main purposes: 18 | 1) As a direction vector (most of the methods assume this). 19 | 2) As a position in 3d space (which is synonymous with a direction vector from the origin to this position). 20 | 3) To hold three Euler rotations, where X is pitch, Y is yaw and Z is roll. 21 | */ 22 | template 23 | class vector3 24 | { 25 | public: 26 | //! Default constructor (null vector). 27 | vector3() : x(0), y(0), z(0) {} 28 | //! Constructor with three different values 29 | vector3(T nx, T ny, T nz) : x(nx), y(ny), z(nz) {} 30 | //! Constructor with three different values, in array form. 31 | vector3(T p[3]) : x(p[0]), y(p[1]), z(p[2]) {} 32 | //! Constructor with the same value for all elements 33 | explicit vector3(T n) : x(n), y(n), z(n) {} 34 | //! Copy constructor 35 | vector3(const vector3& other) : x(other.x), y(other.y), z(other.z) {} 36 | 37 | // operators 38 | 39 | vector3 operator-() const { return vector3(-x, -y, -z); } 40 | 41 | vector3& operator=(const vector3& other) { x = other.x; y = other.y; z = other.z; return *this; } 42 | 43 | vector3 operator+(const vector3& other) const { return vector3(x + other.x, y + other.y, z + other.z); } 44 | vector3& operator+=(const vector3& other) { x+=other.x; y+=other.y; z+=other.z; return *this; } 45 | vector3 operator+(const T val) const { return vector3(x + val, y + val, z + val); } 46 | vector3& operator+=(const T val) { x+=val; y+=val; z+=val; return *this; } 47 | 48 | vector3 operator-(const vector3& other) const { return vector3(x - other.x, y - other.y, z - other.z); } 49 | vector3& operator-=(const vector3& other) { x-=other.x; y-=other.y; z-=other.z; return *this; } 50 | vector3 operator-(const T val) const { return vector3(x - val, y - val, z - val); } 51 | vector3& operator-=(const T val) { x-=val; y-=val; z-=val; return *this; } 52 | 53 | vector3 operator*(const vector3& other) const { return vector3(x * other.x, y * other.y, z * other.z); } 54 | vector3& operator*=(const vector3& other) { x*=other.x; y*=other.y; z*=other.z; return *this; } 55 | vector3 operator*(const T v) const { return vector3(x * v, y * v, z * v); } 56 | vector3& operator*=(const T v) { x*=v; y*=v; z*=v; return *this; } 57 | 58 | vector3 operator/(const vector3& other) const { return vector3(x / other.x, y / other.y, z / other.z); } 59 | vector3& operator/=(const vector3& other) { x/=other.x; y/=other.y; z/=other.z; return *this; } 60 | vector3 operator/(const T v) const { T i=(T)1.0/v; return vector3(x * i, y * i, z * i); } 61 | vector3& operator/=(const T v) { T i=(T)1.0/v; x*=i; y*=i; z*=i; return *this; } 62 | 63 | //! sort in order X, Y, Z. Equality with rounding tolerance. 64 | bool operator<=(const vector3&other) const 65 | { 66 | return (x=(const vector3&other) const 73 | { 74 | return (x>other.x || core::equals(x, other.x)) || 75 | (core::equals(x, other.x) && (y>other.y || core::equals(y, other.y))) || 76 | (core::equals(x, other.x) && core::equals(y, other.y) && (z>other.z || core::equals(z, other.z))); 77 | } 78 | 79 | //! sort in order X, Y, Z. Difference must be above rounding tolerance. 80 | bool operator<(const vector3&other) const 81 | { 82 | return (x(const vector3&other) const 89 | { 90 | return (x>other.x && !core::equals(x, other.x)) || 91 | (core::equals(x, other.x) && y>other.y && !core::equals(y, other.y)) || 92 | (core::equals(x, other.x) && core::equals(y, other.y) && z>other.z && !core::equals(z, other.z)); 93 | } 94 | 95 | //! use weak float compare 96 | bool operator==(const vector3& other) const 97 | { 98 | return this->equals(other); 99 | } 100 | 101 | bool operator!=(const vector3& other) const 102 | { 103 | return !this->equals(other); 104 | } 105 | 106 | // functions 107 | 108 | //! returns if this vector equals the other one, taking floating point rounding errors into account 109 | bool equals(const vector3& other, const T tolerance = (T)ROUNDING_ERROR_f32 ) const 110 | { 111 | return core::equals(x, other.x, tolerance) && 112 | core::equals(y, other.y, tolerance) && 113 | core::equals(z, other.z, tolerance); 114 | } 115 | 116 | vector3& set(const T nx, const T ny, const T nz) {x=nx; y=ny; z=nz; return *this;} 117 | vector3& set(const vector3& p) {x=p.x; y=p.y; z=p.z;return *this;} 118 | 119 | //! Get length of the vector. 120 | T getLength() const { return core::squareroot( x*x + y*y + z*z ); } 121 | 122 | //! Get squared length of the vector. 123 | /** This is useful because it is much faster than getLength(). 124 | \return Squared length of the vector. */ 125 | T getLengthSQ() const { return x*x + y*y + z*z; } 126 | 127 | //! Get the dot product with another vector. 128 | T dotProduct(const vector3& other) const 129 | { 130 | return x*other.x + y*other.y + z*other.z; 131 | } 132 | 133 | //! Get distance from another point. 134 | /** Here, the vector is interpreted as point in 3 dimensional space. */ 135 | T getDistanceFrom(const vector3& other) const 136 | { 137 | return vector3(x - other.x, y - other.y, z - other.z).getLength(); 138 | } 139 | 140 | //! Returns squared distance from another point. 141 | /** Here, the vector is interpreted as point in 3 dimensional space. */ 142 | T getDistanceFromSQ(const vector3& other) const 143 | { 144 | return vector3(x - other.x, y - other.y, z - other.z).getLengthSQ(); 145 | } 146 | 147 | //! Calculates the cross product with another vector. 148 | /** \param p Vector to multiply with. 149 | \return Crossproduct of this vector with p. */ 150 | vector3 crossProduct(const vector3& p) const 151 | { 152 | return vector3(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x); 153 | } 154 | 155 | //! Returns if this vector interpreted as a point is on a line between two other points. 156 | /** It is assumed that the point is on the line. 157 | \param begin Beginning vector to compare between. 158 | \param end Ending vector to compare between. 159 | \return True if this vector is between begin and end, false if not. */ 160 | bool isBetweenPoints(const vector3& begin, const vector3& end) const 161 | { 162 | const T f = (end - begin).getLengthSQ(); 163 | return getDistanceFromSQ(begin) <= f && 164 | getDistanceFromSQ(end) <= f; 165 | } 166 | 167 | //! Normalizes the vector. 168 | /** In case of the 0 vector the result is still 0, otherwise 169 | the length of the vector will be 1. 170 | \return Reference to this vector after normalization. */ 171 | vector3& normalize() 172 | { 173 | f64 length = x*x + y*y + z*z; 174 | if (length == 0 ) // this check isn't an optimization but prevents getting NAN in the sqrt. 175 | return *this; 176 | length = core::reciprocal_squareroot(length); 177 | 178 | x = (T)(x * length); 179 | y = (T)(y * length); 180 | z = (T)(z * length); 181 | return *this; 182 | } 183 | 184 | //! Return normalized one of the vector. 185 | /** In case of the 0 vector the result is still 0, otherwise 186 | the length of the vector will be 1. 187 | \return The normalized vector. */ 188 | vector3 normalized() const 189 | { 190 | vector3 v = *this; 191 | v.normalize(); 192 | return v; 193 | } 194 | 195 | //! Sets the length of the vector to a new value 196 | vector3& setLength(T newlength) 197 | { 198 | normalize(); 199 | return (*this *= newlength); 200 | } 201 | 202 | //! Inverts the vector. 203 | vector3& invert() 204 | { 205 | x *= -1; 206 | y *= -1; 207 | z *= -1; 208 | return *this; 209 | } 210 | 211 | //! Rotates the vector by a specified number of degrees around the Y axis and the specified center. 212 | /** \param degrees Number of degrees to rotate around the Y axis. 213 | \param center The center of the rotation. */ 214 | void rotateXZBy(f64 degrees, const vector3& center=vector3()) 215 | { 216 | degrees *= DEGTORAD64; 217 | f64 cs = cos(degrees); 218 | f64 sn = sin(degrees); 219 | x -= center.x; 220 | z -= center.z; 221 | set((T)(x*cs - z*sn), y, (T)(x*sn + z*cs)); 222 | x += center.x; 223 | z += center.z; 224 | } 225 | 226 | //! Rotates the vector by a specified number of degrees around the Z axis and the specified center. 227 | /** \param degrees: Number of degrees to rotate around the Z axis. 228 | \param center: The center of the rotation. */ 229 | void rotateXYBy(f64 degrees, const vector3& center=vector3()) 230 | { 231 | degrees *= DEGTORAD64; 232 | f64 cs = cos(degrees); 233 | f64 sn = sin(degrees); 234 | x -= center.x; 235 | y -= center.y; 236 | set((T)(x*cs - y*sn), (T)(x*sn + y*cs), z); 237 | x += center.x; 238 | y += center.y; 239 | } 240 | 241 | //! Rotates the vector by a specified number of degrees around the X axis and the specified center. 242 | /** \param degrees: Number of degrees to rotate around the X axis. 243 | \param center: The center of the rotation. */ 244 | void rotateYZBy(f64 degrees, const vector3& center=vector3()) 245 | { 246 | degrees *= DEGTORAD64; 247 | f64 cs = cos(degrees); 248 | f64 sn = sin(degrees); 249 | z -= center.z; 250 | y -= center.y; 251 | set(x, (T)(y*cs - z*sn), (T)(y*sn + z*cs)); 252 | z += center.z; 253 | y += center.y; 254 | } 255 | 256 | //! Creates an interpolated vector between this vector and another vector. 257 | /** \param other The other vector to interpolate with. 258 | \param d Interpolation value between 0.0f (all the other vector) and 1.0f (all this vector). 259 | Note that this is the opposite direction of interpolation to getInterpolated_quadratic() 260 | \return An interpolated vector. This vector is not modified. */ 261 | vector3 getInterpolated(const vector3& other, f64 d) const 262 | { 263 | const f64 inv = 1.0 - d; 264 | return vector3((T)(other.x*inv + x*d), (T)(other.y*inv + y*d), (T)(other.z*inv + z*d)); 265 | } 266 | 267 | //! Creates a quadratically interpolated vector between this and two other vectors. 268 | /** \param v2 Second vector to interpolate with. 269 | \param v3 Third vector to interpolate with (maximum at 1.0f) 270 | \param d Interpolation value between 0.0f (all this vector) and 1.0f (all the 3rd vector). 271 | Note that this is the opposite direction of interpolation to getInterpolated() and interpolate() 272 | \return An interpolated vector. This vector is not modified. */ 273 | vector3 getInterpolated_quadratic(const vector3& v2, const vector3& v3, f64 d) const 274 | { 275 | // this*(1-d)*(1-d) + 2 * v2 * (1-d) + v3 * d * d; 276 | const f64 inv = (T) 1.0 - d; 277 | const f64 mul0 = inv * inv; 278 | const f64 mul1 = (T) 2.0 * d * inv; 279 | const f64 mul2 = d * d; 280 | 281 | return vector3 ((T)(x * mul0 + v2.x * mul1 + v3.x * mul2), 282 | (T)(y * mul0 + v2.y * mul1 + v3.y * mul2), 283 | (T)(z * mul0 + v2.z * mul1 + v3.z * mul2)); 284 | } 285 | 286 | //! Sets this vector to the linearly interpolated vector between a and b. 287 | /** \param a first vector to interpolate with, maximum at 1.0f 288 | \param b second vector to interpolate with, maximum at 0.0f 289 | \param d Interpolation value between 0.0f (all vector b) and 1.0f (all vector a) 290 | Note that this is the opposite direction of interpolation to getInterpolated_quadratic() 291 | */ 292 | vector3& interpolate(const vector3& a, const vector3& b, f64 d) 293 | { 294 | x = (T)((f64)b.x + ( ( a.x - b.x ) * d )); 295 | y = (T)((f64)b.y + ( ( a.y - b.y ) * d )); 296 | z = (T)((f64)b.z + ( ( a.z - b.z ) * d )); 297 | return *this; 298 | } 299 | 300 | 301 | //! Get the rotations that would make a (0,0,1) direction vector point in the same direction as this direction vector. 302 | /** Thanks to Arras on the Irrlicht forums for this method. This utility method is very useful for 303 | orienting scene nodes towards specific targets. For example, if this vector represents the difference 304 | between two scene nodes, then applying the result of getHorizontalAngle() to one scene node will point 305 | it at the other one. 306 | Example code: 307 | // Where target and seeker are of type ISceneNode* 308 | const vector3f toTarget(target->getAbsolutePosition() - seeker->getAbsolutePosition()); 309 | const vector3f requiredRotation = toTarget.getHorizontalAngle(); 310 | seeker->setRotation(requiredRotation); 311 | 312 | \return A rotation vector containing the X (pitch) and Y (raw) rotations (in degrees) that when applied to a 313 | +Z (e.g. 0, 0, 1) direction vector would make it point in the same direction as this vector. The Z (roll) rotation 314 | is always 0, since two Euler rotations are sufficient to point in any given direction. */ 315 | vector3 getHorizontalAngle() const 316 | { 317 | vector3 angle; 318 | 319 | const f64 tmp = (atan2((f64)x, (f64)z) * RADTODEG64); 320 | angle.y = (T)tmp; 321 | 322 | if (angle.y < 0) 323 | angle.y += 360; 324 | if (angle.y >= 360) 325 | angle.y -= 360; 326 | 327 | const f64 z1 = core::squareroot(x*x + z*z); 328 | 329 | angle.x = (T)(atan2((f64)z1, (f64)y) * RADTODEG64 - 90.0); 330 | 331 | if (angle.x < 0) 332 | angle.x += 360; 333 | if (angle.x >= 360) 334 | angle.x -= 360; 335 | 336 | return angle; 337 | } 338 | 339 | //! Get the spherical coordinate angles 340 | /** This returns Euler degrees for the point represented by 341 | this vector. The calculation assumes the pole at (0,1,0) and 342 | returns the angles in X and Y. 343 | */ 344 | vector3 getSphericalCoordinateAngles() const 345 | { 346 | vector3 angle; 347 | const f64 length = x*x + y*y + z*z; 348 | 349 | if (length) 350 | { 351 | if (x!=0) 352 | { 353 | angle.y = (T)(atan2((f64)z,(f64)x) * RADTODEG64); 354 | } 355 | else if (z<0) 356 | angle.y=180; 357 | 358 | angle.x = (T)(acos(y * core::reciprocal_squareroot(length)) * RADTODEG64); 359 | } 360 | return angle; 361 | } 362 | 363 | //! Builds a direction vector from (this) rotation vector. 364 | /** This vector is assumed to be a rotation vector composed of 3 Euler angle rotations, in degrees. 365 | The implementation performs the same calculations as using a matrix to do the rotation. 366 | 367 | \param[in] forwards The direction representing "forwards" which will be rotated by this vector. 368 | If you do not provide a direction, then the +Z axis (0, 0, 1) will be assumed to be forwards. 369 | \return A direction vector calculated by rotating the forwards direction by the 3 Euler angles 370 | (in degrees) represented by this vector. */ 371 | vector3 rotationToDirection(const vector3 & forwards = vector3(0, 0, 1)) const 372 | { 373 | const f64 cr = cos( core::DEGTORAD64 * x ); 374 | const f64 sr = sin( core::DEGTORAD64 * x ); 375 | const f64 cp = cos( core::DEGTORAD64 * y ); 376 | const f64 sp = sin( core::DEGTORAD64 * y ); 377 | const f64 cy = cos( core::DEGTORAD64 * z ); 378 | const f64 sy = sin( core::DEGTORAD64 * z ); 379 | 380 | const f64 srsp = sr*sp; 381 | const f64 crsp = cr*sp; 382 | 383 | const f64 pseudoMatrix[] = { 384 | ( cp*cy ), ( cp*sy ), ( -sp ), 385 | ( srsp*cy-cr*sy ), ( srsp*sy+cr*cy ), ( sr*cp ), 386 | ( crsp*cy+sr*sy ), ( crsp*sy-sr*cy ), ( cr*cp )}; 387 | 388 | return vector3( 389 | (T)(forwards.x * pseudoMatrix[0] + 390 | forwards.y * pseudoMatrix[3] + 391 | forwards.z * pseudoMatrix[6]), 392 | (T)(forwards.x * pseudoMatrix[1] + 393 | forwards.y * pseudoMatrix[4] + 394 | forwards.z * pseudoMatrix[7]), 395 | (T)(forwards.x * pseudoMatrix[2] + 396 | forwards.y * pseudoMatrix[5] + 397 | forwards.z * pseudoMatrix[8])); 398 | } 399 | 400 | //! Fills an array of 4 values with the vector data (usually floats). 401 | /** Useful for setting in shader constants for example. The fourth value 402 | will always be 0. */ 403 | void getAs4Values(T* array) const 404 | { 405 | array[0] = x; 406 | array[1] = y; 407 | array[2] = z; 408 | array[3] = 0; 409 | } 410 | 411 | //! Fills an array of 3 values with the vector data (usually floats). 412 | /** Useful for setting in shader constants for example.*/ 413 | void getAs3Values(T* array) const 414 | { 415 | array[0] = x; 416 | array[1] = y; 417 | array[2] = z; 418 | } 419 | 420 | //! Returns value by index. Note that x, y, z are assumed to be consecutive in memory. 421 | T& operator[] (int idx) 422 | { 423 | assert(0 <= idx && idx < 3); 424 | return *(&x + idx); 425 | } 426 | 427 | const T& operator[] (int idx) const 428 | { 429 | assert(0 <= idx && idx < 3); 430 | return *(&x + idx); 431 | } 432 | 433 | 434 | //! X coordinate of the vector 435 | T x; 436 | 437 | //! Y coordinate of the vector 438 | T y; 439 | 440 | //! Z coordinate of the vector 441 | T z; 442 | }; 443 | 444 | //! partial specialization for integer vectors 445 | // Implementor note: inline keyword needed due to template specialization for s32. Otherwise put specialization into a .cpp 446 | template <> 447 | inline vector3 vector3::operator /(s32 val) const {return core::vector3(x/val,y/val,z/val);} 448 | template <> 449 | inline vector3& vector3::operator /=(s32 val) {x/=val;y/=val;z/=val; return *this;} 450 | 451 | template <> 452 | inline vector3 vector3::getSphericalCoordinateAngles() const 453 | { 454 | vector3 angle; 455 | const f64 length = x*x + y*y + z*z; 456 | 457 | if (length) 458 | { 459 | if (x!=0) 460 | { 461 | angle.y = round32((f32)(atan2((f64)z,(f64)x) * RADTODEG64)); 462 | } 463 | else if (z<0) 464 | angle.y=180; 465 | 466 | angle.x = round32((f32)(acos(y * core::reciprocal_squareroot(length)) * RADTODEG64)); 467 | } 468 | return angle; 469 | } 470 | 471 | //! Typedef for a f32 3d vector. 472 | typedef vector3 vector3f; 473 | 474 | //! Typedef for a f32 3d vector. 475 | typedef vector3 vector3d; 476 | 477 | //! Typedef for an integer 3d vector. 478 | typedef vector3 vector3i; 479 | 480 | //! Function multiplying a scalar and a vector component-wise. 481 | template 482 | vector3 operator*(const S scalar, const vector3& vector) { return vector*scalar; } 483 | 484 | } // end namespace core 485 | } // end namespace irr 486 | 487 | #endif 488 | 489 | -------------------------------------------------------------------------------- /src/AbstractInputProcessor.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/AbstractInputProcessor.cpp -------------------------------------------------------------------------------- /src/AbstractInputProcessor.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/AbstractInputProcessor.h -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(AlgorithmSDK) 2 | CMAKE_MINIMUM_REQUIRED(VERSION 3.5) 3 | MESSAGE(STATUS "Make AlgorithmSDK start") 4 | ADD_DEFINITIONS("-DALGORITHMDLL_EXPORTS") 5 | # Prerelease flag is for internal only. Conan will enable if developing. 6 | OPTION(ALGORITHMDLL_PRERELEASE "ALGORITHMDLL_PRERELEASE" OFF) 7 | MESSAGE(STATUS "ALGORITHMDLL_PRERELEASE = " ${ALGORITHMDLL_PRERELEASE}) 8 | IF(ALGORITHMDLL_PRERELEASE) 9 | ADD_DEFINITIONS("-DALGORITHMDLL_PRERELEASE") 10 | ENDIF() 11 | INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}) 12 | INCLUDE_DIRECTORIES(${EXTERNAL_ROOT_DIR}/Irrlicht-math/include) 13 | AUX_SOURCE_DIRECTORY(. LIB_ALGORITHMSDK_SOURCE) 14 | #Display the .h and .hpp files in the project. 15 | FILE (GLOB_RECURSE LIB_ALGORITHMSDK_HEADER "*.[h,hpp]") 16 | FILE (GLOB_RECURSE LIB_IRRLICHT_HEADER "${EXTERNAL_ROOT_DIR}/Irrlicht-math/include/*.[h,hpp]") 17 | 18 | ADD_DEFINITIONS("-DLIBALGORITHMSDK_BUILD") 19 | 20 | SET(ALGORITHMSDK_BUILD_SOURCE 21 | ${LIB_ALGORITHMSDK_SOURCE} 22 | ${PROJECT_SOURCE_DIR}/version.rc 23 | ${LIB_ALGORITHMSDK_HEADER} 24 | ${LIB_IRRLICHT_HEADER}) 25 | 26 | # Build an object for unit test to reuse. (For unit testing.) 27 | ADD_LIBRARY(ALGORITHMSDK_BUILD_OBJECT OBJECT ${ALGORITHMSDK_BUILD_SOURCE}) 28 | # Link the object to generate a DLL. 29 | ADD_LIBRARY(AlgorithmSDK SHARED $) 30 | 31 | TARGET_LINK_LIBRARIES(AlgorithmSDK ${LIB_SOURCE_LIB} ${CONAN_LIBS}) 32 | 33 | SET_TARGET_PROPERTIES(AlgorithmSDK PROPERTIES OUTPUT_NAME "AlgorithmSDK") 34 | MESSAGE(STATUS "Make AlgorithmSDK done") 35 | -------------------------------------------------------------------------------- /src/DualQuat.h: -------------------------------------------------------------------------------- 1 | /************************************************************************/ 2 | /* https://github.com/gravitino/dualQuaternion */ 3 | /************************************************************************/ 4 | #ifndef DUALQUAT_HPP 5 | #define DUALQUAT_HPP 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #define EPS(value_t) (std::numeric_limits::epsilon()) 15 | 16 | template 17 | struct quat { 18 | 19 | value_t w, x, y, z; 20 | 21 | quat(bool e = 1) : w(e), x(0), y(0), z(0) {} 22 | 23 | quat(value_t w_, 24 | value_t x_, 25 | value_t y_, 26 | value_t z_) : w(w_), x(x_), y(y_), z(z_) {} 27 | 28 | void print() const { 29 | std::cout << "(" << w << "," << x 30 | << "," << y << "," << z 31 | << ")" << std::endl; 32 | } 33 | 34 | quat operator+(const quat& other) const { 35 | return quat(w + other.w, x + other.x, 36 | y + other.y, z + other.z); 37 | } 38 | 39 | quat& operator+=(const quat& other) { 40 | w += other.w; x += other.x; y += other.y; z += other.z; 41 | return *this; 42 | } 43 | 44 | quat operator-(const quat& other) const { 45 | return quat(w - other.w, x - other.x, 46 | y - other.y, z - other.z); 47 | } 48 | 49 | quat& operator-=(const quat& other) { 50 | w -= other.w; x -= other.x; y -= other.y; z -= other.z; 51 | return *this; 52 | } 53 | 54 | quat operator*(const quat& other) const { 55 | return quat(w*other.w - x*other.x - y*other.y - z*other.z, 56 | w*other.x + other.w*x + y*other.z - z*other.y, 57 | w*other.y + other.w*y + z*other.x - x*other.z, 58 | w*other.z + other.w*z + x*other.y - y*other.x); 59 | } 60 | 61 | quat& operator*=(const quat& other) { 62 | *this = (*this)*other; 63 | return *this; 64 | } 65 | 66 | quat operator*(const value_t alpha) const { 67 | return quat(w*alpha, x*alpha, 68 | y*alpha, z*alpha); 69 | } 70 | 71 | quat operator/(const value_t alpha) const { 72 | return quat(w / alpha, x / alpha, 73 | y / alpha, z / alpha); 74 | } 75 | 76 | quat N() const { 77 | const value_t rho = std::sqrt(w*w + x*x + y*y + z*z); 78 | return quat(w / rho, x / rho, y / rho, z / rho); 79 | } 80 | 81 | quat C() const { 82 | return quat(w, -x, -y, -z); 83 | } 84 | 85 | quat I() const { 86 | const value_t rho2 = w*w + x*x + y*y + z*z; 87 | return quat(w / rho2, -x / rho2, -y / rho2, -z / rho2); 88 | } 89 | 90 | quat exp() const { 91 | 92 | assert(w*w < EPS(value_t)); 93 | 94 | value_t dst = std::sqrt(x*x + y*y + z*z); 95 | value_t fac = std::sin(dst) / dst; 96 | 97 | return quat(std::cos(dst), x*fac, y*fac, z*fac); 98 | } 99 | 100 | quat numexp(value_t eps = EPS(value_t)) const { 101 | 102 | quat pow; 103 | quat sum; 104 | size_t i = 1; 105 | 106 | while (pow.dot(pow) > eps) { 107 | pow *= (*this) / i++; 108 | sum += pow; 109 | } 110 | 111 | return sum; 112 | } 113 | 114 | quat log() const { 115 | 116 | assert(isunit()); 117 | 118 | if ((w*w - 1)*(w*w - 1) < EPS(value_t)) 119 | return quat(0); 120 | 121 | const value_t inv = 1.0 / std::sqrt(x*x + y*y + z*z); 122 | const value_t fac = std::acos(w)*inv; 123 | 124 | return quat(0, x*fac, y*fac, z*fac); 125 | } 126 | 127 | value_t dot(const quat other) const { 128 | return w*other.w + x*other.x + y*other.y + z*other.z; 129 | } 130 | 131 | value_t eucnorm() const { 132 | return dot(*this); 133 | } 134 | 135 | value_t lognorm() const { 136 | const auto& generator = log(); 137 | return generator.dot(generator); 138 | } 139 | 140 | value_t eucdist(const quat& other) const { 141 | 142 | if (dot(other) < 0.0) { 143 | const auto& difference = (*this) + other; 144 | return difference.dot(difference); 145 | } 146 | 147 | const auto& difference = (*this) - other; 148 | return difference.dot(difference); 149 | } 150 | 151 | value_t logdist(const quat& other) const { 152 | const auto& difference = ((*this)*(other.C())).log(); 153 | return difference.dot(difference); 154 | } 155 | 156 | bool isunit() const { 157 | const value_t residue = w*w + x*x + y*y + z*z - 1.0; 158 | return residue*residue < EPS(value_t); 159 | } 160 | }; 161 | 162 | template 163 | struct dualquat { 164 | 165 | value_t w, x, y, z, W, X, Y, Z; 166 | 167 | dualquat(bool e = true) : w(e), x(0), y(0), z(0), 168 | W(0), X(0), Y(0), Z(0) {}; 169 | 170 | dualquat(const value_t w_, 171 | const value_t x_, 172 | const value_t y_, 173 | const value_t z_, 174 | const value_t W_, 175 | const value_t X_, 176 | const value_t Y_, 177 | const value_t Z_) : w(w_), x(x_), y(y_), z(z_), 178 | W(W_), X(X_), Y(Y_), Z(Z_) {} 179 | 180 | dualquat(const quat& real, 181 | const quat& dual) : w(real.w), x(real.x), 182 | y(real.y), z(real.z), 183 | W(dual.w), X(dual.x), 184 | Y(dual.y), Z(dual.z) {} 185 | 186 | dualquat(const quat& real, 187 | value_t x, value_t y, value_t z) : w(real.w), x(real.x), 188 | y(real.y), z(real.z) 189 | { 190 | quat tmp(0, x, y, z); 191 | auto m_dual = (tmp * real) * 0.5f; 192 | X = m_dual.x; 193 | Y = m_dual.y; 194 | Z = m_dual.z; 195 | W = m_dual.w; 196 | } 197 | 198 | quat real() const { 199 | return quat(w, x, y, z); 200 | } 201 | 202 | quat dual() const { 203 | return quat(W, X, Y, Z); 204 | } 205 | 206 | void print() const { 207 | std::cout << "(" << w << "," << x 208 | << "," << y << "," << z 209 | << "," << W << "," << X 210 | << "," << Y << "," << Z 211 | << ")" << std::endl; 212 | } 213 | 214 | dualquat operator+(const dualquat& other) const { 215 | return dualquat(w + other.w, x + other.x, 216 | y + other.y, z + other.z, 217 | W + other.W, X + other.X, 218 | Y + other.Y, Z + other.Z); 219 | } 220 | 221 | dualquat& operator+=(const dualquat& other) { 222 | w += other.w; x += other.x; y += other.y; z += other.z; 223 | W += other.W; X += other.X; Y += other.Y; Z += other.Z; 224 | return *this; 225 | } 226 | 227 | dualquat operator-(const dualquat& other) const { 228 | return dualquat(w - other.w, x - other.x, 229 | y - other.y, z - other.z, 230 | W - other.W, X - other.X, 231 | Y - other.Y, Z - other.Z); 232 | } 233 | 234 | dualquat& operator-=(const dualquat& other) { 235 | w -= other.w; x -= other.x; y -= other.y; z -= other.z; 236 | W -= other.W; X -= other.X; Y -= other.Y; Z -= other.Z; 237 | return *this; 238 | } 239 | 240 | // TODO: expand this 241 | dualquat operator*(const dualquat& other) const { 242 | 243 | const auto& a = real(); 244 | const auto& A = dual(); 245 | const auto& b = other.real(); 246 | const auto& B = other.dual(); 247 | 248 | return dualquat(a*b, (a*B) + (A*b)); 249 | } 250 | 251 | dualquat& operator*=(const dualquat& other) { 252 | *this = (*this)*other; 253 | return *this; 254 | } 255 | 256 | dualquat operator*(const value_t alpha) const { 257 | return dualquat(w*alpha, x*alpha, 258 | y*alpha, z*alpha, 259 | W*alpha, X*alpha, 260 | Y*alpha, Z*alpha); 261 | } 262 | 263 | dualquat operator/(const value_t alpha) const { 264 | return dualquat(w / alpha, x / alpha, 265 | y / alpha, z / alpha, 266 | W / alpha, X / alpha, 267 | Y / alpha, Z / alpha); 268 | } 269 | 270 | dualquat N() const { 271 | 272 | const value_t qq = w*w + x*x + y*y + z*z + EPS(value_t); 273 | const value_t qQ = w*W + x*X + y*Y + z*Z; 274 | const value_t invqq = 1.0 / qq; 275 | const value_t invsq = 1.0 / std::sqrt(qq); 276 | const value_t alpha = qQ*invqq*invsq; 277 | 278 | return dualquat(w*invsq, x*invsq, 279 | y*invsq, z*invsq, 280 | W*invsq - w*alpha, X*invsq - x*alpha, 281 | Y*invsq - y*alpha, Z*invsq - z*alpha); 282 | } 283 | 284 | dualquat C() const { 285 | return dualquat(w, -x, -y, -z, W, -X, -Y, -Z); 286 | } 287 | 288 | dualquat D() const { 289 | return dualquat(w, x, y, z, -W, -X, -Y, -Z); 290 | } 291 | 292 | dualquat I() const { 293 | 294 | const value_t qq = w*w + x*x + y*y + z*z; 295 | const value_t qQ = w*W + x*X + y*Y + z*Z; 296 | const value_t invqq = 1.0 / qq; 297 | const value_t alpha = 2.0*qQ*invqq*invqq; 298 | 299 | return dualquat(w*invqq, -x*invqq, 300 | -y*invqq, -z*invqq, 301 | W*invqq - w*alpha, -X*invqq - x*alpha, 302 | -Y*invqq - y*alpha, -Z*invqq - z*alpha); 303 | } 304 | 305 | dualquat exp() const { 306 | 307 | assert(w*w < EPS(value_t) && W*W < EPS(value_t)); 308 | 309 | if (x*x + y*y + z*z < EPS(value_t)) 310 | return dualquat(1, 0, 0, 0, 0, X, Y, Z); 311 | 312 | const value_t theta = 2.0*std::sqrt(x*x + y*y + z*z); 313 | const value_t invvv = 2.0 / theta; 314 | const value_t lx = x*invvv; 315 | const value_t ly = y*invvv; 316 | const value_t lz = z*invvv; 317 | 318 | const value_t pitch = 2.0*(lx*X + ly*Y + lz*Z); 319 | const value_t mx = (2.0*X - pitch*lx) / theta; 320 | const value_t my = (2.0*Y - pitch*ly) / theta; 321 | const value_t mz = (2.0*Z - pitch*lz) / theta; 322 | 323 | assert((lx*mx + ly*my + lz*mz)*(lx*mx + ly*my + lz*mz) < EPS(value_t)); 324 | 325 | const value_t cost2 = std::cos(0.5*theta); 326 | const value_t sint2 = std::sin(0.5*theta); 327 | const value_t alpha = 0.5*pitch*cost2; 328 | 329 | 330 | return dualquat(cost2, 331 | sint2*lx, 332 | sint2*ly, 333 | sint2*lz, 334 | -0.5*pitch*sint2, 335 | sint2*mx + alpha*lx, 336 | sint2*my + alpha*ly, 337 | sint2*mz + alpha*lz); 338 | } 339 | 340 | dualquat numexp(value_t eps = EPS(value_t)) const { 341 | 342 | dualquat pow; 343 | dualquat sum; 344 | size_t i = 1; 345 | 346 | while (pow.dot(pow) > eps) { 347 | pow *= (*this) / i++; 348 | sum += pow; 349 | } 350 | 351 | return sum; 352 | } 353 | 354 | dualquat log() const { 355 | 356 | assert(isunit()); 357 | 358 | if ((w*w - 1)*(w*w - 1) < EPS(value_t)) 359 | return dualquat(0, 0, 0, 0, 0, X, Y, Z); 360 | 361 | const value_t theta = 2.0*std::acos(w); 362 | const value_t invvv = 0.5 / std::sqrt(x*x + y*y + z*z); 363 | const value_t pitch = -4.0*W*invvv; 364 | const value_t alpha = pitch*w; 365 | 366 | const value_t lx = x*invvv; 367 | const value_t ly = y*invvv; 368 | const value_t lz = z*invvv; 369 | const value_t mx = (X - lx*alpha)*invvv; 370 | const value_t my = (Y - ly*alpha)*invvv; 371 | const value_t mz = (Z - lz*alpha)*invvv; 372 | 373 | assert((lx*mx + ly*my + lz*mz)*(lx*mx + ly*my + lz*mz) < EPS(value_t)); 374 | 375 | return dualquat(0, theta*lx, 376 | theta*ly, 377 | theta*lz, 378 | 0, (pitch*lx + theta*mx), 379 | (pitch*ly + theta*my), 380 | (pitch*lz + theta*mz)); 381 | 382 | } 383 | 384 | dualquat fakelog() const { 385 | 386 | assert(isunit()); 387 | 388 | const auto& lower = real().log(); 389 | const auto& upper = dual()*real().C(); 390 | 391 | return dualquat(lower, upper); 392 | } 393 | 394 | value_t dot(const dualquat other) const { 395 | return w*other.w + x*other.x + y*other.y + z*other.z + 396 | W*other.W + X*other.X + Y*other.Y + Z*other.Z; 397 | } 398 | 399 | value_t eucnorm() const { 400 | return dot(*this); 401 | } 402 | 403 | value_t lognorm() const { 404 | const auto& generator = log(); 405 | return generator.dot(generator); 406 | } 407 | 408 | value_t kinnorm() const { 409 | const auto& generator = fakelog(); 410 | return generator.dot(generator); 411 | } 412 | 413 | value_t eucdist(const dualquat& other) const { 414 | 415 | // TODO: could still be errornous 416 | if (dot(other) < 0.0) { 417 | const auto& difference = (*this) + other; 418 | return difference.dot(difference); 419 | } 420 | 421 | const auto& difference = (*this) - other; 422 | return difference.dot(difference); 423 | } 424 | 425 | value_t logdist(const dualquat& other) const { 426 | const auto& difference = ((*this)*(other.C())).log(); 427 | return difference.dot(difference); 428 | } 429 | 430 | value_t kindist(const dualquat& other) const { 431 | const auto& difference = ((*this)*(other.C())).fakelog(); 432 | return difference.dot(difference); 433 | } 434 | 435 | bool isunit() const { 436 | 437 | const value_t residue0 = w*w + x*x + y*y + z*z - 1.0; 438 | const value_t residue1 = w*W + x*X + y*Y + z*Z; 439 | 440 | return residue0*residue0 < EPS(value_t) && 441 | residue1*residue1 < EPS(value_t); 442 | } 443 | 444 | quat getPositionQuat() 445 | { 446 | return (dual() * 2.0f) * (real().C()); 447 | } 448 | 449 | }; 450 | 451 | 452 | namespace average { 453 | 454 | template 455 | quat QLA(const std::vector>& quats) { 456 | 457 | quat result(0); 458 | 459 | for (size_t i = 0; i < quats.size(); i++) 460 | result += quats[i]; 461 | 462 | return result.N(); 463 | } 464 | 465 | template 466 | quat QIA(const std::vector>& quats) { 467 | 468 | quat b = QLA(quats); 469 | 470 | auto logmean = [&]() { 471 | quat avg(0); 472 | for (size_t i = 0; i < quats.size(); i++) 473 | avg += (b.C()*quats[i]).log(); 474 | return avg / quats.size(); 475 | }; 476 | 477 | auto x = logmean(); 478 | auto norm = x.dot(x); 479 | 480 | for (;;){ 481 | 482 | b *= x.exp(); 483 | auto xnew = logmean(); 484 | 485 | const auto newnorm = xnew.dot(xnew); 486 | if (norm < newnorm || newnorm < EPS(value_t)) 487 | break; 488 | else { 489 | x = xnew; 490 | norm = newnorm; 491 | } 492 | } 493 | 494 | return b; 495 | } 496 | 497 | template 498 | quat QLB(const std::vector>& quats, 499 | const std::vector& weights) { 500 | 501 | assert(quats.size() == weights.size()); 502 | 503 | quat result(0); 504 | 505 | for (size_t i = 0; i < quats.size(); i++) 506 | result += quats[i] * weights[i]; 507 | 508 | return result.N(); 509 | } 510 | 511 | template 512 | quat QIB(const std::vector>& quats, 513 | const std::vector& weights) { 514 | 515 | 516 | assert(quats.size() == weights.size()); 517 | 518 | quat b = QLB(quats, weights); 519 | 520 | auto logmean = [&]() { 521 | quat avg(0); 522 | for (size_t i = 0; i < quats.size(); i++) 523 | avg += ((b.C())*quats[i]).log()*weights[i]; 524 | return avg; 525 | }; 526 | 527 | auto x = logmean(); 528 | auto norm = x.dot(x); 529 | 530 | for (;;){ 531 | 532 | b *= x.exp(); 533 | auto xnew = logmean(); 534 | 535 | const auto newnorm = xnew.dot(xnew); 536 | if (norm < newnorm || newnorm < EPS(value_t)) 537 | break; 538 | else { 539 | x = xnew; 540 | norm = newnorm; 541 | } 542 | } 543 | 544 | return b; 545 | } 546 | 547 | template 548 | dualquat DLA(const std::vector>& quats) { 549 | 550 | dualquat result(0); 551 | 552 | for (size_t i = 0; i < quats.size(); i++) 553 | result += quats[i]; 554 | 555 | return (result).N(); 556 | } 557 | 558 | template 559 | dualquat DIA(const std::vector>& quats) { 560 | 561 | dualquat b = DLA(quats); 562 | 563 | auto logmean = [&]() { 564 | dualquat avg(0); 565 | for (size_t i = 0; i < quats.size(); i++) 566 | avg += (b.C()*quats[i]).log(); 567 | return avg / quats.size(); 568 | }; 569 | 570 | auto x = logmean(); 571 | auto norm = x.dot(x); 572 | 573 | for (;;){ 574 | 575 | b *= x.numexp(); 576 | auto xnew = logmean(); 577 | 578 | const auto newnorm = xnew.dot(xnew); 579 | if (norm < newnorm || newnorm < EPS(value_t)) 580 | break; 581 | else { 582 | x = xnew; 583 | norm = newnorm; 584 | } 585 | } 586 | 587 | // std::cout << "precision: " << norm << std::endl; 588 | 589 | return b; 590 | } 591 | 592 | template 593 | dualquat DLB(const std::vector>& quats, 594 | const std::vector& weights) { 595 | 596 | assert(quats.size() == weights.size()); 597 | 598 | dualquat result(0); 599 | 600 | for (size_t i = 0; i < quats.size(); i++) 601 | result += quats[i] * weights[i]; 602 | 603 | return result.N(); 604 | } 605 | 606 | template 607 | dualquat DIB(const std::vector>& quats, 608 | const std::vector& weights) { 609 | 610 | 611 | assert(quats.size() == weights.size()); 612 | 613 | dualquat b = DLB(quats, weights); 614 | 615 | auto logmean = [&]() { 616 | dualquat avg(0); 617 | for (size_t i = 0; i < quats.size(); i++) 618 | avg += ((b.C())*quats[i]).log()*weights[i]; 619 | return avg; 620 | }; 621 | 622 | auto x = logmean(); 623 | auto norm = x.dot(x); 624 | 625 | for (;;){ 626 | 627 | b *= x.numexp(); 628 | auto xnew = logmean(); 629 | 630 | const auto newnorm = xnew.dot(xnew); 631 | if (norm < newnorm || newnorm < EPS(value_t)) 632 | break; 633 | else { 634 | x = xnew; 635 | norm = newnorm; 636 | } 637 | 638 | } 639 | 640 | // std::cout << "precision: " << norm << std::endl; 641 | 642 | return b; 643 | } 644 | 645 | 646 | } 647 | 648 | typedef dualquat dualquatd; 649 | typedef quat quatd; 650 | 651 | #endif -------------------------------------------------------------------------------- /src/IMURotationModel.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/IMURotationModel.cpp -------------------------------------------------------------------------------- /src/IMURotationModel.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/IMURotationModel.h -------------------------------------------------------------------------------- /src/InternalVariables.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/InternalVariables.cpp -------------------------------------------------------------------------------- /src/InternalVariables.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/InternalVariables.h -------------------------------------------------------------------------------- /src/LHTrackingAlgorithm.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/LHTrackingAlgorithm.cpp -------------------------------------------------------------------------------- /src/LHTrackingAlgorithm.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/LHTrackingAlgorithm.h -------------------------------------------------------------------------------- /src/LightHouseData.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/LightHouseData.h -------------------------------------------------------------------------------- /src/LighthouseInputProcessor.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/LighthouseInputProcessor.cpp -------------------------------------------------------------------------------- /src/LighthouseInputProcessor.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/LighthouseInputProcessor.h -------------------------------------------------------------------------------- /src/MoveDetector.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/MoveDetector.cpp -------------------------------------------------------------------------------- /src/MoveDetector.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/MoveDetector.h -------------------------------------------------------------------------------- /src/PresampleDataLoader.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/PresampleDataLoader.cpp -------------------------------------------------------------------------------- /src/PresampleDataLoader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/PresampleDataLoader.h -------------------------------------------------------------------------------- /src/RingBufferDataLoader.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/RingBufferDataLoader.cpp -------------------------------------------------------------------------------- /src/RingBufferDataLoader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/RingBufferDataLoader.h -------------------------------------------------------------------------------- /src/SafeFlag.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | /** 6 | * A thread-safe flag for multiple threads to wait for some condition. 7 | * References: 8 | * http://en.cppreference.com/w/cpp/thread/condition_variable 9 | * http://stackoverflow.com/questions/14920725/waiting-for-an-atomic-bool 10 | */ 11 | class SafeFlag 12 | { 13 | mutable std::mutex mtx; 14 | mutable std::condition_variable cv; 15 | bool flag; 16 | 17 | public: 18 | SafeFlag() 19 | : flag(false) 20 | {} 21 | 22 | bool is_set() const 23 | { 24 | std::lock_guard lock(mtx); 25 | return flag; 26 | } 27 | 28 | void set() 29 | { 30 | { 31 | std::lock_guard lock(mtx); 32 | flag = true; 33 | } 34 | cv.notify_all(); 35 | } 36 | 37 | void reset() 38 | { 39 | { 40 | std::lock_guard lock(mtx); 41 | flag = false; 42 | } 43 | cv.notify_all(); 44 | } 45 | 46 | // Block until flag is set. 47 | void wait() const 48 | { 49 | std::unique_lock lock(mtx); 50 | cv.wait(lock, [this] { return flag; }); 51 | } 52 | 53 | template 54 | bool wait_for(const std::chrono::duration& rel_time) const 55 | { 56 | std::unique_lock lock(mtx); 57 | return cv.wait_for(lock, rel_time, [this] { return flag; }); 58 | } 59 | 60 | template 61 | bool wait_until(const std::chrono::duration& rel_time) const 62 | { 63 | std::unique_lock lock(mtx); 64 | return cv.wait_until(lock, rel_time, [this] { return flag; }); 65 | } 66 | }; 67 | -------------------------------------------------------------------------------- /src/SensorDataInterpretor.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/SensorDataInterpretor.cpp -------------------------------------------------------------------------------- /src/SensorDataInterpretor.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/SensorDataInterpretor.h -------------------------------------------------------------------------------- /src/TO_HMD.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/TO_HMD.cpp -------------------------------------------------------------------------------- /src/TO_HMD.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/TO_HMD.h -------------------------------------------------------------------------------- /src/TimeManager.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/TimeManager.cpp -------------------------------------------------------------------------------- /src/TimeManager.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/TimeManager.h -------------------------------------------------------------------------------- /src/TrackObject.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/TrackObject.cpp -------------------------------------------------------------------------------- /src/TrackObject.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/TrackObject.h -------------------------------------------------------------------------------- /src/TrackObjectManager.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/TrackObjectManager.cpp -------------------------------------------------------------------------------- /src/TrackObjectManager.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/TrackObjectManager.h -------------------------------------------------------------------------------- /src/TrackingDataLoader.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/TrackingDataLoader.cpp -------------------------------------------------------------------------------- /src/TrackingDataLoader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/TrackingDataLoader.h -------------------------------------------------------------------------------- /src/internal.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/internal.h -------------------------------------------------------------------------------- /src/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by version.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /src/ringbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | A simple ring buffer implementation as C++ template. 3 | 4 | Copyright (c) 2011 Hannes Flicka 5 | Licensed under the terms of the MIT license (given below). 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | #ifndef RINGBUFFER_H 27 | #define RINGBUFFER_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | //#define min(a,b) a class ringbuffer { 37 | public: 38 | /** 39 | * create a ringbuffer with space for up to size elements. 40 | */ 41 | explicit ringbuffer(size_t size) 42 | : size(size) 43 | , begin(0) 44 | , end(0) 45 | , wrap(false) 46 | { 47 | buffer = new T[size]; 48 | 49 | hsem_empty = CreateSemaphore(NULL, 0, size, NULL); 50 | } 51 | 52 | /** 53 | * copy constructor 54 | */ 55 | ringbuffer(const ringbuffer & rb) 56 | { 57 | this(rb.size); 58 | begin = rb.begin; 59 | end = rb.end; 60 | hsem_empty = CreateSemaphore(NULL, 0, size, NULL); 61 | memcpy(buffer, rb.buffer, sizeof(T) * size); 62 | } 63 | 64 | /** 65 | * destructor 66 | */ 67 | ~ringbuffer() 68 | { 69 | delete[] buffer; 70 | } 71 | 72 | size_t write(const T * data, size_t n) 73 | { 74 | std::lock_guard lock(mtx); 75 | n = (std::min)(n, getFree_internal()); 76 | 77 | if (n == 0) { 78 | 79 | return n; 80 | } 81 | 82 | const size_t first_chunk = (std::min)(n, size - end); 83 | memcpy(buffer + end, data, first_chunk * sizeof(T)); 84 | end = (end + first_chunk) % size; 85 | 86 | if (first_chunk < n) { 87 | const size_t second_chunk = n - first_chunk; 88 | memcpy(buffer + end, data + first_chunk, second_chunk * sizeof(T)); 89 | end = (end + second_chunk) % size; 90 | } 91 | 92 | if (begin == end) { 93 | wrap = true; 94 | } 95 | ReleaseSemaphore(hsem_empty, n, NULL); 96 | 97 | return n; 98 | } 99 | 100 | size_t read(T * dest, size_t n) 101 | { 102 | DWORD rc = WaitForSingleObject(hsem_empty, 1000); 103 | if (rc == WAIT_TIMEOUT){ 104 | return 0; 105 | } 106 | else if (rc != WAIT_OBJECT_0) 107 | { 108 | return 0; 109 | } 110 | std::lock_guard lock(mtx); 111 | n = min(n, getOccupied_internal()); 112 | 113 | if (n == 0) { 114 | return n; 115 | } 116 | 117 | if (wrap) { 118 | wrap = false; 119 | } 120 | 121 | const size_t first_chunk = (std::min)(n, size - begin); 122 | memcpy(dest, buffer + begin, first_chunk * sizeof(T)); 123 | begin = (begin + first_chunk) % size; 124 | 125 | if (first_chunk < n) { 126 | const size_t second_chunk = n - first_chunk; 127 | memcpy(dest + first_chunk, buffer + begin, second_chunk * sizeof(T)); 128 | begin = (begin + second_chunk) % size; 129 | } 130 | 131 | 132 | return n; 133 | } 134 | 135 | 136 | size_t getOccupied() { 137 | std::lock_guard lock(mtx); 138 | return getOccupied_internal(); 139 | } 140 | 141 | 142 | size_t getFree() { 143 | std::lock_guard lock(mtx); 144 | return getFree_internal(); 145 | } 146 | private: 147 | T * buffer; 148 | size_t size; 149 | size_t begin; 150 | size_t end; 151 | bool wrap; 152 | std::mutex mtx; 153 | 154 | HANDLE hsem_empty; 155 | 156 | size_t getFree_internal() { 157 | size_t occ = 0; 158 | if (end == begin) { 159 | occ = wrap ? size : 0; 160 | } 161 | else if (end > begin) { 162 | occ = end - begin; 163 | } 164 | else { 165 | occ = size + end - begin; 166 | } 167 | return size - occ; 168 | } 169 | 170 | size_t getOccupied_internal() 171 | { 172 | if (end == begin) { 173 | return wrap ? size : 0; 174 | } 175 | else if (end > begin) { 176 | return end - begin; 177 | } 178 | else { 179 | return size + end - begin; 180 | } 181 | } 182 | }; 183 | 184 | #endif // RINGBUFFER_H 185 | -------------------------------------------------------------------------------- /src/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // PractialSensorTest.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /src/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #include 11 | #include 12 | 13 | 14 | 15 | // TODO: reference additional headers your program requires here 16 | -------------------------------------------------------------------------------- /src/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /src/types.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/types.h -------------------------------------------------------------------------------- /src/version.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/version.aps -------------------------------------------------------------------------------- /src/version.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hypereal-opensource/AlgorithmSDK/05000d3f7bc333da09cb063317b99bdeade6a0f4/src/version.rc --------------------------------------------------------------------------------