Skip to content

Commit

Permalink
Fix position of objects created in XRInteraction. Also, ray has to be
Browse files Browse the repository at this point in the history
enabled by pressing both triggers >20%
  • Loading branch information
kwahoo2 committed May 15, 2021
1 parent a144d84 commit 88dc633
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 47 deletions.
71 changes: 46 additions & 25 deletions src/Gui/CoinXRWidget.cpp
Expand Up @@ -436,6 +436,7 @@ void CoinXRWidget::prepareControls()
for (uint32_t i = 0; i < hands; i++)
{
currTriggerVal[i] = 0.0f;
oldTriggerVal[i] = 0.0f;
}

xr::ActionSetCreateInfo actionSetInfo{ };
Expand Down Expand Up @@ -929,39 +930,59 @@ void CoinXRWidget::updateXrControls()
}

//XRInteraction
mXRi->setControllerState(i, worldTransform, conTrans[i], conRotat[i], currTriggerVal[i]);
mXRi->setControllerState(i, conTrans[i], conRotat[i], currTriggerVal[i]);
}

if (((currTriggerVal[0] > 0.2 && oldTriggerVal[0] <= 0.2) && (currTriggerVal[1] > 0.2))
|| ((currTriggerVal[1] > 0.2 && oldTriggerVal[1] <= 0.2) && (currTriggerVal[0] > 0.2))) //enable or disable Interaction
{
if (interaction)
{
interaction = false;
}
else
{
interaction = true;
}
}
for (uint32_t i = 0; i < hands; i++)
{
oldTriggerVal[i] = currTriggerVal[i];
}
}

void CoinXRWidget::updateXrGui()
{
//picking ray
SbVec3f startVec = conTrans[secondaryConId]->translation.getValue();
SbVec3f endVec = conTrans[secondaryConId]->translation.getValue() - rayAxis;

SoSeparator *menuRoot = new SoSeparator; //build a tree just for menu picking
menuRoot->addChild(conTrans[primaryConId]);
menuRoot->addChild(conRotat[primaryConId]);
menuRoot->addChild(camera[0]);
menuRoot->addChild(conMenuSep);

if (mXRi->findPickedObject(menuRoot, vpReg,
startVec, endVec, rayAxis,
nearPlane, farPlane))
if (interaction)
{
//place for menu operations
//picking ray
SbVec3f startVec = conTrans[secondaryConId]->translation.getValue();
SbVec3f endVec = conTrans[secondaryConId]->translation.getValue() - rayAxis;

SoSeparator *menuRoot = new SoSeparator; //build a tree just for menu picking
menuRoot->addChild(conTrans[primaryConId]);
menuRoot->addChild(conRotat[primaryConId]);
menuRoot->addChild(camera[0]);
menuRoot->addChild(conMenuSep);

if (mXRi->findPickedObject(menuRoot, vpReg,
startVec, endVec, rayAxis,
nearPlane, farPlane))
{
//place for menu operations

}
else
{
//if menu not hit, check the scene
mXRi->findPickedObject(wSep, vpReg,
startVec, endVec, rayAxis,
nearPlane, farPlane);
}
}
else
{
//if menu not hit, check the scene
mXRi->findPickedObject(wSep, vpReg,
startVec, endVec, rayAxis,
nearPlane, farPlane);
}

//prepare and execute commands
mXRi->applyInput();
//prepare and execute commands
mXRi->applyInput();
}

}

Expand Down
2 changes: 2 additions & 0 deletions src/Gui/CoinXRWidget.h
Expand Up @@ -121,6 +121,7 @@ class CoinXRWidget : public QOpenGLWidget , protected QOpenGLFunctions_4_5_Core
SbVec3f rayAxis;

bool quit{ false };
bool interaction{ false };
static const uint32_t hands = 2;
uint32_t m_nRenderWidth;
uint32_t m_nRenderHeight;
Expand Down Expand Up @@ -154,6 +155,7 @@ class CoinXRWidget : public QOpenGLWidget , protected QOpenGLFunctions_4_5_Core
float movSpeed;
float scaleMod;
float currTriggerVal[hands];
float oldTriggerVal[hands];
QElapsedTimer eTimer; //measure time of frame
uint32_t primaryConId = 0; //left one one most systemes
uint32_t secondaryConId = 1;
Expand Down
26 changes: 8 additions & 18 deletions src/Gui/XRInteraction.cpp
Expand Up @@ -57,8 +57,8 @@ XRInteraction::XRInteraction()
menuSep->addChild(textTrans);
menuText = new SoText3;
SoScale * textScale = new SoScale;
textScale->scaleFactor.setValue(SbVec3f(0.01f, 0.01f, 0.01f));
menuText->string = "test";
textScale->scaleFactor.setValue(SbVec3f(0.005f, 0.005f, 0.005f));
menuText->string = "Press triggers to enable ray";
menuSep->addChild(textScale);
menuSep->addChild(menuText);

Expand Down Expand Up @@ -87,7 +87,7 @@ XRInteraction::XRInteraction()
void XRInteraction::applyInput()
{
for (uint32_t i = 0; i < hands; i++){
if (currTriggerVal[i] > 0.5 && oldTriggerVal[i] <= 0.5)
if (currTriggerVal[i] > 0.9 && oldTriggerVal[i] <= 0.9)
{

double l = 200.0;
Expand All @@ -110,12 +110,10 @@ void XRInteraction::applyInput()
.arg(l)
.arg(w)
.arg(h)
/*meters to milimeters conversion
* TODO world transformation, translation only so far
*rotation using controller stick will put the box i wrong place*/
.arg((conTransVec[i][0] - wTransVec[0]) * 1000)
.arg((conTransVec[i][1] - wTransVec[1]) * 1000)
.arg((conTransVec[i][2] - wTransVec[2]) * 1000)
/*meters to milimeters conversion*/
.arg((conTransVec[i][0]) * 1000)
.arg((conTransVec[i][1]) * 1000)
.arg((conTransVec[i][2]) * 1000)
.arg(conRotatQuat[i][0])
.arg(conRotatQuat[i][1])
.arg(conRotatQuat[i][2])
Expand All @@ -134,20 +132,12 @@ void XRInteraction::applyInput()

}

void XRInteraction::setControllerState(uint32_t id, const SoTransform *wt, const SoTranslation *st, const SoRotation *sr, float tv)
void XRInteraction::setControllerState(uint32_t id, const SoTranslation *st, const SoRotation *sr, float tv)
{
conTransVec[id] = st->translation.getValue();
conRotatQuat[id] = sr->rotation.getValue();
currTriggerVal[id] = tv;

wTransVec = wt->translation.getValue(); //take note of worldtranformation, world can be moved relative to physical position
wCenter = wt->center.getValue();
wRotatQuat = wt->rotation.getValue();
//wRotatQuat.invert();

/*Base::Console().Warning("Hand pose %d: %f %f %f %f, %f %f %f\n", id,
conRotat[id]->rotation.getValue()[0], conRotat[id]->rotation.getValue()[1],conRotat[id]->rotation.getValue()[2],conRotat[id]->rotation.getValue()[3],
conTrans[id]->translation.getValue()[0], conTrans[id]->translation.getValue()[1], conTrans[id]->translation.getValue()[2]);*/
}

SoSeparator * XRInteraction::getMenuSeparator()
Expand Down
5 changes: 1 addition & 4 deletions src/Gui/XRInteraction.h
Expand Up @@ -65,7 +65,7 @@ class XRInteraction
~XRInteraction();

void applyInput();
void setControllerState(uint32_t id, const SoTransform *wt, const SoTranslation *st, const SoRotation *sr, float tv);
void setControllerState(uint32_t id, const SoTranslation *st, const SoRotation *sr, float tv);
SoSeparator * getMenuSeparator();
SoSeparator * getRaySeparator();
const SoPickedPoint * findPickedObject(SoSeparator *sep, SbViewportRegion vpReg,
Expand All @@ -79,9 +79,6 @@ class XRInteraction
float oldTriggerVal[hands];
SbVec3f conTransVec[hands];
SbRotation conRotatQuat[hands];
SbVec3f wTransVec;
SbVec3f wCenter;
SbRotation wRotatQuat;

QString cmd;
uint32_t objCount = 0;
Expand Down

0 comments on commit 88dc633

Please sign in to comment.