glm (1125872), страница 3
Текст из файла (страница 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.
Matrix types store their values in column-major order.This is useful for uploading data to matrices or copying data to buffer objects.Example:#include <glm/glm.hpp>#include <glm/gtc/type_ptr.hpp>glm::vec3 aVector(3);glm::mat4 someMatrix(1.0);glUniform3fv(uniformLoc, 1, glm::value_ptr(aVector));glUniformMatrix4fv(uniformMatrixLoc,1, GL_FALSE, glm::value_ptr(someMatrix));<glm/gtc/type_ptr.hpp>need to be included to use these features.4.15. GLM_GTC_ulpAllow the measurement of the accuracy of a function against a referenceimplementation. This extension works on floating-point data and provides results inULP.<glm/gtc/ulp.hpp>need to be included to use these features.5.
Known issues5.1. not functionThe GLSL keyword not is also a keyword in C++. To prevent name collisions, ensurecross compiler support and a high API consistency, the GLSL not function has beenimplemented with the name not_.5.2. half based types and component accessesGLM supports half float number types through the extension GLM_GTC_half_float.This extension provides the types half, hvec*, hmat*x* and hquat*.Unfortunately, C++98 specification doesn’t support anonymous unions which limitshvec* vector components access to x, y, z and w.However, Visual C++ does support anonymous unions if the language extensions areenabled (/Za to disable them).
In this case GLM will automatically enables thesupport of all component names (x,y,z,w ; r,g,b,a ; s,t,p,q).To uniformalize the component access across types, GLM provides the defineGLM_FORCE_ONLY_XYZW which will generates errors if component accesses aredone using r,g,b,a or s,t,p,q.#define GLM_FORCE_ONLY_XYZW#include <glm/glm.hpp>6. FAQ6.1 Why GLM follows GLSL specification and conventions?Following GLSL conventions is a really strict policy of GLM. It has been designedfollowing the idea that everyone does its own math library with his own conventions.The idea is that brilliant developers (the OpenGL ARB) worked together and agreedto make GLSL.














