glm (1124588), страница 3
Текст из файла (страница 3)
If GLM_FORCE_PURE is defined, then including a SIMDextension will generate a build error.#define GLM_FORCE_PURE#include <glm/glm.hpp>2.5. CompatibilityCompilers have some language extensions that GLM will automatically takeadvantage of them when they are enabled. To increase cross platform compatibilityand to avoid compiler extensions, a programmer can define GLM_FORCE_CXX98 beforeany inclusion of <glm/glm.hpp>.#define GLM_FORCE_CXX98#include <glm/glm.hpp>For C++11, an equivalent value is available: GLM_FORCE_CXX11.#define GLM_FORCE_CXX11#include <glm/glm.hpp>If both GLM_FORCE_CXX98 and GLM_FORCE_CXX11 are defined then C++ 11 features willbe utilized.2.6. Default precisionWith C++ it isn’t possible to implement GLSL default precision (GLSL 4.10specification section 4.5.3) the way it is specified in GLSL. Hence, instead of writing:precision mediump int;precision highp float;With GLM we need to add before any include of glm.hpp:#define GLM_PRECISION_MEDIUMP_INT;#define GLM_PRECISION_HIGHP_FLOAT;#include <glm/glm.hpp>2.7.
Force use of radiansOpenGL API legacy functions used to take angle values expressed in degrees, aprecedent that GLM is following. However, GLSL functions are typically radiansbased. GLM allows switching all the GLM functions to use radians by declaringGLM_FORCE_RADIANS.// Using radians#define GLM_FORCE_RADIANS#include <glm/glm.hpp>#include <glm/gtc/constants.hpp>#include <glm/gtc/matrix_transform.hpp>glm::mat4 m(1.0f);glm::mat4 r(glm::rotate(m, pi * 0.5f, glm::vec3(0, 0, 1)));// Using degrees#include <glm/glm.hpp>#include <glm/gtc/matrix_transform.hpp>glm::mat4 m(1.0f);glm::mat4 r(glm::rotate(m, 90.f, glm::vec3(0, 0, 1)));3. Deprecated function replacementsOpenGL 3.0 specification has deprecated some features that have been removedfrom OpenGL 3.2 core profile specification. GLM provides some replacementfunctions.3.1.
OpenGL functions (Section 2.11.2 Matrices, OpenGL 2.1specification)glRotate{f, d}:glm::mat4 glm::rotate(glm::mat4 const & m,float angle,glm::vec3 const & axis);glm::dmat4 glm::rotate(glm::dmat4 const & m,double angle,glm::dvec3 const & axis);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>glScale{f, d}:glm::mat4 glm::scale(glm::mat4 const & m,glm::vec3 const & factors);glm::dmat4 glm::scale(glm::dmat4 const & m,glm::dvec3 const & factors);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>glTranslate{f, d}:glm::mat4 glm::translate(glm::mat4 const & m,glm::vec3 const & translation);glm::dmat4 glm::translate(glm::dmat4 const & m,glm::dvec3 const & translation);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>glLoadIdentity:glm::mat4(1.0) or glm::mat4();glm::dmat4(1.0) or glm::dmat4();From GLM core library: <glm/glm.hpp>glMultMatrix{f, d}:glm::mat4() * glm::mat4();glm::dmat4() * glm::dmat4();From GLM core library: <glm/glm.hpp>glLoadTransposeMatrix{f, d}:glm::transpose(glm::mat4());glm::transpose(glm::dmat4());From GLM core library: <glm/glm.hpp>glMultTransposeMatrix{f, d}:glm::mat4() * glm::transpose(glm::mat4());glm::dmat4() * glm::transpose(glm::dmat4());From GLM core library: <glm/glm.hpp>glFrustum:glm::mat4 glm::frustum(float left, float right,float bottom, float top,float zNear, float zFar);glm::dmat4 glm::frustum(double left, double right,double bottom, double top,double zNear, double zFar);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>glOrtho:glm::mat4 glm::ortho(float left, float right,float bottom, float top,float zNear, float zFar);glm::dmat4 glm::ortho(double left, double right,double bottom, double top,double zNear, double zFar);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>3.2.
GLU functions (Chapter 4: Matrix Manipulation, GLU 1.3specification)gluLookAt:glm::mat4 glm::lookAt(glm::vec3 const & eye,glm::vec3 const & center,glm::vec3 const & up);glm::dmat4 glm::lookAt(glm::dvec3 const & eye,glm::dvec3 const & center,glm::dvec3 const & up);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>gluOrtho2D:glm::mat4 glm::ortho(float left, float right, float bottom, float top);glm::dmat4 glm::ortho(double left, double right, double bottom, double top);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>gluPerspective:glm::mat4 perspective(float fovy, float aspect, float zNear, float zFar);glm::dmat4 perspective(double fovy, double aspect, double zNear, double zFar);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>gluPickMatrix:glm::mat4 pickMatrix(glm::vec2 const & center,glm::vec2 const & delta,glm::ivec4 const & viewport);glm::dmat4 pickMatrix(glm::dvec2 const & center,glm::dvec2 const & delta,glm::ivec4 const & viewport);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>gluProject:glm::vec3 project(glm::vec3 const &glm::mat4 const &glm::mat4 const &glm::{i, ' '}vec4obj,model,proj,const & viewport);glm::dvec3 project(glm::dvec3 const & obj,glm::dmat4 const & model,glm::dmat4 const & proj,glm::{i, ' ', d}vec4 const & viewport);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>gluUnProject:glm::vec3 unProject(glm::vec3 const &glm::mat4 const &glm::mat4 const &glm::{i, ' '}vec4win,model,proj,const & viewport);glm::dvec3 unProject(glm::dvec3 const & win,glm::dmat4 const & model,glm::dmat4 const & proj,glm::{i, ' ', d}vec4 const & viewport);From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp>4.
Extensions4.1. GLM_GTC_constantsThis extension provides a list of built-in constants.<glm/gtc/constants.hpp> need to be included to use these features.4.2. GLM_GTC_epsilonApproximated equal and not equal comparisons with selectable epsilon.<glm/gtc/epsilon.hpp> need to be included to use these features.4.3.
GLM_GTC_half_floatThis extension provides half-precision floating-point types support for scalar (half),vectors (hvec*) and matrices (hmat*x*) for every GLM core functions that takesfloating-point parameter.Half float should be essentially used for storage as it isn’t a native format and even ifall the scalar operations are supported, there are implemented by converting half tofloat and then make this conversion back to half.<glm/gtc/half_float.hpp> need to be included to use these features.4.4. GLM_GTC_matrix_accessDefines functions to access rows or columns of a matrix easily.<glm/gtc/matrix_access.hpp>need to be included to use these features.4.5.
GLM_GTC_matrix_integerProvides integer matrix types. Inverse and determinant functions are not supportedfor these types.<glm/gtc/matrix_integer.hpp>need to be included to use these features.4.6. GLM_GTC_matrix_inverseDefines additional matrix inverting functions.<glm/gtc/matrix_inverse.hpp>need to be included to use these features.4.7. GLM_GTC_matrix_transformDefines functions that generate common transformation matrices.The matrices generated by this extension use standard OpenGL fixed-functionconventions. For example, the lookAt function generates a transform from worldspace into the specific eye space that the projective matrix functions ( perspective,ortho, etc) are designed to expect.
The OpenGL compatibility specifications definethe particular layout of this eye space.<glm/gtc/matrix_transform.hpp>need to be included to use these features.4.8. GLM_GTC_noiseDefines 2D, 3D and 4D procedural noise functions.<glm/gtc/noise.hpp>need to be included to use these features.Figure 4.8.1: glm::simplex(glm::vec2(x / 16.f, y / 16.f));Figure 4.8.2: glm::simplex(glm::vec3(x / 16.f, y / 16.f, 0.5f));Figure 4.8.3: glm::simplex(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f));Figure 4.8.4: glm::perlin(glm::vec2(x / 16.f, y / 16.f));Figure 4.8.5: glm::perlin(glm::vec3(x / 16.f, y / 16.f, 0.5f));Figure 4.8.6: glm::perlin(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f)));Figure 4.8.7: glm::perlin(glm::vec2(x / 16.f, y / 16.f), glm::vec2(2.0f));Figure 4.8.8: glm::perlin(glm::vec3(x / 16.f, y / 16.f, 0.5f),glm::vec3(2.0f));Figure 4.8.9: glm::perlin(glm::vec4(x / 16.f, y / 16.f, glm::vec2(0.5f)),glm::vec4(2.0f));4.9.
GLM_GTC_quaternionDefines a templated quaternion type and several quaternion operations.<glm/gtc/quaternion.hpp>need to be included to use these features.4.10. GLM_GTC_randomGenerate random number from various distribution methods.<glm/gtc/random.hpp>need to be included to use these features.Figure 4.10.1: glm::vec4(glm::linearRand(glm::vec2(-1), glm::vec2(1)), 0, 1);Figure 4.10.2: glm::vec4(glm::circularRand(1.0f), 0, 1);Figure 4.10.3: glm::vec4(glm::sphericalRand(1.0f), 1);Figure 4.10.4: glm::vec4(glm::diskRand(1.0f), 0, 1);Figure 4.10.5: glm::vec4(glm::ballRand(1.0f), 1);Figure 4.10.6: glm::vec4(glm::gaussRand(glm::vec3(0), glm::vec3(1)), 1);4.11.
GLM_GTC_reciprocalProvides hyperbolic functions: secant, cosecant, cotangent, etc.<glm/gtc/reciprocal.hpp>need to be included to use these functionalities.4.12. GLM_GTC_swizzleProvide functions to emulate GLSL swizzle operator features but with a differentsyntax that feats C++ boundaries.<glm/gtc/swizzle.hpp>need to be included to use these functionalities.4.13. GLM_GTC_type_precisionVector and matrix types with defined precisions. Eg, i8vec4: vector of 4 signedinteger of 8 bits.<glm/gtc/type_precision.hpp>need to be included to use these functionalities.4.14. GLM_GTC_type_ptrHandles the interaction between pointers and vector, matrix types.This extension defines an overloaded function, glm::value_ptr, which takes any ofthe core template types (vec3, mat4, etc.). It returns a pointer to the memory layoutof the object.














