【发布时间】: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