pages.doxy 23 KB

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