Haiku API: MathsΒΆ

Haiku ships with its own math library. this library is rather simple and offers data structures based on the GLSL specification.

  • Templated vector types:

/* Math Vector data structure */
template<typename T, unsigned D> struct vec_t { T at[D]; };
/* Forward declarations */
template<typename T> struct mat3_t; /**< templated 3x3 matrix */
template<typename T> struct mat4_t; /**< templated 4x4 matrix (homogeneous coordinates) */
/* Haiku Typedefs */
typedef vec_t<uint32_t,2u>  Vec2u; /**< uint32 2D vector */
typedef vec_t<uint32_t,3u>  Vec3u; /**< uint32 3D vector */
typedef vec_t<int32_t,2u>   Vec2i; /**< int32  2D vector */
typedef vec_t<float,2u>     Vec2f; /**< float  2D vector */
typedef vec_t<float,3u>     Vec3f; /**< float  3D vector */
typedef vec_t<float,4u>     Vec4f; /**< float  4D vector */
typedef mat3_t<float>       Mat3f; /**< float  3x3 matrix */
typedef mat4_t<float>       Mat4f; /**< float  4x4 matrix */
/* GLSL Typedefs */
typedef vec_t<float,2u>     vec2;  /**< float  2D vector */
typedef vec_t<float,3u>     vec3;  /**< float  3D vector */
typedef vec_t<float,4u>     vec4;  /**< float  homogeneous vector */
typedef vec_t<uint32_t,2u>  uvec2; /**< uint32 2D vector */
typedef vec_t<uint32_t,3u>  uvec3; /**< uint32 3D vector */
typedef vec_t<uint32_t,4u>  uvec4; /**< uint32 homogeneous vector */
typedef vec_t<int32_t,2u>   ivec2; /**< int32  2D vector */
typedef vec_t<int32_t,3u>   ivec3; /**< int32  3D vector */
typedef vec_t<int32_t,4u>   ivec4; /**< int32  homogeneous vector */
typedef vec_t<double,2u>    dvec2; /**< double 2D vector */
typedef vec_t<double,3u>    dvec3; /**< double 3D vector */
typedef vec_t<double,4u>    dvec4; /**< double homogeneous vector */
typedef vec_t<bool,2u>      bvec2; /**< bool   2D vector */
typedef vec_t<bool,3u>      bvec3; /**< bool   3D vector */
typedef vec_t<bool,4u>      bvec4; /**< bool   homogeneous vector */
typedef mat3_t<float>       mat3;  /**< float  3x3 matrix */
typedef mat4_t<float>       mat4;  /**< float  4x4 matrix */
  • Templated matrix types:

/* Forward declarations */
template<typename T> struct mat3_t; /**< templated 3x3 matrix */
template<typename T> struct mat4_t; /**< templated 4x4 matrix (homogeneous coordinates) */
/* Haiku Typedefs */
typedef mat3_t<float>    Mat3f; /**< float  3x3 matrix */
typedef mat4_t<float>    Mat4f; /**< float  4x4 matrix */
/* GLSL Typedefs */
typedef mat3_t<float>    mat3;  /**< float  3x3 matrix */
typedef mat4_t<float>    mat4;  /**< float  4x4 matrix */

Global maths constants & namespace: