hacky placement of UI ribbon after lower panel is released (need to rework panel visibility logic)

This commit is contained in:
amwatson 2024-03-21 22:12:27 -05:00
parent e486b927b2
commit 6902e9c923
3 changed files with 54 additions and 15 deletions

View file

@ -439,6 +439,28 @@ void GameSurfaceLayer::SetTopPanelFromController(const XrVector3f& controllerPos
mTopPanel.mPanelFromWorld = XrPosef{windowRotation, windowPosition};
}
void GameSurfaceLayer::SetLowerPanelFromController(const XrVector3f& controllerPosition) {
static constexpr XrVector3f viewerPosition{0, 0, 0}; // Set viewer position
const float sphereRadius = XrMath::Vector3f::Length(
mLowerPanel.mPanelFromWorld.position - viewerPosition); // Set the initial distance of the
// window from the viewer
static constexpr XrVector3f windowUpDirection{0, 1, 0}; // Y is up
const XrVector3f windowPosition =
CalculatePanelPosition(viewerPosition, controllerPosition, sphereRadius);
const XrQuaternionf windowRotation =
CalculatePanelRotation(windowPosition, viewerPosition, windowUpDirection);
if (windowPosition.y >
(mTopPanel.mPanelFromWorld.position.y - kDistanceBetweenPanelsInMeters)) {
return;
}
if (XrMath::Quatf::GetYawInRadians(windowRotation) > MATH_FLOAT_PI / 3.0f) { return; }
mLowerPanel.mPanelFromWorld = XrPosef{windowRotation, windowPosition};
}
static constexpr float kThumbstickSpeed = 0.05f;
void GameSurfaceLayer::SetTopPanelFromThumbstick(const float thumbstickY) {

View file

@ -169,8 +169,9 @@ public:
void SetTopPanelFromController(const XrVector3f& controllerPosition);
void SetTopPanelFromThumbstick(const float thumbstickY);
XrPosef SetLowerPanelFromThumbstick(const float thumbstickY);
void SetLowerPanelFromController(const XrVector3f& controllerPosition);
XrPosef GetTopPanelFromHeadPose(uint32_t eye, const XrPosef& headPose);
const XrPosef& GetLowerPanelPose() const { return mLowerPanel.mPanelFromWorld; }
private:
int Init(const XrSession& session, const jobject activityObject);

View file

@ -385,7 +385,7 @@ private:
// Super Immersive Mode update and computation.
//////////////////////////////////////////////////
bool showLowerPanel = appState.ShouldShowLowerPanel();
bool showLowerPanel = true;
float immersiveModeFactor = (VRSettings::values.vr_immersive_mode < 2)
? immersiveScaleFactor[VRSettings::values.vr_immersive_mode]
: immersiveScaleFactor[2];
@ -668,6 +668,7 @@ private:
mInputStateFrame.mIsHandActive[mInputStateFrame.mPreferredHand];
static bool sIsLowerPanelBeingPositioned = false;
const bool wasLowerPanelBeingPositioned = sIsLowerPanelBeingPositioned;
sIsLowerPanelBeingPositioned &=
appState.mLowerMenuType == LowerMenuType::POSITIONAL_MENU &&
@ -707,9 +708,23 @@ private:
// No dialogs/popups that should impede normal cursor interaction with
// applicable panels
if (!shouldRenderCursor && appState.ShouldShowLowerPanel()) {
// Lock ribbon in place when placement is complete
const bool needRibbonUpdate = !sIsLowerPanelBeingPositioned && wasLowerPanelBeingPositioned;
if (needRibbonUpdate) {
mRibbonLayer->SetPanelWithPose(mGameSurfaceLayer->GetLowerPanelPose());
}
if (!shouldRenderCursor) {
shouldRenderCursor = mGameSurfaceLayer->GetRayIntersectionWithPanel(
start, end, cursorPos2d, cursorPose3d);
if ((shouldRenderCursor || sIsLowerPanelBeingPositioned) &&
appState.mLowerMenuType == LowerMenuType::POSITIONAL_MENU &&
triggerState.currentState) {
mGameSurfaceLayer->SetLowerPanelFromController(
XrVector3f{0, cursorPose3d.position.y, cursorPose3d.position.z});
sIsLowerPanelBeingPositioned = true;
} else if (appState.mLowerMenuType == LowerMenuType::MAIN_MENU) {
if (triggerState.currentState == 0 && triggerState.changedSinceLastSync) {
jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID,
cursorPos2d.x, cursorPos2d.y, 0);
@ -724,6 +739,7 @@ private:
cursorPos2d.x, cursorPos2d.y, 2);
}
}
}
if (!shouldRenderCursor) {
shouldRenderCursor = mRibbonLayer->GetRayIntersectionWithPanel(
@ -740,13 +756,13 @@ private:
// the depth
const XrActionStateVector2f& thumbstickState =
mInputStateFrame.mThumbStickState[mInputStateFrame.mPreferredHand];
if (std::abs(thumbstickState.currentState.y) >
kThumbStickDirectionThreshold) {
const XrPosef lowerPanelPose =
mGameSurfaceLayer->SetLowerPanelFromThumbstick(
thumbstickState.currentState.y);
mRibbonLayer->SetPanelWithPose(lowerPanelPose);
sIsLowerPanelBeingPositioned = true;
}
}
}