Vector/matrix math and other basic utilities.
Instructions:
#include <util.h>for everything- Or,
#include <util-basics.h>for just the stuff in the "Basics" section below
- Or,
- Link with
util.lib, or just addutil.vcxprojto your solution and reference it
Basics:
dim(),dim_field()—size of static arrayssizeof_field()—size of a struct membercassert()—compile-time assert (likestatic_assertbut no separate error message)uint,byte, sized integer typesi8,u8throughi64,u64- Float constants:
pi,epsilon = 1e-6f,infinity,NaN - Generic
swap,min,max,clamp,saturate,lerp,square - Float utilities:
isnear(comparisons with epsilon),isfinite,exp2f,log2f - Integer utilities:
round,modPositive, various power-of-2-related utilities offset()—do byte arithmetic on a pointer of any typeexit("error message", ...)—printf a message to stderr, and exit with a nonzero codeLoadFile()—just slurp an entire file into memorytokenize()—in-place destructive tokenization, à lastrtokbut statelessmakeLowercase()—lowercase a string in-placeTextParsingHelper—help parse a text file into lines and tokens, and issue warnings for syntax errorsSerializeHelper,DeserializeHelper—help read/write common types from a byte stream- Logging—to a file and/or a callback
- Asserts, checks, errors, and warnings—with log messages, callbacks, and debugbreaks
Math, based on design principles from On Vector Math Libraries:
- Vectors and matrices in any number of dimensions
- Construction of common transformations
- Functionality for working with affine transformations stored as homogeneous matrices
- Boxes in any number of dimensions
- Quaternions
- Color space conversions
- SIMD math using AOSOA (not well tested)
- Half-float from OpenEXR
Random number generation, from Quick and Easy GPU Random Numbers in D3D11 (although these are on the CPU):
- Xorshift PRNG (simple, fast 32-bit PRNG)
- Wang hash (simple, fast 32-bit hash for seeding Xorshift, etc.)
Todo list (in no particular order):
- Error context stack
- Allow choice of whether to break per individual error/warning/assert
- Range structs (one-dimensional boxes)?
- Ray/line/plane structs
- Primitive intersection tests (e.g. box vs ray, box vs frustum, etc.)
- Primitive clipping (e.g. line vs box, triangle vs box, etc.)
- Splines
- Spherical harmonics
- Perlin noise
- Quadratic equation solver
- Convex hull solver
- Matrix diagonalization and decomposition?
- Complex numbers?
- Projective math?
- Grassmann algebra?
- Dual numbers?
- Filename/path manipulation, à la Python's
os.path - Custom memory allocators with logging, leak detection, etc.
- Threading-related stuff? Or does
std::asyncprovide enough support? - Cross-platform, cross-compiler support
- Command-line parameter parsing
- Basic UTF-8 string processing and conversion to/from UTF-16 for Windows
rigidtransformation class, represented by quat and translation vector?- Infinite-far-plane and z-reversed projection matrices
- Containers (arrays, hashtables, intrusive linked lists)
- Allocators (linear allocator, stack allocator, tracked heap allocator?)