[vlc-devel] [PATCH v2 2/8] viewpoint: add euler to 4x4 matrix conversion
Rémi Denis-Courmont
remi at remlab.net
Wed Mar 6 16:42:19 CET 2019
Le keskiviikkona 6. maaliskuuta 2019, 17.31.32 EET Alexandre Janniaux a écrit
:
> 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 | 13 ++++++++
> src/Makefile.am | 3 +-
> src/misc/viewpoint.c | 73 +++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 88 insertions(+), 1 deletion(-)
> create mode 100644 src/misc/viewpoint.c
>
> diff --git a/include/vlc_viewpoint.h b/include/vlc_viewpoint.h
> index 7c11c86323..e3887c62ec 100644
> --- a/include/vlc_viewpoint.h
> +++ b/include/vlc_viewpoint.h
> @@ -73,4 +73,17 @@ static inline void vlc_viewpoint_reverse( vlc_viewpoint_t
> *vp ) vp->roll *= -1;
> }
>
> +/**
> + * Generate the 4x4 transform matrix corresponding to a viewpoint
> + *
> + * Convert a vlc_viewpoint_t into a 4x4 transform matrix with a
> column-major + * layout.
> + * The transformation is applied as-is. you have to reverse the viewpoint
> with + * \ref vlc_viewpoint_reverse first if you want to transform the
> world. + *
> + * \param vp a valid viewpoint object
> + * \param matrix a 4x4-sized array which will contain the matrix data
> + */
> +void vlc_viewpoint_to_4x4( const vlc_viewpoint_t *vp, float *matrix );
> +
> #endif /* VLC_VIEWPOINT_H_ */
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 5f90229486..5e1a448cca 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -390,7 +390,8 @@ libvlccore_la_SOURCES = \
> misc/sort.c \
> misc/subpicture.c \
> misc/subpicture.h \
> - misc/medialibrary.c
> + misc/medialibrary.c \
> + misc/viewpoint.c
> libvlccore_la_LIBADD = $(LIBS_libvlccore) \
> ../compat/libcompat.la \
> $(LTLIBINTL) $(LTLIBICONV) \
> diff --git a/src/misc/viewpoint.c b/src/misc/viewpoint.c
> new file mode 100644
> index 0000000000..4e8f6a0be7
> --- /dev/null
> +++ b/src/misc/viewpoint.c
> @@ -0,0 +1,73 @@
> +/**************************************************************************
> *** + * viewpoint.c: viewpoint helpers for conversions and transformations +
> ***************************************************************************
> ** + * Copyright (C) 2019 VLC authors and VideoLAN
> + *
> + * Authors: Alexandre Janniaux <ajanni at videolabs.io>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as published by
> + * the Free Software Foundation; either version 2.1 of the License, or + *
> (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public License
> + * along with this program; if not, write to the Free Software Foundation,
> + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. +
> ***************************************************************************
> **/ +
> +#ifdef HAVE_CONFIG_H
> +# include "config.h"
> +#endif
> +
> +#include <vlc_viewpoint.h>
> +
> +void vlc_viewpoint_to_4x4( const vlc_viewpoint_t *p_vp, float *m )
> +{
> + float yaw = vp.yaw * (float)M_PI / 180.f + (float)M_PI_2;
> + float pitch = vp.pitch * (float)M_PI / 180.f;
> + float roll = vp.roll * (float)M_PI / 180.f;
> +
> + float s, c;
> +
> + s = sinf(pitch);
> + c = cosf(pitch);
> + const 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(yaw);
> + c = cosf(yaw);
> + const 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(roll);
> + c = cosf(roll);
> + const 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)
Indentation.
> + {
> + m[4*i+l] += y_rot[i][j] * x_rot[j][k] * z_rot[k][l];
> + }
> +}
--
Реми Дёни-Курмон
http://www.remlab.net/
More information about the vlc-devel
mailing list