[vlc-devel] [PATCH 2/4] viewpoint: add euler to 4x4 matrix conversion
Alexandre Janniaux
ajanni at videolabs.io
Thu Feb 7 12:12:16 CET 2019
Refactor code from opengl/vout_helper and d3d11, by merging the creation of
three 4x4 rotation matrices for the shaders into only one created from the
viewpoint.
---
include/vlc_viewpoint.h | 48 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/include/vlc_viewpoint.h b/include/vlc_viewpoint.h
index df930b3900..0b8404513c 100644
--- a/include/vlc_viewpoint.h
+++ b/include/vlc_viewpoint.h
@@ -66,4 +66,52 @@ static inline void vlc_viewpoint_reverse( vlc_viewpoint_t *p_vp )
p_vp->roll *= -1;
}
+static inline void vlc_viewpoint_to_4x4( const vlc_viewpoint_t *p_vp,
+ float *m )
+{
+ float s, c;
+
+ vlc_viewpoint_t vp = *p_vp;
+ vp.yaw *= M_PI; vp.pitch *= M_PI; vp.roll *= M_PI;
+ vp.yaw /= 180.f; vp.pitch /= 180.f; vp.roll /= 180.f;
+ vp.yaw += M_PI_2;
+
+ s = sinf(vp.pitch);
+ c = cosf(vp.pitch);
+ float x_rot[4][4] = {
+ { 1.f, 0.f, 0.f, 0.f },
+ { 0.f, c, -s, 0.f },
+ { 0.f, s, c, 0.f },
+ { 0.f, 0.f, 0.f, 1.f } };
+
+ s = sinf(vp.yaw);
+ c = cosf(vp.yaw);
+ float y_rot[4][4] = {
+ { c, 0.f, s, 0.f },
+ { 0.f, 1.f, 0.f, 0.f },
+ { -s, 0.f, c, 0.f },
+ { 0.f, 0.f, 0.f, 1.f } };
+
+ s = sinf(vp.roll);
+ c = cosf(vp.roll);
+ float z_rot[4][4] = {
+ { c, s, 0.f, 0.f },
+ { -s, c, 0.f, 0.f },
+ { 0.f, 0.f, 1.f, 0.f },
+ { 0.f, 0.f, 0.f, 1.f } };
+
+ /**
+ * Column-major matrix multiplication mathematically equal to
+ * z_rot * x_rot * y_rot
+ */
+ memset(m, 0, 16 * sizeof(float));
+ for (int i=0; i<4; ++i)
+ for (int j=0; j<4; ++j)
+ for (int k=0; k<4; ++k)
+ for (int l=0; l<4; ++l)
+ {
+ m[4*i+l] += y_rot[i][j] * x_rot[j][k] * z_rot[k][l];
+ }
+}
+
#endif /* VLC_VIEWPOINT_H_ */
--
2.20.1
More information about the vlc-devel
mailing list