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 *****************************************************************************/
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
;
39 const float x_rot
[4][4] = {
40 { 1.f
, 0.f
, 0.f
, 0.f
},
43 { 0.f
, 0.f
, 0.f
, 1.f
} };
47 const float y_rot
[4][4] = {
49 { 0.f
, 1.f
, 0.f
, 0.f
},
51 { 0.f
, 0.f
, 0.f
, 1.f
} };
55 const float z_rot
[4][4] = {
58 { 0.f
, 0.f
, 1.f
, 0.f
},
59 { 0.f
, 0.f
, 0.f
, 1.f
} };
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
];