├── README.md ├── Tesselation.sln ├── data └── textures │ ├── leaf │ ├── dn.jpg │ ├── leaf.xcf │ ├── stencil.png │ └── up.jpg │ ├── terrain │ └── up.jpg │ └── trunk │ └── up.jpg ├── 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 │ ├── CVS │ │ ├── Entries │ │ ├── Entries.Extra │ │ ├── Entries.Extra.Old │ │ ├── Entries.Old │ │ ├── Repository │ │ └── Root │ ├── _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 ├── md5 │ ├── glut.h │ ├── main.cpp │ ├── md5anim.cpp │ ├── md5load.cpp │ ├── md5load.h │ └── md5model.h └── wglew.h ├── screenshots ├── solid.png └── wire.png ├── shader ├── geo_quad │ ├── frag.txt │ ├── geo.txt │ ├── tcs.txt │ ├── tes.txt │ └── vs.txt ├── geo_quad_holes │ ├── frag.txt │ ├── geo.txt │ ├── tcs.txt │ ├── tes.txt │ └── vs.txt ├── geo_quad_simple │ ├── frag.txt │ └── vs.txt └── geo_tri │ ├── frag.txt │ ├── geo.txt │ ├── tcs.txt │ ├── tes.txt │ └── vs.txt └── src ├── Bmp.cpp ├── Bmp.h ├── Core.cpp ├── Core.h ├── Main.cpp ├── Procedural.h ├── Procedural_Leaf.h ├── Procedural_Leaf_Trunk.h ├── Procedural_Terrain.h ├── Procedural_Trunk.h ├── Procedural_bsphere.h ├── Procedural_draw.h ├── Procedural_map.h ├── Procedural_tables.h ├── Procedural_vbo.h ├── Tesselation.vcproj ├── Tesselation.vcxproj ├── Tesselation.vcxproj.filters ├── VecMath.cpp ├── VecMath.h ├── glsl.h └── opengl_FBO.h /README.md: -------------------------------------------------------------------------------- 1 | ### Procedural-Geometry-Maps 2 | 3 | #### License : MIT 4 | #### http://opensource.org/licenses/MIT 5 | 6 | The Maps are generated procedurally. They contain X,Y,Z coordinates, which are used for the visualization with the Tessellation Shader. To be able to have holes too, they can also be generated with and optional 2D marching quads method. 7 | 8 | ![Screenshot1](https://raw.githubusercontent.com/sp4cerat/Procedural-Geometry-Maps/master/screenshots/wire.png) 9 | 10 | ![Screenshot1](https://raw.githubusercontent.com/sp4cerat/Procedural-Geometry-Maps/master/screenshots/solid.png) 11 | 12 | Here the code of how the bean trunk is generated: 13 | 14 | 15 | class Trunk : public Procedural { public: 16 | 17 | Trunk(float importance,int width,int height,int res_x,int res_y,int res_z) 18 | { 19 | this->importance=importance; 20 | map_out.init(width,height); 21 | 22 | int i,j; 23 | 24 | loop(i,0,width) 25 | loop(j,0,height) 26 | { 27 | float a=float(i)/float(width-1); 28 | float b=float(j)/float(height-1); 29 | 30 | vec3f p=trunk_p_out(a,b); 31 | vec3f n=trunk_n_out(a,b); 32 | vec3f c(0,0,0); 33 | map_out.set_pixel(i,j,p,n,c); 34 | } 35 | 36 | map_out.save_vertex_map_to_bmp("../test.bmp"); 37 | 38 | Bmp test("../data/textures/trunk/up.jpg"); 39 | loopi(0,width) 40 | loopj(0,height) 41 | { 42 | map_out.color_map[(i+j*width)*4+0]=test.data[(i+j*width)*3+0]; 43 | map_out.color_map[(i+j*width)*4+1]=test.data[(i+j*width)*3+1]; 44 | map_out.color_map[(i+j*width)*4+2]=test.data[(i+j*width)*3+2]; 45 | } 46 | map_out.gen_textures(); 47 | map_out.tex_scale.y=4; 48 | map_out.tex_scale.z=8; 49 | 50 | // generate vbos 51 | //gen_geometry(res_x,res_y,res_z); 52 | gen_geometry_borderless(res_x,res_y); 53 | //gen_geometry_borderless_strip(res_x,res_y); 54 | } 55 | 56 | vec3f get_displace_xyz(float b) 57 | { 58 | vec3f d; 59 | d.x=15*sin(2*M_PI*b*2); 60 | d.y=b*300.0; 61 | d.z=15*cos(2*M_PI*b*2); 62 | return d; 63 | } 64 | 65 | float get_angle(float b) 66 | { 67 | return b*5; 68 | } 69 | 70 | float get_radius(float b) 71 | { 72 | return 0.3*(1-b*b)*15 ; 73 | } 74 | 75 | float get_liana(float a,float scale=0.1f) 76 | { 77 | a=a-float(int(a)); 78 | if(a>scale*2)return 0; 79 | float d=fabs(a-scale); 80 | return sqrt(scale*scale-d*d); 81 | } 82 | 83 | float get_liana2(float a,float scale=0.1f) 84 | { 85 | a=a-float(int(a)); 86 | if(a>scale)return 0; 87 | if(a<0)return 0; 88 | return a/scale; 89 | } 90 | 91 | float get_max(float a,float b){ return (a>b) ? a:b;} 92 | 93 | vec3f trunk_p_out(float a, float b,float scale=1.0f) 94 | { 95 | int width=map_out.width; 96 | 97 | static bool init=true; 98 | static std::vector radius; 99 | if(init) 100 | { 101 | radius.resize(width*3); 102 | 103 | int i,j,j_max=width; 104 | loop(i,0,3) 105 | { 106 | vec3f p1(1,0,0),p2(1,0,0); 107 | float a1=0+i*120; p1.rot_z(a1*2*M_PI/360.0f); 108 | float a2=(i+1)*120; p2.rot_z(a2*2*M_PI/360.0f); 109 | vec3f center=(p1+p2)*0.5; 110 | a1=-30+i*120; a1 = a1*2*M_PI/360.0f; 111 | a2=-30+i*120+180; a2 = a2*2*M_PI/360.0f; 112 | 113 | loop(j,0,j_max) 114 | { 115 | vec3f p(1,0,0); 116 | p.rot_z(a1+(a2-a1)*float(j)/float(j_max)); 117 | p=p+center; 118 | radius[i*j_max+j]=p.length()*p.length(); 119 | } 120 | } 121 | init=false; 122 | } 123 | float float_ofs=a+get_angle(b); 124 | int radius_ofs = int(float(float_ofs*float(width*3)))%(width*3); 125 | 126 | float displace=0; 127 | 128 | displace+=radius[radius_ofs]; 129 | displace+=get_liana(a+b*3,0.1)*15+ 130 | 0.1+0.2*( 131 | sin(2*3*2*M_PI*b)+ 132 | cos(2*M_PI*(a+2*b))*1.2+ 133 | cos(2*M_PI*(2*3*b+2*a))*1.2+ 134 | sin(4*M_PI*(a-6*b))*0.2+ 135 | cos(3*M_PI*(a*4))*0.2+ 136 | sin(1+32*M_PI*(2*a-b))*0.1+ 137 | cos(2+32*M_PI*(2*a+b))*0.1 138 | ); 139 | 140 | vec3f p; 141 | p.x= cos(2*M_PI*a)*displace*get_radius(b); 142 | p.z= sin(2*M_PI*a)*displace*get_radius(b); 143 | p.y= 0;// 144 | 145 | p=p+get_displace_xyz(b); 146 | 147 | return p; 148 | } 149 | vec3f trunk_n_out(float a, float b) 150 | { 151 | vec3f p =trunk_p_out(a,b); 152 | vec3f dx=trunk_p_out(a+0.02,b)-p; 153 | vec3f dy=trunk_p_out(a,b+0.02)-p; 154 | vec3f n=dx; 155 | n.cross(dx,dy); 156 | n.normalize(); 157 | 158 | return n; 159 | } 160 | }; 161 | -------------------------------------------------------------------------------- /Tesselation.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Express 2013 for Windows Desktop 3 | VisualStudioVersion = 12.0.31101.0 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tesselation", "src\Tesselation.vcxproj", "{98864040-E723-43CF-9479-6FBCDF2F6C51}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Win32 = Debug|Win32 10 | Debug|x64 = Debug|x64 11 | Release|Win32 = Release|Win32 12 | Release|x64 = Release|x64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {98864040-E723-43CF-9479-6FBCDF2F6C51}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {98864040-E723-43CF-9479-6FBCDF2F6C51}.Debug|Win32.Build.0 = Debug|Win32 17 | {98864040-E723-43CF-9479-6FBCDF2F6C51}.Debug|x64.ActiveCfg = Debug|x64 18 | {98864040-E723-43CF-9479-6FBCDF2F6C51}.Debug|x64.Build.0 = Debug|x64 19 | {98864040-E723-43CF-9479-6FBCDF2F6C51}.Release|Win32.ActiveCfg = Release|Win32 20 | {98864040-E723-43CF-9479-6FBCDF2F6C51}.Release|Win32.Build.0 = Release|Win32 21 | {98864040-E723-43CF-9479-6FBCDF2F6C51}.Release|x64.ActiveCfg = Release|x64 22 | {98864040-E723-43CF-9479-6FBCDF2F6C51}.Release|x64.Build.0 = Release|x64 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /data/textures/leaf/dn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/Procedural-Geometry-Maps/145f617fb8da9575da49f37922a0902d8b834012/data/textures/leaf/dn.jpg -------------------------------------------------------------------------------- /data/textures/leaf/leaf.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/Procedural-Geometry-Maps/145f617fb8da9575da49f37922a0902d8b834012/data/textures/leaf/leaf.xcf -------------------------------------------------------------------------------- /data/textures/leaf/stencil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/Procedural-Geometry-Maps/145f617fb8da9575da49f37922a0902d8b834012/data/textures/leaf/stencil.png -------------------------------------------------------------------------------- /data/textures/leaf/up.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/Procedural-Geometry-Maps/145f617fb8da9575da49f37922a0902d8b834012/data/textures/leaf/up.jpg -------------------------------------------------------------------------------- /data/textures/terrain/up.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/Procedural-Geometry-Maps/145f617fb8da9575da49f37922a0902d8b834012/data/textures/terrain/up.jpg -------------------------------------------------------------------------------- /data/textures/trunk/up.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/Procedural-Geometry-Maps/145f617fb8da9575da49f37922a0902d8b834012/data/textures/trunk/up.jpg -------------------------------------------------------------------------------- /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/Procedural-Geometry-Maps/145f617fb8da9575da49f37922a0902d8b834012/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/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/CVS/Entries: -------------------------------------------------------------------------------- 1 | /_matrix33.h/1.5/Mon Sep 20 17:14:36 2004// 2 | /_matrix33_sse.h/1.4/Mon Sep 20 17:14:36 2004// 3 | /_matrix44_sse.h/1.5/Mon Sep 20 17:14:36 2004// 4 | /_vector2.h/1.8/Wed Oct 13 08:25:53 2004// 5 | /_vector3.h/1.13/Mon Sep 20 17:14:36 2004// 6 | /_vector3_sse.h/1.6/Mon Sep 20 17:14:36 2004// 7 | /_vector4.h/1.11/Mon Sep 20 17:14:36 2004// 8 | /_vector4_sse.h/1.6/Mon Sep 20 17:14:36 2004// 9 | /envelopecurve.h/1.13/Mon Sep 20 17:14:36 2004// 10 | /euler.h/1.1/Thu Jan 23 14:48:29 2003// 11 | /eulerangles.h/1.4/Mon Sep 20 17:14:36 2004// 12 | /line.h/1.6/Thu Dec 2 12:32:32 2004// 13 | /matrix.h/1.4/Fri Jun 4 13:17:32 2004// 14 | /matrixdefs.h/1.1/Thu Jan 23 14:48:29 2003// 15 | /noise.h/1.2/Mon Sep 20 17:14:36 2004// 16 | /pknorm.h/1.4/Mon Sep 20 17:14:36 2004// 17 | /plane.h/1.5/Mon Sep 20 17:14:36 2004// 18 | /polar.h/1.4/Mon Sep 20 17:14:36 2004// 19 | /quaternion.h/1.4/Mon Sep 20 17:14:36 2004// 20 | /rectangle.h/1.5/Mon Sep 20 17:14:36 2004// 21 | /transform33.h/1.2/Mon Sep 20 17:14:36 2004// 22 | /triangle.h/1.4/Mon Sep 20 17:14:36 2004// 23 | /vector.h/1.3/Fri Jun 4 13:17:32 2004// 24 | /vector3envelopecurve.h/1.3/Mon Sep 20 17:14:36 2004// 25 | /transform44.h/1.5/Mon Jan 24 11:25:48 2005// 26 | /nmath.h/1.13/Mon Feb 7 10:12:23 2005// 27 | /_matrix44.h/1.11/Fri Mar 18 11:28:29 2005// 28 | /bbox.h/1.17/Fri Mar 18 11:28:29 2005// 29 | /sphere.h/1.6/Fri Mar 18 11:28:29 2005// 30 | D 31 | -------------------------------------------------------------------------------- /ext/mathlib/CVS/Entries.Extra: -------------------------------------------------------------------------------- 1 | /_matrix33.h/////// 2 | /_matrix33_sse.h/////// 3 | /_matrix44_sse.h/////// 4 | /_vector2.h/////// 5 | /_vector3.h/////// 6 | /_vector3_sse.h/////// 7 | /_vector4.h/////// 8 | /_vector4_sse.h/////// 9 | /envelopecurve.h/////// 10 | /euler.h/////// 11 | /eulerangles.h/////// 12 | /line.h/////// 13 | /matrix.h/////// 14 | /matrixdefs.h/////// 15 | /noise.h/////// 16 | /pknorm.h/////// 17 | /plane.h/////// 18 | /polar.h/////// 19 | /quaternion.h/////// 20 | /rectangle.h/////// 21 | /transform33.h/////// 22 | /triangle.h/////// 23 | /vector.h/////// 24 | /vector3envelopecurve.h/////// 25 | /transform44.h/////// 26 | /nmath.h/////// 27 | /_matrix44.h/////// 28 | /bbox.h/////// 29 | /sphere.h/////// 30 | -------------------------------------------------------------------------------- /ext/mathlib/CVS/Entries.Extra.Old: -------------------------------------------------------------------------------- 1 | /_matrix33.h//// 2 | /_matrix33_sse.h//// 3 | /_matrix44.h//// 4 | /_matrix44_sse.h//// 5 | /_vector2.h//// 6 | /_vector3.h//// 7 | /_vector3_sse.h//// 8 | /_vector4.h//// 9 | /_vector4_sse.h//// 10 | /bbox.h//// 11 | /envelopecurve.h//// 12 | /euler.h//// 13 | /eulerangles.h//// 14 | /line.h//// 15 | /matrix.h//// 16 | /matrixdefs.h//// 17 | /noise.h//// 18 | /pknorm.h//// 19 | /plane.h//// 20 | /polar.h//// 21 | /quaternion.h//// 22 | /rectangle.h//// 23 | /sphere.h//// 24 | /transform33.h//// 25 | /triangle.h//// 26 | /vector.h//// 27 | /vector3envelopecurve.h//// 28 | /transform44.h//// 29 | /nmath.h//// 30 | -------------------------------------------------------------------------------- /ext/mathlib/CVS/Entries.Old: -------------------------------------------------------------------------------- 1 | /_matrix33.h/1.5/Mon Sep 20 17:14:36 2004// 2 | /_matrix33_sse.h/1.4/Mon Sep 20 17:14:36 2004// 3 | /_matrix44.h/1.10/Mon Sep 20 17:14:36 2004// 4 | /_matrix44_sse.h/1.5/Mon Sep 20 17:14:36 2004// 5 | /_vector2.h/1.8/Wed Oct 13 08:25:53 2004// 6 | /_vector3.h/1.13/Mon Sep 20 17:14:36 2004// 7 | /_vector3_sse.h/1.6/Mon Sep 20 17:14:36 2004// 8 | /_vector4.h/1.11/Mon Sep 20 17:14:36 2004// 9 | /_vector4_sse.h/1.6/Mon Sep 20 17:14:36 2004// 10 | /bbox.h/1.16/Fri Oct 8 20:06:42 2004// 11 | /envelopecurve.h/1.13/Mon Sep 20 17:14:36 2004// 12 | /euler.h/1.1/Thu Jan 23 14:48:29 2003// 13 | /eulerangles.h/1.4/Mon Sep 20 17:14:36 2004// 14 | /line.h/1.6/Thu Dec 2 12:32:32 2004// 15 | /matrix.h/1.4/Fri Jun 4 13:17:32 2004// 16 | /matrixdefs.h/1.1/Thu Jan 23 14:48:29 2003// 17 | /noise.h/1.2/Mon Sep 20 17:14:36 2004// 18 | /pknorm.h/1.4/Mon Sep 20 17:14:36 2004// 19 | /plane.h/1.5/Mon Sep 20 17:14:36 2004// 20 | /polar.h/1.4/Mon Sep 20 17:14:36 2004// 21 | /quaternion.h/1.4/Mon Sep 20 17:14:36 2004// 22 | /rectangle.h/1.5/Mon Sep 20 17:14:36 2004// 23 | /sphere.h/1.5/Mon Sep 20 17:14:36 2004// 24 | /transform33.h/1.2/Mon Sep 20 17:14:36 2004// 25 | /triangle.h/1.4/Mon Sep 20 17:14:36 2004// 26 | /vector.h/1.3/Fri Jun 4 13:17:32 2004// 27 | /vector3envelopecurve.h/1.3/Mon Sep 20 17:14:36 2004// 28 | /transform44.h/1.5/Mon Jan 24 11:25:48 2005// 29 | /nmath.h/1.13/Mon Feb 7 10:12:23 2005// 30 | D 31 | -------------------------------------------------------------------------------- /ext/mathlib/CVS/Repository: -------------------------------------------------------------------------------- 1 | radonlabs/code/nebula2/inc/mathlib 2 | -------------------------------------------------------------------------------- /ext/mathlib/CVS/Root: -------------------------------------------------------------------------------- 1 | :pserver:sven3@192.168.0.90:/mnt/hdc/cvsroot 2 | -------------------------------------------------------------------------------- /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/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/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/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/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 | -------------------------------------------------------------------------------- /ext/md5/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "GLEW/glew.h" 5 | #include "glut.h" 6 | 7 | typedef float vec3_t[3]; 8 | 9 | #include "md5load.h" 10 | 11 | //function declares 12 | void keyboard (unsigned char key, int x, int y); 13 | void reshape (int w, int h); 14 | void cleanup(); 15 | void display(); 16 | 17 | using namespace std; 18 | 19 | //md5load *md5object = new md5load(); 20 | md5load md5object; 21 | md5load md5object1; 22 | md5load md5object2; 23 | 24 | 25 | int main() 26 | { 27 | glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); 28 | glutInitWindowSize (640, 480); 29 | glutCreateWindow ("MD5 Model"); 30 | 31 | glEnable(GL_TEXTURE_2D); 32 | glShadeModel(GL_SMOOTH); 33 | glClearColor(0.0f,0.0f,0.0f,0.5f); 34 | glClearDepth(1.0f); 35 | glEnable(GL_DEPTH_TEST); 36 | glDepthFunc(GL_LEQUAL); 37 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 38 | 39 | cout << "Texture loaded correctly" << endl; 40 | 41 | //load a model 42 | md5object.init ("../Assets/Models/pinky.md5mesh" , "../Assets/Animations/idle1.md5anim", "../Assets/Textures/pinky_d.tga"); 43 | 44 | atexit(cleanup); 45 | 46 | glutReshapeFunc (reshape); 47 | glutDisplayFunc (display); 48 | glutKeyboardFunc (keyboard); 49 | 50 | glutMainLoop (); 51 | 52 | return 0; 53 | } 54 | 55 | void cleanup () 56 | { 57 | md5object.cleanup(); 58 | md5object1.cleanup(); 59 | md5object2.cleanup(); 60 | } 61 | 62 | void display() 63 | { 64 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 65 | 66 | //enable client states for glDrawElements 67 | glEnableClientState (GL_VERTEX_ARRAY); 68 | glEnableClientState (GL_TEXTURE_COORD_ARRAY); 69 | 70 | md5object.enableTextured(true); 71 | md5object.enableSkeleton(false); 72 | md5object.draw(0.0, -35.0, -150.0, 1.0); 73 | 74 | glDisableClientState (GL_TEXTURE_COORD_ARRAY); 75 | glDisableClientState (GL_VERTEX_ARRAY); 76 | 77 | glutSwapBuffers (); 78 | glutPostRedisplay (); 79 | } 80 | 81 | 82 | /** 83 | * Check if an animation can be used for a given model. Model's 84 | * skeleton and animation's skeleton must match. 85 | */ 86 | int 87 | CheckAnimValidity (const struct md5_model_t *mdl, 88 | const struct md5_anim_t *anim) 89 | { 90 | int i; 91 | 92 | /* md5mesh and md5anim must have the same number of joints */ 93 | if (mdl->num_joints != anim->num_joints) 94 | return 0; 95 | 96 | /* We just check with frame[0] */ 97 | for (i = 0; i < mdl->num_joints; ++i) 98 | { 99 | /* Joints must have the same parent index */ 100 | if (mdl->baseSkel[i].parent != anim->skelFrames[0][i].parent) 101 | return 0; 102 | 103 | /* Joints must have the same name */ 104 | if (strcmp (mdl->baseSkel[i].name, anim->skelFrames[0][i].name) != 0) 105 | return 0; 106 | } 107 | 108 | return 1; 109 | } 110 | 111 | void reshape (int w, int h) 112 | { 113 | if (h == 0) 114 | h = 1; 115 | 116 | glViewport (0, 0, (GLsizei)w, (GLsizei)h); 117 | 118 | glMatrixMode (GL_PROJECTION); 119 | glLoadIdentity (); 120 | gluPerspective (45.0, w/(GLdouble)h, 0.1, 1000.0); 121 | 122 | glMatrixMode (GL_MODELVIEW); 123 | glLoadIdentity (); 124 | } 125 | 126 | void keyboard (unsigned char key, int x, int y) 127 | { 128 | /* Escape */ 129 | if (key == 27) 130 | exit (0); 131 | } -------------------------------------------------------------------------------- /ext/md5/md5load.h: -------------------------------------------------------------------------------- 1 | #ifndef MD5LOAD 2 | #define MD5LOAD 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "glew.h" 11 | #include "glut.h" 12 | 13 | //texture loading 14 | #include "IL/il.h" 15 | #include "IL/ilu.h" 16 | #include "IL/ilut.h" 17 | #pragma comment(lib, "DevIL.lib") 18 | #pragma comment(lib, "ILU.lib") 19 | #pragma comment(lib, "ILUT.lib") 20 | 21 | /* Vectors */ 22 | typedef float vec2_t[2]; 23 | typedef float vec3_t[3]; 24 | typedef float vec5_t[5]; 25 | 26 | /* Quaternion (x, y, z, w) */ 27 | typedef float quat4_t[4]; 28 | enum { 29 | X, Y, Z, W 30 | }; 31 | 32 | /* Joint */ 33 | struct md5_joint_t 34 | { 35 | char name[64]; 36 | int parent; 37 | 38 | vec3_t pos; 39 | quat4_t orient; 40 | }; 41 | 42 | /* Vertex */ 43 | struct md5_vertex_t 44 | { 45 | vec2_t st; 46 | 47 | int start; /* start weight */ 48 | int count; /* weight count */ 49 | }; 50 | 51 | /* Triangle */ 52 | struct md5_triangle_t 53 | { 54 | int index[3]; 55 | }; 56 | 57 | /* Weight */ 58 | struct md5_weight_t 59 | { 60 | int joint; 61 | float bias; 62 | 63 | vec3_t pos; 64 | }; 65 | 66 | /* Bounding box */ 67 | struct md5_bbox_t 68 | { 69 | vec3_t min; 70 | vec3_t max; 71 | }; 72 | 73 | /* MD5 mesh */ 74 | struct md5_mesh_t 75 | { 76 | struct md5_vertex_t *vertices; 77 | struct md5_triangle_t *triangles; 78 | struct md5_weight_t *weights; 79 | 80 | int num_verts; 81 | int num_tris; 82 | int num_weights; 83 | 84 | char shader[256]; 85 | }; 86 | 87 | /* MD5 model structure */ 88 | struct md5_model_t 89 | { 90 | struct md5_joint_t *baseSkel; 91 | struct md5_mesh_t *meshes; 92 | 93 | int num_joints; 94 | int num_meshes; 95 | }; 96 | 97 | /* Animation data */ 98 | struct md5_anim_t 99 | { 100 | int num_frames; 101 | int num_joints; 102 | int frameRate; 103 | 104 | struct md5_joint_t **skelFrames; 105 | struct md5_bbox_t *bboxes; 106 | }; 107 | 108 | /* Animation info */ 109 | const struct anim_info_t 110 | { 111 | int curr_frame; 112 | int next_frame; 113 | 114 | double last_time; 115 | double max_time; 116 | }; 117 | 118 | /* Joint info */ 119 | struct joint_info_t 120 | { 121 | char name[64]; 122 | int parent; 123 | int flags; 124 | int startIndex; 125 | }; 126 | 127 | 128 | /* Base frame joint */ 129 | const struct baseframe_joint_t 130 | { 131 | vec3_t pos; 132 | quat4_t orient; 133 | }; 134 | 135 | 136 | 137 | using namespace std; 138 | 139 | class md5load 140 | { 141 | 142 | 143 | 144 | 145 | public: 146 | md5load(void); //constructor 147 | ~md5load(void); //destructor 148 | void Run(ifstream &theCardFile); 149 | 150 | void draw(float x, float y, float z, float scale); 151 | void init (const char *filename, const char *animfile, char *texturefile); 152 | 153 | void enableSkeleton(bool skeleton); 154 | void enableTextured(bool textured); 155 | void enableRotate(bool rotated); 156 | void cleanup(); 157 | 158 | float getSkeletonPosition(int joint, int xyz); 159 | 160 | 161 | private: 162 | //function definitions 163 | void AllocVertexArrays (); 164 | void FreeAnim (struct md5_anim_t *anim); 165 | int ReadMD5Model (const char *filename, struct md5_model_t *mdl); 166 | int ReadMD5Anim (const char *filename, struct md5_anim_t *anim); 167 | //used to be static 168 | void BuildFrameSkeleton (const struct joint_info_t *jointInfos, const baseframe_joint_t *baseFrame, const float *animFrameData, struct md5_joint_t *skelFrame, int num_joints); 169 | void InterpolateSkeletons (const struct md5_joint_t *skelA, const struct md5_joint_t *skelB, int num_joints, float interp, struct md5_joint_t *out); 170 | void PrepareMesh (const struct md5_mesh_t *mesh, const struct md5_joint_t *skeleton); 171 | void Animate (const struct md5_anim_t *anim, struct anim_info_t *animInfo, double dt); 172 | void DrawSkeleton (const struct md5_joint_t *skeleton, int num_joints); 173 | void FreeVertexArrays (); 174 | void FreeModel (struct md5_model_t *mdl); 175 | 176 | //quaternion functions 177 | void Quat_computeW (quat4_t q); 178 | void Quat_rotatePoint (const quat4_t q, const vec3_t in, vec3_t out); 179 | void Quat_multQuat (const quat4_t qa, const quat4_t qb, quat4_t out); 180 | void Quat_normalize (quat4_t q); 181 | void Quat_multVec (const quat4_t q, const vec3_t v, quat4_t out); 182 | void Quat_slerp (const quat4_t qa, const quat4_t qb, float t, quat4_t out); 183 | float Quat_dotProduct (const quat4_t qa, const quat4_t qb); 184 | 185 | //texture model loading 186 | GLuint loadTexture(char *fileName); 187 | GLuint modeltexture; 188 | 189 | //variable definitions 190 | struct md5_model_t md5file; 191 | struct md5_anim_t md5anim; 192 | 193 | int animated;// = 0; 194 | 195 | struct md5_joint_t *skeleton;// = NULL; 196 | struct anim_info_t animInfo; 197 | 198 | /* vertex array related stuff */ 199 | int max_verts;// = 0; 200 | int max_tris;// = 0; 201 | 202 | vec5_t *vertexArray;// = NULL; 203 | GLuint *vertexIndices;// = NULL; 204 | 205 | bool drawTexture; 206 | bool drawSkeleton; 207 | bool rotate; 208 | 209 | 210 | 211 | 212 | }; 213 | #endif -------------------------------------------------------------------------------- /ext/md5/md5model.h: -------------------------------------------------------------------------------- 1 | /* 2 | * md5model.h -- md5mesh model loader + animation 3 | * last modification: aug. 14, 2007 4 | * 5 | * Copyright (c) 2005-2007 David HENRY 6 | * 7 | * Permission is hereby granted, free of charge, to any person 8 | * obtaining a copy of this software and associated documentation 9 | * files (the "Software"), to deal in the Software without 10 | * restriction, including without limitation the rights to use, 11 | * copy, modify, merge, publish, distribute, sublicense, and/or 12 | * sell copies of the Software, and to permit persons to whom the 13 | * Software is furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. 22 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 23 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 24 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | * 27 | * gcc -Wall -ansi -lGL -lGLU -lglut md5anim.c md5anim.c -o md5model 28 | */ 29 | 30 | #ifndef __MD5MODEL_H__ 31 | #define __MD5MODEL_H__ 32 | 33 | #include "md5load.h" 34 | 35 | 36 | 37 | /** 38 | * Quaternion prototypes 39 | */ 40 | void Quat_computeW (quat4_t q); 41 | void Quat_normalize (quat4_t q); 42 | void Quat_multQuat (const quat4_t qa, const quat4_t qb, quat4_t out); 43 | void Quat_multVec (const quat4_t q, const vec3_t v, quat4_t out); 44 | void Quat_rotatePoint (const quat4_t q, const vec3_t in, vec3_t out); 45 | float Quat_dotProduct (const quat4_t qa, const quat4_t qb); 46 | void Quat_slerp (const quat4_t qa, const quat4_t qb, float t, quat4_t out); 47 | 48 | 49 | /** 50 | * md5mesh prototypes 51 | */ 52 | int ReadMD5Model (const char *filename, struct md5_model_t *mdl); 53 | void PrepareMesh (const struct md5_mesh_t *mesh,const struct md5_joint_t *skeleton); 54 | void AllocVertexArrays (); 55 | void FreeVertexArrays (); 56 | void DrawSkeleton (const struct md5_joint_t *skeleton, int num_joints); 57 | 58 | //textures 59 | //GLuint loadTexture(char *fileName); 60 | 61 | /** 62 | * md5anim prototypes 63 | */ 64 | int CheckAnimValidity (const struct md5_model_t *mdl, 65 | const struct md5_anim_t *anim); 66 | int ReadMD5Anim (const char *filename, struct md5_anim_t *anim); 67 | void FreeAnim (struct md5_anim_t *anim); 68 | void InterpolateSkeletons (const struct md5_joint_t *skelA, 69 | const struct md5_joint_t *skelB, 70 | int num_joints, float interp, 71 | struct md5_joint_t *out); 72 | void Animate (const struct md5_anim_t *anim, 73 | struct anim_info_t *animInfo, double dt); 74 | 75 | 76 | 77 | 78 | #endif /* __MD5MODEL_H__ */ 79 | 80 | -------------------------------------------------------------------------------- /screenshots/solid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/Procedural-Geometry-Maps/145f617fb8da9575da49f37922a0902d8b834012/screenshots/solid.png -------------------------------------------------------------------------------- /screenshots/wire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sp4cerat/Procedural-Geometry-Maps/145f617fb8da9575da49f37922a0902d8b834012/screenshots/wire.png -------------------------------------------------------------------------------- /shader/geo_quad/frag.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(location = 0, index = 0) out vec4 fragColor; 4 | 5 | uniform sampler2D normalmap; 6 | uniform sampler2D colormap; 7 | uniform vec3 tex_scale; 8 | in vec2 tex_uv; 9 | 10 | vec4 bspline_3d_fp( sampler2D texin, vec2 vecin) 11 | { 12 | vec2 tsize = vec2(512.0,512.0); 13 | vec2 one_tsize = vec2(1.0/tsize.x,1.0/tsize.y); 14 | vec2 coord_grid = vecin*tsize - vec2(0.5,0.5); 15 | vec2 fraction = fract(coord_grid); 16 | vec2 one_frac = 1.0 - fraction; 17 | vec2 one_frac2 = one_frac * one_frac; 18 | vec2 fraction2 = fraction * fraction; 19 | vec2 w0 = 1.0/6.0 * one_frac2 * one_frac; 20 | vec2 w1 = 2.0/3.0 - 0.5 * fraction2 * (2.0-fraction); 21 | vec2 w2 = 2.0/3.0 - 0.5 * one_frac2 * (2.0-one_frac); 22 | vec2 w3 = 1.0/6.0 * fraction2 * fraction; 23 | vec2 g0 = w0 + w1; 24 | vec2 g1 = w2 + w3; 25 | vec2 index = coord_grid-fraction; 26 | vec2 h0 = ((w1 / g0) - 0.5 + index)*one_tsize; 27 | vec2 h1 = ((w3 / g1) + 1.5 + index)*one_tsize; 28 | 29 | // fetch the four linear interpolations 30 | vec4 tex000 = texture2D(texin, vec2(h0.x, h0.y)); 31 | vec4 tex001 = texture2D(texin, vec2(h0.x, h1.y)); 32 | tex000 = mix(tex001, tex000, g0.y); 33 | vec4 tex010 = texture2D(texin, vec2(h1.x, h0.y)); 34 | vec4 tex011 = texture2D(texin, vec2(h1.x, h1.y)); 35 | tex010 = mix(tex011, tex010, g0.y); 36 | 37 | tex000 = mix(tex010, tex000, g0.x); 38 | 39 | return tex000; 40 | } 41 | 42 | void main(void) 43 | { 44 | vec4 c1=texture2D(colormap,tex_uv.xy*tex_scale.xy); 45 | vec4 c2=texture2D(colormap,tex_uv.xy*tex_scale.xy*tex_scale.z); 46 | vec4 c=(c1+c2)*0.5; 47 | 48 | if(c1.w<=0.1) discard; 49 | 50 | vec4 n= texture2D(normalmap,tex_uv.xy); 51 | 52 | fragColor = c*((-n.x-2*n.y+1)*0.3+0.2);//vec4(1.0, 0.0, 0.0, 1.0); 53 | } 54 | //vec4 c= bspline_3d_fp(colormap,tex_uv.xy); 55 | -------------------------------------------------------------------------------- /shader/geo_quad/geo.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(triangles, invocations = 1) in; 4 | //layout(line_strip, max_vertices = 4) out; 5 | layout(triangle_strip, max_vertices = 4) out; 6 | 7 | in vec2 tex_uv_tes[]; 8 | out vec2 tex_uv; 9 | 10 | void main(void) 11 | { 12 | for(int i = 0; i < gl_in.length(); ++i) 13 | { 14 | tex_uv = tex_uv_tes[i]; 15 | gl_Position = gl_in[i].gl_Position; 16 | EmitVertex(); 17 | } 18 | //tex_uv = tex_uv_tes[0]; 19 | //gl_Position = gl_in[0].gl_Position; 20 | //EmitVertex(); 21 | 22 | EndPrimitive(); 23 | } 24 | -------------------------------------------------------------------------------- /shader/geo_quad/tcs.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(vertices = 4) out; 4 | 5 | uniform sampler2D geomap; 6 | uniform mat4 mvp_matrix; 7 | uniform float cull_invert; 8 | uniform float importance; 9 | 10 | 11 | vec4 project(vec4 vertex) 12 | { 13 | vec4 pos=texture2D(geomap,vertex.xy); 14 | vec4 result = mvp_matrix*pos; 15 | return result; 16 | } 17 | 18 | float level(float w)//float d) 19 | { 20 | //return clamp(importance * 0.5 * pow(w,0.75)*4*8.0, 1, 32); 21 | return clamp(pow(w,0.5)*importance*4*8.0, 1, 32); 22 | //return clamp(w*8*8.0, 1, 8); 23 | //return clamp((50.0-w)*8.0/50.0, 1, 8); 24 | } 25 | 26 | void main(void) 27 | { 28 | gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; 29 | /* 30 | { 31 | gl_TessLevelInner[0] = 1; 32 | gl_TessLevelInner[1] = 1; 33 | gl_TessLevelOuter[0] = 1; 34 | gl_TessLevelOuter[1] = 1; 35 | gl_TessLevelOuter[2] = 1; 36 | gl_TessLevelOuter[3] = 1; 37 | } 38 | */ 39 | 40 | 41 | 42 | 43 | 44 | if(gl_InvocationID == 0) 45 | { 46 | vec4 v0 = project(gl_in[0].gl_Position); 47 | vec4 v1 = project(gl_in[1].gl_Position); 48 | vec4 v2 = project(gl_in[2].gl_Position); 49 | vec4 v3 = project(gl_in[3].gl_Position); 50 | 51 | bool cull=false; 52 | 53 | 54 | v0.xyz/=v0.w; 55 | v1.xyz/=v1.w; 56 | v2.xyz/=v2.w; 57 | v3.xyz/=v3.w; 58 | 59 | //if (v0.w < 0.0) cull=true; 60 | 61 | if ( max(v0.w,max(v1.w,max(v2.w,v3.w))) < -0.3 ) cull=true; 62 | 63 | //if ( min(v0.z,min(v1.z,min(v2.z,v3.z))) > 1.0 ) cull=true; 64 | 65 | bool all_in_front = ( max(v0.z,max(v1.z,max(v2.z,v3.z))) < 1.0 ); 66 | if (all_in_front) 67 | { 68 | if ( max(v0.x,max(v1.x,max(v2.x,v3.x))) < -1.4 ) cull=true; 69 | if ( max(v0.y,max(v1.y,max(v2.y,v3.y))) < -1.4 ) cull=true; 70 | if ( min(v0.x,min(v1.x,min(v2.x,v3.x))) > 1.4 ) cull=true; 71 | if ( min(v0.y,min(v1.y,min(v2.y,v3.y))) > 1.4 ) cull=true; 72 | } 73 | 74 | if(cull) 75 | { 76 | gl_TessLevelInner[0] = 1; 77 | gl_TessLevelInner[1] = 1; 78 | gl_TessLevelOuter[0] = 1; 79 | gl_TessLevelOuter[1] = 1; 80 | gl_TessLevelOuter[2] = 1; 81 | gl_TessLevelOuter[3] = 1; 82 | } 83 | else 84 | { 85 | float detail0 = level(length(v1.xy-v0.xy)); 86 | float detail1 = level(length(v2.xy-v3.xy)); 87 | float detail2 = level(length(v2.xy-v1.xy)); 88 | float detail3 = level(length(v3.xy-v0.xy)); 89 | float detail01= (detail0+detail1)*0.5; 90 | float detail12= (detail2+detail3)*0.5; 91 | gl_TessLevelInner[0] = detail01; 92 | gl_TessLevelInner[1] = detail12; 93 | gl_TessLevelOuter[0] = detail3; 94 | gl_TessLevelOuter[1] = detail0; 95 | gl_TessLevelOuter[2] = detail2; 96 | gl_TessLevelOuter[3] = detail1; 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /shader/geo_quad/tes.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | uniform sampler2D geomap; 4 | uniform mat4 mvp_matrix; 5 | 6 | layout(quads, equal_spacing, ccw) in; 7 | 8 | out vec2 tex_uv_tes; 9 | 10 | //quad interpol 11 | vec4 interpolate(in vec4 v0, in vec4 v1, in vec4 v2, in vec4 v3) 12 | { 13 | vec4 a = mix(v0, v1, gl_TessCoord.x); 14 | vec4 b = mix(v3, v2, gl_TessCoord.x); 15 | return mix(a, b, gl_TessCoord.y); 16 | } 17 | 18 | void main() 19 | { 20 | vec4 p = interpolate( 21 | gl_in[0].gl_Position, 22 | gl_in[1].gl_Position, 23 | gl_in[2].gl_Position, 24 | gl_in[3].gl_Position); 25 | 26 | p.z=1; 27 | p.w=1; 28 | 29 | tex_uv_tes=p.xy; 30 | 31 | gl_Position=mvp_matrix*texture2D(geomap,p.xy); 32 | /* 33 | 34 | vec2 uv = gl_in[0].gl_Position.xy * gl_TessCoord.x + 35 | gl_in[1].gl_Position.xy * gl_TessCoord.y + 36 | gl_in[2].gl_Position.xy * gl_TessCoord.z; 37 | 38 | tex_uv_tes = uv; 39 | vec4 pos=texture2D(geomap,uv); 40 | gl_Position.xyzw = mvp_matrix*pos; 41 | */ 42 | /* 43 | 44 | gl_Position.xyzw = gl_in[0].gl_Position.xyzw * gl_TessCoord.x + 45 | gl_in[1].gl_Position.xyzw * gl_TessCoord.y + 46 | gl_in[2].gl_Position.xyzw * gl_TessCoord.z; 47 | */ 48 | } 49 | -------------------------------------------------------------------------------- /shader/geo_quad/vs.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | in vec4 vertex; 4 | 5 | void main(void) 6 | { 7 | gl_Position = vertex; 8 | } 9 | -------------------------------------------------------------------------------- /shader/geo_quad_holes/frag.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(location = 0, index = 0) out vec4 fragColor; 4 | 5 | uniform sampler2D normalmap_out; 6 | uniform sampler2D colormap_out; 7 | uniform vec3 tex_scale; 8 | in vec3 tex_uv; 9 | 10 | void main(void) 11 | { 12 | vec4 c= texture2D(normalmap_out,tex_uv.xy)*0.2+ 13 | texture2D(colormap_out,tex_uv.xy*tex_scale.xy)*0.8; 14 | if(c.w<=0.1) discard; 15 | 16 | fragColor = c*0.99+0.01;//vec4(1.0, 0.0, 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /shader/geo_quad_holes/geo.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(triangles, invocations = 1) in; 4 | //layout(line_strip, max_vertices = 4) out; 5 | layout(triangle_strip, max_vertices = 4) out; 6 | 7 | in vec3 tex_uv_tes[]; 8 | out vec3 tex_uv; 9 | 10 | void main(void) 11 | { 12 | for(int i = 0; i < gl_in.length(); ++i) 13 | { 14 | tex_uv = tex_uv_tes[i]; 15 | gl_Position = gl_in[i].gl_Position; 16 | EmitVertex(); 17 | } 18 | // tex_uv = tex_uv_tes[0]; 19 | // gl_Position = gl_in[0].gl_Position; 20 | // EmitVertex(); 21 | 22 | EndPrimitive(); 23 | } 24 | -------------------------------------------------------------------------------- /shader/geo_quad_holes/tcs.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(vertices = 4) out; 4 | 5 | uniform sampler2D geomap_in; 6 | uniform sampler2D geomap_out; 7 | uniform mat4 mvp_matrix; 8 | uniform float cull_invert; 9 | uniform float importance; 10 | 11 | vec4 project(vec4 vertex) 12 | { 13 | vec4 result_in = mvp_matrix*texture2D(geomap_in,vertex.xy); 14 | vec4 result_out = mvp_matrix*texture2D(geomap_out,vertex.xy); 15 | vec4 result=mix(result_out,result_in,vertex.z); 16 | result.xyz /= result.w; 17 | return result; 18 | } 19 | 20 | bool offscreen(vec4 vertex){ 21 | if(vertex.w < -0.1){ 22 | return true; 23 | } 24 | 25 | return any( 26 | lessThan(vertex.xy, vec2(-1.1)) || 27 | greaterThan(vertex.xy, vec2(1.1)) 28 | ); 29 | } 30 | 31 | float level(float w)//float d) 32 | { 33 | return clamp(pow(w,0.5)*importance*4*8.0, 1, 32); 34 | // return clamp(importance * 0.5 * pow(w,0.75)*4*8.0, 1, 32); 35 | //return clamp(pow(w,importance)*4*8.0, 1, 32); 36 | //return clamp(w*8*8.0, 1, 8); 37 | //return clamp((50.0-w)*8.0/50.0, 1, 8); 38 | } 39 | 40 | void main(void) 41 | { 42 | gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; 43 | 44 | /* 45 | gl_TessLevelOuter[0] = 1.0; 46 | gl_TessLevelOuter[1] = 8.0; 47 | gl_TessLevelOuter[2] = 1.0; 48 | gl_TessLevelOuter[3] = 8.0; 49 | 50 | gl_TessLevelInner[0] = 8.0; 51 | gl_TessLevelInner[1] = 1.0; 52 | */ 53 | if(gl_InvocationID == 0) 54 | { 55 | vec4 v0 = project(gl_in[0].gl_Position); 56 | vec4 v1 = project(gl_in[1].gl_Position); 57 | vec4 v2 = project(gl_in[2].gl_Position); 58 | vec4 v3 = project(gl_in[3].gl_Position); 59 | 60 | //vec4 d0 = v1-v0; 61 | //vec4 d1 = v2-v3; 62 | 63 | //vec3 n=normalize(cross(d0.xyw,d1.xyw)); 64 | 65 | //float culling = n.z*cull_invert;//d0.x*d1.y-d1.x*d0.y; 66 | 67 | if( //(culling > 0.25) || 68 | all(bvec4( offscreen(v0), 69 | offscreen(v1), 70 | offscreen(v2), 71 | offscreen(v3) 72 | ))){ 73 | gl_TessLevelInner[0] = 1; 74 | gl_TessLevelOuter[0] = 1; 75 | gl_TessLevelOuter[1] = 1; 76 | gl_TessLevelOuter[2] = 1; 77 | } 78 | else{ 79 | float detail0 = level(length(v1.xy-v0.xy)); 80 | float detail1 = level(length(v2.xy-v3.xy)); 81 | // float detail0 = level((v1.w+v2.w)*0.5); 82 | // float detail1 = level((v2.w+v0.w)*0.5); 83 | // float detail2 = level((v1.w+v0.w)*0.5); 84 | float detail = (detail0+detail1)*0.5; 85 | gl_TessLevelInner[0] = detail; 86 | gl_TessLevelInner[1] = 1; 87 | gl_TessLevelOuter[0] = 1; 88 | gl_TessLevelOuter[1] = detail0; 89 | gl_TessLevelOuter[2] = 1; 90 | gl_TessLevelOuter[3] = detail1; 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /shader/geo_quad_holes/tes.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(quads, equal_spacing, ccw) in; 4 | 5 | uniform sampler2D geomap_in; 6 | uniform sampler2D geomap_out; 7 | uniform mat4 mvp_matrix; 8 | out vec3 tex_uv_tes; 9 | 10 | //quad interpol 11 | vec4 interpolate(in vec4 v0, in vec4 v1, in vec4 v2, in vec4 v3) 12 | { 13 | vec4 a = mix(v0, v1, gl_TessCoord.x); 14 | vec4 b = mix(v3, v2, gl_TessCoord.x); 15 | return mix(a, b, gl_TessCoord.y); 16 | } 17 | 18 | void main() 19 | { 20 | vec4 p = interpolate( 21 | gl_in[0].gl_Position, 22 | gl_in[1].gl_Position, 23 | gl_in[2].gl_Position, 24 | gl_in[3].gl_Position); 25 | 26 | p.w=1; 27 | 28 | tex_uv_tes=p.xyz; 29 | 30 | vec4 result_in = texture2D(geomap_in,p.xy); 31 | vec4 result_out = texture2D(geomap_out,p.xy); 32 | gl_Position=mvp_matrix*mix(result_out,result_in,p.z); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /shader/geo_quad_holes/vs.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | //uniform mat4 projectionMatrix; 4 | //uniform mat4 modelViewMatrix; 5 | 6 | in vec4 vertex; 7 | 8 | void main(void) 9 | { 10 | gl_Position = vertex;//projectionMatrix*modelViewMatrix*vertex; 11 | } 12 | -------------------------------------------------------------------------------- /shader/geo_quad_simple/frag.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(location = 0, index = 0) out vec4 fragColor; 4 | 5 | uniform sampler2D normalmap; 6 | uniform sampler2D colormap; 7 | uniform vec3 tex_scale; 8 | in vec2 tex_uv; 9 | 10 | vec4 bspline_3d_fp( sampler2D texin, vec2 vecin) 11 | { 12 | vec2 tsize = vec2(512.0,512.0); 13 | vec2 one_tsize = vec2(1.0/tsize.x,1.0/tsize.y); 14 | vec2 coord_grid = vecin*tsize - vec2(0.5,0.5); 15 | vec2 fraction = fract(coord_grid); 16 | vec2 one_frac = 1.0 - fraction; 17 | vec2 one_frac2 = one_frac * one_frac; 18 | vec2 fraction2 = fraction * fraction; 19 | vec2 w0 = 1.0/6.0 * one_frac2 * one_frac; 20 | vec2 w1 = 2.0/3.0 - 0.5 * fraction2 * (2.0-fraction); 21 | vec2 w2 = 2.0/3.0 - 0.5 * one_frac2 * (2.0-one_frac); 22 | vec2 w3 = 1.0/6.0 * fraction2 * fraction; 23 | vec2 g0 = w0 + w1; 24 | vec2 g1 = w2 + w3; 25 | vec2 index = coord_grid-fraction; 26 | vec2 h0 = ((w1 / g0) - 0.5 + index)*one_tsize; 27 | vec2 h1 = ((w3 / g1) + 1.5 + index)*one_tsize; 28 | 29 | // fetch the four linear interpolations 30 | vec4 tex000 = texture2D(texin, vec2(h0.x, h0.y)); 31 | vec4 tex001 = texture2D(texin, vec2(h0.x, h1.y)); 32 | tex000 = mix(tex001, tex000, g0.y); 33 | vec4 tex010 = texture2D(texin, vec2(h1.x, h0.y)); 34 | vec4 tex011 = texture2D(texin, vec2(h1.x, h1.y)); 35 | tex010 = mix(tex011, tex010, g0.y); 36 | 37 | tex000 = mix(tex010, tex000, g0.x); 38 | 39 | return tex000; 40 | } 41 | 42 | void main(void) 43 | { 44 | vec4 c= texture2D(colormap,tex_uv.xy*tex_scale.xy); 45 | //vec4 c= bspline_3d_fp(colormap,tex_uv.xy); 46 | 47 | if(c.w<=0.1) discard; 48 | 49 | vec4 n= texture2D(normalmap,tex_uv.xy); 50 | 51 | fragColor = c*((-n.z-n.y+1)*0.2+0.5)*0.5;//vec4(1.0, 0.0, 0.0, 1.0); 52 | } -------------------------------------------------------------------------------- /shader/geo_quad_simple/vs.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | uniform sampler2D geomap; 4 | uniform mat4 mvp_matrix; 5 | 6 | in vec4 vertex; 7 | out vec2 tex_uv; 8 | 9 | void main(void) 10 | { 11 | tex_uv = vertex.xy; 12 | gl_Position = mvp_matrix*texture2D(geomap,vertex.xy); 13 | } 14 | -------------------------------------------------------------------------------- /shader/geo_tri/frag.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(location = 0, index = 0) out vec4 fragColor; 4 | 5 | uniform sampler2D normalmap; 6 | uniform sampler2D colormap; 7 | uniform vec3 tex_scale; 8 | in vec2 tex_uv; 9 | 10 | vec4 bspline_3d_fp( sampler2D texin, vec2 vecin) 11 | { 12 | vec2 tsize = vec2(512.0,512.0); 13 | vec2 one_tsize = vec2(1.0/tsize.x,1.0/tsize.y); 14 | vec2 coord_grid = vecin*tsize - vec2(0.5,0.5); 15 | vec2 fraction = fract(coord_grid); 16 | vec2 one_frac = 1.0 - fraction; 17 | vec2 one_frac2 = one_frac * one_frac; 18 | vec2 fraction2 = fraction * fraction; 19 | vec2 w0 = 1.0/6.0 * one_frac2 * one_frac; 20 | vec2 w1 = 2.0/3.0 - 0.5 * fraction2 * (2.0-fraction); 21 | vec2 w2 = 2.0/3.0 - 0.5 * one_frac2 * (2.0-one_frac); 22 | vec2 w3 = 1.0/6.0 * fraction2 * fraction; 23 | vec2 g0 = w0 + w1; 24 | vec2 g1 = w2 + w3; 25 | vec2 index = coord_grid-fraction; 26 | vec2 h0 = ((w1 / g0) - 0.5 + index)*one_tsize; 27 | vec2 h1 = ((w3 / g1) + 1.5 + index)*one_tsize; 28 | 29 | // fetch the four linear interpolations 30 | vec4 tex000 = texture2D(texin, vec2(h0.x, h0.y)); 31 | vec4 tex001 = texture2D(texin, vec2(h0.x, h1.y)); 32 | tex000 = mix(tex001, tex000, g0.y); 33 | vec4 tex010 = texture2D(texin, vec2(h1.x, h0.y)); 34 | vec4 tex011 = texture2D(texin, vec2(h1.x, h1.y)); 35 | tex010 = mix(tex011, tex010, g0.y); 36 | 37 | tex000 = mix(tex010, tex000, g0.x); 38 | 39 | return tex000; 40 | } 41 | 42 | void main(void) 43 | { 44 | vec4 c= texture2D(colormap,tex_uv.xy*tex_scale.xy); 45 | //vec4 c= bspline_3d_fp(colormap,tex_uv.xy); 46 | 47 | if(c.w<=0.1) discard; 48 | 49 | vec4 n= texture2D(normalmap,tex_uv.xy); 50 | 51 | fragColor = c*0.99+n*0.01;//vec4(1.0, 0.0, 0.0, 1.0); 52 | } -------------------------------------------------------------------------------- /shader/geo_tri/geo.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(triangles, invocations = 1) in; 4 | //layout(line_strip, max_vertices = 4) out; 5 | layout(triangle_strip, max_vertices = 4) out; 6 | 7 | in vec2 tex_uv_tes[]; 8 | out vec2 tex_uv; 9 | 10 | void main(void) 11 | { 12 | for(int i = 0; i < gl_in.length(); ++i) 13 | { 14 | tex_uv = tex_uv_tes[i]; 15 | gl_Position = gl_in[i].gl_Position; 16 | EmitVertex(); 17 | } 18 | // tex_uv = tex_uv_tes[0]; 19 | // gl_Position = gl_in[0].gl_Position; 20 | // EmitVertex(); 21 | 22 | EndPrimitive(); 23 | } 24 | -------------------------------------------------------------------------------- /shader/geo_tri/tcs.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | layout(vertices = 3) out; 4 | 5 | uniform sampler2D geomap; 6 | uniform mat4 mvp_matrix; 7 | uniform float cull_invert; 8 | uniform float importance; 9 | 10 | vec4 project(vec4 vertex) 11 | { 12 | vec4 pos=texture2D(geomap,vertex.xy); 13 | vec4 result = mvp_matrix*pos; 14 | return result; 15 | } 16 | 17 | bool offscreen(vec4 v1, 18 | vec4 v2, 19 | vec4 v3 ) 20 | { 21 | vec3 vx=vec3(v1.x,v2.x,v3.x); 22 | vec3 vy=vec3(v1.y,v2.y,v3.y); 23 | vec3 vz=vec3(v1.z,v2.z,v3.z); 24 | 25 | if(all(lessThan (vz.xyz, vec3(-5.0))))return true; 26 | 27 | /* 28 | if(all(lessThan (vz.xyz, vec3(10.0)))) 29 | { 30 | if (all(greaterThan(vx.xyz, vec3( 4.0)))) return true; 31 | if (all(lessThan (vx.xyz, vec3(-4.0)))) return true; 32 | if (all(greaterThan(vy.xyz, vec3( 4.0)))) return true; 33 | if (all(lessThan (vy.xyz, vec3(-4.0)))) return true; 34 | } 35 | */ 36 | 37 | if (all(greaterThan(vx.xyz, vec3( 1.3)))) return true; 38 | if (all(lessThan (vx.xyz, vec3(-1.3)))) return true; 39 | if (all(greaterThan(vy.xyz, vec3( 1.3)))) return true; 40 | if (all(lessThan (vy.xyz, vec3(-1.3)))) return true; 41 | return false; 42 | /* 43 | if(vertex.z < -10.0){ 44 | return true; 45 | } 46 | //return false; 47 | //if (vertex.z<8) 48 | return any( 49 | lessThan(vertex.xy, vec2(-8.0)) || 50 | greaterThan(vertex.xy, vec2(8.0)) 51 | ); 52 | 53 | return any( 54 | lessThan(vertex.xy, vec2(-1.4)) || 55 | greaterThan(vertex.xy, vec2(1.4)) 56 | ); */ 57 | } 58 | 59 | float level(float w)//float d) 60 | { 61 | return clamp(importance * 0.2 * pow(w,0.75)*4*8.0, 1, 32); 62 | // return clamp(importance * pow(w,0.5)*4*8.0, 1, 32); 63 | 64 | //return clamp(sqrt(w)*4*8.0, 1, 16); 65 | //return clamp(w*8*8.0, 1, 8); 66 | //return clamp((50.0-w)*8.0/50.0, 1, 8); 67 | } 68 | 69 | void main(void) 70 | { 71 | gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; 72 | /* 73 | { 74 | gl_TessLevelInner[0] = 1; 75 | gl_TessLevelOuter[0] = 1; 76 | gl_TessLevelOuter[1] = 1; 77 | gl_TessLevelOuter[2] = 1; 78 | } 79 | */ 80 | 81 | if(gl_InvocationID == 0) 82 | { 83 | vec4 v0 = project(gl_in[0].gl_Position); 84 | vec4 v1 = project(gl_in[1].gl_Position); 85 | vec4 v2 = project(gl_in[2].gl_Position); 86 | 87 | bool cull=false; 88 | 89 | v0.xyz/=v0.w; 90 | v1.xyz/=v1.w; 91 | v2.xyz/=v2.w; 92 | 93 | if ( min(v0.z,min(v1.z,v2.z)) > 1.0 ) cull=true; 94 | if ( max(v0.x,max(v1.x,v2.x)) < -1.4 ) cull=true; 95 | if ( max(v0.y,max(v1.y,v2.y)) < -1.4 ) cull=true; 96 | if ( min(v0.x,min(v1.x,v2.x)) > 1.4 ) cull=true; 97 | if ( min(v0.y,min(v1.y,v2.y)) > 1.4 ) cull=true; 98 | if(cull) 99 | { 100 | gl_TessLevelInner[0] = 1; 101 | gl_TessLevelOuter[0] =-1; 102 | gl_TessLevelOuter[1] =-1; 103 | gl_TessLevelOuter[2] =-1; 104 | } 105 | else 106 | { 107 | float detail0 = level(length(v1.xy-v2.xy)); 108 | float detail1 = level(length(v2.xy-v0.xy)); 109 | float detail2 = level(length(v1.xy-v0.xy)); 110 | float detail = (detail0+detail1+detail2)/3; 111 | gl_TessLevelInner[0] = detail; 112 | gl_TessLevelOuter[0] = detail0; 113 | gl_TessLevelOuter[1] = detail1; 114 | gl_TessLevelOuter[2] = detail2; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /shader/geo_tri/tes.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | uniform sampler2D geomap; 4 | uniform mat4 mvp_matrix; 5 | 6 | layout(triangles, equal_spacing, ccw) in; 7 | 8 | out vec2 tex_uv_tes; 9 | 10 | void main() 11 | { 12 | 13 | vec2 uv = gl_in[0].gl_Position.xy * gl_TessCoord.x + 14 | gl_in[1].gl_Position.xy * gl_TessCoord.y + 15 | gl_in[2].gl_Position.xy * gl_TessCoord.z; 16 | 17 | tex_uv_tes = uv; 18 | vec4 pos=texture2D(geomap,uv); 19 | gl_Position.xyzw = mvp_matrix*pos; 20 | 21 | /* 22 | 23 | gl_Position.xyzw = gl_in[0].gl_Position.xyzw * gl_TessCoord.x + 24 | gl_in[1].gl_Position.xyzw * gl_TessCoord.y + 25 | gl_in[2].gl_Position.xyzw * gl_TessCoord.z; 26 | */ 27 | } 28 | -------------------------------------------------------------------------------- /shader/geo_tri/vs.txt: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | in vec4 vertex; 4 | 5 | void main(void) 6 | { 7 | gl_Position = vertex; 8 | } 9 | -------------------------------------------------------------------------------- /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 | #include "opengl_FBO.h" 18 | /////////////////////////////////////////// 19 | #include "Bmp.h" 20 | #include "Bmp.h" 21 | /////////////////////////////////////////// 22 | typedef float vec3_t[3]; 23 | #include "md5/md5load.h" 24 | //////////////////////////////////////////////////////////////////////////////// 25 | #define SCREEN_SIZE_X 1024 26 | #define SCREEN_SIZE_Y 768 27 | //////////////////////////////////////////////////////////////////////////////// 28 | #define _USE_MATH_DEFINES 29 | #define loopi(start_l,end_l,step_l) for ( int i=start_l;i trunk_matrices; 63 | static std::vector leaf_matrices; 64 | static std::vector terrain_matrices; 65 | static std::vector trunk_matrices_mvp; 66 | static std::vector leaf_matrices_mvp; 67 | static std::vector terrain_matrices_mvp; 68 | 69 | if(trunk_matrices.size()==0) 70 | { 71 | terrain_matrices.clear(); 72 | trunk_matrices.clear(); 73 | leaf_matrices.clear(); 74 | int res=5; 75 | 76 | loopi(-res,res) 77 | loopj(-res,res) 78 | { 79 | matrix44 m; 80 | m.ident(); 81 | m.set_translation(vector3(i*140,0,j*140)); 82 | trunk_matrices.push_back(m); 83 | terrain_matrices.push_back(m); 84 | 85 | loopk(0,32) 86 | { 87 | matrix44 m; 88 | m.ident(); 89 | vec3f c(i*140,0,j*140); 90 | float b=float(k)/32.0f;//c.y/(15*20); 91 | c=c+trunk.get_displace_xyz(b); 92 | float s=1.5f*trunk.get_radius(b)/trunk.get_radius(0); 93 | m.scale(vector3(s,s,s)); 94 | m.translate(vector3(trunk.get_radius(b)*0.75,0,0)); 95 | m.rotate_y(33*trunk.get_angle(b)+k*k*10); 96 | m.set_translation(vector3(c.x,c.y,c.z)); 97 | leaf_matrices.push_back(m); 98 | } 99 | } 100 | terrain_matrices_mvp=terrain_matrices; 101 | trunk_matrices_mvp=trunk_matrices; 102 | leaf_matrices_mvp=leaf_matrices; 103 | } 104 | 105 | loopi(0,terrain_matrices.size()) terrain_matrices_mvp[i]=terrain_matrices[i]*screen.camera; 106 | loopi(0,trunk_matrices.size()) trunk_matrices_mvp[i]=trunk_matrices[i]*screen.camera; 107 | loopi(0,leaf_matrices.size()) leaf_matrices_mvp[i]=leaf_matrices[i]*screen.camera; 108 | 109 | //glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); 110 | 111 | terrain.Draw(terrain_matrices_mvp); 112 | trunk.Draw(trunk_matrices_mvp); 113 | leaf.Draw(leaf_matrices_mvp); 114 | leaftrunk.Draw(leaf_matrices_mvp); 115 | 116 | CoreKeyMouse(); 117 | glutSwapBuffers(); 118 | } 119 | /////////////////////////////////////////// 120 | int main(int argc, char **argv) 121 | { 122 | CoreInit(DrawScene,argc, argv); 123 | glutMainLoop(); 124 | } 125 | /////////////////////////////////////////// 126 | -------------------------------------------------------------------------------- /src/Procedural.h: -------------------------------------------------------------------------------- 1 | #include "Procedural_tables.h" 2 | 3 | struct Vertex{ float u,v,w;} ; 4 | 5 | #include "Procedural_map.h" 6 | #include "Procedural_vbo.h" 7 | #include "Procedural_draw.h" 8 | 9 | class Procedural 10 | { 11 | public: 12 | 13 | float importance; // detail level weight 14 | GeometryMap map_in; 15 | GeometryMap map_out; 16 | BinaryMap map_binary; 17 | 18 | private: 19 | 20 | GeometryVBO vbo_quads_holes; 21 | GeometryVBO vbo_quads; 22 | GeometryVBO vbo_triangles; 23 | GeometryVBO vbo_strips; 24 | 25 | bool no_border; 26 | 27 | public: 28 | 29 | void Draw(std::vector &mvp_matrices) 30 | { 31 | glEnableClientState(GL_VERTEX_ARRAY); CHECK_GL_ERROR(); 32 | 33 | // Draw outside 34 | if(map_out.valid()) 35 | { 36 | if (vbo_triangles.valid()) 37 | proc_draw(importance,mvp_matrices,vbo_triangles,map_out,false); 38 | 39 | if (vbo_quads.valid()) 40 | proc_draw(importance,mvp_matrices,vbo_quads,map_out,false); 41 | 42 | if (vbo_strips.valid()) 43 | proc_draw(importance,mvp_matrices,vbo_strips,map_out,false); 44 | } 45 | 46 | // Draw inside 47 | if(map_in.valid() ) 48 | { 49 | if (vbo_triangles.valid()) 50 | proc_draw(importance,mvp_matrices,vbo_triangles,map_in,true); 51 | 52 | if (vbo_quads.valid()) 53 | proc_draw(importance,mvp_matrices,vbo_quads,map_in,true); 54 | 55 | if (vbo_strips.valid()) 56 | proc_draw(importance,mvp_matrices,vbo_strips,map_in,true); 57 | } 58 | 59 | // Draw border 60 | if(map_out.valid() && map_in.valid() ) 61 | if (vbo_quads_holes.valid()) 62 | proc_draw_holes(importance,mvp_matrices,vbo_quads_holes, map_in,map_out); 63 | 64 | glActiveTextureARB( GL_TEXTURE2 );glBindTexture(GL_TEXTURE_2D, 0 ); 65 | glActiveTextureARB( GL_TEXTURE1 );glBindTexture(GL_TEXTURE_2D, 0 ); 66 | glActiveTextureARB( GL_TEXTURE0 );glBindTexture(GL_TEXTURE_2D, 0 ); 67 | 68 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); CHECK_GL_ERROR(); 69 | glDisableClientState(GL_VERTEX_ARRAY); CHECK_GL_ERROR(); 70 | } 71 | 72 | void gen_geometry_borderless(int res_i = 70,int res_j = 70) 73 | { 74 | int i,j; 75 | for (i=0;i0) 88 | { 89 | Vertex v; 90 | 91 | v.u=a2;v.v=b1;v.w=1;vbo_quads.v.push_back(v); 92 | v.u=a2;v.v=b2;v.w=1;vbo_quads.v.push_back(v); 93 | v.u=a1;v.v=b2;v.w=1;vbo_quads.v.push_back(v); 94 | v.u=a1;v.v=b1;v.w=1;vbo_quads.v.push_back(v); 95 | } 96 | } 97 | } 98 | vbo_quads.gen_vbo(4); 99 | } 100 | 101 | void gen_geometry_borderless_strip(int res_i = 70,int res_j = 70) 102 | { 103 | int i,j; 104 | 105 | for (i=0;iimportance=importance; 9 | 10 | int border=50; 11 | Bmp bmp_out("../data/textures/leaf/up.jpg"); 12 | Bmp bmp_in("../data/textures/leaf/dn.jpg"); 13 | Bmp bmp_height("../data/textures/leaf/stencil.png"); 14 | bmp_height.make_border(border,255,0,255); 15 | this->bmp_height=&bmp_height; 16 | 17 | Bmp bmp_stencil("../data/textures/leaf/stencil.png"); 18 | 19 | map_out.init(width,height); 20 | map_in.init(width,height); 21 | map_binary.init(width,height); 22 | 23 | int i,j; 24 | 25 | loop(i,0,width) 26 | loop(j,0,height) 27 | { 28 | float a=float(i)/float(width); 29 | float b=float(j)/float(height); 30 | 31 | vec3f stencil=bmp_stencil.get_pixel(a,b); 32 | 33 | float alpha=1; 34 | 35 | if (stencil.x>=0.99) 36 | if (stencil.y<=0.01) 37 | if (stencil.z>=0.99) 38 | { 39 | alpha=0; 40 | } 41 | 42 | vec3f p1,p2,n1,n2,c1,c2; 43 | 44 | p1=p_out(a,b); 45 | n1=n_out(a,b); 46 | c1=bmp_out.get_pixel(a,b); 47 | 48 | p2=p_in(a,b); 49 | n2=n_in(a,b); 50 | c2=bmp_in.get_pixel(a,b); 51 | 52 | p1.z-=0.27; 53 | p2.z-=0.27; 54 | 55 | map_out.set_pixel(i,j,p1,n1,c1,alpha); 56 | map_in.set_pixel(i,j,p2,n2,c2,alpha); 57 | map_binary.set_pixel(i,j,alpha); 58 | } 59 | 60 | map_out.gen_textures(); 61 | map_in.gen_textures(); 62 | 63 | // generate vbos 64 | //gen_geometry(res_x,res_y,1); 65 | gen_geometry_borderless(res_x,res_y); 66 | //gen_geometry_borderless_strip(res_x,res_y); 67 | } 68 | 69 | float heightmap(float a,float b) 70 | { 71 | float d=2*fabs(b-0.5); 72 | float 73 | h=sin(a*M_PI)+2*sin(b*M_PI); 74 | h+=d*sin(8*a*M_PI)*0.5;//+sin(b*M_PI); 75 | h-=2*a*a; 76 | return h*3; 77 | } 78 | 79 | float border(float a,float b) 80 | { 81 | float bo=bmp_height->get_pixel(a,b).y; 82 | bo=bo-0.25;//-0.5; 83 | if(bo<0)bo=0; 84 | return bo*0.3; 85 | } 86 | 87 | vec3f p_out(float a, float b) 88 | { 89 | vec3f p(a*30,0,(b-0.5)*30); 90 | p.y+=heightmap(a,b)-heightmap(0,0.5); 91 | return p; 92 | } 93 | 94 | vec3f p_in(float a, float b) 95 | { 96 | vec3f p=p_out(a,b); 97 | p.y-=border(a,b); 98 | return p; 99 | } 100 | 101 | vec3f n_out(float a, float b) 102 | { 103 | vec3f p =p_out(a,b); 104 | vec3f dx=p_out(a+0.02,b)-p; 105 | vec3f dy=p_out(a,b+0.02)-p; 106 | vec3f n=dx; 107 | n.cross(dx,dy); 108 | n.normalize(); 109 | return n; 110 | } 111 | 112 | vec3f n_in(float a, float b) 113 | { 114 | vec3f p =p_in(a,b); 115 | vec3f dx=p_in(a+0.02,b)-p; 116 | vec3f dy=p_in(a,b+0.02)-p; 117 | vec3f n=dx; 118 | n.cross(dx,dy); 119 | n.normalize(); 120 | return n; 121 | } 122 | }; -------------------------------------------------------------------------------- /src/Procedural_Leaf_Trunk.h: -------------------------------------------------------------------------------- 1 | 2 | class LeafTrunk : public Procedural { public: 3 | 4 | Bmp *bmp_height; 5 | Leaf*leaf; 6 | 7 | LeafTrunk(float importance,int width,int height,int res_x,int res_y,Leaf* leaf) 8 | { 9 | this->importance=importance; 10 | 11 | map_out.init(width,height); 12 | this->leaf=leaf; 13 | 14 | int i,j; 15 | loop(i,0,width) 16 | loop(j,0,height) 17 | { 18 | float a=float(i)/float(width-1); 19 | float b=float(j)/float(height-1); 20 | vec3f p1=p_trunk_out(a,b); 21 | vec3f n1=n_trunk_out(a,b); 22 | vec3f c1=vec3f(96.0/256.0,204.0/256.0,0); 23 | map_out.set_pixel(i,j,p1,n1,c1,1); 24 | } 25 | map_out.gen_textures(); 26 | gen_geometry_borderless(res_x,res_y); 27 | //gen_geometry_borderless_strip(res_x,res_y); 28 | } 29 | 30 | vec3f p_trunk_out(float a, float b) 31 | { 32 | a/=2; 33 | vec3f p;//(0,0,b*5-5); 34 | p.x=30*a; 35 | p.z= sin(2*M_PI*(b+0.5))*1.8*(0.5-a); 36 | p.y= cos(2*M_PI*(b+0.5))*1.8*(0.5-a); 37 | p.y+=leaf->heightmap(a,0.5)-leaf->heightmap(0,0.5); 38 | return p; 39 | } 40 | vec3f n_trunk_out(float a, float b) 41 | { 42 | vec3f p =p_trunk_out(a,b); 43 | vec3f dx=p_trunk_out(a+0.02,b)-p; 44 | vec3f dy=p_trunk_out(a,b+0.02)-p; 45 | vec3f n=dx; 46 | n.cross(dx,dy); 47 | n.z= -cos(2*M_PI*(b+0.5)); 48 | n.y= sin(2*M_PI*(b+0.5)); 49 | n.normalize(); 50 | return n; 51 | } 52 | }; -------------------------------------------------------------------------------- /src/Procedural_Terrain.h: -------------------------------------------------------------------------------- 1 | 2 | class Terrain : public Procedural { public: 3 | 4 | Terrain(float importance,int width,int height,int res_x,int res_y,int res_z) 5 | { 6 | this->importance=importance; 7 | //map_in.init(width,height); 8 | map_out.init(width,height); 9 | map_binary.init(width,height); 10 | 11 | Bmp color_texture("../data/textures/terrain/up.jpg"); 12 | 13 | int i,j; 14 | 15 | loop(i,0,width) 16 | loop(j,0,height) 17 | { 18 | float a=float(i)/float(width-1); 19 | float b=float(j)/float(height-1); 20 | 21 | vec3f p=trunk_p_out(a,b); 22 | vec3f n=trunk_n_out(a,b); 23 | vec3f c( 24 | float(color_texture.data[(i+j*width)*3+2])/255.0f, 25 | float(color_texture.data[(i+j*width)*3+1])/255.0f, 26 | float(color_texture.data[(i+j*width)*3+0])/255.0f 27 | ); //=trunk_c_out(a,b); 28 | 29 | float hole = 0;/* 30 | cos(2*M_PI*b)+ 31 | cos(2*M_PI*a)+ 32 | cos(5*M_PI*b)+ 33 | cos(5*M_PI*a);*/ 34 | 35 | map_out.set_pixel(i,j,p,n,c); 36 | p.y-=10.00; 37 | n.y=-n.y; 38 | // map_in.set_pixel(i,j,p,n,c); 39 | map_binary.set_pixel(i,j,(hole<-0.7)? 0:1); 40 | } 41 | 42 | //map_in.gen_textures(); 43 | map_out.gen_textures(); 44 | //map_in.tex_scale.y=1; 45 | //map_in.tex_scale.z=1; 46 | map_out.tex_scale.y=1; 47 | map_out.tex_scale.z=1; 48 | 49 | // generate vbos 50 | //gen_geometry(res_x,res_y,res_z); 51 | gen_geometry_borderless(res_x,res_y); 52 | //gen_geometry_borderless_strip(res_x,res_y); 53 | 54 | //gen_geometry(res_x,res_y,1); 55 | } 56 | 57 | vec3f trunk_p_out(float a, float b,float scale=1.0f) 58 | { 59 | int width=map_out.width; 60 | float displace=//get_liana(a+b*3,0.1)*15+ 61 | 0.05*( 62 | sin(2*M_PI*b)+ 63 | sin(2*M_PI*a)+ 64 | sin(8*M_PI*b)*0.2+ 65 | sin(8*M_PI*a)*0.2 66 | ); 67 | 68 | vec3f p; 69 | p.x= a*140;// cos(2*M_PI*a)*displace*get_radius(b); 70 | p.z= b*140;// sin(2*M_PI*a)*displace*get_radius(b); 71 | p.y= displace*140;// 72 | 73 | return p; 74 | } 75 | 76 | vec3f trunk_n_out(float a, float b) 77 | { 78 | vec3f p =trunk_p_out(a,b); 79 | vec3f dx=trunk_p_out(a+0.02,b)-p; 80 | vec3f dy=trunk_p_out(a,b+0.02)-p; 81 | vec3f n=dx; 82 | n.cross(dx,dy); 83 | n.normalize(); 84 | 85 | return n; 86 | } 87 | }; -------------------------------------------------------------------------------- /src/Procedural_Trunk.h: -------------------------------------------------------------------------------- 1 | 2 | class Trunk : public Procedural { public: 3 | 4 | Trunk(float importance,int width,int height,int res_x,int res_y,int res_z) 5 | { 6 | this->importance=importance; 7 | map_out.init(width,height); 8 | 9 | int i,j; 10 | 11 | loop(i,0,width) 12 | loop(j,0,height) 13 | { 14 | float a=float(i)/float(width-1); 15 | float b=float(j)/float(height-1); 16 | 17 | vec3f p=trunk_p_out(a,b); 18 | vec3f n=trunk_n_out(a,b); 19 | vec3f c(0,0,0);//=trunk_c_out(a,b); 20 | map_out.set_pixel(i,j,p,n,c); 21 | } 22 | 23 | map_out.save_vertex_map_to_bmp("../test.bmp"); 24 | 25 | Bmp test("../data/textures/trunk/up.jpg"); 26 | loopi(0,width) 27 | loopj(0,height) 28 | { 29 | map_out.color_map[(i+j*width)*4+0]=test.data[(i+j*width)*3+0]; 30 | map_out.color_map[(i+j*width)*4+1]=test.data[(i+j*width)*3+1]; 31 | map_out.color_map[(i+j*width)*4+2]=test.data[(i+j*width)*3+2]; 32 | } 33 | map_out.gen_textures(); 34 | map_out.tex_scale.y=4; 35 | map_out.tex_scale.z=8; 36 | 37 | // generate vbos 38 | //gen_geometry(res_x,res_y,res_z); 39 | gen_geometry_borderless(res_x,res_y); 40 | //gen_geometry_borderless_strip(res_x,res_y); 41 | } 42 | 43 | vec3f get_displace_xyz(float b) 44 | { 45 | vec3f d; 46 | d.x=15*sin(2*M_PI*b*2); 47 | d.y=b*300.0; 48 | d.z=15*cos(2*M_PI*b*2); 49 | return d; 50 | } 51 | 52 | float get_angle(float b) 53 | { 54 | return b*5; 55 | } 56 | 57 | float get_radius(float b) 58 | { 59 | return 0.3*(1-b*b)*15 ; 60 | } 61 | 62 | float get_liana(float a,float scale=0.1f) 63 | { 64 | a=a-float(int(a)); 65 | if(a>scale*2)return 0; 66 | float d=fabs(a-scale); 67 | return sqrt(scale*scale-d*d); 68 | } 69 | 70 | float get_liana2(float a,float scale=0.1f) 71 | { 72 | a=a-float(int(a)); 73 | if(a>scale)return 0; 74 | if(a<0)return 0; 75 | return a/scale; 76 | } 77 | 78 | float get_max(float a,float b){ return (a>b) ? a:b;} 79 | 80 | vec3f trunk_p_out(float a, float b,float scale=1.0f) 81 | { 82 | int width=map_out.width; 83 | 84 | static bool init=true; 85 | static std::vector radius; 86 | if(init) 87 | { 88 | radius.resize(width*3); 89 | 90 | int i,j,j_max=width; 91 | loop(i,0,3) 92 | { 93 | vec3f p1(1,0,0),p2(1,0,0); 94 | float a1=0+i*120; p1.rot_z(a1*2*M_PI/360.0f); 95 | float a2=(i+1)*120; p2.rot_z(a2*2*M_PI/360.0f); 96 | vec3f center=(p1+p2)*0.5; 97 | a1=-30+i*120; a1 = a1*2*M_PI/360.0f; 98 | a2=-30+i*120+180; a2 = a2*2*M_PI/360.0f; 99 | 100 | loop(j,0,j_max) 101 | { 102 | vec3f p(1,0,0); 103 | p.rot_z(a1+(a2-a1)*float(j)/float(j_max)); 104 | p=p+center; 105 | radius[i*j_max+j]=p.length()*p.length(); 106 | } 107 | } 108 | init=false; 109 | } 110 | float float_ofs=a+get_angle(b); 111 | int radius_ofs = int(float(float_ofs*float(width*3)))%(width*3); 112 | 113 | float displace=0;//+ 114 | 115 | // int t;loop(t,-10,10){ displace+=get_liana(a+30+t+t*b,0.02)*15;} 116 | // int t;loop(t,-10,10){ displace=get_max(get_liana(a+30+t+t*b,0.02)*15,displace);} 117 | 118 | displace+=radius[radius_ofs]; 119 | displace+=get_liana(a+b*3,0.1)*15+ 120 | 0.1+0.2*( 121 | sin(2*3*2*M_PI*b)+ 122 | cos(2*M_PI*(a+2*b))*1.2+ 123 | cos(2*M_PI*(2*3*b+2*a))*1.2+ 124 | sin(4*M_PI*(a-6*b))*0.2+ 125 | cos(3*M_PI*(a*4))*0.2+ 126 | sin(1+32*M_PI*(2*a-b))*0.1+ 127 | cos(2+32*M_PI*(2*a+b))*0.1 128 | ); 129 | 130 | vec3f p; 131 | p.x= cos(2*M_PI*a)*displace*get_radius(b); 132 | p.z= sin(2*M_PI*a)*displace*get_radius(b); 133 | p.y= 0;// 134 | 135 | p=p+get_displace_xyz(b); 136 | 137 | return p; 138 | } 139 | 140 | vec3f trunk_c_out(float a, float b) 141 | { 142 | vec3f c; 143 | c.x=0.20; 144 | c.y=1.0; 145 | c.z=0.3; 146 | 147 | c.x=0.40; 148 | c.y=0.3; 149 | c.z=0.1; 150 | 151 | float scale=0.0; 152 | vec3f c2=c; 153 | 154 | loopi(0,300) 155 | { 156 | static vec3f rn; 157 | rn.x=float(i^74)*0.01; 158 | rn.y=float(300-(i^3))*0.01; 159 | rn.z=float(i^23)*0.01; 160 | rn.random01_fxyz(); 161 | float v=get_liana2(a+20+sin(b*4*rn.x+rn.y*10)*0.2+b*(rn.y-0.5)*5+rn.z*20,rn.x*0.01); 162 | 163 | if(v>0.00) 164 | { 165 | scale=v; 166 | c2=rn; 167 | } 168 | //scale+=v/(rn.x*0.01); 169 | } 170 | c=(c2*0.1+c)*(scale*0.2+0.8); 171 | 172 | return c; 173 | } 174 | 175 | vec3f trunk_n_out(float a, float b) 176 | { 177 | vec3f p =trunk_p_out(a,b); 178 | vec3f dx=trunk_p_out(a+0.02,b)-p; 179 | vec3f dy=trunk_p_out(a,b+0.02)-p; 180 | vec3f n=dx; 181 | n.cross(dx,dy); 182 | n.normalize(); 183 | 184 | return n; 185 | } 186 | }; -------------------------------------------------------------------------------- /src/Procedural_bsphere.h: -------------------------------------------------------------------------------- 1 | http://www.racer.nl/reference/vfc.htm 2 | void CalcFrustumEquations() 3 | // From the current OpenGL modelview and projection matrices, 4 | // calculate the frustum plane equations (Ax+By+Cz+D=0, n=(A,B,C)) 5 | // The equations can then be used to see on which side points are. 6 | { 7 | dfloat *m,t; 8 | DPlane3 *p; 9 | int i; 10 | 11 | // This piece of code taken from: 12 | // http://www.markmorley.com/opengl/frustumculling.html 13 | // Modified quite a bit to suit the D3 classes. 14 | 15 | // Retrieve matrices from OpenGL 16 | glGetFloatv(GL_MODELVIEW_MATRIX,matModelView.GetM()); 17 | glGetFloatv(GL_PROJECTION_MATRIX,matProjection.GetM()); 18 | 19 | // Combine into 1 matrix 20 | glGetFloatv(GL_PROJECTION_MATRIX,matFrustum.GetM()); 21 | matFrustum.Multiply(&matModelView); 22 | 23 | // Get plane parameters 24 | m=matFrustum.GetM(); 25 | 26 | p=&frustumPlane[RIGHT]; 27 | p->n.x=m[3]-m[0]; 28 | p->n.y=m[7]-m[4]; 29 | p->n.z=m[11]-m[8]; 30 | p->d=m[15]-m[12]; 31 | 32 | p=&frustumPlane[LEFT]; 33 | p->n.x=m[3]+m[0]; 34 | p->n.y=m[7]+m[4]; 35 | p->n.z=m[11]+m[8]; 36 | p->d=m[15]+m[12]; 37 | 38 | p=&frustumPlane[BOTTOM]; 39 | p->n.x=m[3]+m[1]; 40 | p->n.y=m[7]+m[5]; 41 | p->n.z=m[11]+m[9]; 42 | p->d=m[15]+m[13]; 43 | 44 | p=&frustumPlane[TOP]; 45 | p->n.x=m[3]-m[1]; 46 | p->n.y=m[7]-m[5]; 47 | p->n.z=m[11]-m[9]; 48 | p->d=m[15]-m[13]; 49 | 50 | p=&frustumPlane[PFAR]; 51 | p->n.x=m[3]-m[2]; 52 | p->n.y=m[7]-m[6]; 53 | p->n.z=m[11]-m[10]; 54 | p->d=m[15]-m[14]; 55 | 56 | p=&frustumPlane[PNEAR]; 57 | p->n.x=m[3]+m[2]; 58 | p->n.y=m[7]+m[6]; 59 | p->n.z=m[11]+m[10]; 60 | p->d=m[15]+m[14]; 61 | 62 | // Normalize all plane normals 63 | for(i=0;i<6;i++) 64 | frustumPlane[i].Normalize(); 65 | } 66 | 67 | /************** 68 | * Classifying * 69 | **************/ 70 | int DCuller::SphereInFrustum(const DVector3 *center,dfloat radius) const 71 | // Returns classification (INSIDE/INTERSECTING/OUTSIDE) 72 | { 73 | int i; 74 | const DPlane3 *p; 75 | 76 | for(i=0;i<6;i++) 77 | { 78 | p=&frustumPlane[i]; 79 | if(p->n.x*center->x+p->n.y*center->y+p->n.z*center->z+p->d <= -radius) 80 | return OUTSIDE; 81 | } 82 | // Decide: Inside or intersecting 83 | return INTERSECTING; 84 | } -------------------------------------------------------------------------------- /src/Procedural_draw.h: -------------------------------------------------------------------------------- 1 | void proc_draw(float importance,std::vector &mvp_matrices,GeometryVBO& vbo, GeometryMap& map,bool cull_invert=false) 2 | { 3 | glCullFace( cull_invert ? GL_BACK : GL_FRONT); 4 | 5 | glActiveTextureARB( GL_TEXTURE0 );glBindTexture(GL_TEXTURE_2D, map.texture_vertex ); 6 | glActiveTextureARB( GL_TEXTURE1 );glBindTexture(GL_TEXTURE_2D, map.texture_normal ); 7 | glActiveTextureARB( GL_TEXTURE2 );glBindTexture(GL_TEXTURE_2D, map.texture_color ); 8 | 9 | if(vbo.type==3) 10 | { 11 | // Triangle 12 | static Shader tri_shader("../shader/geo_tri"); 13 | tri_shader.begin(); 14 | tri_shader.setUniform1i("geomap",0); 15 | tri_shader.setUniform1i("normalmap",1); 16 | tri_shader.setUniform1i("colormap",2); 17 | tri_shader.setUniform1f("importance",importance); 18 | tri_shader.setUniform3f("tex_scale",map.tex_scale.x,map.tex_scale.y,map.tex_scale.z); 19 | //tri_shader.setUniform1f("cull_invert",cull_invert ? -1 : 1); 20 | //tri_shader.setUniformMatrix4fv("mvp_matrix", 1, 0, (float*)&m_mvp.m[0][0]); CHECK_GL_ERROR(); 21 | 22 | int i;loop(i,0,mvp_matrices.size()) 23 | { 24 | tri_shader.setUniformMatrix4fv("mvp_matrix", 1, 0, (float*)&mvp_matrices[i].m[0][0]); 25 | vbo.draw(i); 26 | } 27 | 28 | tri_shader.end(); 29 | } 30 | 31 | if(vbo.type==4) 32 | { 33 | // Quad 34 | static Shader quad_shader("../shader/geo_quad"); 35 | // static Shader quad_shader("../shader/geo_quad_simple"); 36 | quad_shader.begin(); 37 | quad_shader.setUniform1i("geomap",0); 38 | quad_shader.setUniform1i("normalmap",1); 39 | quad_shader.setUniform1i("colormap",2); 40 | quad_shader.setUniform1f("importance",importance); 41 | quad_shader.setUniform3f("tex_scale",map.tex_scale.x,map.tex_scale.y,map.tex_scale.z); 42 | //quad_shader.setUniformMatrix4fv("mvp_matrix", 1, 0, (float*)&m_mvp.m[0][0]); CHECK_GL_ERROR(); 43 | //quad_shader.setUniform1f("cull_invert",cull_invert ? -1 : 1); 44 | //quad_shader.setUniformMatrix4fv("mvp_matrix", 1, 0, (float*)&m_mvp.m[0][0]); CHECK_GL_ERROR(); 45 | 46 | loopi(0,mvp_matrices.size()) 47 | { 48 | static GLint loc = quad_shader.get_loc("mvp_matrix"); 49 | glUniformMatrix4fv(loc, 1, 0, (float*)&mvp_matrices[i].m[0][0]); 50 | 51 | vbo.draw(i); 52 | } 53 | 54 | quad_shader.end(); 55 | } 56 | 57 | if(vbo.type==1) 58 | { 59 | // Triangle Strip 60 | static Shader quad_shader("../shader/geo_quad_simple"); 61 | quad_shader.begin(); 62 | quad_shader.setUniform1i("geomap",0); 63 | quad_shader.setUniform1i("normalmap",1); 64 | quad_shader.setUniform1i("colormap",2); 65 | quad_shader.setUniform3f("tex_scale",map.tex_scale.x,map.tex_scale.y,map.tex_scale.z); 66 | 67 | int i;loop(i,0,mvp_matrices.size()) 68 | { 69 | static GLint loc = quad_shader.get_loc("mvp_matrix"); 70 | glUniformMatrix4fv(loc, 1, 0, (float*)&mvp_matrices[i].m[0][0]); 71 | vbo.draw(i); 72 | } 73 | 74 | quad_shader.end(); 75 | } 76 | } 77 | 78 | void proc_draw_holes(float importance,std::vector &mvp_matrices,GeometryVBO& vbo, GeometryMap& map_in,GeometryMap& map_out) 79 | { 80 | if(vbo.type!=4) return; 81 | 82 | glCullFace( GL_BACK ); 83 | 84 | glActiveTextureARB( GL_TEXTURE0 );glBindTexture(GL_TEXTURE_2D, map_out.texture_vertex ); 85 | glActiveTextureARB( GL_TEXTURE1 );glBindTexture(GL_TEXTURE_2D, map_in.texture_vertex ); 86 | glActiveTextureARB( GL_TEXTURE2 );glBindTexture(GL_TEXTURE_2D, map_out.texture_normal ); 87 | glActiveTextureARB( GL_TEXTURE3 );glBindTexture(GL_TEXTURE_2D, map_in.texture_normal ); 88 | glActiveTextureARB( GL_TEXTURE4 );glBindTexture(GL_TEXTURE_2D, map_out.texture_color ); 89 | glActiveTextureARB( GL_TEXTURE5 );glBindTexture(GL_TEXTURE_2D, map_in.texture_color ); 90 | 91 | // Hole Quads 92 | static Shader quad_shader("../shader/geo_quad_holes"); 93 | quad_shader.begin(); 94 | quad_shader.setUniform1i("geomap_out",0); 95 | quad_shader.setUniform1i("geomap_in",1); 96 | quad_shader.setUniform1i("normalmap_out",2); 97 | //quad_shader.setUniform1i("normalmap_in",3); 98 | quad_shader.setUniform1i("colormap_out",4); 99 | quad_shader.setUniform1f("importance",importance); 100 | quad_shader.setUniform3f("tex_scale",map_in.tex_scale.x,map_in.tex_scale.y,map_in.tex_scale.z); 101 | //quad_shader.setUniform1i("colormap_in",5); 102 | //quad_shader.setUniformMatrix4fv("mvp_matrix", 1, 0, (float*)&m_mvp.m[0][0]); CHECK_GL_ERROR(); 103 | 104 | int i;loop(i,0,mvp_matrices.size()) 105 | { 106 | quad_shader.setUniformMatrix4fv("mvp_matrix", 1, 0, (float*)&mvp_matrices[i].m[0][0]); 107 | vbo.draw(i); 108 | } 109 | 110 | quad_shader.end(); 111 | 112 | glActiveTextureARB( GL_TEXTURE2 );glBindTexture(GL_TEXTURE_2D, 0 ); 113 | glActiveTextureARB( GL_TEXTURE1 );glBindTexture(GL_TEXTURE_2D, 0 ); 114 | glActiveTextureARB( GL_TEXTURE0 );glBindTexture(GL_TEXTURE_2D, 0 ); 115 | } 116 | 117 | 118 | -------------------------------------------------------------------------------- /src/Procedural_map.h: -------------------------------------------------------------------------------- 1 | struct GeometryMap 2 | { 3 | std::vector vextex_map; // 4 float / pixel , xyz1 4 | std::vector normal_map; // 4 float / pixel , nxnynz1 5 | std::vector color_map; // 4 float / pixel , nxnynz1 6 | int texture_vertex; 7 | int texture_normal; 8 | int texture_color; 9 | int width,height; 10 | vec3f tex_scale; 11 | 12 | bool valid(){ return (vextex_map.size()>0); }; 13 | 14 | void init(int width,int height) 15 | { 16 | this->width=width; 17 | this->height=height; 18 | vextex_map.resize(width*height*4); 19 | normal_map.resize(width*height*4); 20 | color_map.resize(width*height*4); 21 | tex_scale.x=1; 22 | tex_scale.y=1; 23 | tex_scale.z=1; 24 | } 25 | 26 | void save_vertex_map_to_bmp(char* name) 27 | { 28 | Bmp bmp(width,height,24,0); 29 | 30 | vec3f pmin; 31 | pmin.x=vextex_map[0]; 32 | pmin.y=vextex_map[1]; 33 | pmin.z=vextex_map[2]; 34 | vec3f pmax=pmin; 35 | 36 | loopi(0,width) 37 | loopj(0,height) 38 | { 39 | int o = (i+j*width)*4; 40 | float x=vextex_map[o+0]; 41 | float y=vextex_map[o+1]; 42 | float z=vextex_map[o+2]; 43 | if(xpmax.x)pmax.x=x; 47 | if(y>pmax.y)pmax.y=y; 48 | if(z>pmax.z)pmax.z=z; 49 | } 50 | loopi(0,width) 51 | loopj(0,height) 52 | { 53 | int o = (i+j*width); 54 | bmp.data[o*3+0]=(vextex_map[o*4+0]-pmin.x)*255/(pmax.x-pmin.x); 55 | bmp.data[o*3+1]=(vextex_map[o*4+1]-pmin.x)*255/(pmax.x-pmin.x); 56 | bmp.data[o*3+2]=(vextex_map[o*4+2]-pmin.x)*255/(pmax.x-pmin.x); 57 | } 58 | bmp.save(name); 59 | } 60 | 61 | void set_pixel(int i,int j,vec3f p,vec3f n,vec3f c,float alpha=1) 62 | { 63 | if(!valid())return; 64 | int o = (i+j*width)*4; 65 | vextex_map[o+0]=p.x*1 ; 66 | vextex_map[o+1]=p.y*1 ; 67 | vextex_map[o+2]=p.z*1 ; 68 | vextex_map[o+3]=1 ; 69 | 70 | normal_map[o+0]=n.x*1 ; 71 | normal_map[o+1]=n.y*1 ; 72 | normal_map[o+2]=n.z*1 ; 73 | normal_map[o+3]=1 ; 74 | 75 | color_map[o+0]=c.z*255 ; 76 | color_map[o+1]=c.y*255 ; 77 | color_map[o+2]=c.x*255 ; 78 | color_map[o+3]=alpha*255 ; 79 | } 80 | void gen_textures() 81 | { 82 | if(!valid())return; 83 | 84 | texture_vertex = CoreNewFloat16Tex(width,height,&vextex_map[0],true); 85 | texture_normal = CoreNewFloat16Tex(width,height,&normal_map[0],true); 86 | texture_color = CoreNewChar8Tex(width,height,&color_map[0],true); 87 | } 88 | }; 89 | 90 | struct BinaryMap 91 | { 92 | std::vector map_binary; 93 | int width,height; 94 | 95 | bool valid(){ return (map_binary.size()>0); }; 96 | 97 | void init(int width,int height) 98 | { 99 | this->width=width; 100 | this->height=height; 101 | map_binary.resize(width*height,1); 102 | } 103 | uchar get_pixel(float a,float b,float am,float bm) 104 | { 105 | if(!valid())return 1; 106 | int x= float(a/am)*float(width); 107 | int y= float(b/bm)*float(height); 108 | x=x%width; 109 | y=y%height; 110 | return map_binary[y*width+x]; 111 | } 112 | uchar get_region_max(float a1,float b1,float a2,float b2) 113 | { 114 | if(!valid())return 1; 115 | 116 | int x1= float(a1)*float(width); 117 | int y1= float(b1)*float(height); 118 | int x2= float(a2)*float(width); 119 | int y2= float(b2)*float(height); 120 | 121 | int i,j; 122 | 123 | loop(i,x1,x2) 124 | loop(j,y1,y2) 125 | { 126 | int x=i%width; 127 | int y=j%height; 128 | int m=map_binary[y*width+x]; 129 | if (m>0)return 1; 130 | } 131 | return 0; 132 | } 133 | void set_pixel(int x, int y,uchar v) 134 | { 135 | if(!valid())return; 136 | map_binary[y*width+x]=v; 137 | } 138 | }; 139 | 140 | -------------------------------------------------------------------------------- /src/Procedural_tables.h: -------------------------------------------------------------------------------- 1 | 2 | // 0 1 2 3 | // 7 3 4 | // 6 5 4 5 | 6 | vec3f ms_p[8]= 7 | { 8 | vec3f(0.0f,0.0f,0.0f), 9 | vec3f(0.5f,0.0f,0.0f), 10 | vec3f(1.0f,0.0f,0.0f), 11 | vec3f(1.0f,0.5f,0.0f), 12 | vec3f(1.0f,1.0f,0.0f), 13 | vec3f(0.5f,1.0f,0.0f), 14 | vec3f(0.0f,1.0f,0.0f), 15 | vec3f(0.0f,0.5f,0.0f) 16 | }; 17 | 18 | int ms_0=1; 19 | int ms_1=2; 20 | int ms_2=4; 21 | int ms_3=8; 22 | 23 | // todo: kanten zum extruden adden 24 | // 0 1 25 | // 2 3 26 | int ms_idx[16][16]= 27 | { 28 | 29 | // #triangles , id0,id1,id2, ... #extrustion edges, id0,id1, .. 30 | // 0 1 2 31 | // 7 3 32 | // 6 5 4 33 | // 3210 34 | // 0 1 - - 35 | // 2 3 - - 36 | {0, 0 },// 0000 37 | 38 | // 0 1 + - 39 | // 2 3 - - 40 | {1, 0,1,7 , 1, 3,2},//7,1 },// 0001 41 | 42 | // 0 1 - + 43 | // 2 3 - - 44 | {1, 1,2,3 , 1, 1,3},//1,3},// 0010 45 | 46 | // 0 1 + + 47 | // 2 3 - - 48 | {2, 0,2,7, 2,3,7 , 1, 6,5},//3,7},// 0011 49 | 50 | // 0 1 - - 51 | // 2 3 + - 52 | {1, 5,6,7 ,1, 1,3},//5,7 },// 0100 53 | 54 | // 0 1 + - 55 | // 2 3 + - 56 | {2, 0,1,6, 1,5,6 , 1, 5,4},//5,1 },// 0101 57 | 58 | // 0 1 - + 59 | // 2 3 + - 60 | {2, 1,2,3, 5,6,7 , 2, 1,3, 4,6 },//1,3, 5,7 },// 0110 61 | 62 | // 0 1 + + 63 | // 2 3 + - 64 | {3, 0,2,3, 0,3,5, 0,5,6 , 1, 6,5},//5,3 },// 0111 65 | 66 | // 0 1 - - 67 | // 2 3 - + 68 | {1, 3,4,5 , 1, 1,3},//3,5},// 1000 69 | 70 | // 0 1 + - 71 | // 2 3 - + 72 | {2, 0,1,7, 3,4,5 ,2, 3,2,4,6},//7,1, 3,5 },// 1001 73 | 74 | // 0 1 - + 75 | // 2 3 - + 76 | {2, 1,2,4, 1,4,5 , 1, 1,6},//1,5 },// 1010 77 | 78 | // 0 1 + + 79 | // 2 3 - + 80 | {3, 0,2,7, 2,5,7, 2,4,5 , 1, 3,5},//7,5 },// 1011 81 | 82 | // 0 1 - - 83 | // 2 3 + + 84 | {2, 3,4,6, 3,6,7 , 1, 1,6},//3,7},// 1100 85 | 86 | // 0 1 + - 87 | // 2 3 + + 88 | {3, 0,1,6, 1,3,6, 3,4,6 , 1, 5,2},//3,1},// 1101 89 | 90 | // 0 1 - + 91 | // 2 3 + + 92 | {3, 1,2,4, 1,4,7, 4,6,7 , 1, 1,6},//1,7},// 1110 93 | 94 | // 0 1 + + 95 | // 2 3 + + 96 | {2, 0,2,6, 2,4,6 ,0}// 1111 97 | }; 98 | -------------------------------------------------------------------------------- /src/Procedural_vbo.h: -------------------------------------------------------------------------------- 1 | struct GeometryVBO 2 | { 3 | std::vector v; // 1 vertices / triangle-strip 4 | // 3 vertices / triangle 5 | // 4 vertices / quad 6 | int handle; 7 | int type; // 3=triangles, 4=quads 8 | int gl_type; // GL_PATCHES / GL_TRIANGLE_STRIP 9 | 10 | bool valid(){return v.size()>0;} 11 | 12 | void gen_vbo(int vbo_type) 13 | { 14 | if(!valid())return; 15 | 16 | this->type=vbo_type; 17 | 18 | if (type==1) gl_type=GL_TRIANGLE_STRIP; else gl_type=GL_PATCHES; 19 | 20 | printf("GeometryVBO gen_vbo start\n"); 21 | glGenBuffers(1, (GLuint *)(&handle)); 22 | glBindBuffer(GL_ARRAY_BUFFER, handle); 23 | glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*v.size(),&v[0], GL_DYNAMIC_DRAW_ARB ); 24 | glBindBuffer(GL_ARRAY_BUFFER, 0); 25 | printf("GeometryVBO gen_vbo done, %d primitives type %d\n",v.size()/type,type); 26 | } 27 | void draw(int repeated=0) 28 | { 29 | if(!valid())return; 30 | if(repeated>0) 31 | { 32 | glDrawArrays( gl_type, 0, v.size()); 33 | return; 34 | } 35 | 36 | // Enable VBO 37 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, handle); // CHECK_GL_ERROR(); 38 | glVertexPointer ( 3, GL_FLOAT,0, (char *) 0); // CHECK_GL_ERROR(); 39 | 40 | glPatchParameteri(GL_PATCH_VERTICES, type); // CHECK_GL_ERROR(); 41 | glDrawArrays( gl_type, 0, v.size()); // CHECK_GL_ERROR(); 42 | //vertexshader: gl_InstanceID (int) 43 | //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); CHECK_GL_ERROR(); 44 | } 45 | void draw_quads(int repeated=0) 46 | { 47 | if(!valid())return; 48 | if(repeated>0){glDrawArrays( GL_QUADS, 0, v.size()); return;} 49 | 50 | // Enable VBO 51 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, handle); // CHECK_GL_ERROR(); 52 | glVertexPointer ( 3, GL_FLOAT,0, (char *) 0); // CHECK_GL_ERROR(); 53 | 54 | glDrawArrays( GL_QUADS, 0, v.size()); // CHECK_GL_ERROR(); 55 | } 56 | }; 57 | -------------------------------------------------------------------------------- /src/Tesselation.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4e3e02af-6533-48a0-8a3c-1e765ae64f03} 6 | 7 | 8 | {ca42af80-ec24-4624-a19c-8436d4d64bda} 9 | 10 | 11 | {d4713a96-531d-41e3-bc61-574c9e896f5e} 12 | 13 | 14 | {fd0a6c95-2621-4249-aa30-770bdf637d8e} 15 | 16 | 17 | {0adbfd04-1975-4093-a7da-3cc4408ce85d} 18 | 19 | 20 | {7d18d40f-4065-499f-a253-095b7d76819a} 21 | 22 | 23 | {a037f0c6-36e5-44f6-b307-41d51e1e2002} 24 | 25 | 26 | {2b17bf1f-cbed-43c2-9581-e7995562e398} 27 | 28 | 29 | {0d604ac1-2419-4338-8200-51a9f1e4cd9e} 30 | 31 | 32 | {3f507a90-131e-4e4f-b96b-c06dbf24e0b4} 33 | 34 | 35 | 36 | 37 | src\Main 38 | 39 | 40 | ext 41 | 42 | 43 | util 44 | 45 | 46 | util 47 | 48 | 49 | util 50 | 51 | 52 | 53 | 54 | src\Main 55 | 56 | 57 | src\Main 58 | 59 | 60 | src\Main 61 | 62 | 63 | src\Main 64 | 65 | 66 | ext 67 | 68 | 69 | ext 70 | 71 | 72 | ext 73 | 74 | 75 | util 76 | 77 | 78 | util 79 | 80 | 81 | util 82 | 83 | 84 | util 85 | 86 | 87 | util 88 | 89 | 90 | procedural 91 | 92 | 93 | procedural 94 | 95 | 96 | procedural 97 | 98 | 99 | procedural 100 | 101 | 102 | procedural 103 | 104 | 105 | procedural 106 | 107 | 108 | 109 | 110 | shader\geo_tri 111 | 112 | 113 | shader\geo_tri 114 | 115 | 116 | shader\geo_tri 117 | 118 | 119 | shader\geo_tri 120 | 121 | 122 | shader\geo_tri 123 | 124 | 125 | shader\geo_quad_holes 126 | 127 | 128 | shader\geo_quad_holes 129 | 130 | 131 | shader\geo_quad_holes 132 | 133 | 134 | shader\geo_quad_holes 135 | 136 | 137 | shader\geo_quad_holes 138 | 139 | 140 | shader\geo_quad 141 | 142 | 143 | shader\geo_quad 144 | 145 | 146 | shader\geo_quad 147 | 148 | 149 | shader\geo_quad 150 | 151 | 152 | shader\geo_quad 153 | 154 | 155 | shader\geo_quad_simple 156 | 157 | 158 | shader\geo_quad_simple 159 | 160 | 161 | -------------------------------------------------------------------------------- /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 | // GL ERROR CHECK 2 | #define CHECK_GL_ERROR() CheckGLError(__FILE__, __LINE__) 3 | // GL ERROR CHECK 4 | int CheckGLError(char *file, int line); 5 | /////////////////////////////////////////// 6 | class Shader 7 | { 8 | public: 9 | Shader(std::string shadername) 10 | { 11 | name=shadername; 12 | 13 | int type[5]= 14 | { 15 | GL_VERTEX_SHADER, 16 | GL_FRAGMENT_SHADER, 17 | GL_TESS_CONTROL_SHADER, 18 | GL_TESS_EVALUATION_SHADER, 19 | GL_GEOMETRY_SHADER 20 | }; 21 | char extension[5][10]= 22 | { 23 | "/vs.txt", 24 | "/frag.txt", 25 | "/tcs.txt", 26 | "/tes.txt", 27 | "/geo.txt" 28 | }; 29 | for (int i=0;i<5;i++) 30 | { 31 | char filename[1000]; 32 | memset(filename,0,1000); 33 | sprintf(filename,"%s%s",shadername.c_str(),extension[i]); 34 | attach(type[i],filename); 35 | }; 36 | link(); 37 | }; 38 | void attach(int type,char* filename) 39 | { 40 | char* mem=read_file(filename); 41 | if(mem==0)return; 42 | GLuint handle = glCreateShader(type); 43 | glShaderSource(handle, 1, (const GLchar**)(&mem), 0); 44 | CHECK_GL_ERROR(); 45 | glCompileShader(handle); 46 | CHECK_GL_ERROR(); 47 | free(mem); 48 | 49 | GLint compileSuccess=0; 50 | GLchar compilerSpew[256]; 51 | 52 | glGetShaderiv(handle, GL_COMPILE_STATUS, &compileSuccess); 53 | CHECK_GL_ERROR(); 54 | if(!compileSuccess) 55 | { 56 | glGetShaderInfoLog(handle, sizeof(compilerSpew), 0, compilerSpew); 57 | printf("Shader %s\n%s\ncompileSuccess=%d\n",filename,compilerSpew,compileSuccess); 58 | CHECK_GL_ERROR(); 59 | while(1);; 60 | } 61 | handles.push_back(handle); 62 | } 63 | void link() 64 | { 65 | program_handle = glCreateProgram(); 66 | for (int i=0;i handles; 159 | GLuint program_handle; 160 | std::string name; 161 | 162 | char* read_file(char* fname) 163 | { 164 | if(fname==NULL) 165 | { 166 | printf ("GLSL read_file 0 pointer\n"); 167 | return 0; 168 | } 169 | else 170 | { 171 | printf ("GLSL Loading %s\n",fname); 172 | } 173 | 174 | FILE * fp = fopen (fname, "rb"); 175 | 176 | if (fp==0) 177 | { 178 | printf ("File %s NOT FOUND\n",fname); 179 | return 0; 180 | } 181 | fseek(fp, 0L, SEEK_END); 182 | int fsize = ftell(fp); 183 | fseek(fp, 0L, SEEK_SET); 184 | char* mem=(char*)malloc(fsize+1); 185 | for(int i=0;iwidth = texWidth; 67 | this->height = texHeight; 68 | 69 | glGenFramebuffersEXT(1, &fbo); 70 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 71 | get_error(); 72 | 73 | // init texture 74 | glGenTextures(1, (GLuint*)&color_tex); 75 | glBindTexture(GL_TEXTURE_2D, color_tex); 76 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 77 | texWidth, texHeight, 0, 78 | GL_RGBA, GL_FLOAT, NULL); 79 | 80 | //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, 81 | // GL_RGBA, GL_UNSIGNED_BYTE, NULL); 82 | 83 | //GL_TEXTURE_2D,GL_RGBA, bmp.width, bmp.height, 84 | // /*GL_RGBA*/GL_BGRA_EXT, GL_UNSIGNED_BYTE, bmp.data ); 85 | 86 | get_error(); 87 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 88 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 89 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 90 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT); 91 | 92 | glFramebufferTexture2DEXT( 93 | GL_FRAMEBUFFER_EXT, 94 | GL_COLOR_ATTACHMENT0_EXT, 95 | GL_TEXTURE_2D, color_tex, 0); 96 | get_error(); 97 | 98 | glGenRenderbuffersEXT(1, &dbo); 99 | glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, dbo); 100 | 101 | glGenTextures(1, (GLuint*)&depth_tex); 102 | glBindTexture(GL_TEXTURE_2D, depth_tex); 103 | //glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, 104 | // texWidth, texHeight, 0, 105 | // GL_DEPTH_COMPONENT, GL_FLOAT, NULL); 106 | get_error(); 107 | //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE); 108 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); 109 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); 110 | glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE); 111 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 112 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 113 | 114 | /* 115 | //Use generated mipmaps if supported 116 | if(GLEE_SGIS_generate_mipmap) 117 | { 118 | glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, true); 119 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 120 | glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST); 121 | } 122 | 123 | //Use maximum anisotropy if supported 124 | if(GLEE_EXT_texture_filter_anisotropic) 125 | { 126 | GLint maxAnisotropy=1; 127 | glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); 128 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy); 129 | } 130 | */ 131 | 132 | glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, 133 | texWidth, texHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT/*GL_UNSIGNED_INT*/, NULL); 134 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, 135 | GL_TEXTURE_2D, depth_tex, 0); 136 | 137 | get_error(); 138 | glBindTexture(GL_TEXTURE_2D, 0);// don't leave this texture bound or fbo (zero) will use it as src, want to use it just as dest GL_DEPTH_ATTACHMENT_EXT 139 | 140 | get_error(); 141 | 142 | check_framebuffer_status(); 143 | 144 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 145 | glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); 146 | } 147 | 148 | private: 149 | 150 | GLuint fbo; // frame buffer object ref 151 | GLuint dbo; // depth buffer object ref 152 | 153 | void get_error() 154 | { 155 | GLenum err = glGetError(); 156 | if (err != GL_NO_ERROR) 157 | { 158 | printf("GL FBO Error: %s\n",gluErrorString(err)); 159 | printf("Programm Stopped!\n"); 160 | while(1);; 161 | } 162 | } 163 | 164 | void check_framebuffer_status() 165 | { 166 | GLenum status; 167 | status = (GLenum) glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 168 | switch(status) { 169 | case GL_FRAMEBUFFER_COMPLETE_EXT: 170 | return; 171 | break; 172 | case GL_FRAMEBUFFER_UNSUPPORTED_EXT: 173 | printf("Unsupported framebuffer format\n"); 174 | break; 175 | case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: 176 | printf("Framebuffer incomplete, missing attachment\n"); 177 | break; 178 | // case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT: 179 | // printf("Framebuffer incomplete, duplicate attachment\n"); 180 | // break; 181 | case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: 182 | printf("Framebuffer incomplete, attached images must have same dimensions\n"); 183 | break; 184 | case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: 185 | printf("Framebuffer incomplete, attached images must have same format\n"); 186 | break; 187 | case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: 188 | printf("Framebuffer incomplete, missing draw buffer\n"); 189 | break; 190 | case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: 191 | printf("Framebuffer incomplete, missing read buffer\n"); 192 | break; 193 | case 0: 194 | printf("Not ok but trying...\n"); 195 | return; 196 | break; 197 | default:; 198 | printf("Framebuffer error code %d\n",status); 199 | break; 200 | }; 201 | printf("Programm Stopped!\n"); 202 | while(1);; 203 | } 204 | }; 205 | --------------------------------------------------------------------------------