【问题标题】:Difficulties with modelling Latitude and Longitude on Unity3D在 Unity3D 上建模纬度和经度的困难
【发布时间】:2019-10-17 19:39:35
【问题描述】:

我在用球体建模地球并使用另一个球体作为标记来标记地球球体的纬度和经度位置时遇到了一些麻烦。

我已将 x、y 和 z 比例设置为 635.6752,因为这是地球半径的 1000:1 比例(以米为单位)。我用的是伦敦的经纬度定位。

代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Earth : MonoBehaviour
{
    public GameObject ObjectEarth;
    public Transform ObjectMarker; // ObjectMarker object
    public float radius = 635.6752f; // globe ball radius (unity units)
    public float latitude = 51.5072f; // lat
    public float longitude = 0.1275f; // long


    // Start is called before the first frame update
    void Start()
    {

        ObjectEarth.transform.localScale = new Vector3(radius, radius, radius);

        latitude = Mathf.PI * latitude / 180;
        longitude = Mathf.PI * longitude / 180;

        // adjust position by radians   
        latitude -= 1.570795765134f; // subtract 90 degrees (in radians)

        // and switch z and y (since z is forward)
        float xPos = (radius) * Mathf.Sin(latitude) * Mathf.Cos(longitude);
        float zPos = (radius) * Mathf.Sin(latitude) * Mathf.Sin(longitude);
        float yPos = (radius) * Mathf.Cos(latitude);


        // move ObjectMarker to position
        ObjectMarker.position = new Vector3(xPos, yPos, zPos);

    }

    // Update is called once per frame
    void Update()
    {

    }
}

这是场景视图中的输出:

我不太清楚为什么标记物体离地球物体表面这么远,理论上应该在地球物体表面。

欢迎任何帮助和建议。

谢谢!

【问题讨论】:

    标签: c# unity3d coordinates


    【解决方案1】:

    Unity 的球体基元的基本半径为 0.5 个单位。因此,要使球体的半径为radius,您需要将比例设置为该值的两倍:

    ObjectEarth.transform.localScale = 2f * radius * Vector3.one;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-09
      • 1970-01-01
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 2013-02-21
      相关资源
      最近更新 更多