blob: f02357024c02faccbc70183bb8a66ebed81728cb [file] [log] [blame]
Ytai Ben-Tsvicbee7d42021-06-15 00:39:31 -07001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"){}
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "ScreenHeadFusion.h"
18
19namespace android {
20namespace media {
21
22void ScreenHeadFusion::setWorldToHeadPose(int64_t timestamp, const Pose3f& worldToHead) {
23 mWorldToHead = TimestampedPose{.timestamp = timestamp, .pose = worldToHead};
24}
25
26void ScreenHeadFusion::setWorldToScreenPose(int64_t timestamp, const Pose3f& worldToScreen) {
27 mWorldToScreen = TimestampedPose{.timestamp = timestamp, .pose = worldToScreen};
28}
29
30std::optional<ScreenHeadFusion::TimestampedPose> ScreenHeadFusion::calculate() {
31 // TODO: this is temporary, simplistic logic.
32 if (!mWorldToHead.has_value() || !mWorldToScreen.has_value()) {
33 return std::nullopt;
34 }
35 return TimestampedPose{
36 .timestamp = std::min(mWorldToHead->timestamp, mWorldToScreen->timestamp),
37 .pose = mWorldToScreen->pose.inverse() * mWorldToHead->pose};
38}
39
40} // namespace media
41} // namespace android