1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-02 20:43:35 +00:00
lovr/src/core/maf.h

71 lines
3 KiB
C
Raw Normal View History

2017-01-26 10:20:30 +00:00
#pragma once
2019-01-06 11:25:00 +00:00
#ifdef _WIN32
#define MAF_EXPORT __declspec(dllexport)
#else
#define MAF_EXPORT __attribute__((visibility("default")))
2019-01-06 11:25:00 +00:00
#endif
typedef float* vec3;
typedef float* quat;
typedef float* mat4;
// vec3
2019-01-06 11:25:00 +00:00
MAF_EXPORT vec3 vec3_init(vec3 v, vec3 u);
MAF_EXPORT vec3 vec3_set(vec3 v, float x, float y, float z);
MAF_EXPORT vec3 vec3_add(vec3 v, vec3 u);
MAF_EXPORT vec3 vec3_sub(vec3 v, vec3 u);
MAF_EXPORT vec3 vec3_scale(vec3 v, float s);
MAF_EXPORT vec3 vec3_normalize(vec3 v);
MAF_EXPORT float vec3_length(vec3 v);
MAF_EXPORT float vec3_distance(vec3 v, vec3 u);
MAF_EXPORT float vec3_dot(vec3 v, vec3 u);
MAF_EXPORT vec3 vec3_cross(vec3 v, vec3 u);
MAF_EXPORT vec3 vec3_lerp(vec3 v, vec3 u, float t);
2019-02-08 20:39:10 +00:00
MAF_EXPORT vec3 vec3_min(vec3 v, vec3 u);
MAF_EXPORT vec3 vec3_max(vec3 v, vec3 u);
2018-10-07 04:58:40 +00:00
// quat
2019-01-06 11:25:00 +00:00
MAF_EXPORT quat quat_init(quat q, quat r);
MAF_EXPORT quat quat_set(quat q, float x, float y, float z, float w);
MAF_EXPORT quat quat_fromAngleAxis(quat q, float angle, float ax, float ay, float az);
MAF_EXPORT quat quat_fromMat4(quat q, mat4 m);
MAF_EXPORT quat quat_mul(quat q, quat r);
MAF_EXPORT quat quat_normalize(quat q);
MAF_EXPORT float quat_length(quat q);
MAF_EXPORT quat quat_slerp(quat q, quat r, float t);
MAF_EXPORT void quat_rotate(quat q, vec3 v);
MAF_EXPORT void quat_getAngleAxis(quat q, float* angle, float* x, float* y, float* z);
MAF_EXPORT quat quat_between(quat q, vec3 u, vec3 v);
// mat4
#define MAT4_IDENTITY { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }
2017-01-20 02:04:45 +00:00
#define mat4_init mat4_set
2019-01-06 11:25:00 +00:00
MAF_EXPORT mat4 mat4_set(mat4 m, mat4 n);
MAF_EXPORT mat4 mat4_fromMat34(mat4 m, float (*n)[4]);
MAF_EXPORT mat4 mat4_fromMat44(mat4 m, float (*n)[4]);
MAF_EXPORT mat4 mat4_identity(mat4 m);
MAF_EXPORT mat4 mat4_invert(mat4 m);
MAF_EXPORT mat4 mat4_transpose(mat4 m);
MAF_EXPORT mat4 mat4_multiply(mat4 m, mat4 n);
MAF_EXPORT mat4 mat4_translate(mat4 m, float x, float y, float z);
MAF_EXPORT mat4 mat4_rotate(mat4 m, float angle, float x, float y, float z);
MAF_EXPORT mat4 mat4_rotateQuat(mat4 m, quat q);
MAF_EXPORT mat4 mat4_scale(mat4 m, float x, float y, float z);
MAF_EXPORT void mat4_getPosition(mat4 m, vec3 position);
MAF_EXPORT void mat4_getOrientation(mat4 m, quat orientation);
2019-04-30 23:37:43 +00:00
MAF_EXPORT void mat4_getScale(mat4 m, vec3 scale);
2019-01-06 11:25:00 +00:00
MAF_EXPORT void mat4_getTransform(mat4 m, float* x, float* y, float* z, float* sx, float* sy, float* sz, float* angle, float* ax, float* ay, float* az);
MAF_EXPORT mat4 mat4_orthographic(mat4 m, float left, float right, float top, float bottom, float near, float far);
2019-04-11 20:47:25 +00:00
MAF_EXPORT mat4 mat4_perspective(mat4 m, float clipNear, float clipFar, float fov, float aspect);
MAF_EXPORT mat4 mat4_fov(mat4 m, float left, float right, float up, float down, float clipNear, float clipFar);
2019-01-06 11:25:00 +00:00
MAF_EXPORT mat4 mat4_lookAt(mat4 m, vec3 from, vec3 to, vec3 up);
2019-05-09 07:46:47 +00:00
MAF_EXPORT void mat4_transform(mat4 m, vec3 v);
MAF_EXPORT void mat4_transformDirection(mat4 m, vec3 v);
2018-10-07 04:21:25 +00:00
#ifdef LOVR_USE_SSE
2019-01-06 11:25:00 +00:00
MAF_EXPORT mat4 mat4_invertPose(mat4 m);
2018-10-07 04:21:25 +00:00
#else
#define mat4_invertPose mat4_invert
#endif