VLC  4.0.0-dev
vlc_viewpoint.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_viewpoint.h: viewpoint struct and helpers
3  *****************************************************************************
4  * Copyright (C) 2017 VLC authors and VideoLAN
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20 
21 #ifndef VLC_VIEWPOINT_H_
22 #define VLC_VIEWPOINT_H_ 1
23 
24 #include <vlc_common.h>
25 
26 #include <math.h>
27 
28 /**
29  * \file
30  * Video and audio viewpoint struct and helpers
31  */
32 
33 #define FIELD_OF_VIEW_DEGREES_DEFAULT 80.f
34 #define FIELD_OF_VIEW_DEGREES_MAX 150.f
35 #define FIELD_OF_VIEW_DEGREES_MIN 20.f
36 
37 /**
38  * Viewpoints
39  */
40 struct vlc_viewpoint_t {
41  float yaw; /* yaw in degrees */
42  float pitch; /* pitch in degrees */
43  float roll; /* roll in degrees */
44  float fov; /* field of view in degrees */
45 };
46 
47 static inline void vlc_viewpoint_init( vlc_viewpoint_t *p_vp )
48 {
49  p_vp->yaw = p_vp->pitch = p_vp->roll = 0.0f;
51 }
52 
53 static inline void vlc_viewpoint_clip( vlc_viewpoint_t *p_vp )
54 {
55  p_vp->yaw = fmodf( p_vp->yaw, 360.f );
56  p_vp->pitch = fmodf( p_vp->pitch, 360.f );
57  p_vp->roll = fmodf( p_vp->roll, 360.f );
58  p_vp->fov = VLC_CLIP( p_vp->fov, FIELD_OF_VIEW_DEGREES_MIN,
60 }
61 
62 /**
63  * Reverse the viewpoint rotation.
64  *
65  * It can be used to convert a camera view into a world transformation.
66  * It will also copy non-rotation related data from \p src to \p dst.
67  *
68  * \param dst the viewpoint with the final reversed rotation
69  * \param src the viewpoint for which the rotation need to be reversed
70  */
71 static inline void vlc_viewpoint_reverse( vlc_viewpoint_t *dst,
72  const vlc_viewpoint_t *src )
73 {
74  dst->yaw = -src->yaw;
75  dst->pitch = -src->pitch;
76  dst->roll = -src->roll;
77 
78  dst->fov = src->fov;
79 }
80 
81 /**
82  * Generate the 4x4 transform matrix corresponding to a viewpoint
83  *
84  * Convert a vlc_viewpoint_t into a 4x4 transform matrix with a column-major
85  * layout.
86  * The transformation is applied as-is. you have to reverse the viewpoint with
87  * \ref vlc_viewpoint_reverse first if you want to transform the world.
88  *
89  * \param vp a valid viewpoint object
90  * \param matrix a 4x4-sized array which will contain the matrix data
91  */
92 VLC_API
93 void vlc_viewpoint_to_4x4( const vlc_viewpoint_t *vp, float *matrix );
94 
95 #endif /* VLC_VIEWPOINT_H_ */
#define VLC_CLIP(v, min, max)
Definition: vlc_common.h:549
This file is a collection of common definitions and types.
float yaw
Definition: vlc_viewpoint.h:42
float roll
Definition: vlc_viewpoint.h:44
#define FIELD_OF_VIEW_DEGREES_MAX
Definition: vlc_viewpoint.h:35
#define FIELD_OF_VIEW_DEGREES_MIN
Definition: vlc_viewpoint.h:36
float fov
Definition: vlc_viewpoint.h:45
static void vlc_viewpoint_clip(vlc_viewpoint_t *p_vp)
Definition: vlc_viewpoint.h:54
static void vlc_viewpoint_reverse(vlc_viewpoint_t *dst, const vlc_viewpoint_t *src)
Reverse the viewpoint rotation.
Definition: vlc_viewpoint.h:72
Viewpoints.
Definition: vlc_viewpoint.h:41
float pitch
Definition: vlc_viewpoint.h:43
static void vlc_viewpoint_init(vlc_viewpoint_t *p_vp)
Definition: vlc_viewpoint.h:48
#define VLC_API
Definition: fourcc_gen.c:31
#define FIELD_OF_VIEW_DEGREES_DEFAULT
Definition: vlc_viewpoint.h:34
void vlc_viewpoint_to_4x4(const vlc_viewpoint_t *vp, float *matrix)
Generate the 4x4 transform matrix corresponding to a viewpoint.
Definition: viewpoint.c:29