pages.doxy 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*!
  2. \mainpage OpenGL Mathematics
  3. OpenGL Mathematics (GLM) is a C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specification.
  4. GLM provides classes and functions designed and implemented with the same naming conventions and functionalities than GLSL so that when a programmer knows GLSL, he knows GLM as well which makes it really easy to use.
  5. This project isn't limited by GLSL features. An extension system, based on the GLSL extension conventions, provides extended capabilities: matrix transformations, quaternions, half-based types, random numbers, etc...
  6. This library works perfectly with OpenGL but it also ensures interoperability with other third party libraries and SDK. It is a good candidate for software rendering (Raytracing / Rasterisation), image processing, physic simulations and any context that requires a simple and convenient mathematics library.
  7. GLM is written as a platform independent library with no dependence and officially supports the following compilers:
  8. 1. Clang 2.0 and higher
  9. 2. CUDA 3.0 and higher
  10. 3. GCC 3.4 and higher
  11. 4. LLVM 2.3 through GCC 4.2 front-end and higher
  12. 5. Visual Studio 2005 and higher
  13. \note The Doxygen-generated documentation will often state that a type or function
  14. is defined in a namespace that is a child of the \link glm glm \endlink namespace.
  15. Please ignore this; All publicly available types and functions can be accessed as a direct children
  16. of the glm namespace.
  17. The source code is licenced under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</a>.
  18. Thanks for contributing to the project by <a href="https://sourceforge.net/apps/trac/ogl-math/newticket">submitting tickets for bug reports and feature requests</a>.
  19. (SF.net account required). Any feedback is welcome at [email protected].
  20. \li \subpage pg_started
  21. \li \subpage pg_advanced
  22. \li \subpage pg_differences
  23. \li \subpage pg_deprecated
  24. \li \subpage pg_issues
  25. \li \subpage pg_faq
  26. \li \subpage pg_samples
  27. \li \subpage pg_reference
  28. **/
  29. /*!
  30. \page pg_started Getting Started
  31. \section started_compiler Compiler Setup
  32. GLM is a header only library, there is nothing to build to use it which increases its cross platform capabilities.
  33. To use GLM, a programmer only has to include <glm/glm.hpp>. This provides all the GLSL features implemented by GLM.
  34. GLM makes heavy usages of C++ templates. This design may significantly increase the compile time for files that use GLM. Precompiled headers are recommended to avoid this issue.
  35. \section started_sample Use Sample of GLM
  36. \code
  37. #include <glm/glm.hpp>
  38. int foo()
  39. {
  40. glm::vec4 Position = glm::vec4(glm::vec3(0.0), 1.0);
  41. glm::mat4 Model = glm::mat4(1.0);
  42. Model[4] = glm::vec4(1.0, 1.0, 0.0, 1.0);
  43. glm::vec4 Transformed = Model * Position;
  44. return 0;
  45. }
  46. \endcode
  47. \section started_structure Library Structure
  48. GLM is arranged in 2 distinct segments. These are the GLM features based on the GLSL specification and a set of extensions.
  49. Some extensions are stable and backward compatible (\ref gtc GTC \ref virtrev VIRTREV) but some are experimental (\ref gtx GTX)
  50. which means that they are not guarantee to be backward compatible from version to version.
  51. The \ref core "GLM" represents only what GLSL's core provides in terms of types and functions
  52. (to the best of GLM's ability to replicate them). All that is needed to use the core
  53. is to include <tt><glm/glm.hpp></tt>.
  54. \ref gtc "GTC extensions" are functions and types that add onto the core.
  55. These are considered reasonably stable, with their APIs not changing much between
  56. versions. Each core extension is included with a separated header file include. All
  57. of the core extensions are in the "glm/gtc" directory.
  58. \ref gtx "GTX extensions" are functions and types that add onto the
  59. core. Unlike GTC extensions, their APIs are not considered particularly stable, which
  60. is why they are marked "experimental". Like GTC extensions, each experimental extension is included
  61. with a separate header file.
  62. All the extensions can be included at once by default by including <tt><glm/ext.hpp></tt>
  63. but this is not recommanded as it will reduce compilation speed for many unused features.
  64. All of GLM is defined as direct children of the glm namespace, including extensions.
  65. To use a particular extension, simply include the extension header file. All
  66. extension features are added to the glm namespace automatically.
  67. \code
  68. #include <glm/glm.hpp>
  69. #include <glm/gtc/matrix_transform.hpp>
  70. int foo()
  71. {
  72. glm::vec4 Position = glm::vec4(glm::vec3(0.0f), 1.0f);
  73. glm::mat4 Model = glm::translate(
  74. glm::mat4(1.0f), glm::vec3(1.0f));
  75. glm::vec4 Transformed = Model * Position;
  76. return 0;
  77. }
  78. \endcode
  79. \section started_dependencies Dependencies
  80. When <glm/glm.hpp> is included, GLM provides all the GLSL features it implements in C++.
  81. When an extension is included, all the dependent extensions will be included as well. All the extensions depend on GLM core. (<glm/glm.hpp>)
  82. There is no dependence with external libraries or external headers like gl.h, gl3.h, glu.h or windows.h. However, if <boost/static_assert.hpp> is included, Boost static assert will be used throughout GLM code to provide compiled time errors.
  83. \section started_interop OpenGL Interoperability
  84. It is often useful to get a vector type as an array of its base type. For example, the
  85. OpenGL function <tt>glUniform3fv()</tt> takes an array instead of 3 individual values.
  86. If the vector and matrix types were simple arrays, then one could pass them to the function
  87. like so: <tt>glUniform3fv(loc, 1, glm::vec3(0))</tt>. However, this is not the case;
  88. the vector and matrix types are C++ classes, not arrays.
  89. Instead, GLM provides a mechanism to get the content of a vector or matrix as
  90. an array pointer. The \ref gtc_type_ptr extension provides this ability.
  91. \code
  92. #include <glm/glm.hpp>
  93. #include <glm/gtc/type_ptr.hpp>
  94. void BindUniforms(GLuint uniVec, GLuint uniMat)
  95. {
  96. glm::vec4 v(0.0f);
  97. glm::mat4 m(1.0f);
  98. ...
  99. glUniform3fv(uniVec, 1, glm::value_ptr(v));
  100. glUniformMatrix4fv(uniMat, 1, GL_FALSE, glm::value_ptr(m));
  101. }
  102. \endcode
  103. Notice that all matrix types are <em>column-major</em> rather than row-major. Hence the need to pass GL_FALSE to glUniformMatrix4fv.
  104. Alternatively, the first element of the type can be dereferenced.
  105. \code
  106. #include <glm/glm.hpp>
  107. void BindUniforms(GLuint uniVec, GLuint uniMat)
  108. {
  109. glm::vec4 v(0.0f);
  110. glm::mat4 m(1.0f);
  111. ...
  112. glUniform3fv(uniVec, 1, glm::value_ptr(&v[0]));
  113. glUniformMatrix4fv(uniMat, 1, GL_FALSE, &m[0][0]);
  114. }
  115. \endcode
  116. This method requires dereferencing the very first basic type of the object, not merely the first element.
  117. The [] operator on the matrix type returns a column vector; one must then access the first element of that column vector to get a pointer to the basic type.
  118. \note This operation could have been built into the base vector and matrix types and performed with a cast operator.
  119. However, this has some downsides. Implicit casts can cause unexpected and unwanted behavior.
  120. \section started_cuda GLM for CUDA
  121. GLM 0.9.2 introduces CUDA compiler support allowing programmer to use GLM inside a CUDA Kernel.
  122. To make GLM compatible with CUDA, GLM_FORCE_CUDA requires to be define before any inclusion of <tt><glm/glm.hpp></tt>.
  123. \code
  124. #define GLM_FORCE_CUDA
  125. #include <glm/glm.hpp>
  126. \endcode
  127. **/
  128. /*!
  129. \page pg_advanced Advanced Usage
  130. \section advanced_swizzle Swizzle Operators
  131. A common feature of shader languages like GLSL is components swizzling.
  132. This involves being able to select which components of a vector are used and in what order.
  133. For example, "variable.x", "variable.xxy", "variable.zxyy" are examples of swizzling.
  134. \code
  135. vec4 A;
  136. vec2 B;
  137. ...
  138. B.yx = A.wy;
  139. B = A.xx;
  140. \endcode
  141. This functionally turns out to be really complicated to implement in C++ using the exact GLSL conventions.
  142. GLM provides 2 implementions this feature.
  143. \subsection advanced_swizzle_macro Macro implementation
  144. The first implementation follows the GLSL convensions accurately.
  145. It uses macros to achieve this, which might generates name conflicts with system headers or third party libraries.
  146. Therefore, it is disabled by default. To enable this implementation, GLM_SWIZZLE must be defined before any inclusion of <glm/glm.hpp>.
  147. \code
  148. #define GLM_SWIZZLE
  149. #include <glm/glm.hpp>
  150. \endcode
  151. This implementation can be partially enabled by defining GLM_SWIZZLE_XYZW, GLM_SWIZZLE_RGBA or GLM_SWIZZLE_STQP.
  152. Each macro only enable a set of swizzling operators. For example we can only enable x,y,z,w and s,t,q,p operators using:
  153. \code
  154. #define GLM_SWIZZLE_XYZW
  155. #define GLM_SWIZZLE_STQP
  156. #include <glm/glm.hpp>
  157. \endcode
  158. \subsection advanced_swizzle_ext Extension implementation
  159. A safer way to do swizzling is to use the <glm/gtc/swizzle.hpp> extension.
  160. This extension provides the GLSL functionality, but uses a different syntax for it.
  161. Moreover, the swizzle extension also provides dynamic swizzling.
  162. Static swizzling is resovled at compile-time.
  163. The swizzle mask ".xzyy" is as fixed as the type of a particular variable.
  164. Dynamic swizzling is resolved at runtime via function calls.
  165. Dynamic swizzling is more flexible, since one can choose the swizzle mask at runtime, but it runs slower.
  166. This performance issue is enhanced when \ref advanced_simd "SIMD instructions" are used.
  167. \code
  168. #include <glm/glm.hpp>
  169. #include <glm/gtc/swizzle.hpp>
  170. void foo()
  171. {
  172. glm::vec4 ColorRGBA(1.0f, 0.5f, 0.0f, 1.0f);
  173. ...
  174. // Dynamic swizzling (at run time, more flexible)
  175. // l-value:
  176. glm::vec4 ColorBGRA1 =
  177. glm::swizzle(ColorRGBA, glm::B, glm::G, glm::R, glm::A);
  178. // r-value:
  179. glm::swizzle(ColorRGBA, glm::B, glm::G, glm::R, glm::A) = ColorRGBA;
  180. // Static swizzling (at build time, faster)
  181. // l-value:
  182. glm::vec4 ColorBGRA2 =
  183. glm::swizzle<glm::B, glm::G, glm::R, glm::A>(ColorRGBA);
  184. // r-value:
  185. glm::swizzle<glm::B, glm::G, glm::R, glm::A>(ColorRGBA) = ColorRGBA;
  186. }
  187. \endcode
  188. \section advanced_notify Notification System
  189. GLM includes a notification system which can display some information at build time:
  190. \li Compiler
  191. \li Build model: 32bits or 64 bits
  192. \li C++ version
  193. \li Architecture: x86, SSE, AVX, etc.
  194. \li Included extensions
  195. \li etc.
  196. This system is disable by default. To enable this system, define GLM_MESSAGES before any inclusion of <glm/glm.hpp>.
  197. \code
  198. #define GLM_MESSAGES
  199. #include <glm/glm.hpp>
  200. \endcode
  201. \section advanced_inline Force Inline
  202. GLM's functions are defined in headers, so they are defined with C++'s "inline" declaration.
  203. This does not require the compiler to inline them, however.
  204. To force the compiler to inline the function, using whatever capabilities that the compiler provides to do so,
  205. GLM_FORCE_INLINE can be defined before any inclusion of <glm/glm.hpp>.
  206. \code
  207. #define GLM_FORCE_INLINE
  208. #include <glm/glm.hpp>
  209. \endcode
  210. \section advanced_simd SIMD support
  211. GLM provides some SIMD optimizations based on compiler intrinsics.
  212. These optimizations will be automatically utilized based on the build environment.
  213. These optimizations are mainly available through the extensions \ref gtx_simd_vec4 and \ref gtx_simd_mat4.
  214. A programmer can restrict or force instruction sets used for these optimizations using GLM_FORCE_SSE2 or GLM_FORCE_AVX.
  215. A programmer can discard the use of intrinsics by defining GLM_FORCE_PURE before any inclusion of <glm/glm.hpp>.
  216. If GLM_FORCE_PURE is defined, then including a SIMD extension will generate a build error.
  217. \code
  218. #define GLM_FORCE_PURE
  219. #include <glm/glm.hpp>
  220. \endcode
  221. \section advanced_compatibility Compatibility
  222. Compilers have some language extensions that GLM will automatically take advantage of them when they are enabled.
  223. GLM_FORCE_CXX98 can switch off these extensions, forcing GLM to operate on pure C++98.
  224. \code
  225. #define GLM_FORCE_CXX98
  226. #include <glm/glm.hpp>
  227. \endcode
  228. **/
  229. /*!
  230. \page pg_deprecated Deprecated function replacements
  231. The OpenGL 3.0 specification deprecated some features, and most of these have been removed from the OpenGL 3.1 specfication and beyond.
  232. GLM provides some replacement functions. Many of these functions come from the \ref gtc_matrix_transform extension.
  233. \section deprecated_opengl OpenGL function replacements
  234. <dl>
  235. <dt>glRotate[fd]</dt>
  236. <dd>\ref rotate()</dd>
  237. <dt>glScale[fd]</dt>
  238. <dd>\ref scale()</dd>
  239. <dt>glTranslate[fd]</dt>
  240. <dd>\ref translate()</dd>
  241. <dt>glLoadIdentity</dt>
  242. <dd>The default constructor of all matrix types creates an identity matrix.</dd>
  243. <dt>glMultMatrix[fd]</dt>
  244. <dd>Per the GLSL specification, the multiplication operator is overloaded for all matrix types. Multiplying two matrices together will perform matrix multiplication.</dd>
  245. <dt>glLoadTransposeMatrix[fd]</dt>
  246. <dd>\ref transpose()</dd>
  247. <dt>glMultTransposeMatrix</dt>
  248. <dd>Combine the last two.</dd>
  249. <dt>glFrustum</dt>
  250. <dd>\ref frustum()</dd>
  251. <dt>glOrtho</dt>
  252. <dd>\ref ortho()</dd>
  253. <dt>gluLookAt</dt>
  254. <dd>\ref lookAt()</dd>
  255. </dl>
  256. \section deprecated_glu GLU function replacements
  257. <dl>
  258. <dt>gluOrtho2D</dt>
  259. <dd>\ref ortho()</dd>
  260. <dt>gluPerspective</dt>
  261. <dd>\ref perspective()</dd>
  262. <dt>gluProject</dt>
  263. <dd>\ref project()</dd>
  264. <dt>gluUnProject</dt>
  265. <dd>\ref unProject()</dd>
  266. </dl>
  267. **/
  268. /*!
  269. \page pg_differences Differences between GLSL and GLM core
  270. GLM comes very close to replicating GLSL, but it is not exact. Here is a list of
  271. differences between GLM and GLSL:
  272. <ul>
  273. <li>
  274. Precision qualifiers. In GLSL numeric types can have qualifiers that define
  275. the precision of that type. While OpenGL's GLSL ignores these qualifiers, OpenGL
  276. ES's version of GLSL uses them.
  277. C++ has no language equivalent to precision qualifiers. Instead, GLM provides
  278. a set of typedefs for each kind of precision qualifier and type. These types can
  279. be found in \ref core_precision "their own section".
  280. Functions that take types tend to be templated on those types, so they can
  281. take these qualified types just as well as the regular ones.
  282. </li>
  283. </ul>
  284. **/
  285. /*!
  286. \page pg_faq FAQ
  287. \section faq1 Why does GLM follow GLSL specification and conventions?
  288. Following GLSL conventions is a really strict policy of GLM. GLM has been designed according to
  289. the idea that everyone writes their own math library with their own conventions. The idea is that
  290. brilliant developers (the OpenGL ARB) worked together and agreed to make GLSL. Following
  291. GLSL conventions is a way to find consensus. Moreover, basically when a developer knows
  292. GLSL, he knows GLM.
  293. \section faq2 Does GLM run GLSL programs?
  294. No, GLM is a C++ implementation of a subset of GLSL.
  295. \section faq3 Does a GLSL compiler build GLM codes?
  296. No, this is not what GLM intends to do!
  297. \section faq4 Should I use GTX extensions?
  298. \ref gtx are experimental. In GLM this means that these extensions might change from version to version without restriction. In practice, it doesn't really change except time to time. GTC extensions are stabled, tested and perfectly reliable in time. Many GTX extensions extend GTC extensions and provide a way to explore features and implementations before becoming stable by a promotion as GTC extensions. This is similar to how OpenGL extensions can be EXT or ARB extensions before becoming core functionality.
  299. In short, if you use a GTX extension, the API is much more likely to change from version to version than if you don't. But you should not feel too uncomfortable about using them.
  300. \section faq5 Where can I ask my questions?
  301. A good place is the OpenGL Toolkits forum on OpenGL.org:
  302. http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&Board=10&page=1
  303. \section faq6 Where can I find the documentation of extensions?
  304. The Doxygen generated documentation includes a complete list of all extensions available.
  305. Explore this documentation to get a complete view of all GLM capabilities!
  306. http://glm.g-truc.net/html/index.html
  307. \section faq7 Should I use 'using namespace glm;'?
  308. This is unwise. Chances are that if 'using namespace glm;' is called, name collisions will happen.
  309. GLSL names for functions are fairly generic, so it is entirely likely that there is another function called, for example, \link glm::sqrt() sqrt \endlink.
  310. For frequent use of particular types, they can be brough into the global
  311. namespace with a 'using' declaration like this:
  312. /code
  313. using glm::mat4;
  314. mat4 someVariable(3.0f);
  315. /endcode
  316. \section faq8 Is GLM fast?
  317. GLM is mainly designed to be convenient; that's why it is written against GLSL specification.
  318. The <a href="http://en.wikipedia.org/wiki/Pareto_principle">80-20 rule</a> suggests that 80% of a program's performance comes from 20% of its code.
  319. Therefore, one should first identify which 20% of the code is impacting the performance.
  320. In general, if one identifies certain math code to be a performance bottleneck, the only way to solve this is to write specialized code for those particular math needs.
  321. So no canned library solution would be suitable.
  322. That being said, GLM can provides some descent performances alternatives based on approximations or SIMD instructions.
  323. **/
  324. /*!
  325. \page pg_samples Code Samples
  326. This series of samples only shows various GLM functionality.
  327. \section sample1 Compute a Triangle's Normal
  328. \code
  329. #include <glm/glm.hpp> // vec3 normalize cross
  330. glm::vec3 computeNormal(
  331. glm::vec3 const & a,
  332. glm::vec3 const & b,
  333. glm::vec3 const & c)
  334. {
  335. return glm::normalize(glm::cross(c - a, b - a));
  336. }
  337. \endcode
  338. A potentially faster, but less accurate alternative:
  339. \code
  340. #include <glm/glm.hpp> // vec3 cross
  341. #include <glm/gtx/fast_square_root.hpp> // fastNormalize
  342. glm::vec3 computeNormal(
  343. glm::vec3 const & a,
  344. glm::vec3 const & b,
  345. glm::vec3 const & c)
  346. {
  347. return glm::fastNormalize(glm::cross(c - a, b - a));
  348. }
  349. \endcode
  350. \section sample2 Matrix Transform
  351. \code
  352. #include <glm/glm.hpp> //vec3, vec4, ivec4, mat4
  353. #include <glm/gtc/matrix_transform.hpp> //translate, rotate, scale, perspective
  354. #include <glm/gtc/type_ptr.hpp> //value_ptr
  355. void setUniformMVP(
  356. GLuint Location,
  357. glm::vec3 const & Translate,
  358. glm::vec3 const & Rotate)
  359. {
  360. glm::mat4 Projection =
  361. glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);
  362. glm::mat4 ViewTranslate = glm::translate(
  363. glm::mat4(1.0f),
  364. Translate);
  365. glm::mat4 ViewRotateX = glm::rotate(
  366. ViewTranslate,
  367. Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f));
  368. glm::mat4 View = glm::rotate(
  369. ViewRotateX,
  370. Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f));
  371. glm::mat4 Model = glm::scale(
  372. glm::mat4(1.0f),
  373. glm::vec3(0.5f));
  374. glm::mat4 MVP = Projection * View * Model;
  375. glUniformMatrix4fv(
  376. Location, 1, GL_FALSE, glm::value_ptr(MVP));
  377. }
  378. \endcode
  379. \section sample3 Vector Types
  380. \code
  381. #include <glm/glm.hpp> //vec2
  382. #include <glm/gtc/type_precision.hpp> //hvec2, i8vec2, i32vec2
  383. std::size_t const VertexCount = 4;
  384. // Float quad geometry
  385. std::size_t const PositionSizeF32 = VertexCount * sizeof(glm::vec2);
  386. glm::vec2 const PositionDataF32[VertexCount] =
  387. {
  388. glm::vec2(-1.0f,-1.0f),
  389. glm::vec2( 1.0f,-1.0f),
  390. glm::vec2( 1.0f, 1.0f),
  391. glm::vec2(-1.0f, 1.0f)
  392. };
  393. // Half-float quad geometry
  394. std::size_t const PositionSizeF16 = VertexCount * sizeof(glm::hvec2);
  395. glm::hvec2 const PositionDataF16[VertexCount] =
  396. {
  397. glm::hvec2(-1.0f, -1.0f),
  398. glm::hvec2( 1.0f, -1.0f),
  399. glm::hvec2( 1.0f, 1.0f),
  400. glm::hvec2(-1.0f, 1.0f)
  401. };
  402. // 8 bits signed integer quad geometry
  403. std::size_t const PositionSizeI8 = VertexCount * sizeof(glm::i8vec2);
  404. glm::i8vec2 const PositionDataI8[VertexCount] =
  405. {
  406. glm::i8vec2(-1,-1),
  407. glm::i8vec2( 1,-1),
  408. glm::i8vec2( 1, 1),
  409. glm::i8vec2(-1, 1)
  410. };
  411. // 32 bits signed integer quad geometry
  412. std::size_t const PositionSizeI32 = VertexCount * sizeof(glm::i32vec2);
  413. glm::i32vec2 const PositionDataI32[VertexCount] =
  414. {
  415. glm::i32vec2 (-1,-1),
  416. glm::i32vec2 ( 1,-1),
  417. glm::i32vec2 ( 1, 1),
  418. glm::i32vec2 (-1, 1)
  419. };
  420. \endcode
  421. \section sample4 Lighting
  422. \code
  423. #include <glm/glm.hpp> // vec3 normalize reflect dot pow
  424. #include <glm/gtx/random.hpp> // vecRand3
  425. // vecRand3, generate a random and equiprobable normalized vec3
  426. glm::vec3 lighting(
  427. intersection const & Intersection,
  428. material const & Material,
  429. light const & Light,
  430. glm::vec3 const & View)
  431. {
  432. glm::vec3 Color = glm::vec3(0.0f);
  433. glm::vec3 LightVertor = glm::normalize(
  434. Light.position() - Intersection.globalPosition() +
  435. glm::vecRand3(0.0f, Light.inaccuracy());
  436. if(!shadow(
  437. Intersection.globalPosition(),
  438. Light.position(),
  439. LightVertor))
  440. {
  441. float Diffuse = glm::dot(Intersection.normal(), LightVector);
  442. if(Diffuse <= 0.0f)
  443. return Color;
  444. if(Material.isDiffuse())
  445. Color += Light.color() * Material.diffuse() * Diffuse;
  446. if(Material.isSpecular())
  447. {
  448. glm::vec3 Reflect = glm::reflect(
  449. -LightVector,
  450. Intersection.normal());
  451. float Dot = glm::dot(Reflect, View);
  452. float Base = Dot > 0.0f ? Dot : 0.0f;
  453. float Specular = glm::pow(Base, Material.exponent());
  454. Color += Material.specular() * Specular;
  455. }
  456. return Color;
  457. }
  458. \endcode
  459. **/
  460. /*!
  461. \page pg_issues Known Issues
  462. \section issue1 not Function
  463. The GLSL keyword not is also a keyword in C++. To prevent name collisions, the GLSL not
  464. function has been implemented with the name not_.
  465. \section issue2 Half Based Types
  466. GLM supports half float number types through the extension GLM_GTC_half_float. This extension provides the types half, hvec*, hmat*x* and hquat*.
  467. Unfortunately, C++ 98 specification doesn’t support anonymous unions which limit hvec* vector components access to x, y, z and w.
  468. However, Visual C++ does support anonymous unions if the language extensions are enabled (/Za to disable them). In this case GLM will automatically enables the support of all component names (x,y,z,w ; r,g,b,a ; s,t,p,q).
  469. To uniformalize the component access across types, GLM provides the define GLM_FORCE_ONLY_XYZW which will generates errors if component accesses are done using r,g,b,a or s,t,p,q.
  470. \code
  471. #define GLM_FORCE_ONLY_XYZW
  472. #include <glm/glm.hpp>
  473. \endcode
  474. **/
  475. /*!
  476. \page pg_reference References
  477. OpenGL 4.1 core specification:
  478. http://www.opengl.org/registry/doc/glspec41.core.20100725.pdf
  479. GLSL 4.10 specification:
  480. http://www.opengl.org/registry/doc/GLSLangSpec.4.10.6.clean.pdf
  481. GLU 1.3 specification:
  482. http://www.opengl.org/documentation/specs/glu/glu1_3.pdf
  483. GLM HEAD snapshot:
  484. http://ogl-math.git.sourceforge.net/git/gitweb.cgi?p=ogl-math/ogl-math;a=snapshot;h=HEAD;sf=tgz
  485. GLM bug tracker:
  486. https://sourceforge.net/apps/trac/ogl-math
  487. GLM website:
  488. http://glm.g-truc.net
  489. GLM OpenGL SDK page:
  490. http://www.opengl.org/sdk/libs/GLM/
  491. G-Truc Creation page:
  492. http://www.g-truc.net/project-0016.html
  493. The OpenGL Toolkits forum to ask questions about GLM:
  494. http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&Board=10&page=1
  495. **/