pages.doxy 23 KB

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