OpenGL Mathematics

OpenGL Mathematics
Логотип программы OpenGL Mathematics
Тип библиотека
Автор G-Truc Creation (Christophe Riccio)
Написана на C++
Операционная система Кроссплатформенное программное обеспечение
Последняя версия 1.0.1 (26 февраля 2024)
Лицензия MIT License
Сайт glm.g-truc.net

GLM (OpenGL Mathematics — математика для OpenGL) — библиотека для OpenGL, предоставляющая программисту на C++ структуры и функции, позволяющие использовать данные для OpenGL[источник не указан 4040 дней].

Одна из особенностей GLM состоит в том, что его реализация основана на спецификации GLSL (OpenGL Shading Language)[1].

Исходный код GLM распространяется под MIT License.

Примеры кода

// Вычислить нормаль к треугольнику:
#include <glm/glm.hpp>

void computeNormal(triangle & Triangle)
{
  glm::vec3 const & a = Triangle.Position[0];
  glm::vec3 const & b = Triangle.Position[1];
  glm::vec3 const & c = Triangle.Position[2];
  Triangle.Normal = glm::normalize(glm::cross(c - a, b - a));
}
// Матричные преобразования:
#include <glm/glm.hpp> // glm::vec3, glm::vec4, glm::ivec4, glm::mat4
#include <glm/gtc/matrix_projection.hpp> // glm::perspective
#include <glm/gtc/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale
#include <glm/gtc/type_ptr.hpp> // glm::value_ptr

void transform()
{
  glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);
  glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate));
  glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f));
  glm::mat4 View = glm::rotate(ViewRotateX, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f));
  glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f));
  glm::mat4 MVP = Projection * View * Model;
  glUniformMatrix4fv(LocationMVP, 1, GL_FALSE, glm::value_ptr(MVP));
}

Примечания

  1. Архивированная копия. Дата обращения: 26 февраля 2012. Архивировано 11 января 2012 года.

Ссылки

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.