17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 13:19:20 +02:00
Files
maszyna/utilities/headtrack.cpp
maj00r b8f040e6fd propagate template headers transitively, import Console where used
AnimModel.cpp reaches cParser through the simulation core, not a direct
import, so the previous pass missed it; the propagation now follows the
whole import closure. Train.cpp, drivermode.cpp and Globals.cpp call
Console:: inside _WIN32 guards without importing eu07.console - invisible
on Linux, where those blocks are skipped.
2026-09-10 01:41:24 +02:00

80 lines
1.9 KiB
C++

module;
#include <array>
#include <chrono>
#include <deque>
#include <limits>
#include <mutex>
#include <sstream>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include <ostream>
#include <cstddef>
#include <string>
#include "utilities/Globals_macros.h"
#include <GLFW/glfw3.h>
module eu07.utilities.headtrack;
import eu07.utilities.globals;
import eu07.glm;
headtrack::headtrack()
{
}
void headtrack::find_joy() {
for (size_t i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; i++) {
if (!glfwJoystickPresent(i))
continue;
std::string name(glfwGetJoystickName(i));
if (name == Global.headtrack_conf.joy) {
joy_id = i;
return;
}
}
joy_id = -1;
}
float headtrack::get_axis(const float *data, int count, int axis, float mul) {
if (axis < 0)
return 0.0f;
if (axis >= count)
return 0.0f;
return data[axis] * mul;
}
void headtrack::update()
{
if (joy_id == -1 || !glfwJoystickPresent(joy_id)) {
Global.viewport_move = glm::vec3();
Global.viewport_rotate = glm::mat3();
find_joy();
return;
}
int count;
const float* axes = glfwGetJoystickAxes(joy_id, &count);
auto const &move_axes = Global.headtrack_conf.move_axes;
auto const &rot_axes = Global.headtrack_conf.rot_axes;
auto const &move_mul = Global.headtrack_conf.move_mul;
auto const &rot_mul = Global.headtrack_conf.rot_mul;
glm::vec3 move;
move.x = get_axis(axes, count, move_axes.x, move_mul.x);
move.y = get_axis(axes, count, move_axes.y, move_mul.y);
move.z = get_axis(axes, count, move_axes.z, move_mul.z);
glm::vec3 rotate;
rotate.x = get_axis(axes, count, rot_axes.x, rot_mul.x);
rotate.y = get_axis(axes, count, rot_axes.y, rot_mul.y);
rotate.z = get_axis(axes, count, rot_axes.z, rot_mul.z);
Global.viewport_move = move;
Global.viewport_rotate = glm::orientate3(rotate);
}