[vlc-devel] [PATCH 1/3] core: add a variable type for 3D angles
Steve Lhomme
robux4 at videolabs.io
Mon Feb 27 17:35:27 CET 2017
yaw, pitch, roll
---
include/vlc_common.h | 1 +
include/vlc_variables.h | 28 ++++++++++++++++++++++++++++
src/misc/variables.c | 11 ++++++++++-
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/include/vlc_common.h b/include/vlc_common.h
index 6a75753dbf..f31912a649 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -332,6 +332,7 @@ typedef union
void * p_address;
vlc_list_t * p_list;
struct { int32_t x; int32_t y; } coords;
+ struct { float yaw; float pitch; float roll; } angles;
} vlc_value_t;
diff --git a/include/vlc_variables.h b/include/vlc_variables.h
index 83752b171f..9ff95f6b02 100644
--- a/include/vlc_variables.h
+++ b/include/vlc_variables.h
@@ -52,6 +52,7 @@
#define VLC_VAR_FLOAT 0x0050
#define VLC_VAR_ADDRESS 0x0070
#define VLC_VAR_COORDS 0x00A0
+#define VLC_VAR_ANGLES 0x00B0
/**@}*/
/** \defgroup var_flags Additive flags
@@ -213,6 +214,17 @@ static inline int var_SetCoords( vlc_object_t *obj, const char *name,
}
#define var_SetCoords(o,n,x,y) var_SetCoords(VLC_OBJECT(o),n,x,y)
+static inline int var_SetAngles( vlc_object_t *obj, const char *name,
+ float yaw, float pitch, float roll )
+{
+ vlc_value_t val;
+ val.angles.yaw = yaw;
+ val.angles.pitch = pitch;
+ val.angles.roll = roll;
+ return var_SetChecked (obj, name, VLC_VAR_ANGLES, val);
+}
+#define var_SetAngles(o,n,y,p,r) var_SetAngles(VLC_OBJECT(o),n,y,p,r)
+
/**
* Set the value of a float variable
*
@@ -311,6 +323,22 @@ static inline void var_GetCoords( vlc_object_t *obj, const char *name,
}
#define var_GetCoords(o,n,x,y) var_GetCoords(VLC_OBJECT(o),n,x,y)
+static inline void var_GetAngles( vlc_object_t *obj, const char *name,
+ float *p_yaw, float *p_pitch, float *p_roll )
+{
+ vlc_value_t val;
+
+ if (likely(!var_GetChecked (obj, name, VLC_VAR_ANGLES, &val)))
+ {
+ *p_yaw = val.angles.yaw;
+ *p_pitch = val.angles.pitch;
+ *p_roll = val.angles.roll;
+ }
+ else
+ *p_yaw = *p_pitch = *p_roll = 0;
+}
+#define var_GetAngles(o,n,x,y) var_GetAngles(VLC_OBJECT(o),n,x,y)
+
/**
* Get a float value
*
diff --git a/src/misc/variables.c b/src/misc/variables.c
index 72296111e1..8440cb2d01 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -138,7 +138,8 @@ bool_ops = { CmpBool, DupDummy, FreeDummy, },
float_ops = { CmpFloat, DupDummy, FreeDummy, },
int_ops = { CmpInt, DupDummy, FreeDummy, },
string_ops = { CmpString, DupString, FreeString, },
-coords_ops = { NULL, DupDummy, FreeDummy, };
+coords_ops = { NULL, DupDummy, FreeDummy, },
+angles_ops = { NULL, DupDummy, FreeDummy, };
static int varcmp( const void *a, const void *b )
{
@@ -346,6 +347,10 @@ int var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
p_var->ops = &coords_ops;
p_var->val.coords.x = p_var->val.coords.y = 0;
break;
+ case VLC_VAR_ANGLES:
+ p_var->ops = &angles_ops;
+ p_var->val.angles.yaw = p_var->val.angles.pitch = p_var->val.angles.roll = 0.f;
+ break;
case VLC_VAR_ADDRESS:
p_var->ops = &addr_ops;
p_var->val.p_address = NULL;
@@ -1327,6 +1332,7 @@ static void DumpVariable(const void *data, const VISIT which, const int depth)
case VLC_VAR_STRING: typename = "string"; break;
case VLC_VAR_FLOAT: typename = "float"; break;
case VLC_VAR_COORDS: typename = "coordinates"; break;
+ case VLC_VAR_ANGLES: typename = "angles"; break;
case VLC_VAR_ADDRESS: typename = "address"; break;
default: typename = "unknown"; break;
}
@@ -1362,6 +1368,9 @@ static void DumpVariable(const void *data, const VISIT which, const int depth)
printf(": %"PRId32"x%"PRId32,
var->val.coords.x, var->val.coords.y);
break;
+ case VLC_VAR_ANGLES:
+ printf(": %f/%f/%f", var->val.angles.yaw, var->val.angles.pitch, var->val.angles.roll );
+ break;
case VLC_VAR_ADDRESS:
printf(": %p", var->val.p_address);
break;
--
2.11.1
More information about the vlc-devel
mailing list