Cesium for UE4中的坐标系及其转换(再续)

这篇具有很好参考价值的文章主要介绍了Cesium for UE4中的坐标系及其转换(再续)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

GeoTransforms

A lightweight structure to encapsulate coordinate transforms.

轻量级的坐标转换类,可以在ECEF、经纬度和UE4坐标之间进行转换。文章来源地址https://www.toymoban.com/news/detail-506468.html

  • Earth-Centered, Earth-Fixed (ECEF) coordinates
  • Georeferenced coordinates (Latitude/Longitude/Height)
  • Unreal coordinates (relative to the unreal world origin)
// Copyright 2020-2021 CesiumGS, Inc. and Contributors

#pragma once

#include "CesiumGeospatial/Ellipsoid.h"

#include <glm/glm.hpp>

/**
 * @brief A lightweight structure to encapsulate coordinate transforms.
 *
 * It encapsulates the conversions between...
 * - Earth-Centered, Earth-Fixed (ECEF) coordinates
 * - Georeferenced coordinates (Latitude/Longitude/Height)
 * - Unreal coordinates (relative to the unreal world origin)
 *
 */
class CESIUMRUNTIME_API GeoTransforms {

public:
  /**
   * @brief Creates a new instance
   */
  GeoTransforms()
      : _ellipsoid(CesiumGeospatial::Ellipsoid::WGS84),
        _center(glm::dvec3(0.0)),
        _georeferencedToEcef(1.0),
        _ecefToGeoreferenced(1.0),
        _ueAbsToEcef(1.0),
        _ecefToUeAbs(1.0) {
    updateTransforms();
  }

  /**
   * @brief Creates a new instance.
   *
   * The center position is the position of the origin of the
   * local coordinate system that is established by this instance.
   *
   * @param ellipsoid The ellipsoid to use for the georeferenced coordinates
   * @param center The center position.
   */
  GeoTransforms(
      const CesiumGeospatial::Ellipsoid& ellipsoid,
      const glm::dvec3& center)
      : _ellipsoid(ellipsoid),
        _center(center),
        _georeferencedToEcef(1.0),
        _ecefToGeoreferenced(1.0),
        _ueAbsToEcef(1.0),
        _ecefToUeAbs(1.0) {
    updateTransforms();
  }

  /**
   * @brief Set the center position of this instance
   *
   * The center position is the position of the origin of the
   * local coordinate system that is established by this instance.
   *
   * @param center The center position.
   */
  void setCenter(const glm::dvec3& center) noexcept;

  /**
   * @brief Set the ellipsoid of this instance
   *
   * @param ellipsoid The ellipsoid
   */
  void setEllipsoid(const CesiumGeospatial::Ellipsoid& ellipsoid) noexcept;

  /**
   * Transforms the given longitude in degrees (x), latitude in
   * degrees (y), and height in meters (z) into Earth-Centered, Earth-Fixed
   * (ECEF) coordinates.
   */
  glm::dvec3 TransformLongitudeLatitudeHeightToEcef(
      const glm::dvec3& LongitudeLatitudeHeight) const noexcept;

  /**
   * Transforms the given Earth-Centered, Earth-Fixed (ECEF) coordinates into
   * longitude in degrees (x), latitude in degrees (y), and height in
   * meters (z).
   */
  glm::dvec3
  TransformEcefToLongitudeLatitudeHeight(const glm::dvec3& Ecef) const noexcept;

  /**
   * Transforms the given longitude in degrees (x), latitude in
   * degrees (y), and height in meters (z) into Unreal world coordinates
   * (relative to the floating origin).
   */
  glm::dvec3 TransformLongitudeLatitudeHeightToUnreal(
      const glm::dvec3& origin,
      const glm::dvec3& LongitudeLatitudeHeight) const noexcept;

  /**
   * Transforms Unreal world coordinates (relative to the floating origin) into
   * longitude in degrees (x), latitude in degrees (y), and height in
   * meters (z).
   */
  glm::dvec3 TransformUnrealToLongitudeLatitudeHeight(
      const glm::dvec3& origin,
      const glm::dvec3& Ue) const noexcept;

  /**
   * Transforms the given point from Earth-Centered, Earth-Fixed (ECEF) into
   * Unreal world coordinates (relative to the floating origin).
   */
  glm::dvec3 TransformEcefToUnreal(
      const glm::dvec3& origin,
      const glm::dvec3& Ecef) const noexcept;

  /**
   * Transforms the given point from Unreal world coordinates (relative to the
   * floating origin) to Earth-Centered, Earth-Fixed (ECEF).
   */
  glm::dvec3 TransformUnrealToEcef(
      const glm::dvec3& origin,
      const glm::dvec3& Ue) const noexcept;

  /**
   * Transforms a rotator from Unreal world to East-North-Up at the given
   * Unreal relative world location (relative to the floating origin).
   */
  glm::dquat TransformRotatorUnrealToEastNorthUp(
      const glm::dvec3& origin,
      const glm::dquat& UeRotator,
      const glm::dvec3& UeLocation) const noexcept;

  /**
   * Transforms a rotator from East-North-Up to Unreal world at the given
   * Unreal world location (relative to the floating origin).
   */
  glm::dquat TransformRotatorEastNorthUpToUnreal(
      const glm::dvec3& origin,
      const glm::dquat& EnuRotator,
      const glm::dvec3& UeLocation) const noexcept;

  /**
   * Computes the rotation matrix from the local East-North-Up to Unreal at the
   * specified Unreal world location (relative to the floating
   * origin). The returned transformation works in Unreal's left-handed
   * coordinate system.
   */
  glm::dmat3 ComputeEastNorthUpToUnreal(
      const glm::dvec3& origin,
      const glm::dvec3& Ue) const noexcept;

  /**
   * Computes the rotation matrix from the local East-North-Up to
   * Earth-Centered, Earth-Fixed (ECEF) at the specified ECEF location.
   */
  glm::dmat3 ComputeEastNorthUpToEcef(const glm::dvec3& Ecef) const noexcept;

  /*
   * GEOREFERENCE TRANSFORMS
   */

  /**
   * @brief Gets the transformation from the "Georeferenced" reference frame
   * defined by this instance to the "Ellipsoid-centered" reference frame (i.e.
   * ECEF).
   *
   * Gets a matrix that transforms coordinates from the "Georeference" reference
   * frame defined by this instance to the "Ellipsoid-centered" reference frame,
   * which is usually Earth-centered, Earth-fixed. See {@link
   * reference-frames.md}.
   */
  const glm::dmat4&
  GetGeoreferencedToEllipsoidCenteredTransform() const noexcept {
    return this->_georeferencedToEcef;
  }

  /**
   * @brief Gets the transformation from the "Ellipsoid-centered" reference
   * frame (i.e. ECEF) to the georeferenced reference frame defined by this
   * instance.
   *
   * Gets a matrix that transforms coordinates from the "Ellipsoid-centered"
   * reference frame (which is usually Earth-centered, Earth-fixed) to the
   * "Georeferenced" reference frame defined by this instance. See {@link
   * reference-frames.md}.
   */
  const glm::dmat4&
  GetEllipsoidCenteredToGeoreferencedTransform() const noexcept {
    return this->_ecefToGeoreferenced;
  }

  /**
   * @brief Gets the transformation from the _absolute_ "Unreal World" reference
   * frame to the "Ellipsoid-centered" reference frame (i.e. ECEF).
   *
   * Gets a matrix that transforms coordinates from the absolute "Unreal World"
   * reference frame (with respect to the absolute world origin, not the
   * floating origin) to the "Ellipsoid-centered" reference frame (which is
   * usually Earth-centered, Earth-fixed). See {@link reference-frames.md}.
   */
  const glm::dmat4&
  GetAbsoluteUnrealWorldToEllipsoidCenteredTransform() const noexcept {
    return this->_ueAbsToEcef;
  }

  /**
   * @brief Gets the transformation from the "Ellipsoid-centered" reference
   * frame (i.e. ECEF) to the absolute "Unreal World" reference frame.
   *
   * Gets a matrix that transforms coordinates from the "Ellipsoid-centered"
   * reference frame (which is usually Earth-centered, Earth-fixed) to the
   * absolute "Unreal world" reference frame (with respect to the absolute world
   * origin, not the floating origin). See {@link reference-frames.md}.
   */
  const glm::dmat4&
  GetEllipsoidCenteredToAbsoluteUnrealWorldTransform() const noexcept {
    return this->_ecefToUeAbs;
  }

  /**
   * @brief Computes the normal of the plane tangent to the surface of the
   * ellipsoid that is used by this instance, at the provided position.
   *
   * @param position The cartesian position for which to to determine the
   * surface normal.
   * @return The normal.
   */
  glm::dvec3 ComputeGeodeticSurfaceNormal(const glm::dvec3& position) const {
    return _ellipsoid.geodeticSurfaceNormal(position);
  }

  /**
   * Computes the rotation in ellipsoid surface normal between an old position
   * and a new position. This rotation is expressed in terms of Unreal world
   * coordinates, and can be used to maintain an object's orientation relative
   * to the local horizontal as it moves over the globe.
   *
   * @param oldPosition The old ECEF position that the object moved from.
   * @param newPosition The new ECEF position that the object moved to.
   * @return The rotation from the ellipsoid surface normal at the old position
   * to the ellipsoid surface normal at the new position.
   */
  glm::dquat ComputeSurfaceNormalRotation(
      const glm::dvec3& oldPosition,
      const glm::dvec3& newPosition) const;

  /**
   * Computes the rotation in ellipsoid surface normal between an old position
   * and a new position. This rotation is expressed in terms of Unreal world
   * coordinates, and can be used to maintain an object's orientation relative
   * to the local horizontal as it moves over the globe.
   *
   * @param oldPosition The old ECEF position that the object moved from.
   * @param newPosition The new ECEF position that the object moved to.
   * @return The rotation from the ellipsoid surface normal at the old position
   * to the ellipsoid surface normal at the new position.
   */
  glm::dquat ComputeSurfaceNormalRotationUnreal(
      const glm::dvec3& oldPosition,
      const glm::dvec3& newPosition) const;

private:
  /**
   * Update the derived state (i.e. the matrices) when either
   * the center or the ellipsoid has changed.
   */
  void updateTransforms() noexcept;

  // Modifiable state
  CesiumGeospatial::Ellipsoid _ellipsoid;
  glm::dvec3 _center;

  // Derived state
  glm::dmat4 _georeferencedToEcef;
  glm::dmat4 _ecefToGeoreferenced;
  glm::dmat4 _ueAbsToEcef;
  glm::dmat4 _ecefToUeAbs;
};

Usage

glm::dmat4 ecefToUeAbs = glm::dmat4(1.0);
glm::dvec3 center = Cesium3DTilesSelection::getBoundingVolumeCenter(this->_pTileset->getRootTile()->getBoundingVolume());
glm::dmat4 georeferencedToEcef =
    CesiumGeospatial::Transforms::eastNorthUpToFixedFrame(center);
glm::dmat4 ecefToGeoreferenced = glm::affineInverse(georeferencedToEcef);
  // update ECEF -> UE
ecefToUeAbs = CesiumTransforms::unrealToOrFromCesium *
    CesiumTransforms::scaleToUnrealWorld *
    ecefToGeoreferenced;
    
glm::dmat4 AbsToEcef = glm::affineInverse(ecefToUeAbs);

glm::dvec3 ecef= glm::dvec3(AbsToEcef * glm::dvec4(glm::dvec3(
        unrealPosition.X,
        unrealPosition.Y,
        unrealPosition.Z), 1.0));
        
GeoTransforms trans;
glm::dvec3 BLH=trans.TransformEcefToLongitudeLatitudeHeight(ecef);

参考

  1. 地心坐标系
  2. Cesium for UE4 wiki

到了这里,关于Cesium for UE4中的坐标系及其转换(再续)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 齐次坐标变换的理解以及在无人机相机定位坐标系转换中的应用

    4*4矩阵的右边三个数表示平移,如果原来的向量u的w=0,那么就是u+(ai+bj+ck) 对应xyz三个轴的循环变换,注意负号的位置 用描述空间一点的变换方法来描述物体在空间的位置和方向。 先变换的矩阵乘在右边。 A p = B p + A p B o {}^{A}p={}^{B}p+{}^{A}p_{B_{o}} A p = B p + A p B o ​ ​ 从

    2024年04月15日
    浏览(57)
  • cesium学习记录04-坐标系

    这些坐标定义了在用户的显示屏上的像素位置。例如,一个点的屏幕坐标可能是(x, y),其中x是从屏幕的左边开始的像素数,y是从屏幕的顶部开始的像素数。 这是一个三维空间中的点的坐标。在Cesium中,地球通常在(0,0,0)笛卡尔坐标中被建模。其他对象(如飞机或卫星)的位置

    2024年02月13日
    浏览(42)
  • 机器人坐标系转换从局部坐标系转换到世界坐标系

    矩阵方式: 下面是代码: 函数方式: 根据三角函数的特性,可以进行一下简化: 下面是简化前的代码示例:

    2024年04月16日
    浏览(63)
  • 坐标转换(相机坐标系、世界坐标系、图像物理坐标系、图像像素坐标系)

    一般情况下我们所涉及到的坐标包括四个,即相机坐标系、世界坐标系、图像物理坐标系、图像像素坐标系。我们本文的讲解思路是在讲解每个坐标转换之前先讲清楚每个坐标系所表示的含义。本文主要参考由高翔主编的视觉SLAM十四讲第五章相机模型。 相机将三维世界的坐

    2024年02月09日
    浏览(71)
  • 世界坐标系、相机坐标系和图像坐标系的转换

    之前只是停留在会用的阶段,一直没去读懂计算的原理,今天通读了大佬的文章,写的言简意赅,感谢感谢~~特此记录一下,仅用作个人笔记 贴链接,十分感谢~ https://blog.csdn.net/weixin_44278406/article/details/112986651 https://blog.csdn.net/guyuealian/article/details/104184551 将三维物体转换成照

    2023年04月15日
    浏览(63)
  • 相机坐标系、像素坐标系转换

    相机内参矩阵是相机的重要参数之一,它描述了相机光学系统的内部性质,例如焦距、光学中心和图像畸变等信息。在计算机视觉和图形学中,相机内参矩阵通常用于将图像坐标系中的像素坐标转换为相机坐标系中的三维坐标,或者将相机坐标系中的三维坐标投影到图像坐标

    2024年02月13日
    浏览(46)
  • 柱坐标系与直角坐标系的转换

    1.柱坐标系转化为直角坐标系:柱坐标系(r,φ,z)与直角坐标系(x,y,z)的转换关系 x=rcosφ y=rsinφ z=z 2.直角坐标系转化为柱坐标系:直角坐标系(x,y,z)与柱坐标系(r,φ,z)的转换关系: r= φ= z=z

    2024年02月11日
    浏览(41)
  • 图像坐标系如何转换到相机坐标系。

    问题描述:图像坐标系如何转换到相机坐标系。 问题解答: 图像坐标系的定义: 图像坐标系是用于描述数字图像中像素位置的坐标系。图像坐标系的原点是相机光轴与成像平面的交点。X轴沿着成像平面的水平方向正向,Y轴沿着成像平面的垂直方向正向。 相机坐标系的定义

    2024年02月04日
    浏览(50)
  • ROS中RVIZ坐标系及TF坐标系转换

    RVIZ坐标系 X轴--红色 Y轴---绿色 Z轴---蓝色 YAW(偏航角)绕Z轴旋转 PITCH(俯仰角)绕Y轴旋转 ROLL(滚转角)绕X轴旋转 符合右手坐标系原则 利用TF进行坐标系转换 采用以下指令进行转换,其中frame_id child_frame_id 为两个坐标系的名称,通过以下命令可以确定两者的关系 通过在RVIZ中更改“

    2024年02月11日
    浏览(36)
  • 机器人四大坐标系及其应用

    以ABB机器人为例,关于机器人的坐标系讲解其实网上有很多资料讲解,但都比较零散或者说知道什么意思却不知道怎么配置。对与初学者来说还是比较迷茫的,不过下面我会讲解机器人常用的四大坐标系具体是什么意思?具有什么意义,为什么要使用它们?怎么设置?先来个

    2024年02月02日
    浏览(44)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包