1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef DEVICE_VR_ANDROID_ARCORE_ARCORE_MATH_UTILS_H_
6 #define DEVICE_VR_ANDROID_ARCORE_ARCORE_MATH_UTILS_H_
7 
8 #include <array>
9 #include <vector>
10 
11 #include "base/containers/span.h"
12 #include "ui/gfx/transform.h"
13 
14 namespace device {
15 
16 // Creates a matrix that transforms UV coordinates based on how a well known
17 // input was transformed. ArCore doesn't provide a way to get a matrix directly.
18 // There's a function to transform UV vectors individually, which can't be used
19 // from a shader, so we run that on selected well-known vectors
20 // (kDisplayCoordinatesForTransform) and recreate the matrix from the result.
21 gfx::Transform MatrixFromTransformedPoints(const base::span<const float> uvs);
22 
23 // Input coordinates used when computing UV transform.
24 // |MatrixFromTransformedPoints(uvs)| function above assumes that the |uvs| are
25 // the result of transforming kInputCoordinatesForTransform by some matrix.
26 constexpr std::array<float, 6> kInputCoordinatesForTransform = {0.f, 0.f, 1.f,
27                                                                 0.f, 0.f, 1.f};
28 
29 }  // namespace device
30 
31 #endif  // DEVICE_VR_ANDROID_ARCORE_ARCORE_MATH_UTILS_H_
32