Dear Chickeners!
In my OpenGL and physics-simulation adventures I have fequently come across the need for a small math library in Chicken. I spent some time looking at the eggs out there, but some of them seemed a little overkill for my needs, so I decided to roll my own.
I was looking for:
- binary compatible with C/OpenGL/GLSL data-storage (f32vectors and friends)
- simple to use and short naming/syntax
- can multiply/add etc vector/matrix
- includes some transformation helpers like translate, rotate and scale
- not a lot of dependencies
In C++ land, it seems like GLM math library is popular, and it matches the criteria above (except language). A few days in, I've got a fairly functional math util egg:
Feedback is very welcome! In particular, because of all the different types (vec2, vec3, ivec2 etc), I wrote a template macro which does basic substring substitution:
(template
`((D 2 3 4))
(define (make-vecD fill) (make-f32vector D fill))
(define (make-dvecD fill) (make-f64vector D fill))
(define (make-ivecD fill) (make-s32vector D fill))
(define (make-uvecD fill) (make-u32vector D fill))
(define (make-bvecD fill) (make-u8vector D fill)))
That will expand the body three times, each time substituting D with 2~4. This works quite nicely and saves me a lot of copy-paste, but I don't know if it's in the Scheme spirit. Any thoughts?
Vectors use structures from srfi-4, and matrices get their own record (storing column-count along with its srfi-4 vector).
Once chicken-glm stabelizes a little, I'd like to make it reachable from chicken-install.
K.