├── LICENSE ├── README.md ├── bin32 ├── DevIL.dll ├── ILU.dll ├── ILUT.dll ├── glut32.dll └── project32.exe ├── bin64 ├── DevIL.dll ├── ILU.dll ├── ILUT.dll └── glut32.dll ├── data └── white.png ├── ext ├── GL │ ├── glext.h │ ├── glut.def │ ├── glut.h │ ├── glxext.h │ └── wglext.h ├── IL │ ├── DevIL Manual.pdf │ ├── config.h │ ├── config.h.in │ ├── devil_cpp_wrapper.hpp │ ├── devil_internal_exports.h │ ├── il.h │ ├── ilu.h │ ├── ilu_region.h │ ├── ilut.h │ └── ilut_config.h ├── glew.cpp ├── glew.h ├── glxew.h ├── mathlib │ ├── _matrix33.h │ ├── _matrix33_sse.h │ ├── _matrix44.h │ ├── _matrix44_sse.h │ ├── _vector2.h │ ├── _vector3.h │ ├── _vector3_sse.h │ ├── _vector4.h │ ├── _vector4_sse.h │ ├── bbox.h │ ├── envelopecurve.h │ ├── euler.h │ ├── eulerangles.h │ ├── line.h │ ├── matrix.h │ ├── matrixdefs.h │ ├── nmath.h │ ├── noise.h │ ├── ntypes.h │ ├── ntypes.h~ │ ├── pknorm.h │ ├── plane.h │ ├── polar.h │ ├── quaternion.h │ ├── rectangle.h │ ├── sphere.h │ ├── transform33.h │ ├── transform44.h │ ├── triangle.h │ ├── vector.h │ └── vector3envelopecurve.h └── wglew.h ├── lib32 ├── DevIL.lib ├── ILU.lib ├── ILUT.lib └── glut32.lib ├── lib64 ├── DevIL.lib ├── ILU.lib ├── ILUT.lib └── glut32.lib ├── project.sln ├── screenshot.jpg ├── shader └── particle │ ├── frag.txt │ ├── geo.txt │ └── vs.txt ├── sphereN.rle4 └── src ├── Bmp.cpp ├── Bmp.h ├── Core.cpp ├── Core.h ├── Main.cpp ├── Rle4.cpp ├── Rle4.h ├── Tree.cpp ├── Tree.h ├── VecMath.cpp ├── VecMath.h ├── bitmap_fonts.h ├── glsl.h ├── project.vcproj ├── project.vcxproj ├── project.vcxproj.filters └── project.vcxproj.user /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Spacerat 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenGL-Voxel-Splatting 2 | OpenGL Voxel Splatting 3 | 4 | 5 | ![Screenshot1](https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/master/screenshot.jpg) 6 | -------------------------------------------------------------------------------- /bin32/DevIL.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/bin32/DevIL.dll -------------------------------------------------------------------------------- /bin32/ILU.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/bin32/ILU.dll -------------------------------------------------------------------------------- /bin32/ILUT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/bin32/ILUT.dll -------------------------------------------------------------------------------- /bin32/glut32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/bin32/glut32.dll -------------------------------------------------------------------------------- /bin32/project32.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/bin32/project32.exe -------------------------------------------------------------------------------- /bin64/DevIL.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/bin64/DevIL.dll -------------------------------------------------------------------------------- /bin64/ILU.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/bin64/ILU.dll -------------------------------------------------------------------------------- /bin64/ILUT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/bin64/ILUT.dll -------------------------------------------------------------------------------- /bin64/glut32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/bin64/glut32.dll -------------------------------------------------------------------------------- /data/white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/data/white.png -------------------------------------------------------------------------------- /ext/GL/glut.def: -------------------------------------------------------------------------------- 1 | DESCRIPTION 'OpenGL Utility Toolkit for Win32' 2 | 3 | VERSION 3.7 4 | 5 | EXPORTS 6 | 7 | glutAddMenuEntry 8 | glutAddSubMenu 9 | glutAttachMenu 10 | glutBitmapCharacter 11 | glutBitmapLength 12 | glutBitmapWidth 13 | glutButtonBoxFunc 14 | glutChangeToMenuEntry 15 | glutChangeToSubMenu 16 | glutCopyColormap 17 | glutCreateMenu 18 | __glutCreateMenuWithExit 19 | glutCreateSubWindow 20 | glutCreateWindow 21 | __glutCreateWindowWithExit 22 | glutDestroyMenu 23 | glutDestroyWindow 24 | glutDetachMenu 25 | glutDeviceGet 26 | glutDialsFunc 27 | glutDisplayFunc 28 | glutEnterGameMode 29 | glutEntryFunc 30 | glutEstablishOverlay 31 | glutExtensionSupported 32 | glutForceJoystickFunc 33 | glutFullScreen 34 | glutGameModeGet 35 | glutGameModeString 36 | glutGet 37 | glutGetColor 38 | glutGetMenu 39 | glutGetModifiers 40 | glutGetWindow 41 | glutHideOverlay 42 | glutHideWindow 43 | glutIconifyWindow 44 | glutIdleFunc 45 | glutIgnoreKeyRepeat 46 | glutInit 47 | __glutInitWithExit 48 | glutInitDisplayMode 49 | glutInitDisplayString 50 | glutInitWindowPosition 51 | glutInitWindowSize 52 | glutJoystickFunc 53 | glutKeyboardFunc 54 | glutKeyboardUpFunc 55 | glutLayerGet 56 | glutLeaveGameMode 57 | glutMainLoop 58 | glutMenuStateFunc 59 | glutMenuStatusFunc 60 | glutMotionFunc 61 | glutMouseFunc 62 | glutOverlayDisplayFunc 63 | glutPassiveMotionFunc 64 | glutPopWindow 65 | glutPositionWindow 66 | glutPostOverlayRedisplay 67 | glutPostRedisplay 68 | glutPostWindowOverlayRedisplay 69 | glutPostWindowRedisplay 70 | glutPushWindow 71 | glutRemoveMenuItem 72 | glutRemoveOverlay 73 | glutReportErrors 74 | glutReshapeFunc 75 | glutReshapeWindow 76 | glutSetColor 77 | glutSetCursor 78 | glutSetIconTitle 79 | glutSetKeyRepeat 80 | glutSetMenu 81 | glutSetWindow 82 | glutSetWindowTitle 83 | glutSetupVideoResizing 84 | glutShowOverlay 85 | glutShowWindow 86 | glutSolidCone 87 | glutSolidCube 88 | glutSolidDodecahedron 89 | glutSolidIcosahedron 90 | glutSolidOctahedron 91 | glutSolidSphere 92 | glutSolidTeapot 93 | glutSolidTetrahedron 94 | glutSolidTorus 95 | glutSpaceballButtonFunc 96 | glutSpaceballMotionFunc 97 | glutSpaceballRotateFunc 98 | glutSpecialFunc 99 | glutSpecialUpFunc 100 | glutStopVideoResizing 101 | glutStrokeCharacter 102 | glutStrokeLength 103 | glutStrokeWidth 104 | glutSwapBuffers 105 | glutTabletButtonFunc 106 | glutTabletMotionFunc 107 | glutTimerFunc 108 | glutUseLayer 109 | glutVideoPan 110 | glutVideoResize 111 | glutVideoResizeGet 112 | glutVisibilityFunc 113 | glutWarpPointer 114 | glutWindowStatusFunc 115 | glutWireCone 116 | glutWireCube 117 | glutWireDodecahedron 118 | glutWireIcosahedron 119 | glutWireOctahedron 120 | glutWireSphere 121 | glutWireTeapot 122 | glutWireTetrahedron 123 | glutWireTorus 124 | ; __glutSetFCB 125 | ; __glutGetFCB 126 | 127 | -------------------------------------------------------------------------------- /ext/IL/DevIL Manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/ext/IL/DevIL Manual.pdf -------------------------------------------------------------------------------- /ext/IL/config.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONFIG_H__ 2 | #define __CONFIG_H__ 3 | 4 | #define IL_USE_PRAGMA_LIBS // Links to only the libraries that are requested. 5 | #define IL_INLINE_ASM 1 // Define if you can support at least some ASM 6 | 7 | // Supported images formats (IL) 8 | 9 | //#define IL_NO_EXTLIBS 10 | 11 | // #define IL_NO_BLP 12 | // #define IL_NO_BMP 13 | // #define IL_NO_CUT 14 | // #define IL_NO_CHEAD 15 | // #define IL_NO_DCX 16 | // #define IL_NO_DDS 17 | // #define IL_NO_DICOM 18 | // #define IL_NO_DOOM 19 | // #define IL_NO_EXR 20 | // #define IL_NO_FITS 21 | // #define IL_NO_FTX 22 | // #define IL_NO_GIF 23 | // #define IL_NO_HDR 24 | // #define IL_NO_ICO 25 | // #define IL_NO_ICNS 26 | // #define IL_NO_IWI 27 | // #define IL_NO_JP2 28 | // #define IL_NO_JPG 29 | // #define IL_NO_LCMS 30 | // #define IL_NO_LIF 31 | // #define IL_NO_MDL 32 | // #define IL_NO_MNG 33 | // #define IL_NO_PCD 34 | // #define IL_NO_PCX 35 | // #define IL_NO_PIC 36 | // #define IL_NO_PIX 37 | // #define IL_NO_PNG 38 | // #define IL_NO_PNM 39 | // #define IL_NO_PSD 40 | // #define IL_NO_PSP 41 | // #define IL_NO_PXR 42 | // #define IL_NO_RAW 43 | // #define IL_NO_ROT 44 | // #define IL_NO_SGI 45 | // #define IL_NO_SUN 46 | // #define IL_NO_TGA 47 | // #define IL_NO_TIF 48 | // #define IL_NO_TPL 49 | // #define IL_NO_WAL 50 | // #define IL_NO_WDP 51 | // #define IL_NO_XPM 52 | 53 | #define IL_USE_JPEGLIB_UNMODIFIED 1 54 | //#define IL_USE_DXTC_NVIDIA 55 | //#define IL_USE_DXTC_SQUISH 56 | 57 | //#define IL_NO_GAMES 58 | 59 | /* Supported api (ilut) */ 60 | 61 | 62 | // 63 | // sorry just 64 | // cant get this one to work under windows 65 | // have disabled for the now 66 | // 67 | // will look at it some more later 68 | // 69 | // Kriss 70 | // 71 | #undef ILUT_USE_ALLEGRO 72 | 73 | #undef ILUT_USE_DIRECTX8 74 | //#define ILUT_USE_DIRECTX9 75 | //#define ILUT_USE_DIRECTX10 76 | #define ILUT_USE_OPENGL 77 | //#define ILUT_USE_SDL 78 | #define ILUT_USE_WIN32 79 | 80 | 81 | #endif /* __CONFIG_H__ */ 82 | -------------------------------------------------------------------------------- /ext/IL/config.h.in: -------------------------------------------------------------------------------- 1 | /* include/IL/config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Altivec extension found */ 4 | #undef ALTIVEC_GCC 5 | 6 | /* "Enable debug code features" */ 7 | #undef DEBUG 8 | 9 | /* PPC_ASM assembly found */ 10 | #undef GCC_PCC_ASM 11 | 12 | /* X86_64_ASM assembly found */ 13 | #undef GCC_X86_64_ASM 14 | 15 | /* X86_ASM assembly found */ 16 | #undef GCC_X86_ASM 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_DLFCN_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_GLUT_GLUT_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_GL_GLUT_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_GL_GLU_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_GL_GL_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_INTTYPES_H 35 | 36 | /* Define to 1 if you have the `m' library (-lm). */ 37 | #undef HAVE_LIBM 38 | 39 | /* Define to 1 if you have the `z' library (-lz). */ 40 | #undef HAVE_LIBZ 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_MEMORY_H 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_OPENGL_GLU_H 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #undef HAVE_OPENGL_GL_H 50 | 51 | /* Define if you have POSIX threads libraries and header files. */ 52 | #undef HAVE_PTHREAD 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_STDINT_H 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #undef HAVE_STDLIB_H 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #undef HAVE_STRINGS_H 62 | 63 | /* Define to 1 if you have the header file. */ 64 | #undef HAVE_STRING_H 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_SYS_STAT_H 68 | 69 | /* Define to 1 if you have the header file. */ 70 | #undef HAVE_SYS_TYPES_H 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #undef HAVE_UNISTD_H 74 | 75 | /* Use nonstandard varargs form for the GLU tesselator callback */ 76 | #undef HAVE_VARARGS_GLU_TESSCB 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #undef HAVE_WINDOWS_H 80 | 81 | /* Support Allegro API */ 82 | #undef ILUT_USE_ALLEGRO 83 | 84 | /* Support DirectX8 API */ 85 | #undef ILUT_USE_DIRECTX8 86 | 87 | /* Support DirectX9 API */ 88 | #undef ILUT_USE_DIRECTX9 89 | 90 | /* Define if system supports OpenGL API */ 91 | #undef ILUT_USE_OPENGL 92 | 93 | /* Support SDL API */ 94 | #undef ILUT_USE_SDL 95 | 96 | /* Support X11 API */ 97 | #undef ILUT_USE_X11 98 | 99 | /* Support X11 XRender extension */ 100 | #undef ILUT_USE_XRENDER 101 | 102 | /* Support X11 XShm extension */ 103 | #undef ILUT_USE_XSHM 104 | 105 | /* Define if you want to build ILU part of DevIL (used in DevIL 106 | examples/tests) */ 107 | #undef ILU_ENABLED 108 | 109 | /* Define if you can support at least some ASM */ 110 | #undef IL_INLINE_ASM 111 | 112 | /* blp support (BLP is the texture format for Blizzard games.) */ 113 | #undef IL_NO_BLP 114 | 115 | /* bmp support (BMP is a standard Windows bitmap.) */ 116 | #undef IL_NO_BMP 117 | 118 | /* dcx support (DCX is a multi-page PCX file.) */ 119 | #undef IL_NO_DCX 120 | 121 | /* dds support (DDS (DirectDraw Surface) is used by DirectX to load images 122 | (usually DXTC).) */ 123 | #undef IL_NO_DDS 124 | 125 | /* dicom support (DICOM (Digital Imaging and Communications in Medicine) is 126 | used extensively in medical imaging.) */ 127 | #undef IL_NO_DICOM 128 | 129 | /* exr support (EXR is a HDR image file format standardized by Industrial 130 | Light and Magic. OpenEXR powered) */ 131 | #undef IL_NO_EXR 132 | 133 | /* fits support (FITS (Flexible Image Transport System) is used for storing 134 | scientific images and is used extensively in astronomy.) */ 135 | #undef IL_NO_FITS 136 | 137 | /* Define if you want to disable support for various game formats */ 138 | #undef IL_NO_GAMES 139 | 140 | /* gif support (GIF is lossy and proprietary format used mainly to make 141 | animations) */ 142 | #undef IL_NO_GIF 143 | 144 | /* hdr support (HDR is the Radiance High Dynamic Range format, using more bits 145 | per channel than normal.) */ 146 | #undef IL_NO_HDR 147 | 148 | /* icns support (ICNS is the icon format for the Mac OS X operation system.) 149 | */ 150 | #undef IL_NO_ICNS 151 | 152 | /* icon support (ICO is the icon format for the Windows operating system.) */ 153 | #undef IL_NO_ICON 154 | 155 | /* iff support (IFF (Interchange File Format) is used to transfer images 156 | between software from different companies.) */ 157 | #undef IL_NO_IFF 158 | 159 | /* ilbm support (ILBM (Amiga Interleaved BitMap Format).) */ 160 | #undef IL_NO_ILBM 161 | 162 | /* iwi support (IWI is the Infinity Ward Image format used in the Call of Duty 163 | games.) */ 164 | #undef IL_NO_IWI 165 | 166 | /* jp2 support (JP2 (JPEG 2000) is a better, but not so widespread, 167 | alternative to JPEG. JasPer powered) */ 168 | #undef IL_NO_JP2 169 | 170 | /* jpeg support (JPEG is most common lossy format. libjpeg powered) */ 171 | #undef IL_NO_JPG 172 | 173 | /* lcms support () */ 174 | #undef IL_NO_LCMS 175 | 176 | /* lif support (LIF is the image format of the game Homeworld.) */ 177 | #undef IL_NO_LIF 178 | 179 | /* mdl support (MDL is the format for models in the game Half-Life.) */ 180 | #undef IL_NO_MDL 181 | 182 | /* mng support (MNG is basically the animated version of PNG but is not 183 | widespread.) */ 184 | #undef IL_NO_MNG 185 | 186 | /* mp3 support (MP3 (MPEG-1 Audio Layer 3) sometimes have images in them, such 187 | as cover art.) */ 188 | #undef IL_NO_MP3 189 | 190 | /* pcd support (PCD is the Kodak PhotoCD format.) */ 191 | #undef IL_NO_PCD 192 | 193 | /* pcx support (PCX is one of the first widely accepted DOS imaging standards) 194 | */ 195 | #undef IL_NO_PCX 196 | 197 | /* pic support (PIC is used by SoftImage software.) */ 198 | #undef IL_NO_PIC 199 | 200 | /* pix support () */ 201 | #undef IL_NO_PIX 202 | 203 | /* png support (PNG is a smart, loseless and even open format. libpng 204 | powered.) */ 205 | #undef IL_NO_PNG 206 | 207 | /* pnm support (PNM (Portable aNy Map format) is considered the 208 | least-common-denominator for converting pixmap, graymap, or bitmap files 209 | between different platforms.) */ 210 | #undef IL_NO_PNM 211 | 212 | /* psd support (PSD is the PhotoShop native file format.) */ 213 | #undef IL_NO_PSD 214 | 215 | /* psp support (PSP is the Paint Shop Pro native file format.) */ 216 | #undef IL_NO_PSP 217 | 218 | /* pxr support (PXR is used by Pixar.) */ 219 | #undef IL_NO_PXR 220 | 221 | /* raw support (RAW is simply raw data.) */ 222 | #undef IL_NO_RAW 223 | 224 | /* rot support (ROT is the image format for the game Homeworld 2.) */ 225 | #undef IL_NO_ROT 226 | 227 | /* sgi support (SGI is the native raster graphics file format for Silicon 228 | Graphics workstations) */ 229 | #undef IL_NO_SGI 230 | 231 | /* sun support (SUN is the image format used on Sun's operating systems.) */ 232 | #undef IL_NO_SUN 233 | 234 | /* texture support (TEXTURE is the format used in Medieval II: Total War 235 | (similar to DDS).) */ 236 | #undef IL_NO_TEXTURE 237 | 238 | /* tga support (TGA (aka TARGA file format) has been used mainly in games. It 239 | is open and simple.) */ 240 | #undef IL_NO_TGA 241 | 242 | /* tiff support (TIFF is a lossless format supporting greater color depths. 243 | libtiff powered) */ 244 | #undef IL_NO_TIF 245 | 246 | /* tpl support (TPL is the format used by many GameCube and Wii games.) */ 247 | #undef IL_NO_TPL 248 | 249 | /* utx support (UTX is the format used in the Unreal Tournament game series.) 250 | */ 251 | #undef IL_NO_UTX 252 | 253 | /* vtf support (VTF (Valve Texture Format) is used by games based on Valve's 254 | Source engine.) */ 255 | #undef IL_NO_VTF 256 | 257 | /* doom support (WAD is the format for graphics in the original DooM I/II.) */ 258 | #undef IL_NO_WAD 259 | 260 | /* wal support (WAL is the image format used for the game Quake 2.) */ 261 | #undef IL_NO_WAL 262 | 263 | /* wbmp support (WBMP (Wireless Application Protocol Bitmap) is a monochrome 264 | graphics file format optimized for mobile computing devices) */ 265 | #undef IL_NO_WBMP 266 | 267 | /* wdp support (WDP is Microsoft's successor to JPEG, able to store many 268 | different image types either lossy or losslessly, also known as HD Photo.) 269 | */ 270 | #undef IL_NO_WDP 271 | 272 | /* xpm support (XPM (X PixMap) is an ASCII-based image used in X Windows.) */ 273 | #undef IL_NO_XPM 274 | 275 | /* Define if you have nvidia texture tools library installed */ 276 | #undef IL_USE_DXTC_NVIDIA 277 | 278 | /* Define if you have libsquish installed */ 279 | #undef IL_USE_DXTC_SQUISH 280 | 281 | /* Use libjpeg without modification. always enabled. */ 282 | #undef IL_USE_JPEGLIB_UNMODIFIED 283 | 284 | /* LCMS include without lcms/ support */ 285 | #undef LCMS_NODIRINCLUDE 286 | 287 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 288 | */ 289 | #undef LT_OBJDIR 290 | 291 | /* Building on Mac OS X */ 292 | #undef MAX_OS_X 293 | 294 | /* define if you have memalign memory allocation */ 295 | #undef MEMALIGN 296 | 297 | /* define if you have mm_malloc.h header */ 298 | #undef MM_MALLOC 299 | 300 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 301 | #undef NO_MINUS_C_MINUS_O 302 | 303 | /* Name of package */ 304 | #undef PACKAGE 305 | 306 | /* Define to the address where bug reports for this package should be sent. */ 307 | #undef PACKAGE_BUGREPORT 308 | 309 | /* Define to the full name of this package. */ 310 | #undef PACKAGE_NAME 311 | 312 | /* Define to the full name and version of this package. */ 313 | #undef PACKAGE_STRING 314 | 315 | /* Define to the one symbol short name of this package. */ 316 | #undef PACKAGE_TARNAME 317 | 318 | /* Define to the version of this package. */ 319 | #undef PACKAGE_VERSION 320 | 321 | /* define if you have posix_memalign memory allocation */ 322 | #undef POSIX_MEMALIGN 323 | 324 | /* Define to necessary symbol if this constant uses a non-standard name on 325 | your system. */ 326 | #undef PTHREAD_CREATE_JOINABLE 327 | 328 | /* restric keyword available */ 329 | #undef RESTRICT_KEYWORD 330 | 331 | /* SSE extension found */ 332 | #undef SSE 333 | 334 | /* SSE2 extension found */ 335 | #undef SSE2 336 | 337 | /* SSE3 extension found */ 338 | #undef SSE3 339 | 340 | /* Define to 1 if you have the ANSI C header files. */ 341 | #undef STDC_HEADERS 342 | 343 | /* define if you have valloc memory allocation */ 344 | #undef VALLOC 345 | 346 | /* Memory must be vector aligned */ 347 | #undef VECTORMEM 348 | 349 | /* Version number of package */ 350 | #undef VERSION 351 | 352 | /* Define to 1 if your processor stores words with the most significant byte 353 | first (like Motorola and SPARC, unlike Intel and VAX). */ 354 | #undef WORDS_BIGENDIAN 355 | 356 | /* Define to 1 if the X Window System is missing or not being used. */ 357 | #undef X_DISPLAY_MISSING 358 | -------------------------------------------------------------------------------- /ext/IL/devil_internal_exports.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // ImageLib Sources 4 | // Copyright (C) 2000-2009 by Denton Woods 5 | // Last modified: 01/06/2009 6 | // 7 | // Filename: IL/devil_internal_exports.h 8 | // 9 | // Description: Internal stuff for DevIL (IL, ILU and ILUT) 10 | // 11 | //----------------------------------------------------------------------------- 12 | 13 | #ifndef IL_EXPORTS_H 14 | #define IL_EXPORTS_H 15 | 16 | #include "IL/il.h" 17 | 18 | #ifdef DEBUG 19 | #include 20 | #else 21 | #define assert(x) 22 | #endif 23 | 24 | //#ifndef NOINLINE 25 | #ifndef INLINE 26 | #if defined(__GNUC__) 27 | #define INLINE extern inline 28 | #elif defined(_MSC_VER) //@TODO: Get this working in MSVC++. 29 | // http://www.greenend.org.uk/rjk/2003/03/inline.html 30 | #define NOINLINE 31 | //#define INLINE 32 | /*#ifndef _WIN64 // Cannot use inline assembly in x64 target platform. 33 | #define USE_WIN32_ASM 34 | #endif//_WIN64*/ 35 | #define INLINE __inline 36 | #else 37 | #define INLINE inline 38 | #endif 39 | #endif 40 | //#else 41 | //#define INLINE 42 | //#endif //NOINLINE 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | #define IL_MAX(a,b) (((a) > (b)) ? (a) : (b)) 49 | #define IL_MIN(a,b) (((a) < (b)) ? (a) : (b)) 50 | 51 | 52 | //! Basic Palette struct 53 | typedef struct ILpal 54 | { 55 | ILubyte* Palette; //!< the image palette (if any) 56 | ILuint PalSize; //!< size of the palette (in bytes) 57 | ILenum PalType; //!< the palette types in il.h (0x0500 range) 58 | } ILpal; 59 | 60 | 61 | //! The Fundamental Image structure 62 | /*! Every bit of information about an image is stored in this internal structure.*/ 63 | typedef struct ILimage 64 | { 65 | ILuint Width; //!< the image's width 66 | ILuint Height; //!< the image's height 67 | ILuint Depth; //!< the image's depth 68 | ILubyte Bpp; //!< bytes per pixel (now number of channels) 69 | ILubyte Bpc; //!< bytes per channel 70 | ILuint Bps; //!< bytes per scanline (components for IL) 71 | ILubyte* Data; //!< the image data 72 | ILuint SizeOfData; //!< the total size of the data (in bytes) 73 | ILuint SizeOfPlane; //!< SizeOfData in a 2d image, size of each plane slice in a 3d image (in bytes) 74 | ILenum Format; //!< image format (in IL enum style) 75 | ILenum Type; //!< image type (in IL enum style) 76 | ILenum Origin; //!< origin of the image 77 | ILpal Pal; //!< palette details 78 | ILuint Duration; //!< length of the time to display this "frame" 79 | ILenum CubeFlags; //!< cube map flags for sides present in chain 80 | struct ILimage* Mipmaps; //!< mipmapped versions of this image terminated by a NULL - usu. NULL 81 | struct ILimage* Next; //!< next image in the chain - usu. NULL 82 | struct ILimage* Faces; //!< next cubemap face in the chain - usu. NULL 83 | struct ILimage* Layers; //!< subsequent layers in the chain - usu. NULL 84 | ILuint* AnimList; //!< animation list 85 | ILuint AnimSize; //!< animation list size 86 | void* Profile; //!< colour profile 87 | ILuint ProfileSize; //!< colour profile size 88 | ILuint OffX; //!< x-offset of the image 89 | ILuint OffY; //!< y-offset of the image 90 | ILubyte* DxtcData; //!< compressed data 91 | ILenum DxtcFormat; //!< compressed data format 92 | ILuint DxtcSize; //!< compressed data size 93 | } ILimage; 94 | 95 | 96 | // Memory functions 97 | ILAPI void* ILAPIENTRY ialloc(const ILsizei Size); 98 | ILAPI void ILAPIENTRY ifree(const void *Ptr); 99 | ILAPI void* ILAPIENTRY icalloc(const ILsizei Size, const ILsizei Num); 100 | #ifdef ALTIVEC_GCC 101 | ILAPI void* ILAPIENTRY ivec_align_buffer(void *buffer, const ILuint size); 102 | #endif 103 | 104 | // Internal library functions in IL 105 | ILAPI ILimage* ILAPIENTRY ilGetCurImage(void); 106 | ILAPI void ILAPIENTRY ilSetCurImage(ILimage *Image); 107 | ILAPI void ILAPIENTRY ilSetError(ILenum Error); 108 | ILAPI void ILAPIENTRY ilSetPal(ILpal *Pal); 109 | 110 | // 111 | // Utility functions 112 | // 113 | ILAPI ILubyte ILAPIENTRY ilGetBppFormat(ILenum Format); 114 | ILAPI ILenum ILAPIENTRY ilGetFormatBpp(ILubyte Bpp); 115 | ILAPI ILubyte ILAPIENTRY ilGetBpcType(ILenum Type); 116 | ILAPI ILenum ILAPIENTRY ilGetTypeBpc(ILubyte Bpc); 117 | ILAPI ILubyte ILAPIENTRY ilGetBppPal(ILenum PalType); 118 | ILAPI ILenum ILAPIENTRY ilGetPalBaseType(ILenum PalType); 119 | ILAPI ILuint ILAPIENTRY ilNextPower2(ILuint Num); 120 | ILAPI ILenum ILAPIENTRY ilTypeFromExt(ILconst_string FileName); 121 | ILAPI void ILAPIENTRY ilReplaceCurImage(ILimage *Image); 122 | ILAPI void ILAPIENTRY iMemSwap(ILubyte *, ILubyte *, const ILuint); 123 | 124 | // 125 | // Image functions 126 | // 127 | ILAPI void ILAPIENTRY iBindImageTemp (void); 128 | ILAPI ILboolean ILAPIENTRY ilClearImage_ (ILimage *Image); 129 | ILAPI void ILAPIENTRY ilCloseImage (ILimage *Image); 130 | ILAPI void ILAPIENTRY ilClosePal (ILpal *Palette); 131 | ILAPI ILpal* ILAPIENTRY iCopyPal (void); 132 | ILAPI ILboolean ILAPIENTRY ilCopyImageAttr (ILimage *Dest, ILimage *Src); 133 | ILAPI ILimage* ILAPIENTRY ilCopyImage_ (ILimage *Src); 134 | ILAPI void ILAPIENTRY ilGetClear (void *Colours, ILenum Format, ILenum Type); 135 | ILAPI ILuint ILAPIENTRY ilGetCurName (void); 136 | ILAPI ILboolean ILAPIENTRY ilIsValidPal (ILpal *Palette); 137 | ILAPI ILimage* ILAPIENTRY ilNewImage (ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILubyte Bpc); 138 | ILAPI ILimage* ILAPIENTRY ilNewImageFull (ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data); 139 | ILAPI ILboolean ILAPIENTRY ilInitImage (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data); 140 | ILAPI ILboolean ILAPIENTRY ilResizeImage (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILubyte Bpc); 141 | ILAPI ILboolean ILAPIENTRY ilTexImage_ (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data); 142 | ILAPI ILboolean ILAPIENTRY ilTexSubImage_ (ILimage *Image, void *Data); 143 | ILAPI void* ILAPIENTRY ilConvertBuffer (ILuint SizeOfData, ILenum SrcFormat, ILenum DestFormat, ILenum SrcType, ILenum DestType, ILpal *SrcPal, void *Buffer); 144 | ILAPI ILimage* ILAPIENTRY iConvertImage (ILimage *Image, ILenum DestFormat, ILenum DestType); 145 | ILAPI ILpal* ILAPIENTRY iConvertPal (ILpal *Pal, ILenum DestFormat); 146 | ILAPI ILubyte* ILAPIENTRY iGetFlipped (ILimage *Image); 147 | ILAPI ILboolean ILAPIENTRY iMirror(); 148 | ILAPI void ILAPIENTRY iFlipBuffer(ILubyte *buff, ILuint depth, ILuint line_size, ILuint line_num); 149 | ILubyte* iFlipNewBuffer(ILubyte *buff, ILuint depth, ILuint line_size, ILuint line_num); 150 | ILAPI void ILAPIENTRY iGetIntegervImage(ILimage *Image, ILenum Mode, ILint *Param); 151 | 152 | // Internal library functions in ILU 153 | ILAPI ILimage* ILAPIENTRY iluRotate_(ILimage *Image, ILfloat Angle); 154 | ILAPI ILimage* ILAPIENTRY iluRotate3D_(ILimage *Image, ILfloat x, ILfloat y, ILfloat z, ILfloat Angle); 155 | ILAPI ILimage* ILAPIENTRY iluScale_(ILimage *Image, ILuint Width, ILuint Height, ILuint Depth); 156 | 157 | #ifdef __cplusplus 158 | } 159 | #endif 160 | 161 | #endif//IL_EXPORTS_H 162 | -------------------------------------------------------------------------------- /ext/IL/ilu.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // ImageLib Utility Sources 4 | // Copyright (C) 2000-2009 by Denton Woods 5 | // Last modified: 03/07/2009 6 | // 7 | // Filename: IL/ilu.h 8 | // 9 | // Description: The main include file for ILU 10 | // 11 | //----------------------------------------------------------------------------- 12 | 13 | // Doxygen comment 14 | /*! \file ilu.h 15 | The main include file for ILU 16 | */ 17 | 18 | #ifndef __ilu_h_ 19 | #ifndef __ILU_H__ 20 | 21 | #define __ilu_h_ 22 | #define __ILU_H__ 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | #ifdef _WIN32 32 | #if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY)) 33 | #if defined(_MSC_VER) || defined(__BORLANDC__) 34 | #pragma comment(lib, "ILU.lib") 35 | #endif 36 | #endif 37 | #endif 38 | 39 | 40 | #define ILU_VERSION_1_7_8 1 41 | #define ILU_VERSION 178 42 | 43 | 44 | #define ILU_FILTER 0x2600 45 | #define ILU_NEAREST 0x2601 46 | #define ILU_LINEAR 0x2602 47 | #define ILU_BILINEAR 0x2603 48 | #define ILU_SCALE_BOX 0x2604 49 | #define ILU_SCALE_TRIANGLE 0x2605 50 | #define ILU_SCALE_BELL 0x2606 51 | #define ILU_SCALE_BSPLINE 0x2607 52 | #define ILU_SCALE_LANCZOS3 0x2608 53 | #define ILU_SCALE_MITCHELL 0x2609 54 | 55 | 56 | // Error types 57 | #define ILU_INVALID_ENUM 0x0501 58 | #define ILU_OUT_OF_MEMORY 0x0502 59 | #define ILU_INTERNAL_ERROR 0x0504 60 | #define ILU_INVALID_VALUE 0x0505 61 | #define ILU_ILLEGAL_OPERATION 0x0506 62 | #define ILU_INVALID_PARAM 0x0509 63 | 64 | 65 | // Values 66 | #define ILU_PLACEMENT 0x0700 67 | #define ILU_LOWER_LEFT 0x0701 68 | #define ILU_LOWER_RIGHT 0x0702 69 | #define ILU_UPPER_LEFT 0x0703 70 | #define ILU_UPPER_RIGHT 0x0704 71 | #define ILU_CENTER 0x0705 72 | #define ILU_CONVOLUTION_MATRIX 0x0710 73 | 74 | #define ILU_VERSION_NUM IL_VERSION_NUM 75 | #define ILU_VENDOR IL_VENDOR 76 | 77 | 78 | // Languages 79 | #define ILU_ENGLISH 0x0800 80 | #define ILU_ARABIC 0x0801 81 | #define ILU_DUTCH 0x0802 82 | #define ILU_JAPANESE 0x0803 83 | #define ILU_SPANISH 0x0804 84 | #define ILU_GERMAN 0x0805 85 | #define ILU_FRENCH 0x0806 86 | 87 | 88 | // Filters 89 | /* 90 | #define ILU_FILTER_BLUR 0x0803 91 | #define ILU_FILTER_GAUSSIAN_3x3 0x0804 92 | #define ILU_FILTER_GAUSSIAN_5X5 0x0805 93 | #define ILU_FILTER_EMBOSS1 0x0807 94 | #define ILU_FILTER_EMBOSS2 0x0808 95 | #define ILU_FILTER_LAPLACIAN1 0x080A 96 | #define ILU_FILTER_LAPLACIAN2 0x080B 97 | #define ILU_FILTER_LAPLACIAN3 0x080C 98 | #define ILU_FILTER_LAPLACIAN4 0x080D 99 | #define ILU_FILTER_SHARPEN1 0x080E 100 | #define ILU_FILTER_SHARPEN2 0x080F 101 | #define ILU_FILTER_SHARPEN3 0x0810 102 | */ 103 | 104 | 105 | typedef struct ILinfo 106 | { 107 | ILuint Id; // the image's id 108 | ILubyte *Data; // the image's data 109 | ILuint Width; // the image's width 110 | ILuint Height; // the image's height 111 | ILuint Depth; // the image's depth 112 | ILubyte Bpp; // bytes per pixel (not bits) of the image 113 | ILuint SizeOfData; // the total size of the data (in bytes) 114 | ILenum Format; // image format (in IL enum style) 115 | ILenum Type; // image type (in IL enum style) 116 | ILenum Origin; // origin of the image 117 | ILubyte *Palette; // the image's palette 118 | ILenum PalType; // palette type 119 | ILuint PalSize; // palette size 120 | ILenum CubeFlags; // flags for what cube map sides are present 121 | ILuint NumNext; // number of images following 122 | ILuint NumMips; // number of mipmaps 123 | ILuint NumLayers; // number of layers 124 | } ILinfo; 125 | 126 | 127 | typedef struct ILpointf { 128 | ILfloat x; 129 | ILfloat y; 130 | } ILpointf; 131 | 132 | typedef struct ILpointi { 133 | ILint x; 134 | ILint y; 135 | } ILpointi; 136 | 137 | ILAPI ILboolean ILAPIENTRY iluAlienify(void); 138 | ILAPI ILboolean ILAPIENTRY iluBlurAvg(ILuint Iter); 139 | ILAPI ILboolean ILAPIENTRY iluBlurGaussian(ILuint Iter); 140 | ILAPI ILboolean ILAPIENTRY iluBuildMipmaps(void); 141 | ILAPI ILuint ILAPIENTRY iluColoursUsed(void); 142 | ILAPI ILboolean ILAPIENTRY iluCompareImage(ILuint Comp); 143 | ILAPI ILboolean ILAPIENTRY iluContrast(ILfloat Contrast); 144 | ILAPI ILboolean ILAPIENTRY iluCrop(ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, ILuint Height, ILuint Depth); 145 | ILAPI void ILAPIENTRY iluDeleteImage(ILuint Id); // Deprecated 146 | ILAPI ILboolean ILAPIENTRY iluEdgeDetectE(void); 147 | ILAPI ILboolean ILAPIENTRY iluEdgeDetectP(void); 148 | ILAPI ILboolean ILAPIENTRY iluEdgeDetectS(void); 149 | ILAPI ILboolean ILAPIENTRY iluEmboss(void); 150 | ILAPI ILboolean ILAPIENTRY iluEnlargeCanvas(ILuint Width, ILuint Height, ILuint Depth); 151 | ILAPI ILboolean ILAPIENTRY iluEnlargeImage(ILfloat XDim, ILfloat YDim, ILfloat ZDim); 152 | ILAPI ILboolean ILAPIENTRY iluEqualize(void); 153 | ILAPI ILconst_string ILAPIENTRY iluErrorString(ILenum Error); 154 | ILAPI ILboolean ILAPIENTRY iluConvolution(ILint *matrix, ILint scale, ILint bias); 155 | ILAPI ILboolean ILAPIENTRY iluFlipImage(void); 156 | ILAPI ILboolean ILAPIENTRY iluGammaCorrect(ILfloat Gamma); 157 | ILAPI ILuint ILAPIENTRY iluGenImage(void); // Deprecated 158 | ILAPI void ILAPIENTRY iluGetImageInfo(ILinfo *Info); 159 | ILAPI ILint ILAPIENTRY iluGetInteger(ILenum Mode); 160 | ILAPI void ILAPIENTRY iluGetIntegerv(ILenum Mode, ILint *Param); 161 | ILAPI ILstring ILAPIENTRY iluGetString(ILenum StringName); 162 | ILAPI void ILAPIENTRY iluImageParameter(ILenum PName, ILenum Param); 163 | ILAPI void ILAPIENTRY iluInit(void); 164 | ILAPI ILboolean ILAPIENTRY iluInvertAlpha(void); 165 | ILAPI ILuint ILAPIENTRY iluLoadImage(ILconst_string FileName); 166 | ILAPI ILboolean ILAPIENTRY iluMirror(void); 167 | ILAPI ILboolean ILAPIENTRY iluNegative(void); 168 | ILAPI ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance); 169 | ILAPI ILboolean ILAPIENTRY iluPixelize(ILuint PixSize); 170 | ILAPI void ILAPIENTRY iluRegionfv(ILpointf *Points, ILuint n); 171 | ILAPI void ILAPIENTRY iluRegioniv(ILpointi *Points, ILuint n); 172 | ILAPI ILboolean ILAPIENTRY iluReplaceColour(ILubyte Red, ILubyte Green, ILubyte Blue, ILfloat Tolerance); 173 | ILAPI ILboolean ILAPIENTRY iluRotate(ILfloat Angle); 174 | ILAPI ILboolean ILAPIENTRY iluRotate3D(ILfloat x, ILfloat y, ILfloat z, ILfloat Angle); 175 | ILAPI ILboolean ILAPIENTRY iluSaturate1f(ILfloat Saturation); 176 | ILAPI ILboolean ILAPIENTRY iluSaturate4f(ILfloat r, ILfloat g, ILfloat b, ILfloat Saturation); 177 | ILAPI ILboolean ILAPIENTRY iluScale(ILuint Width, ILuint Height, ILuint Depth); 178 | ILAPI ILboolean ILAPIENTRY iluScaleAlpha(ILfloat scale); 179 | ILAPI ILboolean ILAPIENTRY iluScaleColours(ILfloat r, ILfloat g, ILfloat b); 180 | ILAPI ILboolean ILAPIENTRY iluSetLanguage(ILenum Language); 181 | ILAPI ILboolean ILAPIENTRY iluSharpen(ILfloat Factor, ILuint Iter); 182 | ILAPI ILboolean ILAPIENTRY iluSwapColours(void); 183 | ILAPI ILboolean ILAPIENTRY iluWave(ILfloat Angle); 184 | 185 | #define iluColorsUsed iluColoursUsed 186 | #define iluSwapColors iluSwapColours 187 | #define iluReplaceColor iluReplaceColour 188 | #define iluScaleColor iluScaleColour 189 | 190 | #ifdef __cplusplus 191 | } 192 | #endif 193 | 194 | #endif // __ILU_H__ 195 | #endif // __ilu_h_ 196 | -------------------------------------------------------------------------------- /ext/IL/ilu_region.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // ImageLib Utility Sources 4 | // Copyright (C) 2000-2002 by Denton Woods 5 | // Last modified: 07/09/2002 <--Y2K Compliant! =] 6 | // 7 | // Filename: src-ILU/src/ilu_region.h 8 | // 9 | // Description: Creates an image region. 10 | // 11 | //----------------------------------------------------------------------------- 12 | 13 | #ifndef ILU_REGION_H 14 | #define ILU_REGION_H 15 | 16 | typedef struct Edge 17 | { 18 | ILint yUpper; 19 | ILfloat xIntersect, dxPerScan; 20 | struct Edge *next; 21 | } Edge; 22 | 23 | 24 | #endif//ILU_REGION_H 25 | 26 | -------------------------------------------------------------------------------- /ext/IL/ilut_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILUT_CONFIG_H__ 2 | #define __ILUT_CONFIG_H__ 3 | 4 | #define IL_USE_PRAGMA_LIBS 5 | 6 | // Supported APIs (ILUT) 7 | 8 | // 9 | // sorry just 10 | // cant get this one to work under windows 11 | // have disabled for the now 12 | // 13 | // will look at it some more later 14 | // 15 | // Kriss 16 | // 17 | #undef ILUT_USE_ALLEGRO 18 | 19 | #undef ILUT_USE_DIRECTX8 20 | #define ILUT_USE_DIRECTX9 21 | //#define ILUT_USE_DIRECTX10 22 | #define ILUT_USE_OPENGL 23 | //#define ILUT_USE_SDL 24 | #define ILUT_USE_WIN32 25 | 26 | #endif//__ILUT_CONFIG_H__ 27 | -------------------------------------------------------------------------------- /ext/mathlib/_vector2.h: -------------------------------------------------------------------------------- 1 | #ifndef _VECTOR2_H 2 | #define _VECTOR2_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class _vector2 6 | @ingroup Math 7 | 8 | Generic vector2 class. 9 | 10 | (C) 2002 RadonLabs GmbH 11 | */ 12 | #include "mathlib/nmath.h" 13 | #include 14 | 15 | //------------------------------------------------------------------------------ 16 | class _vector2 { 17 | public: 18 | /// constructor 1 19 | _vector2(); 20 | /// constructor 2 21 | _vector2(const float _x, const float _y); 22 | /// constructor 3 23 | _vector2(const _vector2& vec); 24 | /// constructor 4 25 | _vector2(const float* p); 26 | /// set elements 1 27 | void set(const float _x, const float _y); 28 | /// set elements 2 29 | void set(const _vector2& vec); 30 | /// set elements 3 31 | void set(const float* p); 32 | /// return length 33 | float len() const; 34 | /// normalize 35 | void norm(); 36 | /// in place add 37 | void operator+=(const _vector2& v0); 38 | /// in place sub 39 | void operator-=(const _vector2& v0); 40 | /// in place scalar mul 41 | void operator*=(const float s); 42 | /// in place scalar div 43 | void operator/=(const float s); 44 | /// fuzzy compare operator 45 | bool isequal(const _vector2& v, const float tol) const; 46 | /// fuzzy compare, returns -1, 0, +1 47 | int compare(const _vector2& v, float tol) const; 48 | /// rotate around P(0,0) 49 | void rotate(float angle); 50 | 51 | float x, y; 52 | }; 53 | 54 | //------------------------------------------------------------------------------ 55 | /** 56 | */ 57 | inline 58 | _vector2::_vector2() : 59 | x(0.0f), 60 | y(0.0f) 61 | { 62 | // empty 63 | } 64 | 65 | //------------------------------------------------------------------------------ 66 | /** 67 | */ 68 | inline 69 | _vector2::_vector2(const float _x, const float _y) : 70 | x(_x), 71 | y(_y) 72 | { 73 | // empty 74 | } 75 | 76 | //------------------------------------------------------------------------------ 77 | /** 78 | */ 79 | inline 80 | _vector2::_vector2(const _vector2& vec) : 81 | x(vec.x), 82 | y(vec.y) 83 | { 84 | // empty 85 | } 86 | 87 | //------------------------------------------------------------------------------ 88 | /** 89 | */ 90 | inline 91 | _vector2::_vector2(const float* p) : 92 | x(p[0]), 93 | y(p[1]) 94 | { 95 | // empty 96 | } 97 | 98 | //------------------------------------------------------------------------------ 99 | /** 100 | */ 101 | inline 102 | void 103 | _vector2::set(const float _x, const float _y) 104 | { 105 | x = _x; 106 | y = _y; 107 | } 108 | 109 | //------------------------------------------------------------------------------ 110 | /** 111 | */ 112 | inline 113 | void 114 | _vector2::set(const _vector2& v) 115 | { 116 | x = v.x; 117 | y = v.y; 118 | } 119 | 120 | //------------------------------------------------------------------------------ 121 | /** 122 | */ 123 | inline 124 | void 125 | _vector2::set(const float* p) 126 | { 127 | x = p[0]; 128 | y = p[1]; 129 | } 130 | 131 | //------------------------------------------------------------------------------ 132 | /** 133 | */ 134 | inline 135 | float 136 | _vector2::len() const 137 | { 138 | return (float) sqrt(x * x + y * y); 139 | } 140 | 141 | //------------------------------------------------------------------------------ 142 | /** 143 | */ 144 | inline 145 | void 146 | _vector2::norm() 147 | { 148 | float l = len(); 149 | if (l > TINY) 150 | { 151 | x /= l; 152 | y /= l; 153 | } 154 | } 155 | 156 | //------------------------------------------------------------------------------ 157 | /** 158 | */ 159 | inline 160 | void 161 | _vector2::operator +=(const _vector2& v0) 162 | { 163 | x += v0.x; 164 | y += v0.y; 165 | } 166 | 167 | //------------------------------------------------------------------------------ 168 | /** 169 | */ 170 | inline 171 | void 172 | _vector2::operator -=(const _vector2& v0) 173 | { 174 | x -= v0.x; 175 | y -= v0.y; 176 | } 177 | 178 | //------------------------------------------------------------------------------ 179 | /** 180 | */ 181 | inline 182 | void 183 | _vector2::operator *=(const float s) 184 | { 185 | x *= s; 186 | y *= s; 187 | } 188 | 189 | //------------------------------------------------------------------------------ 190 | /** 191 | */ 192 | inline 193 | void 194 | _vector2::operator /=(const float s) 195 | { 196 | x /= s; 197 | y /= s; 198 | } 199 | 200 | //------------------------------------------------------------------------------ 201 | /** 202 | */ 203 | inline 204 | bool 205 | _vector2::isequal(const _vector2& v, const float tol) const 206 | { 207 | if (fabs(v.x - x) > tol) return false; 208 | else if (fabs(v.y - y) > tol) return false; 209 | return true; 210 | } 211 | 212 | //------------------------------------------------------------------------------ 213 | /** 214 | */ 215 | inline 216 | int 217 | _vector2::compare(const _vector2& v, float tol) const 218 | { 219 | if (fabs(v.x - x) > tol) return (v.x > x) ? +1 : -1; 220 | else if (fabs(v.y - y) > tol) return (v.y > y) ? +1 : -1; 221 | else return 0; 222 | } 223 | 224 | //------------------------------------------------------------------------------ 225 | /** 226 | */ 227 | inline 228 | void 229 | _vector2::rotate(float angle) 230 | { 231 | // rotates this one around P(0,0). 232 | float sa, ca; 233 | 234 | sa = (float) sin(angle); 235 | ca = (float) cos(angle); 236 | 237 | // "handmade" multiplication 238 | _vector2 help(ca * this->x - sa * this->y, 239 | sa * this->x + ca * this->y); 240 | 241 | *this = help; 242 | } 243 | 244 | //------------------------------------------------------------------------------ 245 | /** 246 | */ 247 | static 248 | inline 249 | _vector2 operator +(const _vector2& v0, const _vector2& v1) 250 | { 251 | return _vector2(v0.x + v1.x, v0.y + v1.y); 252 | } 253 | 254 | //------------------------------------------------------------------------------ 255 | /** 256 | */ 257 | static 258 | inline 259 | _vector2 operator -(const _vector2& v0, const _vector2& v1) 260 | { 261 | return _vector2(v0.x - v1.x, v0.y - v1.y); 262 | } 263 | 264 | //------------------------------------------------------------------------------ 265 | /** 266 | */ 267 | static 268 | inline 269 | _vector2 operator *(const _vector2& v0, const float s) 270 | { 271 | return _vector2(v0.x * s, v0.y * s); 272 | } 273 | 274 | //------------------------------------------------------------------------------ 275 | /** 276 | */ 277 | static 278 | inline 279 | _vector2 operator -(const _vector2& v) 280 | { 281 | return _vector2(-v.x, -v.y); 282 | } 283 | 284 | //------------------------------------------------------------------------------ 285 | #endif 286 | 287 | -------------------------------------------------------------------------------- /ext/mathlib/_vector4.h: -------------------------------------------------------------------------------- 1 | #ifndef _VECTOR4_H 2 | #define _VECTOR4_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class _vector4 6 | @ingroup Math 7 | 8 | A generic vector4 class. 9 | 10 | (C) 2002 RadonLabs GmbH 11 | */ 12 | #include "mathlib/nmath.h" 13 | #include 14 | 15 | //------------------------------------------------------------------------------ 16 | class _vector4 17 | { 18 | public: 19 | enum component 20 | { 21 | X = (1<<0), 22 | Y = (1<<1), 23 | Z = (1<<2), 24 | W = (1<<3), 25 | }; 26 | 27 | /// constructor 1 28 | _vector4(); 29 | /// constructor 2 30 | _vector4(const float _x, const float _y, const float _z, const float _w); 31 | /// constructor 3 32 | _vector4(const _vector4& vec); 33 | /// constructor from vector3 (w will be set to 1.0) 34 | _vector4(const _vector3& vec3); 35 | /// set elements 1 36 | void set(const float _x, const float _y, const float _z, const float _w); 37 | /// set elements 2 38 | void set(const _vector4& v); 39 | /// set to vector3 (w will be set to 1.0) 40 | void set(const _vector3& v); 41 | /// return length 42 | float len() const; 43 | /// normalize 44 | void norm(); 45 | /// inplace add 46 | void operator +=(const _vector4& v); 47 | /// inplace sub 48 | void operator -=(const _vector4& v); 49 | /// inplace scalar mul 50 | void operator *=(const float s); 51 | /// vector3 assignment operator (w set to 1.0f) 52 | _vector4& operator=(const _vector3& v); 53 | /// fuzzy compare 54 | bool isequal(const _vector4& v, float tol) const; 55 | /// fuzzy compare, return -1, 0, +1 56 | int compare(const _vector4& v, float tol) const; 57 | /// set own components to minimum 58 | void minimum(const _vector4& v); 59 | /// set own components to maximum 60 | void maximum(const _vector4& v); 61 | /// set component float value by mask 62 | void setcomp(float val, int mask); 63 | /// get component float value by mask 64 | float getcomp(int mask); 65 | /// get write mask for smallest component 66 | int mincompmask() const; 67 | /// inplace linear interpolation 68 | void lerp(const _vector4& v0, float lerpVal); 69 | /// saturate components between 0 and 1 70 | void saturate(); 71 | /// dot product 72 | float dot(const _vector4& v0) const; 73 | 74 | float x, y, z, w; 75 | }; 76 | 77 | //------------------------------------------------------------------------------ 78 | /** 79 | */ 80 | inline 81 | _vector4::_vector4() : 82 | x(0.0f), 83 | y(0.0f), 84 | z(0.0f), 85 | w(0.0f) 86 | { 87 | // empty 88 | } 89 | 90 | //------------------------------------------------------------------------------ 91 | /** 92 | */ 93 | inline 94 | _vector4::_vector4(const float _x, const float _y, const float _z, const float _w) : 95 | x(_x), 96 | y(_y), 97 | z(_z), 98 | w(_w) 99 | { 100 | // empty 101 | } 102 | 103 | //------------------------------------------------------------------------------ 104 | /** 105 | */ 106 | inline 107 | _vector4::_vector4(const _vector4& v) : 108 | x(v.x), 109 | y(v.y), 110 | z(v.z), 111 | w(v.w) 112 | { 113 | // empty 114 | } 115 | 116 | //------------------------------------------------------------------------------ 117 | /** 118 | */ 119 | inline 120 | _vector4::_vector4(const _vector3& v) : 121 | x(v.x), 122 | y(v.y), 123 | z(v.z), 124 | w(1.0f) 125 | { 126 | // empty 127 | } 128 | 129 | //------------------------------------------------------------------------------ 130 | /** 131 | */ 132 | inline 133 | void 134 | _vector4::set(const float _x, const float _y, const float _z, const float _w) 135 | { 136 | x = _x; 137 | y = _y; 138 | z = _z; 139 | w = _w; 140 | } 141 | 142 | //------------------------------------------------------------------------------ 143 | /** 144 | */ 145 | inline 146 | void 147 | _vector4::set(const _vector4& v) 148 | { 149 | x = v.x; 150 | y = v.y; 151 | z = v.z; 152 | w = v.w; 153 | } 154 | 155 | //------------------------------------------------------------------------------ 156 | /** 157 | */ 158 | inline 159 | void 160 | _vector4::set(const _vector3& v) 161 | { 162 | x = v.x; 163 | y = v.y; 164 | z = v.z; 165 | w = 1.0f; 166 | } 167 | 168 | //------------------------------------------------------------------------------ 169 | /** 170 | */ 171 | inline 172 | float 173 | _vector4::len() const 174 | { 175 | return (float) sqrt(x * x + y * y + z * z + w * w); 176 | } 177 | 178 | //------------------------------------------------------------------------------ 179 | /** 180 | */ 181 | inline 182 | void 183 | _vector4::norm() 184 | { 185 | float l = len(); 186 | if (l > TINY) 187 | { 188 | float oneDivL = 1.0f / l; 189 | x *= oneDivL; 190 | y *= oneDivL; 191 | z *= oneDivL; 192 | w *= oneDivL; 193 | } 194 | } 195 | 196 | //------------------------------------------------------------------------------ 197 | /** 198 | */ 199 | inline 200 | void 201 | _vector4::operator +=(const _vector4& v) 202 | { 203 | x += v.x; 204 | y += v.y; 205 | z += v.z; 206 | w += v.w; 207 | } 208 | 209 | //------------------------------------------------------------------------------ 210 | /** 211 | */ 212 | inline 213 | void 214 | _vector4::operator -=(const _vector4& v) 215 | { 216 | x -= v.x; 217 | y -= v.y; 218 | z -= v.z; 219 | w -= v.w; 220 | } 221 | 222 | //------------------------------------------------------------------------------ 223 | /** 224 | */ 225 | inline 226 | void 227 | _vector4::operator *=(const float s) 228 | { 229 | x *= s; 230 | y *= s; 231 | z *= s; 232 | w *= s; 233 | } 234 | 235 | //------------------------------------------------------------------------------ 236 | /** 237 | */ 238 | inline 239 | _vector4& 240 | _vector4::operator=(const _vector3& v) 241 | { 242 | this->set(v); 243 | return *this; 244 | } 245 | 246 | //------------------------------------------------------------------------------ 247 | /** 248 | */ 249 | inline 250 | bool 251 | _vector4::isequal(const _vector4& v, float tol) const 252 | { 253 | if (fabs(v.x - x) > tol) return false; 254 | else if (fabs(v.y - y) > tol) return false; 255 | else if (fabs(v.z - z) > tol) return false; 256 | else if (fabs(v.w - w) > tol) return false; 257 | return true; 258 | } 259 | 260 | //------------------------------------------------------------------------------ 261 | /** 262 | */ 263 | inline 264 | int 265 | _vector4::compare(const _vector4& v, float tol) const 266 | { 267 | if (fabs(v.x - x) > tol) return (v.x > x) ? +1 : -1; 268 | else if (fabs(v.y - y) > tol) return (v.y > y) ? +1 : -1; 269 | else if (fabs(v.z - z) > tol) return (v.z > z) ? +1 : -1; 270 | else if (fabs(v.w - w) > tol) return (v.w > w) ? +1 : -1; 271 | else return 0; 272 | } 273 | 274 | //------------------------------------------------------------------------------ 275 | /** 276 | */ 277 | inline 278 | void 279 | _vector4::minimum(const _vector4& v) 280 | { 281 | if (v.x < x) x = v.x; 282 | if (v.y < y) y = v.y; 283 | if (v.z < z) z = v.z; 284 | if (v.w < w) w = v.w; 285 | } 286 | 287 | //------------------------------------------------------------------------------ 288 | /** 289 | */ 290 | inline 291 | void 292 | _vector4::maximum(const _vector4& v) 293 | { 294 | if (v.x > x) x = v.x; 295 | if (v.y > y) y = v.y; 296 | if (v.z > z) z = v.z; 297 | if (v.w > w) w = v.w; 298 | } 299 | 300 | //------------------------------------------------------------------------------ 301 | /** 302 | */ 303 | static 304 | inline 305 | _vector4 operator +(const _vector4& v0, const _vector4& v1) 306 | { 307 | return _vector4(v0.x + v1.x, v0.y + v1.y, v0.z + v1.z, v0.w + v1.w); 308 | } 309 | 310 | //------------------------------------------------------------------------------ 311 | /** 312 | */ 313 | static 314 | inline 315 | _vector4 operator -(const _vector4& v0, const _vector4& v1) 316 | { 317 | return _vector4(v0.x - v1.x, v0.y - v1.y, v0.z - v1.z, v0.w - v1.w); 318 | } 319 | 320 | //------------------------------------------------------------------------------ 321 | /** 322 | */ 323 | static 324 | inline 325 | _vector4 operator *(const _vector4& v0, const float& s) 326 | { 327 | return _vector4(v0.x * s, v0.y * s, v0.z * s, v0.w * s); 328 | } 329 | 330 | //------------------------------------------------------------------------------ 331 | /** 332 | */ 333 | static 334 | inline 335 | _vector4 operator -(const _vector4& v) 336 | { 337 | return _vector4(-v.x, -v.y, -v.z, -v.w); 338 | } 339 | 340 | //------------------------------------------------------------------------------ 341 | /** 342 | */ 343 | inline 344 | void 345 | _vector4::setcomp(float val, int mask) 346 | { 347 | if (mask & X) x = val; 348 | if (mask & Y) y = val; 349 | if (mask & Z) z = val; 350 | if (mask & W) w = val; 351 | } 352 | 353 | //------------------------------------------------------------------------------ 354 | /** 355 | */ 356 | inline 357 | float 358 | _vector4::getcomp(int mask) 359 | { 360 | switch (mask) 361 | { 362 | case X: return x; 363 | case Y: return y; 364 | case Z: return z; 365 | default: return w; 366 | } 367 | } 368 | 369 | //------------------------------------------------------------------------------ 370 | /** 371 | */ 372 | inline 373 | int 374 | _vector4::mincompmask() const 375 | { 376 | float minVal = x; 377 | int minComp = X; 378 | if (y < minVal) 379 | { 380 | minComp = Y; 381 | minVal = y; 382 | } 383 | if (z < minVal) 384 | { 385 | minComp = Z; 386 | minVal = z; 387 | } 388 | if (w < minVal) 389 | { 390 | minComp = W; 391 | minVal = w; 392 | } 393 | return minComp; 394 | } 395 | 396 | //------------------------------------------------------------------------------ 397 | /** 398 | */ 399 | inline 400 | void 401 | _vector4::lerp(const _vector4& v0, float lerpVal) 402 | { 403 | x = v0.x + ((x - v0.x) * lerpVal); 404 | y = v0.y + ((y - v0.y) * lerpVal); 405 | z = v0.z + ((z - v0.z) * lerpVal); 406 | w = v0.w + ((w - v0.w) * lerpVal); 407 | } 408 | 409 | //------------------------------------------------------------------------------ 410 | /** 411 | */ 412 | inline 413 | void 414 | _vector4::saturate() 415 | { 416 | x = n_saturate(x); 417 | y = n_saturate(y); 418 | z = n_saturate(z); 419 | w = n_saturate(w); 420 | } 421 | 422 | 423 | //------------------------------------------------------------------------------ 424 | /** 425 | Dot product for vector4 426 | */ 427 | inline 428 | float _vector4::dot(const _vector4& v0) const 429 | { 430 | return ( x * v0.x + y * v0.y + z * v0.z + w * v0.w ); 431 | } 432 | 433 | //------------------------------------------------------------------------------ 434 | #endif 435 | 436 | -------------------------------------------------------------------------------- /ext/mathlib/_vector4_sse.h: -------------------------------------------------------------------------------- 1 | #ifndef _VECTOR4_SSE_H 2 | #define _VECTOR4_SSE_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class _vector4_sse 6 | @ingroup Math 7 | 8 | A vector4 class using SSE. 9 | 10 | (C) 2002 RadonLabs GmbH 11 | */ 12 | #include 13 | 14 | //------------------------------------------------------------------------------ 15 | class _vector4_sse 16 | { 17 | public: 18 | /// constructor 1 19 | _vector4_sse(); 20 | /// constructor 2 21 | _vector4_sse(const float _x, const float _y, const float _z, const float _w); 22 | /// constructor 3 23 | _vector4_sse(const _vector4_sse& vec); 24 | /// set elements 1 25 | void set(const float _x, const float _y, const float _z, const float _w); 26 | /// set elements 2 27 | void set(const _vector4_sse& v); 28 | /// return length 29 | float len() const; 30 | /// normalize 31 | void norm(); 32 | /// inplace add 33 | void operator +=(const _vector4_sse& v); 34 | /// inplace sub 35 | void operator -=(const _vector4_sse& v); 36 | /// inplace scalar mul 37 | void operator *=(const float s); 38 | /// fuzzy compare 39 | bool isequal(const _vector4_sse& v, float tol) const; 40 | /// fuzzy compare, return -1, 0, +1 41 | int compare(const _vector4_sse& v, float tol) const; 42 | /// set own components to minimum 43 | void minimum(const _vector4_sse& v); 44 | /// set own components to maximum 45 | void maximum(const _vector4_sse& v); 46 | /// inplace linear interpolation 47 | void lerp(const _vector4_sse& v0, float lerpVal); 48 | 49 | union 50 | { 51 | __m128 m128; 52 | struct 53 | { 54 | float x, y, z, w; 55 | }; 56 | }; 57 | 58 | /// private constructor, takes _m128 59 | _vector4_sse(const __m128& m); 60 | /// add components 61 | float addhorizontal(const __m128 &a); 62 | }; 63 | 64 | //------------------------------------------------------------------------------ 65 | /** 66 | */ 67 | inline 68 | _vector4_sse::_vector4_sse() 69 | { 70 | m128 = _mm_setzero_ps(); 71 | } 72 | 73 | //------------------------------------------------------------------------------ 74 | /** 75 | */ 76 | inline 77 | _vector4_sse::_vector4_sse(const float _x, const float _y, const float _z, const float _w) 78 | { 79 | m128 = _mm_set_ps(_w, _z, _y, _x); 80 | } 81 | 82 | //------------------------------------------------------------------------------ 83 | /** 84 | */ 85 | inline 86 | _vector4_sse::_vector4_sse(const _vector4_sse& v) 87 | { 88 | m128 = v.m128; 89 | } 90 | 91 | //------------------------------------------------------------------------------ 92 | /** 93 | */ 94 | inline 95 | _vector4_sse::_vector4_sse(const __m128& m) : 96 | m128(m) 97 | { 98 | // empty 99 | } 100 | 101 | //------------------------------------------------------------------------------ 102 | /** 103 | */ 104 | inline 105 | void 106 | _vector4_sse::set(const float _x, const float _y, const float _z, const float _w) 107 | { 108 | m128 = _mm_set_ps(_w, _z, _y, _x); 109 | } 110 | 111 | //------------------------------------------------------------------------------ 112 | /** 113 | */ 114 | inline 115 | void 116 | _vector4_sse::set(const _vector4_sse& v) 117 | { 118 | m128 = v.m128; 119 | } 120 | 121 | //------------------------------------------------------------------------------ 122 | /** 123 | */ 124 | inline 125 | float 126 | _vector4_sse::len() const 127 | { 128 | const int X = 0; 129 | const int Y = 1; 130 | const int Z = 2; 131 | const int W = 3; 132 | 133 | __m128 a = _mm_mul_ps(m128, m128); 134 | 135 | // horizontal add 136 | __m128 b = _mm_add_ss(a, _mm_add_ss(_mm_shuffle_ps(a, a, _MM_SHUFFLE(X,X,X,X)), _mm_add_ss(_mm_shuffle_ps(a, a, _MM_SHUFFLE(Y,Y,Y,Y)), _mm_shuffle_ps(a, a, _MM_SHUFFLE(Z,Z,Z,Z))))); 137 | __m128 l = _mm_sqrt_ss(b); 138 | 139 | return l.m128_f32[X]; 140 | } 141 | 142 | //------------------------------------------------------------------------------ 143 | /** 144 | */ 145 | inline 146 | void 147 | _vector4_sse::norm() 148 | { 149 | const int X = 0; 150 | const int Y = 1; 151 | const int Z = 2; 152 | const int W = 3; 153 | 154 | // get len 155 | __m128 a = _mm_mul_ps(m128, m128); 156 | __m128 b = _mm_add_ss(a, _mm_add_ss(_mm_shuffle_ps(a, a, _MM_SHUFFLE(X,X,X,X)), _mm_add_ss(_mm_shuffle_ps(a, a, _MM_SHUFFLE(Y,Y,Y,Y)), _mm_shuffle_ps(a, a, _MM_SHUFFLE(Z,Z,Z,Z))))); 157 | 158 | // get reciprocal of square root of squared length 159 | __m128 f = _mm_rsqrt_ss(b); 160 | __m128 oneDivLen = _mm_shuffle_ps(f, f, _MM_SHUFFLE(X, X, X, X)); 161 | 162 | m128 = _mm_mul_ps(m128, oneDivLen); 163 | } 164 | 165 | //------------------------------------------------------------------------------ 166 | /** 167 | */ 168 | inline 169 | void 170 | _vector4_sse::operator +=(const _vector4_sse& v) 171 | { 172 | m128 = _mm_add_ps(m128, v.m128); 173 | } 174 | 175 | //------------------------------------------------------------------------------ 176 | /** 177 | */ 178 | inline 179 | void 180 | _vector4_sse::operator -=(const _vector4_sse& v) 181 | { 182 | m128 = _mm_sub_ps(m128, v.m128); 183 | } 184 | 185 | //------------------------------------------------------------------------------ 186 | /** 187 | */ 188 | inline 189 | void 190 | _vector4_sse::operator *=(const float s) 191 | { 192 | __m128 packed = _mm_set1_ps(s); 193 | m128 = _mm_mul_ps(m128, packed); 194 | } 195 | 196 | //------------------------------------------------------------------------------ 197 | /** 198 | */ 199 | inline 200 | bool 201 | _vector4_sse::isequal(const _vector4_sse& v, float tol) const 202 | { 203 | if (fabs(v.x - x) > tol) return false; 204 | else if (fabs(v.y - y) > tol) return false; 205 | else if (fabs(v.z - z) > tol) return false; 206 | else if (fabs(v.w - w) > tol) return false; 207 | return true; 208 | } 209 | 210 | //------------------------------------------------------------------------------ 211 | /** 212 | */ 213 | inline 214 | int 215 | _vector4_sse::compare(const _vector4_sse& v, float tol) const 216 | { 217 | if (fabs(v.x - x) > tol) return (v.x > x) ? +1 : -1; 218 | else if (fabs(v.y - y) > tol) return (v.y > y) ? +1 : -1; 219 | else if (fabs(v.z - z) > tol) return (v.z > z) ? +1 : -1; 220 | else if (fabs(v.w - w) > tol) return (v.w > w) ? +1 : -1; 221 | else return 0; 222 | } 223 | 224 | //------------------------------------------------------------------------------ 225 | /** 226 | */ 227 | inline 228 | void 229 | _vector4_sse::minimum(const _vector4_sse& v) 230 | { 231 | if (v.x < x) x = v.x; 232 | if (v.y < y) y = v.y; 233 | if (v.z < z) z = v.z; 234 | if (v.w < w) w = v.w; 235 | } 236 | 237 | //------------------------------------------------------------------------------ 238 | /** 239 | */ 240 | inline 241 | void 242 | _vector4_sse::maximum(const _vector4_sse& v) 243 | { 244 | if (v.x > x) x = v.x; 245 | if (v.y > y) y = v.y; 246 | if (v.z > z) z = v.z; 247 | if (v.w > w) w = v.w; 248 | } 249 | 250 | //------------------------------------------------------------------------------ 251 | /** 252 | */ 253 | static 254 | inline 255 | _vector4_sse operator +(const _vector4_sse& v0, const _vector4_sse& v1) 256 | { 257 | return _vector4_sse(_mm_add_ps(v0.m128, v1.m128)); 258 | } 259 | 260 | //------------------------------------------------------------------------------ 261 | /** 262 | */ 263 | static 264 | inline 265 | _vector4_sse operator -(const _vector4_sse& v0, const _vector4_sse& v1) 266 | { 267 | return _vector4_sse(_mm_sub_ps(v0.m128, v1.m128)); 268 | } 269 | 270 | //------------------------------------------------------------------------------ 271 | /** 272 | */ 273 | static 274 | inline 275 | _vector4_sse operator *(const _vector4_sse& v0, const float& s) 276 | { 277 | __m128 packed = _mm_set1_ps(s); 278 | return _vector4_sse(_mm_mul_ps(v0.m128, packed)); 279 | } 280 | 281 | //------------------------------------------------------------------------------ 282 | /** 283 | */ 284 | static 285 | inline 286 | _vector4_sse operator -(const _vector4_sse& v) 287 | { 288 | __m128 zero = _mm_setzero_ps(); 289 | return _vector4_sse(_mm_sub_ps(zero, v.m128)); 290 | } 291 | 292 | //------------------------------------------------------------------------------ 293 | /** 294 | */ 295 | inline 296 | void 297 | _vector4_sse::lerp(const _vector4_sse& v0, float lerpVal) 298 | { 299 | x = v0.x + ((x - v0.x) * lerpVal); 300 | y = v0.y + ((y - v0.y) * lerpVal); 301 | z = v0.z + ((z - v0.z) * lerpVal); 302 | w = v0.w + ((w - v0.w) * lerpVal); 303 | } 304 | 305 | //------------------------------------------------------------------------------ 306 | #endif 307 | -------------------------------------------------------------------------------- /ext/mathlib/envelopecurve.h: -------------------------------------------------------------------------------- 1 | #ifndef N_ENVELOPE_CURVE_H 2 | #define N_ENVELOPE_CURVE_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class nEnvelopeCurve 6 | @ingroup Math 7 | 8 | An envelope curve class. 9 | 10 | (C) 2004 RadonLabs GmbH 11 | */ 12 | #include "mathlib/nmath.h" 13 | 14 | //------------------------------------------------------------------------------ 15 | // nEnvelopeVurve 16 | //------------------------------------------------------------------------------ 17 | class nEnvelopeCurve 18 | { 19 | public: 20 | /// possible modulation functions 21 | enum 22 | { 23 | Sine = 0, 24 | Cosine, 25 | }; 26 | 27 | /// constructor 1 28 | nEnvelopeCurve(); 29 | /// constructor 2 30 | nEnvelopeCurve(const float keyFrameValue0, const float keyFrameValue1, 31 | const float keyFrameValue2, const float keyFrameValue3, 32 | const float keyFramePos1, const float keyFramePos2, 33 | const float frequency, const float amplitude, 34 | const int modulationFunc); 35 | // set all parameters 36 | void SetParameters(const float keyFrameValue0, const float keyFrameValue1, 37 | const float keyFrameValue2, const float keyFrameValue3, 38 | const float keyFramePos1, const float keyFramePos2, 39 | const float frequency, const float amplitude, 40 | const int modulationFunc); 41 | // assign to other envelope curve 42 | void SetParameters(const nEnvelopeCurve& src); 43 | /// get the function value; pos must be between 0 and 1 44 | float GetValue(float pos) const; 45 | /// get the highest possible value 46 | float GetMaxPossibleValue() const; 47 | 48 | enum 49 | { 50 | NumValues = 4, 51 | }; 52 | float keyFrameValues[NumValues]; 53 | float keyFramePos1, keyFramePos2; // 0 through 1 54 | float frequency, amplitude; // parameters of the sinus function 55 | int modulationFunc; // use sine or cosine for modulation? 56 | }; 57 | 58 | //------------------------------------------------------------------------------ 59 | /** 60 | */ 61 | inline 62 | nEnvelopeCurve::nEnvelopeCurve() : 63 | keyFramePos1(.2f), 64 | keyFramePos2(.8f), 65 | frequency(.0f), 66 | amplitude(.0f), 67 | modulationFunc(Sine) 68 | { 69 | keyFrameValues[0] = .0f; 70 | keyFrameValues[1] = .0f; 71 | keyFrameValues[2] = .0f; 72 | keyFrameValues[3] = .0f; 73 | } 74 | 75 | //------------------------------------------------------------------------------ 76 | /** 77 | */ 78 | inline 79 | nEnvelopeCurve::nEnvelopeCurve(const float keyFrameValue0, 80 | const float keyFrameValue1, const float keyFrameValue2, 81 | const float keyFrameValue3, const float keyFramePos1, 82 | const float keyFramePos2, const float frequency, 83 | const float amplitude, const int modulationFunc/* = Sine*/) : 84 | keyFramePos1(keyFramePos1), 85 | keyFramePos2(keyFramePos2), 86 | frequency(frequency), 87 | amplitude(amplitude), 88 | modulationFunc(modulationFunc) 89 | { 90 | this->keyFrameValues[0] = keyFrameValue0; 91 | this->keyFrameValues[1] = keyFrameValue1; 92 | this->keyFrameValues[2] = keyFrameValue2; 93 | this->keyFrameValues[3] = keyFrameValue3; 94 | } 95 | 96 | //------------------------------------------------------------------------------ 97 | /** 98 | */ 99 | inline 100 | void nEnvelopeCurve::SetParameters(const float keyFrameValue0, const float keyFrameValue1, 101 | const float keyFrameValue2, const float keyFrameValue3, 102 | const float keyFramePos1, const float keyFramePos2, 103 | const float frequency, const float amplitude, 104 | const int modulationFunc/* = Sine*/) 105 | { 106 | this->keyFrameValues[0] = keyFrameValue0; 107 | this->keyFrameValues[1] = keyFrameValue1; 108 | this->keyFrameValues[2] = keyFrameValue2; 109 | this->keyFrameValues[3] = keyFrameValue3; 110 | this->keyFramePos1 = keyFramePos1; 111 | this->keyFramePos2 = keyFramePos2; 112 | this->frequency = frequency; 113 | this->amplitude = amplitude; 114 | this->modulationFunc = modulationFunc; 115 | } 116 | //------------------------------------------------------------------------------ 117 | /** 118 | */ 119 | inline 120 | void nEnvelopeCurve::SetParameters(const nEnvelopeCurve& src) 121 | { 122 | this->keyFrameValues[0] = src.keyFrameValues[0]; 123 | this->keyFrameValues[1] = src.keyFrameValues[1]; 124 | this->keyFrameValues[2] = src.keyFrameValues[2]; 125 | this->keyFrameValues[3] = src.keyFrameValues[3]; 126 | this->keyFramePos1 = src.keyFramePos1; 127 | this->keyFramePos2 = src.keyFramePos2; 128 | this->frequency = src.frequency; 129 | this->amplitude = src.amplitude; 130 | this->modulationFunc = src.modulationFunc; 131 | } 132 | 133 | //------------------------------------------------------------------------------ 134 | /** 135 | */ 136 | inline 137 | float nEnvelopeCurve::GetValue(float pos) const 138 | { 139 | pos = n_saturate(pos); 140 | 141 | float value; 142 | if (pos < this->keyFramePos1) 143 | { 144 | value = this->keyFrameValues[0] + 145 | (this->keyFrameValues[1] - this->keyFrameValues[0]) * 146 | (pos / this->keyFramePos1); 147 | } 148 | else if (pos < this->keyFramePos2) 149 | { 150 | value = this->keyFrameValues[1] + 151 | (this->keyFrameValues[2] - this->keyFrameValues[1]) * 152 | ((pos-this->keyFramePos1) / (this->keyFramePos2-this->keyFramePos1)); 153 | } 154 | else 155 | { 156 | value = this->keyFrameValues[2] + 157 | (this->keyFrameValues[3] - this->keyFrameValues[2]) * 158 | ((pos-this->keyFramePos2) / (1.0f-this->keyFramePos2)); 159 | } 160 | 161 | if (this->amplitude > 0.0f) 162 | { 163 | if (Sine == this->modulationFunc) 164 | { 165 | value += n_sin(pos * N_PI * 2 * this->frequency) * this->amplitude; 166 | } 167 | else 168 | { 169 | value += n_cos(pos * N_PI * 2 * this->frequency) * this->amplitude; 170 | } 171 | } 172 | 173 | return value; 174 | } 175 | 176 | //------------------------------------------------------------------------------ 177 | /** 178 | */ 179 | inline 180 | float nEnvelopeCurve::GetMaxPossibleValue() const 181 | { 182 | float maxVal; 183 | int keyFrame; 184 | maxVal = this->keyFrameValues[0]; 185 | for (keyFrame = 1; keyFrame < NumValues; keyFrame++) 186 | { 187 | maxVal = n_max(maxVal, this->keyFrameValues[keyFrame]); 188 | } 189 | 190 | return maxVal + this->amplitude; 191 | } 192 | //------------------------------------------------------------------------------ 193 | #endif 194 | -------------------------------------------------------------------------------- /ext/mathlib/euler.h: -------------------------------------------------------------------------------- 1 | /**** EulerAngles.h - Support for 24 angle schemes ****/ 2 | /* Ken Shoemake, 1993 */ 3 | #ifndef _H_EulerAngles 4 | #define _H_EulerAngles 5 | 6 | /*** Definitions ***/ 7 | typedef struct {float x, y, z, w;} QuatX; /* Quaternion */ 8 | //enum QuatPart {X, Y, Z, W}; 9 | typedef float HMatrix[4][4]; /* Right-handed, for column vectors */ 10 | typedef QuatX EulerAngles; /* (x,y,z)=ang 1,2,3, w=order code */ 11 | 12 | /*** Order type constants, constructors, extractors ***/ 13 | /* There are 24 possible conventions, designated by: */ 14 | /* o EulAxI = axis used initially */ 15 | /* o EulPar = parity of axis permutation */ 16 | /* o EulRep = repetition of initial axis as last */ 17 | /* o EulFrm = frame from which axes are taken */ 18 | /* Axes I,J,K will be a permutation of X,Y,Z. */ 19 | /* Axis H will be either I or K, depending on EulRep. */ 20 | /* Frame S takes axes from initial static frame. */ 21 | /* If ord = (AxI=X, Par=Even, Rep=No, Frm=S), then */ 22 | /* {a,b,c,ord} means Rz(c)Ry(b)Rx(a), where Rz(c)v */ 23 | /* rotates v around Z by c radians. */ 24 | #define EulFrmS 0 25 | #define EulFrmR 1 26 | #define EulFrm(ord) ((unsigned)(ord)&1) 27 | #define EulRepNo 0 28 | #define EulRepYes 1 29 | #define EulRep(ord) (((unsigned)(ord)>>1)&1) 30 | #define EulParEven 0 31 | #define EulParOdd 1 32 | #define EulPar(ord) (((unsigned)(ord)>>2)&1) 33 | #define EulSafe "\000\001\002\000" 34 | #define EulNext "\001\002\000\001" 35 | #define EulAxI(ord) ((int)(EulSafe[(((unsigned)(ord)>>3)&3)])) 36 | #define EulAxJ(ord) ((int)(EulNext[EulAxI(ord)+(EulPar(ord)==EulParOdd)])) 37 | #define EulAxK(ord) ((int)(EulNext[EulAxI(ord)+(EulPar(ord)!=EulParOdd)])) 38 | #define EulAxH(ord) ((EulRep(ord)==EulRepNo)?EulAxK(ord):EulAxI(ord)) 39 | /* EulGetOrd unpacks all useful information about order simultaneously. */ 40 | #define EulGetOrd(ord,i,j,k,h,n,s,f) {unsigned o=ord;f=o&1;o>>=1;s=o&1;o>>=1;\ 41 | n=o&1;o>>=1;i=EulSafe[o&3];j=EulNext[i+n];k=EulNext[i+1-n];h=s?k:i;} 42 | /* EulOrd creates an order value between 0 and 23 from 4-tuple choices. */ 43 | #define EulOrd(i,p,r,f) (((((((i)<<1)+(p))<<1)+(r))<<1)+(f)) 44 | /* Static axes */ 45 | enum xx_yy_zz_ww 46 | { 47 | XX = (1<<0), 48 | YY = (1<<1), 49 | ZZ = (1<<2), 50 | WW = (1<<3), 51 | }; 52 | 53 | #define EulOrdXYZs EulOrd(XX,EulParEven,EulRepNo,EulFrmS) 54 | #define EulOrdXYXs EulOrd(XX,EulParEven,EulRepYes,EulFrmS) 55 | #define EulOrdXZYs EulOrd(XX,EulParOdd,EulRepNo,EulFrmS) 56 | #define EulOrdXZXs EulOrd(XX,EulParOdd,EulRepYes,EulFrmS) 57 | #define EulOrdYZXs EulOrd(YY,EulParEven,EulRepNo,EulFrmS) 58 | #define EulOrdYZYs EulOrd(YY,EulParEven,EulRepYes,EulFrmS) 59 | #define EulOrdYXZs EulOrd(YY,EulParOdd,EulRepNo,EulFrmS) 60 | #define EulOrdYXYs EulOrd(YY,EulParOdd,EulRepYes,EulFrmS) 61 | #define EulOrdZXYs EulOrd(ZZ,EulParEven,EulRepNo,EulFrmS) 62 | #define EulOrdZXZs EulOrd(ZZ,EulParEven,EulRepYes,EulFrmS) 63 | #define EulOrdZYXs EulOrd(ZZ,EulParOdd,EulRepNo,EulFrmS) 64 | #define EulOrdZYZs EulOrd(ZZ,EulParOdd,EulRepYes,EulFrmS) 65 | /* Rotating axes */ 66 | #define EulOrdZYXr EulOrd(XX,EulParEven,EulRepNo,EulFrmR) 67 | #define EulOrdXYXr EulOrd(XX,EulParEven,EulRepYes,EulFrmR) 68 | #define EulOrdYZXr EulOrd(XX,EulParOdd,EulRepNo,EulFrmR) 69 | #define EulOrdXZXr EulOrd(XX,EulParOdd,EulRepYes,EulFrmR) 70 | #define EulOrdXZYr EulOrd(YY,EulParEven,EulRepNo,EulFrmR) 71 | #define EulOrdYZYr EulOrd(YY,EulParEven,EulRepYes,EulFrmR) 72 | #define EulOrdZXYr EulOrd(YY,EulParOdd,EulRepNo,EulFrmR) 73 | #define EulOrdYXYr EulOrd(YY,EulParOdd,EulRepYes,EulFrmR) 74 | #define EulOrdYXZr EulOrd(ZZ,EulParEven,EulRepNo,EulFrmR) 75 | #define EulOrdZXZr EulOrd(ZZ,EulParEven,EulRepYes,EulFrmR) 76 | #define EulOrdXYZr EulOrd(ZZ,EulParOdd,EulRepNo,EulFrmR) 77 | #define EulOrdZYZr EulOrd(ZZ,EulParOdd,EulRepYes,EulFrmR) 78 | 79 | EulerAngles Eul_(float ai, float aj, float ah, int order); 80 | QuatX Eul_ToQuat(EulerAngles ea); 81 | void Eul_ToHMatrix(EulerAngles ea, HMatrix M); 82 | EulerAngles Eul_FromHMatrix(HMatrix M, int order); 83 | EulerAngles Eul_FromQuat(QuatX q, int order); 84 | #endif 85 | -------------------------------------------------------------------------------- /ext/mathlib/eulerangles.h: -------------------------------------------------------------------------------- 1 | #ifndef N_EULERANGLES_H 2 | #define N_EULERANGLES_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class nEulerAngles 6 | @ingroup Math 7 | 8 | A class representing a rotation using 3 euler angles. 9 | 10 | (C) 2004 RadonLabs GmbH 11 | */ 12 | #include 13 | #include 14 | #include "mathlib/matrix.h" 15 | #include "mathlib/euler.h" 16 | 17 | //------------------------------------------------------------------- 18 | /** 19 | @class nEulerAngles 20 | @ingroup NebulaMathDataTypes 21 | */ 22 | //------------------------------------------------------------------- 23 | class nEulerAngles { 24 | public: 25 | float x,y,z; 26 | 27 | //-- constructors ----------------------------------------------- 28 | nEulerAngles() 29 | : x(0.0f), 30 | y(0.0f), 31 | z(0.0f) 32 | {}; 33 | nEulerAngles(float _x, float _y, float _z) 34 | : x(_x), 35 | y(_y), 36 | z(_z) 37 | {}; 38 | nEulerAngles(const nEulerAngles& e) 39 | : x(e.x), 40 | y(e.y), 41 | z(e.z) 42 | {}; 43 | nEulerAngles(const matrix33& m) 44 | { 45 | Set(m); 46 | } 47 | 48 | //-- setting elements ------------------------------------------- 49 | void Set(float _x, float _y, float _z) 50 | { 51 | x = _x; 52 | y = _y; 53 | z = _z; 54 | }; 55 | void Set(const nEulerAngles& e) 56 | { 57 | x = e.x; 58 | y = e.y; 59 | z = e.z; 60 | }; 61 | void Set(const matrix33& m) 62 | { 63 | int i,j,k,h,n,s,f; 64 | EulGetOrd(EulOrdXYZs,i,j,k,h,n,s,f); 65 | if (s == EulRepYes) 66 | { 67 | double sy = (float) sqrt(m.m[0][1]*m.m[0][1] + m.m[0][2]*m.m[0][2]); 68 | if (sy > 16*FLT_EPSILON) 69 | { 70 | this->x = (float) atan2(m.m[0][1], m.m[0][2]); 71 | this->y = (float) atan2(sy, m.m[0][0]); 72 | this->z = (float) atan2(m.m[1][0], -m.m[2][0]); 73 | } 74 | else 75 | { 76 | this->x = (float) atan2(-m.m[1][2], m.m[1][1]); 77 | this->y = (float) atan2(sy, m.m[0][0]); 78 | this->z = 0; 79 | } 80 | } 81 | else 82 | { 83 | double cy = sqrt(m.m[0][0]*m.m[0][0] + m.m[1][0]*m.m[1][0]); 84 | if (cy > 16*FLT_EPSILON) 85 | { 86 | this->x = (float) atan2(m.m[2][1], m.m[2][2]); 87 | this->y = (float) atan2(-m.m[2][0], cy); 88 | this->z = (float) atan2(m.m[1][0], m.m[0][0]); 89 | } 90 | else 91 | { 92 | this->x = (float) atan2(-m.m[1][2], m.m[1][1]); 93 | this->y = (float) atan2(-m.m[2][0], cy); 94 | this->z = 0; 95 | } 96 | } 97 | if (n==EulParOdd) 98 | { 99 | this->x = -this->x; 100 | this->y = -this->y; 101 | this->z = -this->z; 102 | } 103 | if (f==EulFrmR) 104 | { 105 | float t = this->x; 106 | this->x = this->z; 107 | this->z = t; 108 | } 109 | } 110 | 111 | matrix33 GetMatrix() 112 | { 113 | matrix33 mat; 114 | 115 | double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss; 116 | int i,j,k,h,n,s,f; 117 | EulGetOrd(EulOrdXYZs,i,j,k,h,n,s,f); 118 | if (f==EulFrmR) {float t = x; x = z; z = t;} 119 | if (n==EulParOdd) {x = -x; y = -y; z = -z;} 120 | ti = x; tj = y; th = z; 121 | ci = cos(ti); cj = cos(tj); ch = cos(th); 122 | si = sin(ti); sj = sin(tj); sh = sin(th); 123 | cc = ci*ch; cs = ci*sh; sc = si*ch; ss = si*sh; 124 | if (s==EulRepYes) { 125 | mat.M11 = (float)(cj); mat.M12 = (float)( sj*si); mat.M13 = (float)( sj*ci); 126 | mat.M21 = (float)(sj*sh); mat.M22 = (float)(-cj*ss+cc); mat.M23 = (float)(-cj*cs-sc); 127 | mat.M31 = (float)(-sj*ch); mat.M23 = (float)( cj*sc+cs); mat.M33 = (float)( cj*cc-ss); 128 | } else { 129 | mat.M11 = (float)(cj*ch); mat.M12 = (float)(sj*sc-cs); mat.M13 = (float)(sj*cc+ss); 130 | mat.M21 = (float)(cj*sh); mat.M22 = (float)(sj*ss+cc); mat.M23 = (float)(sj*cs-sc); 131 | mat.M31 = (float)(-sj); mat.M32 = (float)(cj*si); mat.M33 = (float)(cj*ci); 132 | } 133 | 134 | return mat; 135 | } 136 | 137 | //-- operators -------------------------------------------------- 138 | bool operator== (const nEulerAngles& e) 139 | { 140 | return ((x == e.x) && (y == e.y) && (z == e.z)) ? true : false; 141 | } 142 | 143 | bool operator!= (const nEulerAngles& e) 144 | { 145 | return ((x != e.x) || (y != e.y) || (z != e.z)) ? true : false; 146 | } 147 | }; 148 | 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /ext/mathlib/line.h: -------------------------------------------------------------------------------- 1 | #ifndef N_LINE_H 2 | #define N_LINE_H 3 | //------------------------------------------------------------------- 4 | /** 5 | @class line2 6 | @ingroup Math 7 | 8 | A 2- and 3-dimensional line objects. 9 | 10 | (C) 2004 RadonLabs GmbH 11 | */ 12 | #include "mathlib/vector.h" 13 | 14 | //------------------------------------------------------------------- 15 | class line2 16 | { 17 | public: 18 | /// constructor 19 | line2(); 20 | /// constructor #2 21 | line2(const vector2& v0, const vector2& v1); 22 | /// copy constructor 23 | line2(const line2& rhs); 24 | /// return start point 25 | const vector2& start() const; 26 | /// return end point 27 | vector2 end() const; 28 | /// return vector 29 | const vector2& vec() const; 30 | /// return length 31 | float len() const; 32 | /// get point on line given t 33 | vector2 ipol(const float t) const; 34 | 35 | vector2 b; 36 | vector2 m; 37 | }; 38 | 39 | //------------------------------------------------------------------- 40 | /** 41 | */ 42 | inline 43 | line2::line2() 44 | { 45 | // empty 46 | } 47 | 48 | //------------------------------------------------------------------- 49 | /** 50 | */ 51 | inline 52 | line2::line2(const vector2& v0, const vector2& v1) : 53 | b(v0), 54 | m(v1 - v0) 55 | { 56 | // empty 57 | } 58 | 59 | //------------------------------------------------------------------- 60 | /** 61 | */ 62 | inline 63 | line2::line2(const line2& rhs) : 64 | b(rhs.b), 65 | m(rhs.m) 66 | { 67 | // empty 68 | } 69 | 70 | //------------------------------------------------------------------- 71 | /** 72 | */ 73 | inline 74 | const vector2& 75 | line2::start() const 76 | { 77 | return this->b; 78 | } 79 | 80 | //------------------------------------------------------------------- 81 | /** 82 | */ 83 | inline 84 | vector2 85 | line2::end() const 86 | { 87 | return this->b + this->m; 88 | } 89 | 90 | //------------------------------------------------------------------- 91 | /** 92 | */ 93 | inline 94 | const vector2& 95 | line2::vec() const 96 | { 97 | return this->m; 98 | } 99 | 100 | //------------------------------------------------------------------- 101 | /** 102 | */ 103 | inline 104 | float 105 | line2::len() const 106 | { 107 | return m.len(); 108 | } 109 | 110 | //------------------------------------------------------------------- 111 | /** 112 | */ 113 | inline 114 | vector2 115 | line2::ipol(const float t) const 116 | { 117 | return vector2(b + m * t); 118 | } 119 | 120 | //------------------------------------------------------------------------------ 121 | /** 122 | @class line3 123 | @ingroup Math 124 | */ 125 | class line3 126 | { 127 | public: 128 | /// constructor 129 | line3(); 130 | /// constructor #2 131 | line3(const vector3& v0, const vector3& v1); 132 | /// copy constructor 133 | line3(const line3& l); 134 | /// set start and end point 135 | void set(const vector3& v0, const vector3& v1); 136 | /// get start point 137 | const vector3& start() const; 138 | /// get end point 139 | vector3 end() const; 140 | /// get vector 141 | const vector3& vec() const; 142 | /// get length 143 | float len() const; 144 | /// get squared length 145 | float lensquared() const; 146 | /// minimal distance of point to line 147 | float distance(const vector3& p) const; 148 | /// get point on line at t 149 | vector3 ipol(float t) const; 150 | 151 | vector3 b; 152 | vector3 m; 153 | }; 154 | 155 | //------------------------------------------------------------------------------ 156 | /** 157 | */ 158 | inline 159 | line3::line3() 160 | { 161 | // empty 162 | } 163 | 164 | //------------------------------------------------------------------------------ 165 | /** 166 | */ 167 | inline 168 | line3::line3(const vector3& v0, const vector3& v1) : 169 | b(v0), 170 | m(v1 - v0) 171 | { 172 | // empty 173 | } 174 | 175 | //------------------------------------------------------------------------------ 176 | /** 177 | */ 178 | inline 179 | line3::line3(const line3& rhs) : 180 | b(rhs.b), 181 | m(rhs.m) 182 | { 183 | // empty 184 | } 185 | 186 | //------------------------------------------------------------------------------ 187 | /** 188 | */ 189 | inline 190 | void 191 | line3::set(const vector3& v0, const vector3& v1) 192 | { 193 | this->b = v0; 194 | this->m = v1 - v0; 195 | } 196 | 197 | //------------------------------------------------------------------------------ 198 | /** 199 | */ 200 | inline 201 | const vector3& 202 | line3::start() const 203 | { 204 | return this->b; 205 | } 206 | 207 | //------------------------------------------------------------------------------ 208 | /** 209 | */ 210 | inline 211 | vector3 212 | line3::end() const 213 | { 214 | return this->b + this->m; 215 | } 216 | 217 | //------------------------------------------------------------------------------ 218 | /** 219 | */ 220 | inline 221 | const vector3& 222 | line3::vec() const 223 | { 224 | return this->m; 225 | } 226 | 227 | //------------------------------------------------------------------------------ 228 | /** 229 | */ 230 | inline 231 | float 232 | line3::len() const 233 | { 234 | return this->m.len(); 235 | } 236 | 237 | //------------------------------------------------------------------------------ 238 | /** 239 | */ 240 | inline 241 | float 242 | line3::lensquared() const 243 | { 244 | return this->m.lensquared(); 245 | } 246 | 247 | //------------------------------------------------------------------------------ 248 | /** 249 | */ 250 | inline 251 | float 252 | line3::distance(const vector3& p) const 253 | { 254 | vector3 diff(p - this->b); 255 | float l = (this->m % this->m); 256 | if (l > 0.0f) 257 | { 258 | float t = (this->m % diff) / l; 259 | diff = diff - this->m * t; 260 | return diff.len(); 261 | } else { 262 | // line is really a point... 263 | vector3 v(p - this->b); 264 | return v.len(); 265 | } 266 | } 267 | 268 | //------------------------------------------------------------------------------ 269 | /** 270 | */ 271 | inline 272 | vector3 273 | line3::ipol(const float t) const 274 | { 275 | return vector3(b + m*t); 276 | } 277 | 278 | //------------------------------------------------------------------------------ 279 | #endif 280 | -------------------------------------------------------------------------------- /ext/mathlib/matrix.h: -------------------------------------------------------------------------------- 1 | #ifndef N_MATRIX_H 2 | #define N_MATRIX_H 3 | //------------------------------------------------------------------- 4 | // CLASSES 5 | // matrix33 -- 3x3 matrix 6 | // matrix34 -- 3x4 matrix 7 | // matrix44 -- 4x4 matrix 8 | //------------------------------------------------------------------- 9 | #include "mathlib/ntypes.h" 10 | 11 | #ifndef __USE_SSE__ 12 | #include "mathlib/_matrix33.h" 13 | #include "mathlib/_matrix44.h" 14 | typedef _matrix33 matrix33; 15 | typedef _matrix44 matrix44; 16 | #else 17 | #include "mathlib/_matrix33_sse.h" 18 | #include "mathlib/_matrix44_sse.h" 19 | typedef _matrix33_sse matrix33; 20 | typedef _matrix44_sse matrix44; 21 | #endif 22 | 23 | //------------------------------------------------------------------- 24 | #endif 25 | -------------------------------------------------------------------------------- /ext/mathlib/matrixdefs.h: -------------------------------------------------------------------------------- 1 | #ifndef N_MATRIXDEFS_H 2 | #define N_MATRIXDEFS_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | Common defines for matrix classes. 6 | 7 | (C) 2002 RadonLabs GmbH 8 | */ 9 | #define M11 m[0][0] 10 | #define M12 m[0][1] 11 | #define M13 m[0][2] 12 | #define M14 m[0][3] 13 | #define M21 m[1][0] 14 | #define M22 m[1][1] 15 | #define M23 m[1][2] 16 | #define M24 m[1][3] 17 | #define M31 m[2][0] 18 | #define M32 m[2][1] 19 | #define M33 m[2][2] 20 | #define M34 m[2][3] 21 | #define M41 m[3][0] 22 | #define M42 m[3][1] 23 | #define M43 m[3][2] 24 | #define M44 m[3][3] 25 | 26 | //------------------------------------------------------------------------------ 27 | #endif 28 | -------------------------------------------------------------------------------- /ext/mathlib/nmath.h: -------------------------------------------------------------------------------- 1 | #ifndef N_MATH_H 2 | #define N_MATH_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | General math functions and macros. 6 | 7 | (C) 2003 RadonLabs GmbH 8 | */ 9 | #include 10 | #include 11 | 12 | #ifdef _MSC_VER 13 | #define isnan _isnan 14 | #define isinf _isinf 15 | #endif 16 | 17 | #ifndef PI 18 | #define PI (3.1415926535897932384626433832795028841971693993751f) 19 | #endif 20 | 21 | #define N_PI PI 22 | 23 | #ifndef TINY 24 | #define TINY (0.0000001f) 25 | #endif 26 | 27 | #define n_max(a,b) (((a) > (b)) ? (a) : (b)) 28 | #define n_min(a,b) (((a) < (b)) ? (a) : (b)) 29 | #define n_abs(a) (((a)<0.0f) ? (-(a)) : (a)) 30 | #define n_sgn(a) (((a)<0.0f) ? (-1) : (1)) 31 | #define n_deg2rad(d) (((d)*PI)/180.0f) 32 | #define n_rad2deg(r) (((r)*180.0f)/PI) 33 | #define n_sin(x) (float(sin(x))) 34 | #define n_cos(x) (float(cos(x))) 35 | #define n_tan(x) (float(tan(x))) 36 | #define n_atan(x) (float(atan(x))) 37 | 38 | //------------------------------------------------------------------------------ 39 | /** 40 | log2() function. 41 | */ 42 | const float LN_2 = 0.693147180559945f; 43 | inline float n_log2(float f) 44 | { 45 | return logf(f) / LN_2; 46 | } 47 | 48 | //------------------------------------------------------------------------------ 49 | /** 50 | Integer clamping. 51 | */ 52 | inline int n_iclamp(int val, int minVal, int maxVal) 53 | { 54 | if (val < minVal) return minVal; 55 | else if (val > maxVal) return maxVal; 56 | else return val; 57 | } 58 | 59 | //------------------------------------------------------------------------------ 60 | /** 61 | acos with value clamping. 62 | */ 63 | inline float n_acos(float x) 64 | { 65 | if(x > 1.0f) x = 1.0f; 66 | if(x < -1.0f) x = -1.0f; 67 | return (float)acos(x); 68 | } 69 | 70 | //------------------------------------------------------------------------------ 71 | /** 72 | asin with value clamping. 73 | */ 74 | inline float n_asin(float x) 75 | { 76 | if(x > 1.0f) x = 1.0f; 77 | if(x < -1.0f) x = -1.0f; 78 | return (float)asin(x); 79 | } 80 | 81 | //------------------------------------------------------------------------------ 82 | /** 83 | Safe sqrt. 84 | */ 85 | inline float n_sqrt(float x) 86 | { 87 | if (x < 0.0f) x = (float) 0.0f; 88 | return (float) sqrt(x); 89 | } 90 | 91 | //------------------------------------------------------------------------------ 92 | /** 93 | A fuzzy floating point equality check 94 | */ 95 | inline bool n_fequal(float f0, float f1, float tol) { 96 | float f = f0-f1; 97 | if ((f>(-tol)) && (ftol) return true; 116 | else return false; 117 | } 118 | 119 | //------------------------------------------------------------------------------ 120 | /** 121 | fast float to int conversion (always truncates) 122 | see http://www.stereopsis.com/FPU.html for a discussion. 123 | NOTE: this works only on x86 endian machines. 124 | */ 125 | inline long n_ftol(float val) 126 | { 127 | double v = double(val) + (68719476736.0*1.5); 128 | return ((long*)&v)[0] >> 16; 129 | } 130 | 131 | //------------------------------------------------------------------------------ 132 | /** 133 | Smooth a new value towards an old value using a change value. 134 | */ 135 | inline float n_smooth(float newVal, float curVal, float maxChange) 136 | { 137 | float diff = newVal - curVal; 138 | if (fabs(diff) > maxChange) 139 | { 140 | if (diff > 0.0f) 141 | { 142 | curVal += maxChange; 143 | if (curVal > newVal) 144 | { 145 | curVal = newVal; 146 | } 147 | } 148 | else if (diff < 0.0f) 149 | { 150 | curVal -= maxChange; 151 | if (curVal < newVal) 152 | { 153 | curVal = newVal; 154 | } 155 | } 156 | } 157 | else 158 | { 159 | curVal = newVal; 160 | } 161 | return curVal; 162 | } 163 | 164 | //------------------------------------------------------------------------------ 165 | /** 166 | Clamp a value against lower und upper boundary. 167 | */ 168 | inline float n_clamp(float val, float lower, float upper) 169 | { 170 | if (val < lower) return lower; 171 | else if (val > upper) return upper; 172 | else return val; 173 | } 174 | 175 | //------------------------------------------------------------------------------ 176 | /** 177 | Saturate a value (clamps between 0.0f and 1.0f) 178 | */ 179 | inline float n_saturate(float val) 180 | { 181 | if (val < 0.0f) return 0.0f; 182 | else if (val > 1.0f) return 1.0f; 183 | else return val; 184 | } 185 | 186 | //------------------------------------------------------------------------------ 187 | /** 188 | Return a pseudo random number between 0 and 1. 189 | */ 190 | inline float n_rand() 191 | { 192 | return float(rand()) / float(RAND_MAX); 193 | } 194 | 195 | //------------------------------------------------------------------------------ 196 | /** 197 | Chop float to int. 198 | */ 199 | inline int n_fchop(float f) 200 | { 201 | // FIXME! 202 | return int(f); 203 | } 204 | 205 | //------------------------------------------------------------------------------ 206 | /** 207 | Round float to integer. 208 | */ 209 | inline int n_frnd(float f) 210 | { 211 | return n_fchop(floorf(f + 0.5f)); 212 | } 213 | 214 | //------------------------------------------------------------------------------ 215 | /** 216 | Linearly interpolate between 2 values: ret = x + l * (y - x) 217 | */ 218 | inline float n_lerp(float x, float y, float l) 219 | { 220 | return x + l * (y - x); 221 | } 222 | 223 | //------------------------------------------------------------------------------ 224 | #endif 225 | 226 | -------------------------------------------------------------------------------- /ext/mathlib/noise.h: -------------------------------------------------------------------------------- 1 | #ifndef N_PERLIN_H 2 | #define N_PERLIN_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class noise 6 | @ingroup Math 7 | 8 | Perlin noise class. 9 | 10 | See http://mrl.nyu.edu/~perlin/noise/ for details. 11 | 12 | (C) 2004 RadonLabs GmbH 13 | */ 14 | #include "kernel/ntypes.h" 15 | #include "math.h" 16 | 17 | //------------------------------------------------------------------------------ 18 | class noise 19 | { 20 | public: 21 | /// generate noise value 22 | static float gen(float x, float y, float z); 23 | 24 | private: 25 | /// compute fade curve 26 | static float fade(float t); 27 | /// lerp between a and b 28 | static float lerp(float t, float a, float b); 29 | /// convert into gradient direction 30 | static float grad(int hash, float x, float y, float z); 31 | 32 | static int perm[512]; 33 | }; 34 | 35 | //------------------------------------------------------------------------------ 36 | /** 37 | */ 38 | inline 39 | float 40 | noise::fade(float t) 41 | { 42 | return t * t * t * (t * (t * 6.0f - 15.0f) + 10.0f); 43 | } 44 | 45 | //------------------------------------------------------------------------------ 46 | /** 47 | */ 48 | inline 49 | float 50 | noise::lerp(float t, float a, float b) 51 | { 52 | return a + t * (b - a); 53 | } 54 | 55 | //------------------------------------------------------------------------------ 56 | /** 57 | */ 58 | inline 59 | float 60 | noise::grad(int hash, float x, float y, float z) 61 | { 62 | int h = hash & 15; 63 | float u = h < 8 ? x : y; 64 | float v = h < 4 ? y : ((h == 12) || (h==14)) ? x : z; 65 | return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); 66 | } 67 | 68 | //------------------------------------------------------------------------------ 69 | /** 70 | */ 71 | inline 72 | float 73 | noise::gen(float x, float y, float z) 74 | { 75 | float floorX = floorf(x); 76 | float floorY = floorf(y); 77 | float floorZ = floorf(z); 78 | 79 | // find unit cube that contains point 80 | int X = int(floorX) & 255; 81 | int Y = int(floorY) & 255; 82 | int Z = int(floorZ) & 255; 83 | 84 | // find relative x,y,z of point in cube 85 | x -= floorX; 86 | y -= floorY; 87 | z -= floorZ; 88 | 89 | // compute fade curves for x, y, z 90 | float u = fade(x); 91 | float v = fade(y); 92 | float w = fade(z); 93 | 94 | // hash coords of 8 cube corners 95 | int A = perm[X] + Y; 96 | int AA = perm[A] + Z; 97 | int AB = perm[A+1] + Z; 98 | int B = perm[X+1] + Y; 99 | int BA = perm[B] + Z; 100 | int BB = perm[B+1] + Z; 101 | 102 | // add blended results from 8 corners of cube 103 | return lerp(w, lerp(v, lerp(u, grad(perm[AA ], x , y , z ), 104 | grad(perm[BA ], x-1, y , z )), 105 | lerp(u, grad(perm[AB ], x , y-1, z ), 106 | grad(perm[BB ], x-1, y-1, z ))), 107 | lerp(v, lerp(u, grad(perm[AA+1], x , y , z-1 ), 108 | grad(perm[BA+1], x-1, y , z-1 )), 109 | lerp(u, grad(perm[AB+1], x , y-1, z-1 ), 110 | grad(perm[BB+1], x-1, y-1, z-1 )))); 111 | } 112 | 113 | //------------------------------------------------------------------------------ 114 | #endif -------------------------------------------------------------------------------- /ext/mathlib/ntypes.h: -------------------------------------------------------------------------------- 1 | #ifndef N_TYPES_H 2 | #define N_TYPES_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | Lowlevel Nebula defs. 6 | 7 | (C) 2002 RadonLabs GmbH 8 | */ 9 | #ifndef __XBxX__ 10 | #include 11 | #include 12 | #endif 13 | 14 | //#include "kernel/nsystem.h" 15 | //#include "kernel/ndebug.h" 16 | //#include "kernel/ndefclass.h" 17 | 18 | // Shortcut Typedefs 19 | typedef unsigned long ulong; 20 | //typedef unsigned int uint; 21 | ////typedef unsigned short ushort; 22 | //typedef unsigned char uchar; 23 | //typedef float float2[2]; 24 | //typedef float float3[3]; 25 | //typedef float float4[4]; 26 | struct nFloat4 27 | { 28 | float x; 29 | float y; 30 | float z; 31 | float w; 32 | }; 33 | struct nFloat3 34 | { 35 | float x; 36 | float y; 37 | float z; 38 | }; 39 | struct nFloat2 40 | { 41 | float x; 42 | float y; 43 | }; 44 | typedef unsigned int nFourCC; 45 | typedef double nTime; 46 | 47 | #ifndef NULL 48 | #define NULL (0L) 49 | #endif 50 | 51 | //------------------------------------------------------------------------------ 52 | #define N_MAXPATH (512) // maximum length for complete path 53 | #define N_MAXNAMELEN (32) // maximum length for single path component 54 | 55 | //------------------------------------------------------------------------------ 56 | #define nID(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d)) 57 | #define MAKE_FOURCC(ch0,ch1,ch2,ch3) (ch0 | ch1<<8 | ch2<<16 | ch3<<24) 58 | #define FOURCC(i) (((i&0xff000000)>>24) | ((i&0x00ff0000)>>8) | ((i&0x0000ff00)<<8) | ((i&0x000000ff)<<24)) 59 | #define N_WHITESPACE " \r\n\t" 60 | 61 | #ifdef __LINUX__ 62 | #define n_stricmp strcasecmp 63 | #else 64 | #define n_stricmp stricmp 65 | #endif 66 | 67 | #ifdef __WIN32__ 68 | #define snprintf _snprintf 69 | #define vsnprintf _vsnprintf 70 | #endif 71 | 72 | // maps unsigned 8 bits/channel to D3DCOLOR 73 | #define N_ARGB(a,r,g,b) ((uint)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) 74 | #define N_RGBA(r,g,b,a) N_ARGB(a,r,g,b) 75 | #define N_XRGB(r,g,b) N_ARGB(0xff,r,g,b) 76 | #define N_COLORVALUE(r,g,b,a) N_RGBA((uint)((r)*255.f),(uint)((g)*255.f),(uint)((b)*255.f),(uint)((a)*255.f)) 77 | 78 | //------------------------------------------------------------------------------ 79 | // public kernel C functions 80 | //------------------------------------------------------------------------------ 81 | /* 82 | void __cdecl n_printf(const char *, ...); 83 | void __cdecl n_error(const char*, ...); 84 | void __cdecl n_message(const char*, ...); 85 | void n_sleep(double); 86 | char *n_strdup(const char *); 87 | char *n_strncpy2(char *, const char *, size_t); 88 | bool n_strmatch(const char *, const char *); 89 | void n_strcat(char *, const char *, size_t); 90 | 91 | void n_barf(const char *, const char *, int); 92 | void n_barf2(const char*, const char*, const char*, int); 93 | 94 | void *n_dllopen(const char *); 95 | void n_dllclose(void *); 96 | void *n_dllsymbol(void *, const char *); 97 | 98 | nFourCC n_strtofourcc(const char*); 99 | const char* n_fourcctostr(nFourCC); 100 | */ 101 | //------------------------------------------------------------------------------ 102 | // Nebula memory management and debugging stuff. 103 | //------------------------------------------------------------------------------ 104 | extern bool nMemoryLoggingEnabled; 105 | struct nMemoryStats 106 | { 107 | int highWaterSize; // max allocated size so far 108 | int totalCount; // total number of allocations 109 | int totalSize; // current allocated size 110 | }; 111 | 112 | void n_dbgmeminit(); // initialize memory debugging system 113 | nMemoryStats n_dbgmemgetstats(); // defined in ndbgalloc.cc 114 | 115 | #ifdef new 116 | #undef new 117 | #endif 118 | 119 | #ifdef delete 120 | #undef delete 121 | #endif 122 | 123 | // implemented in ndbgalloc.cc 124 | void* operator new(size_t size); 125 | void* operator new(size_t size, const char* file, int line); 126 | void* operator new[](size_t size); 127 | void* operator new[](size_t size, const char* file, int line); 128 | void operator delete(void* p); 129 | void operator delete[](void* p); 130 | void* n_malloc_dbg(size_t size, const char* file, int line); 131 | void* n_calloc_dbg(size_t num, size_t size, const char* file, int line); 132 | void* n_realloc_dbg(void* memblock, size_t size, const char* file, int line); 133 | void n_free_dbg(void* memblock, const char* file, int line); 134 | 135 | #ifdef _DEBUG 136 | #define n_new(type) new(__FILE__,__LINE__) type 137 | #define n_new_array(type,size) new(__FILE__,__LINE__) type[size] 138 | #define n_delete(ptr) delete ptr 139 | #define n_delete_array(ptr) delete[] ptr 140 | #define n_malloc(size) n_malloc_dbg(size, __FILE__, __LINE__); 141 | #define n_calloc(num, size) n_calloc_dbg(num, size, __FILE__, __LINE__); 142 | #define n_realloc(memblock, size) n_realloc_dbg(memblock, size, __FILE__, __LINE__); 143 | #define n_free(memblock) n_free_dbg(memblock, __FILE__, __LINE__); 144 | #else 145 | #define n_new(type) new type 146 | #define n_new_array(type,size) new type[size] 147 | #define n_delete(ptr) delete ptr 148 | #define n_delete_array(ptr) delete[] ptr 149 | #define n_malloc(size) malloc(size) 150 | #define n_calloc(num, size) calloc(num, size) 151 | #define n_realloc(memblock, size) realloc(memblock, size) 152 | #define n_free(memblock) free(memblock) 153 | #endif 154 | 155 | // define an nAttribute C++ class extension, declares 156 | // a function member, setter and getter method for the attribute 157 | // #define __ref_attr(TYPE,NAME) private: TYPE NAME; public: void Set##NAME(const TYPE& t) {this->NAME = t; }; const TYPE& Get##NAME() const { return this->NAME; }; 158 | // #define __attr(TYPE,NAME) private: TYPE NAME; public: void Set##NAME(TYPE t) {this->NAME = t}; TYPE Get##NAME() const { return this->NAME; }; 159 | 160 | #define nSetter(METHOD, TYPE, MEMBER) inline void METHOD(TYPE t) { this->MEMBER = t; } 161 | #define nGetter(TYPE, METHOD, MEMBER) inline TYPE METHOD() const { return this->MEMBER; } 162 | 163 | //-------------------------------------------------------------------- 164 | #endif 165 | -------------------------------------------------------------------------------- /ext/mathlib/ntypes.h~: -------------------------------------------------------------------------------- 1 | #ifndef N_TYPES_H 2 | #define N_TYPES_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | Lowlevel Nebula defs. 6 | 7 | (C) 2002 RadonLabs GmbH 8 | */ 9 | #ifndef __XBxX__ 10 | #include 11 | #include 12 | #endif 13 | 14 | //#include "kernel/nsystem.h" 15 | //#include "kernel/ndebug.h" 16 | //#include "kernel/ndefclass.h" 17 | 18 | // Shortcut Typedefs 19 | typedef unsigned long ulong; 20 | //typedef unsigned int uint; 21 | ////typedef unsigned short ushort; 22 | //typedef unsigned char uchar; 23 | typedef float float2[2]; 24 | typedef float float3[3]; 25 | typedef float float4[4]; 26 | struct nFloat4 27 | { 28 | float x; 29 | float y; 30 | float z; 31 | float w; 32 | }; 33 | struct nFloat3 34 | { 35 | float x; 36 | float y; 37 | float z; 38 | }; 39 | struct nFloat2 40 | { 41 | float x; 42 | float y; 43 | }; 44 | typedef unsigned int nFourCC; 45 | typedef double nTime; 46 | 47 | #ifndef NULL 48 | #define NULL (0L) 49 | #endif 50 | 51 | //------------------------------------------------------------------------------ 52 | #define N_MAXPATH (512) // maximum length for complete path 53 | #define N_MAXNAMELEN (32) // maximum length for single path component 54 | 55 | //------------------------------------------------------------------------------ 56 | #define nID(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d)) 57 | #define MAKE_FOURCC(ch0,ch1,ch2,ch3) (ch0 | ch1<<8 | ch2<<16 | ch3<<24) 58 | #define FOURCC(i) (((i&0xff000000)>>24) | ((i&0x00ff0000)>>8) | ((i&0x0000ff00)<<8) | ((i&0x000000ff)<<24)) 59 | #define N_WHITESPACE " \r\n\t" 60 | 61 | #ifdef __LINUX__ 62 | #define n_stricmp strcasecmp 63 | #else 64 | #define n_stricmp stricmp 65 | #endif 66 | 67 | #ifdef __WIN32__ 68 | #define snprintf _snprintf 69 | #define vsnprintf _vsnprintf 70 | #endif 71 | 72 | // maps unsigned 8 bits/channel to D3DCOLOR 73 | #define N_ARGB(a,r,g,b) ((uint)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) 74 | #define N_RGBA(r,g,b,a) N_ARGB(a,r,g,b) 75 | #define N_XRGB(r,g,b) N_ARGB(0xff,r,g,b) 76 | #define N_COLORVALUE(r,g,b,a) N_RGBA((uint)((r)*255.f),(uint)((g)*255.f),(uint)((b)*255.f),(uint)((a)*255.f)) 77 | 78 | //------------------------------------------------------------------------------ 79 | // public kernel C functions 80 | //------------------------------------------------------------------------------ 81 | void __cdecl n_printf(const char *, ...); 82 | void __cdecl n_error(const char*, ...); 83 | void __cdecl n_message(const char*, ...); 84 | void n_sleep(double); 85 | char *n_strdup(const char *); 86 | char *n_strncpy2(char *, const char *, size_t); 87 | bool n_strmatch(const char *, const char *); 88 | void n_strcat(char *, const char *, size_t); 89 | 90 | void n_barf(const char *, const char *, int); 91 | void n_barf2(const char*, const char*, const char*, int); 92 | 93 | void *n_dllopen(const char *); 94 | void n_dllclose(void *); 95 | void *n_dllsymbol(void *, const char *); 96 | 97 | nFourCC n_strtofourcc(const char*); 98 | const char* n_fourcctostr(nFourCC); 99 | 100 | //------------------------------------------------------------------------------ 101 | // Nebula memory management and debugging stuff. 102 | //------------------------------------------------------------------------------ 103 | extern bool nMemoryLoggingEnabled; 104 | struct nMemoryStats 105 | { 106 | int highWaterSize; // max allocated size so far 107 | int totalCount; // total number of allocations 108 | int totalSize; // current allocated size 109 | }; 110 | 111 | void n_dbgmeminit(); // initialize memory debugging system 112 | nMemoryStats n_dbgmemgetstats(); // defined in ndbgalloc.cc 113 | 114 | #ifdef new 115 | #undef new 116 | #endif 117 | 118 | #ifdef delete 119 | #undef delete 120 | #endif 121 | 122 | // implemented in ndbgalloc.cc 123 | void* operator new(size_t size); 124 | void* operator new(size_t size, const char* file, int line); 125 | void* operator new[](size_t size); 126 | void* operator new[](size_t size, const char* file, int line); 127 | void operator delete(void* p); 128 | void operator delete[](void* p); 129 | void* n_malloc_dbg(size_t size, const char* file, int line); 130 | void* n_calloc_dbg(size_t num, size_t size, const char* file, int line); 131 | void* n_realloc_dbg(void* memblock, size_t size, const char* file, int line); 132 | void n_free_dbg(void* memblock, const char* file, int line); 133 | 134 | #ifdef _DEBUG 135 | #define n_new(type) new(__FILE__,__LINE__) type 136 | #define n_new_array(type,size) new(__FILE__,__LINE__) type[size] 137 | #define n_delete(ptr) delete ptr 138 | #define n_delete_array(ptr) delete[] ptr 139 | #define n_malloc(size) n_malloc_dbg(size, __FILE__, __LINE__); 140 | #define n_calloc(num, size) n_calloc_dbg(num, size, __FILE__, __LINE__); 141 | #define n_realloc(memblock, size) n_realloc_dbg(memblock, size, __FILE__, __LINE__); 142 | #define n_free(memblock) n_free_dbg(memblock, __FILE__, __LINE__); 143 | #else 144 | #define n_new(type) new type 145 | #define n_new_array(type,size) new type[size] 146 | #define n_delete(ptr) delete ptr 147 | #define n_delete_array(ptr) delete[] ptr 148 | #define n_malloc(size) malloc(size) 149 | #define n_calloc(num, size) calloc(num, size) 150 | #define n_realloc(memblock, size) realloc(memblock, size) 151 | #define n_free(memblock) free(memblock) 152 | #endif 153 | 154 | // define an nAttribute C++ class extension, declares 155 | // a function member, setter and getter method for the attribute 156 | // #define __ref_attr(TYPE,NAME) private: TYPE NAME; public: void Set##NAME(const TYPE& t) {this->NAME = t; }; const TYPE& Get##NAME() const { return this->NAME; }; 157 | // #define __attr(TYPE,NAME) private: TYPE NAME; public: void Set##NAME(TYPE t) {this->NAME = t}; TYPE Get##NAME() const { return this->NAME; }; 158 | 159 | #define nSetter(METHOD, TYPE, MEMBER) inline void METHOD(TYPE t) { this->MEMBER = t; } 160 | #define nGetter(TYPE, METHOD, MEMBER) inline TYPE METHOD() const { return this->MEMBER; } 161 | 162 | //-------------------------------------------------------------------- 163 | #endif 164 | -------------------------------------------------------------------------------- /ext/mathlib/pknorm.h: -------------------------------------------------------------------------------- 1 | #ifndef N_PKNORM_H 2 | #define N_PKNORM_H 3 | //------------------------------------------------------------------- 4 | /** 5 | @class pknorm3 6 | @ingroup Math 7 | 8 | A normal packed into 16 bits 9 | 10 | (C) 2004 RadonLabs GmbH 11 | */ 12 | #include "mathlib/vector.h" 13 | 14 | //------------------------------------------------------------------- 15 | class pknorm3 { 16 | ushort n; 17 | 18 | public: 19 | //--- pack each component into 5 bits --------------------------- 20 | void pack(vector3& v) { 21 | const float r = 31.999f; 22 | unsigned int ix = (unsigned int) (r * (v.x+1.0f)*0.5f); 23 | unsigned int iy = (unsigned int)(r * (v.y+1.0f)*0.5f); 24 | unsigned int iz = (unsigned int) (r * (v.z+1.0f)*0.5f); 25 | n = ((ix&31)<<10) | ((iy&31)<<5) | (iz&31); 26 | }; 27 | 28 | //--- unpack into vector3 --------------------------------------- 29 | vector3 unpack(void) { 30 | const float r = 31.999f; 31 | float ix = float((n>>10) & 31); 32 | float iy = float((n>>5) & 31); 33 | float iz = float(n & 31); 34 | vector3 v((((ix/r)*2.0f)-1.0f), 35 | (((iy/r)*2.0f)-1.0f), 36 | (((iz/r)*2.0f)-1.0f)); 37 | return v; 38 | }; 39 | 40 | //-- constructors ----------------------------------------------- 41 | pknorm3() : n(0) {}; 42 | pknorm3(vector3& v) { 43 | pack(v); 44 | }; 45 | 46 | //-- get/set packed representation ------------------------------ 47 | ushort getpacked(void) { 48 | return n; 49 | }; 50 | void setpacked(ushort _n) { 51 | n = _n; 52 | }; 53 | }; 54 | //------------------------------------------------------------------- 55 | #endif 56 | -------------------------------------------------------------------------------- /ext/mathlib/plane.h: -------------------------------------------------------------------------------- 1 | #ifndef N_PLANE_H 2 | #define N_PLANE_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class plane 6 | @ingroup Math 7 | 8 | A plane in 3d space. 9 | 10 | (C) 2004 RadonLabs GmbH 11 | */ 12 | #include "mathlib/vector.h" 13 | #include "mathlib/line.h" 14 | 15 | //------------------------------------------------------------------------------ 16 | class plane 17 | { 18 | public: 19 | /// default constructor 20 | plane(); 21 | /// constructor 1 22 | plane(float A, float B, float C, float D); 23 | /// constructor 2 24 | plane(const plane& p); 25 | /// constructor 3 26 | plane(const vector3& v0, const vector3& v1, const vector3& v2); 27 | /// set contents 28 | void set(float A, float B, float C, float D); 29 | /// construct plane from 3 vectors 30 | void set(const vector3& v0, const vector3& v1, const vector3& v2); 31 | /// compute distance of point to plane 32 | float distance(const vector3& v) const; 33 | /// get plane normal 34 | vector3 normal() const; 35 | /// get intersecting t of line with one sided plane 36 | bool intersect(const line3& l, float& t) const; 37 | /// get plane/plane intersection 38 | bool intersect(const plane& p, line3& l) const; 39 | 40 | float a , b, c, d; 41 | }; 42 | 43 | //------------------------------------------------------------------------------ 44 | /** 45 | */ 46 | inline 47 | plane::plane() : 48 | a(0.0f), 49 | b(0.0f), 50 | c(0.0f), 51 | d(1.0f) 52 | { 53 | // empty 54 | } 55 | 56 | //------------------------------------------------------------------------------ 57 | /** 58 | */ 59 | inline 60 | plane::plane(float A, float B, float C, float D) : 61 | a(A), 62 | b(B), 63 | c(C), 64 | d(D) 65 | { 66 | // empty 67 | } 68 | 69 | //------------------------------------------------------------------------------ 70 | /** 71 | */ 72 | inline 73 | plane::plane(const plane& rhs) : 74 | a(rhs.a), 75 | b(rhs.b), 76 | c(rhs.c), 77 | d(rhs.d) 78 | { 79 | // empty 80 | } 81 | 82 | //------------------------------------------------------------------------------ 83 | /** 84 | */ 85 | inline 86 | void 87 | plane::set(float A, float B, float C, float D) 88 | { 89 | this->a = A; 90 | this->b = B; 91 | this->c = C; 92 | this->d = D; 93 | } 94 | 95 | //------------------------------------------------------------------------------ 96 | /** 97 | Constructs a plane from 3 position vectors. 98 | */ 99 | inline 100 | void 101 | plane::set(const vector3& v0, const vector3& v1, const vector3& v2) 102 | { 103 | vector3 cross((v2 - v0) * (v1 - v0)); 104 | cross.norm(); 105 | this->a = cross.x; 106 | this->b = cross.y; 107 | this->c = cross.z; 108 | this->d = -(a * v0.x + b * v0.y + c * v0.z); 109 | } 110 | 111 | //------------------------------------------------------------------------------ 112 | /** 113 | */ 114 | inline 115 | plane::plane(const vector3& v0, const vector3& v1, const vector3& v2) 116 | { 117 | this->set(v0, v1, v2); 118 | } 119 | 120 | //------------------------------------------------------------------------------ 121 | /** 122 | Computes the distance of a point to the plane. Return 0.0 if the 123 | point is on the plane. 124 | */ 125 | inline 126 | float 127 | plane::distance(const vector3& v) const 128 | { 129 | return this->a * v.x + this->b * v.y + this->c * v.z + this->d; 130 | } 131 | 132 | //------------------------------------------------------------------------------ 133 | /** 134 | Returns the plane normal. 135 | */ 136 | inline 137 | vector3 138 | plane::normal() const 139 | { 140 | return vector3(this->a, this->b, this->c); 141 | } 142 | 143 | //------------------------------------------------------------------------------ 144 | /** 145 | Get intersecting t of line with one-sided plane. Returns false 146 | if the line is parallel to the plane. 147 | */ 148 | inline 149 | bool 150 | plane::intersect(const line3& l, float& t) const 151 | { 152 | float f0 = this->a * l.b.x + this->b * l.b.y + this->c * l.b.z + this->d; 153 | float f1 = this->a * -l.m.x + this->b * -l.m.y + this->c * -l.m.z; 154 | if ((f1 < -0.0001f) || (f1 > 0.0001f)) 155 | { 156 | t = f0 / f1; 157 | return true; 158 | } 159 | else 160 | { 161 | return false; 162 | } 163 | } 164 | 165 | //------------------------------------------------------------------------------ 166 | /** 167 | Get plane/plane intersection. Return false if planes are parallel. 168 | */ 169 | inline 170 | bool 171 | plane::intersect(const plane& p, line3& l) const 172 | { 173 | vector3 n0 = this->normal(); 174 | vector3 n1 = p.normal(); 175 | float n00 = n0 % n0; 176 | float n01 = n0 % n1; 177 | float n11 = n1 % n1; 178 | float det = n00 * n11 - n01 * n01; 179 | const float tol = 1e-06f; 180 | if (fabs(det) < tol) 181 | { 182 | return false; 183 | } 184 | else 185 | { 186 | float inv_det = 1.0f/det; 187 | float c0 = (n11 * this->d - n01 * p.d) * inv_det; 188 | float c1 = (n00 * p.d - n01 * this->d)* inv_det; 189 | l.m = n0 * n1; 190 | l.b = n0 * c0 + n1 * c1; 191 | return true; 192 | } 193 | } 194 | 195 | //------------------------------------------------------------------------------ 196 | #endif 197 | -------------------------------------------------------------------------------- /ext/mathlib/polar.h: -------------------------------------------------------------------------------- 1 | #ifndef N_POLAR_H 2 | #define N_POLAR_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class polar2 6 | @ingroup Math 7 | 8 | A polar coordinate inline class, consisting of 2 angles theta (latitude) 9 | and rho (longitude). Also offers conversion between cartesian and 10 | polar space. 11 | 12 | Allowed range for theta is 0..180 degree (in rad!) and for rho 0..360 degree 13 | (in rad). 14 | 15 | (C) 2004 RadonLabs GmbH 16 | */ 17 | #include 18 | #include 19 | #include 20 | 21 | #include "mathlib/vector.h" 22 | 23 | //------------------------------------------------------------------------------ 24 | class polar2 25 | { 26 | public: 27 | /// the default constructor 28 | polar2(); 29 | /// constructor, theta and rho args 30 | polar2(float t, float r); 31 | /// constructor, normalized cartesian vector as arg 32 | polar2(const vector3& v); 33 | /// the copy constructor 34 | polar2(const polar2& src); 35 | /// the assignment operator 36 | polar2& operator=(const polar2& rhs); 37 | /// convert to normalized cartesian coords 38 | vector3 get_cartesian() const; 39 | /// get theta and rho in a 2d vec 40 | vector2 get() const; 41 | /// set to polar object 42 | void set(const polar2& p); 43 | /// set to theta and rho 44 | void set(const float t, const float r); 45 | /// set to cartesian 46 | void set(const vector3&); 47 | /// fuzzy equality check 48 | bool isequal(const polar2& rhs, float tol); 49 | 50 | float theta; 51 | float rho; 52 | 53 | private: 54 | /// the equal operator is not allowed, use isequal() with tolerance! 55 | bool operator==(const polar2& /*rhs*/) { return false; } 56 | }; 57 | 58 | //------------------------------------------------------------------------------ 59 | /** 60 | */ 61 | inline 62 | polar2::polar2() : 63 | theta(0.0f), 64 | rho(0.0f) 65 | { 66 | // empty 67 | } 68 | 69 | //------------------------------------------------------------------------------ 70 | /** 71 | */ 72 | inline 73 | polar2::polar2(float t, float r) : 74 | theta(t), 75 | rho(r) 76 | { 77 | // empty 78 | } 79 | 80 | //------------------------------------------------------------------------------ 81 | /** 82 | */ 83 | inline 84 | polar2::polar2(const vector3& v) 85 | { 86 | this->set(v); 87 | } 88 | 89 | //------------------------------------------------------------------------------ 90 | /** 91 | */ 92 | inline 93 | polar2::polar2(const polar2& src) : 94 | theta(src.theta), 95 | rho(src.rho) 96 | { 97 | // empty 98 | } 99 | 100 | //------------------------------------------------------------------------------ 101 | /** 102 | */ 103 | inline 104 | polar2& 105 | polar2::operator=(const polar2& rhs) 106 | { 107 | this->theta = rhs.theta; 108 | this->rho = rhs.rho; 109 | return *this; 110 | } 111 | 112 | //------------------------------------------------------------------------------ 113 | /** 114 | */ 115 | inline 116 | void 117 | polar2::set(const polar2& p) 118 | { 119 | this->theta = p.theta; 120 | this->rho = p.rho; 121 | } 122 | 123 | //------------------------------------------------------------------------------ 124 | /** 125 | */ 126 | inline 127 | void 128 | polar2::set(const float t, const float r) 129 | { 130 | this->theta = t; 131 | this->rho = r; 132 | } 133 | 134 | //------------------------------------------------------------------------------ 135 | /** 136 | Convert cartesian to polar. 137 | */ 138 | inline 139 | void 140 | polar2::set(const vector3& vec) 141 | { 142 | double dTheta = acos(vec.y); 143 | 144 | // build a normalized 2d vector of the xz component 145 | vector2 v2(vec.x, vec.z); 146 | v2.norm(); 147 | 148 | // adjust dRho based on the quadrant we are in 149 | double dRho; 150 | if ((v2.x >= 0.0f) && (v2.y >= 0.0f)) 151 | { 152 | // quadrant 1 153 | dRho = asin(v2.x); 154 | } 155 | else if ((v2.x < 0.0f) && (v2.y >= 0.0f)) 156 | { 157 | // quadrant 2 158 | dRho = asin(v2.y) + n_deg2rad(270.0f); 159 | } 160 | else if ((v2.x < 0.0f) && (v2.y < 0.0f)) 161 | { 162 | // quadrant 3 163 | dRho = asin(-v2.x) + n_deg2rad(180.0f); 164 | } 165 | else 166 | { 167 | // quadrant 4 168 | dRho = asin(-v2.y) + n_deg2rad(90.0f); 169 | } 170 | 171 | this->theta = (float) dTheta; 172 | this->rho = (float) dRho; 173 | } 174 | 175 | //------------------------------------------------------------------------------ 176 | /** 177 | Convert polar to cartesian. 178 | */ 179 | inline 180 | vector3 181 | polar2::get_cartesian() const 182 | { 183 | vector3 v; 184 | double sin_theta = sin(this->theta); 185 | double cos_theta = cos(this->theta); 186 | double sin_rho = sin(this->rho); 187 | double cos_rho = cos(this->rho); 188 | float x = (float) (sin_theta * sin_rho); 189 | float y = (float) cos_theta; 190 | float z = (float) (sin_theta * cos_rho); 191 | v.set(x,y,z); 192 | return v; 193 | } 194 | 195 | //------------------------------------------------------------------------------ 196 | /** 197 | */ 198 | inline 199 | bool 200 | polar2::isequal(const polar2& rhs, float tol) 201 | { 202 | float dt = n_abs(rhs.theta - this->theta); 203 | float dr = n_abs(rhs.rho - this->rho); 204 | if (dt > tol) return false; 205 | else if (dr > tol) return false; 206 | return true; 207 | } 208 | 209 | //------------------------------------------------------------------------------ 210 | #endif 211 | -------------------------------------------------------------------------------- /ext/mathlib/quaternion.h: -------------------------------------------------------------------------------- 1 | #ifndef N_QUATERNION_H 2 | #define N_QUATERNION_H 3 | //------------------------------------------------------------------- 4 | /** 5 | @class quaternion 6 | @ingroup Math 7 | 8 | quaternion class with some basic operators. 9 | 10 | - 08-Dec-00 floh extended, ATTENTION: argument ordering in 11 | constructor has changed! 12 | 13 | (C) 2004 RadonLabs GmbH 14 | */ 15 | #include 16 | #include 17 | #include 18 | #include "mathlib/vector.h" 19 | 20 | //------------------------------------------------------------------- 21 | // quaternion 22 | //------------------------------------------------------------------- 23 | class quaternion { 24 | public: 25 | float x,y,z,w; 26 | 27 | //-- constructors ----------------------------------------------- 28 | quaternion() 29 | : x(0.0f), y(0.0f), z(0.0f), w(1.0f) 30 | {}; 31 | quaternion(float _x, float _y, float _z, float _w) 32 | : x(_x), y(_y), z(_z), w(_w) 33 | {}; 34 | quaternion(const quaternion& q) 35 | : x(q.x), y(q.y), z(q.z), w(q.w) 36 | {}; 37 | 38 | //-- setting elements ------------------------------------------- 39 | void set(float _x, float _y, float _z, float _w) { 40 | x = _x; 41 | y = _y; 42 | z = _z; 43 | w = _w; 44 | }; 45 | void set(const quaternion& q) { 46 | x = q.x; 47 | y = q.y; 48 | z = q.z; 49 | w = q.w; 50 | }; 51 | 52 | //-- misc operations -------------------------------------------- 53 | void ident(void) { 54 | x = 0.0f; 55 | y = 0.0f; 56 | z = 0.0f; 57 | w = 1.0f; 58 | }; 59 | 60 | void conjugate(void) { 61 | x = -x; 62 | y = -y; 63 | z = -z; 64 | }; 65 | 66 | void scale(float s) { 67 | x *= s; 68 | y *= s; 69 | z *= s; 70 | w *= s; 71 | }; 72 | 73 | float norm(void) { 74 | return x*x + y*y + z*z + w*w; 75 | }; 76 | 77 | float magnitude(void) { 78 | float n = norm(); 79 | if (n > 0.0f) return n_sqrt(n); 80 | else return 0.0f; 81 | }; 82 | 83 | void invert(void) { 84 | float n = norm(); 85 | if (n > 0.0f) scale(1.0f / norm()); 86 | conjugate(); 87 | }; 88 | 89 | void normalize(void) { 90 | float l = magnitude(); 91 | if (l > 0.0f) scale(1.0f / l); 92 | else set(0.0f,0.0f,0.0f,1.0f); 93 | }; 94 | 95 | //-- operators -------------------------------------------------- 96 | bool operator==(const quaternion& q) { 97 | return ((x==q.x) && (y==q.y) && (z==q.z) && (w==q.w)) ? true : false; 98 | }; 99 | 100 | bool operator!=(const quaternion& q) { 101 | return ((x!=q.x) || (y!=q.y) || (z!=q.z) || (w!=q.w)) ? true : false; 102 | }; 103 | 104 | const quaternion& operator+=(const quaternion& q) { 105 | x += q.x; 106 | y += q.y; 107 | z += q.z; 108 | w += q.w; 109 | return *this; 110 | }; 111 | 112 | const quaternion& operator-=(const quaternion& q) { 113 | x -= q.x; 114 | y -= q.y; 115 | z -= q.z; 116 | w -= q.w; 117 | return *this; 118 | }; 119 | 120 | const quaternion& operator*=(const quaternion& q) { 121 | float qx = w*q.x + x*q.w + y*q.z - z*q.y; 122 | float qy = w*q.y + y*q.w + z*q.x - x*q.z; 123 | float qz = w*q.z + z*q.w + x*q.y - y*q.x; 124 | float qw = w*q.w - x*q.x - y*q.y - z*q.z; 125 | x = qx; 126 | y = qy; 127 | z = qz; 128 | w = qw; 129 | return *this; 130 | }; 131 | 132 | /// rotate vector by quaternion 133 | vector3 rotate(const vector3& v) { 134 | quaternion q(v.x * w + v.z * y - v.y * z, 135 | v.y * w + v.x * z - v.z * x, 136 | v.z * w + v.y * x - v.x * y, 137 | v.x * x + v.y * y + v.z * z); 138 | 139 | return vector3(w * q.x + x * q.w + y * q.z - z * q.y, 140 | w * q.y + y * q.w + z * q.x - x * q.z, 141 | w * q.z + z * q.w + x * q.y - y * q.x); 142 | }; 143 | 144 | /** 145 | Create a rotation from one vector to an other. Works only with unit vectors. 146 | 147 | See http://www.martinb.com/maths/algebra/vectors/angleBetween/index.htm for 148 | more information. 149 | 150 | @param from source unit vector 151 | @param to destination unit vector 152 | */ 153 | void set_from_axes( const vector3& from, const vector3& to ) 154 | { 155 | vector3 c(from * to); 156 | set(c.x, c.y, c.z, from % to); 157 | w += 1.0f; // reducing angle to halfangle 158 | if( w <= TINY ) // angle close to PI 159 | { 160 | if ((from.z * from.z) > (from.x * from.x)) 161 | set(0, from.z, -from.y, w); 162 | //from*vector3(1,0,0) 163 | else 164 | set(from.y, -from.x, 0, w); 165 | //from*vector3(0,0,1) 166 | } 167 | normalize(); 168 | } 169 | 170 | /** 171 | Create a rotation from one vector to an other. Works with non unit vectors. 172 | 173 | See http://www.martinb.com/maths/algebra/vectors/angleBetween/index.htm for 174 | more information. 175 | 176 | @param from source vector 177 | @param to destination vector 178 | */ 179 | void set_from_axes2( const vector3& from, const vector3& to ) 180 | { 181 | vector3 c(from * to); 182 | set(c.x, c.y, c.z, from % to); 183 | normalize(); // if "from" or "to" not unit, normalize quat 184 | w += 1.0f; // reducing angle to halfangle 185 | if( w <= TINY ) // angle close to PI 186 | { 187 | if ((from.z * from.z) > (from.x * from.x)) 188 | set(0, from.z, -from.y, w); 189 | //from*vector3(1,0,0) 190 | else 191 | set(from.y, -from.x, 0, w); 192 | //from*vector3(0,0,1) 193 | } 194 | normalize(); 195 | } 196 | 197 | //-- convert from euler angles ---------------------------------- 198 | void set_rotate_axis_angle(const vector3& v, float a) { 199 | float sin_a = n_sin(a * 0.5f); 200 | float cos_a = n_cos(a * 0.5f); 201 | x = v.x * sin_a; 202 | y = v.y * sin_a; 203 | z = v.z * sin_a; 204 | w = cos_a; 205 | }; 206 | 207 | void set_rotate_x(float a) { 208 | float sin_a = n_sin(a * 0.5f); 209 | float cos_a = n_cos(a * 0.5f); 210 | x = sin_a; 211 | y = 0.0f; 212 | z = 0.0f; 213 | w = cos_a; 214 | }; 215 | 216 | void set_rotate_y(float a) { 217 | float sin_a = n_sin(a * 0.5f); 218 | float cos_a = n_cos(a * 0.5f); 219 | x = 0.0f; 220 | y = sin_a; 221 | z = 0.0f; 222 | w = cos_a; 223 | }; 224 | 225 | void set_rotate_z(float a) { 226 | float sin_a = n_sin(a * 0.5f); 227 | float cos_a = n_cos(a * 0.5f); 228 | x = 0.0f; 229 | y = 0.0f; 230 | z = sin_a; 231 | w = cos_a; 232 | }; 233 | 234 | void set_rotate_xyz(float ax, float ay, float az) { 235 | quaternion qx, qy, qz; 236 | qx.set_rotate_x(ax); 237 | qy.set_rotate_y(ay); 238 | qz.set_rotate_z(az); 239 | *this = qx; 240 | *this *= qy; 241 | *this *= qz; 242 | }; 243 | 244 | //--- fuzzy compare operators ----------------------------------- 245 | bool isequal(const quaternion& v, float tol) const 246 | { 247 | if (fabs(v.x-x) > tol) return false; 248 | else if (fabs(v.y-y) > tol) return false; 249 | else if (fabs(v.z-z) > tol) return false; 250 | else if (fabs(v.w-w) > tol) return false; 251 | return true; 252 | }; 253 | 254 | //-- rotation interpolation, set this matrix to the ------------- 255 | //-- interpolated result of q0->q1 with l as interpolator ------- 256 | void slerp(const quaternion& q0, const quaternion& q1, float l) 257 | { 258 | float fScale1; 259 | float fScale2; 260 | quaternion A = q0; 261 | quaternion B = q1; 262 | 263 | // compute dot product, aka cos(theta): 264 | float fCosTheta = A.x*B.x + A.y*B.y + A.z*B.z + A.w*B.w; 265 | 266 | if (fCosTheta < 0.0f) 267 | { 268 | // flip start quaternion 269 | A.x = -A.x; A.y = -A.y; A.z = -A.z; A.w = -A.w; 270 | fCosTheta = -fCosTheta; 271 | } 272 | 273 | if ((fCosTheta + 1.0f) > 0.05f) 274 | { 275 | // If the quaternions are close, use linear interploation 276 | if ((1.0f - fCosTheta) < 0.05f) 277 | { 278 | fScale1 = 1.0f - l; 279 | fScale2 = l; 280 | } 281 | else 282 | { 283 | // Otherwise, do spherical interpolation 284 | float fTheta = n_acos(fCosTheta); 285 | float fSinTheta = n_sin(fTheta); 286 | fScale1 = n_sin( fTheta * (1.0f-l) ) / fSinTheta; 287 | fScale2 = n_sin( fTheta * l ) / fSinTheta; 288 | } 289 | } 290 | else 291 | { 292 | B.x = -A.y; 293 | B.y = A.x; 294 | B.z = -A.w; 295 | B.w = A.z; 296 | fScale1 = n_sin( PI * (0.5f - l) ); 297 | fScale2 = n_sin( PI * l ); 298 | } 299 | 300 | x = fScale1 * A.x + fScale2 * B.x; 301 | y = fScale1 * A.y + fScale2 * B.y; 302 | z = fScale1 * A.z + fScale2 * B.z; 303 | w = fScale1 * A.w + fScale2 * B.w; 304 | }; 305 | }; 306 | 307 | //--- global operators ---------------------------------------------- 308 | static inline quaternion operator+(const quaternion& q0, const quaternion& q1) { 309 | return quaternion(q0.x+q1.x, q0.y+q1.y, q0.z+q1.z, q0.w+q1.w); 310 | }; 311 | 312 | static inline quaternion operator-(const quaternion& q0, const quaternion& q1) { 313 | return quaternion(q0.x-q1.x, q0.y-q1.y, q0.z-q1.z, q0.w-q1.w); 314 | }; 315 | 316 | static inline quaternion operator*(const quaternion& q0, const quaternion& q1) { 317 | return quaternion(q0.w*q1.x + q0.x*q1.w + q0.y*q1.z - q0.z*q1.y, 318 | q0.w*q1.y + q0.y*q1.w + q0.z*q1.x - q0.x*q1.z, 319 | q0.w*q1.z + q0.z*q1.w + q0.x*q1.y - q0.y*q1.x, 320 | q0.w*q1.w - q0.x*q1.x - q0.y*q1.y - q0.z*q1.z); 321 | }; 322 | //------------------------------------------------------------------- 323 | #endif 324 | -------------------------------------------------------------------------------- /ext/mathlib/rectangle.h: -------------------------------------------------------------------------------- 1 | #ifndef N_RECTANGLE_H 2 | #define N_RECTANGLE_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class rectangle 6 | @ingroup Math 7 | 8 | A 2d rectangle class. 9 | 10 | (C) 2003 RadonLabs GmbH 11 | */ 12 | #include "mathlib/vector.h" 13 | 14 | //------------------------------------------------------------------------------ 15 | class rectangle 16 | { 17 | public: 18 | /// default constructor 19 | rectangle(); 20 | /// constructor 1 21 | rectangle(const vector2& topLeft, const vector2& bottomRight); 22 | /// set content 23 | void set(const vector2& topLeft, const vector2& bottomRight); 24 | /// return true if point is inside 25 | bool inside(const vector2& p) const; 26 | /// return midpoint 27 | vector2 midpoint() const; 28 | /// return width 29 | float width() const; 30 | /// return height 31 | float height() const; 32 | /// return size 33 | vector2 size() const; 34 | 35 | vector2 v0; 36 | vector2 v1; 37 | }; 38 | 39 | //------------------------------------------------------------------------------ 40 | /** 41 | */ 42 | inline 43 | rectangle::rectangle() 44 | { 45 | // empty 46 | } 47 | 48 | //------------------------------------------------------------------------------ 49 | /** 50 | */ 51 | inline 52 | rectangle::rectangle(const vector2& topLeft, const vector2& bottomRight) : 53 | v0(topLeft), 54 | v1(bottomRight) 55 | { 56 | // empty 57 | } 58 | 59 | //------------------------------------------------------------------------------ 60 | /** 61 | */ 62 | inline 63 | void 64 | rectangle::set(const vector2& topLeft, const vector2& bottomRight) 65 | { 66 | this->v0 = topLeft; 67 | this->v1 = bottomRight; 68 | } 69 | 70 | //------------------------------------------------------------------------------ 71 | /** 72 | */ 73 | inline 74 | bool 75 | rectangle::inside(const vector2& p) const 76 | { 77 | return ((this->v0.x <= p.x) && (p.x <= this->v1.x) && 78 | (this->v0.y <= p.y) && (p.y <= this->v1.y)); 79 | } 80 | 81 | //------------------------------------------------------------------------------ 82 | /** 83 | */ 84 | inline 85 | vector2 86 | rectangle::midpoint() const 87 | { 88 | return (this->v0 + this->v1) * 0.5f; 89 | } 90 | 91 | //------------------------------------------------------------------------------ 92 | /** 93 | */ 94 | inline 95 | float 96 | rectangle::width() const 97 | { 98 | return this->v1.x - this->v0.x; 99 | } 100 | 101 | //------------------------------------------------------------------------------ 102 | /** 103 | */ 104 | inline 105 | float 106 | rectangle::height() const 107 | { 108 | return this->v1.y - this->v0.y; 109 | } 110 | 111 | //------------------------------------------------------------------------------ 112 | /** 113 | */ 114 | inline 115 | vector2 116 | rectangle::size() const 117 | { 118 | return this->v1 - this->v0; 119 | } 120 | 121 | //------------------------------------------------------------------------------ 122 | #endif 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /ext/mathlib/sphere.h: -------------------------------------------------------------------------------- 1 | #ifndef N_SPHERE_H 2 | #define N_SPHERE_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class sphere 6 | @ingroup Math 7 | 8 | A 3-dimensional sphere. 9 | 10 | (C) 2004 RadonLabs GmbH 11 | */ 12 | #include "mathlib/vector.h" 13 | #include "mathlib/bbox.h" 14 | #include "mathlib/matrix.h" 15 | #include "mathlib/rectangle.h" 16 | 17 | //------------------------------------------------------------------------------ 18 | class sphere 19 | { 20 | public: 21 | /// default constructor 22 | sphere(); 23 | /// pos/radius constructor 24 | sphere(const vector3& _p, float _r); 25 | /// x,y,z,r constructor 26 | sphere(float _x, float _y, float _z, float _r); 27 | /// copy constructor 28 | sphere(const sphere& rhs); 29 | /// set position and radius 30 | void set(const vector3& _p, float _r); 31 | /// set x,y,z, radius 32 | void set(float _x, float _y, float _z, float _r); 33 | /// check if 2 spheres overlap 34 | bool intersects(const sphere& s) const; 35 | /// check if sphere intersects box 36 | bool intersects(const bbox3& box) const; 37 | /// check if 2 moving sphere have contact 38 | bool intersect_sweep(const vector3& va, const sphere& sb, const vector3& vb, float& u0, float& u1) const; 39 | /// project sphere to screen rectangle (right handed coordinate system) 40 | rectangle project_screen_rh(const matrix44& modelView, const matrix44& projection) const; 41 | 42 | vector3 p; // position 43 | float r; // radius 44 | }; 45 | 46 | //------------------------------------------------------------------------------ 47 | /** 48 | */ 49 | inline 50 | sphere::sphere() : 51 | r(1.0f) 52 | { 53 | // empty 54 | } 55 | 56 | //------------------------------------------------------------------------------ 57 | /** 58 | */ 59 | inline 60 | sphere::sphere(const vector3& _p, float _r) : 61 | p(_p), 62 | r(_r) 63 | { 64 | // empty 65 | } 66 | 67 | //------------------------------------------------------------------------------ 68 | /** 69 | */ 70 | inline 71 | sphere::sphere(float _x, float _y, float _z, float _r) : 72 | p(_x, _y, _z), 73 | r(_r) 74 | { 75 | // empty 76 | } 77 | 78 | //------------------------------------------------------------------------------ 79 | /** 80 | */ 81 | inline 82 | sphere::sphere(const sphere& rhs) : 83 | p(rhs.p), 84 | r(rhs.r) 85 | { 86 | // empty 87 | } 88 | 89 | //------------------------------------------------------------------------------ 90 | /** 91 | */ 92 | inline 93 | void 94 | sphere::set(const vector3& _p, float _r) 95 | { 96 | this->p = _p; 97 | this->r = _r; 98 | } 99 | 100 | //------------------------------------------------------------------------------ 101 | /** 102 | */ 103 | inline 104 | void 105 | sphere::set(float _x, float _y, float _z, float _r) 106 | { 107 | this->p.set(_x, _y, _z); 108 | this->r = _r; 109 | } 110 | 111 | //------------------------------------------------------------------------------ 112 | /** 113 | */ 114 | inline 115 | bool 116 | sphere::intersects(const sphere& s) const 117 | { 118 | vector3 d(s.p - p); 119 | float rsum = s.r + r; 120 | if (d.lensquared() <= (rsum * rsum)) return true; 121 | else return false; 122 | } 123 | 124 | //------------------------------------------------------------------------------ 125 | /** 126 | Check if sphere intersects with box. 127 | Taken from "Simple Intersection Tests For Games", 128 | Gamasutra, Oct 18 1999 129 | */ 130 | inline 131 | bool 132 | sphere::intersects(const bbox3& box) const 133 | { 134 | float s, d = 0; 135 | 136 | // find the square of the distance 137 | // from the sphere to the box, 138 | if (p.x < box.vmin.x) 139 | { 140 | s = p.x - box.vmin.x; 141 | d += s*s; 142 | } 143 | else if (p.x > box.vmax.x) 144 | { 145 | s = p.x - box.vmax.x; 146 | d += s*s; 147 | } 148 | 149 | if (p.y < box.vmin.y) 150 | { 151 | s = p.y - box.vmin.y; 152 | d += s*s; 153 | } 154 | else if (p.y > box.vmax.y) 155 | { 156 | s = p.y - box.vmax.y; 157 | d += s*s; 158 | } 159 | 160 | if (p.z < box.vmin.z) 161 | { 162 | s = p.z - box.vmin.z; 163 | d += s*s; 164 | } 165 | else if (p.z > box.vmax.z) 166 | { 167 | s = p.z - box.vmax.z; 168 | d += s*s; 169 | } 170 | 171 | return d <= r*r; 172 | } 173 | 174 | //------------------------------------------------------------------------------ 175 | /** 176 | Check if 2 moving spheres have contact. 177 | Taken from "Simple Intersection Tests For Games" 178 | article in Gamasutra, Oct 18 1999 179 | 180 | @param va [in] distance travelled by 'this' 181 | @param sb [in] the other sphere 182 | @param vb [in] distance travelled by sb 183 | @param u0 [out] normalized intro contact 184 | @param u1 [out] normalized outro contact 185 | */ 186 | inline 187 | bool 188 | sphere::intersect_sweep(const vector3& va, const sphere& sb, const vector3& vb, float& u0, float& u1) const 189 | { 190 | vector3 vab(vb - va); 191 | vector3 ab(sb.p - p); 192 | float rab = r + sb.r; 193 | 194 | // check if spheres are currently overlapping... 195 | if ((ab % ab) <= (rab * rab)) 196 | { 197 | u0 = 0.0f; 198 | u1 = 0.0f; 199 | return true; 200 | } 201 | else 202 | { 203 | // check if they hit each other 204 | float a = vab % vab; 205 | if ((a < -TINY) || (a > +TINY)) 206 | { 207 | // if a is '0' then the objects don't move relative to each other 208 | float b = (vab % ab) * 2.0f; 209 | float c = (ab % ab) - (rab * rab); 210 | float q = b*b - 4*a*c; 211 | if (q >= 0.0f) 212 | { 213 | // 1 or 2 contacts 214 | float sq = (float) sqrt(q); 215 | float d = 1.0f / (2.0f*a); 216 | float r1 = (-b + sq) * d; 217 | float r2 = (-b - sq) * d; 218 | if (r1 < r2) 219 | { 220 | u0 = r1; 221 | u1 = r2; 222 | } 223 | else 224 | { 225 | u0 = r2; 226 | u1 = r1; 227 | } 228 | return true; 229 | } 230 | else 231 | { 232 | return false; 233 | } 234 | } 235 | else 236 | { 237 | return false; 238 | } 239 | } 240 | } 241 | 242 | //------------------------------------------------------------------------------ 243 | /** 244 | Project the sphere (defined in global space) to a screen space rectangle, 245 | given the current View and Projection matrices. The method assumes that 246 | the sphere is at least partially visible. 247 | */ 248 | inline 249 | rectangle 250 | sphere::project_screen_rh(const matrix44& view, const matrix44& projection) const 251 | { 252 | // compute front center point of the sphere in view space 253 | vector3 viewPos = view * this->p; 254 | if (viewPos.z < 0.0f) 255 | { 256 | vector3 screenPos = projection.mult_divw(viewPos); 257 | screenPos.y = -screenPos.y; 258 | vector3 screenSize = projection.mult_divw(vector3(this->r, this->r, viewPos.z)); 259 | screenSize.y = -screenSize.y; 260 | float left = n_saturate(0.5f * (1.0f + (screenPos.x - screenSize.x))); 261 | float right = n_saturate(0.5f * (1.0f + (screenPos.x + screenSize.x))); 262 | float top = n_saturate(0.5f * (1.0f + (screenPos.y + screenSize.y))); 263 | float bottom = n_saturate(0.5f * (1.0f + (screenPos.y - screenSize.y))); 264 | 265 | return rectangle(vector2(left, top), vector2(right, bottom)); 266 | } 267 | else 268 | { 269 | // hmm, we're behind the view volume 270 | return rectangle(vector2(0.0f, 0.0f), vector2(1.0f, 1.0f)); 271 | } 272 | } 273 | 274 | 275 | //------------------------------------------------------------------------------ 276 | #endif 277 | -------------------------------------------------------------------------------- /ext/mathlib/transform33.h: -------------------------------------------------------------------------------- 1 | #ifndef N_TRANSFORM33_H 2 | #define N_TRANSFORM33_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class transform33 6 | @ingroup Math 7 | 8 | A 3x3 matrix which is described by 2D translation, rotation and scale. 9 | 10 | (C) 2004 RadonLabs GmbH 11 | */ 12 | #include "mathlib/matrix.h" 13 | #include "mathlib/vector.h" 14 | 15 | //------------------------------------------------------------------------------ 16 | class transform33 17 | { 18 | public: 19 | /// constructor 20 | transform33(); 21 | /// set translation 22 | void settranslation(const vector2& v); 23 | /// get translation 24 | const vector2& gettranslation() const; 25 | /// set euler rotation 26 | void seteulerrotation(const vector2& v); 27 | /// get euler rotation 28 | const vector2& geteulerrotation() const; 29 | /// return true if the transformation matrix is dirty 30 | bool isdirty() const; 31 | /// set scale 32 | void setscale(const vector2& v); 33 | /// get scale 34 | const vector2& getscale() const; 35 | /// get resulting 3x3 matrix 36 | const matrix33& getmatrix33(); 37 | /// get resulting 4x4 matrix, with 3x3 matrix cast to the upper-left corner 38 | void getmatrix44(matrix44& out); 39 | 40 | private: 41 | /// update internal matrix 42 | void update(); 43 | 44 | enum 45 | { 46 | Dirty = (1<<0), 47 | }; 48 | vector2 translation; 49 | vector2 euler; 50 | vector2 scale; 51 | matrix33 matrix; 52 | uchar flags; 53 | }; 54 | 55 | //------------------------------------------------------------------------------ 56 | /** 57 | */ 58 | inline 59 | transform33::transform33() : 60 | scale(1.0f, 1.0f), 61 | flags(0) 62 | { 63 | // empty 64 | } 65 | 66 | //------------------------------------------------------------------------------ 67 | /** 68 | */ 69 | inline 70 | void 71 | transform33::settranslation(const vector2& v) 72 | { 73 | this->translation = v; 74 | this->flags |= Dirty; 75 | } 76 | 77 | //------------------------------------------------------------------------------ 78 | /** 79 | */ 80 | inline 81 | const vector2& 82 | transform33::gettranslation() const 83 | { 84 | return this->translation; 85 | } 86 | 87 | //------------------------------------------------------------------------------ 88 | /** 89 | */ 90 | inline 91 | void 92 | transform33::seteulerrotation(const vector2& v) 93 | { 94 | this->euler = v; 95 | this->flags |= Dirty; 96 | } 97 | 98 | //------------------------------------------------------------------------------ 99 | /** 100 | */ 101 | inline 102 | const vector2& 103 | transform33::geteulerrotation() const 104 | { 105 | return this->euler; 106 | } 107 | 108 | //------------------------------------------------------------------------------ 109 | /** 110 | */ 111 | inline 112 | void 113 | transform33::setscale(const vector2& v) 114 | { 115 | this->scale = v; 116 | this->flags |= Dirty; 117 | } 118 | 119 | //------------------------------------------------------------------------------ 120 | /** 121 | */ 122 | inline 123 | const vector2& 124 | transform33::getscale() const 125 | { 126 | return this->scale; 127 | } 128 | 129 | //------------------------------------------------------------------------------ 130 | /** 131 | */ 132 | inline 133 | void 134 | transform33::update() 135 | { 136 | if (this->flags & Dirty) 137 | { 138 | this->matrix.ident(); 139 | this->matrix.scale(vector3(this->scale.x, this->scale.y, 1.0f)); 140 | this->matrix.rotate_x(this->euler.x); 141 | this->matrix.rotate_y(this->euler.y); 142 | this->matrix.translate(this->translation); 143 | this->flags &= ~Dirty; 144 | } 145 | } 146 | 147 | //------------------------------------------------------------------------------ 148 | /** 149 | */ 150 | inline 151 | const matrix33& 152 | transform33::getmatrix33() 153 | { 154 | this->update(); 155 | return this->matrix; 156 | } 157 | 158 | //------------------------------------------------------------------------------ 159 | /** 160 | */ 161 | inline 162 | void 163 | transform33::getmatrix44(matrix44& out) 164 | { 165 | this->update(); 166 | out.set(this->matrix.M11, this->matrix.M12, this->matrix.M13, 0.0f, 167 | this->matrix.M21, this->matrix.M22, this->matrix.M23, 0.0f, 168 | this->matrix.M31, this->matrix.M32, this->matrix.M33, 0.0f, 169 | 0.0f, 0.0f, 0.0f, 1.0f); 170 | } 171 | 172 | //------------------------------------------------------------------------------ 173 | /** 174 | */ 175 | inline 176 | bool 177 | transform33::isdirty() const 178 | { 179 | return (0 != (this->flags & Dirty)); 180 | } 181 | 182 | //------------------------------------------------------------------------------ 183 | #endif 184 | 185 | 186 | -------------------------------------------------------------------------------- /ext/mathlib/transform44.h: -------------------------------------------------------------------------------- 1 | #ifndef N_TRANSFORM44_H 2 | #define N_TRANSFORM44_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class transform44 6 | @ingroup Math 7 | 8 | A 4x4 matrix which is described by translation, rotation and scale. 9 | 10 | (C) 2004 RadonLabs GmbH 11 | */ 12 | #include "mathlib/matrix.h" 13 | #include "mathlib/vector.h" 14 | 15 | //------------------------------------------------------------------------------ 16 | class transform44 17 | { 18 | public: 19 | /// constructor 20 | transform44(); 21 | /// set translation 22 | void settranslation(const vector3& v); 23 | /// get translation 24 | const vector3& gettranslation() const; 25 | /// set euler rotation 26 | void seteulerrotation(const vector3& v); 27 | /// get euler rotation 28 | const vector3& geteulerrotation() const; 29 | /// set quaternion rotation 30 | void setquatrotation(const quaternion& q); 31 | /// get quaternion rotation 32 | const quaternion& getquatrotation() const; 33 | /// set scale 34 | void setscale(const vector3& v); 35 | /// get scale 36 | const vector3& getscale() const; 37 | /// set optional rotate pivot 38 | void setrotatepivot(const vector3& p, bool balance); 39 | /// get optional rotate pivot 40 | const vector3& getrotatepivot() const; 41 | /// set optional scale pivot 42 | void setscalepivot(const vector3& p); 43 | /// get optional scale pivot 44 | const vector3& getscalepivot() const; 45 | /// set matrix 4x4 46 | void setmatrix(matrix44 matrix); //not per reference - so make shure the data is copyed 47 | /// get resulting 4x4 matrix 48 | const matrix44& getmatrix(); 49 | /// return true if euler rotation is used (otherwise quaternion rotation is used) 50 | bool iseulerrotation() const; 51 | /// return true if the transformation matrix is dirty 52 | bool isdirty() const; 53 | /// return true if rotate pivot has been set 54 | bool hasrotatepivot() const; 55 | /// return true if scale pivot has been set 56 | bool hasscalepivot() const; 57 | 58 | private: 59 | enum 60 | { 61 | Dirty = (1<<0), 62 | UseEuler = (1<<1), 63 | HasRotatePivot = (1<<2), 64 | HasRotatePivotTranslation = (1<<3), 65 | HasScalePivot = (1<<4), 66 | }; 67 | vector3 translation; 68 | vector3 euler; 69 | quaternion quat; 70 | vector3 scale; 71 | vector3 rotatePivot; 72 | vector3 rotatePivotTranslation; 73 | vector3 scalePivot; 74 | matrix44 matrix; 75 | uchar flags; 76 | }; 77 | 78 | //------------------------------------------------------------------------------ 79 | /** 80 | */ 81 | inline 82 | transform44::transform44() : 83 | scale(1.0f, 1.0f, 1.0f), 84 | flags(0) 85 | { 86 | // empty 87 | } 88 | 89 | //------------------------------------------------------------------------------ 90 | /** 91 | */ 92 | inline 93 | void 94 | transform44::settranslation(const vector3& v) 95 | { 96 | this->translation = v; 97 | this->flags |= Dirty; 98 | } 99 | 100 | //------------------------------------------------------------------------------ 101 | /** 102 | */ 103 | inline 104 | const vector3& 105 | transform44::gettranslation() const 106 | { 107 | return this->translation; 108 | } 109 | 110 | //------------------------------------------------------------------------------ 111 | /** 112 | */ 113 | inline 114 | void 115 | transform44::seteulerrotation(const vector3& v) 116 | { 117 | this->euler = v; 118 | this->flags |= (Dirty | UseEuler); 119 | } 120 | 121 | //------------------------------------------------------------------------------ 122 | /** 123 | */ 124 | inline 125 | const vector3& 126 | transform44::geteulerrotation() const 127 | { 128 | return this->euler; 129 | } 130 | 131 | //------------------------------------------------------------------------------ 132 | /** 133 | */ 134 | inline 135 | void 136 | transform44::setquatrotation(const quaternion& q) 137 | { 138 | this->quat = q; 139 | this->flags |= Dirty; 140 | this->flags &= ~UseEuler; 141 | } 142 | 143 | //------------------------------------------------------------------------------ 144 | /** 145 | */ 146 | inline 147 | const quaternion& 148 | transform44::getquatrotation() const 149 | { 150 | return this->quat; 151 | } 152 | 153 | //------------------------------------------------------------------------------ 154 | /** 155 | */ 156 | inline 157 | void 158 | transform44::setscale(const vector3& v) 159 | { 160 | this->scale = v; 161 | this->flags |= Dirty; 162 | } 163 | 164 | //------------------------------------------------------------------------------ 165 | /** 166 | */ 167 | inline 168 | const vector3& 169 | transform44::getscale() const 170 | { 171 | return this->scale; 172 | } 173 | 174 | //------------------------------------------------------------------------------ 175 | /** 176 | Same as Maya MFnTransfrom: 177 | If balance if true, then the overall transformation matrix will not change 178 | and a compensating transformation will be added to the rotate translate 179 | pivot to compensate for the pivot modification. 180 | */ 181 | inline 182 | void 183 | transform44::setrotatepivot(const vector3& p, bool balance) 184 | { 185 | if (balance) 186 | { 187 | this->rotatePivotTranslation = p * -1.f; 188 | this->flags |= Dirty | HasRotatePivotTranslation; 189 | } 190 | this->rotatePivot = p; 191 | this->flags |= Dirty | HasRotatePivot; 192 | } 193 | 194 | //------------------------------------------------------------------------------ 195 | /** 196 | */ 197 | inline 198 | const vector3& 199 | transform44::getrotatepivot() const 200 | { 201 | return this->rotatePivot; 202 | } 203 | 204 | //------------------------------------------------------------------------------ 205 | /** 206 | */ 207 | inline 208 | void 209 | transform44::setscalepivot(const vector3& p) 210 | { 211 | this->scalePivot = p; 212 | this->flags |= Dirty | HasScalePivot; 213 | } 214 | 215 | //------------------------------------------------------------------------------ 216 | /** 217 | */ 218 | inline 219 | const vector3& 220 | transform44::getscalepivot() const 221 | { 222 | return this->scalePivot; 223 | } 224 | 225 | //------------------------------------------------------------------------------ 226 | /** 227 | */ 228 | inline 229 | const matrix44& 230 | transform44::getmatrix() 231 | { 232 | if (this->flags & Dirty) 233 | { 234 | if (this->flags & UseEuler) 235 | { 236 | this->matrix.ident(); 237 | if (this->flags & HasScalePivot) 238 | { 239 | this->matrix.translate(-this->scalePivot); 240 | } 241 | this->matrix.scale(this->scale); 242 | if (this->flags & HasScalePivot) 243 | { 244 | this->matrix.translate(this->scalePivot); 245 | } 246 | if (this->flags & HasRotatePivot) 247 | { 248 | this->matrix.translate(-this->rotatePivot); 249 | } 250 | this->matrix.rotate_x(this->euler.x); 251 | this->matrix.rotate_y(this->euler.y); 252 | this->matrix.rotate_z(this->euler.z); 253 | if (this->flags & HasRotatePivot) 254 | { 255 | this->matrix.translate(this->rotatePivot); 256 | } 257 | if (this->flags & HasRotatePivotTranslation) 258 | { 259 | this->matrix.translate(this->rotatePivotTranslation); 260 | } 261 | this->matrix.translate(this->translation); 262 | } 263 | else 264 | { 265 | this->matrix.ident(); 266 | if (this->flags & HasScalePivot) 267 | { 268 | this->matrix.translate(-this->scalePivot); 269 | } 270 | this->matrix.scale(this->scale); 271 | if (this->flags & HasScalePivot) 272 | { 273 | this->matrix.translate(this->scalePivot); 274 | } 275 | if (this->flags & HasRotatePivot) 276 | { 277 | this->matrix.translate(-this->rotatePivot); 278 | } 279 | this->matrix.mult_simple(matrix44(this->quat)); 280 | if (this->flags & HasRotatePivot) 281 | { 282 | this->matrix.translate(this->rotatePivot); 283 | } 284 | if (this->flags & HasRotatePivotTranslation) 285 | { 286 | this->matrix.translate(this->rotatePivotTranslation); 287 | } 288 | this->matrix.translate(this->translation); 289 | } 290 | this->flags &= ~Dirty; 291 | } 292 | return this->matrix; 293 | } 294 | 295 | //------------------------------------------------------------------------------ 296 | /** 297 | */ 298 | inline 299 | bool 300 | transform44::iseulerrotation() const 301 | { 302 | return (0 != (this->flags & UseEuler)); 303 | } 304 | 305 | //------------------------------------------------------------------------------ 306 | /** 307 | */ 308 | inline 309 | bool 310 | transform44::isdirty() const 311 | { 312 | return (0 != (this->flags & Dirty)); 313 | } 314 | 315 | //------------------------------------------------------------------------------ 316 | /** 317 | */ 318 | inline 319 | bool 320 | transform44::hasrotatepivot() const 321 | { 322 | return (0 != (this->flags & HasRotatePivot)); 323 | } 324 | 325 | //------------------------------------------------------------------------------ 326 | /** 327 | */ 328 | inline 329 | bool 330 | transform44::hasscalepivot() const 331 | { 332 | return (0 != (this->flags & HasScalePivot)); 333 | } 334 | 335 | //------------------------------------------------------------------------------ 336 | /** 337 | */ 338 | inline 339 | void 340 | transform44::setmatrix(matrix44 m) 341 | { 342 | this->matrix = m; 343 | this->flags &= ~Dirty; 344 | } 345 | //------------------------------------------------------------------------------ 346 | #endif 347 | 348 | 349 | -------------------------------------------------------------------------------- /ext/mathlib/triangle.h: -------------------------------------------------------------------------------- 1 | #ifndef N_TRIANGLE_H 2 | #define N_TRIANGLE_H 3 | //------------------------------------------------------------------- 4 | /** 5 | @class triangle 6 | @ingroup Math 7 | 8 | A 3D-triangle. 9 | 10 | (C) 2004 RadonLabs GmbH 11 | */ 12 | #include "mathlib/vector.h" 13 | #include "mathlib/line.h" 14 | #include "mathlib/plane.h" 15 | #include 16 | #include 17 | 18 | //------------------------------------------------------------------- 19 | // Triangle points are tri(s,t)=b + s*e0 + t*e1 where 20 | // 0<=s<=1, 0<=t<=1 and 0<=s+t<=1 21 | //------------------------------------------------------------------- 22 | class triangle { 23 | public: 24 | vector3 b,e0,e1; 25 | 26 | triangle() {}; 27 | triangle(const vector3& v0, const vector3& v1, const vector3& v2) 28 | : b(v0), e0(v1-v0), e1(v2-v0) {}; 29 | triangle(const triangle& t) 30 | : b(t.b), e0(t.e0), e1(t.e1) {}; 31 | 32 | void set(const vector3& v0, const vector3& v1, const vector3& v2) { 33 | b = v0; 34 | e0 = v1-v0; 35 | e1 = v2-v0; 36 | }; 37 | 38 | //--- get the face normal of the triangle --------------------------------- 39 | vector3 normal(void) const { 40 | vector3 cross(e0*e1); 41 | cross.norm(); 42 | return cross; 43 | }; 44 | 45 | //--- get the midpoint (center of gravity) of the triangle ---------------- 46 | vector3 midpoint(void) const { 47 | const float oneThird = 1.0f / 3.0f; 48 | return b + ((e0+e1) * oneThird); 49 | }; 50 | 51 | //--- get the plane of the triangle --------------------------------------- 52 | plane getplane(void) const { 53 | return plane(b,b+e0,b+e1); 54 | }; 55 | 56 | //--- get one the edge points --------------------------------------------- 57 | vector3 point(int i) const 58 | { 59 | switch (i) 60 | { 61 | case 0: return b; 62 | case 1: return b + e0; 63 | case 2: return b + e1; 64 | default: return vector3(0.0f, 0.0f, 0.0f); 65 | } 66 | }; 67 | 68 | //--- check if and where line intersects triangle ------------------------- 69 | // Taken from Magic Software (http://www.cs.unc.edu/~eberly) 70 | // Return false if line is parallel to triangle or hits its backside. 71 | // 72 | bool intersect(const line3& line, float& ipos) { 73 | 74 | // Compute plane of triangle, Dot(normal,X-tri.b) = 0 where 'normal' is 75 | // the plane normal. If the angle between the line direction and normal 76 | // is small, then the line is effectively parallel to the triangle. 77 | const float fTolerance = 1e-04f; 78 | vector3 norm(e0*e1); 79 | float fDenominator = norm % line.m; 80 | //float fLLenSqr = line.m % line.m; 81 | //float fNLenSqr = norm % norm; 82 | 83 | // check if intersecting backface or parallel... 84 | if (fDenominator >= -fTolerance) return false; 85 | 86 | //if ((fDenominator*fDenominator) <= (fTolerance*fLLenSqr*fNLenSqr)) { 87 | // // line and triangle are parallel 88 | // return false; 89 | //} 90 | 91 | // The line is X(t) = line.b + t*line.m. Compute line parameter t for 92 | // intersection of line and plane of triangle. Substitute in the plane 93 | // equation to get Dot(normal,line.b-tri.b) + t*Dot(normal,line.m) 94 | vector3 kDiff0(line.b - b); 95 | float fTime = -(norm % kDiff0) / fDenominator; 96 | if ((fTime<-fTolerance) || (fTime>(1.0f+fTolerance))) return false; 97 | 98 | // Find difference of intersection point of line with plane and vertex 99 | // of triangle. 100 | vector3 kDiff1(kDiff0 + line.m*fTime); 101 | 102 | // Compute if intersection point is inside triangle. Write 103 | // kDiff1 = s0*E0 + s1*E1 and solve for s0 and s1. 104 | float fE00 = e0 % e0; 105 | float fE01 = e0 % e1; 106 | float fE11 = e1 % e1; 107 | float fDet = (float) fabs(fE00*fE11-fE01*fE01); // = |normal|^2 > 0 108 | float fR0 = e0 % kDiff1; 109 | float fR1 = e1 % kDiff1; 110 | 111 | float fS0 = fE11*fR0 - fE01*fR1; 112 | float fS1 = fE00*fR1 - fE01*fR0; 113 | 114 | if ((fS0>=-fTolerance) && (fS1>=-fTolerance) && (fS0+fS1<=fDet+fTolerance)) { 115 | // intersection is inside triangle 116 | ipos = fTime; 117 | return true; 118 | } else { 119 | // intersection is outside triangle 120 | return false; 121 | } 122 | }; 123 | 124 | //--- check if and where line intersects triangle ------------------------- 125 | // Taken from Magic Software (http://www.cs.unc.edu/~eberly) 126 | // Return false if line is parallel to triangle 127 | // 128 | bool intersect_both_sides(const line3& line, float& ipos) { 129 | 130 | // Compute plane of triangle, Dot(normal,X-tri.b) = 0 where 'normal' is 131 | // the plane normal. If the angle between the line direction and normal 132 | // is small, then the line is effectively parallel to the triangle. 133 | const float fTolerance = 1e-04f; 134 | vector3 norm(e0*e1); 135 | float fDenominator = norm % line.m; 136 | float fLLenSqr = line.m % line.m; 137 | float fNLenSqr = norm % norm; 138 | 139 | // check if intersecting backface or parallel... 140 | if (fDenominator*fDenominator <= fTolerance*fLLenSqr*fNLenSqr) return false; 141 | 142 | //if ((fDenominator*fDenominator) <= (fTolerance*fLLenSqr*fNLenSqr)) { 143 | // // line and triangle are parallel 144 | // return false; 145 | //} 146 | 147 | // The line is X(t) = line.b + t*line.m. Compute line parameter t for 148 | // intersection of line and plane of triangle. Substitute in the plane 149 | // equation to get Dot(normal,line.b-tri.b) + t*Dot(normal,line.m) 150 | vector3 kDiff0(line.b - b); 151 | float fTime = -(norm % kDiff0) / fDenominator; 152 | if ((fTime<-fTolerance) || (fTime>(1.0f+fTolerance))) return false; 153 | 154 | // Find difference of intersection point of line with plane and vertex 155 | // of triangle. 156 | vector3 kDiff1(kDiff0 + line.m*fTime); 157 | 158 | // Compute if intersection point is inside triangle. Write 159 | // kDiff1 = s0*E0 + s1*E1 and solve for s0 and s1. 160 | float fE00 = e0 % e0; 161 | float fE01 = e0 % e1; 162 | float fE11 = e1 % e1; 163 | float fDet = (float) fabs(fE00*fE11-fE01*fE01); // = |normal|^2 > 0 164 | float fR0 = e0 % kDiff1; 165 | float fR1 = e1 % kDiff1; 166 | 167 | float fS0 = fE11*fR0 - fE01*fR1; 168 | float fS1 = fE00*fR1 - fE01*fR0; 169 | 170 | if ((fS0>=-fTolerance) && (fS1>=-fTolerance) && (fS0+fS1<=fDet+fTolerance)) { 171 | // intersection is inside triangle 172 | ipos = fTime; 173 | return true; 174 | } else { 175 | // intersection is outside triangle 176 | return false; 177 | } 178 | }; 179 | }; 180 | 181 | //------------------------------------------------------------------- 182 | #endif 183 | 184 | -------------------------------------------------------------------------------- /ext/mathlib/vector.h: -------------------------------------------------------------------------------- 1 | #ifndef N_VECTOR_H 2 | #define N_VECTOR_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | Implement 2, 3 and 4-dimensional vector classes. 6 | 7 | (C) 2002 RadonLabs GmbH 8 | */ 9 | #include "ntypes.h" 10 | 11 | #ifndef __USE_SSE__ 12 | // generic vector classes 13 | #include "mathlib/_vector2.h" 14 | #include "mathlib/_vector3.h" 15 | #include "mathlib/_vector4.h" 16 | typedef _vector2 vector2; 17 | typedef _vector3 vector3; 18 | typedef _vector4 vector4; 19 | #else 20 | // sse vector classes 21 | #include "mathlib/_vector2.h" 22 | #include "mathlib/_vector3_sse.h" 23 | #include "mathlib/_vector4_sse.h" 24 | typedef _vector2 vector2; 25 | typedef _vector3_sse vector3; 26 | typedef _vector4_sse vector4; 27 | #endif 28 | 29 | //------------------------------------------------------------------------------ 30 | #endif 31 | -------------------------------------------------------------------------------- /ext/mathlib/vector3envelopecurve.h: -------------------------------------------------------------------------------- 1 | #ifndef N_VECTOR3_ENVELOPE_CURVE_H 2 | #define N_VECTOR3_ENVELOPE_CURVE_H 3 | //------------------------------------------------------------------------------ 4 | /** 5 | @class nVector3EnvelopeCurve 6 | @ingroup Math 7 | 8 | A 3-dimensional envelope curve. 9 | 10 | (C) 2004 RadonLabs GmbH 11 | */ 12 | #include "mathlib/nmath.h" 13 | #include "mathlib/vector.h" 14 | 15 | //------------------------------------------------------------------------------ 16 | // nColorEnvelopeVurve 17 | //------------------------------------------------------------------------------ 18 | class nVector3EnvelopeCurve 19 | { 20 | public: 21 | /// constructor 1 22 | nVector3EnvelopeCurve(); 23 | /// constructor 2 24 | nVector3EnvelopeCurve(const vector3& keyFrameValue0, const vector3& keyFrameValue1, 25 | const vector3& keyFrameValue2, const vector3& keyFrameValue3, 26 | const float keyFramePos1, const float keyFramePos2); 27 | // set all parameters 28 | void SetParameters(const vector3& keyFrameValue0, const vector3& keyFrameValue1, 29 | const vector3& keyFrameValue2, const vector3& keyFrameValue3, 30 | const float keyFramePos1, const float keyFramePos2); 31 | // assign to other color envelope curve 32 | void SetParameters(const nVector3EnvelopeCurve& src); 33 | /// get the function value; pos must be between 0 and 1 34 | const vector3& GetValue(float pos) const; 35 | 36 | enum 37 | { 38 | NumValues = 4, 39 | }; 40 | 41 | vector3 keyFrameValues[NumValues]; 42 | float keyFramePos1, keyFramePos2; // 0 through 1 43 | float frequency, amplitude; // parameters of the sinus function 44 | }; 45 | 46 | //------------------------------------------------------------------------------ 47 | /** 48 | */ 49 | inline 50 | nVector3EnvelopeCurve::nVector3EnvelopeCurve() : 51 | keyFramePos1(.2f), 52 | keyFramePos2(.8f) 53 | { 54 | keyFrameValues[0] = vector3(1.0f, 1.0f, 1.0f); 55 | keyFrameValues[1] = vector3(1.0f, 1.0f, 1.0f); 56 | keyFrameValues[2] = vector3(1.0f, 1.0f, 1.0f); 57 | keyFrameValues[3] = vector3(1.0f, 1.0f, 1.0f); 58 | } 59 | 60 | //------------------------------------------------------------------------------ 61 | /** 62 | */ 63 | inline 64 | nVector3EnvelopeCurve::nVector3EnvelopeCurve(const vector3& keyFrameValue0, 65 | const vector3& keyFrameValue1, const vector3& keyFrameValue2, 66 | const vector3& keyFrameValue3, const float keyFramePos1, 67 | const float keyFramePos2) : 68 | keyFramePos1(keyFramePos1), 69 | keyFramePos2(keyFramePos2) 70 | { 71 | this->keyFrameValues[0] = keyFrameValue0; 72 | this->keyFrameValues[1] = keyFrameValue1; 73 | this->keyFrameValues[2] = keyFrameValue2; 74 | this->keyFrameValues[3] = keyFrameValue3; 75 | } 76 | 77 | //------------------------------------------------------------------------------ 78 | /** 79 | */ 80 | inline 81 | void 82 | nVector3EnvelopeCurve::SetParameters(const vector3& keyFrameValue0, const vector3& keyFrameValue1, 83 | const vector3& keyFrameValue2, const vector3& keyFrameValue3, 84 | const float keyFramePos1, const float keyFramePos2) 85 | { 86 | this->keyFrameValues[0] = keyFrameValue0; 87 | this->keyFrameValues[1] = keyFrameValue1; 88 | this->keyFrameValues[2] = keyFrameValue2; 89 | this->keyFrameValues[3] = keyFrameValue3; 90 | this->keyFramePos1 = keyFramePos1; 91 | this->keyFramePos2 = keyFramePos2; 92 | } 93 | //------------------------------------------------------------------------------ 94 | /** 95 | */ 96 | inline 97 | void 98 | nVector3EnvelopeCurve::SetParameters(const nVector3EnvelopeCurve& src) 99 | { 100 | this->keyFrameValues[0] = src.keyFrameValues[0]; 101 | this->keyFrameValues[1] = src.keyFrameValues[1]; 102 | this->keyFrameValues[2] = src.keyFrameValues[2]; 103 | this->keyFrameValues[3] = src.keyFrameValues[3]; 104 | this->keyFramePos1 = src.keyFramePos1; 105 | this->keyFramePos2 = src.keyFramePos2; 106 | } 107 | 108 | //------------------------------------------------------------------------------ 109 | /** 110 | */ 111 | inline 112 | const vector3& 113 | nVector3EnvelopeCurve::GetValue(float pos) const 114 | { 115 | n_assert(pos >= 0.0); 116 | n_assert(pos <= 1.0); 117 | 118 | static vector3 linearValue; 119 | 120 | if (pos < this->keyFramePos1) 121 | { 122 | linearValue = this->keyFrameValues[1]; 123 | linearValue.lerp(this->keyFrameValues[0], 124 | (pos / this->keyFramePos1)); 125 | } 126 | else if (pos < this->keyFramePos2) 127 | { 128 | linearValue = this->keyFrameValues[2]; 129 | linearValue.lerp(this->keyFrameValues[1], 130 | (pos-this->keyFramePos1) / (this->keyFramePos2-this->keyFramePos1)); 131 | } 132 | else 133 | { 134 | linearValue = this->keyFrameValues[3]; 135 | linearValue.lerp(this->keyFrameValues[2], 136 | (pos-this->keyFramePos2) / (1.0f-this->keyFramePos2)); 137 | } 138 | 139 | return linearValue; 140 | } 141 | 142 | //------------------------------------------------------------------------------ 143 | #endif 144 | -------------------------------------------------------------------------------- /lib32/DevIL.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/lib32/DevIL.lib -------------------------------------------------------------------------------- /lib32/ILU.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/lib32/ILU.lib -------------------------------------------------------------------------------- /lib32/ILUT.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/lib32/ILUT.lib -------------------------------------------------------------------------------- /lib32/glut32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/lib32/glut32.lib -------------------------------------------------------------------------------- /lib64/DevIL.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/lib64/DevIL.lib -------------------------------------------------------------------------------- /lib64/ILU.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/lib64/ILU.lib -------------------------------------------------------------------------------- /lib64/ILUT.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/lib64/ILUT.lib -------------------------------------------------------------------------------- /lib64/glut32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/lib64/glut32.lib -------------------------------------------------------------------------------- /project.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2012 for Windows Desktop 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "project", "src\project.vcxproj", "{791ABC2E-5701-47FA-86CE-2DE6E3428DAB}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {791ABC2E-5701-47FA-86CE-2DE6E3428DAB}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {791ABC2E-5701-47FA-86CE-2DE6E3428DAB}.Debug|Win32.Build.0 = Debug|Win32 14 | {791ABC2E-5701-47FA-86CE-2DE6E3428DAB}.Release|Win32.ActiveCfg = Release|Win32 15 | {791ABC2E-5701-47FA-86CE-2DE6E3428DAB}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/screenshot.jpg -------------------------------------------------------------------------------- /shader/particle/frag.txt: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0, index = 0) out vec4 fragColor; 4 | 5 | in float geo_out; 6 | 7 | void main(void) 8 | { 9 | fragColor = vec4(geo_out,geo_out,geo_out,1.0); 10 | } -------------------------------------------------------------------------------- /shader/particle/geo.txt: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(points, invocations = 1) in; 4 | layout(triangle_strip, max_vertices = 16) out; 5 | 6 | in vec4 vs_out0[]; 7 | in vec4 vs_out1[]; 8 | in vec4 vs_out2[]; 9 | in vec4 vs_out3[]; 10 | out float geo_out; 11 | uniform mat4 projectionMatrix; 12 | uniform vec4 block_pos; 13 | uniform float scale; 14 | 15 | void main(void) 16 | { 17 | for ( int i=0 ; i<4;i++) 18 | { 19 | vec4 plus; 20 | if(i==0)plus=vs_out0[0]; 21 | if(i==1)plus=vs_out1[0]; 22 | if(i==2)plus=vs_out2[0]; 23 | if(i==3)plus=vs_out3[0]; 24 | 25 | geo_out=plus.w;//*0.25; 26 | plus.w=0.0; 27 | plus+=block_pos; 28 | 29 | plus=projectionMatrix*plus; 30 | 31 | if (plus.z>0) 32 | if (plus.x/plus.w<=1.05) 33 | if (plus.x/plus.w>=-1.05) 34 | if (plus.y/plus.w<=1.05) 35 | if (plus.y/plus.w>=-1.05) 36 | { 37 | gl_Position = vec4(-scale,-scale, 0.0 , 0.0 )+plus; 38 | EmitVertex(); 39 | gl_Position = vec4( scale,-scale, 0.0 , 0.0 )+plus; 40 | EmitVertex(); 41 | gl_Position = vec4(-scale, scale, 0.0 , 0.0 )+plus; 42 | EmitVertex(); 43 | gl_Position = vec4( scale, scale, 0.0 , 0.0 )+plus; 44 | EmitVertex(); 45 | EndPrimitive(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /shader/particle/vs.txt: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec4 vertex0; 4 | in vec4 vertex1; 5 | in vec4 vertex2; 6 | in vec4 vertex3; 7 | out vec4 vs_out0; 8 | out vec4 vs_out1; 9 | out vec4 vs_out2; 10 | out vec4 vs_out3; 11 | 12 | void main(void) 13 | { 14 | vs_out0=vertex0*(1.0/1.0); 15 | vs_out1=vertex1*(1.0/1.0); 16 | vs_out2=vertex2*(1.0/1.0); 17 | vs_out3=vertex3*(1.0/1.0); 18 | gl_Position = vec4(1,1,1,1); 19 | } -------------------------------------------------------------------------------- /sphereN.rle4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/OpenGL-Voxel-Splatting/996e47383a51300e891254eb36500934ecfcdb52/sphereN.rle4 -------------------------------------------------------------------------------- /src/Bmp.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////// 2 | #pragma once 3 | /////////////////////////////////////////// 4 | #include 5 | #include 6 | #include 7 | #include "VecMath.h" 8 | /////////////////////////////////////////// 9 | class Bmp 10 | { 11 | public: 12 | 13 | Bmp(); 14 | Bmp(int x,int y,int bpp,unsigned char*data=0); 15 | Bmp(const char*filename); 16 | ~Bmp(); 17 | 18 | void load(const char *filename); 19 | bool save(const char*filename); 20 | 21 | vec3f getSxSyT(float x); 22 | int sampleByte(int x,int y); 23 | bool set(int x,int y,int bpp,unsigned char*data); 24 | bool set3d(int x,int y,int z,int bpp,unsigned char*buffer); 25 | void crop(int x,int y); 26 | bool scale(int x,int y); 27 | bool blur(int count); 28 | bool hblur(int count); 29 | bool vblur(int count); 30 | bool addalpha(unsigned char r,unsigned char g,unsigned char b); 31 | bool normalize(void); 32 | bool normalMap(void); 33 | vec3f get_pixel(float x,float y); 34 | vec3f get_f_fdx_fdy(float x,float y); 35 | void make_border(int border,int r,int g,int b) 36 | { 37 | int s=width*height; 38 | for (int i=0;i=level)found++; 67 | for (int jj=-1;jj<=1;jj++) 68 | if (data[(i+(j+jj)*width)*3]>=level)found++; 69 | 70 | /* 71 | for (int ii=-1;ii<=1;ii++) 72 | for (int jj=-1;jj<=1;jj++) 73 | if (data[(i+ii+(j+jj)*width)*3]>=level)found++; 74 | */ 75 | 76 | if(found==6)data[(i+j*width)*3]=level+1; 77 | } 78 | //level++; 79 | } 80 | 81 | for (int i=0;i 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include // Header File For The GLUT Library 11 | #include 12 | #include 13 | #include 14 | using namespace std; 15 | #include "VecMath.h" 16 | #include "glsl.h" 17 | /////////////////////////////////////////// 18 | #include "Bmp.h" 19 | #include "Bmp.h" 20 | /////////////////////////////////////////// 21 | #define SCREEN_SIZE_X 1024 22 | #define SCREEN_SIZE_Y 768 23 | //////////////////////////////////////////////////////////////////////////////// 24 | #define _USE_MATH_DEFINES 25 | #define loopi(start_l,end_l,step_l) for ( int i=start_l;ix=x; 63 | this->y=y; 64 | this->z=z; 65 | this->w=w; 66 | } 67 | 68 | uint to_uint() 69 | { 70 | return *((unsigned int*)this); 71 | }; 72 | }; 73 | //////////////////////////////////////////////////////////////////////////////// 74 | class Keyboard 75 | { 76 | public: 77 | 78 | bool key [256]; // actual 79 | bool key2[256]; // before 80 | 81 | Keyboard(){ int a; loop(a,0,256) key[a] = key2[a]=0; } 82 | 83 | bool KeyDn(char a)//key down 84 | { 85 | return key[a]; 86 | } 87 | bool KeyPr(char a)//pressed 88 | { 89 | return ((!key2[a]) && key[a] ); 90 | } 91 | bool KeyUp(char a)//released 92 | { 93 | return ((!key[a]) && key2[a] ); 94 | } 95 | void update() 96 | { 97 | int a;loop( a,0,256 ) key2[a] = key[a]; 98 | } 99 | }; 100 | //////////////////////////////////////////////////////////////////////////////// 101 | class Mouse 102 | { 103 | public: 104 | 105 | bool button[256]; 106 | bool button2[256]; 107 | float mouseX,mouseY; 108 | float mouseX2,mouseY2; 109 | float mouseDX,mouseDY; 110 | 111 | Mouse() 112 | { 113 | int a; loop(a,0,256) button[a] = button2[a]=0; 114 | mouseX=mouseY=mouseDX=mouseDY= 0; 115 | } 116 | void update() 117 | { 118 | mouseDX=mouseX-mouseX2;mouseX2=mouseX; 119 | mouseDY=mouseY-mouseY2;mouseY2=mouseY; 120 | int a;loop( a,0,256 ) button2[a] = button[a]; 121 | } 122 | }; 123 | //////////////////////////////////////////////////////////////////////////////// 124 | class ScreenA 125 | { 126 | public: 127 | ScreenA() 128 | { 129 | // pos=vec3f(-5.69, -8.46, -15.48); 130 | // rot=vec3f(19.63, 2.73, 0.00); 131 | // pos -12.88 -9.46 -10.39 rot -50.39 13.28 0.00 132 | 133 | pos=vec3f( -13.60, -19.70, -21.06); 134 | rot=vec3f(130.07, 15.23, 0.00); 135 | fov=60; 136 | screentime=0; 137 | 138 | // pos=vec3f( -12.88, -9.46, -10.39); 139 | // rot=vec3f(-50.39, 13.28, 0.00); 140 | }; 141 | 142 | float screentime; 143 | int window_width; 144 | int window_height; 145 | int window2_width; 146 | int window2_height; 147 | int window3_width; 148 | int window3_height; 149 | bool fullscreen; 150 | 151 | matrix44 camera; 152 | 153 | vec3f pos,rot,lookat; 154 | float fov; 155 | }; 156 | //////////////////////////////////////////////////////////////////////////////// 157 | void CoreInit(void (GLUTCALLBACK *drawFunc)(void),int argc,char **argv); 158 | 159 | double CoreCubicInterpolate( 160 | double y0,double y1, 161 | double y2,double y3, 162 | double mu); 163 | char* CoreReadFile(char* name); 164 | GLuint CoreNewFloat16Tex(int width,int height,float* buffer,bool alpha); 165 | GLuint CoreNewChar8Tex(int width,int height,uchar* buffer,bool alpha); 166 | GLuint CoreNewFloat32Tex(int width,int height,float* buffer,bool alpha); 167 | GLuint CoreTextureFromBmp(Bmp &bmp); 168 | void CoreScreenshot(int counter,char* prefix=NULL); 169 | void CoreDrawQuad(); 170 | void CoreKeyMouse(); 171 | //////////////////////////////////////////////////////////////////////////////// 172 | extern Keyboard keyboard; 173 | extern Mouse mouse; 174 | extern ScreenA screen; 175 | //////////////////////////////////////////////////////////////////////////////// 176 | extern int handle_window1; 177 | extern int handle_window2; 178 | extern int handle_window3; 179 | //////////////////////////////////////////////////////////////////////////////// 180 | -------------------------------------------------------------------------------- /src/Main.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////// 2 | #include 3 | #include "Core.h" 4 | /////////////////////////////////////////// 5 | #include "RLE4.h" 6 | /////////////////////////////////////////// 7 | #include "bitmap_fonts.h" 8 | /////////////////////////////////////////// 9 | struct CUBE256 10 | { 11 | 12 | vec3f pos,rot; 13 | 14 | struct MipMap 15 | { 16 | int handle; 17 | std::vector voxels; // x y<<8 z<<16 color<<24 18 | }; 19 | std::vector mipmaps; 20 | 21 | //std::vector voxels; // x y<<8 z<<16 color<<24 22 | 23 | void set_voxel(int mipmap,uint x,uint y,uint z,uchar4 color) 24 | { 25 | if(x>255) return;if(x<0) return; 26 | if(y>255) return;if(x<0) return; 27 | if(z>255) return;if(x<0) return; 28 | if(mipmap>=mipmaps.size()) mipmaps.resize(mipmap+1); 29 | mipmaps[mipmap].voxels.push_back( uchar4(x,y,z,color.x).to_uint() ); 30 | } 31 | void gen_vbo() 32 | { 33 | if(mipmaps.size()==0) return; 34 | 35 | loopi(0,mipmaps.size()) 36 | if(mipmaps[i].voxels.size()>0) 37 | { 38 | //voxels.resize(voxels.size()); 39 | glGenBuffers(1, (GLuint *)(&mipmaps[i].handle)); 40 | glBindBuffer(GL_ARRAY_BUFFER, (GLuint)(mipmaps[i].handle)); 41 | glBufferData(GL_ARRAY_BUFFER, mipmaps[i].voxels.size()*4,&mipmaps[i].voxels[0], GL_STATIC_DRAW_ARB ); 42 | } 43 | } 44 | void draw(int mipmap=0,vec3f add=vec3f(0,0,0)) 45 | { 46 | if(mipmap>=mipmaps.size()) return; 47 | if(mipmaps[mipmap].voxels.size()==0) return; 48 | 49 | static Shader shader("Particle Shader"); 50 | static bool init=true; 51 | 52 | if(init) 53 | { 54 | init=false; 55 | /*+++++++++++++++++++++++++++++++++++++*/ 56 | shader.attach(GL_VERTEX_SHADER,"../shader/particle/vs.txt"); 57 | shader.attach(GL_FRAGMENT_SHADER,"../shader/particle/frag.txt"); 58 | shader.attach(GL_GEOMETRY_SHADER,"../shader/particle/geo.txt"); 59 | shader.link(); 60 | /*+++++++++++++++++++++++++++++++++++++*/ 61 | } 62 | 63 | float Projection[16]; 64 | float Modelview[16]; 65 | glGetFloatv(GL_PROJECTION_MATRIX, Projection); 66 | 67 | shader.begin(); 68 | shader.setUniformMatrix4fv("projectionMatrix", 1, 0, Projection); 69 | 70 | int vertexLocation0 = glGetAttribLocation(shader.program_handle, "vertex0"); 71 | glEnableVertexAttribArray(vertexLocation0); 72 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, mipmaps[mipmap].handle); CHECK_GL_ERROR(); 73 | glEnableClientState(GL_VERTEX_ARRAY); CHECK_GL_ERROR(); 74 | glVertexAttribPointer(vertexLocation0, 4, GL_UNSIGNED_BYTE, GL_TRUE, 16, 0); 75 | 76 | int vertexLocation1 = glGetAttribLocation(shader.program_handle, "vertex1"); 77 | glEnableVertexAttribArray(vertexLocation1); 78 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, mipmaps[mipmap].handle); CHECK_GL_ERROR(); 79 | glEnableClientState(GL_VERTEX_ARRAY); CHECK_GL_ERROR(); 80 | glVertexAttribPointer(vertexLocation1, 4, GL_UNSIGNED_BYTE, GL_TRUE, 16, (void*)4); 81 | 82 | int vertexLocation2 = glGetAttribLocation(shader.program_handle, "vertex2"); 83 | glEnableVertexAttribArray(vertexLocation2); 84 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, mipmaps[mipmap].handle); CHECK_GL_ERROR(); 85 | glEnableClientState(GL_VERTEX_ARRAY); CHECK_GL_ERROR(); 86 | glVertexAttribPointer(vertexLocation2, 4, GL_UNSIGNED_BYTE, GL_TRUE, 16, (void*)8); 87 | 88 | int vertexLocation3 = glGetAttribLocation(shader.program_handle, "vertex3"); 89 | glEnableVertexAttribArray(vertexLocation3); 90 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, mipmaps[mipmap].handle); CHECK_GL_ERROR(); 91 | glEnableClientState(GL_VERTEX_ARRAY); CHECK_GL_ERROR(); 92 | glVertexAttribPointer(vertexLocation3, 4, GL_UNSIGNED_BYTE, GL_TRUE, 16, (void*)12); 93 | 94 | vec3f pos_sum=add+pos; 95 | shader.setUniform4f("block_pos",pos_sum.x,pos_sum.y,pos_sum.z,1 ); 96 | shader.setUniform1f("scale",0.1f*float(1< cubes; 113 | 114 | void init_cubes() 115 | { 116 | cubes.resize(cubes_x*cubes_y*cubes_z); 117 | 118 | int c=0; 119 | loopk(0,cubes_z) 120 | loopj(0,cubes_y) 121 | loopi(0,cubes_x) 122 | { 123 | cubes[c++].pos=vec3f(i,j,k); 124 | } 125 | } 126 | void set_voxel(int mipmap,uint x,uint y,uint z,uchar4 color) 127 | { 128 | if(x>cubes_x*256)return; 129 | if(y>cubes_y*256)return; 130 | if(z>cubes_z*256)return; 131 | x<<=mipmap; 132 | y<<=mipmap; 133 | z<<=mipmap; 134 | int id=(x>>8)+(y>>8)*cubes_x+(z>>8)*cubes_x*cubes_y; 135 | cubes[id].set_voxel(mipmap,x&255,y&255,z&255,color); 136 | } 137 | /////////////////////////////////////////// 138 | void DrawScene() 139 | { 140 | static int framenumber=0; 141 | 142 | glViewport(0,0,screen.window_width,screen.window_height); 143 | glClearDepth(1.0f); 144 | glClearColor(0,0,0,0); 145 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 146 | 147 | glMatrixMode( GL_PROJECTION); 148 | glLoadIdentity(); 149 | gluPerspective(screen.fov, (GLfloat)screen.window_width / (GLfloat) screen.window_height, 0.01, 10000.0); 150 | 151 | // Position 152 | glRotatef(screen.rot.z, 0,0,1); 153 | glRotatef(screen.rot.y, 1,0,0); 154 | glRotatef(screen.rot.x, 0,1,0); 155 | glTranslatef( 156 | screen.pos.x, 157 | screen.pos.y, 158 | screen.pos.z 159 | ); 160 | 161 | // Particle 162 | glScalef(16,16,16); 163 | 164 | glMatrixMode( GL_MODELVIEW); 165 | glLoadIdentity(); 166 | 167 | loopi(0,cubes.size()) 168 | loopk(0,4) 169 | loopj(0,4) 170 | { 171 | vec3f add=vec3f(cubes_x*k,0,cubes_y*j); 172 | vec3f pos=cubes[i].pos; 173 | 174 | //int mipmap = log(1+(screen.pos-(pos+vec3f(0.5,0.5,0.5)-add*16)).length()/16) / log( 2.0f ); 175 | int mipmap = sqrt(sqrt((screen.pos+((pos+vec3f(0.5,0.5,0.5)+add)*16)).length()))-1; 176 | if(mipmap<0)mipmap=0; 177 | 178 | cubes[i].draw(mipmap,add); 179 | } 180 | 181 | //OSD 182 | 183 | beginRenderText( screen.window_width, screen.window_height); 184 | { 185 | char text[100]; int HCOL= 0,VCOL = 5; glColor3f( 1.0f, 1.0f, 1.0f ); 186 | 187 | sprintf(text, "FrameTime / FPS / MTri/s: %2.2fms %2.2f" , screen.screentime,1.0/screen.screentime ); renderText( VCOL, HCOL+=15, BITMAP_FONT_TYPE_HELVETICA_12, text ); 188 | sprintf(text, "Resolution : %d %d", screen.window_width, screen.window_height); renderText( VCOL, HCOL+=15, BITMAP_FONT_TYPE_HELVETICA_12, text ); 189 | 190 | } 191 | endRenderText(); 192 | 193 | 194 | printf("pos %2.2f %2.2f %2.2f rot %2.2f %2.2f %2.2f \r", 195 | screen.pos.x, 196 | screen.pos.y, 197 | screen.pos.z, 198 | screen.rot.x, 199 | screen.rot.y, 200 | screen.rot.z 201 | ); 202 | 203 | CoreKeyMouse(); 204 | 205 | glutSwapBuffers(); 206 | } 207 | /////////////////////////////////////////// 208 | int main(int argc, char **argv) 209 | { 210 | printf("Loading ...\n"); 211 | 212 | RLE4 rle; 213 | 214 | init_cubes(); 215 | // rle.load_m5("../voxelstein.rle4"); 216 | rle.load_m5("../sphereN.rle4"); 217 | 218 | printf("\n\n#Cubes %d\n\n",cubes.size()); 219 | 220 | int sum=0; 221 | loopi(0,cubes.size()) 222 | if(cubes[i].mipmaps.size()>0) 223 | sum+=cubes[i].mipmaps[0].voxels.size(); 224 | printf("\n\nvoxels total:%d Million\n\n",sum/(1024*1024)); 225 | 226 | screen.window_width = SCREEN_SIZE_X; 227 | screen.window_height = SCREEN_SIZE_Y; 228 | CoreInit(DrawScene,argc, argv); 229 | wglSwapIntervalEXT(0); 230 | 231 | loopi(0,cubes.size()) cubes[i].gen_vbo(); 232 | 233 | printf("main loop\n"); 234 | glutMainLoop(); 235 | } 236 | /////////////////////////////////////////// -------------------------------------------------------------------------------- /src/Rle4.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Core.h" 3 | 4 | struct Map4 5 | { 6 | int sx,sy,sz,slabs_size; 7 | uint *map_mem; 8 | uint *map; 9 | ushort *slabs; 10 | //uint nop; 11 | 12 | // map: 13 | // id 0 : rle siz 14 | // id 0 : tex siz 15 | // id 1 : rle len 16 | // id 2 : rle elems ... [] 17 | // id x : tex elems ... [] 18 | }; 19 | 20 | struct Map5 21 | { 22 | int sx,sy,sz; // total size 23 | int tx,ty,tz; // tile size 24 | 25 | struct Tile 26 | { 27 | uint slabs_size; 28 | uint *map; 29 | ushort *slabs; 30 | }; 31 | 32 | Tile tiles[64*32]; 33 | }; 34 | 35 | 36 | class Tree; 37 | 38 | struct RLE4 39 | { 40 | /*------------------------------------------------------*/ 41 | Map4 map [16],mapgpu [16];int nummaps; 42 | Map5 map5[16],mapgpu5[16]; 43 | /*------------------------------------------------------*/ 44 | void compress_all(Tree& tree); 45 | /*------------------------------------------------------*/ 46 | Map4 compress(Tree& tree,int mip_lvl); //int sx,int sy,int sz,uchar* col1,uchar* col2); 47 | /*------------------------------------------------------*/ 48 | void init(); 49 | /*------------------------------------------------------*/ 50 | void clear(); 51 | /*------------------------------------------------------*/ 52 | void save(char *filename); 53 | /*------------------------------------------------------*/ 54 | bool load(char *filename); 55 | /*------------------------------------------------------*/ 56 | bool load_m5(char *filename); 57 | /*------------------------------------------------------*/ 58 | void setgeom (long x, long y, long z, long issolid); 59 | void setcol (long x, long y, long z, long argb); 60 | long loadvxl (char *filnam); 61 | long loadvxl_octree (char *filnam); 62 | Map4 compressvxl(ushort* mem,int sx,int sy,int sz,int mip_lvl); 63 | /*------------------------------------------------------*/ 64 | }; 65 | -------------------------------------------------------------------------------- /src/Tree.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tree.h" 3 | /*------------------------------------------------------*/ 4 | // std::vector triangle_list; 5 | std::vector Tree::vertex_arr; 6 | std::vector Tree::normal_arr; 7 | std::vector Tree::faces_arr; 8 | /*------------------------------------------------------*/ 9 | -------------------------------------------------------------------------------- /src/VecMath.cpp: -------------------------------------------------------------------------------- 1 | #include "VecMath.h" 2 | 3 | int vec3f::random_number = 3457734; 4 | 5 | void vec3f::random_init() 6 | { 7 | random_number = 3457734; 8 | } 9 | 10 | float vec3f::random_float(){ 11 | static int t = random_number; 12 | t = (t * 2345633 + t*1245 + t*356 + t*35 + t/34 + t/325 - 8647445); 13 | random_number = t; 14 | 15 | return ( float (abs(t)%10000)/10000); 16 | } 17 | 18 | 19 | 20 | 21 | vec3f vec3f::random(){ 22 | static vec3f rnd; 23 | rnd.x=random_float()*2-1; 24 | rnd.y=random_float()*2-1; 25 | rnd.z=random_float()*2-1; 26 | rnd.normalize(); 27 | return rnd; 28 | } 29 | 30 | vec3f vec3f::normalize( vec3f a ) 31 | { 32 | float square = a.x*a.x + a.y*a.y + a.z*a.z; 33 | if (square <= 0.00001f ) 34 | { 35 | a.x=1;a.y=0;a.z=0; 36 | return a; 37 | } 38 | float len = 1.0f / (float)sqrt(square); 39 | a.x*=len;a.y*=len;a.z*=len; 40 | return a; 41 | } 42 | 43 | 44 | /* 45 | bool lines_intersect ( vec3f line1[2] ,vec3f line2[2] , vec3f* intersection = NULL) 46 | { 47 | // BBox 48 | 49 | if ( line1[0].x < line2[0].x ) if ( line1[0].x < line2[1].x ) if ( line1[1].x < line2[0].x ) if ( line1[1].x < line2[1].x ) return false; 50 | if ( line1[0].x > line2[0].x ) if ( line1[0].x > line2[1].x ) if ( line1[1].x > line2[0].x ) if ( line1[1].x > line2[1].x ) return false; 51 | if ( line1[0].y > line2[0].y ) if ( line1[0].y > line2[1].y ) if ( line1[1].y > line2[0].y ) if ( line1[1].y > line2[1].y ) return false; 52 | if ( line1[0].y < line2[0].y ) if ( line1[0].y < line2[1].y ) if ( line1[1].y < line2[0].y ) if ( line1[1].y < line2[1].y ) return false; 53 | 54 | // intersect 55 | 56 | 57 | //a x + b = c y + d 58 | //a x - c y = d - b 59 | 60 | //- a2 a1 x + a2 c1 y =-a2 d1 + a2 b1 61 | // a1 a2 x - a1 c2 y = a1 d2 - a1 b2 62 | 63 | // y = ( a1 d2 - a1 b2 - a2 d1 + a2 b1 ) / ( a2 c1 - a1 c2 ) 64 | 65 | 66 | vec3f delta1 = line1[1] - line1[0]; 67 | vec3f delta2 = line2[1] - line2[0]; 68 | vec3f point1 = line1[0]; 69 | vec3f point2 = line2[0]; 70 | 71 | float div1 = delta1.y*delta2.x - delta1.x*delta2.y; 72 | float div2 = delta2.y*delta1.x - delta2.x*delta1.y; 73 | 74 | float a = 2; 75 | 76 | if ( div1 != 0) 77 | { 78 | a = ( delta1.x*point2.y - 79 | delta1.x*point1.y - 80 | delta1.y*point2.x + 81 | delta1.y*point1.x ) / div1; 82 | }else 83 | if ( div2 != 0) 84 | { 85 | a = ( delta2.x*point1.y - 86 | delta2.x*point2.y - 87 | delta2.y*point1.x + 88 | delta2.y*point2.x ) / div2; 89 | } 90 | if ( a <= 1 ) 91 | if ( a >= 0 ) 92 | { 93 | if (intersection) 94 | { 95 | if ( div1 != 0) 96 | *intersection = delta2 * a + point2; 97 | else 98 | *intersection = delta1 * a + point1; 99 | } 100 | return true; 101 | } 102 | 103 | return false; 104 | }; 105 | */ 106 | -------------------------------------------------------------------------------- /src/VecMath.h: -------------------------------------------------------------------------------- 1 | #ifndef _VecMath_class 2 | #define _VecMath_class 3 | 4 | //#include 5 | #include 6 | 7 | #ifndef vec3i 8 | struct vec3i { int x,y,z;}; 9 | #endif 10 | 11 | //#define __USE_SSE__ 12 | #include "mathlib/vector.h" 13 | #include "mathlib/matrix.h" 14 | 15 | struct vec3f 16 | { 17 | float x, y, z; 18 | 19 | inline vec3f( void ) {} 20 | 21 | //inline vec3f operator =( vector3 a ) 22 | // { vec3f b ; b.x = a.x; b.y = a.y; b.z = a.z; return b;} 23 | 24 | inline vec3f( vector3 a ) 25 | { x = a.x; y = a.y; z = a.z; } 26 | 27 | inline vec3f( const float X, const float Y, const float Z ) 28 | { x = X; y = Y; z = Z; } 29 | 30 | inline vec3f operator + ( const vec3f& a ) const 31 | { return vec3f( x + a.x, y + a.y, z + a.z ); } 32 | 33 | inline vec3f operator += ( const vec3f& a ) const 34 | { return vec3f( x + a.x, y + a.y, z + a.z ); } 35 | 36 | inline vec3f operator * ( const float a ) const 37 | { return vec3f( x * a, y * a, z * a ); } 38 | 39 | inline vec3f operator * ( const vec3f a ) const 40 | { return vec3f( x * a.x, y * a.y, z * a.z ); } 41 | 42 | inline vector3 v3 () const 43 | { return vector3( x , y, z ); } 44 | 45 | inline vec3f operator = ( const vector3 a ) 46 | { x=a.x;y=a.y;z=a.z;return *this; } 47 | 48 | inline vec3f operator = ( const vec3f a ) 49 | { x=a.x;y=a.y;z=a.z;return *this; } 50 | 51 | inline vec3f operator / ( const vec3f a ) const 52 | { return vec3f( x / a.x, y / a.y, z / a.z ); } 53 | 54 | inline vec3f operator - ( const vec3f& a ) const 55 | { return vec3f( x - a.x, y - a.y, z - a.z ); } 56 | 57 | inline vec3f operator / ( const float a ) const 58 | { return vec3f( x / a, y / a, z / a ); } 59 | 60 | inline float dot( const vec3f& a ) const 61 | { return a.x*x + a.y*y + a.z*z; } 62 | 63 | inline vec3f cross( const vec3f& a , const vec3f& b ) 64 | { 65 | x = a.y * b.z - a.z * b.y; 66 | y = a.z * b.x - a.x * b.z; 67 | z = a.x * b.y - a.y * b.x; 68 | return *this; 69 | } 70 | 71 | inline float angle( const vec3f& v ) 72 | { 73 | vec3f a = v , b = *this; 74 | float dot = v.x*x + v.y*y + v.z*z; 75 | float len = a.length() * b.length(); 76 | if(len==0)len=0.00001f; 77 | float input = dot / len; 78 | if (input<-1) input=-1; 79 | if (input>1) input=1; 80 | return (float) acos ( input ); 81 | } 82 | 83 | inline float angle2( const vec3f& v , const vec3f& w ) 84 | { 85 | vec3f a = v , b= *this; 86 | float dot = a.x*b.x + a.y*b.y + a.z*b.z; 87 | float len = a.length() * b.length(); 88 | if(len==0)len=1; 89 | 90 | vec3f plane; plane.cross( b,w ); 91 | 92 | if ( plane.x * a.x + plane.y * a.y + plane.z * a.z > 0 ) 93 | return (float) -acos ( dot / len ); 94 | 95 | return (float) acos ( dot / len ); 96 | } 97 | 98 | inline vec3f rot_x( float a ) 99 | { 100 | float yy = cos ( a ) * y + sin ( a ) * z; 101 | float zz = cos ( a ) * z - sin ( a ) * y; 102 | y = yy; z = zz; 103 | return *this; 104 | } 105 | inline vec3f rot_y( float a ) 106 | { 107 | float xx = cos ( -a ) * x + sin ( -a ) * z; 108 | float zz = cos ( -a ) * z - sin ( -a ) * x; 109 | x = xx; z = zz; 110 | return *this; 111 | } 112 | inline void clamp( float min, float max ) 113 | { 114 | if (xmax) x=max; 118 | if (y>max) y=max; 119 | if (z>max) z=max; 120 | } 121 | inline vec3f rot_z( float a ) 122 | { 123 | float yy = cos ( a ) * y + sin ( a ) * x; 124 | float xx = cos ( a ) * x - sin ( a ) * y; 125 | y = yy; x = xx; 126 | return *this; 127 | } 128 | inline vec3f invert() 129 | { 130 | x=-x;y=-y;z=-z;return *this; 131 | } 132 | inline vec3f frac() 133 | { 134 | return vec3f( 135 | x-float(int(x)), 136 | y-float(int(y)), 137 | z-float(int(z)) 138 | ); 139 | } 140 | 141 | inline vec3f integer() 142 | { 143 | return vec3f( 144 | float(int(x)), 145 | float(int(y)), 146 | float(int(z)) 147 | ); 148 | } 149 | 150 | inline float length() const 151 | { 152 | return (float)sqrt(x*x + y*y + z*z); 153 | } 154 | 155 | inline vec3f normalize( float desired_length = 1 ) 156 | { 157 | float square = x*x + y*y + z*z; 158 | if (square <= 0.00001f ) 159 | { 160 | x=1;y=0;z=0; 161 | return *this; 162 | } 163 | float len = desired_length / (float)sqrt(square); 164 | x*=len;y*=len;z*=len; 165 | return *this; 166 | } 167 | static vec3f normalize( vec3f a ); 168 | 169 | static void random_init(); 170 | static float random_float(); 171 | static vec3f random(); 172 | 173 | static int random_number; 174 | 175 | double random_float_01(double a){ 176 | double rnf=a*14.434252+a*364.2343+a*4213.45352+a*2341.43255+a*254341.43535+a*223454341.3523534245+23453.423412; 177 | int rni=((int)rnf)%100000; 178 | return double(rni)/(100000.0f-1.0f); 179 | } 180 | 181 | vec3f random01_fxyz(){ 182 | x=(float)random_float_01(x); 183 | y=(float)random_float_01(y); 184 | z=(float)random_float_01(z); 185 | return *this; 186 | } 187 | }; 188 | 189 | /* 190 | class Matrix 191 | { 192 | public: 193 | 194 | float m[16]; 195 | 196 | void identity() 197 | { 198 | static float identity[16]={ 199 | 1,0,0,0, 200 | 0,1,0,0, 201 | 0,0,1,0, 202 | 0,0,0,1 203 | }; 204 | memcpy( m,identity,16 ); 205 | } 206 | 207 | Matrix( vec3f a,vec3f b,vec3f c,vec3f d = vec3f(0,0,0)) { 208 | 209 | identity() ; 210 | 211 | m[ 0] = a.x;m[ 1] = b.x;m[ 2] = c.x;m[ 3] = d.x; 212 | m[ 4] = a.y;m[ 5] = b.y;m[ 6] = c.y;m[ 7] = d.y; 213 | m[ 8] = a.z;m[ 9] = b.z;m[10] = c.z;m[11] = d.z; 214 | m[15]=1; 215 | } 216 | 217 | Matrix( void ) { 218 | 219 | identity() ; 220 | } 221 | 222 | inline vec3f operator * ( const vec3f& a ) const 223 | { 224 | vec3f out; 225 | out.x = a.x*m[ 0] + a.y*m[ 4] + a.z*m[ 8] + m[12]; 226 | out.y = a.x*m[ 1] + a.y*m[ 5] + a.z*m[ 9] + m[13]; 227 | out.z = a.x*m[ 2] + a.y*m[ 6] + a.z*m[10] + m[14]; 228 | // out.x = a.x*m[ 0] + a.y*m[ 1] + a.z*m[ 2] + m[ 3]; 229 | // out.y = a.x*m[ 4] + a.y*m[ 5] + a.z*m[ 6] + m[ 7]; 230 | // out.z = a.x*m[ 8] + a.y*m[ 9] + a.z*m[10] + m[11]; 231 | // out.x = a.x*m[ 0] + a.x*m[ 1] + a.x*m[ 2] + m[ 3]; 232 | // out.y = a.y*m[ 4] + a.y*m[ 5] + a.y*m[ 6] + m[ 7]; 233 | // out.z = a.z*m[ 8] + a.z*m[ 9] + a.z*m[10] + m[11]; 234 | return out; 235 | } 236 | 237 | Matrix operator * ( const Matrix& a ) const 238 | { 239 | int i,j,k; 240 | Matrix result; 241 | 242 | for (i=0;i<4;i++) 243 | for (j=0;j<4;j++) 244 | { 245 | result.m[i+j*4]=0; 246 | 247 | for (k=0;k<4;k++) 248 | result.m[i+j*4] += a.m[i+k*4] * m[j*4+k] ; 249 | } 250 | return result; 251 | } 252 | }; 253 | */ 254 | #endif 255 | -------------------------------------------------------------------------------- /src/glsl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // GL ERROR CHECK 4 | #define CHECK_GL_ERROR() CheckGLError(__FILE__, __LINE__) 5 | // GL ERROR CHECK 6 | int CheckGLError(char *file, int line); 7 | /////////////////////////////////////////// 8 | class Shader 9 | { 10 | public: 11 | Shader(std::string shadername){name=shadername;}; 12 | void attach(int type,char* filename) 13 | { 14 | char* mem=read_file(filename); 15 | GLuint handle = glCreateShader(type); 16 | glShaderSource(handle, 1, (const GLchar**)(&mem), 0); 17 | CHECK_GL_ERROR(); 18 | glCompileShader(handle); 19 | CHECK_GL_ERROR(); 20 | 21 | GLint compileSuccess=0; 22 | GLchar compilerSpew[256]; 23 | 24 | glGetShaderiv(handle, GL_COMPILE_STATUS, &compileSuccess); 25 | CHECK_GL_ERROR(); 26 | if(!compileSuccess) 27 | { 28 | glGetShaderInfoLog(handle, sizeof(compilerSpew), 0, compilerSpew); 29 | printf("Shader %s\n%s\ncompileSuccess=%d\n",filename,compilerSpew,compileSuccess); 30 | CHECK_GL_ERROR(); 31 | while(1);; 32 | } 33 | handles.push_back(handle); 34 | } 35 | void link() 36 | { 37 | program_handle = glCreateProgram(); 38 | for (int i=0;i handles; 139 | GLuint program_handle; 140 | std::string name; 141 | 142 | char* read_file(char* name) 143 | { 144 | FILE * fp = fopen (name, "rb"); 145 | 146 | if (fp==0) 147 | { 148 | printf ("File %s NOT FOUND\n"); 149 | while(1);; 150 | } 151 | fseek(fp, 0L, SEEK_END); 152 | int fsize = ftell(fp); 153 | fseek(fp, 0L, SEEK_SET); 154 | char* mem=(char*)malloc(fsize+1); 155 | for(int i=0;i 2 | 11 | 12 | 15 | 18 | 19 | 20 | 21 | 22 | 29 | 32 | 35 | 38 | 41 | 44 | 56 | 59 | 62 | 65 | 77 | 80 | 83 | 86 | 89 | 92 | 95 | 98 | 99 | 106 | 109 | 112 | 115 | 118 | 122 | 134 | 137 | 140 | 143 | 155 | 158 | 161 | 164 | 167 | 170 | 173 | 176 | 177 | 184 | 187 | 190 | 193 | 196 | 199 | 210 | 213 | 216 | 219 | 233 | 236 | 239 | 242 | 245 | 248 | 251 | 254 | 255 | 262 | 265 | 268 | 271 | 274 | 278 | 288 | 291 | 294 | 297 | 311 | 314 | 317 | 320 | 323 | 326 | 329 | 332 | 333 | 334 | 335 | 336 | 337 | 340 | 343 | 344 | 347 | 348 | 351 | 352 | 355 | 356 | 357 | 360 | 363 | 364 | 367 | 368 | 369 | 372 | 375 | 376 | 379 | 380 | 383 | 384 | 387 | 388 | 391 | 392 | 395 | 396 | 399 | 400 | 403 | 404 | 405 | 408 | 411 | 412 | 415 | 416 | 419 | 420 | 423 | 424 | 427 | 428 | 431 | 432 | 435 | 436 | 439 | 440 | 441 | 444 | 445 | 446 | 447 | 448 | 449 | -------------------------------------------------------------------------------- /src/project.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {791ABC2E-5701-47FA-86CE-2DE6E3428DAB} 15 | project 16 | 17 | 18 | 19 | Application 20 | true 21 | MultiByte 22 | v110 23 | 24 | 25 | Application 26 | false 27 | true 28 | MultiByte 29 | v110 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | ..\bin32 43 | 44 | 45 | ..\bin32\tmp 46 | 47 | 48 | ..\bin32\project32D 49 | 50 | 51 | $(SolutionDir)bin32\tmp 52 | 53 | 54 | 55 | Level3 56 | Disabled 57 | ..\ext 58 | 59 | 60 | true 61 | ..\lib32 62 | glut32.lib;DevIL.lib;ILU.lib;ILUT.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 63 | ..\bin32\project32D.exe 64 | 65 | 66 | 67 | 68 | TurnOffAllWarnings 69 | MaxSpeed 70 | true 71 | true 72 | ..\ext 73 | _CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions) 74 | 75 | 76 | true 77 | true 78 | true 79 | ..\lib32 80 | glut32.lib;DevIL.lib;ILU.lib;ILUT.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 81 | ..\bin32\project32.exe 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /src/project.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {6f8fac40-4325-4561-aa61-b066f828773e} 6 | 7 | 8 | {373f9713-bf5f-4ee1-95ea-d623df52ea44} 9 | 10 | 11 | {52c4f001-2484-47af-b020-1ae6417fdaa7} 12 | 13 | 14 | {db671589-3abf-4435-80c1-bf2c90bb93a8} 15 | 16 | 17 | {cb13f5d3-c6d9-4485-ba1c-9ea61c18424a} 18 | 19 | 20 | {393ccbf4-8ddd-48c9-bb72-36d3f89277b6} 21 | 22 | 23 | 24 | 25 | Main 26 | 27 | 28 | ext 29 | 30 | 31 | util 32 | 33 | 34 | util 35 | 36 | 37 | util 38 | 39 | 40 | util 41 | 42 | 43 | util 44 | 45 | 46 | 47 | 48 | util 49 | 50 | 51 | Main 52 | 53 | 54 | util 55 | 56 | 57 | util 58 | 59 | 60 | 61 | 62 | shader\particle 63 | 64 | 65 | shader\particle 66 | 67 | 68 | shader\particle 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/project.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(SolutionDir)bin32\project32.exe 5 | WindowsLocalDebugger 6 | $(SolutionDir)bin32 7 | 8 | --------------------------------------------------------------------------------