Skip to content

Instantly share code, notes, and snippets.

View phmongeau's full-sized avatar
🤖

Philippe Mongeau phmongeau

🤖
View GitHub Profile
@mmozeiko
mmozeiko / pcg32.h
Last active November 29, 2025 10:55
simple standalone C headers for PCG random number generator
#pragma once
#include <stdint.h>
// pcg32_next() implementation matches pcg_engines::oneseq_xsh_rr_64_32
// NOTE: use this only for compatibility with 32-bit architectures
// otherwise prefer using pcg64.h implementation with 128-bit state
typedef struct {
@mmozeiko
mmozeiko / x11_opengl.c
Last active December 17, 2025 12:39
setting up and using modern OpenGL 4.5 core context on X11 with EGL
// example how to set up OpenGL core context on X11 with EGL
// and use basic functionality of OpenGL 4.5 version
// to compile on Ubuntu first install following packages: build-essential libx11-dev libgl-dev libegl-dev
// then run:
// gcc x11_opengl.c -o x11_opengl -lm -lX11 -lEGL
// important extension functionality used here:
// (4.3) KHR_debug: https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_debug.txt
// (4.5) ARB_direct_state_access: https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_direct_state_access.txt

Multi-dimensional array views for systems programmers

As C programmers, most of us think of pointer arithmetic for multi-dimensional arrays in a nested way:

The address for a 1-dimensional array is base + x. The address for a 2-dimensional array is base + x + y*x_size for row-major layout and base + y + x*y_size for column-major layout. The address for a 3-dimensional array is base + x + (y + z*y_size)*x_size for row-column-major layout. And so on.

@vurtun
vurtun / _GJK.md
Last active October 13, 2025 01:37
3D Gilbert–Johnson–Keerthi (GJK) distance algorithm

Gilbert–Johnson–Keerthi (GJK) 3D distance algorithm

The Gilbert–Johnson–Keerthi (GJK) distance algorithm is a method of determining the minimum distance between two convex sets. The algorithm's stability, speed which operates in near-constant time, and small storage footprint make it popular for realtime collision detection.

Unlike many other distance algorithms, it has no requirments on geometry data to be stored in any specific format, but instead relies solely on a support function to iteratively generate closer simplices to the correct answer using the Minkowski sum (CSO) of two convex shapes.

API Design: Coroutines APIs (Janurary-2017)

I am currently dealing with a lot of libraries at work. Both third party as well as libraries written or being currently in process of being written by me. I absolutely love writing and working with libraries. Especially if they present or bring me to either a new or different approach to solve a problem. Or at least provide a different view.

Over time I noticed however that quite regulary we had to decide that we cannot use a third party library. Often it is the usual reason.

@phmongeau
phmongeau / ik_fk_snap.mel
Created April 21, 2013 04:14
IK_FK snap
float $arm1RX = `getAttr JT_L_ikArm_1.rx`;
float $arm1RY = `getAttr JT_L_ikArm_1.ry`;
float $arm1RZ = `getAttr JT_L_ikArm_1.rz`;
setAttr JT_L_fkArm_1.rx $arm1RX;
setAttr JT_L_fkArm_1.ry $arm1RY;
setAttr JT_L_fkArm_1.rz $arm1RZ;
@phmongeau
phmongeau / EX_L_footRoll
Last active December 16, 2015 11:29
foot roll maya expression
if(RG_L_footIcon_1.ballX < 0) {
JT_L_heelCtrl_1.rotateX = RG_L_footIcon_1.ballX;
JT_L_toesTipCtrl_1.rotateX = 0;
}
else if (RG_L_footIcon_1.ballX < 50) {
JT_L_heelCtrl_1.rotateX = 0;
JT_L_toesTipCtrl_1.rotateX = 0;
JT_L_ballCtrl_1.rotateX = 1 - RG_L_footIcon_1.ballX;
}
else {
@alols
alols / softwrapcmd.vim
Created December 1, 2011 21:38
SoftWrap vim command
" Turn hard wrapped text into soft wrapped.
" This command will join all lines within a range that are not separated
" by empty lines. Automatic word wrap must be off (set fo-=a).
" Useful if you need to copy and paste into a word processor.
command! -range=% SoftWrap
\ <line2>put _ |
\ <line1>,<line2>g/.\+/ .;-/^$/ join |normal $x