📽 Highly Optimized 2D / 3D Graphics Math (glm) for C
MIT License
Bot releases are visible (Hide)
Non-Square matrices are fixed ( many thanks to @EasyIP2023 ). Also now SSE can work without SSE2 which may not available on 32bit devices e.g. i686. Some fast math issues also fixed. Func param name conflicts with a macro, again! Now fixed.
In this release lot of critic bugs are fixed. Feel free to report any bugs, we are here for them 🐛
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
https://github.com/sponsors/recp
https://opencollective.com/cglm#backer
https://patreon.com/recp
Published by recp 7 months ago
Now we have some missing functionalities:
📌 ray sphere intersection, reflect, refract, face forward
📌 additional CI via GitHub Actions ( many thanks to @waywardmonkeys )
📌 struct API for ivec2, ivec3, and ivec4 ( many thanks to @tarhses )
📌 struct API improvements ( many thanks to @duarm, @waywardmonkeys )
📌 add new functions for ivec2 and ivec3 ( many thanks to @vitassuper )
glm_ray_sphere(origin, dir, s, &t1, &t2)) -> bool
ray sphere intersectionglm_ray_at(orig, dir, t, &point)
point by parameterglm_vec3_faceforward(N, I, Nref, dest)
glm_vec[2|3|4]_reflect(I, N, &dest)
reflectglm_vec[2|3|4]_refract(I, N, eta, &dest)
refractglm_ray_sphere()
:
and many others improvements and bug fixes, thanks to those who help to make the library more robust and better than before.
glm_ray_sphere
, glm_ray_at
, glm_vec3_faceforward
, glm_vec[2|3|4]_reflect
, glm_vec[2|3|4]_refract
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
https://github.com/sponsors/recp
https://opencollective.com/cglm#backer
https://patreon.com/recp
Published by recp 10 months ago
Now we have some missing functionalities:
📌 aabb2d ( many thanks to @duarm )
📌 euler to quat functionality ( many thanks to @telephone001 )
📌 new subtraction family of vector functions ( many thanks to @BeeverFeever )
and many others improvements and bugfixes, thanks to @v1993, @myfreeer, @gottfriedleibniz and others to make the library more robust and better than before.
glms_mat4_ins3()
( thanks to @telephone001 )glm_vec2_center()
( thanks @duarm )alignof
( thanks to @v1993 )glmm_fmsub()
on arm-neon ( thanks to @gottfriedleibniz )Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
https://github.com/sponsors/recp
https://opencollective.com/cglm#backer
https://patreon.com/recp
Published by recp about 1 year ago
📌 Now we have mat2x3, mat2x4, mat3x2, mat3x4, mat4x2 and mat4x3 types and its functions ( many thanks to @EasyIP2023 )
Each one has its own header e.g mat3x4.h, including one of them:
will include all matrix headers. Feel free to share any bugs found to fix them.
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
https://github.com/sponsors/recp
https://opencollective.com/cglm#backer
https://patreon.com/recp
Published by recp over 1 year ago
Now we have WASM 128 SIMD support ( many thanks to @myfreeer ).
Currently the tests can be cross-compiled to wasi using clang and wasi-sdk with cmake arguments below:
-DCMAKE_C_FLAGS="-msimd128"
-DCMAKE_TOOLCHAIN_FILE=/path/to/wasi-sdk-19.0/share/cmake/wasi-sdk.cmake
-DWASI_SDK_PREFIX=/path/to/wasi-sdk-19.0
-DCGLM_USE_TEST=ON
Where /path/to/wasi-sdk-19.0/
is the path to extracted wasi sdk.
Now we can omit or change namespace of struct api which was ( and still as default ) glms_
. We can omit the namespace completely to use like mat4_mul(mat4_mul(m1, m2), m3)
... or option to use like mat4s_mul(mat4s_mul(m1, m2), m3)
...
This makes things more flexible & readable for struct api.
now we can omit glms_ like:
/* previous / default */
return glms_vec3_normalized(glms_vec3_cross(a, b));
/* this must be defined before cglm inc especially common.h */
#define CGLM_OMIT_NS_FROM_STRUCT_API /* or define at compiler settings */
/* new!! */
return vec3_normalized(vec3_cross(a, b));
/* if CGLM_STRUCT_API_NAME_SUFFIX is defined as `s` */
return vec3s_normalized(vec3s_cross(a, b));
new options:
CGLM_OMIT_NS_FROM_STRUCT_API
, omits CGLM_STRUCT_API_NS (glms_) namespace completely if there is sub namespace e.g mat4_, vec4_ ... DEFAULT is not definedCGLM_STRUCT_API_NS
: define name space for struct api, DEFAULT is glms
CGLM_STRUCT_API_NAME_SUFFIX
: define name suffix, DEFAULT is empty e.g defining it as #define CGLM_STRUCT_API_NAME_SUFFIX s
will add s
suffix to mat4_mul -> mat4s_mul
/fp:fast
on msvc ( thanks to @gottfriedleibniz, @deadwanderer ) see https://github.com/recp/cglm/issues/289
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
https://github.com/sponsors/recp
https://opencollective.com/cglm#backer
https://patreon.com/recp
Published by recp over 1 year ago
Bugfixes and Improvements:
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
https://github.com/sponsors/recp
https://opencollective.com/cglm#backer
https://patreon.com/recp
Published by recp almost 2 years ago
New features:
Bugfixes and Improvements:
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
https://github.com/sponsors/recp
https://opencollective.com/cglm#backer
https://patreon.com/recp
Published by recp almost 2 years ago
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
https://github.com/sponsors/recp
https://opencollective.com/cglm#backer
https://patreon.com/recp
Published by recp almost 2 years ago
Now we have post transform functions which is similar to existing transform function but with different multiplication order.
new affine functions:
CGLM_INLINE void glm_spin(mat4 m, float angle, vec3 axis)
: rotates existing transform around itself by with axis. this helps to rotate object around itself without moving manually or providing a pivot for glm_rotate_at()
to rotate around itselfCurrent implementations apply transforms to vector first, but sometimes we may need to apply rotations as last transform, cglm introduces post-transform operations e.g. apply rotation/translate last instead of first to vector.
Post transform function have similar names with existing ones with ed
suffix:
CGLM_INLINE void glm_translated_to(mat4 m, vec3 v, mat4 dest)
CGLM_INLINE void glm_translated(mat4 m, vec3 v)
CGLM_INLINE void glm_translated_x(mat4 m, float to)
CGLM_INLINE void glm_translated_y(mat4 m, float to)
CGLM_INLINE void glm_translated_z(mat4 m, float to)
CGLM_INLINE void glm_rotated_x(mat4 m, float angle, mat4 dest)
CGLM_INLINE void glm_rotated_y(mat4 m, float angle, mat4 dest)
CGLM_INLINE void glm_rotated_z(mat4 m, float angle, mat4 dest)
CGLM_INLINE void glm_rotated(mat4 m, float angle, vec3 axis)
CGLM_INLINE void glm_rotated_at(mat4 m, vec3 pivot, float angle, vec3 axis)
CGLM_INLINE void glm_spinned(mat4 m, float angle, vec3 axis)
new project functions:
CGLM_INLINE float glm_project_z(vec3 pos, mat4 m)
- map object's z coordinate to window coordinatesCGLM_INLINE float glm_project_z_no(vec3 pos, mat4 m)
CGLM_INLINE float glm_project_z_zo(vec3 pos, mat4 m)
new ivec functions ( thanks to @Chris-F5 ):
void glm_ivec2(int * __restrict v, ivec2 dest);
void glm_ivec2_copy(ivec2 a, ivec2 dest);
void glm_ivec2_zero(ivec2 v);
void glm_ivec2_one(ivec2 v);
void glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest);
void glm_ivec2_adds(ivec2 v, int s, ivec2 dest);
void glm_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest);
void glm_ivec2_subs(ivec2 v, int s, ivec2 dest);
void glm_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest);
void glm_ivec2_scale(ivec2 v, int s, ivec2 dest);
int glm_ivec2_distance2(ivec2 a, ivec2 b);
float glm_ivec2_distance(ivec2 a, ivec2 b);
void glm_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest);
void glm_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest);
void glm_ivec2_clamp(ivec2 v, int minVal, int maxVal);
void glm_ivec3(ivec4 v4, ivec3 dest);
void glm_ivec3_copy(ivec3 a, ivec3 dest);
void glm_ivec3_zero(ivec3 v);
void glm_ivec3_one(ivec3 v);
void glm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest);
void glm_ivec3_adds(ivec3 v, int s, ivec3 dest);
void glm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest);
void glm_ivec3_subs(ivec3 v, int s, ivec3 dest);
void glm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest);
void glm_ivec3_scale(ivec3 v, int s, ivec3 dest);
int glm_ivec3_distance2(ivec3 a, ivec3 b);
float glm_ivec3_distance(ivec3 a, ivec3 b);
void glm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest);
void glm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest);
void glm_ivec3_clamp(ivec3 v, int minVal, int maxVal);
void glm_ivec4(ivec3 v3, int last, ivec4 dest);
void glm_ivec4_copy(ivec4 a, ivec4 dest);
void glm_ivec4_zero(ivec4 v);
void glm_ivec4_one(ivec4 v);
void glm_ivec4_add(ivec4 a, ivec4 b, ivec4 dest);
void glm_ivec4_adds(ivec4 v, int s, ivec4 dest);
void glm_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest);
void glm_ivec4_subs(ivec4 v, int s, ivec4 dest);
void glm_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest);
void glm_ivec4_scale(ivec4 v, int s, ivec4 dest);
int glm_ivec4_distance2(ivec4 a, ivec4 b);
float glm_ivec4_distance(ivec4 a, ivec4 b);
void glm_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest);
void glm_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest);
void glm_ivec4_clamp(ivec4 v, int minVal, int maxVal);
Bugfixes and Improvements:
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
https://github.com/sponsors/recp
https://opencollective.com/cglm#backer
https://patreon.com/recp
Published by recp over 2 years ago
Bugfixes and Improvements:
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
Published by recp about 3 years ago
Now there are _no
and _zo
vesions of project / unproject functions. They are placed in include/cglm/clipspace/
and include/cglm/call/clipspace/
folders.
if CGLM_CLIPSPACE_INCLUDE_ALL
is defined then all clipspace headers are icluded in project.h or related main headers, otherwise only related clipspace headers will be included to avoid including unused headers...
glm_pickmatrix()
aka gluPickMatrix()
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
Published by recp over 3 years ago
cglm now supports different clipspace configurations.
Many many thanks to @raedwulf and @michael-g to provide this feature to cglm which was in TODOs long time. There are missing tests for now but tests will or should be added as soon as possible. Also thanks to @hartenfels and @bwhmather fixing build files...
Options
#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
#define CGLM_FORCE_LEFT_HANDED
#define CGLM_CLIPSPACE_INCLUDE_ALL
/* auto created in cglm */
#define CGLM_CONFIG_CLIP_CONTROL
#define CGLM_CLIP_CONTROL_LH_ZO
#define CGLM_CLIP_CONTROL_LH_NO
#define CGLM_CLIP_CONTROL_RH_ZO
#define CGLM_CLIP_CONTROL_RH_NO
New functions
Now there are _no
, _zo
, _lh
, _rh
... vesions of projection and view functions. No need to paste all of them here, they are placed in include/cglm/clipspace/
, include/cglm/struct/clipspace/
and include/cglm/call/clipspace/
folders.
if CGLM_CLIPSPACE_INCLUDE_ALL
is defined then all clipspace headers are icluded in cam.h or related main headers, otherwise only related clipspace headers will be included to avoid including unused headers...
Supporting cross platform, multiple OS-es and multiple CPUs requires multiple hardwares to test on it which requires extra financial cost. Also sparing time is another big issue while working at somewhere fulltime... Your company can become a sponsor to help:
Published by recp over 3 years ago
New Features and Improvements
New glmm functions:
glmm_set1(x)
glmm_splat_x(x)
glmm_splat_y(x)
glmm_splat_z(x)
glmm_splat_w(x)
glmm_xor(a, b)
for neonglmm_vhadd(a)
for neonPublished by recp over 3 years ago
New Features:
Implement FMA
SIMD operations are optimized with FMA instructions to reduce operations and increasee accuracy. The gennerated CPU instructions are reduced. All matrix and related-vector operations are optimized.
FMA must be enable for these optimizations (with -mfma flag on GCC and Clang, /arch:AVX2 /O1-2 on MSVC)
New glmm functions (SSE + NEON):
glmm_vhadd()
- broadcast-ed haddglmm_fmadd(a, b, c)
- fused multiply addglmm_fnmadd(a, b, c)
- fused negative multiply addglmm_fmsub(a, b, c)
- fused multiply subglmm_fnmsub(a, b, c)
- fused negative multiply subNew glmm functions (AVX):
glmm256_fmadd(a, b, c)
- fused multiply add AVXglmm256_fnmadd(a, b, c)
- fused negative multiply add AVXglmm256_fmsub(a, b, c)
- fused multiply sub AVXglmm256_fnmsub(a, b, c)
- fused negative multiply sub AVXglm_mat4_scale_avx(mat4 m, float s)
- scale matrix with scalar (if AVX enabled)CMake
This requires no building or installation of cglm.
cmake_minimum_required(VERSION 3.8.2)
project(<Your Project Name>)
add_executable(${PROJECT_NAME} src/main.c)
target_link_libraries(${LIBRARY_NAME} PRIVATE
cglm_headers)
add_subdirectory(external/cglm/ EXCLUDE_FROM_ALL)
Published by recp over 3 years ago
Bugfixes and Improvements:
glm_aabb_sphere()
) ( thanks to @ILeonor to report this ) - todo: more aabb v sphere intersect optionsPublished by recp almost 4 years ago
New Features:
This is useful for people who want to use cglm as a meson subproject
without polluting the main project's install target.
Bugfixes and Improvements:
This modifies glmm_{load,store}3 functions to make the compiler assume
the v pointer is appropriately aligned for the type it is being cast to.
Not tested with CGLM_ALL_UNALIGNED, but it probably doesn't matter.
Published by recp about 4 years ago
New Features:
Bugfixes and Improvements:
Published by recp about 4 years ago
New Features:
Now we have 2D Affine Transform functions. 2D Transform functions are suffixed with 2d, functions that don't have any suffixes are 3D. For instance glm_translate2d()
is 2D and glm_translate()
is 3D.
New Functions:
Translate2D:
glm_translate2d()
glm_translate2d_to()
glm_translate2d_x()
glm_translate2d_y()
glm_translate2d_make()
Scale2D:
glm_scale2d_to()
glm_scale2d_make()
glm_scale2d()
glm_scale2d_uni()
Rotate2D:
glm_rotate2d_make()
glm_rotate2d()
glm_rotate2d_to()
All these functions are documented at https://cglm.readthedocs.io/en/latest/affine2d.html . Rotate functions are rotating around Z axes. SIMD optimizations will be applied in the future releases.
Bugfixes and Improvements:
CGLM_DEFINE_PRINTS
macro for test targets to see printed resultsBuild:
Published by recp over 4 years ago
Bugfixes and Improvements:
vec2/vec3/vec4_eq_all
New Features:
FLT_EPSILON
with GLM_FLT_EPSILON
Published by recp over 4 years ago
Improvements: