Skip to content

Instantly share code, notes, and snippets.

@naikrovek
Created May 31, 2019 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naikrovek/9c39f93e8118eba484a09d39d9081c96 to your computer and use it in GitHub Desktop.
Save naikrovek/9c39f93e8118eba484a09d39d9081c96 to your computer and use it in GitHub Desktop.
excerpt from SpaceMouse.cpp
while (hid_read(Device, pOutput, 28) > 0 && ctr < maxreads)
{
drecieved = true;
if (printdebug)
{
dreport += FString::FromHexBlob(pOutput, 28);
}
unsigned char* pCurr = pOutput;
for (int i = 0; i < 4; i++)
{
unsigned char report = *pCurr;
int16 tx = *(int16*)(pCurr + 1);
int16 ty = *(int16*)(pCurr + 3);
int16 tz = *(int16*)(pCurr + 5);
int16 rx = *(int16*)(pCurr + 7); // new
int16 ry = *(int16*)(pCurr + 9); // new
int16 rz = *(int16*)(pCurr + 11); // new
float fx = (float)tx / FSpaceMouseModule::gResolution;
float fy = (float)ty / FSpaceMouseModule::gResolution;
float fz = (float)tz / FSpaceMouseModule::gResolution;
float rotx = (float)rx / FSpaceMouseModule::gResolution; // new
float roty = (float)ry / FSpaceMouseModule::gResolution; // new
float rotz = (float)rz / FSpaceMouseModule::gResolution; // new
if (report == 0 && printdebug)
{
dr0 = FString::FromHexBlob(pCurr, 7);
}
if (report == 1)
{
Moving = true;
FVector xmap = FSpaceMouseModule::Settings->XTranslationAxisMap;
FVector ymap = FSpaceMouseModule::Settings->YTranslationAxisMap;
FVector zmap = FSpaceMouseModule::Settings->ZTranslationAxisMap;
Translation = FVector(
fx * xmap.X + fy * xmap.Y + fz * xmap.Z,
fx * ymap.X + fy * ymap.Y + fz * ymap.Z,
fx * zmap.X + fy * zmap.Y + fz * zmap.Z
) * FSpaceMouseModule::Settings->TranslationUnitsPerSec * FApp::GetDeltaTime();
FVector rxmap = FSpaceMouseModule::Settings->PitchAxisMap; // changed var name
FVector rymap = FSpaceMouseModule::Settings->YawAxisMap; // changed var name
FVector rzmap = FSpaceMouseModule::Settings->RollAxisMap; // changed var name
Rotation = FRotator(
rotx * rxmap.X + roty * rxmap.Y + rotz * rxmap.Z, // changed var names
rotx * rymap.X + roty * rymap.Y + rotz * rymap.Z, // changed var names
rotx * rzmap.X + roty * rzmap.Y + rotz * rzmap.Z // changed var names
) * FSpaceMouseModule::Settings->RotationDegreesPerSec * FApp::GetDeltaTime();
if (printdebug)
{
dr1 = FString::FromHexBlob(pCurr, 13);
}
pCurr += 13; // new
}
else if (report == 2) // merged this logic into previous `if`
{
/*
Moving = true;
if (printdebug) dr2 = FString::FromHexBlob(pCurr, 7);
*/
pCurr += 7; // new
}
else if (report == 3)
{
int ii = 0;
for (int j = 0; j < 6; j++)
{
for (int k = 0; k < 8; k++)
{
Buttons[ii] = (1 << k & (unsigned char)*(pCurr + 1 + j)) > 0;
ii++;
}
}
if (printdebug)
{
dr3 = FString::FromHexBlob(pCurr, 7);
}
pCurr += 7; // new
}
//pCurr += 7; // changed - it's not always 7 anymore.
}
ctr++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment