qml: history.push changes view by default
[vlc.git] / src / misc / viewpoint.c
blobb4fb5484af0f0c2d2eb75b5f4f8829440348d55b
1 /*****************************************************************************
2 * viewpoint.c: viewpoint helpers for conversions and transformations
3 *****************************************************************************
4 * Copyright (C) 2019 VLC authors and VideoLAN
6 * Authors: Alexandre Janniaux <ajanni@videolabs.io>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <vlc_viewpoint.h>
29 void vlc_viewpoint_to_4x4( const vlc_viewpoint_t *vp, float *m )
31 float yaw = vp->yaw * (float)M_PI / 180.f + (float)M_PI_2;
32 float pitch = vp->pitch * (float)M_PI / 180.f;
33 float roll = vp->roll * (float)M_PI / 180.f;
35 float s, c;
37 s = sinf(pitch);
38 c = cosf(pitch);
39 const float x_rot[4][4] = {
40 { 1.f, 0.f, 0.f, 0.f },
41 { 0.f, c, -s, 0.f },
42 { 0.f, s, c, 0.f },
43 { 0.f, 0.f, 0.f, 1.f } };
45 s = sinf(yaw);
46 c = cosf(yaw);
47 const float y_rot[4][4] = {
48 { c, 0.f, s, 0.f },
49 { 0.f, 1.f, 0.f, 0.f },
50 { -s, 0.f, c, 0.f },
51 { 0.f, 0.f, 0.f, 1.f } };
53 s = sinf(roll);
54 c = cosf(roll);
55 const float z_rot[4][4] = {
56 { c, s, 0.f, 0.f },
57 { -s, c, 0.f, 0.f },
58 { 0.f, 0.f, 1.f, 0.f },
59 { 0.f, 0.f, 0.f, 1.f } };
61 /**
62 * Column-major matrix multiplication mathematically equal to
63 * z_rot * x_rot * y_rot
65 memset(m, 0, 16 * sizeof(float));
66 for (int i=0; i<4; ++i)
67 for (int j=0; j<4; ++j)
68 for (int k=0; k<4; ++k)
69 for (int l=0; l<4; ++l)
70 m[4*i+l] += y_rot[i][j] * x_rot[j][k] * z_rot[k][l];