C++ 使用 glm 实现 Cartesian3.fromDegrees

C++ 使用 glm 实现 Cartesian3.fromDegrees

cpp 复制代码
#include <glm/glm.hpp>
#define _USE_MATH_DEFINES
#include <cmath>

namespace FastBVH
{
  float RADIANS_PER_DEGREE = M_PI / 180.0;
  // 定义地球半径的平方(可以用你自己的椭球模型)
  const glm::dvec3 defaultRadiiSquared = glm::dvec3(6378137.0f * 6378137.0f, 6378137.0f * 6378137.0f, 6356752.3f * 6356752.3f);

  class Cartesian3
  {
  public:
    static glm::dvec3 fromRadians(double longitude, double latitude, double height)
    {
      const glm::dvec3 &radiiSquared = defaultRadiiSquared;

      double cosLatitude = std::cos(latitude);
      glm::dvec3 scratchN(cosLatitude * std::cos(longitude), cosLatitude * std::sin(longitude), std::sin(latitude));

      scratchN = glm::normalize(scratchN);

      glm::dvec3 scratchK = radiiSquared * scratchN;

      double gamma = std::sqrt(dot(scratchN, scratchK));
      scratchK = scratchK / gamma;

      scratchN = scratchN * height;

      return scratchK + scratchN;
    }

    static glm::dvec3 fromDegrees(double longitude, double latitude, double height)
    {
      longitude = longitude * RADIANS_PER_DEGREE;
      latitude = latitude * RADIANS_PER_DEGREE;
      return fromRadians(longitude, latitude, height);
    }
  };
}
相关推荐
北 染 星 辰9 分钟前
Python--TCP/UDP通信
开发语言·python
Wendy_robot16 分钟前
远程连接MySQL并操作
linux·c++·mysql
zhooyu27 分钟前
C++和OpenGL实现3D游戏编程【目录】
开发语言·游戏·游戏程序
小ᶻᶻᶻᶻ29 分钟前
从零开始搭建 PHP
开发语言·php
oliveira-time34 分钟前
C++ prime plus课后习题-第二章
开发语言·c++·算法
mit6.8241 小时前
[Linux#49][UDP] 2w字详解 | socketaddr | 常用API | 实操:实现简易Udp传输
linux·网络·c++·笔记·后端
0点51 胜1 小时前
[ffmpeg]音频格式转换
开发语言·c++·ffmpeg
水木流年追梦1 小时前
【python因果推断库16】使用 PyMC 模型进行回归拐点设计
开发语言·python·回归
guigui_hello1 小时前
VScode的简单使用
c++·ide·vscode·编辑器
只想摆烂@2 小时前
C# winfrom 如何多窗体优雅的回调方法
开发语言·c#