Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f10f72c authored by Ytai Ben-tsvi's avatar Ytai Ben-tsvi Committed by Android (Google) Code Review
Browse files

Merge changes I58e1c380,I3aa1f225,Ifb73050e into sc-v2-dev

* changes:
  Fix display orientation handling
  Better support for head and screen sensors being the same one
  Refine the recenter operation
parents 4cd7136c 7901bddf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -53,10 +53,10 @@ TEST(HeadTrackingProcessor, BasicComposition) {
    processor->setWorldToHeadPose(0, Pose3f(), Twist3f());
    processor->setWorldToScreenPose(0, Pose3f());

    processor->setDisplayOrientation(physicalToLogical);
    processor->setWorldToHeadPose(0, worldToHead, Twist3f());
    processor->setWorldToScreenPose(0, worldToScreen);
    processor->setScreenToStagePose(screenToStage);
    processor->setDisplayOrientation(physicalToLogical);
    processor->calculate(0);
    ASSERT_EQ(processor->getActualMode(), HeadTrackingMode::SCREEN_RELATIVE);
    EXPECT_EQ(processor->getHeadToStagePose(), worldToHead.inverse() * worldToScreen *
+29 −11
Original line number Diff line number Diff line
@@ -57,7 +57,14 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {
    }

    void setWorldToScreenPose(int64_t timestamp, const Pose3f& worldToScreen) override {
        mScreenPoseDriftCompensator.setInput(timestamp, worldToScreen);
        if (mPhysicalToLogicalAngle != mPendingPhysicalToLogicalAngle) {
            // We're introducing an artificial discontinuity. Enable the rate limiter.
            mRateLimiter.enable();
            mPhysicalToLogicalAngle = mPendingPhysicalToLogicalAngle;
        }

        mScreenPoseDriftCompensator.setInput(
                timestamp, worldToScreen * Pose3f(rotateY(-mPhysicalToLogicalAngle)));
        mWorldToScreenTimestamp = timestamp;
    }

@@ -66,10 +73,7 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {
    }

    void setDisplayOrientation(float physicalToLogicalAngle) override {
        if (mPhysicalToLogicalAngle != physicalToLogicalAngle) {
            mRateLimiter.enable();
        }
        mPhysicalToLogicalAngle = physicalToLogicalAngle;
        mPendingPhysicalToLogicalAngle = physicalToLogicalAngle;
    }

    void calculate(int64_t timestamp) override {
@@ -80,8 +84,7 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {
        }

        if (mWorldToScreenTimestamp.has_value()) {
            const Pose3f worldToLogicalScreen = mScreenPoseDriftCompensator.getOutput() *
                                                Pose3f(rotateY(-mPhysicalToLogicalAngle));
            const Pose3f worldToLogicalScreen = mScreenPoseDriftCompensator.getOutput();
            mScreenHeadFusion.setWorldToScreenPose(mWorldToScreenTimestamp.value(),
                                                   worldToLogicalScreen);
        }
@@ -108,15 +111,30 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {

    HeadTrackingMode getActualMode() const override { return mModeSelector.getActualMode(); }

    void recenter() override {
    void recenter(bool recenterHead, bool recenterScreen) override {
        if (recenterHead) {
            mHeadPoseDriftCompensator.recenter();
        }
        if (recenterScreen) {
            mScreenPoseDriftCompensator.recenter();
        }

        // If a sensor being recentered is included in the current mode, apply rate limiting to
        // avoid discontinuities.
        HeadTrackingMode mode = mModeSelector.getActualMode();
        if ((recenterHead && (mode == HeadTrackingMode::WORLD_RELATIVE ||
                              mode == HeadTrackingMode::SCREEN_RELATIVE)) ||
            (recenterScreen && mode == HeadTrackingMode::SCREEN_RELATIVE)) {
            mRateLimiter.enable();
        }
    }

  private:
    const Options mOptions;
    float mPhysicalToLogicalAngle = 0;
    // We store the physical to logical angle as "pending" until the next world-to-screen sample it
    // applies to arrives.
    float mPendingPhysicalToLogicalAngle = 0;
    std::optional<int64_t> mWorldToHeadTimestamp;
    std::optional<int64_t> mWorldToScreenTimestamp;
    Pose3f mHeadToStagePose;
−122 B (38.9 KiB)
Loading image diff...
+2 −2
Original line number Diff line number Diff line
@@ -89,9 +89,9 @@ class HeadTrackingProcessor {
    virtual HeadTrackingMode getActualMode() const = 0;

    /**
     * This causes the current poses for both the head and screen to be considered "center".
     * This causes the current poses for both the head and/or screen to be considered "center".
     */
    virtual void recenter() = 0;
    virtual void recenter(bool recenterHead = true, bool recenterScreen = true) = 0;
};

/**
+4 −2
Original line number Diff line number Diff line
@@ -77,11 +77,13 @@ class SensorPoseProvider {

    /**
     * Start receiving pose updates from a given sensor.
     * Attempting to start a sensor that has already been started results in undefined behavior.
     * @param sensor The sensor to subscribe to.
     * @param samplingPeriod Sampling interval, in microseconds. Actual rate might be slightly
     * different.
     * @return A handle, which can be later used for stopSensor(). INVALID_HANDLE would be returned
     * in case of error.
     * @return The sensor handle, which can be later used for stopSensor(). INVALID_HANDLE would be
     * returned in case of error. This is guaranteed to be the same handle as the one returned by
     * ASensor_getHandle(sensor).
     */
    virtual int32_t startSensor(const ASensor* sensor,
                                std::chrono::microseconds samplingPeriod) = 0;
Loading