Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/freeglut/progs/demos/spaceball/vmath.inl @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* vector functions */ | |
| 2 static INLINE vec3_t v3_cons(float x, float y, float z) | |
| 3 { | |
| 4 vec3_t res; | |
| 5 res.x = x; | |
| 6 res.y = y; | |
| 7 res.z = z; | |
| 8 return res; | |
| 9 } | |
| 10 | |
| 11 static INLINE vec3_t quat_vec(quat_t q) | |
| 12 { | |
| 13 vec3_t v; | |
| 14 v.x = q.x; | |
| 15 v.y = q.y; | |
| 16 v.z = q.z; | |
| 17 return v; | |
| 18 } | |
| 19 | |
| 20 static INLINE float v3_dot(vec3_t v1, vec3_t v2) | |
| 21 { | |
| 22 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; | |
| 23 } | |
| 24 | |
| 25 /* quaternion functions */ | |
| 26 static INLINE quat_t quat_cons(float s, float x, float y, float z) | |
| 27 { | |
| 28 quat_t q; | |
| 29 q.x = x; | |
| 30 q.y = y; | |
| 31 q.z = z; | |
| 32 q.w = s; | |
| 33 return q; | |
| 34 } | |
| 35 | |
| 36 static INLINE quat_t quat_mul(quat_t q1, quat_t q2) | |
| 37 { | |
| 38 quat_t res; | |
| 39 vec3_t v1 = quat_vec(q1); | |
| 40 vec3_t v2 = quat_vec(q2); | |
| 41 | |
| 42 res.w = q1.w * q2.w - v3_dot(v1, v2); | |
| 43 res.x = v2.x * q1.w + v1.x * q2.w + (v1.y * v2.z - v1.z * v2.y); | |
| 44 res.y = v2.y * q1.w + v1.y * q2.w + (v1.z * v2.x - v1.x * v2.z); | |
| 45 res.z = v2.z * q1.w + v1.z * q2.w + (v1.x * v2.y - v1.y * v2.x); | |
| 46 return res; | |
| 47 } | |
| 48 | |
| 49 static INLINE void quat_to_mat(mat4_t res, quat_t q) | |
| 50 { | |
| 51 m4_cons(res, 1.0f - 2.0f * q.y*q.y - 2.0f * q.z*q.z, 2.0f * q.x * q.y + 2.0f * q.w * q.z, 2.0f * q.z * q.x - 2.0f * q.w * q.y, 0, | |
| 52 2.0f * q.x * q.y - 2.0f * q.w * q.z, 1.0f - 2.0f * q.x*q.x - 2.0f * q.z*q.z, 2.0f * q.y * q.z + 2.0f * q.w * q.x, 0, | |
| 53 2.0f * q.z * q.x + 2.0f * q.w * q.y, 2.0f * q.y * q.z - 2.0f * q.w * q.x, 1.0f - 2.0f * q.x*q.x - 2.0f * q.y*q.y, 0, | |
| 54 0, 0, 0, 1); | |
| 55 } | |
| 56 | |
| 57 /* matrix functions */ | |
| 58 static INLINE void m4_cons(mat4_t m, | |
| 59 float m11, float m12, float m13, float m14, | |
| 60 float m21, float m22, float m23, float m24, | |
| 61 float m31, float m32, float m33, float m34, | |
| 62 float m41, float m42, float m43, float m44) | |
| 63 { | |
| 64 m[0][0] = m11; m[1][0] = m12; m[2][0] = m13; m[3][0] = m14; | |
| 65 m[0][1] = m21; m[1][1] = m22; m[2][1] = m23; m[3][1] = m24; | |
| 66 m[0][2] = m31; m[1][2] = m32; m[2][2] = m33; m[3][2] = m34; | |
| 67 m[0][3] = m41; m[1][3] = m42; m[2][3] = m43; m[3][3] = m44; | |
| 68 } |
