├── AntTweakBar.dll ├── Framework.cpp ├── Framework.hpp ├── MarchingCubeTables.hpp ├── README.txt ├── configure.sh ├── core ├── Affine.cpp ├── Algebra.hpp ├── Matrix2x2.cpp ├── Matrix3x3.cpp ├── Matrix4x4.cpp ├── Projection.cpp ├── Transform.hpp ├── Vector2.cpp ├── Vector3.cpp └── Vector4.cpp ├── cube.glsl ├── freeglut.dll ├── glew.hpp ├── include ├── AntTweakBar.h └── GL │ ├── freeglut.h │ ├── freeglut_ext.h │ ├── freeglut_std.h │ ├── glew.h │ ├── glxew.h │ └── wglew.h ├── lib ├── linux │ ├── lin32 │ │ ├── libAntTweakBar.so │ │ ├── libAntTweakBar.so.1 │ │ ├── libGLEW.so │ │ ├── libGLEW.so.1.7 │ │ ├── libGLEW.so.1.7.0 │ │ ├── libglut.so │ │ ├── libglut.so.3 │ │ └── libglut.so.3.9.0 │ └── lin64 │ │ ├── libAntTweakBar.so │ │ ├── libAntTweakBar.so.1 │ │ ├── libGLEW.so │ │ ├── libGLEW.so.1.7 │ │ ├── libGLEW.so.1.7.0 │ │ ├── libglut.so │ │ ├── libglut.so.3 │ │ └── libglut.so.3.9.0 └── windows │ └── win32 │ ├── AntTweakBar.lib │ ├── freeglut.lib │ └── glew32s.lib ├── main.cpp ├── marchingCube.glsl └── premake4.lua /AntTweakBar.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/AntTweakBar.dll -------------------------------------------------------------------------------- /Framework.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // \author J Dupuy 3 | // \brief Utility functions and classes for simple OpenGL demos. 4 | // 5 | //////////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef FRAMEWORK_HPP 8 | #define FRAMEWORK_HPP 9 | 10 | #include 11 | #include "glew.hpp" 12 | 13 | // offset for buffer objects 14 | #define FW_BUFFER_OFFSET(i) ((char*)NULL + (i)) 15 | 16 | namespace fw 17 | { 18 | // Framework exception 19 | class FWException : public std::exception 20 | { 21 | public: 22 | virtual ~FWException() throw() {} 23 | const char* what() const throw() {return mMessage.c_str();} 24 | protected: 25 | std::string mMessage; 26 | }; 27 | 28 | 29 | // Get next power of two 30 | GLuint next_power_of_two(GLuint number); 31 | 32 | 33 | // Build GLSL program 34 | GLvoid build_glsl_program( GLuint program, 35 | const std::string& srcfile, 36 | const std::string& options, 37 | GLboolean link ) throw(FWException); 38 | 39 | 40 | // Check OpenGL errors (uses ARB_debug_output if available) 41 | // (throws an exception if an error is detected) 42 | GLvoid check_gl_error() throw(FWException); 43 | 44 | 45 | // Save a portion of the OpenGL front buffer (= take a screenshot). 46 | // File will be a TGA in BGR format, uncompressed. 47 | // The OpenGL state is restored the way it was before this function call. 48 | GLvoid save_gl_front_buffer( GLint x, 49 | GLint y, 50 | GLsizei width, 51 | GLsizei height) throw(FWException); 52 | 53 | 54 | // Pack four floats in an unsigned integer 55 | // Floats are clamped in range [0,1] 56 | // (follows GL4.2 specs) 57 | GLuint pack_4f_to_uint_10_10_10_2(GLfloat x, 58 | GLfloat y, 59 | GLfloat z, 60 | GLfloat w); 61 | GLuint pack_4fv_to_uint_10_10_10_2(const GLfloat *v); 62 | 63 | // Pack four floats in a signed integer 64 | // Floats are clamped in range [-1,1] 65 | // (follows GL4.2 specs) 66 | GLint pack_4f_to_int_10_10_10_2(GLfloat x, 67 | GLfloat y, 68 | GLfloat z, 69 | GLfloat w); 70 | GLint pack_4fv_to_int_10_10_10_2(const GLfloat *v); 71 | 72 | 73 | // Half to float conversion 74 | GLhalf float_to_half(GLfloat f); 75 | GLfloat half_to_float(GLhalf h); 76 | 77 | 78 | // Basic timer class 79 | class Timer 80 | { 81 | public: 82 | // Constructors / Destructor 83 | Timer(); 84 | 85 | // Manipulation 86 | void Start(); 87 | void Stop() ; 88 | 89 | // Queries 90 | double Ticks() const; 91 | 92 | // Members 93 | private: 94 | double mStartTicks; 95 | double mStopTicks; 96 | bool mIsTicking; 97 | }; 98 | 99 | 100 | // Tga image loader 101 | class Tga 102 | { 103 | public: 104 | // Constants 105 | enum 106 | { 107 | PIXEL_FORMAT_UNKNOWN=0, 108 | PIXEL_FORMAT_LUMINANCE, 109 | PIXEL_FORMAT_LUMINANCE_ALPHA, 110 | PIXEL_FORMAT_BGR, 111 | PIXEL_FORMAT_BGRA 112 | }; 113 | 114 | // Constructors / Destructor 115 | Tga(); 116 | // see Load 117 | explicit Tga(const std::string& filename) throw(FWException); 118 | ~Tga(); 119 | 120 | // Manipulation 121 | // load from a tga file 122 | void Load(const std::string& filename) throw(FWException); 123 | 124 | // Queries 125 | GLushort Width() const; 126 | GLushort Height() const; 127 | GLint PixelFormat() const; 128 | GLubyte* Pixels() const; // data must be used for read only 129 | 130 | private: 131 | // Non copyable 132 | Tga(const Tga& tga); 133 | Tga& operator=(const Tga& tga); 134 | 135 | // Internal manipulation 136 | void _Flip(); 137 | void _LoadColourMapped(std::ifstream&, GLchar*) throw(FWException); 138 | void _LoadLuminance(std::ifstream&, GLchar*) throw(FWException); 139 | void _LoadUnmapped(std::ifstream&, GLchar*) throw(FWException); 140 | void _LoadUnmappedRle(std::ifstream&, GLchar*) throw(FWException); 141 | void _LoadColourMappedRle(std::ifstream&, GLchar*) throw(FWException); 142 | void _LoadLuminanceRle(std::ifstream&, GLchar*) throw(FWException); 143 | void _Clear(); 144 | 145 | // Members 146 | GLubyte* mPixels; 147 | GLushort mWidth; 148 | GLushort mHeight; 149 | GLint mPixelFormat; 150 | }; 151 | 152 | } // namespace fw 153 | 154 | #endif 155 | 156 | -------------------------------------------------------------------------------- /MarchingCubeTables.hpp: -------------------------------------------------------------------------------- 1 | // number of faces to build depending on marching cube case 2 | // 256 entries 3 | const GLint CASE_TO_FACE_COUNT[] = { 4 | 0, 1, 1, 2, 1, 2, 2, 3, 5 | 1, 2, 2, 3, 2, 3, 3, 2, 6 | 1, 2, 2, 3, 2, 3, 3, 4, 7 | 2, 3, 3, 4, 3, 4, 4, 3, 8 | 1, 2, 2, 3, 2, 3, 3, 4, 9 | 2, 3, 3, 4, 3, 4, 4, 3, 10 | 2, 3, 3, 2, 3, 4, 4, 3, 11 | 3, 4, 4, 3, 4, 5, 5, 2, 12 | 1, 2, 2, 3, 2, 3, 3, 4, 13 | 2, 3, 3, 4, 3, 4, 4, 3, 14 | 2, 3, 3, 4, 3, 4, 4, 5, 15 | 3, 4, 4, 5, 4, 5, 5, 4, 16 | 2, 3, 3, 4, 3, 4, 2, 3, 17 | 3, 4, 4, 5, 4, 5, 3, 2, 18 | 3, 4, 4, 3, 4, 5, 3, 2, 19 | 4, 5, 5, 4, 5, 2, 4, 1, 20 | 1, 2, 2, 3, 2, 3, 3, 4, 21 | 2, 3, 3, 4, 3, 4, 4, 3, 22 | 2, 3, 3, 4, 3, 4, 4, 5, 23 | 3, 2, 4, 3, 4, 3, 5, 2, 24 | 2, 3, 3, 4, 3, 4, 4, 5, 25 | 3, 4, 4, 5, 4, 5, 5, 4, 26 | 3, 4, 4, 3, 4, 5, 5, 4, 27 | 4, 3, 5, 2, 5, 4, 2, 1, 28 | 2, 3, 3, 4, 3, 4, 4, 5, 29 | 3, 4, 4, 5, 2, 3, 3, 2, 30 | 3, 4, 4, 5, 4, 5, 5, 2, 31 | 4, 3, 5, 4, 3, 2, 4, 1, 32 | 3, 4, 4, 5, 4, 5, 3, 4, 33 | 4, 5, 5, 2, 3, 4, 2, 1, 34 | 2, 3, 3, 2, 3, 4, 2, 1, 35 | 3, 2, 4, 1, 2, 1, 1, 0 36 | }; 37 | 38 | // face construction table 39 | // 256*5*4 entries 40 | const GLint EDGE_CONNECT_LIST[] = { 41 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 42 | 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 43 | 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 44 | 1, 8, 3, -1, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45 | 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46 | 0, 8, 3, -1, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 47 | 9, 2, 10, -1, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 48 | 2, 8, 3, -1, 2, 10, 8, -1, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, 49 | 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 50 | 0, 11, 2, -1, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 51 | 1, 9, 0, -1, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 52 | 1, 11, 2, -1, 1, 9, 11, -1, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, 53 | 3, 10, 1, -1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 54 | 0, 10, 1, -1, 0, 8, 10, -1, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, 55 | 3, 9, 0, -1, 3, 11, 9, -1, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, 56 | 9, 8, 10, -1, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 57 | 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 58 | 4, 3, 0, -1, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 | 0, 1, 9, -1, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60 | 4, 1, 9, -1, 4, 7, 1, -1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 61 | 1, 2, 10, -1, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62 | 3, 4, 7, -1, 3, 0, 4, -1, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, 63 | 9, 2, 10, -1, 9, 0, 2, -1, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, 64 | 2, 10, 9, -1, 2, 9, 7, -1, 2, 7, 3, -1, 7, 9, 4, -1, -1, -1, -1, -1, 65 | 8, 4, 7, -1, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 66 | 11, 4, 7, -1, 11, 2, 4, -1, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, 67 | 9, 0, 1, -1, 8, 4, 7, -1, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, 68 | 4, 7, 11, -1, 9, 4, 11, -1, 9, 11, 2, -1, 9, 2, 1, -1, -1, -1, -1, -1, 69 | 3, 10, 1, -1, 3, 11, 10, -1, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, 70 | 1, 11, 10, -1, 1, 4, 11, -1, 1, 0, 4, -1, 7, 11, 4, -1, -1, -1, -1, -1, 71 | 4, 7, 8, -1, 9, 0, 11, -1, 9, 11, 10, -1, 11, 0, 3, -1, -1, -1, -1, -1, 72 | 4, 7, 11, -1, 4, 11, 9, -1, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, 73 | 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 74 | 9, 5, 4, -1, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 75 | 0, 5, 4, -1, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 76 | 8, 5, 4, -1, 8, 3, 5, -1, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, 77 | 1, 2, 10, -1, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 78 | 3, 0, 8, -1, 1, 2, 10, -1, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, 79 | 5, 2, 10, -1, 5, 4, 2, -1, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, 80 | 2, 10, 5, -1, 3, 2, 5, -1, 3, 5, 4, -1, 3, 4, 8, -1, -1, -1, -1, -1, 81 | 9, 5, 4, -1, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 82 | 0, 11, 2, -1, 0, 8, 11, -1, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, 83 | 0, 5, 4, -1, 0, 1, 5, -1, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, 84 | 2, 1, 5, -1, 2, 5, 8, -1, 2, 8, 11, -1, 4, 8, 5, -1, -1, -1, -1, -1, 85 | 10, 3, 11, -1, 10, 1, 3, -1, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, 86 | 4, 9, 5, -1, 0, 8, 1, -1, 8, 10, 1, -1, 8, 11, 10, -1, -1, -1, -1, -1, 87 | 5, 4, 0, -1, 5, 0, 11, -1, 5, 11, 10, -1, 11, 0, 3, -1, -1, -1, -1, -1, 88 | 5, 4, 8, -1, 5, 8, 10, -1, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, 89 | 9, 7, 8, -1, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 90 | 9, 3, 0, -1, 9, 5, 3, -1, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, 91 | 0, 7, 8, -1, 0, 1, 7, -1, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, 92 | 1, 5, 3, -1, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 93 | 9, 7, 8, -1, 9, 5, 7, -1, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, 94 | 10, 1, 2, -1, 9, 5, 0, -1, 5, 3, 0, -1, 5, 7, 3, -1, -1, -1, -1, -1, 95 | 8, 0, 2, -1, 8, 2, 5, -1, 8, 5, 7, -1, 10, 5, 2, -1, -1, -1, -1, -1, 96 | 2, 10, 5, -1, 2, 5, 3, -1, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, 97 | 7, 9, 5, -1, 7, 8, 9, -1, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, 98 | 9, 5, 7, -1, 9, 7, 2, -1, 9, 2, 0, -1, 2, 7, 11, -1, -1, -1, -1, -1, 99 | 2, 3, 11, -1, 0, 1, 8, -1, 1, 7, 8, -1, 1, 5, 7, -1, -1, -1, -1, -1, 100 | 11, 2, 1, -1, 11, 1, 7, -1, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, 101 | 9, 5, 8, -1, 8, 5, 7, -1, 10, 1, 3, -1, 10, 3, 11, -1, -1, -1, -1, -1, 102 | 5, 7, 0, -1, 5, 0, 9, -1, 7, 11, 0, -1, 1, 0, 10, -1, 11, 10, 0, -1, 103 | 11, 10, 0, -1, 11, 0, 3, -1, 10, 5, 0, -1, 8, 0, 7, -1, 5, 7, 0, -1, 104 | 11, 10, 5, -1, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 105 | 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 106 | 0, 8, 3, -1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 107 | 9, 0, 1, -1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 108 | 1, 8, 3, -1, 1, 9, 8, -1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, 109 | 1, 6, 5, -1, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 110 | 1, 6, 5, -1, 1, 2, 6, -1, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, 111 | 9, 6, 5, -1, 9, 0, 6, -1, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, 112 | 5, 9, 8, -1, 5, 8, 2, -1, 5, 2, 6, -1, 3, 2, 8, -1, -1, -1, -1, -1, 113 | 2, 3, 11, -1, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 114 | 11, 0, 8, -1, 11, 2, 0, -1, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, 115 | 0, 1, 9, -1, 2, 3, 11, -1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, 116 | 5, 10, 6, -1, 1, 9, 2, -1, 9, 11, 2, -1, 9, 8, 11, -1, -1, -1, -1, -1, 117 | 6, 3, 11, -1, 6, 5, 3, -1, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, 118 | 0, 8, 11, -1, 0, 11, 5, -1, 0, 5, 1, -1, 5, 11, 6, -1, -1, -1, -1, -1, 119 | 3, 11, 6, -1, 0, 3, 6, -1, 0, 6, 5, -1, 0, 5, 9, -1, -1, -1, -1, -1, 120 | 6, 5, 9, -1, 6, 9, 11, -1, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, 121 | 5, 10, 6, -1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 122 | 4, 3, 0, -1, 4, 7, 3, -1, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, 123 | 1, 9, 0, -1, 5, 10, 6, -1, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, 124 | 10, 6, 5, -1, 1, 9, 7, -1, 1, 7, 3, -1, 7, 9, 4, -1, -1, -1, -1, -1, 125 | 6, 1, 2, -1, 6, 5, 1, -1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, 126 | 1, 2, 5, -1, 5, 2, 6, -1, 3, 0, 4, -1, 3, 4, 7, -1, -1, -1, -1, -1, 127 | 8, 4, 7, -1, 9, 0, 5, -1, 0, 6, 5, -1, 0, 2, 6, -1, -1, -1, -1, -1, 128 | 7, 3, 9, -1, 7, 9, 4, -1, 3, 2, 9, -1, 5, 9, 6, -1, 2, 6, 9, -1, 129 | 3, 11, 2, -1, 7, 8, 4, -1, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, 130 | 5, 10, 6, -1, 4, 7, 2, -1, 4, 2, 0, -1, 2, 7, 11, -1, -1, -1, -1, -1, 131 | 0, 1, 9, -1, 4, 7, 8, -1, 2, 3, 11, -1, 5, 10, 6, -1, -1, -1, -1, -1, 132 | 9, 2, 1, -1, 9, 11, 2, -1, 9, 4, 11, -1, 7, 11, 4, -1, 5, 10, 6, -1, 133 | 8, 4, 7, -1, 3, 11, 5, -1, 3, 5, 1, -1, 5, 11, 6, -1, -1, -1, -1, -1, 134 | 5, 1, 11, -1, 5, 11, 6, -1, 1, 0, 11, -1, 7, 11, 4, -1, 0, 4, 11, -1, 135 | 0, 5, 9, -1, 0, 6, 5, -1, 0, 3, 6, -1, 11, 6, 3, -1, 8, 4, 7, -1, 136 | 6, 5, 9, -1, 6, 9, 11, -1, 4, 7, 9, -1, 7, 11, 9, -1, -1, -1, -1, -1, 137 | 10, 4, 9, -1, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 138 | 4, 10, 6, -1, 4, 9, 10, -1, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, 139 | 10, 0, 1, -1, 10, 6, 0, -1, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 140 | 8, 3, 1, -1, 8, 1, 6, -1, 8, 6, 4, -1, 6, 1, 10, -1, -1, -1, -1, -1, 141 | 1, 4, 9, -1, 1, 2, 4, -1, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, 142 | 3, 0, 8, -1, 1, 2, 9, -1, 2, 4, 9, -1, 2, 6, 4, -1, -1, -1, -1, -1, 143 | 0, 2, 4, -1, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 144 | 8, 3, 2, -1, 8, 2, 4, -1, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, 145 | 10, 4, 9, -1, 10, 6, 4, -1, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, 146 | 0, 8, 2, -1, 2, 8, 11, -1, 4, 9, 10, -1, 4, 10, 6, -1, -1, -1, -1, -1, 147 | 3, 11, 2, -1, 0, 1, 6, -1, 0, 6, 4, -1, 6, 1, 10, -1, -1, -1, -1, -1, 148 | 6, 4, 1, -1, 6, 1, 10, -1, 4, 8, 1, -1, 2, 1, 11, -1, 8, 11, 1, -1, 149 | 9, 6, 4, -1, 9, 3, 6, -1, 9, 1, 3, -1, 11, 6, 3, -1, -1, -1, -1, -1, 150 | 8, 11, 1, -1, 8, 1, 0, -1, 11, 6, 1, -1, 9, 1, 4, -1, 6, 4, 1, -1, 151 | 3, 11, 6, -1, 3, 6, 0, -1, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, 152 | 6, 4, 8, -1, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 153 | 7, 10, 6, -1, 7, 8, 10, -1, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, 154 | 0, 7, 3, -1, 0, 10, 7, -1, 0, 9, 10, -1, 6, 7, 10, -1, -1, -1, -1, -1, 155 | 10, 6, 7, -1, 1, 10, 7, -1, 1, 7, 8, -1, 1, 8, 0, -1, -1, -1, -1, -1, 156 | 10, 6, 7, -1, 10, 7, 1, -1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, 157 | 1, 2, 6, -1, 1, 6, 8, -1, 1, 8, 9, -1, 8, 6, 7, -1, -1, -1, -1, -1, 158 | 2, 6, 9, -1, 2, 9, 1, -1, 6, 7, 9, -1, 0, 9, 3, -1, 7, 3, 9, -1, 159 | 7, 8, 0, -1, 7, 0, 6, -1, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, 160 | 7, 3, 2, -1, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 161 | 2, 3, 11, -1, 10, 6, 8, -1, 10, 8, 9, -1, 8, 6, 7, -1, -1, -1, -1, -1, 162 | 2, 0, 7, -1, 2, 7, 11, -1, 0, 9, 7, -1, 6, 7, 10, -1, 9, 10, 7, -1, 163 | 1, 8, 0, -1, 1, 7, 8, -1, 1, 10, 7, -1, 6, 7, 10, -1, 2, 3, 11, -1, 164 | 11, 2, 1, -1, 11, 1, 7, -1, 10, 6, 1, -1, 6, 7, 1, -1, -1, -1, -1, -1, 165 | 8, 9, 6, -1, 8, 6, 7, -1, 9, 1, 6, -1, 11, 6, 3, -1, 1, 3, 6, -1, 166 | 0, 9, 1, -1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 167 | 7, 8, 0, -1, 7, 0, 6, -1, 3, 11, 0, -1, 11, 6, 0, -1, -1, -1, -1, -1, 168 | 7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 169 | 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 170 | 3, 0, 8, -1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 171 | 0, 1, 9, -1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 172 | 8, 1, 9, -1, 8, 3, 1, -1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, 173 | 10, 1, 2, -1, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 174 | 1, 2, 10, -1, 3, 0, 8, -1, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, 175 | 2, 9, 0, -1, 2, 10, 9, -1, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, 176 | 6, 11, 7, -1, 2, 10, 3, -1, 10, 8, 3, -1, 10, 9, 8, -1, -1, -1, -1, -1, 177 | 7, 2, 3, -1, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 178 | 7, 0, 8, -1, 7, 6, 0, -1, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 179 | 2, 7, 6, -1, 2, 3, 7, -1, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, 180 | 1, 6, 2, -1, 1, 8, 6, -1, 1, 9, 8, -1, 8, 7, 6, -1, -1, -1, -1, -1, 181 | 10, 7, 6, -1, 10, 1, 7, -1, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, 182 | 10, 7, 6, -1, 1, 7, 10, -1, 1, 8, 7, -1, 1, 0, 8, -1, -1, -1, -1, -1, 183 | 0, 3, 7, -1, 0, 7, 10, -1, 0, 10, 9, -1, 6, 10, 7, -1, -1, -1, -1, -1, 184 | 7, 6, 10, -1, 7, 10, 8, -1, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, 185 | 6, 8, 4, -1, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 186 | 3, 6, 11, -1, 3, 0, 6, -1, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, 187 | 8, 6, 11, -1, 8, 4, 6, -1, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 188 | 9, 4, 6, -1, 9, 6, 3, -1, 9, 3, 1, -1, 11, 3, 6, -1, -1, -1, -1, -1, 189 | 6, 8, 4, -1, 6, 11, 8, -1, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 190 | 1, 2, 10, -1, 3, 0, 11, -1, 0, 6, 11, -1, 0, 4, 6, -1, -1, -1, -1, -1, 191 | 4, 11, 8, -1, 4, 6, 11, -1, 0, 2, 9, -1, 2, 10, 9, -1, -1, -1, -1, -1, 192 | 10, 9, 3, -1, 10, 3, 2, -1, 9, 4, 3, -1, 11, 3, 6, -1, 4, 6, 3, -1, 193 | 8, 2, 3, -1, 8, 4, 2, -1, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, 194 | 0, 4, 2, -1, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 195 | 1, 9, 0, -1, 2, 3, 4, -1, 2, 4, 6, -1, 4, 3, 8, -1, -1, -1, -1, -1, 196 | 1, 9, 4, -1, 1, 4, 2, -1, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, 197 | 8, 1, 3, -1, 8, 6, 1, -1, 8, 4, 6, -1, 6, 10, 1, -1, -1, -1, -1, -1, 198 | 10, 1, 0, -1, 10, 0, 6, -1, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, 199 | 4, 6, 3, -1, 4, 3, 8, -1, 6, 10, 3, -1, 0, 3, 9, -1, 10, 9, 3, -1, 200 | 10, 9, 4, -1, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 201 | 4, 9, 5, -1, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 202 | 0, 8, 3, -1, 4, 9, 5, -1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, 203 | 5, 0, 1, -1, 5, 4, 0, -1, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, 204 | 11, 7, 6, -1, 8, 3, 4, -1, 3, 5, 4, -1, 3, 1, 5, -1, -1, -1, -1, -1, 205 | 9, 5, 4, -1, 10, 1, 2, -1, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, 206 | 6, 11, 7, -1, 1, 2, 10, -1, 0, 8, 3, -1, 4, 9, 5, -1, -1, -1, -1, -1, 207 | 7, 6, 11, -1, 5, 4, 10, -1, 4, 2, 10, -1, 4, 0, 2, -1, -1, -1, -1, -1, 208 | 3, 4, 8, -1, 3, 5, 4, -1, 3, 2, 5, -1, 10, 5, 2, -1, 11, 7, 6, -1, 209 | 7, 2, 3, -1, 7, 6, 2, -1, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, 210 | 9, 5, 4, -1, 0, 8, 6, -1, 0, 6, 2, -1, 6, 8, 7, -1, -1, -1, -1, -1, 211 | 3, 6, 2, -1, 3, 7, 6, -1, 1, 5, 0, -1, 5, 4, 0, -1, -1, -1, -1, -1, 212 | 6, 2, 8, -1, 6, 8, 7, -1, 2, 1, 8, -1, 4, 8, 5, -1, 1, 5, 8, -1, 213 | 9, 5, 4, -1, 10, 1, 6, -1, 1, 7, 6, -1, 1, 3, 7, -1, -1, -1, -1, -1, 214 | 1, 6, 10, -1, 1, 7, 6, -1, 1, 0, 7, -1, 8, 7, 0, -1, 9, 5, 4, -1, 215 | 4, 0, 10, -1, 4, 10, 5, -1, 0, 3, 10, -1, 6, 10, 7, -1, 3, 7, 10, -1, 216 | 7, 6, 10, -1, 7, 10, 8, -1, 5, 4, 10, -1, 4, 8, 10, -1, -1, -1, -1, -1, 217 | 6, 9, 5, -1, 6, 11, 9, -1, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, 218 | 3, 6, 11, -1, 0, 6, 3, -1, 0, 5, 6, -1, 0, 9, 5, -1, -1, -1, -1, -1, 219 | 0, 11, 8, -1, 0, 5, 11, -1, 0, 1, 5, -1, 5, 6, 11, -1, -1, -1, -1, -1, 220 | 6, 11, 3, -1, 6, 3, 5, -1, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 221 | 1, 2, 10, -1, 9, 5, 11, -1, 9, 11, 8, -1, 11, 5, 6, -1, -1, -1, -1, -1, 222 | 0, 11, 3, -1, 0, 6, 11, -1, 0, 9, 6, -1, 5, 6, 9, -1, 1, 2, 10, -1, 223 | 11, 8, 5, -1, 11, 5, 6, -1, 8, 0, 5, -1, 10, 5, 2, -1, 0, 2, 5, -1, 224 | 6, 11, 3, -1, 6, 3, 5, -1, 2, 10, 3, -1, 10, 5, 3, -1, -1, -1, -1, -1, 225 | 5, 8, 9, -1, 5, 2, 8, -1, 5, 6, 2, -1, 3, 8, 2, -1, -1, -1, -1, -1, 226 | 9, 5, 6, -1, 9, 6, 0, -1, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, 227 | 1, 5, 8, -1, 1, 8, 0, -1, 5, 6, 8, -1, 3, 8, 2, -1, 6, 2, 8, -1, 228 | 1, 5, 6, -1, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 229 | 1, 3, 6, -1, 1, 6, 10, -1, 3, 8, 6, -1, 5, 6, 9, -1, 8, 9, 6, -1, 230 | 10, 1, 0, -1, 10, 0, 6, -1, 9, 5, 0, -1, 5, 6, 0, -1, -1, -1, -1, -1, 231 | 0, 3, 8, -1, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 232 | 10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 233 | 11, 5, 10, -1, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 234 | 11, 5, 10, -1, 11, 7, 5, -1, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 235 | 5, 11, 7, -1, 5, 10, 11, -1, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 236 | 10, 7, 5, -1, 10, 11, 7, -1, 9, 8, 1, -1, 8, 3, 1, -1, -1, -1, -1, -1, 237 | 11, 1, 2, -1, 11, 7, 1, -1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 238 | 0, 8, 3, -1, 1, 2, 7, -1, 1, 7, 5, -1, 7, 2, 11, -1, -1, -1, -1, -1, 239 | 9, 7, 5, -1, 9, 2, 7, -1, 9, 0, 2, -1, 2, 11, 7, -1, -1, -1, -1, -1, 240 | 7, 5, 2, -1, 7, 2, 11, -1, 5, 9, 2, -1, 3, 2, 8, -1, 9, 8, 2, -1, 241 | 2, 5, 10, -1, 2, 3, 5, -1, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, 242 | 8, 2, 0, -1, 8, 5, 2, -1, 8, 7, 5, -1, 10, 2, 5, -1, -1, -1, -1, -1, 243 | 9, 0, 1, -1, 5, 10, 3, -1, 5, 3, 7, -1, 3, 10, 2, -1, -1, -1, -1, -1, 244 | 9, 8, 2, -1, 9, 2, 1, -1, 8, 7, 2, -1, 10, 2, 5, -1, 7, 5, 2, -1, 245 | 1, 3, 5, -1, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 246 | 0, 8, 7, -1, 0, 7, 1, -1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, 247 | 9, 0, 3, -1, 9, 3, 5, -1, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, 248 | 9, 8, 7, -1, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 249 | 5, 8, 4, -1, 5, 10, 8, -1, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, 250 | 5, 0, 4, -1, 5, 11, 0, -1, 5, 10, 11, -1, 11, 3, 0, -1, -1, -1, -1, -1, 251 | 0, 1, 9, -1, 8, 4, 10, -1, 8, 10, 11, -1, 10, 4, 5, -1, -1, -1, -1, -1, 252 | 10, 11, 4, -1, 10, 4, 5, -1, 11, 3, 4, -1, 9, 4, 1, -1, 3, 1, 4, -1, 253 | 2, 5, 1, -1, 2, 8, 5, -1, 2, 11, 8, -1, 4, 5, 8, -1, -1, -1, -1, -1, 254 | 0, 4, 11, -1, 0, 11, 3, -1, 4, 5, 11, -1, 2, 11, 1, -1, 5, 1, 11, -1, 255 | 0, 2, 5, -1, 0, 5, 9, -1, 2, 11, 5, -1, 4, 5, 8, -1, 11, 8, 5, -1, 256 | 9, 4, 5, -1, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 257 | 2, 5, 10, -1, 3, 5, 2, -1, 3, 4, 5, -1, 3, 8, 4, -1, -1, -1, -1, -1, 258 | 5, 10, 2, -1, 5, 2, 4, -1, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 259 | 3, 10, 2, -1, 3, 5, 10, -1, 3, 8, 5, -1, 4, 5, 8, -1, 0, 1, 9, -1, 260 | 5, 10, 2, -1, 5, 2, 4, -1, 1, 9, 2, -1, 9, 4, 2, -1, -1, -1, -1, -1, 261 | 8, 4, 5, -1, 8, 5, 3, -1, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 262 | 0, 4, 5, -1, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 263 | 8, 4, 5, -1, 8, 5, 3, -1, 9, 0, 5, -1, 0, 3, 5, -1, -1, -1, -1, -1, 264 | 9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 265 | 4, 11, 7, -1, 4, 9, 11, -1, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, 266 | 0, 8, 3, -1, 4, 9, 7, -1, 9, 11, 7, -1, 9, 10, 11, -1, -1, -1, -1, -1, 267 | 1, 10, 11, -1, 1, 11, 4, -1, 1, 4, 0, -1, 7, 4, 11, -1, -1, -1, -1, -1, 268 | 3, 1, 4, -1, 3, 4, 8, -1, 1, 10, 4, -1, 7, 4, 11, -1, 10, 11, 4, -1, 269 | 4, 11, 7, -1, 9, 11, 4, -1, 9, 2, 11, -1, 9, 1, 2, -1, -1, -1, -1, -1, 270 | 9, 7, 4, -1, 9, 11, 7, -1, 9, 1, 11, -1, 2, 11, 1, -1, 0, 8, 3, -1, 271 | 11, 7, 4, -1, 11, 4, 2, -1, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 272 | 11, 7, 4, -1, 11, 4, 2, -1, 8, 3, 4, -1, 3, 2, 4, -1, -1, -1, -1, -1, 273 | 2, 9, 10, -1, 2, 7, 9, -1, 2, 3, 7, -1, 7, 4, 9, -1, -1, -1, -1, -1, 274 | 9, 10, 7, -1, 9, 7, 4, -1, 10, 2, 7, -1, 8, 7, 0, -1, 2, 0, 7, -1, 275 | 3, 7, 10, -1, 3, 10, 2, -1, 7, 4, 10, -1, 1, 10, 0, -1, 4, 0, 10, -1, 276 | 1, 10, 2, -1, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 277 | 4, 9, 1, -1, 4, 1, 7, -1, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, 278 | 4, 9, 1, -1, 4, 1, 7, -1, 0, 8, 1, -1, 8, 7, 1, -1, -1, -1, -1, -1, 279 | 4, 0, 3, -1, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 280 | 4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 281 | 9, 10, 8, -1, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 282 | 3, 0, 9, -1, 3, 9, 11, -1, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, 283 | 0, 1, 10, -1, 0, 10, 8, -1, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, 284 | 3, 1, 10, -1, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 285 | 1, 2, 11, -1, 1, 11, 9, -1, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, 286 | 3, 0, 9, -1, 3, 9, 11, -1, 1, 2, 9, -1, 2, 11, 9, -1, -1, -1, -1, -1, 287 | 0, 2, 11, -1, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 288 | 3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 289 | 2, 3, 8, -1, 2, 8, 10, -1, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, 290 | 9, 10, 2, -1, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 291 | 2, 3, 8, -1, 2, 8, 10, -1, 0, 1, 8, -1, 1, 10, 8, -1, -1, -1, -1, -1, 292 | 1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 293 | 1, 3, 8, -1, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 294 | 0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 295 | 0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 296 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 297 | }; 298 | 299 | 300 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Building the sources 2 | -------------------- 3 | 4 | 1 On Windows 5 | Just open the solution with vs2010, and press CTRL+F5. 6 | 7 | 2 On Linux 8 | In a terminal, type "sh configure.sh", then either: 9 | - "make config=release32" or 10 | - "make config=release64" 11 | depending on your system. 12 | You can get more options for build by typing "make help" 13 | 14 | Enjoy ! 15 | 16 | -------------------------------------------------------------------------------- /configure.sh: -------------------------------------------------------------------------------- 1 | echo "Building symbolic links..." 2 | 3 | ln -sf ./libGLEW.so.1.7.0 ./lib/linux/lin32/libGLEW.so.1.7 4 | ln -sf ./libGLEW.so.1.7.0 ./lib/linux/lin32/libGLEW.so 5 | ln -sf ./libglut.so.3.9.0 ./lib/linux/lin32/libglut.so 6 | ln -sf ./libglut.so.3.9.0 ./lib/linux/lin32/libglut.so.3 7 | ln -sf ./libAntTweakBar.so ./lib/linux/lin32/libAntTweakBar.so.1 8 | 9 | ln -sf ./libGLEW.so.1.7.0 ./lib/linux/lin64/libGLEW.so.1.7 10 | ln -sf ./libGLEW.so.1.7.0 ./lib/linux/lin64/libGLEW.so 11 | ln -sf ./libglut.so.3.9.0 ./lib/linux/lin64/libglut.so 12 | ln -sf ./libglut.so.3.9.0 ./lib/linux/lin64/libglut.so.3 13 | ln -sf ./libAntTweakBar.so ./lib/linux/lin64/libAntTweakBar.so.1 14 | 15 | echo "done!" 16 | 17 | -------------------------------------------------------------------------------- /core/Affine.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Transform.hpp" 4 | 5 | //////////////////////////////////////////////////////////////////////////////// 6 | // static data 7 | const Affine Affine::IDENTITY(Matrix3x3::Diagonal(1,1,1), 8 | Vector3(0,0,0), 9 | 1.0f); 10 | 11 | 12 | //////////////////////////////////////////////////////////////////////////////// 13 | // Factories 14 | Affine Affine::Translation(const Vector3& translation) 15 | { 16 | return Affine(Matrix3x3::Diagonal(1,1,1), 17 | translation, 18 | 1.0f); 19 | } 20 | 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | // Explicit constructor 24 | Affine::Affine(const Matrix3x3& unitAxis, 25 | const Vector3& position, 26 | float scale) : 27 | mUnitAxis(unitAxis), 28 | mPosition(position), 29 | mScale(scale), 30 | mIsRS(position == Vector3::ZERO) 31 | { 32 | // if(position != Vector3::ZERO) 33 | // mIsRS = false; 34 | } 35 | 36 | 37 | //////////////////////////////////////////////////////////////////////////////// 38 | // Comparison operators 39 | bool Affine::operator==(const Affine& affine) const 40 | { return !((*this) != affine); } 41 | 42 | bool Affine::operator!=(const Affine& affine) const 43 | { 44 | return ( mUnitAxis != affine.mUnitAxis 45 | || mPosition != affine.mPosition 46 | || mScale != affine.mScale); 47 | } 48 | 49 | 50 | //////////////////////////////////////////////////////////////////////////////// 51 | // Translate 52 | void Affine::TranslateWorld(const Vector3& direction) 53 | { 54 | mPosition += direction; 55 | mIsRS = mPosition == Vector3::ZERO; 56 | } 57 | 58 | void Affine::TranslateLocal(const Vector3& direction) 59 | { 60 | TranslateWorld(mUnitAxis * direction); 61 | } 62 | 63 | 64 | //////////////////////////////////////////////////////////////////////////////// 65 | // RotateWorld 66 | void Affine::RotateAboutWorldX(float radians) 67 | { mUnitAxis = Matrix3x3::RotationAboutX(radians) * mUnitAxis; normalizeAxis(); } 68 | 69 | void Affine::RotateAboutWorldY(float radians) 70 | { mUnitAxis = Matrix3x3::RotationAboutY(radians) * mUnitAxis; normalizeAxis(); } 71 | 72 | void Affine::RotateAboutWorldZ(float radians) 73 | { mUnitAxis = Matrix3x3::RotationAboutZ(radians) * mUnitAxis; normalizeAxis(); } 74 | 75 | 76 | //////////////////////////////////////////////////////////////////////////////// 77 | // RotateLocal 78 | void Affine::RotateAboutLocalX(float radians) 79 | { mUnitAxis *= Matrix3x3::RotationAboutX(radians); 80 | normalizeAxis(); } 81 | 82 | void Affine::RotateAboutLocalY(float radians) 83 | { mUnitAxis *= Matrix3x3::RotationAboutY(radians); 84 | normalizeAxis(); } 85 | 86 | void Affine::RotateAboutLocalZ(float radians) 87 | { mUnitAxis *= Matrix3x3::RotationAboutZ(radians); 88 | normalizeAxis(); } 89 | 90 | 91 | //////////////////////////////////////////////////////////////////////////////// 92 | // Look at 93 | void Affine::LookAt(const Vector3& targetPos, 94 | const Vector3& unitUp) 95 | { 96 | mUnitAxis = Matrix3x3::LookAtRotation(mPosition, targetPos, unitUp); 97 | } 98 | 99 | 100 | //////////////////////////////////////////////////////////////////////////////// 101 | // Reset 102 | void Affine::MakeDefaultAxis() 103 | { 104 | mUnitAxis = Matrix3x3::Diagonal(1,1,1); 105 | } 106 | 107 | void Affine::MakeZeroPosition() 108 | { 109 | mIsRS = true; 110 | mPosition = Vector3(0.0f, 0.0f, 0.0f); 111 | } 112 | 113 | void Affine::MakeUnitScale() 114 | { 115 | mScale = 1.0f; 116 | } 117 | 118 | 119 | //////////////////////////////////////////////////////////////////////////////// 120 | // Matrix extraction 121 | Matrix4x4 Affine::ExtractTransformMatrix() const 122 | { 123 | return Matrix4x4(mUnitAxis[0][0]*mScale, 124 | mUnitAxis[1][0]*mScale, 125 | mUnitAxis[2][0]*mScale, 126 | mPosition[0], 127 | mUnitAxis[0][1]*mScale, 128 | mUnitAxis[1][1]*mScale, 129 | mUnitAxis[2][1]*mScale, 130 | mPosition[1], 131 | mUnitAxis[0][2]*mScale, 132 | mUnitAxis[1][2]*mScale, 133 | mUnitAxis[2][2]*mScale, 134 | mPosition[2], 135 | 0.0f, 0.0f, 0.0f, 1.0f); 136 | } 137 | 138 | Matrix4x4 Affine::ExtractInverseTransformMatrix() const 139 | { 140 | if(mIsRS) 141 | { 142 | // return transpose only 143 | float invScale = 1.0f / mScale; 144 | return Matrix4x4(mUnitAxis[0][0]*invScale, 145 | mUnitAxis[0][1], 146 | mUnitAxis[0][2], 147 | 0.0f, 148 | mUnitAxis[1][0], 149 | mUnitAxis[1][1]*invScale, 150 | mUnitAxis[1][2], 151 | 0.0f, 152 | mUnitAxis[2][0], 153 | mUnitAxis[2][1], 154 | mUnitAxis[2][2]*invScale, 155 | 0.0f, 156 | 0.0f , 0.0f, 0.0f, 1.0f); 157 | } 158 | else 159 | { 160 | // compute full inverse 161 | return ExtractTransformMatrix().Inverse(); 162 | } 163 | } 164 | 165 | 166 | //////////////////////////////////////////////////////////////////////////////// 167 | // Axis queries 168 | const Vector3& Affine::UnitXAxis() const { return mUnitAxis[0]; } 169 | const Vector3& Affine::UnitYAxis() const { return mUnitAxis[1]; } 170 | const Vector3& Affine::UnitZAxis() const { return mUnitAxis[2]; } 171 | 172 | 173 | //////////////////////////////////////////////////////////////////////////////// 174 | // Accessors 175 | const Matrix3x3& Affine::GetUnitAxis() const { return mUnitAxis; } 176 | const Vector3& Affine::GetPosition() const { return mPosition; } 177 | float Affine::GetScale() const { return mScale; } 178 | 179 | 180 | //////////////////////////////////////////////////////////////////////////////// 181 | // Mutators 182 | void Affine::SetPosition(const Vector3& position) 183 | { 184 | mPosition = position; 185 | mIsRS = mPosition == Vector3::ZERO; 186 | } 187 | 188 | void Affine::SetScale(float nonZeroScale) 189 | { 190 | #ifndef NDEBUG 191 | assert(nonZeroScale != 0.0f); 192 | #endif 193 | mScale = nonZeroScale; 194 | } 195 | 196 | 197 | //////////////////////////////////////////////////////////////////////////////// 198 | // Normalize Axis 199 | void Affine::normalizeAxis() 200 | { 201 | mUnitAxis[0] = mUnitAxis[0].Normalize(); 202 | mUnitAxis[1] = mUnitAxis[1].Normalize(); 203 | mUnitAxis[2] = mUnitAxis[2].Normalize(); 204 | } 205 | 206 | 207 | -------------------------------------------------------------------------------- /core/Algebra.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // \file Algebra.hpp 3 | // \author J. Dupuy 4 | // \brief Simple algebra library. 5 | // List of classes 6 | // - Vector2: 2d column vector 7 | // - Vector3: 3d column vector 8 | // - Vector4: 4d column vector 9 | // - Matrix2x2: 2x2 square, column major matrix 10 | // - Matrix3x3: 3x3 square, column major matrix 11 | // - Matrix4x4: 4x4 square, column major matrix 12 | // Notes: 13 | // - angles must be provided in radians 14 | // - user is encouraged to use bracket operators to access members 15 | // 16 | //////////////////////////////////////////////////////////////////////////////// 17 | 18 | #ifndef ALGEBRA_HPP 19 | #define ALGEBRA_HPP 20 | 21 | #include 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | // Vector2 definition 25 | class Vector2 26 | { 27 | public: 28 | // Factories 29 | static Vector2 CompMult(const Vector2& u, 30 | const Vector2& v); 31 | static Vector2 CompDiv(const Vector2& u, 32 | const Vector2& v); 33 | static Vector2 CompPow(const Vector2& base, 34 | const Vector2& exponent); 35 | static Vector2 CompMin(const Vector2& u, 36 | const Vector2& v); 37 | static Vector2 CompMax(const Vector2& u, 38 | const Vector2& v); 39 | static Vector2 CompClamp(const Vector2& v, 40 | const Vector2& min, 41 | const Vector2& max); 42 | 43 | // Factories (continued) 44 | static Vector2 Reflect(const Vector2& incident, 45 | const Vector2& unitNormal); 46 | static Vector2 Refract(const Vector2& unitIncident, 47 | const Vector2& unitNormal, 48 | const float& eta); 49 | 50 | // Static manipulation 51 | static float DotProduct(const Vector2& u, const Vector2& v); 52 | 53 | // Constructors 54 | Vector2(const float& x =0, 55 | const float& y =0); 56 | 57 | // Access operators 58 | const float& operator[](size_t row) const; 59 | float& operator[](size_t row); 60 | 61 | // Arithmetic operators 62 | Vector2 operator+(const Vector2& v) const; 63 | Vector2 operator-(const Vector2& v) const; 64 | Vector2 operator*(const float& s) const; 65 | Vector2 operator/(const float& s) const; 66 | Vector2 operator+() const; 67 | Vector2 operator-() const; 68 | 69 | // Assignment operators 70 | Vector2& operator*=(const float& s); 71 | Vector2& operator+=(const Vector2& v); 72 | Vector2& operator-=(const Vector2& v); 73 | Vector2& operator/=(const float& s); 74 | 75 | // Comparison operators 76 | bool operator==(const Vector2& m) const; 77 | bool operator!=(const Vector2& m) const; 78 | 79 | // Queries 80 | float Length() const; 81 | float LengthSquared() const; 82 | Vector2 Normalize() const; 83 | 84 | // Per component queries 85 | Vector2 Sign() const; 86 | Vector2 Abs() const; 87 | Vector2 Sqr() const; 88 | Vector2 Sqrt() const; 89 | Vector2 Exp() const; 90 | Vector2 Log() const; 91 | Vector2 Log10() const; 92 | Vector2 Ceil() const; 93 | Vector2 Floor() const; 94 | Vector2 Frac() const; 95 | 96 | // Mutators 97 | void SetX(const float& x); 98 | void SetY(const float& y); 99 | 100 | // Accessors 101 | const float& GetX() const; 102 | const float& GetY() const; 103 | 104 | // Constants 105 | static const Vector2 ZERO; 106 | 107 | private: 108 | // Members 109 | float mX, mY; 110 | }; 111 | 112 | 113 | //////////////////////////////////////////////////////////////////////////////// 114 | // Vector3 definition 115 | class Vector3 116 | { 117 | public: 118 | // Factories 119 | static Vector3 CrossProduct(const Vector3& u, 120 | const Vector3& v); 121 | static Vector3 CompMult(const Vector3& u, 122 | const Vector3& v); 123 | static Vector3 CompDiv(const Vector3& u, 124 | const Vector3& v); 125 | static Vector3 CompPow(const Vector3& base, 126 | const Vector3& exponent); 127 | static Vector3 CompMin(const Vector3& u, 128 | const Vector3& v); 129 | static Vector3 CompMax(const Vector3& u, 130 | const Vector3& v); 131 | static Vector3 CompClamp(const Vector3& v, 132 | const Vector3& min, 133 | const Vector3& max); 134 | 135 | // Factories (continued) 136 | static Vector3 Reflect(const Vector3& incident, 137 | const Vector3& unitNormal); 138 | static Vector3 Refract(const Vector3& unitIncident, 139 | const Vector3& unitNormal, 140 | const float& eta); 141 | 142 | // Static manipulation 143 | static float DotProduct(const Vector3& u, const Vector3& v); 144 | 145 | // Constructors 146 | Vector3(const float& x =0, 147 | const float& y =0, 148 | const float& z =0); 149 | 150 | // Access operators 151 | const float& operator[](size_t row) const; 152 | float& operator[](size_t row); 153 | 154 | // Arithmetic operators 155 | Vector3 operator+(const Vector3& v) const; 156 | Vector3 operator-(const Vector3& v) const; 157 | Vector3 operator*(const float& s) const; 158 | Vector3 operator/(const float& s) const; 159 | Vector3 operator+() const; 160 | Vector3 operator-() const; 161 | 162 | // Assignment operators 163 | Vector3& operator+=(const Vector3& v); 164 | Vector3& operator-=(const Vector3& v); 165 | Vector3& operator*=(const float& s); 166 | Vector3& operator/=(const float& s); 167 | 168 | // Comparison operators 169 | bool operator==(const Vector3& m) const; 170 | bool operator!=(const Vector3& m) const; 171 | 172 | // Queries 173 | float Length() const; 174 | float LengthSquared() const; 175 | Vector3 Normalize() const; 176 | 177 | // Per component queries 178 | Vector3 Sign() const; 179 | Vector3 Abs() const; 180 | Vector3 Sqr() const; 181 | Vector3 Sqrt() const; 182 | Vector3 Exp() const; 183 | Vector3 Log() const; 184 | Vector3 Log10() const; 185 | Vector3 Ceil() const; 186 | Vector3 Floor() const; 187 | Vector3 Frac() const; 188 | 189 | // Mutators 190 | void SetX(const float& x); 191 | void SetY(const float& y); 192 | void SetZ(const float& z); 193 | 194 | // Accessors 195 | const float& GetX() const; 196 | const float& GetY() const; 197 | const float& GetZ() const; 198 | 199 | // Constants 200 | static const Vector3 ZERO; 201 | 202 | private: 203 | // Members 204 | float mX, mY, mZ; 205 | }; 206 | 207 | 208 | //////////////////////////////////////////////////////////////////////////////// 209 | // Vector4 definition 210 | class Vector4 211 | { 212 | public: 213 | // Factories 214 | static Vector4 CompMult(const Vector4& u, 215 | const Vector4& v); 216 | static Vector4 CompDiv(const Vector4& u, 217 | const Vector4& v); 218 | static Vector4 CompPow(const Vector4& base, 219 | const Vector4& exponent); 220 | static Vector4 CompMin(const Vector4& u, 221 | const Vector4& v); 222 | static Vector4 CompMax(const Vector4& u, 223 | const Vector4& v); 224 | static Vector4 CompClamp(const Vector4& v, 225 | const Vector4& min, 226 | const Vector4& max); 227 | 228 | // Static manipulation 229 | static float DotProduct(const Vector4& u, const Vector4& v); 230 | 231 | // Constructors 232 | Vector4(const float& x =0, 233 | const float& y =0, 234 | const float& z =0, 235 | const float& w =0); 236 | 237 | // Access operators 238 | const float& operator[](size_t row) const; 239 | float& operator[](size_t row); 240 | 241 | // Arithmetic operators 242 | Vector4 operator+(const Vector4& v) const; 243 | Vector4 operator-(const Vector4& v) const; 244 | Vector4 operator*(const float& s) const; 245 | Vector4 operator/(const float& s) const; 246 | Vector4 operator+() const; 247 | Vector4 operator-() const; 248 | 249 | // Assignment operators 250 | Vector4& operator+=(const Vector4& v); 251 | Vector4& operator-=(const Vector4& v); 252 | Vector4& operator*=(const float& s); 253 | Vector4& operator/=(const float& s); 254 | 255 | // Comparison operators 256 | bool operator==(const Vector4& m) const; 257 | bool operator!=(const Vector4& m) const; 258 | 259 | // Queries 260 | float Length() const; 261 | float LengthSquared() const; 262 | Vector4 Normalize() const; 263 | 264 | // Per component queries 265 | Vector4 Sign() const; 266 | Vector4 Abs() const; 267 | Vector4 Sqr() const; 268 | Vector4 Sqrt() const; 269 | Vector4 Exp() const; 270 | Vector4 Log() const; 271 | Vector4 Log10() const; 272 | Vector4 Ceil() const; 273 | Vector4 Floor() const; 274 | Vector4 Frac() const; 275 | 276 | // Mutators 277 | void SetX(const float& x); 278 | void SetY(const float& y); 279 | void SetZ(const float& z); 280 | void SetW(const float& w); 281 | 282 | // Accessors 283 | const float& GetX() const; 284 | const float& GetY() const; 285 | const float& GetZ() const; 286 | const float& GetW() const; 287 | 288 | // Constants 289 | static const Vector4 ZERO; 290 | 291 | private: 292 | // Members 293 | float mX, mY, mZ, mW; 294 | }; 295 | 296 | 297 | //////////////////////////////////////////////////////////////////////////////// 298 | // Matrix2x2 definition 299 | class Matrix2x2 300 | { 301 | public: 302 | // Factories 303 | static Matrix2x2 CompMult(const Matrix2x2& m1, 304 | const Matrix2x2& m2); 305 | static Matrix2x2 CompDiv(const Matrix2x2& m1, 306 | const Matrix2x2& m2); 307 | static Matrix2x2 CompPow(const Matrix2x2& base, 308 | const Matrix2x2& exponent); 309 | static Matrix2x2 CompMin(const Matrix2x2& m1, 310 | const Matrix2x2& m2); 311 | static Matrix2x2 CompMax(const Matrix2x2& m1, 312 | const Matrix2x2& m2); 313 | static Matrix2x2 CompClamp(const Matrix2x2& m, 314 | const Matrix2x2& min, 315 | const Matrix2x2& max); 316 | 317 | // Factories (continued) 318 | static Matrix2x2 OuterProduct(const Vector2& c, 319 | const Vector2& r); 320 | static Matrix2x2 Diagonal(const float& m00, 321 | const float& m11); 322 | static Matrix2x2 Rotation(const float& radians); 323 | static Matrix2x2 Scale(const float& x, 324 | const float& y); 325 | 326 | // Constructors 327 | Matrix2x2(const Vector2& c0, 328 | const Vector2& c1); 329 | Matrix2x2(const float& m00 =0, const float& m10 =0, 330 | const float& m01 =0, const float& m11 =0); 331 | 332 | // Access operators 333 | const Vector2& operator[](size_t column) const; 334 | Vector2& operator[](size_t column); 335 | 336 | // Arithmetic operators 337 | Matrix2x2 operator+(const Matrix2x2& m) const; 338 | Matrix2x2 operator-(const Matrix2x2& m) const; 339 | Matrix2x2 operator+() const; 340 | Matrix2x2 operator-() const; 341 | Matrix2x2 operator*(const Matrix2x2& m) const; 342 | Vector2 operator*(const Vector2& v) const; 343 | 344 | // Assignment operators 345 | Matrix2x2& operator+=(const Matrix2x2& m); 346 | Matrix2x2& operator-=(const Matrix2x2& m); 347 | Matrix2x2& operator*=(const Matrix2x2& m); 348 | 349 | // Comparison operators 350 | bool operator==(const Matrix2x2& m) const; 351 | bool operator!=(const Matrix2x2& m) const; 352 | 353 | // Queries 354 | bool IsInvertible() const; 355 | float Determinant() const; 356 | Matrix2x2 Inverse() const; 357 | Matrix2x2 Transpose() const; 358 | Matrix2x2 Adjugate() const; 359 | 360 | // Per component queries 361 | Matrix2x2 Sign() const; 362 | Matrix2x2 Abs() const; 363 | Matrix2x2 Sqr() const; 364 | Matrix2x2 Sqrt() const; 365 | Matrix2x2 Exp() const; 366 | Matrix2x2 Log() const; 367 | Matrix2x2 Log10() const; 368 | Matrix2x2 Ceil() const; 369 | Matrix2x2 Floor() const; 370 | Matrix2x2 Frac() const; 371 | 372 | // Constants 373 | static const Matrix2x2 IDENTITY; 374 | 375 | private: 376 | // Members 377 | Vector2 mC0, mC1; // columns 378 | }; 379 | 380 | 381 | //////////////////////////////////////////////////////////////////////////////// 382 | // Matrix3x3 definition 383 | class Matrix3x3 384 | { 385 | public: 386 | // Factories 387 | static Matrix3x3 CompMult(const Matrix3x3& m1, 388 | const Matrix3x3& m2); 389 | static Matrix3x3 CompDiv(const Matrix3x3& m1, 390 | const Matrix3x3& m2); 391 | static Matrix3x3 CompPow(const Matrix3x3& base, 392 | const Matrix3x3& exponent); 393 | static Matrix3x3 CompMin(const Matrix3x3& m1, 394 | const Matrix3x3& m2); 395 | static Matrix3x3 CompMax(const Matrix3x3& m1, 396 | const Matrix3x3& m2); 397 | static Matrix3x3 CompClamp(const Matrix3x3& m, 398 | const Matrix3x3& min, 399 | const Matrix3x3& max); 400 | 401 | // Factories (continued) 402 | static Matrix3x3 OuterProduct(const Vector3& c, 403 | const Vector3& r); 404 | static Matrix3x3 Diagonal(const float& m00, 405 | const float& m11, 406 | const float& m22); 407 | static Matrix3x3 RotationAboutX(const float& radians); 408 | static Matrix3x3 RotationAboutY(const float& radians); 409 | static Matrix3x3 RotationAboutZ(const float& radians); 410 | static Matrix3x3 Rotation(const float& yaw, 411 | const float& pitch, 412 | const float& roll); 413 | static Matrix3x3 RotationAboutAxis(const Vector3& unitAxis, 414 | const float& radians); 415 | static Matrix3x3 VectorRotation(const Vector3& unitFrom, 416 | const Vector3& unitTo); 417 | static Matrix3x3 LookAtRotation(const Vector3& eyePos, 418 | const Vector3& targetPos, 419 | const Vector3& unitUpVector); 420 | static Matrix3x3 Scale(const float& x, 421 | const float& y, 422 | const float& z); 423 | 424 | // Constructors 425 | Matrix3x3(const Vector3& c0, 426 | const Vector3& c1, 427 | const Vector3& c2); 428 | Matrix3x3(const float& m00 =0, const float& m10 =0, const float& m20 =0, 429 | const float& m01 =0, const float& m11 =0, const float& m21 =0, 430 | const float& m02 =0, const float& m12 =0, const float& m22 =0); 431 | 432 | // Access operators 433 | const Vector3& operator[](size_t column) const; 434 | Vector3& operator[](size_t column); 435 | 436 | // Arithmetic operators 437 | Matrix3x3 operator+(const Matrix3x3& m) const; 438 | Matrix3x3 operator-(const Matrix3x3& m) const; 439 | Matrix3x3 operator+() const; 440 | Matrix3x3 operator-() const; 441 | Matrix3x3 operator*(const Matrix3x3& m) const; 442 | Vector3 operator*(const Vector3& v) const; 443 | 444 | // Assignment operators 445 | Matrix3x3& operator+=(const Matrix3x3& m); 446 | Matrix3x3& operator-=(const Matrix3x3& m); 447 | Matrix3x3& operator*=(const Matrix3x3& m); 448 | 449 | // Comparison operators 450 | bool operator==(const Matrix3x3& m) const; 451 | bool operator!=(const Matrix3x3& m) const; 452 | 453 | // Queries 454 | bool IsInvertible() const; 455 | float Determinant() const; 456 | Matrix3x3 Inverse() const; 457 | Matrix3x3 Transpose() const; 458 | Matrix3x3 Adjugate() const; 459 | 460 | // Per component queries 461 | Matrix3x3 Sign() const; 462 | Matrix3x3 Abs() const; 463 | Matrix3x3 Sqr() const; 464 | Matrix3x3 Sqrt() const; 465 | Matrix3x3 Exp() const; 466 | Matrix3x3 Log() const; 467 | Matrix3x3 Log10() const; 468 | Matrix3x3 Ceil() const; 469 | Matrix3x3 Floor() const; 470 | Matrix3x3 Frac() const; 471 | 472 | // Constants 473 | static const Matrix3x3 IDENTITY; 474 | 475 | private: 476 | // Members 477 | Vector3 mC0, mC1, mC2; // columns 478 | }; 479 | 480 | 481 | //////////////////////////////////////////////////////////////////////////////// 482 | // Matrix4x4 definition 483 | class Matrix4x4 484 | { 485 | public: 486 | // Factories 487 | static Matrix4x4 CompMult(const Matrix4x4& m1, 488 | const Matrix4x4& m2); 489 | static Matrix4x4 CompDiv(const Matrix4x4& m1, 490 | const Matrix4x4& m2); 491 | static Matrix4x4 CompPow(const Matrix4x4& base, 492 | const Matrix4x4& exponent); 493 | static Matrix4x4 CompMin(const Matrix4x4& m1, 494 | const Matrix4x4& m2); 495 | static Matrix4x4 CompMax(const Matrix4x4& m1, 496 | const Matrix4x4& m2); 497 | static Matrix4x4 CompClamp(const Matrix4x4& m, 498 | const Matrix4x4& min, 499 | const Matrix4x4& max); 500 | 501 | // Factories (continued) 502 | static Matrix4x4 OuterProduct(const Vector4& c, 503 | const Vector4& r); 504 | static Matrix4x4 Diagonal(const float& m00, 505 | const float& m11, 506 | const float& m22, 507 | const float& m33); 508 | static Matrix4x4 RotationAboutX(const float& radians); 509 | static Matrix4x4 RotationAboutY(const float& radians); 510 | static Matrix4x4 RotationAboutZ(const float& radians); 511 | static Matrix4x4 Rotation(const float& yaw, 512 | const float& pitch, 513 | const float& roll); 514 | static Matrix4x4 RotationAboutAxis(const Vector3& unitAxis, 515 | const float& radians); 516 | static Matrix4x4 VectorRotation(const Vector3& unitFrom, 517 | const Vector3& unitTo); 518 | static Matrix4x4 LookAtRotation(const Vector3& eyePos, 519 | const Vector3& targetPos, 520 | const Vector3& unitUpVector); 521 | static Matrix4x4 Scale(const float& x, 522 | const float& y, 523 | const float& z); 524 | static Matrix4x4 Translation(const Vector3& direction); 525 | static Matrix4x4 LookAt(const Vector3& eyePos, 526 | const Vector3& targetPos, 527 | const Vector3& unitUpVector); 528 | 529 | // Factories (continued) 530 | static Matrix4x4 Ortho(const float& left, 531 | const float& right, 532 | const float& bottom, 533 | const float& top, 534 | const float& near, 535 | const float& far); 536 | static Matrix4x4 Frustum(const float& left, 537 | const float& right, 538 | const float& bottom, 539 | const float& top, 540 | const float& near, 541 | const float& far); 542 | static Matrix4x4 Perspective(const float& fovyRadians, 543 | const float& aspect, 544 | const float& near, 545 | const float& far); 546 | 547 | // Constructors 548 | Matrix4x4(const Vector4& c0, 549 | const Vector4& c1, 550 | const Vector4& c2, 551 | const Vector4& c3); 552 | Matrix4x4(const float& m00 =0, 553 | const float& m10 =0, 554 | const float& m20 =0, 555 | const float& m30 =0, 556 | const float& m01 =0, 557 | const float& m11 =0, 558 | const float& m21 =0, 559 | const float& m31 =0, 560 | const float& m02 =0, 561 | const float& m12 =0, 562 | const float& m22 =0, 563 | const float& m32 =0, 564 | const float& m03 =0, 565 | const float& m13 =0, 566 | const float& m23 =0, 567 | const float& m33 =0); 568 | 569 | // Access operators 570 | const Vector4& operator[](size_t column) const; 571 | Vector4& operator[](size_t column); 572 | 573 | // Arithmetic operators 574 | Matrix4x4 operator+(const Matrix4x4& m) const; 575 | Matrix4x4 operator-(const Matrix4x4& m) const; 576 | Matrix4x4 operator+() const; 577 | Matrix4x4 operator-() const; 578 | Matrix4x4 operator*(const Matrix4x4& m) const; 579 | Vector4 operator*(const Vector4& v) const; 580 | 581 | // Assignment operators 582 | Matrix4x4& operator+=(const Matrix4x4& m); 583 | Matrix4x4& operator-=(const Matrix4x4& m); 584 | Matrix4x4& operator*=(const Matrix4x4& m); 585 | 586 | // Comparison operators 587 | bool operator==(const Matrix4x4& m) const; 588 | bool operator!=(const Matrix4x4& m) const; 589 | 590 | // Queries 591 | bool IsInvertible() const; 592 | float Determinant() const; 593 | Matrix4x4 Inverse() const; 594 | Matrix4x4 Transpose() const; 595 | Matrix4x4 Adjugate() const; 596 | 597 | // Per component queries 598 | Matrix4x4 Sign() const; 599 | Matrix4x4 Abs() const; 600 | Matrix4x4 Sqr() const; 601 | Matrix4x4 Sqrt() const; 602 | Matrix4x4 Exp() const; 603 | Matrix4x4 Log() const; 604 | Matrix4x4 Log10() const; 605 | Matrix4x4 Ceil() const; 606 | Matrix4x4 Floor() const; 607 | Matrix4x4 Frac() const; 608 | 609 | // Constants 610 | static const Matrix4x4 IDENTITY; 611 | 612 | private: 613 | // Hidden constructors 614 | explicit Matrix4x4(const Matrix3x3& m); 615 | 616 | // Members 617 | Vector4 mC0, mC1, mC2, mC3; 618 | }; 619 | 620 | 621 | //////////////////////////////////////////////////////////////////////////////// 622 | // Additionnal operators 623 | Vector2 operator*(const float& s, const Vector2& v); 624 | Vector3 operator*(const float& s, const Vector3& v); 625 | Vector4 operator*(const float& s, const Vector4& v); 626 | Matrix2x2 operator*(const float& s, const Matrix2x2& m); 627 | Matrix3x3 operator*(const float& s, const Matrix3x3& m); 628 | Matrix4x4 operator*(const float& s, const Matrix4x4& m); 629 | 630 | #endif 631 | 632 | -------------------------------------------------------------------------------- /core/Matrix2x2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Algebra.hpp" 5 | 6 | //////////////////////////////////////////////////////////////////////////////// 7 | // Constants 8 | const Matrix2x2 Matrix2x2::IDENTITY(1,0, 9 | 0,1); 10 | 11 | 12 | //////////////////////////////////////////////////////////////////////////////// 13 | // Factories 14 | Matrix2x2 Matrix2x2::CompMult(const Matrix2x2& m1, 15 | const Matrix2x2& m2) 16 | { 17 | return Matrix2x2(Vector2::CompMult(m1[0], m2[0]), 18 | Vector2::CompMult(m1[1], m2[1])); 19 | } 20 | 21 | Matrix2x2 Matrix2x2::CompDiv(const Matrix2x2& m1, 22 | const Matrix2x2& m2) 23 | { 24 | return Matrix2x2(Vector2::CompDiv(m1[0], m2[0]), 25 | Vector2::CompDiv(m1[1], m2[1])); 26 | } 27 | 28 | Matrix2x2 Matrix2x2::CompPow(const Matrix2x2& base, 29 | const Matrix2x2& exponent) 30 | { 31 | return Matrix2x2(Vector2::CompPow(base[0], exponent[0]), 32 | Vector2::CompPow(base[1], exponent[1])); 33 | } 34 | 35 | Matrix2x2 Matrix2x2::CompMin(const Matrix2x2& m1, 36 | const Matrix2x2& m2) 37 | { 38 | return Matrix2x2(Vector2::CompMin(m1[0], m2[0]), 39 | Vector2::CompMin(m1[1], m2[1])); 40 | } 41 | 42 | Matrix2x2 Matrix2x2::CompMax(const Matrix2x2& m1, 43 | const Matrix2x2& m2) 44 | { 45 | return Matrix2x2(Vector2::CompMax(m1[0], m2[0]), 46 | Vector2::CompMax(m1[1], m2[1])); 47 | } 48 | 49 | Matrix2x2 Matrix2x2::CompClamp(const Matrix2x2& m, 50 | const Matrix2x2& min, 51 | const Matrix2x2& max) 52 | { 53 | return Matrix2x2(Vector2::CompClamp(m[0], min[0], max[0]), 54 | Vector2::CompClamp(m[1], min[1], max[1])); 55 | } 56 | 57 | 58 | //////////////////////////////////////////////////////////////////////////////// 59 | // Factories (continued) 60 | Matrix2x2 Matrix2x2::OuterProduct(const Vector2& c, 61 | const Vector2& r) 62 | { 63 | return Matrix2x2(r[0]*c, r[1]*c); 64 | } 65 | 66 | Matrix2x2 Matrix2x2::Diagonal(const float& m00, const float& m11) 67 | { 68 | return Matrix2x2(m00, 0, 69 | 0 , m11); 70 | } 71 | 72 | Matrix2x2 Matrix2x2::Rotation(const float& radians) 73 | { 74 | // do some precomputations 75 | float c = std::cos(radians); 76 | float s = std::sin(radians); 77 | return Matrix2x2( c, -s, 78 | s, c); 79 | } 80 | 81 | Matrix2x2 Matrix2x2::Scale(const float& x, 82 | const float& y) 83 | { 84 | return Diagonal(x, y); 85 | } 86 | 87 | 88 | //////////////////////////////////////////////////////////////////////////////// 89 | // Column Constructor 90 | Matrix2x2::Matrix2x2(const Vector2& c0, 91 | const Vector2& c1): 92 | mC0(c0), mC1(c1) 93 | { 94 | 95 | } 96 | 97 | 98 | //////////////////////////////////////////////////////////////////////////////// 99 | // Scalar Constructor 100 | Matrix2x2::Matrix2x2(const float& m00, const float& m10, 101 | const float& m01, const float& m11): 102 | mC0(Vector2(m00,m01)), 103 | mC1(Vector2(m10,m11)) 104 | { 105 | 106 | } 107 | 108 | 109 | //////////////////////////////////////////////////////////////////////////////// 110 | // Access operators 111 | const Vector2& Matrix2x2::operator[](size_t column) const 112 | { 113 | #ifndef NDEBUG 114 | assert(column < 2); 115 | #endif 116 | return (&mC0)[column]; 117 | } 118 | 119 | Vector2& Matrix2x2::operator[](size_t column) 120 | { 121 | return const_cast< Vector2& > 122 | ((static_cast< const Matrix2x2& >(*this))[column]); 123 | } 124 | 125 | 126 | //////////////////////////////////////////////////////////////////////////////// 127 | // Arithmetic operators 128 | Matrix2x2 Matrix2x2::operator+(const Matrix2x2& m) const 129 | { return Matrix2x2(mC0+m.mC0, mC1+m.mC1); } 130 | 131 | Matrix2x2 Matrix2x2::operator-(const Matrix2x2& m) const 132 | { return Matrix2x2(mC0-m.mC0, mC1-m.mC1); } 133 | 134 | Matrix2x2 Matrix2x2::operator+() const 135 | { return (*this); } 136 | 137 | Matrix2x2 Matrix2x2::operator-() const 138 | { return Matrix2x2(-mC0, -mC1); } 139 | 140 | Matrix2x2 Matrix2x2::operator*(const Matrix2x2& m) const 141 | { 142 | return Matrix2x2( (*this)[0][0]*m[0][0] 143 | + (*this)[1][0]*m[0][1], 144 | (*this)[0][0]*m[1][0] 145 | + (*this)[1][0]*m[1][1], 146 | (*this)[0][1]*m[0][0] 147 | + (*this)[1][1]*m[0][1], 148 | (*this)[0][1]*m[1][0] 149 | + (*this)[1][1]*m[1][1]); 150 | } 151 | 152 | Vector2 Matrix2x2::operator*(const Vector2& v) const 153 | { 154 | return Vector2((*this)[0][0]*v[0]+(*this)[1][0]*v[1], 155 | (*this)[0][1]*v[0]+(*this)[1][1]*v[1]); 156 | } 157 | 158 | 159 | //////////////////////////////////////////////////////////////////////////////// 160 | // Assignment operators 161 | Matrix2x2& Matrix2x2::operator+=(const Matrix2x2& m) 162 | { 163 | mC0 += m.mC0; 164 | mC1 += m.mC1; 165 | return (*this); 166 | } 167 | 168 | Matrix2x2& Matrix2x2::operator-=(const Matrix2x2& m) 169 | { 170 | mC0 -= m.mC0; 171 | mC1 -= m.mC1; 172 | return (*this); 173 | } 174 | 175 | Matrix2x2& Matrix2x2::operator*=(const Matrix2x2& m) 176 | { 177 | return (*this) = (*this) * m; 178 | } 179 | 180 | 181 | //////////////////////////////////////////////////////////////////////////////// 182 | // Comparison operators 183 | bool Matrix2x2::operator==(const Matrix2x2& m) const 184 | { return !((*this) != m); } 185 | 186 | bool Matrix2x2::operator!=(const Matrix2x2& m) const 187 | { return (mC0 != m.mC0 || mC1 != m.mC1); } 188 | 189 | 190 | //////////////////////////////////////////////////////////////////////////////// 191 | // Is Invertible ? 192 | bool Matrix2x2::IsInvertible() const 193 | { 194 | return (Determinant() != 0.0f); 195 | } 196 | 197 | 198 | //////////////////////////////////////////////////////////////////////////////// 199 | // Determinant 200 | float Matrix2x2::Determinant() const 201 | { 202 | return ( (*this)[0][0]*(*this)[1][1] - (*this)[1][0]*(*this)[0][1] ); 203 | } 204 | 205 | 206 | //////////////////////////////////////////////////////////////////////////////// 207 | // Inverse 208 | Matrix2x2 Matrix2x2::Inverse() const 209 | { 210 | #ifndef NDEBUG 211 | assert(IsInvertible()); 212 | #endif 213 | return 1.0f/Determinant() * Adjugate(); 214 | } 215 | 216 | 217 | //////////////////////////////////////////////////////////////////////////////// 218 | // Transpose 219 | Matrix2x2 Matrix2x2::Transpose() const 220 | { 221 | return Matrix2x2( (*this)[0][0], (*this)[0][1], 222 | (*this)[1][0], (*this)[1][1] ); 223 | } 224 | 225 | 226 | //////////////////////////////////////////////////////////////////////////////// 227 | // Adjugate 228 | Matrix2x2 Matrix2x2::Adjugate() const 229 | { 230 | // return transpose of cofactors 231 | return Matrix2x2( (*this)[1][1], -(*this)[0][1], 232 | -(*this)[1][0], (*this)[0][0]); 233 | } 234 | 235 | 236 | //////////////////////////////////////////////////////////////////////////////// 237 | // Queries 238 | Matrix2x2 Matrix2x2::Sign() const 239 | { return Matrix2x2(mC0.Sign(), 240 | mC1.Sign()); } 241 | 242 | Matrix2x2 Matrix2x2::Abs() const 243 | { return Matrix2x2(mC0.Abs(), 244 | mC1.Abs()); } 245 | 246 | Matrix2x2 Matrix2x2::Sqr() const 247 | { return Matrix2x2(mC0.Sqr(), 248 | mC1.Sqr()); } 249 | 250 | Matrix2x2 Matrix2x2::Sqrt() const 251 | { return Matrix2x2(mC0.Sqrt(), 252 | mC1.Sqrt()); } 253 | 254 | Matrix2x2 Matrix2x2::Exp() const 255 | { return Matrix2x2(mC0.Exp(), 256 | mC1.Exp()); } 257 | 258 | Matrix2x2 Matrix2x2::Log() const 259 | { return Matrix2x2(mC0.Log(), 260 | mC1.Log()); } 261 | 262 | Matrix2x2 Matrix2x2::Log10() const 263 | { return Matrix2x2(mC0.Log10(), 264 | mC1.Log10()); } 265 | 266 | Matrix2x2 Matrix2x2::Ceil() const 267 | { return Matrix2x2(mC0.Ceil(), 268 | mC1.Ceil()); } 269 | 270 | Matrix2x2 Matrix2x2::Floor() const 271 | { return Matrix2x2(mC0.Floor(), 272 | mC1.Floor()); } 273 | 274 | Matrix2x2 Matrix2x2::Frac() const 275 | { return Matrix2x2(mC0.Frac(), 276 | mC1.Frac()); } 277 | 278 | 279 | //////////////////////////////////////////////////////////////////////////////// 280 | // Additionnal operators 281 | Matrix2x2 operator*(const float& s, const Matrix2x2& m) 282 | { 283 | return Matrix2x2(s*m[0], s*m[1]); 284 | } 285 | 286 | 287 | #if 0 288 | 289 | int main(int argc, char **argv) 290 | { 291 | Matrix2x2 m = Matrix2x2::IDENTITY; 292 | 293 | } 294 | #endif 295 | 296 | -------------------------------------------------------------------------------- /core/Matrix3x3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Algebra.hpp" 5 | 6 | //////////////////////////////////////////////////////////////////////////////// 7 | // Constants 8 | const Matrix3x3 Matrix3x3::IDENTITY(1,0,0, 9 | 0,1,0, 10 | 0,0,1); 11 | 12 | 13 | //////////////////////////////////////////////////////////////////////////////// 14 | // Factories 15 | Matrix3x3 Matrix3x3::CompMult(const Matrix3x3& m1, 16 | const Matrix3x3& m2) 17 | { 18 | return Matrix3x3(Vector3::CompMult(m1[0], m2[0]), 19 | Vector3::CompMult(m1[1], m2[1]), 20 | Vector3::CompMult(m1[2], m2[2])); 21 | } 22 | 23 | Matrix3x3 Matrix3x3::CompDiv(const Matrix3x3& m1, 24 | const Matrix3x3& m2) 25 | { 26 | return Matrix3x3(Vector3::CompDiv(m1[0], m2[0]), 27 | Vector3::CompDiv(m1[1], m2[1]), 28 | Vector3::CompDiv(m1[2], m2[2])); 29 | } 30 | 31 | Matrix3x3 Matrix3x3::CompPow(const Matrix3x3& base, 32 | const Matrix3x3& exponent) 33 | { 34 | return Matrix3x3(Vector3::CompPow(base[0], exponent[0]), 35 | Vector3::CompPow(base[1], exponent[1]), 36 | Vector3::CompPow(base[2], exponent[2])); 37 | } 38 | 39 | Matrix3x3 Matrix3x3::CompMin(const Matrix3x3& m1, 40 | const Matrix3x3& m2) 41 | { 42 | return Matrix3x3(Vector3::CompMin(m1[0], m2[0]), 43 | Vector3::CompMin(m1[1], m2[1]), 44 | Vector3::CompMin(m1[2], m2[2])); 45 | } 46 | 47 | Matrix3x3 Matrix3x3::CompMax(const Matrix3x3& m1, 48 | const Matrix3x3& m2) 49 | { 50 | return Matrix3x3(Vector3::CompMax(m1[0], m2[0]), 51 | Vector3::CompMax(m1[1], m2[1]), 52 | Vector3::CompMax(m1[2], m2[2])); 53 | } 54 | 55 | Matrix3x3 Matrix3x3::CompClamp(const Matrix3x3& m, 56 | const Matrix3x3& min, 57 | const Matrix3x3& max) 58 | { 59 | return Matrix3x3(Vector3::CompClamp(m[0], min[0], max[0]), 60 | Vector3::CompClamp(m[1], min[1], max[1]), 61 | Vector3::CompClamp(m[2], min[2], max[2])); 62 | } 63 | 64 | 65 | //////////////////////////////////////////////////////////////////////////////// 66 | // Factories (continued) 67 | Matrix3x3 Matrix3x3::OuterProduct(const Vector3& c, 68 | const Vector3& r) 69 | { 70 | return Matrix3x3(r[0]*c, r[1]*c, r[2]*c); 71 | } 72 | 73 | Matrix3x3 Matrix3x3::Diagonal(const float& m00, 74 | const float& m11, 75 | const float& m22) 76 | { 77 | return Matrix3x3(m00, 0 , 0 , 78 | 0 , m11, 0 , 79 | 0 , 0 , m22); 80 | } 81 | 82 | Matrix3x3 Matrix3x3::RotationAboutX(const float& radians) 83 | { 84 | // do some precomputations 85 | float c = std::cos(radians); 86 | float s = std::sin(radians); 87 | return Matrix3x3(1, 0, 0, 88 | 0, c, -s, 89 | 0, s, c); 90 | } 91 | 92 | Matrix3x3 Matrix3x3::RotationAboutY(const float& radians) 93 | { 94 | // do some precomputations 95 | float c = std::cos(radians); 96 | float s = std::sin(radians); 97 | return Matrix3x3( c, 0, s, 98 | 0, 1, 0, 99 | -s, 0, c); 100 | } 101 | 102 | Matrix3x3 Matrix3x3::RotationAboutZ(const float& radians) 103 | { 104 | // do some precomputations 105 | float c = std::cos(radians); 106 | float s = std::sin(radians); 107 | return Matrix3x3(c, -s, 0, 108 | s, c, 0, 109 | 0, 0, 1); 110 | } 111 | 112 | Matrix3x3 Matrix3x3::Rotation(const float& yaw, 113 | const float& pitch, 114 | const float& roll) 115 | { 116 | return RotationAboutX(yaw) * RotationAboutY(pitch) * RotationAboutZ(roll); 117 | } 118 | 119 | Matrix3x3 Matrix3x3::RotationAboutAxis(const Vector3& unitAxis, 120 | const float& radians) 121 | { 122 | // precompute stuff 123 | Vector3 axisSquared(Vector3::CompMult(unitAxis, unitAxis)); 124 | float c = std::cos(radians); 125 | float s = std::sin(radians); 126 | float oneMinusC = 1.0f - c; 127 | float axay = unitAxis[0] * unitAxis[1]; 128 | float axaz = unitAxis[0] * unitAxis[2]; 129 | float ayaz = unitAxis[1] * unitAxis[2]; 130 | 131 | return Matrix3x3( axisSquared[0] * oneMinusC + c, 132 | axay * oneMinusC - unitAxis[2] * s, 133 | axaz * oneMinusC + unitAxis[1] * s, 134 | axay * oneMinusC + unitAxis[2] * s, 135 | axisSquared[1] * oneMinusC + c, 136 | ayaz * oneMinusC - unitAxis[0] * s, 137 | axaz * oneMinusC - unitAxis[1] * s, 138 | ayaz * oneMinusC + unitAxis[0] * s, 139 | axisSquared[2] * oneMinusC + c ); 140 | } 141 | 142 | Matrix3x3 Matrix3x3::VectorRotation(const Vector3& unitFrom, 143 | const Vector3& unitTo) 144 | { 145 | // compute the unit rotation axis 146 | Vector3 v = Vector3::CrossProduct(unitFrom, unitTo); 147 | float e = Vector3::DotProduct(unitFrom, unitTo); 148 | float h = 1.0f / (1.0f + e); 149 | Vector3 hv = h*v; 150 | 151 | // return the matrix 152 | return Matrix3x3(e + hv[0]*v[0], hv[0]*v[1] - v[2], hv[0]*v[2] + v[1], 153 | hv[0]*v[1] + v[2], e + hv[1]*v[1], hv[1]*v[2] - v[0], 154 | hv[0]*v[2] - v[1], hv[1]*v[2] + v[0], e + hv[2]*v[2]); 155 | } 156 | 157 | Matrix3x3 Matrix3x3::LookAtRotation(const Vector3& eyePos, 158 | const Vector3& targetPos, 159 | const Vector3& unitUpVector) 160 | { 161 | #ifndef NDEBUG 162 | assert(eyePos != targetPos && unitUpVector != Vector3::ZERO); 163 | #endif 164 | // using OpenGL2.1 SDK (gluLookAt) 165 | Vector3 f((targetPos - eyePos).Normalize()); 166 | Vector3 s(Vector3::CrossProduct(f, unitUpVector)); 167 | Vector3 u(Vector3::CrossProduct(s, f)); 168 | 169 | return Matrix3x3(s[0], u[0], -f[0], 170 | s[1], u[1], -f[1], 171 | s[2], u[2], -f[2] ); 172 | } 173 | 174 | Matrix3x3 Matrix3x3::Scale(const float& x, 175 | const float& y, 176 | const float& z) 177 | { 178 | return Diagonal(x, y, z); 179 | } 180 | 181 | 182 | //////////////////////////////////////////////////////////////////////////////// 183 | // Column Constructor 184 | Matrix3x3::Matrix3x3(const Vector3& c0, 185 | const Vector3& c1, 186 | const Vector3& c2): 187 | mC0(c0), mC1(c1), mC2(c2) 188 | { 189 | 190 | } 191 | 192 | 193 | //////////////////////////////////////////////////////////////////////////////// 194 | // Scalar Constructor 195 | Matrix3x3::Matrix3x3(const float& m00, const float& m10, const float& m20, 196 | const float& m01, const float& m11, const float& m21, 197 | const float& m02, const float& m12, const float& m22): 198 | mC0(Vector3(m00,m01,m02)), 199 | mC1(Vector3(m10,m11,m12)), 200 | mC2(Vector3(m20,m21,m22)) 201 | { 202 | 203 | } 204 | 205 | 206 | //////////////////////////////////////////////////////////////////////////////// 207 | // Access operators 208 | const Vector3& Matrix3x3::operator[](size_t column) const 209 | { 210 | #ifndef NDEBUG 211 | assert(column < 3); 212 | #endif 213 | return (&mC0)[column]; 214 | } 215 | 216 | Vector3& Matrix3x3::operator[](size_t column) 217 | { 218 | return const_cast< Vector3& > 219 | ((static_cast< const Matrix3x3& >(*this))[column]); 220 | } 221 | 222 | 223 | //////////////////////////////////////////////////////////////////////////////// 224 | // Arithmetic operators 225 | Matrix3x3 Matrix3x3::operator+(const Matrix3x3& m) const 226 | { return Matrix3x3(mC0+m.mC0, mC1+m.mC1, mC2+m.mC2); } 227 | 228 | Matrix3x3 Matrix3x3::operator-(const Matrix3x3& m) const 229 | { return Matrix3x3(mC0-m.mC0, mC1-m.mC1, mC2-m.mC2); } 230 | 231 | Matrix3x3 Matrix3x3::operator+() const 232 | { return (*this); } 233 | 234 | Matrix3x3 Matrix3x3::operator-() const 235 | { return Matrix3x3(-mC0, -mC1, -mC2); } 236 | 237 | Matrix3x3 Matrix3x3::operator*(const Matrix3x3& m) const 238 | { 239 | return Matrix3x3( (*this)[0][0]*m[0][0] 240 | + (*this)[1][0]*m[0][1] 241 | + (*this)[2][0]*m[0][2], 242 | (*this)[0][0]*m[1][0] 243 | + (*this)[1][0]*m[1][1] 244 | + (*this)[2][0]*m[1][2], 245 | (*this)[0][0]*m[2][0] 246 | + (*this)[1][0]*m[2][1] 247 | + (*this)[2][0]*m[2][2], 248 | (*this)[0][1]*m[0][0] 249 | + (*this)[1][1]*m[0][1] 250 | + (*this)[2][1]*m[0][2], 251 | (*this)[0][1]*m[1][0] 252 | + (*this)[1][1]*m[1][1] 253 | + (*this)[2][1]*m[1][2], 254 | (*this)[0][1]*m[2][0] 255 | + (*this)[1][1]*m[2][1] 256 | + (*this)[2][1]*m[2][2], 257 | (*this)[0][2]*m[0][0] 258 | + (*this)[1][2]*m[0][1] 259 | + (*this)[2][2]*m[0][2], 260 | (*this)[0][2]*m[1][0] 261 | + (*this)[1][2]*m[1][1] 262 | + (*this)[2][2]*m[1][2], 263 | (*this)[0][2]*m[2][0] 264 | + (*this)[1][2]*m[2][1] 265 | + (*this)[2][2]*m[2][2] ); 266 | } 267 | 268 | Vector3 Matrix3x3::operator*(const Vector3& v) const 269 | { 270 | return Vector3((*this)[0][0]*v[0]+(*this)[1][0]*v[1]+(*this)[2][0]*v[2], 271 | (*this)[0][1]*v[0]+(*this)[1][1]*v[1]+(*this)[2][1]*v[2], 272 | (*this)[0][2]*v[0]+(*this)[1][2]*v[1]+(*this)[2][2]*v[2]); 273 | } 274 | 275 | 276 | //////////////////////////////////////////////////////////////////////////////// 277 | // Assignment operators 278 | Matrix3x3& Matrix3x3::operator+=(const Matrix3x3& m) 279 | { 280 | mC0 += m.mC0; 281 | mC1 += m.mC1; 282 | mC2 += m.mC2; 283 | return (*this); 284 | } 285 | 286 | Matrix3x3& Matrix3x3::operator-=(const Matrix3x3& m) 287 | { 288 | mC0 -= m.mC0; 289 | mC1 -= m.mC1; 290 | mC2 -= m.mC2; 291 | return (*this); 292 | } 293 | 294 | Matrix3x3& Matrix3x3::operator*=(const Matrix3x3& m) 295 | { 296 | return ((*this) = (*this) * m); 297 | } 298 | 299 | 300 | //////////////////////////////////////////////////////////////////////////////// 301 | // Comparison operators 302 | bool Matrix3x3::operator==(const Matrix3x3& m) const 303 | { return !((*this) != m); } 304 | 305 | bool Matrix3x3::operator!=(const Matrix3x3& m) const 306 | { return (mC0 != m.mC0 || mC1 != m.mC1 || mC2 != m.mC2); } 307 | 308 | 309 | //////////////////////////////////////////////////////////////////////////////// 310 | // Is Invertible ? 311 | bool Matrix3x3::IsInvertible() const 312 | { 313 | return (Determinant() != 0.0f); 314 | } 315 | 316 | 317 | //////////////////////////////////////////////////////////////////////////////// 318 | // Determinant 319 | float Matrix3x3::Determinant() const 320 | { 321 | return ( (*this)[0][0]*( (*this)[1][1]*(*this)[2][2] 322 | -(*this)[2][1]*(*this)[1][2] ) 323 | - (*this)[1][0]*( (*this)[2][1]*(*this)[0][2] 324 | -(*this)[0][1]*(*this)[2][2] ) 325 | + (*this)[2][0]*( (*this)[0][1]*(*this)[1][2] 326 | -(*this)[1][1]*(*this)[0][2] ) ); 327 | } 328 | 329 | 330 | //////////////////////////////////////////////////////////////////////////////// 331 | // Inverse 332 | Matrix3x3 Matrix3x3::Inverse() const 333 | { 334 | #ifndef NDEBUG 335 | assert(IsInvertible()); 336 | #endif 337 | return 1.0f/Determinant() * Adjugate(); 338 | } 339 | 340 | 341 | //////////////////////////////////////////////////////////////////////////////// 342 | // Transpose 343 | Matrix3x3 Matrix3x3::Transpose() const 344 | { 345 | return Matrix3x3((*this)[0][0], (*this)[0][1], (*this)[0][2], 346 | (*this)[1][0], (*this)[1][1], (*this)[1][2], 347 | (*this)[2][0], (*this)[2][1], (*this)[2][2] ); 348 | } 349 | 350 | 351 | //////////////////////////////////////////////////////////////////////////////// 352 | // Adjugate 353 | Matrix3x3 Matrix3x3::Adjugate() const 354 | { 355 | // compute cofactors 356 | float c00 = (*this)[1][1] * (*this)[2][2] - (*this)[1][2] * (*this)[2][1]; 357 | float c10 = (*this)[0][2] * (*this)[2][2] - (*this)[0][1] * (*this)[2][2]; 358 | float c20 = (*this)[0][1] * (*this)[1][2] - (*this)[1][1] * (*this)[0][2]; 359 | float c01 = (*this)[1][2] * (*this)[2][0] - (*this)[1][0] * (*this)[2][2]; 360 | float c11 = (*this)[0][0] * (*this)[2][2] - (*this)[0][2] * (*this)[2][0]; 361 | float c21 = (*this)[1][0] * (*this)[0][2] - (*this)[0][0] * (*this)[1][2]; 362 | float c02 = (*this)[1][0] * (*this)[2][1] - (*this)[1][1] * (*this)[2][0]; 363 | float c12 = (*this)[2][0] * (*this)[0][1] - (*this)[0][0] * (*this)[2][1]; 364 | float c22 = (*this)[0][0] * (*this)[1][1] - (*this)[0][1] * (*this)[1][0]; 365 | 366 | // return transpose of cofactors 367 | return Matrix3x3(c00, c01, c02, 368 | c10, c11, c12, 369 | c20, c21, c22); 370 | } 371 | 372 | 373 | //////////////////////////////////////////////////////////////////////////////// 374 | // Queries 375 | Matrix3x3 Matrix3x3::Sign() const 376 | { return Matrix3x3(mC0.Sign(), 377 | mC1.Sign(), 378 | mC2.Sign()); } 379 | 380 | Matrix3x3 Matrix3x3::Abs() const 381 | { return Matrix3x3(mC0.Abs(), 382 | mC1.Abs(), 383 | mC2.Abs()); } 384 | 385 | Matrix3x3 Matrix3x3::Sqr() const 386 | { return Matrix3x3(mC0.Sqr(), 387 | mC1.Sqr(), 388 | mC2.Sqr()); } 389 | 390 | Matrix3x3 Matrix3x3::Sqrt() const 391 | { return Matrix3x3(mC0.Sqrt(), 392 | mC1.Sqrt(), 393 | mC2.Sqrt()); } 394 | 395 | Matrix3x3 Matrix3x3::Exp() const 396 | { return Matrix3x3(mC0.Exp(), 397 | mC1.Exp(), 398 | mC2.Exp()); } 399 | 400 | Matrix3x3 Matrix3x3::Log() const 401 | { return Matrix3x3(mC0.Log(), 402 | mC1.Log(), 403 | mC2.Log()); } 404 | 405 | Matrix3x3 Matrix3x3::Log10() const 406 | { return Matrix3x3(mC0.Log10(), 407 | mC1.Log10(), 408 | mC2.Log10()); } 409 | 410 | Matrix3x3 Matrix3x3::Ceil() const 411 | { return Matrix3x3(mC0.Ceil(), 412 | mC1.Ceil(), 413 | mC2.Ceil()); } 414 | 415 | Matrix3x3 Matrix3x3::Floor() const 416 | { return Matrix3x3(mC0.Floor(), 417 | mC1.Floor(), 418 | mC2.Floor()); } 419 | 420 | Matrix3x3 Matrix3x3::Frac() const 421 | { return Matrix3x3(mC0.Frac(), 422 | mC1.Frac(), 423 | mC2.Frac()); } 424 | 425 | 426 | //////////////////////////////////////////////////////////////////////////////// 427 | // Additionnal operators 428 | Matrix3x3 operator*(const float& s, const Matrix3x3& m) 429 | { 430 | return Matrix3x3(s*m[0], s*m[1], s*m[2]); 431 | } 432 | 433 | 434 | #if 0 435 | 436 | int main(int argc, char **argv) 437 | { 438 | Matrix3x3 m = Matrix3x3::IDENTITY; 439 | 440 | } 441 | #endif 442 | 443 | -------------------------------------------------------------------------------- /core/Matrix4x4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Algebra.hpp" 5 | 6 | //////////////////////////////////////////////////////////////////////////////// 7 | // Constants 8 | const Matrix4x4 Matrix4x4::IDENTITY(1,0,0,0, 9 | 0,1,0,0, 10 | 0,0,1,0, 11 | 0,0,0,1); 12 | 13 | 14 | //////////////////////////////////////////////////////////////////////////////// 15 | // Factories 16 | Matrix4x4 Matrix4x4::CompMult(const Matrix4x4& m1, 17 | const Matrix4x4& m2) 18 | { 19 | return Matrix4x4(Vector4::CompMult(m1[0], m2[0]), 20 | Vector4::CompMult(m1[1], m2[1]), 21 | Vector4::CompMult(m1[2], m2[2]), 22 | Vector4::CompMult(m1[3], m2[3])); 23 | } 24 | 25 | Matrix4x4 Matrix4x4::CompDiv(const Matrix4x4& m1, 26 | const Matrix4x4& m2) 27 | { 28 | return Matrix4x4(Vector4::CompDiv(m1[0], m2[0]), 29 | Vector4::CompDiv(m1[1], m2[1]), 30 | Vector4::CompDiv(m1[2], m2[2]), 31 | Vector4::CompDiv(m1[3], m2[3])); 32 | } 33 | 34 | Matrix4x4 Matrix4x4::CompPow(const Matrix4x4& base, 35 | const Matrix4x4& exponent) 36 | { 37 | return Matrix4x4(Vector4::CompPow(base[0], exponent[0]), 38 | Vector4::CompPow(base[1], exponent[1]), 39 | Vector4::CompPow(base[2], exponent[2]), 40 | Vector4::CompPow(base[3], exponent[3])); 41 | } 42 | 43 | Matrix4x4 Matrix4x4::CompMin(const Matrix4x4& m1, 44 | const Matrix4x4& m2) 45 | { 46 | return Matrix4x4(Vector4::CompMin(m1[0], m2[0]), 47 | Vector4::CompMin(m1[1], m2[1]), 48 | Vector4::CompMin(m1[2], m2[2]), 49 | Vector4::CompMin(m1[3], m2[3])); 50 | } 51 | 52 | Matrix4x4 Matrix4x4::CompMax(const Matrix4x4& m1, 53 | const Matrix4x4& m2) 54 | { 55 | return Matrix4x4(Vector4::CompMax(m1[0], m2[0]), 56 | Vector4::CompMax(m1[1], m2[1]), 57 | Vector4::CompMax(m1[2], m2[2]), 58 | Vector4::CompMax(m1[3], m2[3])); 59 | } 60 | 61 | Matrix4x4 Matrix4x4::CompClamp(const Matrix4x4& m, 62 | const Matrix4x4& min, 63 | const Matrix4x4& max) 64 | { 65 | return Matrix4x4(Vector4::CompClamp(m[0], min[0], max[0]), 66 | Vector4::CompClamp(m[1], min[1], max[1]), 67 | Vector4::CompClamp(m[2], min[2], max[2]), 68 | Vector4::CompClamp(m[3], min[3], max[3])); 69 | } 70 | 71 | 72 | //////////////////////////////////////////////////////////////////////////////// 73 | // Factories (continued) 74 | Matrix4x4 Matrix4x4::OuterProduct(const Vector4& c, 75 | const Vector4& r) 76 | { 77 | return Matrix4x4(r[0]*c, r[1]*c, r[2]*c, r[3]*c); 78 | } 79 | 80 | Matrix4x4 Matrix4x4::Diagonal(const float& m00, 81 | const float& m11, 82 | const float& m22, 83 | const float& m33) 84 | { 85 | return Matrix4x4(m00, 0 , 0 , 0 , 86 | 0 , m11, 0 , 0 , 87 | 0 , 0 , m22, 0 , 88 | 0 , 0 , 0 , m33); 89 | } 90 | 91 | Matrix4x4 Matrix4x4::RotationAboutX(const float& radians) 92 | { 93 | // do some precomputations 94 | float c = std::cos(radians); 95 | float s = std::sin(radians); 96 | return Matrix4x4(1, 0, 0, 0 , 97 | 0, c, -s, 0 , 98 | 0, s, c, 0 , 99 | 0, 0, 0, 1); 100 | } 101 | 102 | Matrix4x4 Matrix4x4::RotationAboutY(const float& radians) 103 | { 104 | // do some precomputations 105 | float c = std::cos(radians); 106 | float s = std::sin(radians); 107 | return Matrix4x4( c, 0, s, 0, 108 | 0, 1, 0, 0, 109 | -s, 0, c, 0, 110 | 0, 0, 0, 1); 111 | } 112 | 113 | Matrix4x4 Matrix4x4::RotationAboutZ(const float& radians) 114 | { 115 | // do some precomputations 116 | float c = std::cos(radians); 117 | float s = std::sin(radians); 118 | return Matrix4x4(c, -s, 0, 0, 119 | s, c, 0, 0, 120 | 0, 0, 1, 0, 121 | 0, 0, 0, 1); 122 | } 123 | 124 | Matrix4x4 Matrix4x4::Rotation(const float& yaw, 125 | const float& pitch, 126 | const float& roll) 127 | { 128 | // save a few computations by using Matrix3x3 129 | Matrix3x3 r = Matrix3x3::RotationAboutX(yaw); 130 | r *= Matrix3x3::RotationAboutY(pitch); 131 | r *= Matrix3x3::RotationAboutZ(roll); 132 | 133 | return Matrix4x4(r); 134 | } 135 | 136 | Matrix4x4 Matrix4x4::RotationAboutAxis(const Vector3& unitAxis, 137 | const float& radians) 138 | { 139 | return Matrix4x4(Matrix3x3::RotationAboutAxis(unitAxis, radians)); 140 | } 141 | 142 | Matrix4x4 Matrix4x4::VectorRotation(const Vector3& unitFrom, 143 | const Vector3& unitTo) 144 | { 145 | return Matrix4x4(Matrix3x3::VectorRotation(unitFrom, unitTo)); 146 | } 147 | 148 | Matrix4x4 Matrix4x4::LookAtRotation(const Vector3& eyePos, 149 | const Vector3& targetPos, 150 | const Vector3& unitUpVector) 151 | { 152 | return Matrix4x4(Matrix3x3::LookAtRotation(eyePos, 153 | targetPos, 154 | unitUpVector)); 155 | } 156 | 157 | Matrix4x4 Matrix4x4::Scale(const float& x, 158 | const float& y, 159 | const float& z) 160 | { 161 | return Diagonal(x, y, z, 1); 162 | } 163 | 164 | Matrix4x4 Matrix4x4::Translation(const Vector3& direction) 165 | { 166 | return Matrix4x4(1,0,0,direction[0], 167 | 0,1,0,direction[1], 168 | 0,0,1,direction[2], 169 | 0,0,0,1); 170 | } 171 | 172 | Matrix4x4 Matrix4x4::LookAt(const Vector3& eyePos, 173 | const Vector3& targetPos, 174 | const Vector3& unitUpVector) 175 | { 176 | // from OpenGL2.1 SDK (gluLookAt) 177 | return Matrix4x4(Matrix3x3::LookAtRotation(eyePos, 178 | targetPos, 179 | unitUpVector).Transpose()) 180 | * Translation(-eyePos); 181 | } 182 | 183 | //////////////////////////////////////////////////////////////////////////////// 184 | // Factories (continued) 185 | Matrix4x4 Matrix4x4::Ortho(const float& left, 186 | const float& right, 187 | const float& bottom, 188 | const float& top, 189 | const float& near, 190 | const float& far) 191 | { 192 | #ifndef NDEBUG 193 | assert(left != right && bottom != top && near != bottom); 194 | #endif 195 | // do some precomputations 196 | float oneOverRightMinusLeft = 1.0f/(right - left); 197 | float oneOverTopMinusBottom = 1.0f/(top - bottom); 198 | float oneOverFarMinusNear = 1.0f/(far - near); 199 | 200 | // from OpenGL2.1 SDK (glOrtho) 201 | return Matrix4x4(2.0f * oneOverRightMinusLeft, 202 | 0, 203 | 0, 204 | -(right + left) * oneOverRightMinusLeft, 205 | 0, 206 | 2.0f * oneOverTopMinusBottom, 207 | 0, 208 | -(top + bottom) * oneOverTopMinusBottom, 209 | 0, 210 | 0, 211 | -2.0f * oneOverFarMinusNear, 212 | -(far + near) * oneOverFarMinusNear, 213 | 0,0,0,1 ); 214 | } 215 | 216 | 217 | Matrix4x4 Matrix4x4::Frustum(const float& left, 218 | const float& right, 219 | const float& bottom, 220 | const float& top, 221 | const float& near, 222 | const float& far) 223 | { 224 | #ifndef NDEBUG 225 | assert( left != right 226 | && bottom != top 227 | && near < far 228 | && near > 0.0f); 229 | #endif 230 | // do some precomputations 231 | float oneOverRightMinusLeft = 1.0f/(right - left); 232 | float oneOverTopMinusBottom = 1.0f/(top - bottom); 233 | float oneOverFarMinusNear = 1.0f/(far - near); 234 | float twoNearVal = 2.0f * near; 235 | 236 | // from OpenGL2.1 SDK (glFrustum) 237 | return Matrix4x4(twoNearVal * oneOverRightMinusLeft, 238 | 0, 239 | (right + left) * oneOverRightMinusLeft, 240 | 0, 241 | 242 | 0, 243 | twoNearVal * oneOverTopMinusBottom, 244 | (top + bottom) * oneOverTopMinusBottom, 245 | 0, 246 | 247 | 0, 248 | 0, 249 | -(far + near) * oneOverFarMinusNear, 250 | -(twoNearVal*far) * oneOverFarMinusNear, 251 | 0,0,-1,0 ); 252 | } 253 | 254 | 255 | Matrix4x4 Matrix4x4::Perspective(const float& fovyRadians, 256 | const float& aspect, 257 | const float& near, 258 | const float& far) 259 | { 260 | #ifndef NDEBUG 261 | assert( fovyRadians > 0.0f 262 | && aspect > 0.0f 263 | && near < far 264 | && near > 0.0f); 265 | #endif 266 | // from OpenGL2.1 SDK (gluPerspective) 267 | float f = 1.0f/tan(fovyRadians*0.5f); 268 | float invNearMinusFar = 1.0f/(near-far); 269 | return Matrix4x4(f/aspect, 0, 0, 0, 270 | 0 , f, 0, 0, 271 | 0, 0, (far+near)*invNearMinusFar, 272 | 2.0f*near*far*invNearMinusFar, 273 | 0, 0, -1.0f, 0); 274 | 275 | } 276 | 277 | 278 | //////////////////////////////////////////////////////////////////////////////// 279 | // Column Constructor 280 | Matrix4x4::Matrix4x4(const Vector4& c0, 281 | const Vector4& c1, 282 | const Vector4& c2, 283 | const Vector4& c3): 284 | mC0(c0), mC1(c1), mC2(c2), mC3(c3) 285 | { 286 | 287 | } 288 | 289 | 290 | //////////////////////////////////////////////////////////////////////////////// 291 | // Scalar Constructor 292 | Matrix4x4::Matrix4x4(const float& m00, 293 | const float& m10, 294 | const float& m20, 295 | const float& m30, 296 | const float& m01, 297 | const float& m11, 298 | const float& m21, 299 | const float& m31, 300 | const float& m02, 301 | const float& m12, 302 | const float& m22, 303 | const float& m32, 304 | const float& m03, 305 | const float& m13, 306 | const float& m23, 307 | const float& m33): 308 | mC0(Vector4(m00,m01,m02,m03)), 309 | mC1(Vector4(m10,m11,m12,m13)), 310 | mC2(Vector4(m20,m21,m22,m23)), 311 | mC3(Vector4(m30,m31,m32,m33)) 312 | { 313 | 314 | } 315 | 316 | 317 | //////////////////////////////////////////////////////////////////////////////// 318 | // Access operators 319 | const Vector4& Matrix4x4::operator[](size_t column) const 320 | { 321 | #ifndef NDEBUG 322 | assert(column < 4); 323 | #endif 324 | return (&mC0)[column]; 325 | } 326 | 327 | Vector4& Matrix4x4::operator[](size_t column) 328 | { 329 | return const_cast< Vector4& > 330 | ((static_cast< const Matrix4x4& >(*this))[column]); 331 | } 332 | 333 | 334 | //////////////////////////////////////////////////////////////////////////////// 335 | // Arithmetic operators 336 | Matrix4x4 Matrix4x4::operator+(const Matrix4x4& m) const 337 | { return Matrix4x4(mC0+m.mC0, mC1+m.mC1, mC2+m.mC2, mC3+m.mC3); } 338 | 339 | Matrix4x4 Matrix4x4::operator-(const Matrix4x4& m) const 340 | { return Matrix4x4(mC0-m.mC0, mC1-m.mC1, mC2-m.mC2, mC3-m.mC3); } 341 | 342 | Matrix4x4 Matrix4x4::operator+() const 343 | { return (*this); } 344 | 345 | Matrix4x4 Matrix4x4::operator-() const 346 | { return Matrix4x4(-mC0, -mC1, -mC2, -mC3); } 347 | 348 | Matrix4x4 Matrix4x4::operator*(const Matrix4x4& m) const 349 | { 350 | return Matrix4x4( (*this)[0][0]*m[0][0]+(*this)[1][0]*m[0][1] 351 | +(*this)[2][0]*m[0][2]+(*this)[3][0]*m[0][3], 352 | (*this)[0][0]*m[1][0]+(*this)[1][0]*m[1][1] 353 | +(*this)[2][0]*m[1][2]+(*this)[3][0]*m[1][3], 354 | (*this)[0][0]*m[2][0]+(*this)[1][0]*m[2][1] 355 | +(*this)[2][0]*m[2][2]+(*this)[3][0]*m[2][3], 356 | (*this)[0][0]*m[3][0]+(*this)[1][0]*m[3][1] 357 | +(*this)[2][0]*m[3][2]+(*this)[3][0]*m[3][3], 358 | (*this)[0][1]*m[0][0]+(*this)[1][1]*m[0][1] 359 | +(*this)[2][1]*m[0][2]+(*this)[3][1]*m[0][3], 360 | (*this)[0][1]*m[1][0]+(*this)[1][1]*m[1][1] 361 | +(*this)[2][1]*m[1][2]+(*this)[3][1]*m[1][3], 362 | (*this)[0][1]*m[2][0]+(*this)[1][1]*m[2][1] 363 | +(*this)[2][1]*m[2][2]+(*this)[3][1]*m[2][3], 364 | (*this)[0][1]*m[3][0]+(*this)[1][1]*m[3][1] 365 | +(*this)[2][1]*m[3][2]+(*this)[3][1]*m[3][3], 366 | (*this)[0][2]*m[0][0]+(*this)[1][2]*m[0][1] 367 | +(*this)[2][2]*m[0][2]+(*this)[3][2]*m[0][3], 368 | (*this)[0][2]*m[1][0]+(*this)[1][2]*m[1][1] 369 | +(*this)[2][2]*m[1][2]+(*this)[3][2]*m[1][3], 370 | (*this)[0][2]*m[2][0]+(*this)[1][2]*m[2][1] 371 | +(*this)[2][2]*m[2][2]+(*this)[3][2]*m[2][3], 372 | (*this)[0][2]*m[3][0]+(*this)[1][2]*m[3][1] 373 | +(*this)[2][2]*m[3][2]+(*this)[3][2]*m[3][3], 374 | (*this)[0][3]*m[0][0]+(*this)[1][3]*m[0][1] 375 | +(*this)[2][3]*m[0][2]+(*this)[3][3]*m[0][3], 376 | (*this)[0][3]*m[1][0]+(*this)[1][3]*m[1][1] 377 | +(*this)[2][3]*m[1][2]+(*this)[3][3]*m[1][3], 378 | (*this)[0][3]*m[2][0]+(*this)[1][3]*m[2][1] 379 | +(*this)[2][3]*m[2][2]+(*this)[3][3]*m[2][3], 380 | (*this)[0][3]*m[3][0]+(*this)[1][3]*m[2][1] 381 | +(*this)[2][3]*m[3][2]+(*this)[3][3]*m[3][3] ); 382 | } 383 | 384 | Vector4 Matrix4x4::operator*(const Vector4& v) const 385 | { 386 | return Vector4( (*this)[0][0]*v[0]+(*this)[1][0]*v[1] 387 | +(*this)[2][0]*v[2]+(*this)[3][0]*v[3], 388 | (*this)[0][1]*v[0]+(*this)[1][1]*v[1] 389 | +(*this)[2][1]*v[2]+(*this)[3][1]*v[3], 390 | (*this)[0][2]*v[0]+(*this)[1][2]*v[1] 391 | +(*this)[2][2]*v[2]+(*this)[3][2]*v[3], 392 | (*this)[0][3]*v[0]+(*this)[1][3]*v[1] 393 | +(*this)[2][3]*v[2]+(*this)[3][3]*v[3] ); 394 | } 395 | 396 | 397 | //////////////////////////////////////////////////////////////////////////////// 398 | // Assignment operators 399 | Matrix4x4& Matrix4x4::operator+=(const Matrix4x4& m) 400 | { 401 | mC0 += m.mC0; 402 | mC1 += m.mC1; 403 | mC2 += m.mC2; 404 | mC3 += m.mC3; 405 | return (*this); 406 | } 407 | 408 | Matrix4x4& Matrix4x4::operator-=(const Matrix4x4& m) 409 | { 410 | mC0 -= m.mC0; 411 | mC1 -= m.mC1; 412 | mC2 -= m.mC2; 413 | mC3 -= m.mC3; 414 | return (*this); 415 | } 416 | 417 | Matrix4x4& Matrix4x4::operator*=(const Matrix4x4& m) 418 | { 419 | return ((*this) = (*this) * m); 420 | } 421 | 422 | 423 | //////////////////////////////////////////////////////////////////////////////// 424 | // Comparison operators 425 | bool Matrix4x4::operator==(const Matrix4x4& m) const 426 | { return !((*this) != m); } 427 | 428 | bool Matrix4x4::operator!=(const Matrix4x4& m) const 429 | { return (mC0 != m.mC0 || mC1 != m.mC1 || mC2 != m.mC2 || mC3 != m.mC3); } 430 | 431 | 432 | //////////////////////////////////////////////////////////////////////////////// 433 | // Is Invertible ? 434 | bool Matrix4x4::IsInvertible() const 435 | { 436 | return (Determinant() != 0.0f); 437 | } 438 | 439 | 440 | //////////////////////////////////////////////////////////////////////////////// 441 | // Determinant 442 | float Matrix4x4::Determinant() const 443 | { 444 | return ( ((*this)[0][0]*(*this)[1][1] - (*this)[1][0]*(*this)[0][1]) 445 | *((*this)[2][2]*(*this)[3][3] - (*this)[3][2]*(*this)[2][3]) 446 | -((*this)[0][0]*(*this)[2][1] - (*this)[2][0]*(*this)[1][0]) 447 | *((*this)[1][2]*(*this)[3][3] - (*this)[3][2]*(*this)[1][3]) 448 | +((*this)[0][0]*(*this)[3][1] - (*this)[3][0]*(*this)[0][1]) 449 | *((*this)[1][2]*(*this)[2][3] - (*this)[2][2]*(*this)[1][3]) 450 | +((*this)[1][0]*(*this)[2][1] - (*this)[2][0]*(*this)[1][1]) 451 | *((*this)[0][2]*(*this)[3][3] - (*this)[3][2]*(*this)[0][3]) 452 | -((*this)[1][0]*(*this)[3][1] - (*this)[3][0]*(*this)[1][1]) 453 | *((*this)[0][2]*(*this)[2][3] - (*this)[2][2]*(*this)[0][3]) 454 | +((*this)[2][0]*(*this)[3][1] - (*this)[3][0]*(*this)[2][1]) 455 | *((*this)[0][2]*(*this)[1][3] - (*this)[1][2]*(*this)[0][3]) ); 456 | } 457 | 458 | 459 | //////////////////////////////////////////////////////////////////////////////// 460 | // Inverse 461 | Matrix4x4 Matrix4x4::Inverse() const 462 | { 463 | #ifndef NDEBUG 464 | assert(IsInvertible()); 465 | #endif 466 | // use laplace expansion theorem 467 | float s0 = (*this)[0][0] * (*this)[1][1] - (*this)[1][0] * (*this)[0][1]; 468 | float s1 = (*this)[0][0] * (*this)[2][1] - (*this)[2][0] * (*this)[0][1]; 469 | float s2 = (*this)[0][0] * (*this)[3][1] - (*this)[3][0] * (*this)[0][1]; 470 | float s3 = (*this)[1][0] * (*this)[2][1] - (*this)[2][0] * (*this)[1][1]; 471 | float s4 = (*this)[1][0] * (*this)[3][1] - (*this)[3][0] * (*this)[1][1]; 472 | float s5 = (*this)[2][0] * (*this)[3][1] - (*this)[3][0] * (*this)[2][1]; 473 | 474 | float c5 = (*this)[2][2] * (*this)[3][3] - (*this)[3][2] * (*this)[2][3]; 475 | float c4 = (*this)[1][2] * (*this)[3][3] - (*this)[3][2] * (*this)[1][3]; 476 | float c3 = (*this)[1][2] * (*this)[2][3] - (*this)[2][2] * (*this)[1][3]; 477 | float c2 = (*this)[0][2] * (*this)[3][3] - (*this)[3][2] * (*this)[0][3]; 478 | float c1 = (*this)[0][2] * (*this)[2][3] - (*this)[2][2] * (*this)[0][3]; 479 | float c0 = (*this)[0][2] * (*this)[1][3] - (*this)[1][2] * (*this)[0][3]; 480 | 481 | // compute inverse of determinant 482 | float invDet = 1.0f/(s0*c5 -s1*c4 + s2*c3 + s3*c2 - s4*c1 + s5*c0); 483 | 484 | // return transpose of cofactors 485 | return 486 | invDet*Matrix4x4( + (*this)[1][1]*c5 - (*this)[2][1]*c4 + (*this)[3][1]*c3, 487 | - (*this)[1][0]*c5 + (*this)[2][0]*c4 - (*this)[3][0]*c3, 488 | + (*this)[1][3]*s5 - (*this)[2][3]*s4 + (*this)[3][3]*s3, 489 | - (*this)[1][2]*s5 + (*this)[2][2]*s4 - (*this)[3][2]*s3, 490 | 491 | - (*this)[0][1]*c5 + (*this)[2][1]*c2 - (*this)[3][1]*c1, 492 | + (*this)[0][0]*c5 - (*this)[2][0]*c2 + (*this)[3][0]*c1, 493 | - (*this)[0][3]*s5 + (*this)[2][3]*s2 - (*this)[3][3]*s1, 494 | + (*this)[0][2]*s5 - (*this)[2][2]*s2 + (*this)[3][2]*s1, 495 | 496 | + (*this)[0][1]*c4 - (*this)[1][1]*c2 + (*this)[3][1]*c0, 497 | - (*this)[0][0]*c4 + (*this)[1][0]*c2 - (*this)[3][0]*c0, 498 | + (*this)[0][3]*s4 - (*this)[1][3]*s2 + (*this)[3][3]*s0, 499 | - (*this)[0][2]*s4 + (*this)[1][2]*s2 - (*this)[3][2]*s0, 500 | 501 | - (*this)[0][1]*c3 + (*this)[1][1]*c1 - (*this)[2][1]*c0, 502 | + (*this)[0][0]*c3 - (*this)[1][0]*c1 + (*this)[2][0]*c0, 503 | - (*this)[0][3]*s3 + (*this)[1][3]*s1 - (*this)[2][3]*s0, 504 | + (*this)[0][2]*s3 - (*this)[1][2]*s1 + (*this)[2][2]*s0); 505 | } 506 | 507 | 508 | //////////////////////////////////////////////////////////////////////////////// 509 | // Transpose 510 | Matrix4x4 Matrix4x4::Transpose() const 511 | { 512 | return Matrix4x4((*this)[0][0], (*this)[0][1], (*this)[0][2], (*this)[0][3], 513 | (*this)[1][0], (*this)[1][1], (*this)[1][2], (*this)[1][3], 514 | (*this)[2][0], (*this)[2][1], (*this)[2][2], (*this)[2][3], 515 | (*this)[3][0], (*this)[3][1], (*this)[3][2], (*this)[3][3] 516 | ); 517 | } 518 | 519 | 520 | //////////////////////////////////////////////////////////////////////////////// 521 | // Adjugate 522 | Matrix4x4 Matrix4x4::Adjugate() const 523 | { 524 | // use laplace expansion theorem 525 | float s0 = (*this)[0][0] * (*this)[1][1] - (*this)[1][0] * (*this)[0][1]; 526 | float s1 = (*this)[0][0] * (*this)[2][1] - (*this)[2][0] * (*this)[0][1]; 527 | float s2 = (*this)[0][0] * (*this)[3][1] - (*this)[3][0] * (*this)[0][1]; 528 | float s3 = (*this)[1][0] * (*this)[2][1] - (*this)[2][0] * (*this)[1][1]; 529 | float s4 = (*this)[1][0] * (*this)[3][1] - (*this)[3][0] * (*this)[1][1]; 530 | float s5 = (*this)[2][0] * (*this)[3][1] - (*this)[3][0] * (*this)[2][1]; 531 | 532 | float c5 = (*this)[2][2] * (*this)[3][3] - (*this)[3][2] * (*this)[2][3]; 533 | float c4 = (*this)[1][2] * (*this)[3][3] - (*this)[3][2] * (*this)[1][3]; 534 | float c3 = (*this)[1][2] * (*this)[2][3] - (*this)[2][2] * (*this)[1][3]; 535 | float c2 = (*this)[0][2] * (*this)[3][3] - (*this)[3][2] * (*this)[0][3]; 536 | float c1 = (*this)[0][2] * (*this)[2][3] - (*this)[2][2] * (*this)[0][3]; 537 | float c0 = (*this)[0][2] * (*this)[1][3] - (*this)[1][2] * (*this)[0][3]; 538 | 539 | // return transpose of cofactors 540 | return Matrix4x4( + (*this)[1][1]*c5 - (*this)[2][1]*c4 + (*this)[3][1]*c3, 541 | - (*this)[1][0]*c5 + (*this)[2][0]*c4 - (*this)[3][0]*c3, 542 | + (*this)[1][3]*s5 - (*this)[2][3]*s4 + (*this)[3][3]*s3, 543 | - (*this)[1][2]*s5 + (*this)[2][2]*s4 - (*this)[3][2]*s3, 544 | 545 | - (*this)[0][1]*c5 + (*this)[2][1]*c2 - (*this)[3][1]*c1, 546 | + (*this)[0][0]*c5 - (*this)[2][0]*c2 + (*this)[3][0]*c1, 547 | - (*this)[0][3]*s5 + (*this)[2][3]*s2 - (*this)[3][3]*s1, 548 | + (*this)[0][2]*s5 - (*this)[2][2]*s2 + (*this)[3][2]*s1, 549 | 550 | + (*this)[0][1]*c4 - (*this)[1][1]*c2 + (*this)[3][1]*c0, 551 | - (*this)[0][0]*c4 + (*this)[1][0]*c2 - (*this)[3][0]*c0, 552 | + (*this)[0][3]*s4 - (*this)[1][3]*s2 + (*this)[3][3]*s0, 553 | - (*this)[0][2]*s4 + (*this)[1][2]*s2 - (*this)[3][2]*s0, 554 | 555 | - (*this)[0][1]*c3 + (*this)[1][1]*c1 - (*this)[2][1]*c0, 556 | + (*this)[0][0]*c3 - (*this)[1][0]*c1 + (*this)[2][0]*c0, 557 | - (*this)[0][3]*s3 + (*this)[1][3]*s1 - (*this)[2][3]*s0, 558 | + (*this)[0][2]*s3 - (*this)[1][2]*s1 + (*this)[2][2]*s0); 559 | } 560 | 561 | 562 | //////////////////////////////////////////////////////////////////////////////// 563 | // Queries 564 | Matrix4x4 Matrix4x4::Sign() const 565 | { return Matrix4x4(mC0.Sign(), 566 | mC1.Sign(), 567 | mC2.Sign(), 568 | mC3.Sign()); } 569 | 570 | Matrix4x4 Matrix4x4::Abs() const 571 | { return Matrix4x4(mC0.Abs(), 572 | mC1.Abs(), 573 | mC2.Abs(), 574 | mC3.Abs()); } 575 | 576 | Matrix4x4 Matrix4x4::Sqr() const 577 | { return Matrix4x4(mC0.Sqr(), 578 | mC1.Sqr(), 579 | mC2.Sqr(), 580 | mC3.Sqr()); } 581 | 582 | Matrix4x4 Matrix4x4::Sqrt() const 583 | { return Matrix4x4(mC0.Sqrt(), 584 | mC1.Sqrt(), 585 | mC2.Sqrt(), 586 | mC3.Sqrt()); } 587 | 588 | Matrix4x4 Matrix4x4::Exp() const 589 | { return Matrix4x4(mC0.Exp(), 590 | mC1.Exp(), 591 | mC2.Exp(), 592 | mC3.Exp()); } 593 | 594 | Matrix4x4 Matrix4x4::Log() const 595 | { return Matrix4x4(mC0.Log(), 596 | mC1.Log(), 597 | mC2.Log(), 598 | mC3.Log()); } 599 | 600 | Matrix4x4 Matrix4x4::Log10() const 601 | { return Matrix4x4(mC0.Log10(), 602 | mC1.Log10(), 603 | mC2.Log10(), 604 | mC3.Log10()); } 605 | 606 | Matrix4x4 Matrix4x4::Ceil() const 607 | { return Matrix4x4(mC0.Ceil(), 608 | mC1.Ceil(), 609 | mC2.Ceil(), 610 | mC3.Ceil()); } 611 | 612 | Matrix4x4 Matrix4x4::Floor() const 613 | { return Matrix4x4(mC0.Floor(), 614 | mC1.Floor(), 615 | mC2.Floor(), 616 | mC3.Floor()); } 617 | 618 | Matrix4x4 Matrix4x4::Frac() const 619 | { return Matrix4x4(mC0.Frac(), 620 | mC1.Frac(), 621 | mC2.Frac(), 622 | mC3.Frac()); } 623 | 624 | //////////////////////////////////////////////////////////////////////////////// 625 | // Mat3 construtor 626 | Matrix4x4::Matrix4x4(const Matrix3x3& m) : 627 | mC0(m[0][0], m[0][1], m[0][2], 0), 628 | mC1(m[1][0], m[1][1], m[1][2], 0), 629 | mC2(m[2][0], m[2][1], m[2][2], 0), 630 | mC3( 0 , 0 , 0 , 1) 631 | { 632 | } 633 | 634 | 635 | //////////////////////////////////////////////////////////////////////////////// 636 | // Additionnal operators 637 | Matrix4x4 operator*(const float& s, const Matrix4x4& m) 638 | { 639 | return Matrix4x4(s*m[0], s*m[1], s*m[2], s*m[3]); 640 | } 641 | 642 | 643 | #if 0 644 | 645 | int main(int argc, char **argv) 646 | { 647 | Matrix4x4 m = Matrix4x4::IDENTITY; 648 | 649 | } 650 | #endif 651 | 652 | -------------------------------------------------------------------------------- /core/Projection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Transform.hpp" 5 | 6 | 7 | //////////////////////////////////////////////////////////////////////////////// 8 | // Perspective factory 9 | Projection Projection::Perspective(float fovy, 10 | float aspect, 11 | float near, 12 | float far) 13 | { 14 | #ifndef NDEBUG 15 | assert( fovy > 0.0f 16 | && aspect > 0.0f 17 | && near < far 18 | && near > 0.0f); 19 | #endif 20 | 21 | // convert to frustum 22 | float halfHeight = std::tan(fovy*0.5f) * near; 23 | float halfWidth = halfHeight * aspect; 24 | 25 | return Frustum(-halfWidth, 26 | halfWidth, 27 | -halfHeight, 28 | halfHeight, 29 | near, 30 | far); 31 | } 32 | 33 | 34 | //////////////////////////////////////////////////////////////////////////////// 35 | // Frustum factory 36 | Projection Projection::Frustum(float left, 37 | float right, 38 | float bottom, 39 | float top, 40 | float near, 41 | float far) 42 | { 43 | #ifndef NDEBUG 44 | assert( left != right 45 | && bottom != top 46 | && near != far 47 | && near > 0.0f 48 | && far > 0.0f); 49 | #endif 50 | 51 | return Projection(left, 52 | right, 53 | bottom, 54 | top, 55 | near, 56 | far, 57 | PROJECTION_TYPE_PERSPECTIVE); 58 | } 59 | 60 | 61 | //////////////////////////////////////////////////////////////////////////////// 62 | // Ortho factory 63 | Projection Projection::Orthographic(float left, 64 | float right, 65 | float bottom, 66 | float top, 67 | float near, 68 | float far) 69 | { 70 | #ifndef NDEBUG 71 | assert( left != right 72 | && bottom != top 73 | && near != far); 74 | #endif 75 | return Projection(left, 76 | right, 77 | bottom, 78 | top, 79 | near, 80 | far, 81 | PROJECTION_TYPE_ORTHOGRAPHIC); 82 | } 83 | 84 | 85 | //////////////////////////////////////////////////////////////////////////////// 86 | // Explicit constructor 87 | Projection::Projection(float left, 88 | float right, 89 | float bottom, 90 | float top, 91 | float near, 92 | float far, 93 | Projection::ProjectionType type): 94 | mLeft(left), 95 | mRight(right), 96 | mBottom(bottom), 97 | mTop(top), 98 | mNear(near), 99 | mFar(far), 100 | mType(type) 101 | { 102 | } 103 | 104 | 105 | //////////////////////////////////////////////////////////////////////////////// 106 | // Extract Matrix 107 | Matrix4x4 Projection::ExtractTransformMatrix() const 108 | { 109 | if(mType == PROJECTION_TYPE_PERSPECTIVE) 110 | return Matrix4x4::Frustum(mLeft, 111 | mRight, 112 | mBottom, 113 | mTop, 114 | mNear, 115 | mFar); 116 | return Matrix4x4::Ortho(mLeft, 117 | mRight, 118 | mBottom, 119 | mTop, 120 | mNear, 121 | mFar); 122 | } 123 | 124 | Matrix4x4 Projection::ExtractInverseTransformMatrix() const 125 | { 126 | return ExtractTransformMatrix().Inverse(); 127 | } 128 | 129 | 130 | //////////////////////////////////////////////////////////////////////////////// 131 | // Queries 132 | float Projection::Width() const 133 | { return std::abs(mRight - mLeft); } 134 | 135 | float Projection::Height() const 136 | { return std::abs(mTop - mBottom); } 137 | 138 | float Projection::Depth() const 139 | { return std::abs(mFar - mNear); } 140 | 141 | float Projection::Aspect() const 142 | { return Width() / Height(); } 143 | 144 | bool Projection::IsPerspective() const 145 | { return (mType == PROJECTION_TYPE_PERSPECTIVE); } 146 | 147 | bool Projection::IsOrthographic() const 148 | { return (mType == PROJECTION_TYPE_ORTHOGRAPHIC); } 149 | 150 | 151 | //////////////////////////////////////////////////////////////////////////////// 152 | // Fit to aspect 153 | void Projection::FitHeightToAspect(float aspect) 154 | { 155 | // compute factor 156 | float factor = Aspect()/aspect; 157 | 158 | mBottom *= factor; 159 | mTop *= factor; 160 | } 161 | 162 | void Projection::FitWidthToAspect(float aspect) 163 | { 164 | // get current aspect 165 | float factor = aspect/Aspect(); 166 | 167 | mLeft *= factor; 168 | mRight *= factor; 169 | } 170 | 171 | 172 | //////////////////////////////////////////////////////////////////////////////// 173 | // Accessors 174 | const float& Projection::GetLeft() const 175 | {return mLeft;} 176 | const float& Projection::GetRight() const 177 | {return mRight;} 178 | const float& Projection::GetBottom() const 179 | {return mBottom;} 180 | const float& Projection::GetTop() const 181 | {return mTop;} 182 | const float& Projection::GetNear() const 183 | {return mNear;} 184 | const float& Projection::GetFar() const 185 | {return mFar;} 186 | Projection::ProjectionType Projection::GetType() const 187 | {return mType;} 188 | 189 | 190 | //////////////////////////////////////////////////////////////////////////////// 191 | // Mutators 192 | void Projection::SetLeft(float left) 193 | { 194 | #ifndef NDEBUG 195 | assert(left != mRight); 196 | #endif 197 | mLeft = left; 198 | } 199 | 200 | void Projection::SetRight(float right) 201 | { 202 | #ifndef NDEBUG 203 | assert(right != mLeft); 204 | #endif 205 | mRight = right; 206 | } 207 | 208 | void Projection::SetBottom(float bottom) 209 | { 210 | #ifndef NDEBUG 211 | assert(bottom != mTop); 212 | #endif 213 | mBottom = bottom; 214 | } 215 | 216 | void Projection::SetTop(float top) 217 | { 218 | #ifndef NDEBUG 219 | assert(mBottom != top); 220 | #endif 221 | mTop = top; 222 | } 223 | 224 | void Projection::SetNear(float near) 225 | { 226 | #ifndef NDEBUG 227 | assert(near != mFar); 228 | if(mType == PROJECTION_TYPE_PERSPECTIVE) 229 | assert(near > 0.0f); 230 | #endif 231 | mNear = near; 232 | } 233 | 234 | void Projection::SetFar(float far) 235 | { 236 | #ifndef NDEBUG 237 | assert(far != mNear); 238 | if(mType == PROJECTION_TYPE_PERSPECTIVE) 239 | assert(far > 0.0f); 240 | #endif 241 | mFar = far; 242 | } 243 | 244 | void Projection::SetType(Projection::ProjectionType type) 245 | { 246 | mType = type; 247 | } 248 | 249 | 250 | 251 | 252 | 253 | -------------------------------------------------------------------------------- /core/Transform.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // \file Transform.hpp 3 | // \author J Dupuy 4 | // \brief Provides classes to build transformations easily. Every class has at 5 | // least one matrix extraction method. 6 | // List of classes 7 | // - Affine: allows to build affine transformations in a right handed 8 | // cartesian coordinate system. 9 | // - Projection: allows to build projections. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////// 12 | 13 | #ifndef TRANSFORM_HPP 14 | #define TRANSFORM_HPP 15 | 16 | #include "Algebra.hpp" 17 | 18 | //////////////////////////////////////////////////////////////////////////////// 19 | // Affine definition 20 | class Affine 21 | { 22 | public: 23 | // Factories 24 | static Affine Translation(const Vector3& translation); 25 | static Affine RotationAboutX(float radians); 26 | static Affine RotationAboutY(float radians); 27 | static Affine RotationAboutZ(float radians); 28 | static Affine RotationAboutAxis(const Vector3& unitAxis, 29 | float radians); 30 | static Affine Rotation(float yawRadians, 31 | float pitchRadians, 32 | float rollRadians); 33 | static Affine Scale(float nonZeroFactor); 34 | static Affine LookAt(const Vector3& position, 35 | const Vector3& targetPosition, 36 | const Vector3& unitUp); 37 | 38 | // Comparison operators 39 | bool operator==(const Affine& affine) const; 40 | bool operator!=(const Affine& affine) const; 41 | 42 | // Translations 43 | void TranslateWorld(const Vector3& direction); 44 | void TranslateLocal(const Vector3& direction); 45 | 46 | // Rotations 47 | void RotateAboutWorldX(float radians); 48 | void RotateAboutWorldY(float radians); 49 | void RotateAboutWorldZ(float radians); 50 | void RotateAboutLocalX(float radians); 51 | void RotateAboutLocalY(float radians); 52 | void RotateAboutLocalZ(float radians); 53 | 54 | // Look at 55 | void LookAt(const Vector3& targetPos, 56 | const Vector3& unitUp); 57 | 58 | // Resets 59 | void MakeDefaultAxis(); 60 | void MakeZeroPosition(); 61 | void MakeUnitScale(); 62 | 63 | // Matrix extraction 64 | Matrix4x4 ExtractTransformMatrix() const; 65 | Matrix4x4 ExtractInverseTransformMatrix() const; 66 | 67 | // Axis queries 68 | const Vector3& UnitXAxis() const; 69 | const Vector3& UnitYAxis() const; 70 | const Vector3& UnitZAxis() const; 71 | 72 | // Accessors 73 | const Matrix3x3& GetUnitAxis() const; 74 | const Vector3& GetPosition() const; 75 | float GetScale() const; 76 | 77 | // Mutators 78 | void SetScale(float nonZeroScale); 79 | void SetPosition(const Vector3& position); 80 | 81 | // Constants 82 | static const Affine IDENTITY; // neutral transformation 83 | 84 | private: 85 | // Hidden constructors 86 | Affine(const Matrix3x3& unitAxis, 87 | const Vector3& position, 88 | float scale); 89 | 90 | // Internal manipulation 91 | void normalizeAxis(); 92 | 93 | // Members 94 | Matrix3x3 mUnitAxis; // axis 95 | Vector3 mPosition; // position 96 | float mScale; // (uniform) scale 97 | bool mIsRS; // rotation scale only 98 | }; 99 | 100 | 101 | //////////////////////////////////////////////////////////////////////////////// 102 | // Projection definition 103 | class Projection 104 | { 105 | public: 106 | // Constants 107 | enum ProjectionType 108 | { 109 | PROJECTION_TYPE_PERSPECTIVE = 0, 110 | PROJECTION_TYPE_ORTHOGRAPHIC 111 | }; 112 | 113 | // Factories 114 | static Projection Orthographic(float left, 115 | float right, 116 | float bottom, 117 | float top, 118 | float near, 119 | float far); 120 | static Projection Perspective(float fovyRadians, 121 | float aspect, 122 | float near, 123 | float far); 124 | static Projection Frustum(float left, 125 | float right, 126 | float bottom, 127 | float top, 128 | float near, 129 | float far); 130 | 131 | // Manipulation 132 | void FitHeightToAspect(float aspect); 133 | void FitWidthToAspect(float aspect); 134 | 135 | // Matrix extraction 136 | Matrix4x4 ExtractTransformMatrix() const; 137 | Matrix4x4 ExtractInverseTransformMatrix() const; 138 | 139 | // Queries 140 | float Width() const; 141 | float Height() const; 142 | float Depth() const; 143 | float Aspect() const; 144 | bool IsPerspective() const; 145 | bool IsOrthographic() const; 146 | 147 | // Mutators 148 | void SetLeft(float left); 149 | void SetRight(float left); 150 | void SetBottom(float left); 151 | void SetTop(float left); 152 | void SetNear(float left); 153 | void SetFar(float left); 154 | void SetType(ProjectionType type); 155 | 156 | // Accessors 157 | const float& GetLeft() const; 158 | const float& GetRight() const; 159 | const float& GetBottom() const; 160 | const float& GetTop() const; 161 | const float& GetNear() const; 162 | const float& GetFar() const; 163 | ProjectionType GetType() const; 164 | 165 | private: 166 | 167 | // Hidden construtors 168 | Projection(float left, 169 | float right, 170 | float bottom, 171 | float top, 172 | float near, 173 | float far, 174 | ProjectionType type); 175 | 176 | // Members 177 | float mLeft; 178 | float mRight; 179 | float mBottom; 180 | float mTop; 181 | float mNear; 182 | float mFar; 183 | ProjectionType mType; 184 | }; 185 | 186 | #endif 187 | 188 | -------------------------------------------------------------------------------- /core/Vector2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "Algebra.hpp" 6 | 7 | //////////////////////////////////////////////////////////////////////////////// 8 | // Constants 9 | const Vector2 Vector2::ZERO(0.0f,0.0f); 10 | 11 | 12 | //////////////////////////////////////////////////////////////////////////////// 13 | // Factories 14 | Vector2 Vector2::CompMult(const Vector2& u, 15 | const Vector2& v) 16 | { return Vector2(u[0]*v[0], u[1]*v[1]); } 17 | 18 | Vector2 Vector2::CompDiv(const Vector2& u, 19 | const Vector2& v) 20 | { return Vector2(u[0]/v[0], u[1]/v[1]); } 21 | 22 | Vector2 Vector2::CompPow(const Vector2& base, 23 | const Vector2& exponent) 24 | { return Vector2(std::pow(base[0],exponent[0]), 25 | std::pow(base[1],exponent[1])); } 26 | 27 | Vector2 Vector2::CompMin(const Vector2& u, 28 | const Vector2& v) 29 | { return Vector2(std::min(u[0],v[0]), 30 | std::min(u[1],v[1])); } 31 | 32 | Vector2 Vector2::CompMax(const Vector2& u, 33 | const Vector2& v) 34 | { return Vector2(std::max(u[0],v[0]), 35 | std::max(u[1],v[1])); } 36 | 37 | Vector2 Vector2::CompClamp(const Vector2& v, 38 | const Vector2& min, 39 | const Vector2& max) 40 | { return CompMin(CompMax(v, min), max); } 41 | 42 | 43 | //////////////////////////////////////////////////////////////////////////////// 44 | // Factories (continued) 45 | Vector2 Vector2::Reflect(const Vector2& incident, 46 | const Vector2& unitNormal) 47 | { 48 | return incident - 2.0f*DotProduct(unitNormal, incident)*unitNormal; 49 | } 50 | 51 | Vector2 Vector2::Refract(const Vector2& unitIncident, 52 | const Vector2& unitNormal, 53 | const float& eta) 54 | { 55 | float nDotI = DotProduct(unitIncident, unitNormal); 56 | float k = 1.0f - eta * eta * (1.0f - nDotI * nDotI); 57 | if(k < 0.0f) 58 | return Vector2(0.0f, 0.0f); 59 | else 60 | return eta * unitIncident - (eta * nDotI + std::sqrt(k)) * unitNormal; 61 | } 62 | 63 | 64 | //////////////////////////////////////////////////////////////////////////////// 65 | // Constructor 66 | Vector2::Vector2(const float& x, const float& y) : 67 | mX(x), mY(y) 68 | { 69 | } 70 | 71 | 72 | //////////////////////////////////////////////////////////////////////////////// 73 | // Length 74 | float Vector2::Length() const 75 | { 76 | return std::sqrt(LengthSquared()); 77 | } 78 | 79 | 80 | //////////////////////////////////////////////////////////////////////////////// 81 | // Length Squared 82 | float Vector2::LengthSquared() const 83 | { 84 | return mX*mX + mY*mY; 85 | } 86 | 87 | 88 | //////////////////////////////////////////////////////////////////////////////// 89 | // Normalize 90 | Vector2 Vector2::Normalize() const 91 | { 92 | float invLength = 1.0f/Length(); 93 | return invLength*(*this); 94 | } 95 | 96 | 97 | //////////////////////////////////////////////////////////////////////////////// 98 | // Bracket operators 99 | const float& Vector2::operator[](size_t row) const 100 | { 101 | #ifndef NDEBUG 102 | assert(row < 2); 103 | #endif 104 | return (&mX)[row]; 105 | } 106 | 107 | float& Vector2::operator[](size_t row) 108 | { 109 | return const_cast< float& >((static_cast< const Vector2& >(*this))[row]); 110 | } 111 | 112 | 113 | //////////////////////////////////////////////////////////////////////////////// 114 | // Arithmetic operators 115 | Vector2 Vector2::operator+(const Vector2& v) const 116 | {return Vector2(mX+v.mX, mY+v.mY);} 117 | 118 | Vector2 Vector2::operator-(const Vector2& v) const 119 | {return Vector2(mX-v.mX, mY-v.mY);} 120 | 121 | Vector2 Vector2::operator/(const float& s) const 122 | { 123 | #ifndef NDEBUG 124 | assert(s != 0.0f); 125 | #endif 126 | return (1.0f/s) * (*this); 127 | } 128 | 129 | Vector2 Vector2::operator+() const 130 | {return Vector2(+mX, +mY);} 131 | 132 | Vector2 Vector2::operator-() const 133 | {return Vector2(-mX, -mY);} 134 | 135 | //////////////////////////////////////////////////////////////////////////////// 136 | // Assignment operators 137 | Vector2& Vector2::operator+=(const Vector2& v) 138 | {mX+=v.mX; mY+=v.mY; return (*this);} 139 | 140 | Vector2& Vector2::operator-=(const Vector2& v) 141 | {mX-=v.mX; mY-=v.mY; return (*this);} 142 | 143 | Vector2& Vector2::operator/=(const float& s) 144 | { 145 | #ifndef NDEBUG 146 | assert(s != 0.0f); 147 | #endif 148 | float invS = 1.0f/s; 149 | mX *= invS; 150 | mY *= invS; 151 | return (*this); 152 | } 153 | 154 | //////////////////////////////////////////////////////////////////////////////// 155 | // Comparison operators 156 | bool Vector2::operator==(const Vector2& v) const 157 | { return (v.mX == mX && v.mY == mY); } 158 | 159 | bool Vector2::operator!=(const Vector2& v) const 160 | { return !(v == *this); } 161 | 162 | 163 | //////////////////////////////////////////////////////////////////////////////// 164 | // Accessors 165 | const float& Vector2::GetX() const {return mX;} 166 | const float& Vector2::GetY() const {return mY;} 167 | 168 | 169 | //////////////////////////////////////////////////////////////////////////////// 170 | // Mutators 171 | void Vector2::SetX(const float& x) {mX = x;} 172 | void Vector2::SetY(const float& y) {mY = y;} 173 | 174 | 175 | //////////////////////////////////////////////////////////////////////////////// 176 | // Additionnal operators 177 | Vector2 operator*(const float& s, const Vector2& v) 178 | { 179 | return Vector2(s*v[0], s*v[1]); 180 | } 181 | 182 | 183 | //////////////////////////////////////////////////////////////////////////////// 184 | // Per component queries 185 | Vector2 Vector2::Sign() const 186 | { return Vector2(float((mX > 0) - (mX < 0)), 187 | float((mY > 0) - (mY < 0))); } 188 | 189 | Vector2 Vector2::Abs() const 190 | {return Vector2(std::abs(mX), std::abs(mY));} 191 | 192 | Vector2 Vector2::Sqr() const 193 | {return Vector2(mX*mX, mY*mY);} 194 | 195 | Vector2 Vector2::Sqrt() const 196 | {return Vector2(std::sqrt(mX), std::sqrt(mY));} 197 | 198 | Vector2 Vector2::Exp() const 199 | {return Vector2(std::exp(mX), std::exp(mY));} 200 | 201 | Vector2 Vector2::Log() const 202 | {return Vector2(std::log(mX), std::log(mY));} 203 | 204 | Vector2 Vector2::Log10() const 205 | {return Vector2(std::log10(mX), std::log10(mY));} 206 | 207 | Vector2 Vector2::Ceil() const 208 | {return Vector2(std::ceil(mX), std::ceil(mY));} 209 | 210 | Vector2 Vector2::Floor() const 211 | {return Vector2(std::floor(mX), std::floor(mY));} 212 | 213 | Vector2 Vector2::Frac() const 214 | {return (*this) - Floor();} 215 | 216 | 217 | //////////////////////////////////////////////////////////////////////////////// 218 | // Dot product 219 | float Vector2::DotProduct(const Vector2& u, const Vector2& v) 220 | { 221 | return u[0]*v[0]+u[1]*v[1]; 222 | } 223 | 224 | 225 | #if 0 226 | #include 227 | int main(int argc, char** argv) 228 | { 229 | Vector2 x = Vector2(1,8); 230 | std::cout << x.GetX() << " " << x.GetY() << std::endl; 231 | std::cout << x[0] << " " << x[1] << std::endl; 232 | x[0] += 2; 233 | x[1] = 9 - x[1]; 234 | std::cout << x[0] << " " << x[1] << std::endl; 235 | 236 | Vector2 a(1,0); 237 | a = a.Abs(); 238 | a = a.Exp(); 239 | a = -Vector2(0,1); 240 | Vector2 b(1,0); 241 | b = -Vector2::CompMult(a,b); 242 | std::cout << Vector2::DotProduct(a.Normalize(),b) << std::endl; 243 | std::cout << a.Length() << " " << a.LengthSquared() << std::endl; 244 | } 245 | #endif 246 | 247 | -------------------------------------------------------------------------------- /core/Vector3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "Algebra.hpp" 6 | 7 | //////////////////////////////////////////////////////////////////////////////// 8 | // Constants 9 | const Vector3 Vector3::ZERO(0.0f,0.0f,0.0f); 10 | 11 | 12 | //////////////////////////////////////////////////////////////////////////////// 13 | // Factories 14 | Vector3 Vector3::CompMult(const Vector3& u, 15 | const Vector3& v) 16 | { return Vector3(u[0]*v[0], u[1]*v[1], u[2]*v[2]); } 17 | 18 | Vector3 Vector3::CompDiv(const Vector3& u, 19 | const Vector3& v) 20 | { return Vector3(u[0]/v[0], u[1]/v[1], u[2]/v[2]); } 21 | 22 | Vector3 Vector3::CompPow(const Vector3& base, 23 | const Vector3& exponent) 24 | { return Vector3(std::pow(base[0],exponent[0]), 25 | std::pow(base[1],exponent[1]), 26 | std::pow(base[2],exponent[2])); } 27 | 28 | Vector3 Vector3::CompMin(const Vector3& u, 29 | const Vector3& v) 30 | { return Vector3(std::min(u[0],v[0]), 31 | std::min(u[1],v[1]), 32 | std::min(u[2],v[2])); } 33 | 34 | Vector3 Vector3::CompMax(const Vector3& u, 35 | const Vector3& v) 36 | { return Vector3(std::max(u[0],v[0]), 37 | std::max(u[1],v[1]), 38 | std::max(u[2],v[2])); } 39 | 40 | Vector3 Vector3::CompClamp(const Vector3& v, 41 | const Vector3& min, 42 | const Vector3& max) 43 | { return CompMin(CompMax(v, min), max); } 44 | 45 | 46 | //////////////////////////////////////////////////////////////////////////////// 47 | // Factories (continued) 48 | Vector3 Vector3::Reflect(const Vector3& incident, 49 | const Vector3& unitNormal) 50 | { 51 | return incident - 2.0f*DotProduct(unitNormal, incident)*unitNormal; 52 | } 53 | 54 | Vector3 Vector3::Refract(const Vector3& unitIncident, 55 | const Vector3& unitNormal, 56 | const float& eta) 57 | { 58 | float nDotI = DotProduct(unitIncident, unitNormal); 59 | float k = 1.0f - eta * eta * (1.0f - nDotI * nDotI); 60 | if(k < 0.0f) 61 | return Vector3(0.0f, 0.0f, 0.0f); 62 | else 63 | return eta * unitIncident - (eta * nDotI + std::sqrt(k)) * unitNormal; 64 | } 65 | 66 | 67 | //////////////////////////////////////////////////////////////////////////////// 68 | // Constructor 69 | Vector3::Vector3(const float& x, const float& y, const float& z) : 70 | mX(x), mY(y), mZ(z) 71 | { 72 | } 73 | 74 | 75 | //////////////////////////////////////////////////////////////////////////////// 76 | // Length 77 | float Vector3::Length() const 78 | { 79 | return std::sqrt(LengthSquared()); 80 | } 81 | 82 | 83 | //////////////////////////////////////////////////////////////////////////////// 84 | // Length Squared 85 | float Vector3::LengthSquared() const 86 | { 87 | return mX*mX + mY*mY + mZ*mZ; 88 | } 89 | 90 | 91 | //////////////////////////////////////////////////////////////////////////////// 92 | // Normalize 93 | Vector3 Vector3::Normalize() const 94 | { 95 | float invLength = 1.0f/Length(); 96 | return invLength*(*this); 97 | } 98 | 99 | 100 | //////////////////////////////////////////////////////////////////////////////// 101 | // Bracket operators 102 | const float& Vector3::operator[](size_t row) const 103 | { 104 | #ifndef NDEBUG 105 | assert(row < 3); 106 | #endif 107 | return (&mX)[row]; 108 | } 109 | 110 | float& Vector3::operator[](size_t row) 111 | { 112 | return const_cast< float& >((static_cast< const Vector3& >(*this))[row]); 113 | } 114 | 115 | 116 | //////////////////////////////////////////////////////////////////////////////// 117 | // Arithmetic operators 118 | Vector3 Vector3::operator+(const Vector3& v) const 119 | {return Vector3(mX+v.mX, mY+v.mY, mZ+v.mZ);} 120 | 121 | Vector3 Vector3::operator-(const Vector3& v) const 122 | {return Vector3(mX-v.mX, mY-v.mY, mZ-v.mZ);} 123 | 124 | Vector3 Vector3::operator/(const float& s) const 125 | { 126 | #ifndef NDEBUG 127 | assert(s != 0.0f); 128 | #endif 129 | return (1.0f/s) * (*this); 130 | } 131 | 132 | Vector3 Vector3::operator+() const 133 | {return Vector3(+mX, +mY, +mZ);} 134 | 135 | Vector3 Vector3::operator-() const 136 | {return Vector3(-mX, -mY, -mZ);} 137 | 138 | //////////////////////////////////////////////////////////////////////////////// 139 | // Assignment operators 140 | Vector3& Vector3::operator+=(const Vector3& v) 141 | {mX+=v.mX; mY+=v.mY; mZ+=v.mZ; return (*this);} 142 | 143 | Vector3& Vector3::operator-=(const Vector3& v) 144 | {mX-=v.mX; mY-=v.mY; mZ-=v.mZ; return (*this);} 145 | 146 | Vector3& Vector3::operator/=(const float& s) 147 | { 148 | #ifndef NDEBUG 149 | assert(s != 0.0f); 150 | #endif 151 | float invS = 1.0f/s; 152 | mX *= invS; 153 | mY *= invS; 154 | mZ *= invS; 155 | return (*this); 156 | } 157 | 158 | //////////////////////////////////////////////////////////////////////////////// 159 | // Comparison operators 160 | bool Vector3::operator==(const Vector3& v) const 161 | { return (v.mX == mX && v.mY == mY && v.mZ == mZ); } 162 | 163 | bool Vector3::operator!=(const Vector3& v) const 164 | { return !(v == *this); } 165 | 166 | 167 | //////////////////////////////////////////////////////////////////////////////// 168 | // Accessors 169 | const float& Vector3::GetX() const {return mX;} 170 | const float& Vector3::GetY() const {return mY;} 171 | const float& Vector3::GetZ() const {return mZ;} 172 | 173 | 174 | //////////////////////////////////////////////////////////////////////////////// 175 | // Mutators 176 | void Vector3::SetX(const float& x) {mX = x;} 177 | void Vector3::SetY(const float& y) {mY = y;} 178 | void Vector3::SetZ(const float& z) {mZ = z;} 179 | 180 | 181 | //////////////////////////////////////////////////////////////////////////////// 182 | // Additionnal operators 183 | Vector3 operator*(const float& s, const Vector3& v) 184 | { 185 | return Vector3(s*v[0], s*v[1], s*v[2]); 186 | } 187 | 188 | 189 | //////////////////////////////////////////////////////////////////////////////// 190 | // Per component queries 191 | Vector3 Vector3::Sign() const 192 | { return Vector3(float((mX > 0) - (mX < 0)), 193 | float((mY > 0) - (mY < 0)), 194 | float((mZ > 0) - (mZ < 0))); } 195 | 196 | Vector3 Vector3::Abs() const 197 | {return Vector3(std::abs(mX), std::abs(mY), std::abs(mZ));} 198 | 199 | Vector3 Vector3::Sqr() const 200 | {return Vector3(mX*mX, mY*mY, mZ*mZ);} 201 | 202 | Vector3 Vector3::Sqrt() const 203 | {return Vector3(std::sqrt(mX), std::sqrt(mY), std::sqrt(mZ));} 204 | 205 | Vector3 Vector3::Exp() const 206 | {return Vector3(std::exp(mX), std::exp(mY), std::exp(mZ));} 207 | 208 | Vector3 Vector3::Log() const 209 | {return Vector3(std::log(mX), std::log(mY), std::log(mZ));} 210 | 211 | Vector3 Vector3::Log10() const 212 | {return Vector3(std::log10(mX), std::log10(mY), std::log10(mZ));} 213 | 214 | Vector3 Vector3::Ceil() const 215 | {return Vector3(std::ceil(mX), std::ceil(mY), std::ceil(mZ));} 216 | 217 | Vector3 Vector3::Floor() const 218 | {return Vector3(std::floor(mX), std::floor(mY), std::floor(mZ));} 219 | 220 | Vector3 Vector3::Frac() const 221 | {return (*this) - Floor();} 222 | 223 | 224 | //////////////////////////////////////////////////////////////////////////////// 225 | // Dot product 226 | float Vector3::DotProduct(const Vector3& u, const Vector3& v) 227 | { 228 | return u[0]*v[0]+u[1]*v[1]+u[2]*v[2]; 229 | } 230 | 231 | 232 | //////////////////////////////////////////////////////////////////////////////// 233 | // Cross product 234 | Vector3 Vector3::CrossProduct(const Vector3& u, const Vector3& v) 235 | { 236 | return Vector3(u[1]*v[2]-v[1]*u[2], 237 | u[2]*v[0]-v[2]*u[0], 238 | u[0]*v[1]-v[0]*u[1]); 239 | } 240 | 241 | 242 | #if 0 243 | #include 244 | int main(int argc, char** argv) 245 | { 246 | Vector3 x = Vector3(1,8,0); 247 | std::cout << x.GetX() << " " << x.GetY() << " " << x.GetZ() << " " << std::endl; 248 | std::cout << x[0] << " " << x[1] << " " << x[2] << " " << std::endl; 249 | x[0]+= 3; 250 | x[1] = 9 - x[1]; 251 | x[2] -= x.GetY(); 252 | std::cout << x[0] << " " << x[1] << " " << x[2] << " " << std::endl; 253 | 254 | x = Vector3(-98,0,56).Sign(); 255 | std::cout << x[0] << " " << x[1] << " " << x[2] << " " << std::endl; 256 | 257 | Vector3 a(1,0,0); 258 | a = a.Abs(); 259 | a = a.Exp(); 260 | a = -Vector3(1,0,0); 261 | Vector3 b(1,0,0); 262 | b = -Vector3::CompMult(a,b); 263 | std::cout << Vector3::DotProduct(a.Normalize(),b) << std::endl; 264 | std::cout << a.Length() << " " << a.LengthSquared() << std::endl; 265 | } 266 | #endif 267 | 268 | -------------------------------------------------------------------------------- /core/Vector4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "Algebra.hpp" 6 | 7 | //////////////////////////////////////////////////////////////////////////////// 8 | // Constants 9 | const Vector4 Vector4::ZERO(0.0f,0.0f,0.0f,0.0f); 10 | 11 | 12 | //////////////////////////////////////////////////////////////////////////////// 13 | // Factories 14 | Vector4 Vector4::CompMult(const Vector4& u, 15 | const Vector4& v) 16 | { return Vector4(u[0]*v[0], u[1]*v[1], u[2]*v[2], u[3]*v[3]); } 17 | 18 | Vector4 Vector4::CompDiv(const Vector4& u, 19 | const Vector4& v) 20 | { return Vector4(u[0]/v[0], u[1]/v[1], u[2]/v[2], u[3]/v[3]); } 21 | 22 | Vector4 Vector4::CompPow(const Vector4& base, 23 | const Vector4& exponent) 24 | { return Vector4(std::pow(base[0],exponent[0]), 25 | std::pow(base[1],exponent[1]), 26 | std::pow(base[2],exponent[2]), 27 | std::pow(base[3],exponent[3])); } 28 | 29 | Vector4 Vector4::CompMin(const Vector4& u, 30 | const Vector4& v) 31 | { return Vector4(std::min(u[0],v[0]), 32 | std::min(u[1],v[1]), 33 | std::min(u[2],v[2]), 34 | std::min(u[3],v[3])); } 35 | 36 | Vector4 Vector4::CompMax(const Vector4& u, 37 | const Vector4& v) 38 | { return Vector4(std::max(u[0],v[0]), 39 | std::max(u[1],v[1]), 40 | std::max(u[2],v[2]), 41 | std::max(u[3],v[3])); } 42 | 43 | Vector4 Vector4::CompClamp(const Vector4& v, 44 | const Vector4& min, 45 | const Vector4& max) 46 | { return CompMin(CompMax(v, min), max); } 47 | 48 | 49 | //////////////////////////////////////////////////////////////////////////////// 50 | // Constructor 51 | Vector4::Vector4(const float& x, 52 | const float& y, 53 | const float& z, 54 | const float& w) : 55 | mX(x), mY(y), mZ(z), mW(w) 56 | { 57 | } 58 | 59 | 60 | //////////////////////////////////////////////////////////////////////////////// 61 | // Length 62 | float Vector4::Length() const 63 | { 64 | return std::sqrt(LengthSquared()); 65 | } 66 | 67 | 68 | //////////////////////////////////////////////////////////////////////////////// 69 | // Length Squared 70 | float Vector4::LengthSquared() const 71 | { 72 | return mX*mX + mY*mY + mZ*mZ + mW*mW; 73 | } 74 | 75 | 76 | //////////////////////////////////////////////////////////////////////////////// 77 | // Normalize 78 | Vector4 Vector4::Normalize() const 79 | { 80 | float invLength = 1.0f/Length(); 81 | return invLength*(*this); 82 | } 83 | 84 | 85 | //////////////////////////////////////////////////////////////////////////////// 86 | // Bracket operators 87 | const float& Vector4::operator[](size_t row) const 88 | { 89 | #ifndef NDEBUG 90 | assert(row < 4); 91 | #endif 92 | return (&mX)[row]; 93 | } 94 | 95 | float& Vector4::operator[](size_t row) 96 | { 97 | return const_cast< float& >((static_cast< const Vector4& >(*this))[row]); 98 | } 99 | 100 | 101 | //////////////////////////////////////////////////////////////////////////////// 102 | // Arithmetic operators 103 | Vector4 Vector4::operator+(const Vector4& v) const 104 | {return Vector4(mX+v.mX, mY+v.mY, mZ+v.mZ, mW+v.mW);} 105 | 106 | Vector4 Vector4::operator-(const Vector4& v) const 107 | {return Vector4(mX-v.mX, mY-v.mY, mZ-v.mZ, mW-v.mW);} 108 | 109 | Vector4 Vector4::operator/(const float& s) const 110 | { 111 | #ifndef NDEBUG 112 | assert(s != 0.0f); 113 | #endif 114 | return (1.0f/s) * (*this); 115 | } 116 | 117 | Vector4 Vector4::operator+() const 118 | {return Vector4(+mX, +mY, +mZ, +mW);} 119 | 120 | Vector4 Vector4::operator-() const 121 | {return Vector4(-mX, -mY, -mZ, -mW);} 122 | 123 | //////////////////////////////////////////////////////////////////////////////// 124 | // Assignment operators 125 | Vector4& Vector4::operator+=(const Vector4& v) 126 | {mX+=v.mX; mY+=v.mY; mZ+=v.mZ; mW+=v.mW; return (*this);} 127 | 128 | Vector4& Vector4::operator-=(const Vector4& v) 129 | {mX-=v.mX; mY-=v.mY; mZ-=v.mZ; mW-=v.mW; return (*this);} 130 | 131 | Vector4& Vector4::operator/=(const float& s) 132 | { 133 | #ifndef NDEBUG 134 | assert(s != 0.0f); 135 | #endif 136 | float invS = 1.0f/s; 137 | mX *= invS; 138 | mY *= invS; 139 | mZ *= invS; 140 | mW *= invS; 141 | return (*this); 142 | } 143 | 144 | //////////////////////////////////////////////////////////////////////////////// 145 | // Comparison operators 146 | bool Vector4::operator==(const Vector4& v) const 147 | { return (v.mX == mX && v.mY == mY && v.mZ == mZ && v.mW == mW); } 148 | 149 | bool Vector4::operator!=(const Vector4& v) const 150 | { return !(v == *this); } 151 | 152 | 153 | //////////////////////////////////////////////////////////////////////////////// 154 | // Accessors 155 | const float& Vector4::GetX() const {return mX;} 156 | const float& Vector4::GetY() const {return mY;} 157 | const float& Vector4::GetZ() const {return mZ;} 158 | const float& Vector4::GetW() const {return mW;} 159 | 160 | 161 | //////////////////////////////////////////////////////////////////////////////// 162 | // Mutators 163 | void Vector4::SetX(const float& x) {mX = x;} 164 | void Vector4::SetY(const float& y) {mY = y;} 165 | void Vector4::SetZ(const float& z) {mZ = z;} 166 | void Vector4::SetW(const float& w) {mW = w;} 167 | 168 | 169 | //////////////////////////////////////////////////////////////////////////////// 170 | // Additionnal operators 171 | Vector4 operator*(const float& s, const Vector4& v) 172 | { 173 | return Vector4(s*v[0], s*v[1], s*v[2], s*v[3]); 174 | } 175 | 176 | 177 | //////////////////////////////////////////////////////////////////////////////// 178 | // Per component queries 179 | Vector4 Vector4::Sign() const 180 | { return Vector4(float((mX > 0) - (mX < 0)), 181 | float((mY > 0) - (mY < 0)), 182 | float((mZ > 0) - (mZ < 0)), 183 | float((mW > 0) - (mW < 0))); } 184 | 185 | Vector4 Vector4::Abs() const 186 | {return Vector4(std::abs(mX), std::abs(mY), std::abs(mZ), std::abs(mW));} 187 | 188 | Vector4 Vector4::Sqr() const 189 | {return Vector4(mX*mX, mY*mY, mZ*mZ, mW*mW);} 190 | 191 | Vector4 Vector4::Sqrt() const 192 | {return Vector4(std::sqrt(mX), std::sqrt(mY), std::sqrt(mZ), std::sqrt(mW));} 193 | 194 | Vector4 Vector4::Exp() const 195 | {return Vector4(std::exp(mX), std::exp(mY), std::exp(mZ), std::exp(mW));} 196 | 197 | Vector4 Vector4::Log() const 198 | {return Vector4(std::log(mX), std::log(mY), std::log(mZ), std::log(mW));} 199 | 200 | Vector4 Vector4::Log10() const 201 | {return Vector4(std::log10(mX), 202 | std::log10(mY), 203 | std::log10(mZ), 204 | std::log10(mW));} 205 | 206 | Vector4 Vector4::Ceil() const 207 | {return Vector4(std::ceil(mX), std::ceil(mY), std::ceil(mZ), std::ceil(mW));} 208 | 209 | Vector4 Vector4::Floor() const 210 | {return Vector4(std::floor(mX), 211 | std::floor(mY), 212 | std::floor(mZ), 213 | std::floor(mW));} 214 | 215 | Vector4 Vector4::Frac() const 216 | {return (*this) - Floor();} 217 | 218 | 219 | //////////////////////////////////////////////////////////////////////////////// 220 | // Dot product 221 | float Vector4::DotProduct(const Vector4& u, const Vector4& v) 222 | { 223 | return u[0]*v[0]+u[1]*v[1]+u[2]*v[2]+u[3]*v[3]; 224 | } 225 | 226 | 227 | #if 0 228 | #include 229 | int main(int argc, char** argv) 230 | { 231 | Vector4 x = Vector4(1,8,0,8); 232 | std::cout << x.GetX() << " " 233 | << x.GetY() << " " 234 | << x.GetZ() << " " 235 | << x.GetW() << std::endl; 236 | std::cout << x[0] << " " << x[1] << " " << x[2] << " " << x[3] << std::endl; 237 | x[0]+= 4; 238 | x[1] = 9 - x[1]; 239 | x[2] -= x.GetY(); 240 | x[3] = x.GetW()-1; 241 | std::cout << x[0] << " " << x[1] << " " << x[2] << " " << x[3] << std::endl; 242 | 243 | x = Vector4(-98,0,56,-0).Sign(); 244 | std::cout << x[0] << " " << x[1] << " " << x[2] << " " << x[3] << std::endl; 245 | 246 | x = 2.0f*x; 247 | 248 | x /= 2.0f; 249 | std::cout << x[0] << " " << x[1] << " " << x[2] << " " << x[3] << std::endl; 250 | 251 | Vector4 a(1,0,0,1); 252 | a = a.Abs(); 253 | a = a.Exp(); 254 | a = -Vector4(1,0,0,0); 255 | Vector4 b(-1,0,0,0); 256 | b = -Vector4::CompMult(a,b); 257 | std::cout << Vector4::DotProduct(a.Normalize(),b) << std::endl; 258 | std::cout << a.Length() << " " << a.LengthSquared() << std::endl; 259 | } 260 | #endif 261 | 262 | -------------------------------------------------------------------------------- /cube.glsl: -------------------------------------------------------------------------------- 1 | #version 410 2 | 3 | uniform mat4 uModelViewProjection; 4 | 5 | 6 | #ifdef _VERTEX_ 7 | layout(location = 0) in vec4 iPosition; 8 | 9 | void main() { 10 | gl_Position = uModelViewProjection * iPosition; 11 | } 12 | #endif 13 | 14 | 15 | #ifdef _FRAGMENT_ 16 | layout(location = 0) out vec4 oColour; 17 | 18 | void main() { 19 | oColour = vec4(1.0); 20 | } 21 | #endif // _FRAGMENT_ 22 | -------------------------------------------------------------------------------- /freeglut.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/freeglut.dll -------------------------------------------------------------------------------- /glew.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // \author Jonathan Dupuy 3 | // 4 | //////////////////////////////////////////////////////////////////////////////// 5 | 6 | #ifndef GLEW_HPP 7 | #define GLEW_HPP 8 | 9 | #ifdef _WIN32 10 | # define GLEW_STATIC 11 | #endif // _WIN32 12 | 13 | #define GLEW_NO_GLU 14 | 15 | #include "GL/glew.h" 16 | 17 | #endif 18 | 19 | //////////////////////////////////////////////////////////////////////////////// 20 | 21 | -------------------------------------------------------------------------------- /include/AntTweakBar.h: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // 3 | // @file AntTweakBar.h 4 | // 5 | // @brief AntTweakBar is a light and intuitive graphical user interface 6 | // that can be readily integrated into OpenGL and DirectX 7 | // applications in order to interactively tweak parameters. 8 | // 9 | // @author Philippe Decaudin - http://www.antisphere.com 10 | // 11 | // @doc http://www.antisphere.com/Wiki/tools:anttweakbar 12 | // 13 | // @license This file is part of the AntTweakBar library. 14 | // AntTweakBar is a free software released under the zlib license. 15 | // For conditions of distribution and use, see License.txt 16 | // 17 | // ---------------------------------------------------------------------------- 18 | 19 | 20 | #if !defined TW_INCLUDED 21 | #define TW_INCLUDED 22 | 23 | #include 24 | 25 | #define TW_VERSION 114 // Version Mmm : M=Major mm=minor (e.g., 102 is version 1.02) 26 | 27 | 28 | #ifdef __cplusplus 29 | # if defined(_MSC_VER) 30 | # pragma warning(push) 31 | # pragma warning(disable: 4995 4530) 32 | # include 33 | # pragma warning(pop) 34 | # else 35 | # include 36 | # endif 37 | extern "C" { 38 | #endif // __cplusplus 39 | 40 | 41 | // ---------------------------------------------------------------------------- 42 | // OS specific definitions 43 | // ---------------------------------------------------------------------------- 44 | 45 | #if defined(_WIN32) || defined(_WIN64) 46 | # define TW_CALL __stdcall 47 | # define TW_CDECL_CALL __cdecl 48 | # define TW_EXPORT_API __declspec(dllexport) 49 | # define TW_IMPORT_API __declspec(dllimport) 50 | #else 51 | # define TW_CALL 52 | # define TW_CDECL_CALL 53 | # define TW_EXPORT_API 54 | # define TW_IMPORT_API 55 | #endif 56 | 57 | #if defined TW_EXPORTS 58 | # define TW_API TW_EXPORT_API 59 | #elif defined TW_STATIC 60 | # define TW_API 61 | # if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA) 62 | # ifdef _WIN64 63 | # pragma comment(lib, "AntTweakBarStatic64") 64 | # else 65 | # pragma comment(lib, "AntTweakBarStatic") 66 | # endif 67 | # endif 68 | #else 69 | # define TW_API TW_IMPORT_API 70 | # if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA) 71 | # ifdef _WIN64 72 | # pragma comment(lib, "AntTweakBar64") 73 | # else 74 | # pragma comment(lib, "AntTweakBar") 75 | # endif 76 | # endif 77 | #endif 78 | 79 | 80 | // ---------------------------------------------------------------------------- 81 | // Bar functions and definitions 82 | // ---------------------------------------------------------------------------- 83 | 84 | typedef struct CTwBar TwBar; // structure CTwBar is not exposed. 85 | 86 | TW_API TwBar * TW_CALL TwNewBar(const char *barName); 87 | TW_API int TW_CALL TwDeleteBar(TwBar *bar); 88 | TW_API int TW_CALL TwDeleteAllBars(); 89 | TW_API int TW_CALL TwSetTopBar(const TwBar *bar); 90 | TW_API TwBar * TW_CALL TwGetTopBar(); 91 | TW_API int TW_CALL TwSetBottomBar(const TwBar *bar); 92 | TW_API TwBar * TW_CALL TwGetBottomBar(); 93 | TW_API const char * TW_CALL TwGetBarName(TwBar *bar); 94 | TW_API int TW_CALL TwGetBarCount(); 95 | TW_API TwBar * TW_CALL TwGetBarByIndex(int barIndex); 96 | TW_API TwBar * TW_CALL TwGetBarByName(const char *barName); 97 | TW_API int TW_CALL TwRefreshBar(TwBar *bar); 98 | 99 | 100 | // ---------------------------------------------------------------------------- 101 | // Var functions and definitions 102 | // ---------------------------------------------------------------------------- 103 | 104 | typedef enum ETwType 105 | { 106 | TW_TYPE_UNDEF = 0, 107 | #ifdef __cplusplus 108 | TW_TYPE_BOOLCPP = 1, 109 | #endif // __cplusplus 110 | TW_TYPE_BOOL8 = 2, 111 | TW_TYPE_BOOL16, 112 | TW_TYPE_BOOL32, 113 | TW_TYPE_CHAR, 114 | TW_TYPE_INT8, 115 | TW_TYPE_UINT8, 116 | TW_TYPE_INT16, 117 | TW_TYPE_UINT16, 118 | TW_TYPE_INT32, 119 | TW_TYPE_UINT32, 120 | TW_TYPE_FLOAT, 121 | TW_TYPE_DOUBLE, 122 | TW_TYPE_COLOR32, // 32 bits color. Order is RGBA if API is OpenGL or Direct3D10, and inversed if API is Direct3D9 (can be modified by defining 'colorOrder=...', see doc) 123 | TW_TYPE_COLOR3F, // 3 floats color. Order is RGB. 124 | TW_TYPE_COLOR4F, // 4 floats color. Order is RGBA. 125 | TW_TYPE_CDSTRING, // Null-terminated C Dynamic String (pointer to an array of char dynamically allocated with malloc/realloc/strdup) 126 | #ifdef __cplusplus 127 | TW_TYPE_STDSTRING = (0x2fff0000+sizeof(std::string)), // C++ STL string (std::string) 128 | #endif // __cplusplus 129 | TW_TYPE_QUAT4F = TW_TYPE_CDSTRING+2, // 4 floats encoding a quaternion {qx,qy,qz,qs} 130 | TW_TYPE_QUAT4D, // 4 doubles encoding a quaternion {qx,qy,qz,qs} 131 | TW_TYPE_DIR3F, // direction vector represented by 3 floats 132 | TW_TYPE_DIR3D // direction vector represented by 3 doubles 133 | } TwType; 134 | #define TW_TYPE_CSSTRING(n) ((TwType)(0x30000000+((n)&0xfffffff))) // Null-terminated C Static String of size n (defined as char[n], with n<2^28) 135 | 136 | typedef void (TW_CALL * TwSetVarCallback)(const void *value, void *clientData); 137 | typedef void (TW_CALL * TwGetVarCallback)(void *value, void *clientData); 138 | typedef void (TW_CALL * TwButtonCallback)(void *clientData); 139 | 140 | TW_API int TW_CALL TwAddVarRW(TwBar *bar, const char *name, TwType type, void *var, const char *def); 141 | TW_API int TW_CALL TwAddVarRO(TwBar *bar, const char *name, TwType type, const void *var, const char *def); 142 | TW_API int TW_CALL TwAddVarCB(TwBar *bar, const char *name, TwType type, TwSetVarCallback setCallback, TwGetVarCallback getCallback, void *clientData, const char *def); 143 | TW_API int TW_CALL TwAddButton(TwBar *bar, const char *name, TwButtonCallback callback, void *clientData, const char *def); 144 | TW_API int TW_CALL TwAddSeparator(TwBar *bar, const char *name, const char *def); 145 | TW_API int TW_CALL TwRemoveVar(TwBar *bar, const char *name); 146 | TW_API int TW_CALL TwRemoveAllVars(TwBar *bar); 147 | 148 | typedef struct CTwEnumVal 149 | { 150 | int Value; 151 | const char * Label; 152 | } TwEnumVal; 153 | typedef struct CTwStructMember 154 | { 155 | const char * Name; 156 | TwType Type; 157 | size_t Offset; 158 | const char * DefString; 159 | } TwStructMember; 160 | typedef void (TW_CALL * TwSummaryCallback)(char *summaryString, size_t summaryMaxLength, const void *value, void *clientData); 161 | 162 | TW_API int TW_CALL TwDefine(const char *def); 163 | TW_API TwType TW_CALL TwDefineEnum(const char *name, const TwEnumVal *enumValues, unsigned int nbValues); 164 | TW_API TwType TW_CALL TwDefineEnumFromString(const char *name, const char *enumString); 165 | TW_API TwType TW_CALL TwDefineStruct(const char *name, const TwStructMember *structMembers, unsigned int nbMembers, size_t structSize, TwSummaryCallback summaryCallback, void *summaryClientData); 166 | 167 | typedef void (TW_CALL * TwCopyCDStringToClient)(char **destinationClientStringPtr, const char *sourceString); 168 | TW_API void TW_CALL TwCopyCDStringToClientFunc(TwCopyCDStringToClient copyCDStringFunc); 169 | TW_API void TW_CALL TwCopyCDStringToLibrary(char **destinationLibraryStringPtr, const char *sourceClientString); 170 | #ifdef __cplusplus 171 | typedef void (TW_CALL * TwCopyStdStringToClient)(std::string& destinationClientString, const std::string& sourceString); 172 | TW_API void TW_CALL TwCopyStdStringToClientFunc(TwCopyStdStringToClient copyStdStringToClientFunc); 173 | TW_API void TW_CALL TwCopyStdStringToLibrary(std::string& destinationLibraryString, const std::string& sourceClientString); 174 | #endif // __cplusplus 175 | 176 | typedef enum ETwParamValueType 177 | { 178 | TW_PARAM_INT32, 179 | TW_PARAM_FLOAT, 180 | TW_PARAM_DOUBLE, 181 | TW_PARAM_CSTRING // Null-terminated array of char (ie, c-string) 182 | } TwParamValueType; 183 | TW_API int TW_CALL TwGetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int outValueMaxCount, void *outValues); 184 | TW_API int TW_CALL TwSetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int inValueCount, const void *inValues); 185 | 186 | 187 | // ---------------------------------------------------------------------------- 188 | // Management functions and definitions 189 | // ---------------------------------------------------------------------------- 190 | 191 | typedef enum ETwGraphAPI 192 | { 193 | TW_OPENGL = 1, 194 | TW_DIRECT3D9 = 2, 195 | TW_DIRECT3D10 = 3, 196 | TW_DIRECT3D11 = 4 197 | } TwGraphAPI; 198 | 199 | TW_API int TW_CALL TwInit(TwGraphAPI graphAPI, void *device); 200 | TW_API int TW_CALL TwTerminate(); 201 | 202 | TW_API int TW_CALL TwDraw(); 203 | TW_API int TW_CALL TwWindowSize(int width, int height); 204 | 205 | TW_API int TW_CALL TwSetCurrentWindow(int windowID); // multi-windows support 206 | TW_API int TW_CALL TwGetCurrentWindow(); 207 | TW_API int TW_CALL TwWindowExists(int windowID); 208 | 209 | typedef enum ETwKeyModifier 210 | { 211 | TW_KMOD_NONE = 0x0000, // same codes as SDL keysym.mod 212 | TW_KMOD_SHIFT = 0x0003, 213 | TW_KMOD_CTRL = 0x00c0, 214 | TW_KMOD_ALT = 0x0100, 215 | TW_KMOD_META = 0x0c00 216 | } TwKeyModifier; 217 | typedef enum EKeySpecial 218 | { 219 | TW_KEY_BACKSPACE = '\b', 220 | TW_KEY_TAB = '\t', 221 | TW_KEY_CLEAR = 0x0c, 222 | TW_KEY_RETURN = '\r', 223 | TW_KEY_PAUSE = 0x13, 224 | TW_KEY_ESCAPE = 0x1b, 225 | TW_KEY_SPACE = ' ', 226 | TW_KEY_DELETE = 0x7f, 227 | TW_KEY_UP = 273, // same codes and order as SDL 1.2 keysym.sym 228 | TW_KEY_DOWN, 229 | TW_KEY_RIGHT, 230 | TW_KEY_LEFT, 231 | TW_KEY_INSERT, 232 | TW_KEY_HOME, 233 | TW_KEY_END, 234 | TW_KEY_PAGE_UP, 235 | TW_KEY_PAGE_DOWN, 236 | TW_KEY_F1, 237 | TW_KEY_F2, 238 | TW_KEY_F3, 239 | TW_KEY_F4, 240 | TW_KEY_F5, 241 | TW_KEY_F6, 242 | TW_KEY_F7, 243 | TW_KEY_F8, 244 | TW_KEY_F9, 245 | TW_KEY_F10, 246 | TW_KEY_F11, 247 | TW_KEY_F12, 248 | TW_KEY_F13, 249 | TW_KEY_F14, 250 | TW_KEY_F15, 251 | TW_KEY_LAST 252 | } TwKeySpecial; 253 | 254 | TW_API int TW_CALL TwKeyPressed(int key, int modifiers); 255 | TW_API int TW_CALL TwKeyTest(int key, int modifiers); 256 | 257 | typedef enum ETwMouseAction 258 | { 259 | TW_MOUSE_RELEASED, 260 | TW_MOUSE_PRESSED 261 | } TwMouseAction; 262 | typedef enum ETwMouseButtonID 263 | { 264 | TW_MOUSE_LEFT = 1, // same code as SDL_BUTTON_LEFT 265 | TW_MOUSE_MIDDLE = 2, // same code as SDL_BUTTON_MIDDLE 266 | TW_MOUSE_RIGHT = 3 // same code as SDL_BUTTON_RIGHT 267 | } TwMouseButtonID; 268 | 269 | TW_API int TW_CALL TwMouseButton(TwMouseAction action, TwMouseButtonID button); 270 | TW_API int TW_CALL TwMouseMotion(int mouseX, int mouseY); 271 | TW_API int TW_CALL TwMouseWheel(int pos); 272 | 273 | TW_API const char * TW_CALL TwGetLastError(); 274 | typedef void (TW_CALL * TwErrorHandler)(const char *errorMessage); 275 | TW_API void TW_CALL TwHandleErrors(TwErrorHandler errorHandler); 276 | 277 | 278 | // ---------------------------------------------------------------------------- 279 | // Helper functions to translate events from some common window management 280 | // frameworks to AntTweakBar. 281 | // They call TwKeyPressed, TwMouse* and TwWindowSize for you (implemented in 282 | // files TwEventWin.c TwEventSDL*.c TwEventGLFW.c TwEventGLUT.c) 283 | // ---------------------------------------------------------------------------- 284 | 285 | // For Windows message proc 286 | #ifndef _W64 // Microsoft specific (detection of 64 bits portability issues) 287 | # define _W64 288 | #endif // _W64 289 | #ifdef _WIN64 290 | TW_API int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned __int64 _W64 wParam, __int64 _W64 lParam); 291 | #else 292 | TW_API int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned int _W64 wParam, int _W64 lParam); 293 | #endif 294 | #define TwEventWin32 TwEventWin // For compatibility with AntTweakBar versions prior to 1.11 295 | 296 | // For libSDL event loop 297 | TW_API int TW_CALL TwEventSDL(const void *sdlEvent, unsigned char sdlMajorVersion, unsigned char sdlMinorVersion); 298 | 299 | // For GLFW event callbacks 300 | // Define GLFW_CDECL before including AntTweakBar.h if your version of GLFW uses cdecl calling convensions 301 | #ifdef GLFW_CDECL 302 | TW_API int TW_CDECL_CALL TwEventMouseButtonGLFWcdecl(int glfwButton, int glfwAction); 303 | TW_API int TW_CDECL_CALL TwEventKeyGLFWcdecl(int glfwKey, int glfwAction); 304 | TW_API int TW_CDECL_CALL TwEventCharGLFWcdecl(int glfwChar, int glfwAction); 305 | TW_API int TW_CDECL_CALL TwEventMousePosGLFWcdecl(int mouseX, int mouseY); 306 | TW_API int TW_CDECL_CALL TwEventMouseWheelGLFWcdecl(int wheelPos); 307 | # define TwEventMouseButtonGLFW TwEventMouseButtonGLFWcdecl 308 | # define TwEventKeyGLFW TwEventKeyGLFWcdecl 309 | # define TwEventCharGLFW TwEventCharGLFWcdecl 310 | # define TwEventMousePosGLFW TwEventMousePosGLFWcdecl 311 | # define TwEventMouseWheelGLFW TwEventMouseWheelGLFWcdecl 312 | #else 313 | TW_API int TW_CALL TwEventMouseButtonGLFW(int glfwButton, int glfwAction); 314 | TW_API int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction); 315 | TW_API int TW_CALL TwEventCharGLFW(int glfwChar, int glfwAction); 316 | # define TwEventMousePosGLFW TwMouseMotion 317 | # define TwEventMouseWheelGLFW TwMouseWheel 318 | #endif 319 | 320 | // For GLUT event callbacks (Windows calling convention for GLUT callbacks is cdecl) 321 | #if defined(_WIN32) || defined(_WIN64) 322 | # define TW_GLUT_CALL TW_CDECL_CALL 323 | #else 324 | # define TW_GLUT_CALL 325 | #endif 326 | TW_API int TW_GLUT_CALL TwEventMouseButtonGLUT(int glutButton, int glutState, int mouseX, int mouseY); 327 | TW_API int TW_GLUT_CALL TwEventMouseMotionGLUT(int mouseX, int mouseY); 328 | TW_API int TW_GLUT_CALL TwEventKeyboardGLUT(unsigned char glutKey, int mouseX, int mouseY); 329 | TW_API int TW_GLUT_CALL TwEventSpecialGLUT(int glutKey, int mouseX, int mouseY); 330 | TW_API int TW_CALL TwGLUTModifiersFunc(int (TW_CALL *glutGetModifiersFunc)(void)); 331 | typedef void (TW_GLUT_CALL *GLUTmousebuttonfun)(int glutButton, int glutState, int mouseX, int mouseY); 332 | typedef void (TW_GLUT_CALL *GLUTmousemotionfun)(int mouseX, int mouseY); 333 | typedef void (TW_GLUT_CALL *GLUTkeyboardfun)(unsigned char glutKey, int mouseX, int mouseY); 334 | typedef void (TW_GLUT_CALL *GLUTspecialfun)(int glutKey, int mouseX, int mouseY); 335 | 336 | // For SFML event loop 337 | TW_API int TW_CALL TwEventSFML(const void *sfmlEvent, unsigned char sfmlMajorVersion, unsigned char sfmlMinorVersion); 338 | 339 | 340 | // ---------------------------------------------------------------------------- 341 | // Make sure the types have the right sizes 342 | // ---------------------------------------------------------------------------- 343 | 344 | #define TW_COMPILE_TIME_ASSERT(name, x) typedef int TW_DUMMY_ ## name[(x) * 2 - 1] 345 | 346 | TW_COMPILE_TIME_ASSERT(TW_CHAR, sizeof(char) == 1); 347 | TW_COMPILE_TIME_ASSERT(TW_SHORT, sizeof(short) == 2); 348 | TW_COMPILE_TIME_ASSERT(TW_INT, sizeof(int) == 4); 349 | TW_COMPILE_TIME_ASSERT(TW_FLOAT, sizeof(float) == 4); 350 | TW_COMPILE_TIME_ASSERT(TW_DOUBLE, sizeof(double) == 8); 351 | 352 | // Check pointer size on Windows 353 | #if !defined(_WIN64) && defined(_WIN32) 354 | // If the following assert failed, the platform is not 32-bit and _WIN64 is not defined. 355 | // When targetting 64-bit Windows platform, _WIN64 must be defined. 356 | TW_COMPILE_TIME_ASSERT(TW_PTR32, sizeof(void*) == 4); 357 | #elif defined(_WIN64) 358 | // If the following assert failed, _WIN64 is defined but the targeted platform is not 64-bit. 359 | TW_COMPILE_TIME_ASSERT(TW_PTR64, sizeof(void*) == 8); 360 | #endif 361 | 362 | // --------------------------------------------------------------------------- 363 | 364 | 365 | #ifdef __cplusplus 366 | } // extern "C" 367 | #endif // __cplusplus 368 | 369 | 370 | #endif // !defined TW_INCLUDED 371 | -------------------------------------------------------------------------------- /include/GL/freeglut.h: -------------------------------------------------------------------------------- 1 | #ifndef __FREEGLUT_H__ 2 | #define __FREEGLUT_H__ 3 | 4 | /* 5 | * freeglut.h 6 | * 7 | * The freeglut library include file 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 10 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 11 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 12 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | */ 16 | 17 | #include "freeglut_std.h" 18 | #include "freeglut_ext.h" 19 | 20 | /*** END OF FILE ***/ 21 | 22 | #endif /* __FREEGLUT_H__ */ 23 | -------------------------------------------------------------------------------- /include/GL/freeglut_ext.h: -------------------------------------------------------------------------------- 1 | #ifndef __FREEGLUT_EXT_H__ 2 | #define __FREEGLUT_EXT_H__ 3 | 4 | /* 5 | * freeglut_ext.h 6 | * 7 | * The non-GLUT-compatible extensions to the freeglut library include file 8 | * 9 | * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved. 10 | * Written by Pawel W. Olszta, 11 | * Creation date: Thu Dec 2 1999 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a 14 | * copy of this software and associated documentation files (the "Software"), 15 | * to deal in the Software without restriction, including without limitation 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | * and/or sell copies of the Software, and to permit persons to whom the 18 | * Software is furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included 21 | * in all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 27 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 28 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* 36 | * Additional GLUT Key definitions for the Special key function 37 | */ 38 | #define GLUT_KEY_NUM_LOCK 0x006D 39 | #define GLUT_KEY_BEGIN 0x006E 40 | #define GLUT_KEY_DELETE 0x006F 41 | 42 | /* 43 | * GLUT API Extension macro definitions -- behaviour when the user clicks on an "x" to close a window 44 | */ 45 | #define GLUT_ACTION_EXIT 0 46 | #define GLUT_ACTION_GLUTMAINLOOP_RETURNS 1 47 | #define GLUT_ACTION_CONTINUE_EXECUTION 2 48 | 49 | /* 50 | * Create a new rendering context when the user opens a new window? 51 | */ 52 | #define GLUT_CREATE_NEW_CONTEXT 0 53 | #define GLUT_USE_CURRENT_CONTEXT 1 54 | 55 | /* 56 | * Direct/Indirect rendering context options (has meaning only in Unix/X11) 57 | */ 58 | #define GLUT_FORCE_INDIRECT_CONTEXT 0 59 | #define GLUT_ALLOW_DIRECT_CONTEXT 1 60 | #define GLUT_TRY_DIRECT_CONTEXT 2 61 | #define GLUT_FORCE_DIRECT_CONTEXT 3 62 | 63 | /* 64 | * GLUT API Extension macro definitions -- the glutGet parameters 65 | */ 66 | #define GLUT_INIT_STATE 0x007C 67 | 68 | #define GLUT_ACTION_ON_WINDOW_CLOSE 0x01F9 69 | 70 | #define GLUT_WINDOW_BORDER_WIDTH 0x01FA 71 | #define GLUT_WINDOW_HEADER_HEIGHT 0x01FB 72 | 73 | #define GLUT_VERSION 0x01FC 74 | 75 | #define GLUT_RENDERING_CONTEXT 0x01FD 76 | #define GLUT_DIRECT_RENDERING 0x01FE 77 | 78 | #define GLUT_FULL_SCREEN 0x01FF 79 | 80 | /* 81 | * New tokens for glutInitDisplayMode. 82 | * Only one GLUT_AUXn bit may be used at a time. 83 | * Value 0x0400 is defined in OpenGLUT. 84 | */ 85 | #define GLUT_AUX 0x1000 86 | 87 | #define GLUT_AUX1 0x1000 88 | #define GLUT_AUX2 0x2000 89 | #define GLUT_AUX3 0x4000 90 | #define GLUT_AUX4 0x8000 91 | 92 | /* 93 | * Context-related flags, see freeglut_state.c 94 | */ 95 | #define GLUT_INIT_MAJOR_VERSION 0x0200 96 | #define GLUT_INIT_MINOR_VERSION 0x0201 97 | #define GLUT_INIT_FLAGS 0x0202 98 | #define GLUT_INIT_PROFILE 0x0203 99 | 100 | /* 101 | * Flags for glutInitContextFlags, see freeglut_init.c 102 | */ 103 | #define GLUT_DEBUG 0x0001 104 | #define GLUT_FORWARD_COMPATIBLE 0x0002 105 | 106 | 107 | /* 108 | * Flags for glutInitContextProfile, see freeglut_init.c 109 | */ 110 | #define GLUT_CORE_PROFILE 0x0001 111 | #define GLUT_COMPATIBILITY_PROFILE 0x0002 112 | 113 | /* 114 | * Process loop function, see freeglut_main.c 115 | */ 116 | FGAPI void FGAPIENTRY glutMainLoopEvent( void ); 117 | FGAPI void FGAPIENTRY glutLeaveMainLoop( void ); 118 | FGAPI void FGAPIENTRY glutExit ( void ); 119 | 120 | /* 121 | * Window management functions, see freeglut_window.c 122 | */ 123 | FGAPI void FGAPIENTRY glutFullScreenToggle( void ); 124 | 125 | /* 126 | * Window-specific callback functions, see freeglut_callbacks.c 127 | */ 128 | FGAPI void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) ); 129 | FGAPI void FGAPIENTRY glutCloseFunc( void (* callback)( void ) ); 130 | FGAPI void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) ); 131 | /* A. Donev: Also a destruction callback for menus */ 132 | FGAPI void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) ); 133 | 134 | /* 135 | * State setting and retrieval functions, see freeglut_state.c 136 | */ 137 | FGAPI void FGAPIENTRY glutSetOption ( GLenum option_flag, int value ); 138 | FGAPI int * FGAPIENTRY glutGetModeValues(GLenum mode, int * size); 139 | /* A.Donev: User-data manipulation */ 140 | FGAPI void* FGAPIENTRY glutGetWindowData( void ); 141 | FGAPI void FGAPIENTRY glutSetWindowData(void* data); 142 | FGAPI void* FGAPIENTRY glutGetMenuData( void ); 143 | FGAPI void FGAPIENTRY glutSetMenuData(void* data); 144 | 145 | /* 146 | * Font stuff, see freeglut_font.c 147 | */ 148 | FGAPI int FGAPIENTRY glutBitmapHeight( void* font ); 149 | FGAPI GLfloat FGAPIENTRY glutStrokeHeight( void* font ); 150 | FGAPI void FGAPIENTRY glutBitmapString( void* font, const unsigned char *string ); 151 | FGAPI void FGAPIENTRY glutStrokeString( void* font, const unsigned char *string ); 152 | 153 | /* 154 | * Geometry functions, see freeglut_geometry.c 155 | */ 156 | FGAPI void FGAPIENTRY glutWireRhombicDodecahedron( void ); 157 | FGAPI void FGAPIENTRY glutSolidRhombicDodecahedron( void ); 158 | FGAPI void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale ); 159 | FGAPI void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale ); 160 | FGAPI void FGAPIENTRY glutWireCylinder( GLdouble radius, GLdouble height, GLint slices, GLint stacks); 161 | FGAPI void FGAPIENTRY glutSolidCylinder( GLdouble radius, GLdouble height, GLint slices, GLint stacks); 162 | 163 | /* 164 | * Extension functions, see freeglut_ext.c 165 | */ 166 | typedef void (*GLUTproc)(); 167 | FGAPI GLUTproc FGAPIENTRY glutGetProcAddress( const char *procName ); 168 | 169 | /* 170 | * Joystick functions, see freeglut_joystick.c 171 | */ 172 | /* USE OF THESE FUNCTIONS IS DEPRECATED !!!!! */ 173 | /* If you have a serious need for these functions in your application, please either 174 | * contact the "freeglut" developer community at freeglut-developer@lists.sourceforge.net, 175 | * switch to the OpenGLUT library, or else port your joystick functionality over to PLIB's 176 | * "js" library. 177 | */ 178 | int glutJoystickGetNumAxes( int ident ); 179 | int glutJoystickGetNumButtons( int ident ); 180 | int glutJoystickNotWorking( int ident ); 181 | float glutJoystickGetDeadBand( int ident, int axis ); 182 | void glutJoystickSetDeadBand( int ident, int axis, float db ); 183 | float glutJoystickGetSaturation( int ident, int axis ); 184 | void glutJoystickSetSaturation( int ident, int axis, float st ); 185 | void glutJoystickSetMinRange( int ident, float *axes ); 186 | void glutJoystickSetMaxRange( int ident, float *axes ); 187 | void glutJoystickSetCenter( int ident, float *axes ); 188 | void glutJoystickGetMinRange( int ident, float *axes ); 189 | void glutJoystickGetMaxRange( int ident, float *axes ); 190 | void glutJoystickGetCenter( int ident, float *axes ); 191 | 192 | /* 193 | * Initialization functions, see freeglut_init.c 194 | */ 195 | FGAPI void FGAPIENTRY glutInitContextVersion( int majorVersion, int minorVersion ); 196 | FGAPI void FGAPIENTRY glutInitContextFlags( int flags ); 197 | FGAPI void FGAPIENTRY glutInitContextProfile( int profile ); 198 | 199 | /* 200 | * GLUT API macro definitions -- the display mode definitions 201 | */ 202 | #define GLUT_CAPTIONLESS 0x0400 203 | #define GLUT_BORDERLESS 0x0800 204 | #define GLUT_SRGB 0x1000 205 | 206 | #ifdef __cplusplus 207 | } 208 | #endif 209 | 210 | /*** END OF FILE ***/ 211 | 212 | #endif /* __FREEGLUT_EXT_H__ */ 213 | -------------------------------------------------------------------------------- /include/GL/freeglut_std.h: -------------------------------------------------------------------------------- 1 | #ifndef __FREEGLUT_STD_H__ 2 | #define __FREEGLUT_STD_H__ 3 | 4 | /* 5 | * freeglut_std.h 6 | * 7 | * The GLUT-compatible part of the freeglut library include file 8 | * 9 | * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved. 10 | * Written by Pawel W. Olszta, 11 | * Creation date: Thu Dec 2 1999 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a 14 | * copy of this software and associated documentation files (the "Software"), 15 | * to deal in the Software without restriction, including without limitation 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | * and/or sell copies of the Software, and to permit persons to whom the 18 | * Software is furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included 21 | * in all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 27 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 28 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* 36 | * Under windows, we have to differentiate between static and dynamic libraries 37 | */ 38 | #ifdef _WIN32 39 | /* #pragma may not be supported by some compilers. 40 | * Discussion by FreeGLUT developers suggests that 41 | * Visual C++ specific code involving pragmas may 42 | * need to move to a separate header. 24th Dec 2003 43 | */ 44 | 45 | /* Define FREEGLUT_LIB_PRAGMAS to 1 to include library 46 | * pragmas or to 1 to exclude library pragmas. 47 | * The default behavior depends on the compiler/platform. 48 | */ 49 | # ifndef FREEGLUT_LIB_PRAGMAS 50 | # if ( defined(_MSC_VER) || defined(__WATCOMC__) ) && !defined(_WIN32_WCE) 51 | # define FREEGLUT_LIB_PRAGMAS 1 52 | # else 53 | # define FREEGLUT_LIB_PRAGMAS 0 54 | # endif 55 | # endif 56 | 57 | # ifndef WIN32_LEAN_AND_MEAN 58 | # define WIN32_LEAN_AND_MEAN 1 59 | # endif 60 | # define NOMINMAX 61 | # include 62 | 63 | /* Windows static library */ 64 | # ifdef FREEGLUT_STATIC 65 | 66 | # define FGAPI 67 | # define FGAPIENTRY 68 | 69 | /* Link with Win32 static freeglut lib */ 70 | # if FREEGLUT_LIB_PRAGMAS 71 | # pragma comment (lib, "freeglut_static.lib") 72 | # endif 73 | 74 | /* Windows shared library (DLL) */ 75 | # else 76 | 77 | # define FGAPIENTRY __stdcall 78 | # if defined(FREEGLUT_EXPORTS) 79 | # define FGAPI __declspec(dllexport) 80 | # else 81 | # define FGAPI __declspec(dllimport) 82 | 83 | /* Link with Win32 shared freeglut lib */ 84 | # if FREEGLUT_LIB_PRAGMAS 85 | # pragma comment (lib, "freeglut.lib") 86 | # endif 87 | 88 | # endif 89 | 90 | # endif 91 | 92 | /* Drag in other Windows libraries as required by FreeGLUT */ 93 | # if FREEGLUT_LIB_PRAGMAS 94 | # pragma comment (lib, "glu32.lib") /* link OpenGL Utility lib */ 95 | # pragma comment (lib, "opengl32.lib") /* link Microsoft OpenGL lib */ 96 | # pragma comment (lib, "gdi32.lib") /* link Windows GDI lib */ 97 | # pragma comment (lib, "winmm.lib") /* link Windows MultiMedia lib */ 98 | # pragma comment (lib, "user32.lib") /* link Windows user lib */ 99 | # endif 100 | 101 | #else 102 | 103 | /* Non-Windows definition of FGAPI and FGAPIENTRY */ 104 | # define FGAPI 105 | # define FGAPIENTRY 106 | 107 | #endif 108 | 109 | /* 110 | * The freeglut and GLUT API versions 111 | */ 112 | #define FREEGLUT 1 113 | #define GLUT_API_VERSION 4 114 | #define FREEGLUT_VERSION_2_0 1 115 | #define GLUT_XLIB_IMPLEMENTATION 13 116 | 117 | /* 118 | * Always include OpenGL and GLU headers 119 | */ 120 | #include 121 | #include 122 | 123 | /* 124 | * GLUT API macro definitions -- the special key codes: 125 | */ 126 | #define GLUT_KEY_F1 0x0001 127 | #define GLUT_KEY_F2 0x0002 128 | #define GLUT_KEY_F3 0x0003 129 | #define GLUT_KEY_F4 0x0004 130 | #define GLUT_KEY_F5 0x0005 131 | #define GLUT_KEY_F6 0x0006 132 | #define GLUT_KEY_F7 0x0007 133 | #define GLUT_KEY_F8 0x0008 134 | #define GLUT_KEY_F9 0x0009 135 | #define GLUT_KEY_F10 0x000A 136 | #define GLUT_KEY_F11 0x000B 137 | #define GLUT_KEY_F12 0x000C 138 | #define GLUT_KEY_LEFT 0x0064 139 | #define GLUT_KEY_UP 0x0065 140 | #define GLUT_KEY_RIGHT 0x0066 141 | #define GLUT_KEY_DOWN 0x0067 142 | #define GLUT_KEY_PAGE_UP 0x0068 143 | #define GLUT_KEY_PAGE_DOWN 0x0069 144 | #define GLUT_KEY_HOME 0x006A 145 | #define GLUT_KEY_END 0x006B 146 | #define GLUT_KEY_INSERT 0x006C 147 | 148 | /* 149 | * GLUT API macro definitions -- mouse state definitions 150 | */ 151 | #define GLUT_LEFT_BUTTON 0x0000 152 | #define GLUT_MIDDLE_BUTTON 0x0001 153 | #define GLUT_RIGHT_BUTTON 0x0002 154 | #define GLUT_DOWN 0x0000 155 | #define GLUT_UP 0x0001 156 | #define GLUT_LEFT 0x0000 157 | #define GLUT_ENTERED 0x0001 158 | 159 | /* 160 | * GLUT API macro definitions -- the display mode definitions 161 | */ 162 | #define GLUT_RGB 0x0000 163 | #define GLUT_RGBA 0x0000 164 | #define GLUT_INDEX 0x0001 165 | #define GLUT_SINGLE 0x0000 166 | #define GLUT_DOUBLE 0x0002 167 | #define GLUT_ACCUM 0x0004 168 | #define GLUT_ALPHA 0x0008 169 | #define GLUT_DEPTH 0x0010 170 | #define GLUT_STENCIL 0x0020 171 | #define GLUT_MULTISAMPLE 0x0080 172 | #define GLUT_STEREO 0x0100 173 | #define GLUT_LUMINANCE 0x0200 174 | 175 | /* 176 | * GLUT API macro definitions -- windows and menu related definitions 177 | */ 178 | #define GLUT_MENU_NOT_IN_USE 0x0000 179 | #define GLUT_MENU_IN_USE 0x0001 180 | #define GLUT_NOT_VISIBLE 0x0000 181 | #define GLUT_VISIBLE 0x0001 182 | #define GLUT_HIDDEN 0x0000 183 | #define GLUT_FULLY_RETAINED 0x0001 184 | #define GLUT_PARTIALLY_RETAINED 0x0002 185 | #define GLUT_FULLY_COVERED 0x0003 186 | 187 | /* 188 | * GLUT API macro definitions -- fonts definitions 189 | * 190 | * Steve Baker suggested to make it binary compatible with GLUT: 191 | */ 192 | #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__WATCOMC__) 193 | # define GLUT_STROKE_ROMAN ((void *)0x0000) 194 | # define GLUT_STROKE_MONO_ROMAN ((void *)0x0001) 195 | # define GLUT_BITMAP_9_BY_15 ((void *)0x0002) 196 | # define GLUT_BITMAP_8_BY_13 ((void *)0x0003) 197 | # define GLUT_BITMAP_TIMES_ROMAN_10 ((void *)0x0004) 198 | # define GLUT_BITMAP_TIMES_ROMAN_24 ((void *)0x0005) 199 | # define GLUT_BITMAP_HELVETICA_10 ((void *)0x0006) 200 | # define GLUT_BITMAP_HELVETICA_12 ((void *)0x0007) 201 | # define GLUT_BITMAP_HELVETICA_18 ((void *)0x0008) 202 | #else 203 | /* 204 | * I don't really know if it's a good idea... But here it goes: 205 | */ 206 | extern void* glutStrokeRoman; 207 | extern void* glutStrokeMonoRoman; 208 | extern void* glutBitmap9By15; 209 | extern void* glutBitmap8By13; 210 | extern void* glutBitmapTimesRoman10; 211 | extern void* glutBitmapTimesRoman24; 212 | extern void* glutBitmapHelvetica10; 213 | extern void* glutBitmapHelvetica12; 214 | extern void* glutBitmapHelvetica18; 215 | 216 | /* 217 | * Those pointers will be used by following definitions: 218 | */ 219 | # define GLUT_STROKE_ROMAN ((void *) &glutStrokeRoman) 220 | # define GLUT_STROKE_MONO_ROMAN ((void *) &glutStrokeMonoRoman) 221 | # define GLUT_BITMAP_9_BY_15 ((void *) &glutBitmap9By15) 222 | # define GLUT_BITMAP_8_BY_13 ((void *) &glutBitmap8By13) 223 | # define GLUT_BITMAP_TIMES_ROMAN_10 ((void *) &glutBitmapTimesRoman10) 224 | # define GLUT_BITMAP_TIMES_ROMAN_24 ((void *) &glutBitmapTimesRoman24) 225 | # define GLUT_BITMAP_HELVETICA_10 ((void *) &glutBitmapHelvetica10) 226 | # define GLUT_BITMAP_HELVETICA_12 ((void *) &glutBitmapHelvetica12) 227 | # define GLUT_BITMAP_HELVETICA_18 ((void *) &glutBitmapHelvetica18) 228 | #endif 229 | 230 | /* 231 | * GLUT API macro definitions -- the glutGet parameters 232 | */ 233 | #define GLUT_WINDOW_X 0x0064 234 | #define GLUT_WINDOW_Y 0x0065 235 | #define GLUT_WINDOW_WIDTH 0x0066 236 | #define GLUT_WINDOW_HEIGHT 0x0067 237 | #define GLUT_WINDOW_BUFFER_SIZE 0x0068 238 | #define GLUT_WINDOW_STENCIL_SIZE 0x0069 239 | #define GLUT_WINDOW_DEPTH_SIZE 0x006A 240 | #define GLUT_WINDOW_RED_SIZE 0x006B 241 | #define GLUT_WINDOW_GREEN_SIZE 0x006C 242 | #define GLUT_WINDOW_BLUE_SIZE 0x006D 243 | #define GLUT_WINDOW_ALPHA_SIZE 0x006E 244 | #define GLUT_WINDOW_ACCUM_RED_SIZE 0x006F 245 | #define GLUT_WINDOW_ACCUM_GREEN_SIZE 0x0070 246 | #define GLUT_WINDOW_ACCUM_BLUE_SIZE 0x0071 247 | #define GLUT_WINDOW_ACCUM_ALPHA_SIZE 0x0072 248 | #define GLUT_WINDOW_DOUBLEBUFFER 0x0073 249 | #define GLUT_WINDOW_RGBA 0x0074 250 | #define GLUT_WINDOW_PARENT 0x0075 251 | #define GLUT_WINDOW_NUM_CHILDREN 0x0076 252 | #define GLUT_WINDOW_COLORMAP_SIZE 0x0077 253 | #define GLUT_WINDOW_NUM_SAMPLES 0x0078 254 | #define GLUT_WINDOW_STEREO 0x0079 255 | #define GLUT_WINDOW_CURSOR 0x007A 256 | 257 | #define GLUT_SCREEN_WIDTH 0x00C8 258 | #define GLUT_SCREEN_HEIGHT 0x00C9 259 | #define GLUT_SCREEN_WIDTH_MM 0x00CA 260 | #define GLUT_SCREEN_HEIGHT_MM 0x00CB 261 | #define GLUT_MENU_NUM_ITEMS 0x012C 262 | #define GLUT_DISPLAY_MODE_POSSIBLE 0x0190 263 | #define GLUT_INIT_WINDOW_X 0x01F4 264 | #define GLUT_INIT_WINDOW_Y 0x01F5 265 | #define GLUT_INIT_WINDOW_WIDTH 0x01F6 266 | #define GLUT_INIT_WINDOW_HEIGHT 0x01F7 267 | #define GLUT_INIT_DISPLAY_MODE 0x01F8 268 | #define GLUT_ELAPSED_TIME 0x02BC 269 | #define GLUT_WINDOW_FORMAT_ID 0x007B 270 | 271 | /* 272 | * GLUT API macro definitions -- the glutDeviceGet parameters 273 | */ 274 | #define GLUT_HAS_KEYBOARD 0x0258 275 | #define GLUT_HAS_MOUSE 0x0259 276 | #define GLUT_HAS_SPACEBALL 0x025A 277 | #define GLUT_HAS_DIAL_AND_BUTTON_BOX 0x025B 278 | #define GLUT_HAS_TABLET 0x025C 279 | #define GLUT_NUM_MOUSE_BUTTONS 0x025D 280 | #define GLUT_NUM_SPACEBALL_BUTTONS 0x025E 281 | #define GLUT_NUM_BUTTON_BOX_BUTTONS 0x025F 282 | #define GLUT_NUM_DIALS 0x0260 283 | #define GLUT_NUM_TABLET_BUTTONS 0x0261 284 | #define GLUT_DEVICE_IGNORE_KEY_REPEAT 0x0262 285 | #define GLUT_DEVICE_KEY_REPEAT 0x0263 286 | #define GLUT_HAS_JOYSTICK 0x0264 287 | #define GLUT_OWNS_JOYSTICK 0x0265 288 | #define GLUT_JOYSTICK_BUTTONS 0x0266 289 | #define GLUT_JOYSTICK_AXES 0x0267 290 | #define GLUT_JOYSTICK_POLL_RATE 0x0268 291 | 292 | /* 293 | * GLUT API macro definitions -- the glutLayerGet parameters 294 | */ 295 | #define GLUT_OVERLAY_POSSIBLE 0x0320 296 | #define GLUT_LAYER_IN_USE 0x0321 297 | #define GLUT_HAS_OVERLAY 0x0322 298 | #define GLUT_TRANSPARENT_INDEX 0x0323 299 | #define GLUT_NORMAL_DAMAGED 0x0324 300 | #define GLUT_OVERLAY_DAMAGED 0x0325 301 | 302 | /* 303 | * GLUT API macro definitions -- the glutVideoResizeGet parameters 304 | */ 305 | #define GLUT_VIDEO_RESIZE_POSSIBLE 0x0384 306 | #define GLUT_VIDEO_RESIZE_IN_USE 0x0385 307 | #define GLUT_VIDEO_RESIZE_X_DELTA 0x0386 308 | #define GLUT_VIDEO_RESIZE_Y_DELTA 0x0387 309 | #define GLUT_VIDEO_RESIZE_WIDTH_DELTA 0x0388 310 | #define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 0x0389 311 | #define GLUT_VIDEO_RESIZE_X 0x038A 312 | #define GLUT_VIDEO_RESIZE_Y 0x038B 313 | #define GLUT_VIDEO_RESIZE_WIDTH 0x038C 314 | #define GLUT_VIDEO_RESIZE_HEIGHT 0x038D 315 | 316 | /* 317 | * GLUT API macro definitions -- the glutUseLayer parameters 318 | */ 319 | #define GLUT_NORMAL 0x0000 320 | #define GLUT_OVERLAY 0x0001 321 | 322 | /* 323 | * GLUT API macro definitions -- the glutGetModifiers parameters 324 | */ 325 | #define GLUT_ACTIVE_SHIFT 0x0001 326 | #define GLUT_ACTIVE_CTRL 0x0002 327 | #define GLUT_ACTIVE_ALT 0x0004 328 | 329 | /* 330 | * GLUT API macro definitions -- the glutSetCursor parameters 331 | */ 332 | #define GLUT_CURSOR_RIGHT_ARROW 0x0000 333 | #define GLUT_CURSOR_LEFT_ARROW 0x0001 334 | #define GLUT_CURSOR_INFO 0x0002 335 | #define GLUT_CURSOR_DESTROY 0x0003 336 | #define GLUT_CURSOR_HELP 0x0004 337 | #define GLUT_CURSOR_CYCLE 0x0005 338 | #define GLUT_CURSOR_SPRAY 0x0006 339 | #define GLUT_CURSOR_WAIT 0x0007 340 | #define GLUT_CURSOR_TEXT 0x0008 341 | #define GLUT_CURSOR_CROSSHAIR 0x0009 342 | #define GLUT_CURSOR_UP_DOWN 0x000A 343 | #define GLUT_CURSOR_LEFT_RIGHT 0x000B 344 | #define GLUT_CURSOR_TOP_SIDE 0x000C 345 | #define GLUT_CURSOR_BOTTOM_SIDE 0x000D 346 | #define GLUT_CURSOR_LEFT_SIDE 0x000E 347 | #define GLUT_CURSOR_RIGHT_SIDE 0x000F 348 | #define GLUT_CURSOR_TOP_LEFT_CORNER 0x0010 349 | #define GLUT_CURSOR_TOP_RIGHT_CORNER 0x0011 350 | #define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 0x0012 351 | #define GLUT_CURSOR_BOTTOM_LEFT_CORNER 0x0013 352 | #define GLUT_CURSOR_INHERIT 0x0064 353 | #define GLUT_CURSOR_NONE 0x0065 354 | #define GLUT_CURSOR_FULL_CROSSHAIR 0x0066 355 | 356 | /* 357 | * GLUT API macro definitions -- RGB color component specification definitions 358 | */ 359 | #define GLUT_RED 0x0000 360 | #define GLUT_GREEN 0x0001 361 | #define GLUT_BLUE 0x0002 362 | 363 | /* 364 | * GLUT API macro definitions -- additional keyboard and joystick definitions 365 | */ 366 | #define GLUT_KEY_REPEAT_OFF 0x0000 367 | #define GLUT_KEY_REPEAT_ON 0x0001 368 | #define GLUT_KEY_REPEAT_DEFAULT 0x0002 369 | 370 | #define GLUT_JOYSTICK_BUTTON_A 0x0001 371 | #define GLUT_JOYSTICK_BUTTON_B 0x0002 372 | #define GLUT_JOYSTICK_BUTTON_C 0x0004 373 | #define GLUT_JOYSTICK_BUTTON_D 0x0008 374 | 375 | /* 376 | * GLUT API macro definitions -- game mode definitions 377 | */ 378 | #define GLUT_GAME_MODE_ACTIVE 0x0000 379 | #define GLUT_GAME_MODE_POSSIBLE 0x0001 380 | #define GLUT_GAME_MODE_WIDTH 0x0002 381 | #define GLUT_GAME_MODE_HEIGHT 0x0003 382 | #define GLUT_GAME_MODE_PIXEL_DEPTH 0x0004 383 | #define GLUT_GAME_MODE_REFRESH_RATE 0x0005 384 | #define GLUT_GAME_MODE_DISPLAY_CHANGED 0x0006 385 | 386 | /* 387 | * Initialization functions, see fglut_init.c 388 | */ 389 | FGAPI void FGAPIENTRY glutInit( int* pargc, char** argv ); 390 | FGAPI void FGAPIENTRY glutInitWindowPosition( int x, int y ); 391 | FGAPI void FGAPIENTRY glutInitWindowSize( int width, int height ); 392 | FGAPI void FGAPIENTRY glutInitDisplayMode( unsigned int displayMode ); 393 | FGAPI void FGAPIENTRY glutInitDisplayString( const char* displayMode ); 394 | 395 | /* 396 | * Process loop function, see freeglut_main.c 397 | */ 398 | FGAPI void FGAPIENTRY glutMainLoop( void ); 399 | 400 | /* 401 | * Window management functions, see freeglut_window.c 402 | */ 403 | FGAPI int FGAPIENTRY glutCreateWindow( const char* title ); 404 | FGAPI int FGAPIENTRY glutCreateSubWindow( int window, int x, int y, int width, int height ); 405 | FGAPI void FGAPIENTRY glutDestroyWindow( int window ); 406 | FGAPI void FGAPIENTRY glutSetWindow( int window ); 407 | FGAPI int FGAPIENTRY glutGetWindow( void ); 408 | FGAPI void FGAPIENTRY glutSetWindowTitle( const char* title ); 409 | FGAPI void FGAPIENTRY glutSetIconTitle( const char* title ); 410 | FGAPI void FGAPIENTRY glutReshapeWindow( int width, int height ); 411 | FGAPI void FGAPIENTRY glutPositionWindow( int x, int y ); 412 | FGAPI void FGAPIENTRY glutShowWindow( void ); 413 | FGAPI void FGAPIENTRY glutHideWindow( void ); 414 | FGAPI void FGAPIENTRY glutIconifyWindow( void ); 415 | FGAPI void FGAPIENTRY glutPushWindow( void ); 416 | FGAPI void FGAPIENTRY glutPopWindow( void ); 417 | FGAPI void FGAPIENTRY glutFullScreen( void ); 418 | 419 | /* 420 | * Display-connected functions, see freeglut_display.c 421 | */ 422 | FGAPI void FGAPIENTRY glutPostWindowRedisplay( int window ); 423 | FGAPI void FGAPIENTRY glutPostRedisplay( void ); 424 | FGAPI void FGAPIENTRY glutSwapBuffers( void ); 425 | 426 | /* 427 | * Mouse cursor functions, see freeglut_cursor.c 428 | */ 429 | FGAPI void FGAPIENTRY glutWarpPointer( int x, int y ); 430 | FGAPI void FGAPIENTRY glutSetCursor( int cursor ); 431 | 432 | /* 433 | * Overlay stuff, see freeglut_overlay.c 434 | */ 435 | FGAPI void FGAPIENTRY glutEstablishOverlay( void ); 436 | FGAPI void FGAPIENTRY glutRemoveOverlay( void ); 437 | FGAPI void FGAPIENTRY glutUseLayer( GLenum layer ); 438 | FGAPI void FGAPIENTRY glutPostOverlayRedisplay( void ); 439 | FGAPI void FGAPIENTRY glutPostWindowOverlayRedisplay( int window ); 440 | FGAPI void FGAPIENTRY glutShowOverlay( void ); 441 | FGAPI void FGAPIENTRY glutHideOverlay( void ); 442 | 443 | /* 444 | * Menu stuff, see freeglut_menu.c 445 | */ 446 | FGAPI int FGAPIENTRY glutCreateMenu( void (* callback)( int menu ) ); 447 | FGAPI void FGAPIENTRY glutDestroyMenu( int menu ); 448 | FGAPI int FGAPIENTRY glutGetMenu( void ); 449 | FGAPI void FGAPIENTRY glutSetMenu( int menu ); 450 | FGAPI void FGAPIENTRY glutAddMenuEntry( const char* label, int value ); 451 | FGAPI void FGAPIENTRY glutAddSubMenu( const char* label, int subMenu ); 452 | FGAPI void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value ); 453 | FGAPI void FGAPIENTRY glutChangeToSubMenu( int item, const char* label, int value ); 454 | FGAPI void FGAPIENTRY glutRemoveMenuItem( int item ); 455 | FGAPI void FGAPIENTRY glutAttachMenu( int button ); 456 | FGAPI void FGAPIENTRY glutDetachMenu( int button ); 457 | 458 | /* 459 | * Global callback functions, see freeglut_callbacks.c 460 | */ 461 | FGAPI void FGAPIENTRY glutTimerFunc( unsigned int time, void (* callback)( int ), int value ); 462 | FGAPI void FGAPIENTRY glutIdleFunc( void (* callback)( void ) ); 463 | 464 | /* 465 | * Window-specific callback functions, see freeglut_callbacks.c 466 | */ 467 | FGAPI void FGAPIENTRY glutKeyboardFunc( void (* callback)( unsigned char, int, int ) ); 468 | FGAPI void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) ); 469 | FGAPI void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) ); 470 | FGAPI void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) ); 471 | FGAPI void FGAPIENTRY glutDisplayFunc( void (* callback)( void ) ); 472 | FGAPI void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) ); 473 | FGAPI void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) ); 474 | FGAPI void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) ); 475 | FGAPI void FGAPIENTRY glutEntryFunc( void (* callback)( int ) ); 476 | 477 | FGAPI void FGAPIENTRY glutKeyboardUpFunc( void (* callback)( unsigned char, int, int ) ); 478 | FGAPI void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) ); 479 | FGAPI void FGAPIENTRY glutJoystickFunc( void (* callback)( unsigned int, int, int, int ), int pollInterval ); 480 | FGAPI void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) ); 481 | FGAPI void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) ); 482 | FGAPI void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) ); 483 | FGAPI void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) ); 484 | 485 | FGAPI void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) ); 486 | FGAPI void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) ); 487 | FGAPI void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) ); 488 | FGAPI void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) ); 489 | FGAPI void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) ); 490 | FGAPI void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) ); 491 | FGAPI void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) ); 492 | 493 | /* 494 | * State setting and retrieval functions, see freeglut_state.c 495 | */ 496 | FGAPI int FGAPIENTRY glutGet( GLenum query ); 497 | FGAPI int FGAPIENTRY glutDeviceGet( GLenum query ); 498 | FGAPI int FGAPIENTRY glutGetModifiers( void ); 499 | FGAPI int FGAPIENTRY glutLayerGet( GLenum query ); 500 | 501 | /* 502 | * Font stuff, see freeglut_font.c 503 | */ 504 | FGAPI void FGAPIENTRY glutBitmapCharacter( void* font, int character ); 505 | FGAPI int FGAPIENTRY glutBitmapWidth( void* font, int character ); 506 | FGAPI void FGAPIENTRY glutStrokeCharacter( void* font, int character ); 507 | FGAPI int FGAPIENTRY glutStrokeWidth( void* font, int character ); 508 | FGAPI int FGAPIENTRY glutBitmapLength( void* font, const unsigned char* string ); 509 | FGAPI int FGAPIENTRY glutStrokeLength( void* font, const unsigned char* string ); 510 | 511 | /* 512 | * Geometry functions, see freeglut_geometry.c 513 | */ 514 | FGAPI void FGAPIENTRY glutWireCube( GLdouble size ); 515 | FGAPI void FGAPIENTRY glutSolidCube( GLdouble size ); 516 | FGAPI void FGAPIENTRY glutWireSphere( GLdouble radius, GLint slices, GLint stacks ); 517 | FGAPI void FGAPIENTRY glutSolidSphere( GLdouble radius, GLint slices, GLint stacks ); 518 | FGAPI void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks ); 519 | FGAPI void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks ); 520 | 521 | FGAPI void FGAPIENTRY glutWireTorus( GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings ); 522 | FGAPI void FGAPIENTRY glutSolidTorus( GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings ); 523 | FGAPI void FGAPIENTRY glutWireDodecahedron( void ); 524 | FGAPI void FGAPIENTRY glutSolidDodecahedron( void ); 525 | FGAPI void FGAPIENTRY glutWireOctahedron( void ); 526 | FGAPI void FGAPIENTRY glutSolidOctahedron( void ); 527 | FGAPI void FGAPIENTRY glutWireTetrahedron( void ); 528 | FGAPI void FGAPIENTRY glutSolidTetrahedron( void ); 529 | FGAPI void FGAPIENTRY glutWireIcosahedron( void ); 530 | FGAPI void FGAPIENTRY glutSolidIcosahedron( void ); 531 | 532 | /* 533 | * Teapot rendering functions, found in freeglut_teapot.c 534 | */ 535 | FGAPI void FGAPIENTRY glutWireTeapot( GLdouble size ); 536 | FGAPI void FGAPIENTRY glutSolidTeapot( GLdouble size ); 537 | 538 | /* 539 | * Game mode functions, see freeglut_gamemode.c 540 | */ 541 | FGAPI void FGAPIENTRY glutGameModeString( const char* string ); 542 | FGAPI int FGAPIENTRY glutEnterGameMode( void ); 543 | FGAPI void FGAPIENTRY glutLeaveGameMode( void ); 544 | FGAPI int FGAPIENTRY glutGameModeGet( GLenum query ); 545 | 546 | /* 547 | * Video resize functions, see freeglut_videoresize.c 548 | */ 549 | FGAPI int FGAPIENTRY glutVideoResizeGet( GLenum query ); 550 | FGAPI void FGAPIENTRY glutSetupVideoResizing( void ); 551 | FGAPI void FGAPIENTRY glutStopVideoResizing( void ); 552 | FGAPI void FGAPIENTRY glutVideoResize( int x, int y, int width, int height ); 553 | FGAPI void FGAPIENTRY glutVideoPan( int x, int y, int width, int height ); 554 | 555 | /* 556 | * Colormap functions, see freeglut_misc.c 557 | */ 558 | FGAPI void FGAPIENTRY glutSetColor( int color, GLfloat red, GLfloat green, GLfloat blue ); 559 | FGAPI GLfloat FGAPIENTRY glutGetColor( int color, int component ); 560 | FGAPI void FGAPIENTRY glutCopyColormap( int window ); 561 | 562 | /* 563 | * Misc keyboard and joystick functions, see freeglut_misc.c 564 | */ 565 | FGAPI void FGAPIENTRY glutIgnoreKeyRepeat( int ignore ); 566 | FGAPI void FGAPIENTRY glutSetKeyRepeat( int repeatMode ); 567 | FGAPI void FGAPIENTRY glutForceJoystickFunc( void ); 568 | 569 | /* 570 | * Misc functions, see freeglut_misc.c 571 | */ 572 | FGAPI int FGAPIENTRY glutExtensionSupported( const char* extension ); 573 | FGAPI void FGAPIENTRY glutReportErrors( void ); 574 | 575 | /* Comment from glut.h of classic GLUT: 576 | 577 | Win32 has an annoying issue where there are multiple C run-time 578 | libraries (CRTs). If the executable is linked with a different CRT 579 | from the GLUT DLL, the GLUT DLL will not share the same CRT static 580 | data seen by the executable. In particular, atexit callbacks registered 581 | in the executable will not be called if GLUT calls its (different) 582 | exit routine). GLUT is typically built with the 583 | "/MD" option (the CRT with multithreading DLL support), but the Visual 584 | C++ linker default is "/ML" (the single threaded CRT). 585 | 586 | One workaround to this issue is requiring users to always link with 587 | the same CRT as GLUT is compiled with. That requires users supply a 588 | non-standard option. GLUT 3.7 has its own built-in workaround where 589 | the executable's "exit" function pointer is covertly passed to GLUT. 590 | GLUT then calls the executable's exit function pointer to ensure that 591 | any "atexit" calls registered by the application are called if GLUT 592 | needs to exit. 593 | 594 | Note that the __glut*WithExit routines should NEVER be called directly. 595 | To avoid the atexit workaround, #define GLUT_DISABLE_ATEXIT_HACK. */ 596 | 597 | /* to get the prototype for exit() */ 598 | #include 599 | 600 | #if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK) && !defined(__WATCOMC__) 601 | FGAPI void FGAPIENTRY __glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int)); 602 | FGAPI int FGAPIENTRY __glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int)); 603 | FGAPI int FGAPIENTRY __glutCreateMenuWithExit(void (* func)(int), void (__cdecl *exitfunc)(int)); 604 | #ifndef FREEGLUT_BUILDING_LIB 605 | #if defined(__GNUC__) 606 | #define FGUNUSED __attribute__((unused)) 607 | #else 608 | #define FGUNUSED 609 | #endif 610 | static void FGAPIENTRY FGUNUSED glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); } 611 | #define glutInit glutInit_ATEXIT_HACK 612 | static int FGAPIENTRY FGUNUSED glutCreateWindow_ATEXIT_HACK(const char *title) { return __glutCreateWindowWithExit(title, exit); } 613 | #define glutCreateWindow glutCreateWindow_ATEXIT_HACK 614 | static int FGAPIENTRY FGUNUSED glutCreateMenu_ATEXIT_HACK(void (* func)(int)) { return __glutCreateMenuWithExit(func, exit); } 615 | #define glutCreateMenu glutCreateMenu_ATEXIT_HACK 616 | #endif 617 | #endif 618 | 619 | #ifdef __cplusplus 620 | } 621 | #endif 622 | 623 | /*** END OF FILE ***/ 624 | 625 | #endif /* __FREEGLUT_STD_H__ */ 626 | 627 | -------------------------------------------------------------------------------- /lib/linux/lin32/libAntTweakBar.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/lib/linux/lin32/libAntTweakBar.so -------------------------------------------------------------------------------- /lib/linux/lin32/libAntTweakBar.so.1: -------------------------------------------------------------------------------- 1 | ./libAntTweakBar.so -------------------------------------------------------------------------------- /lib/linux/lin32/libGLEW.so: -------------------------------------------------------------------------------- 1 | ./libGLEW.so.1.7.0 -------------------------------------------------------------------------------- /lib/linux/lin32/libGLEW.so.1.7: -------------------------------------------------------------------------------- 1 | ./libGLEW.so.1.7.0 -------------------------------------------------------------------------------- /lib/linux/lin32/libGLEW.so.1.7.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/lib/linux/lin32/libGLEW.so.1.7.0 -------------------------------------------------------------------------------- /lib/linux/lin32/libglut.so: -------------------------------------------------------------------------------- 1 | ./libglut.so.3.9.0 -------------------------------------------------------------------------------- /lib/linux/lin32/libglut.so.3: -------------------------------------------------------------------------------- 1 | ./libglut.so.3.9.0 -------------------------------------------------------------------------------- /lib/linux/lin32/libglut.so.3.9.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/lib/linux/lin32/libglut.so.3.9.0 -------------------------------------------------------------------------------- /lib/linux/lin64/libAntTweakBar.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/lib/linux/lin64/libAntTweakBar.so -------------------------------------------------------------------------------- /lib/linux/lin64/libAntTweakBar.so.1: -------------------------------------------------------------------------------- 1 | ./libAntTweakBar.so -------------------------------------------------------------------------------- /lib/linux/lin64/libGLEW.so: -------------------------------------------------------------------------------- 1 | ./libGLEW.so.1.7.0 -------------------------------------------------------------------------------- /lib/linux/lin64/libGLEW.so.1.7: -------------------------------------------------------------------------------- 1 | ./libGLEW.so.1.7.0 -------------------------------------------------------------------------------- /lib/linux/lin64/libGLEW.so.1.7.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/lib/linux/lin64/libGLEW.so.1.7.0 -------------------------------------------------------------------------------- /lib/linux/lin64/libglut.so: -------------------------------------------------------------------------------- 1 | ./libglut.so.3.9.0 -------------------------------------------------------------------------------- /lib/linux/lin64/libglut.so.3: -------------------------------------------------------------------------------- 1 | ./libglut.so.3.9.0 -------------------------------------------------------------------------------- /lib/linux/lin64/libglut.so.3.9.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/lib/linux/lin64/libglut.so.3.9.0 -------------------------------------------------------------------------------- /lib/windows/win32/AntTweakBar.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/lib/windows/win32/AntTweakBar.lib -------------------------------------------------------------------------------- /lib/windows/win32/freeglut.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/lib/windows/win32/freeglut.lib -------------------------------------------------------------------------------- /lib/windows/win32/glew32s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdupuy/marchingCube/0e8b46a56d3bf69246f34672d9500d3d44040147/lib/windows/win32/glew32s.lib -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // \author Jonathan Dupuy 3 | // 4 | //////////////////////////////////////////////////////////////////////////////// 5 | 6 | // enable gui 7 | #define _ANT_ENABLE 8 | 9 | // GL libraries 10 | #include "glew.hpp" 11 | #include "GL/freeglut.h" 12 | 13 | #ifdef _ANT_ENABLE 14 | # include "AntTweakBar.h" 15 | #endif // _ANT_ENABLE 16 | 17 | // Standard librabries 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | // Custom libraries 25 | #include "Algebra.hpp" // Basic algebra library 26 | #include "Transform.hpp" // Basic transformations 27 | #include "Framework.hpp" // utility classes/functions 28 | 29 | #include "MarchingCubeTables.hpp" // tables for marching cube 30 | 31 | 32 | //////////////////////////////////////////////////////////////////////////////// 33 | // Global variables 34 | // 35 | //////////////////////////////////////////////////////////////////////////////// 36 | 37 | // Constants 38 | const float PI = 3.14159265; 39 | const float FOVY = PI*0.25f; 40 | 41 | enum { 42 | // buffers 43 | BUFFER_CUBE_VERTICES = 0, 44 | BUFFER_CUBE_INDEXES, 45 | BUFFER_CASE_TO_FACE_COUNT, 46 | BUFFER_EDGE_CONNECT_LIST, 47 | BUFFER_COUNT, 48 | 49 | // vertex arrays 50 | VERTEX_ARRAY_CUBE = 0, 51 | VERTEX_ARRAY_EMPTY, 52 | VERTEX_ARRAY_COUNT, 53 | 54 | // textures 55 | TEXTURE_EDGE_CONNECT_LIST = 0, 56 | TEXTURE_COUNT, 57 | 58 | // programs 59 | PROGRAM_CUBE = 0, 60 | PROGRAM_MARCHING_CUBE, 61 | PROGRAM_COUNT 62 | }; 63 | 64 | // OpenGL objects 65 | GLuint *buffers = NULL; 66 | GLuint *vertexArrays = NULL; 67 | GLuint *textures = NULL; 68 | GLuint *programs = NULL; 69 | 70 | // Tools 71 | Affine cameraInvWorld = Affine::Translation(Vector3(0,0,-2.5)); 72 | Projection cameraProjection = Projection::Perspective(FOVY, 73 | 1.0f, 74 | 0.1f, 75 | 10.0f); 76 | 77 | bool mouseLeft = false; 78 | bool mouseRight = false; 79 | 80 | GLfloat deltaTicks = 0.0f; 81 | GLint marchingCubeCase = 0; 82 | 83 | #ifdef _ANT_ENABLE 84 | GLfloat speed = 0.0f; // app speed (in ms) 85 | #endif 86 | 87 | 88 | //////////////////////////////////////////////////////////////////////////////// 89 | // Functions 90 | // 91 | //////////////////////////////////////////////////////////////////////////////// 92 | 93 | // convert nvidia indexes to compressed index 94 | static GLint voxel_edge_to_vertices(GLint edge) { 95 | GLint edges = 0; 96 | switch(edge) { 97 | case 0: edges = 0x0 | 0x1<<3; break; 98 | case 1: edges = 0x1 | 0x2<<3; break; 99 | case 2: edges = 0x2 | 0x3<<3; break; 100 | case 3: edges = 0x0 | 0x3<<3; break; 101 | case 4: edges = 0x4 | 0x5<<3; break; 102 | case 5: edges = 0x5 | 0x6<<3; break; 103 | case 6: edges = 0x6 | 0x7<<3; break; 104 | case 7: edges = 0x4 | 0x7<<3; break; 105 | case 8: edges = 0x0 | 0x4<<3; break; 106 | case 9: edges = 0x1 | 0x5<<3; break; 107 | case 10: edges = 0x2 | 0x6<<3; break; 108 | case 11: edges = 0x3 | 0x7<<3; break; 109 | default: break; 110 | } 111 | return edges; 112 | } 113 | 114 | #ifdef _ANT_ENABLE 115 | 116 | static void TW_CALL toggle_fullscreen(void *data) { 117 | // toggle fullscreen 118 | glutFullScreenToggle(); 119 | } 120 | 121 | #endif // _USE_GUI 122 | 123 | //////////////////////////////////////////////////////////////////////////////// 124 | // on init cb 125 | void on_init() { 126 | // GLint maxUniformBlockSize = 0; 127 | // glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &maxUniformBlockSize); 128 | // std::cout << "GL_MAX_UNIFORM_BLOCK_SIZE : " << maxUniformBlockSize << std::endl; 129 | const GLfloat CUBE_VERTICES[] = { -0.5f, -0.5f, 0.5f, 1, // 0 130 | -0.5f, 0.5f, 0.5f, 1, // 1 131 | 0.5f, 0.5f, 0.5f, 1, // 2 132 | 0.5f, -0.5f, 0.5f, 1, // 3 133 | -0.5f, -0.5f, -0.5f, 1, // 4 134 | -0.5f, 0.5f, -0.5f, 1, // 5 135 | 0.5f, 0.5f, -0.5f, 1, // 6 136 | 0.5f, -0.5f, -0.5f, 1 }; // 7 137 | const GLushort CUBE_INDEXES[] = { 2,1,1,0,0,3, // front 138 | 6,2,2,3,3,7, // right 139 | 5,6,6,7,7,4, // back 140 | 1,5,5,4,4,0 }; // left 141 | GLint* edgeList = new GLint[2048]; 142 | GLint compressedVertexIndex = 0; 143 | 144 | // compress table 145 | for(GLint i = 0; i<256*5*4; i+=4) { 146 | compressedVertexIndex = voxel_edge_to_vertices(EDGE_CONNECT_LIST[i]); 147 | compressedVertexIndex|= voxel_edge_to_vertices(EDGE_CONNECT_LIST[i+1]) 148 | << 6; 149 | compressedVertexIndex|= voxel_edge_to_vertices(EDGE_CONNECT_LIST[i+2]) 150 | << 12; 151 | // drop fourth component (which is always -1) 152 | edgeList[i/4] = compressedVertexIndex; 153 | } 154 | 155 | // alloc names 156 | buffers = new GLuint[BUFFER_COUNT]; 157 | vertexArrays = new GLuint[VERTEX_ARRAY_COUNT]; 158 | textures = new GLuint[TEXTURE_COUNT]; 159 | programs = new GLuint[PROGRAM_COUNT]; 160 | 161 | // gen names 162 | glGenBuffers(BUFFER_COUNT, buffers); 163 | glGenVertexArrays(VERTEX_ARRAY_COUNT, vertexArrays); 164 | glGenTextures(TEXTURE_COUNT, textures); 165 | for(GLuint i=0; i(&mvp)); 329 | glProgramUniformMatrix4fv(programs[PROGRAM_MARCHING_CUBE], 330 | glGetUniformLocation(programs[PROGRAM_MARCHING_CUBE], 331 | "uModelViewProjection"), 332 | 1, 333 | 0, 334 | reinterpret_cast(&mvp)); 335 | glProgramUniform1i(programs[PROGRAM_MARCHING_CUBE], 336 | glGetUniformLocation(programs[PROGRAM_MARCHING_CUBE], 337 | "uCase"), 338 | marchingCubeCase); 339 | 340 | // set viewport 341 | glViewport(0,0,windowWidth, windowHeight); 342 | 343 | // clear back buffer 344 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 345 | 346 | // render the cube 347 | glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 348 | glUseProgram(programs[PROGRAM_CUBE]); 349 | glBindVertexArray(vertexArrays[VERTEX_ARRAY_CUBE]); 350 | glDrawElements(GL_LINES, 351 | 24, 352 | GL_UNSIGNED_SHORT, 353 | FW_BUFFER_OFFSET(0)); 354 | 355 | // run marching cube 356 | glUseProgram(programs[PROGRAM_MARCHING_CUBE]); 357 | // glBindVertexArray(vertexArrays[VERTEX_ARRAY_EMPTY]); 358 | glBindVertexArray(vertexArrays[VERTEX_ARRAY_CUBE]); // hack for amd 359 | glDrawArrays(GL_POINTS, 0, 1); 360 | 361 | glBindVertexArray(0); 362 | 363 | #ifdef _ANT_ENABLE 364 | // back to default vertex array 365 | TwDraw(); 366 | #endif // _ANT_ENABLE 367 | 368 | fw::check_gl_error(); 369 | 370 | // start ticking 371 | deltaTimer.Start(); 372 | 373 | glutSwapBuffers(); 374 | glutPostRedisplay(); 375 | } 376 | 377 | 378 | //////////////////////////////////////////////////////////////////////////////// 379 | // on resize cb 380 | void on_resize(GLint w, GLint h) { 381 | #ifdef _ANT_ENABLE 382 | TwWindowSize(w, h); 383 | #endif 384 | // update projection 385 | cameraProjection.FitWidthToAspect(float(w)/float(h)); 386 | } 387 | 388 | 389 | //////////////////////////////////////////////////////////////////////////////// 390 | // on key down cb 391 | void on_key_down(GLubyte key, GLint x, GLint y) { 392 | #ifdef _ANT_ENABLE 393 | if(1==TwEventKeyboardGLUT(key, x, y)) 394 | return; 395 | #endif 396 | if (key==27) // escape 397 | glutLeaveMainLoop(); 398 | if(key=='f') 399 | glutFullScreenToggle(); 400 | if(key=='p') 401 | fw::save_gl_front_buffer(0, 402 | 0, 403 | glutGet(GLUT_WINDOW_WIDTH), 404 | glutGet(GLUT_WINDOW_HEIGHT)); 405 | 406 | } 407 | 408 | 409 | //////////////////////////////////////////////////////////////////////////////// 410 | // on mouse button cb 411 | void on_mouse_button(GLint button, GLint state, GLint x, GLint y) { 412 | #ifdef _ANT_ENABLE 413 | if(1 == TwEventMouseButtonGLUT(button, state, x, y)) 414 | return; 415 | #endif // _ANT_ENABLE 416 | if(state==GLUT_DOWN) 417 | { 418 | mouseLeft |= button == GLUT_LEFT_BUTTON; 419 | mouseRight |= button == GLUT_RIGHT_BUTTON; 420 | } 421 | else 422 | { 423 | mouseLeft &= button == GLUT_LEFT_BUTTON ? false : mouseLeft; 424 | mouseRight &= button == GLUT_RIGHT_BUTTON ? false : mouseRight; 425 | } 426 | if(button == 3) 427 | cameraInvWorld.TranslateWorld(Vector3(0,0,0.15f)); 428 | if(button == 4) 429 | cameraInvWorld.TranslateWorld(Vector3(0,0,-0.15f)); 430 | } 431 | 432 | 433 | //////////////////////////////////////////////////////////////////////////////// 434 | // on mouse motion cb 435 | void on_mouse_motion(GLint x, GLint y) { 436 | #ifdef _ANT_ENABLE 437 | if(1 == TwEventMouseMotionGLUT(x,y)) 438 | return; 439 | #endif // _ANT_ENABLE 440 | 441 | static GLint sMousePreviousX = 0; 442 | static GLint sMousePreviousY = 0; 443 | const GLint MOUSE_XREL = x-sMousePreviousX; 444 | const GLint MOUSE_YREL = y-sMousePreviousY; 445 | sMousePreviousX = x; 446 | sMousePreviousY = y; 447 | 448 | if(mouseLeft) 449 | { 450 | cameraInvWorld.RotateAboutWorldX(1.0f*MOUSE_YREL*deltaTicks); 451 | cameraInvWorld.RotateAboutLocalY(1.0f*MOUSE_XREL*deltaTicks); 452 | } 453 | if(mouseRight) 454 | { 455 | cameraInvWorld.TranslateWorld(deltaTicks*Vector3( 0.3f*MOUSE_XREL, 456 | -0.3f*MOUSE_YREL, 457 | 0)); 458 | } 459 | } 460 | 461 | 462 | //////////////////////////////////////////////////////////////////////////////// 463 | // on mouse wheel cb 464 | void on_mouse_wheel(GLint wheel, GLint direction, GLint x, GLint y) { 465 | #ifdef _ANT_ENABLE 466 | if(1 == TwMouseWheel(wheel)) 467 | return; 468 | #endif // _ANT_ENABLE 469 | cameraInvWorld.TranslateWorld(Vector3(0,0,float(direction)*0.15f)); 470 | } 471 | 472 | 473 | //////////////////////////////////////////////////////////////////////////////// 474 | // Main 475 | // 476 | //////////////////////////////////////////////////////////////////////////////// 477 | int main(int argc, char** argv) { 478 | const GLuint CONTEXT_MAJOR = 4; 479 | const GLuint CONTEXT_MINOR = 1; 480 | 481 | // init glut 482 | glutInit(&argc, argv); 483 | glutInitContextVersion(CONTEXT_MAJOR ,CONTEXT_MINOR); 484 | #ifdef _ANT_ENABLE 485 | glutInitContextFlags(GLUT_DEBUG); 486 | glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); 487 | #else 488 | glutInitContextFlags(GLUT_DEBUG | GLUT_FORWARD_COMPATIBLE); 489 | glutInitContextProfile(GLUT_CORE_PROFILE); 490 | #endif 491 | 492 | // build window 493 | glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); 494 | glutInitWindowSize(800, 600); 495 | glutInitWindowPosition(0, 0); 496 | glutCreateWindow("marching cube"); 497 | 498 | // init glew 499 | glewExperimental = GL_TRUE; // segfault on GenVertexArrays on Nvidia otherwise 500 | GLenum err = glewInit(); 501 | if(GLEW_OK != err) 502 | { 503 | std::stringstream ss; 504 | ss << err; 505 | std::cerr << "glewInit() gave error " << ss.str() << std::endl; 506 | return 1; 507 | } 508 | 509 | // glewInit generates an INVALID_ENUM error for some reason... 510 | glGetError(); 511 | 512 | // set callbacks 513 | glutCloseFunc(&on_clean); 514 | glutReshapeFunc(&on_resize); 515 | glutDisplayFunc(&on_update); 516 | glutKeyboardFunc(&on_key_down); 517 | glutMouseFunc(&on_mouse_button); 518 | glutPassiveMotionFunc(&on_mouse_motion); 519 | glutMotionFunc(&on_mouse_motion); 520 | glutMouseWheelFunc(&on_mouse_wheel); 521 | 522 | // run 523 | try 524 | { 525 | // run demo 526 | on_init(); 527 | glutMainLoop(); 528 | } 529 | catch(std::exception& e) 530 | { 531 | std::cerr << "Fatal exception: " << e.what() << std::endl; 532 | return 1; 533 | } 534 | 535 | return 0; 536 | } 537 | 538 | 539 | -------------------------------------------------------------------------------- /marchingCube.glsl: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | uniform mat4 uModelViewProjection; 4 | uniform int uCase; 5 | 6 | uniform isamplerBuffer sEdgeConnectList; 7 | 8 | layout(std140) uniform CaseToNumPolys { 9 | ivec4 uCaseToNumPolys[64]; 10 | }; 11 | 12 | //layout(std140) uniform EdgeConnectList { 13 | // ivec4 uEdgeConnectList[512]; 14 | //}; 15 | 16 | #ifdef _VERTEX_ 17 | 18 | //layout(location=0) in vec4 iDummy; 19 | 20 | void main() { 21 | // empty 22 | } 23 | #endif //_VERTEX_ 24 | 25 | 26 | #ifdef _GEOMETRY_ 27 | /* 28 | * 3D coordinate system 29 | * 30 | * [+z] 31 | * | 32 | * | 33 | * | 34 | * | 35 | * | 36 | * | 37 | * +----------------[+y] 38 | * / 39 | * / 40 | * / 41 | * / 42 | * [+x] 43 | * 44 | * 45 | * Voxel Vertices 46 | * 47 | * v5 //////////////// v6 48 | * //| // | 49 | * // | // | 50 | * // | // | 51 | * v1 /////////////// v2 | 52 | * || | || | 53 | || | || | 54 | * || v4------------||-- v7 55 | * || / || / 56 | * || / || / 57 | * ||/ || / 58 | * || ||/ 59 | * v0 /////////////// v3 60 | * 61 | * 62 | * Voxel Edges 63 | * 64 | * //////////5//////////+ 65 | * //| // | 66 | * 9/ | 10/ | 67 | * // 4 // | 68 | * //////////1////////// 6 69 | * || | || | 70 | || | || | 71 | * || +--------7----||--- + 72 | * 0| / 2| / 73 | * || 8 || 11 74 | * ||/ || / 75 | * || ||/ 76 | * +/////////3///////// 77 | * 78 | */ 79 | 80 | 81 | layout(points) in; 82 | layout(triangle_strip, max_vertices = 15) out; 83 | 84 | void main() { 85 | // compute the edges of the voxel 86 | float voxelHalfSize = 0.5; 87 | float xmin = -voxelHalfSize; 88 | float xmax = +voxelHalfSize; 89 | float ymin = -voxelHalfSize; 90 | float ymax = +voxelHalfSize; 91 | float zmin = -voxelHalfSize; 92 | float zmax = +voxelHalfSize; 93 | 94 | // follow tables convention (GPU Gems3) 95 | vec3 voxelVertices[8]; 96 | voxelVertices[0] = vec3(xmax, ymin, zmin); 97 | voxelVertices[1] = vec3(xmax, ymin, zmax); 98 | voxelVertices[2] = vec3(xmax, ymax, zmax); 99 | voxelVertices[3] = vec3(xmax, ymax, zmin); 100 | voxelVertices[4] = vec3(xmin, ymin, zmin); 101 | voxelVertices[5] = vec3(xmin, ymin, zmax); 102 | voxelVertices[6] = vec3(xmin, ymax, zmax); 103 | voxelVertices[7] = vec3(xmin, ymax, zmin); 104 | 105 | // emit vertices using the marching cube tables 106 | int numPolys = uCaseToNumPolys[uCase/4][uCase%4]; 107 | int i = 0; 108 | int edgeList, idx1, idx2; 109 | vec3 vertex; 110 | while(i>3 & 0x7; 116 | vertex = 0.5 * voxelVertices[idx1] 117 | + 0.5 * voxelVertices[idx2]; 118 | gl_Position = uModelViewProjection * vec4(vertex,1.0); 119 | EmitVertex(); 120 | idx1 = edgeList>>6 & 0x7; 121 | idx2 = edgeList>>9 & 0x7; 122 | vertex = 0.5 * voxelVertices[idx1] 123 | + 0.5 * voxelVertices[idx2]; 124 | gl_Position = uModelViewProjection * vec4(vertex,1.0); 125 | EmitVertex(); 126 | idx1 = edgeList>>12 & 0x7; 127 | idx2 = edgeList>>15 & 0x7; 128 | vertex = 0.5 * voxelVertices[idx1] 129 | + 0.5 * voxelVertices[idx2]; 130 | gl_Position = uModelViewProjection * vec4(vertex,1.0); 131 | EmitVertex(); 132 | EndPrimitive(); 133 | ++i; 134 | } 135 | } 136 | #endif //_GEOMETRY_ 137 | 138 | 139 | #ifdef _FRAGMENT_ 140 | layout(location=0) out vec4 oColour; 141 | 142 | void main() { 143 | oColour = vec4(1.0,0.0,0.0,0.0); 144 | } 145 | #endif //_FRAGMENT_ 146 | -------------------------------------------------------------------------------- /premake4.lua: -------------------------------------------------------------------------------- 1 | solution "OpenGL" 2 | configurations { 3 | "debug", 4 | "release" 5 | } 6 | platforms { "x64", "x32" } 7 | 8 | -- --------------------------------------------------------- 9 | -- Project 10 | project "demo" 11 | basedir "./" 12 | language "C++" 13 | location "./" 14 | kind "ConsoleApp" -- Shouldn't this be in configuration section ? 15 | files { "*.hpp", "*.cpp" } 16 | files { "core/*.cpp" } 17 | includedirs { 18 | "include", 19 | "core" 20 | } 21 | objdir "obj" 22 | 23 | -- Debug configurations 24 | configuration {"debug"} 25 | defines {"DEBUG"} 26 | flags {"Symbols", "ExtraWarnings"} 27 | 28 | -- Release configurations 29 | configuration {"release"} 30 | defines {"NDEBUG"} 31 | flags {"Optimize"} 32 | 33 | -- Linux x86 platform gmake 34 | configuration {"linux", "gmake", "x32"} 35 | linkoptions { 36 | "-Wl,-rpath,./lib/linux/lin32 -L./lib/linux/lin32 -lGLEW -lglut -lAntTweakBar" 37 | } 38 | libdirs { 39 | "lib/linux/lin32" 40 | } 41 | 42 | -- Linux x64 platform gmake 43 | configuration {"linux", "gmake", "x64"} 44 | linkoptions { 45 | "-Wl,-rpath,./lib/linux/lin64 -L./lib/linux/lin64 -lGLEW -lglut -lAntTweakBar" 46 | } 47 | libdirs { 48 | "lib/linux/lin64" 49 | } 50 | 51 | -- Visual x86 52 | configuration {"vs2010", "x32"} 53 | libdirs { 54 | "lib/windows/win32" 55 | } 56 | links { 57 | "glew32s", 58 | "freeglut", 59 | "AntTweakBar" 60 | } 61 | 62 | ---- Visual x64 63 | -- configuration {"vs2010", "x64"} 64 | -- links { 65 | -- "glew32s", 66 | -- "freeglut", 67 | -- } 68 | -- libdirs { 69 | -- "lib/windows/win64" 70 | -- } 71 | 72 | 73 | --------------------------------------------------------------------------------