OpenGL Mathematics (GMath) is a header only C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications.
GMath provides classes and functions designed and implemented with the same naming conventions and functionality than GLSL so that anyone who knows GLSL, can use GMath as well in C++.
The point of GMath's work is making it's basic data type(vector, matrix and quaternion) more purely for storage.
Several characteristics of GMath must be known before startingļ¼
-
Default right-hand coordinate system.
-
Matrix uses column priority to store data.
-
In order to keep GMath lightweight, it only keeps the common functions in GLSL.
-
Use template class, you can set the precision of data you want.
Todo list:
- Support the left-hand coordinate system.
- Optimize code structure.
- Test code cover 100%.
- ...
-
Copy all the files in the src folder into your project.
-
By inlcude GMath.hpp files, you can use all the functions of GMath
-
Here is the sample code
#include "GMath.hpp" void main(){ gm::Vec3 axisX(2, 0, 0); gm::Vec3 axisY(0, 1, 2); gm::Vec3 axisZ(1, 0, 0.5); gm::Mat3 unitM3; gm::Mat3 coordinateM3( axisX * 0.5, 3.0f * axisY, -axisZ ); unitM3 *= 2; std::cout << "Vector3:\n" << axisY << "Matrix3X3:\n" << unitM3 * coordinateM3 << std::endl; }
Like GLSL:
-
Vec3.x, Vec3.r, Vec3.s
is the same data in memory. -
number * vector = vector * number = number multiplied by every element(x, y, z) in the vector.
-
number * matrix = matrix * number = number multiplied by every element in the matrix.
-
vector * vector = The product of each corresponding element of them.
Using function
gm::dot
orgm::cross
compute by geometric method.
To know how to use GMath in the project. Look at SFLCameraVirtual.h and SFLModelNoLight.h
The source code is licensed under GPL v3, License is available here.