Update to spice2x-25-04-25 (pre-apply)
> broken commit
This commit is contained in:
+52
-140
@@ -8,7 +8,6 @@
|
||||
#include "util/detour.h"
|
||||
#include "util/logging.h"
|
||||
#include "util/memutils.h"
|
||||
#include "misc/vrutil.h"
|
||||
|
||||
#pragma pack(push)
|
||||
|
||||
@@ -148,15 +147,11 @@ namespace games::drs {
|
||||
return 1;
|
||||
}
|
||||
|
||||
char DRS_TAPELED[38 * 49][3] {};
|
||||
bool VR_STARTED = false;
|
||||
linalg::aliases::float3 VR_SCALE(100, 100, 1.f);
|
||||
linalg::aliases::float3 VR_OFFSET(0.f, 0.f, -0.1f);
|
||||
float VR_ROTATION = 0.f;
|
||||
VRFoot VR_FOOTS[2] {
|
||||
{1},
|
||||
{2},
|
||||
};
|
||||
char DRS_TAPELED[DRS_TAPELED_COLS_TOTAL][3] {};
|
||||
bool DISABLE_TOUCH = false;
|
||||
bool TRANSPOSE_TOUCH = false;
|
||||
|
||||
std::vector<TouchEvent> TOUCH_EVENTS;
|
||||
|
||||
inline DWORD scale_double_to_xy(double val) {
|
||||
return static_cast<DWORD>(val * 32768);
|
||||
@@ -221,138 +216,54 @@ namespace games::drs {
|
||||
touch_callback(&dev, game_touches.get(), (int) event_count, 0, user_data);
|
||||
}
|
||||
|
||||
uint32_t VRFoot::get_index() {
|
||||
if (index == ~0u) {
|
||||
if (id == 1) return vrutil::INDEX_LEFT;
|
||||
if (id == 2) return vrutil::INDEX_RIGHT;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
void start_touch() {
|
||||
std::thread t([] {
|
||||
log_info("drs", "starting touch input thread");
|
||||
|
||||
linalg::aliases::float3 VRFoot::to_world(linalg::aliases::float3 pos) {
|
||||
pos = linalg::aliases::float3(-pos.z, pos.x, pos.y);
|
||||
const float deg_to_rad = (float) (1 / 180.f * M_PI);
|
||||
auto s = sinf(VR_ROTATION * deg_to_rad);
|
||||
auto c = cosf(VR_ROTATION * deg_to_rad);
|
||||
pos = linalg::aliases::float3(pos.x * c - pos.y * s,
|
||||
pos.x * s + pos.y * c,
|
||||
pos.z);
|
||||
return pos * VR_SCALE + VR_OFFSET;
|
||||
}
|
||||
// main loop
|
||||
while (TRUE) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
|
||||
void start_vr() {
|
||||
if (vrutil::STATUS != vrutil::VRStatus::Running) return;
|
||||
if (!VR_STARTED) {
|
||||
VR_STARTED = true;
|
||||
std::thread t([] {
|
||||
log_info("drs", "starting VR thread");
|
||||
|
||||
// dance floor plane
|
||||
const linalg::aliases::float3 plane_normal(0, 0, 1);
|
||||
const linalg::aliases::float3 plane_point(0, 0, 0);
|
||||
const float touch_width = 1.f;
|
||||
const float touch_height = 1.f;
|
||||
|
||||
// main loop
|
||||
while (vrutil::STATUS == vrutil::VRStatus::Running) {
|
||||
|
||||
// iterate foots
|
||||
for (auto &foot : VR_FOOTS) {
|
||||
vr::TrackedDevicePose_t pose;
|
||||
vr::VRControllerState_t state;
|
||||
vrutil::get_con_pose(foot.get_index(), &pose, &state);
|
||||
|
||||
// only accept valid poses
|
||||
if (pose.bPoseIsValid) {
|
||||
auto length = std::max(foot.length, 0.001f);
|
||||
|
||||
// get components
|
||||
auto translation = foot.to_world(vrutil::get_translation(
|
||||
pose.mDeviceToAbsoluteTracking));
|
||||
auto direction = -linalg::qzdir(linalg::qmul(
|
||||
vrutil::get_rotation(pose.mDeviceToAbsoluteTracking.m),
|
||||
foot.rotation));
|
||||
direction = linalg::aliases::float3 {
|
||||
-direction.z, direction.x, direction.y
|
||||
};
|
||||
|
||||
// get intersection point
|
||||
auto intersection = vrutil::intersect_point(
|
||||
direction, translation,
|
||||
plane_normal, plane_point);
|
||||
auto distance = linalg::distance(
|
||||
translation, intersection);
|
||||
|
||||
// update event details
|
||||
foot.height = std::max(0.f, translation.z - intersection.z);
|
||||
foot.event.id = foot.id;
|
||||
foot.event.x = (intersection.x / 38.f) * touch_width;
|
||||
foot.event.y = (intersection.y / 49.f) * touch_height;
|
||||
if (translation.z > intersection.z) {
|
||||
foot.event.width = foot.size_base
|
||||
+ foot.size_scale * std::max(0.f, 1.f - distance / length);
|
||||
} else {
|
||||
foot.event.width = foot.size_base + foot.size_scale;
|
||||
}
|
||||
foot.event.height = foot.event.width;
|
||||
|
||||
// check if controller points down
|
||||
if (direction.z < 0) {
|
||||
|
||||
// check if plane in range
|
||||
if (distance <= length) {
|
||||
|
||||
// check previous event
|
||||
switch (foot.event.type) {
|
||||
case DRS_UP:
|
||||
|
||||
// generate down event
|
||||
foot.event.type = DRS_DOWN;
|
||||
break;
|
||||
|
||||
case DRS_DOWN:
|
||||
case DRS_MOVE:
|
||||
|
||||
// generate move event
|
||||
foot.event.type = DRS_MOVE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// send event
|
||||
drs::fire_touches(&foot.event, 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// foot not intersecting with plane
|
||||
switch (foot.event.type) {
|
||||
case DRS_DOWN:
|
||||
case DRS_MOVE:
|
||||
|
||||
// generate up event
|
||||
foot.event.type = DRS_UP;
|
||||
drs::fire_touches(&foot.event, 1);
|
||||
break;
|
||||
|
||||
case DRS_UP:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
TOUCH_EVENTS.clear();
|
||||
touch_get_events(TOUCH_EVENTS);
|
||||
for (auto &te : TOUCH_EVENTS) {
|
||||
drs_touch_t drs_event;
|
||||
switch (te.type) {
|
||||
case TOUCH_DOWN:
|
||||
drs_event.type = DRS_DOWN;
|
||||
break;
|
||||
case TOUCH_UP:
|
||||
drs_event.type = DRS_UP;
|
||||
break;
|
||||
case TOUCH_MOVE:
|
||||
drs_event.type = DRS_MOVE;
|
||||
break;
|
||||
}
|
||||
drs_event.id = te.id;
|
||||
|
||||
// slow down
|
||||
vrutil::scan();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
// DRS uses 100x100 (px) as default foot size, so use that
|
||||
const float w = 100.1/1920.f;
|
||||
const float h = 100.1/1080.f;
|
||||
drs_event.width = w;
|
||||
drs_event.height = h;
|
||||
|
||||
const float x = te.x / 1920.f;
|
||||
const float y = te.y / 1080.f;
|
||||
// note that only x-y are transposed, not w-h
|
||||
if (TRANSPOSE_TOUCH) {
|
||||
drs_event.x = y;
|
||||
drs_event.y = x;
|
||||
} else {
|
||||
drs_event.x = x;
|
||||
drs_event.y = y;
|
||||
}
|
||||
drs::fire_touches(&drs_event, 1);
|
||||
}
|
||||
VR_STARTED = false;
|
||||
return nullptr;
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
|
||||
DRSGame::DRSGame() : Game("DANCERUSH") {
|
||||
@@ -397,9 +308,10 @@ namespace games::drs {
|
||||
detour::iat("?InitTouch@TouchSDK@@QEAAHPEAU_DeviceInfo@@HP6AXU2@PEBU_TouchPointData@@HHPEBX@ZP6AX1_N3@ZPEAX@Z",
|
||||
(void *) &TouchSDK_InitTouch, avs::game::DLL_INSTANCE);
|
||||
|
||||
// VR
|
||||
if (vrutil::STATUS == vrutil::VRStatus::Running) {
|
||||
start_vr();
|
||||
if (!DISABLE_TOUCH) {
|
||||
start_touch();
|
||||
} else {
|
||||
log_info("drs", "no native input method detected");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user