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_PUBLIC_MOJOM_POSE_H_ 6 #define DEVICE_VR_PUBLIC_MOJOM_POSE_H_ 7 8 #include "base/component_export.h" 9 #include "base/optional.h" 10 #include "ui/gfx/geometry/point3_f.h" 11 #include "ui/gfx/geometry/quaternion.h" 12 #include "ui/gfx/transform.h" 13 14 namespace device { 15 16 // Pose represents some entity's position and orientation and is always 17 // expressed relative to some coordinate system. Alternatively, the pose can be 18 // viewed as a rigid transform that performs a coordinate system change from the 19 // coordinate system represented by the entity (i.e. coordinate system whose 20 // origin is equal to entity's position and whose orientation is equal to 21 // entity's orientation) to the coordinate system relative to which the pose is 22 // supposed to be expressed. 23 // 24 // If the pose represents a position of entity |entity| in coordinate space 25 // |coord|, it is recommended to name such a variable as |coord_from_entity|. 26 // In order to obtain the matrix that performs the coordinate system 27 // transformation, the callers can use |GetOtherFromThis()| method. The 28 // resulting matrix will encode coordinate system change from |entity| space to 29 // |coord| space. 30 // 31 // The source for the naming convention can be found here: 32 // https://www.sebastiansylvan.com/post/matrix_naming_convention/ COMPONENT_EXPORT(VR_PUBLIC_TYPEMAPS)33class COMPONENT_EXPORT(VR_PUBLIC_TYPEMAPS) Pose { 34 public: 35 explicit Pose(); 36 explicit Pose(const gfx::Point3F& position, 37 const gfx::Quaternion& orientation); 38 39 // Creates a pose from transform by decomposing it. The method assumes that 40 // the passed in matrix represents a rigid transformation (i.e. only the 41 // orientation and translation components of the decomposed matrix will affect 42 // the result). If the matrix could not be decomposed, the method will return 43 // a base::nullopt. 44 static base::Optional<Pose> Create(const gfx::Transform& other_from_this); 45 46 const gfx::Point3F& position() const { return position_; } 47 48 const gfx::Quaternion& orientation() const { return orientation_; } 49 50 // Returns the underlying matrix representation of the pose. 51 const gfx::Transform& ToTransform() const; 52 53 private: 54 gfx::Point3F position_; 55 gfx::Quaternion orientation_; 56 57 // Transformation that can be used to switch from coordinate system 58 // represented by this pose to other coordinate system (i.e. the coordinate 59 // system relative to which this pose is supposed to be expressed). 60 gfx::Transform other_from_this_; 61 }; 62 63 } // namespace device 64 65 #endif // DEVICE_VR_PUBLIC_MOJOM_POSE_H_ 66