mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-17 04:15:44 +00:00
d/simulated: Make it possible to pass in movement mode
And a little bit of tidy.
This commit is contained in:
parent
06806cc6ef
commit
121bcf028a
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020, Collabora, Ltd.
|
||||
// Copyright 2020-2023, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
|
@ -22,6 +22,8 @@
|
|||
#include "util/u_logging.h"
|
||||
#include "util/u_distortion_mesh.h"
|
||||
|
||||
#include "simulated_interface.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
@ -31,13 +33,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
enum simulated_movement
|
||||
{
|
||||
SIMULATED_WOBBLE,
|
||||
SIMULATED_ROTATE,
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* A example HMD device.
|
||||
*
|
||||
|
@ -71,7 +66,6 @@ simulated_hmd(struct xrt_device *xdev)
|
|||
}
|
||||
|
||||
DEBUG_GET_ONCE_LOG_OPTION(simulated_log, "SIMULATED_LOG", U_LOGGING_WARN)
|
||||
DEBUG_GET_ONCE_BOOL_OPTION(simulated_rotate, "SIMULATED_ROTATE", false)
|
||||
|
||||
#define DH_TRACE(p, ...) U_LOG_XDEV_IFL_T(&dh->base, dh->log_level, __VA_ARGS__)
|
||||
#define DH_DEBUG(p, ...) U_LOG_XDEV_IFL_D(&dh->base, dh->log_level, __VA_ARGS__)
|
||||
|
@ -118,7 +112,7 @@ simulated_hmd_get_tracked_pose(struct xrt_device *xdev,
|
|||
|
||||
switch (dh->movement) {
|
||||
default:
|
||||
case SIMULATED_WOBBLE:
|
||||
case SIMULATED_MOVEMENT_WOBBLE:
|
||||
// Wobble time.
|
||||
dh->pose.position.x = dh->center.x + sin((time_s / t2) * M_PI) * d2 - d;
|
||||
dh->pose.position.y = dh->center.y + sin((time_s / t) * M_PI) * d;
|
||||
|
@ -128,13 +122,17 @@ simulated_hmd_get_tracked_pose(struct xrt_device *xdev,
|
|||
dh->pose.orientation.w = 1;
|
||||
math_quat_normalize(&dh->pose.orientation);
|
||||
break;
|
||||
case SIMULATED_ROTATE:
|
||||
case SIMULATED_MOVEMENT_ROTATE:
|
||||
// Reset position.
|
||||
dh->pose.position = dh->center;
|
||||
|
||||
// Rotate around the up vector.
|
||||
math_quat_from_angle_vector(time_s / 4, &up, &dh->pose.orientation);
|
||||
break;
|
||||
case SIMULATED_MOVEMENT_STATIONARY:
|
||||
// Reset pose.
|
||||
dh->pose = (struct xrt_pose)XRT_POSE_IDENTITY;
|
||||
break;
|
||||
}
|
||||
|
||||
out_relation->pose = dh->pose;
|
||||
|
@ -157,7 +155,7 @@ simulated_hmd_get_view_poses(struct xrt_device *xdev,
|
|||
}
|
||||
|
||||
struct xrt_device *
|
||||
simulated_hmd_create(void)
|
||||
simulated_hmd_create(enum simulated_movement movement)
|
||||
{
|
||||
enum u_device_alloc_flags flags =
|
||||
(enum u_device_alloc_flags)(U_DEVICE_ALLOC_HMD | U_DEVICE_ALLOC_TRACKING_NONE);
|
||||
|
@ -172,6 +170,7 @@ simulated_hmd_create(void)
|
|||
dh->created_ns = os_monotonic_get_ns();
|
||||
dh->diameter_m = 0.05f;
|
||||
dh->log_level = debug_get_log_option_simulated_log();
|
||||
dh->movement = movement;
|
||||
|
||||
// Print name.
|
||||
snprintf(dh->base.str, XRT_DEVICE_NAME_LEN, "Simulated HMD");
|
||||
|
@ -197,12 +196,6 @@ simulated_hmd_create(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// Select the type of movement.
|
||||
dh->movement = SIMULATED_WOBBLE;
|
||||
if (debug_get_bool_option_simulated_rotate()) {
|
||||
dh->movement = SIMULATED_ROTATE;
|
||||
}
|
||||
|
||||
// Setup variable tracker.
|
||||
u_var_add_root(dh, "Simulated HMD", true);
|
||||
u_var_add_pose(dh, &dh->pose, "pose");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020, Collabora, Ltd.
|
||||
// Copyright 2020-2023, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
|
@ -9,10 +9,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "xrt/xrt_compiler.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
* @defgroup drv_simulated Simulated driver
|
||||
* @ingroup drv
|
||||
|
@ -20,6 +24,24 @@ extern "C" {
|
|||
* @brief Simple do-nothing simulated driver.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @dir drivers/simulated
|
||||
*
|
||||
* @brief @ref drv_simulated files.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* What type of movement should the simulated device do.
|
||||
*
|
||||
* @ingroup drv_simulated
|
||||
*/
|
||||
enum simulated_movement
|
||||
{
|
||||
SIMULATED_MOVEMENT_WOBBLE,
|
||||
SIMULATED_MOVEMENT_ROTATE,
|
||||
SIMULATED_MOVEMENT_STATIONARY,
|
||||
};
|
||||
|
||||
/*!
|
||||
* Create a auto prober for simulated devices.
|
||||
*
|
||||
|
@ -34,13 +56,7 @@ simulated_create_auto_prober(void);
|
|||
* @ingroup drv_simulated
|
||||
*/
|
||||
struct xrt_device *
|
||||
simulated_hmd_create(void);
|
||||
|
||||
/*!
|
||||
* @dir drivers/simulated
|
||||
*
|
||||
* @brief @ref drv_simulated files.
|
||||
*/
|
||||
simulated_hmd_create(enum simulated_movement movement);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020, Collabora, Ltd.
|
||||
// Copyright 2020-2023, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
|
@ -17,6 +17,9 @@
|
|||
|
||||
#include "simulated_interface.h"
|
||||
|
||||
|
||||
DEBUG_GET_ONCE_BOOL_OPTION(simulated_rotate, "SIMULATED_ROTATE", false)
|
||||
|
||||
/*!
|
||||
* @implements xrt_auto_prober
|
||||
*/
|
||||
|
@ -57,7 +60,14 @@ simulated_prober_autoprobe(struct xrt_auto_prober *xap,
|
|||
return 0;
|
||||
}
|
||||
|
||||
out_xdevs[0] = simulated_hmd_create();
|
||||
// Select the type of movement.
|
||||
enum simulated_movement movement = SIMULATED_MOVEMENT_WOBBLE;
|
||||
if (debug_get_bool_option_simulated_rotate()) {
|
||||
movement = SIMULATED_MOVEMENT_ROTATE;
|
||||
}
|
||||
|
||||
out_xdevs[0] = simulated_hmd_create(movement);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -340,7 +340,7 @@ rgb_open_system(struct xrt_builder *xb, cJSON *config, struct xrt_prober *xp, st
|
|||
}
|
||||
#endif
|
||||
} else {
|
||||
head = simulated_hmd_create();
|
||||
head = simulated_hmd_create(SIMULATED_MOVEMENT_WOBBLE);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ sdl_system_devices_init(struct sdl_program *sp)
|
|||
sp->xsysd_base.destroy = sdl_system_devices_destroy;
|
||||
|
||||
#ifdef USE_SIMULATED
|
||||
struct xrt_device *head = simulated_hmd_create();
|
||||
struct xrt_device *head = simulated_hmd_create(SIMULATED_MOVEMENT_WOBBLE);
|
||||
#else
|
||||
struct xrt_device *head = &sp->xdev_base;
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue